Skip to content

Commit f2022c2

Browse files
committed
refactor(vcf_generator_lite): 重构主窗口布局和组件创建逻辑
- 引入 VerticalDialogLayout 混入类以支持垂直布局 - 重写 _create_widgets 方法,使用新的布局结构- 优化组件创建逻辑,提高代码复用性和可维护性- 增加类型注解和遵循 SOLID 原则的代码结构
1 parent 614469b commit f2022c2

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/vcf_generator_lite/window/main/window.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from ttk_text.scrolled_text import ScrolledText
88

99
from vcf_generator_lite.constants import APP_NAME, URL_LICENSE, URL_RELEASES, URL_REPORT, URL_REPOSITORY
10+
from vcf_generator_lite.layout.vertical_dialog_layout import VerticalDialogLayout
1011
from vcf_generator_lite.util.tkinter.menu import MenuBarWindowExtension, MenuCascade, MenuCommand, MenuSeparator
1112
from vcf_generator_lite.util.tkinter.widget import auto_wrap_configure_event
1213
from vcf_generator_lite.widget.menu import TextContextMenu
@@ -16,7 +17,7 @@
1617
EVENT_GENERATE, USAGE
1718

1819

19-
class MainWindow(ExtendedTk, MenuBarWindowExtension):
20+
class MainWindow(ExtendedTk, VerticalDialogLayout, MenuBarWindowExtension):
2021
generate_button: Button
2122
content_text: ScrolledText
2223
progress_bar: Progressbar
@@ -30,30 +31,34 @@ def _configure_ui_withdraw(self):
3031
self.title(APP_NAME)
3132
self.wm_minsize_pt(300, 300)
3233
self.wm_size_pt(450, 450)
33-
self._create_widgets()
34+
self._create_widgets(self)
3435
self._create_menus()
3536

3637
@override
3738
def _configure_ui(self):
3839
super()._configure_ui()
3940
self.content_text.focus_set()
4041

41-
def _create_widgets(self):
42-
description_label = Label(self, text=USAGE, justify=LEFT)
42+
@override
43+
def _create_header(self, parent: Misc):
44+
description_label = Label(parent, text=USAGE, justify=LEFT)
4345
description_label.bind("<Configure>", auto_wrap_configure_event, "+")
4446
description_label.pack(fill=X, padx="7p", pady="7p")
47+
return description_label
4548

46-
self.content_text = ScrolledText(self, undo=True, tabs="2c", tabstyle="wordprocessor", maxundo=5)
49+
@override
50+
def _create_content(self, master: Misc):
51+
content_frame = Frame(master)
52+
self.content_text = ScrolledText(content_frame, undo=True, tabs="2c", tabstyle="wordprocessor", maxundo=5)
4753
self.content_text.insert(0.0, DEFAULT_INPUT_CONTENT)
4854
self.content_text.edit_reset()
4955
self.content_text.pack(fill=BOTH, expand=True, padx="7p", pady=0)
5056
text_context_menu = TextContextMenu(self.content_text)
5157
text_context_menu.bind_to_widget()
58+
return content_frame
5259

53-
action_frame = self._create_action_bar(self)
54-
action_frame.pack(fill=X)
55-
56-
def _create_action_bar(self, master: Misc):
60+
@override
61+
def _create_actions(self, master: Misc):
5762
action_frame = Frame(master)
5863
sizegrip = Sizegrip(action_frame)
5964
sizegrip.place(relx=1, rely=1, anchor=SE)

0 commit comments

Comments
 (0)