Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b09ec59

Browse files
committedApr 5, 2020
update
1 parent 7ed0e5d commit b09ec59

File tree

4 files changed

+63
-26
lines changed

4 files changed

+63
-26
lines changed
 

‎src/build.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
BLOCK_CIPHER = None
44
APP_NAME = 'Pythub'
55
APP_APP = 'Pythub.app'
6-
APP_VERSION = '0.0.2'
6+
APP_VERSION = '0.0.3'
77
SCRIPTS = ['pythub.py']
88
BINARIES = []
99
DATAS = []

‎src/pythub.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,17 @@
1111
class App(View):
1212
def __init__(self, master=None):
1313
super(App, self).__init__()
14-
master.title('Pythub')
15-
master.resizable(False, False)
1614

1715
def fn_build(self):
1816
'''生成可执行文件'''
1917
if not self.status_build:
20-
thread_build = Thread(target=self.thread)
18+
thread_build = Thread(target=self.fn_thread)
2119
thread_build.setDaemon(True)
2220
thread_build.start()
2321
else:
2422
self.label_status['text'] = '正在打包,请稍后再操作!'
2523

26-
def thread(self):
24+
def fn_thread(self):
2725
'''线程执行生成动作'''
2826
if len(self.entry_value_list[0].get()) == 0:
2927
self.label_status['text'] = '请选择源文件'
@@ -41,5 +39,7 @@ def thread(self):
4139

4240
if __name__ == '__main__':
4341
root = Tk()
42+
root.title('Pythub')
4443
App(root)
44+
set_window_center(root)
4545
root.mainloop()

‎src/utils.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,38 @@
22
# utils functions
33

44

5-
def set_window_center(window, width, height):
5+
def set_window_center(window, width=None, height=None, minsize=True, resize=False):
66
"""设置窗口宽高及居中"""
7-
# 获取屏幕 宽、高
7+
# 获取窗口宽高
8+
if width == None or height == None:
9+
# 宽高为 None 时取窗口自身大小
10+
window.update_idletasks() # 更新
11+
window.withdraw() # 隐藏重绘
12+
# window.update() # 获取窗口宽高之前需要先刷新窗口
13+
if width is None:
14+
width = window.winfo_width()
15+
if height is None:
16+
height = window.winfo_height()
17+
18+
# 获取屏幕宽高
819
w_s = window.winfo_screenwidth()
920
h_s = window.winfo_screenheight()
21+
1022
# 计算 x, y 位置
1123
x_co = (w_s - width) / 2
12-
y_co = (h_s - height) / 2 - 50
24+
y_co = (h_s - height) / 2
25+
26+
# 设置窗口宽高和居中定位
1327
window.geometry("%dx%d+%d+%d" % (width, height, x_co, y_co))
14-
window.minsize(width, height)
28+
window.deiconify() # 显示
29+
# 是否设置窗口最小尺寸
30+
if minsize:
31+
window.minsize(width, height)
32+
# 是否可调整大小
33+
if resize:
34+
window.resizable(True, True)
35+
else:
36+
window.resizable(False, False)
1537

1638

1739
def get_screen_size(window):
@@ -21,7 +43,8 @@ def get_screen_size(window):
2143

2244
def get_window_size(window):
2345
"""获取窗口 宽、高"""
24-
return window.winfo_reqwidth(), window.winfo_reqheight()
46+
window.update()
47+
return window.winfo_width(), window.winfo_height()
2548

2649

2750
def treeview_sort_column(tv, col, reverse):

‎src/view.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
import os.path
44
from tkinter import (Button, Checkbutton, Entry, IntVar, Label, LabelFrame, StringVar, filedialog)
55

6-
from utils import set_window_center
7-
86

97
class View(object):
108
def __init__(self, master=None):
119
self.root = master
1210
self.status_build = False
13-
self.init_frame()
11+
self.init_view()
1412

15-
def init_frame(self):
13+
def init_view(self):
1614
'''基本框架'''
1715
self.frm_project = LabelFrame(self.root, text='项目')
1816
self.frm_config = LabelFrame(self.root, text='配置')
@@ -65,11 +63,11 @@ def init_project(self):
6563

6664
def init_config(self):
6765
'''配置选项'''
68-
# 定义变量
69-
self.cfg_onefile = IntVar()
70-
self.cfg_onedir = IntVar()
71-
self.cfg_noconsole = IntVar()
72-
self.cfg_clean = IntVar()
66+
# 定义变量,并初始化
67+
self.cfg_onefile = IntVar(value=1)
68+
self.cfg_onedir = IntVar(value=0)
69+
self.cfg_noconsole = IntVar(value=1)
70+
self.cfg_clean = IntVar(value=1)
7371
self.cfg_rename = IntVar()
7472
self.cfg_exe_name = StringVar()
7573
# 子配置框架
@@ -88,25 +86,35 @@ def init_config(self):
8886
self.btn_clean = Checkbutton(
8987
self.frm_config_base, text='构建前清理', variable=self.cfg_clean)
9088
self.btn_isonefile = Checkbutton(
91-
self.frm_config_exe, text='单个执行文件', variable=self.cfg_onefile)
89+
self.frm_config_exe, text='独立执行文件', variable=self.cfg_onefile)
9290
self.btn_isonedir = Checkbutton(
93-
self.frm_config_exe, text='文件夹包', variable=self.cfg_onedir)
91+
self.frm_config_exe, text='文件夹包含', variable=self.cfg_onedir)
9492
self.btn_rename = Checkbutton(
9593
self.frm_config_other, text='修改执行文件名', variable=self.cfg_rename)
9694
self.entry_rename = Entry(
9795
self.frm_config_other, textvariable=self.cfg_exe_name)
96+
9897
# 放置按钮
9998
self.btn_isonefile.pack(side='left', fill='x')
10099
self.btn_isonedir.pack(side='left', fill='x')
101100
self.btn_noconsole.pack(side='left', fill='x')
102101
self.btn_clean.pack(side='left', fill='x')
103102
self.btn_rename.pack(side='left', fill='x')
104103
self.entry_rename.pack(fill='x')
105-
# 初始化默认值
106-
self.cfg_onefile.set(1)
107-
self.cfg_onedir.set(0)
108-
self.cfg_noconsole.set(1)
109-
self.cfg_clean.set(1)
104+
105+
# 变量自动切换操作
106+
self.cfg_onefile.trace('w', self.cfg_onefile_trace)
107+
self.cfg_onedir.trace('w', self.cfg_onedir_trace)
108+
109+
def cfg_onefile_trace(self, *args):
110+
'''cfg_onefile 与 cfg_onedir 可以同时不选,但不能同时选中,选中独立执行文件时不能选中文件夹包'''
111+
if self.cfg_onefile.get() == 1:
112+
self.cfg_onedir.set(0)
113+
114+
def cfg_onedir_trace(self, *args):
115+
'''cfg_onefile 与 cfg_onedir 可以同时不选,但不能同时选中,选中文件夹包含时不能选中独立执行文件'''
116+
if self.cfg_onedir.get() == 1:
117+
self.cfg_onefile.set(0)
110118

111119
def init_operate(self):
112120
'''操作命令'''
@@ -224,3 +232,9 @@ def fn_build_cmd(self):
224232
cmds.append(self.entry_value_list[0].get())
225233

226234
return ' '.join(cmds)
235+
236+
if __name__ == '__main__':
237+
from tkinter import Tk
238+
root = Tk()
239+
View(root)
240+
root.mainloop()

0 commit comments

Comments
 (0)
Please sign in to comment.