-
Notifications
You must be signed in to change notification settings - Fork 0
/
facility.py
246 lines (209 loc) · 8.01 KB
/
facility.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#-------------------------------------------------------------------------------
# Name: Minitools
# Purpose: Minitools.
#
# Author: Ekira
#
# Created: 09/02/2017
# Modified: 12/10/2018
# Copyright: (C) Ekira 2017
# Licence: <GNU Lesser General Public License>
#-------------------------------------------------------------------------------
# -*- coding: utf-8 -*- #
import wx, os, _thread, json, sys, urllib
from urllib import request
import subprocess
import pswgen_gui
import idnum_gui
import xls2csv_gui
import csv2xlsx_gui
import gbk2utf_gui
import watermark_gui
G_APP_NAME = "facility"
G_VERSION = "0.0.4"
G_UPDATE_URL = "http://www.xxiong.me/facility/"
G_HOME_PATH = os.path.join(os.path.expanduser('~'), ".facility")
G_CONFIG_PATH = os.path.join(G_HOME_PATH, "facility.json")
G_LOG_PATH = os.path.join(G_HOME_PATH, "facility.log")
class MainWindow(wx.App):
def __init__(self):
self.HOME_PATH = G_HOME_PATH
self.APP_NAME = G_APP_NAME
self.VERSION = G_VERSION
self.UPDATE_URL = G_UPDATE_URL
if not os.path.isdir(self.HOME_PATH):
os.mkdir(self.HOME_PATH)
try:
_thread.start_new_thread(self.check_update, ())
except:
pass
wx.App.__init__(self)
def check_update(self):
apppath = os.path.abspath(sys.argv[0])
appname = os.path.split(apppath)[-1]
updateurl = os.path.join(G_UPDATE_URL, "update")
data = json.loads(request.urlopen(updateurl).read())
config_path = G_CONFIG_PATH
config = dict()
if os.path.exists(config_path):
with open(config_path, 'r') as f:
config = json.load(f)
config["facility"]["version"] = G_VERSION
config["facility"]["name"] = appname
config["facility"]["path"] = apppath
else:
config = {
"facility": {
"version": G_VERSION,
"name": appname,
"path": apppath
},
"latest_facility": {
"version": G_VERSION,
"name": appname,
"path": apppath
}
}
## 检查预更新版本是否为最新
remote_latest = data["latest"]
if remote_latest["version"] > config["latest_facility"]["version"]:
_url = os.path.join(G_UPDATE_URL, remote_latest["name"])
_localpath = os.path.join(G_HOME_PATH, remote_latest["name"])
urllib.request.urlretrieve(_url, _localpath)
config["latest_facility"]["version"] = remote_latest["version"]
config["latest_facility"]["name"] = remote_latest["name"]
config["latest_facility"]["path"] = _localpath
with open(config_path, 'w') as f:
json.dump(config, f)
## 检查是否更新到最新版本
if config["latest_facility"]["version"] > config["facility"]["version"]:
self.updateButton.SetLabel("有新版本,点击更新")
self.updateButton.Enable(True)
else:
self.updateButton.SetLabel("当前已是最新版本")
self.config = config
def OnInit(self):
framestyle=wx.MINIMIZE_BOX|wx.SYSTEM_MENU|wx.CAPTION|wx.CLOSE_BOX|wx.CLIP_CHILDREN
app_title = "%s-v%s" % (self.APP_NAME, self.VERSION)
frame = wx.Frame(parent=None, title=app_title, size=(600,400), style=framestyle)
frame.SetFont(wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
bg = wx.Panel(frame)
xls2csvButton = wx.Button(bg, label="xls(x) 转 csv")
csv2xlsButton = wx.Button(bg, label="csv 转 xlsx")
gbk2utfButton = wx.Button(bg, label="gbk <=> utf-8")
passwdgenButton = wx.Button(bg, label="随机密码生成器")
chsidgenButton = wx.Button(bg, label="身份证号码生成器")
watermarkButton = wx.Button(bg, label="批量图片嵌水印")
updateButton = wx.Button(bg, label="正在检查更新...")
updateButton.Enable(False)
grid = wx.GridSizer(rows=6, cols=3, vgap=10, hgap=5)
grid.AddMany([
(xls2csvButton,0,wx.EXPAND),
(csv2xlsButton,0,wx.EXPAND),
(gbk2utfButton,0,wx.EXPAND),
(passwdgenButton,0,wx.EXPAND),
(chsidgenButton,0,wx.EXPAND),
(watermarkButton,0,wx.EXPAND),
(updateButton,0,wx.EXPAND),
])
bg.SetSizer(grid)
self.bg = bg
self.frame = frame
self.xls2csvButton = xls2csvButton
self.csv2xlsButton = csv2xlsButton
self.gbk2utfButton = gbk2utfButton
self.passwdgenButton = passwdgenButton
self.chsidgenButton = chsidgenButton
self.watermarkButton = watermarkButton
self.updateButton = updateButton
self.Bind(wx.EVT_BUTTON, self.OnXls2csvButton, xls2csvButton)
self.Bind(wx.EVT_BUTTON, self.OnCsv2xlsButton, csv2xlsButton)
self.Bind(wx.EVT_BUTTON, self.OnGbk2utfButton, gbk2utfButton)
self.Bind(wx.EVT_BUTTON, self.OnPasswdgenButton, passwdgenButton)
self.Bind(wx.EVT_BUTTON, self.OnChsidgenButton, chsidgenButton)
self.Bind(wx.EVT_BUTTON, self.OnWatermarkButton, watermarkButton)
self.Bind(wx.EVT_BUTTON, self.OnUpdateButton, updateButton)
frame.Show()
return True
def OnXls2csvButton(self, event):
try:
dlg = xls2csv_gui.Xls2CsvWindow(self.bg, "xls(x) 转 csv", (500,400))
self.frame.Show(False)
dlg.ShowModal()
dlg.Destroy()
finally:
dlg.Destroy()
self.frame.Show(True)
return
def OnCsv2xlsButton(self, event):
try:
dlg = csv2xlsx_gui.Csv2XlsWindow(self.bg, "csv 转 xlsx", (500,400))
self.frame.Show(False)
dlg.ShowModal()
dlg.Destroy()
finally:
dlg.Destroy()
self.frame.Show(True)
return
def OnGbk2utfButton(self, event):
try:
dlg = gbk2utf_gui.Gbk2UtfWindow(self.bg, "gbk <=> utf-8", (500,400))
self.frame.Show(False)
dlg.ShowModal()
dlg.Destroy()
finally:
dlg.Destroy()
self.frame.Show(True)
return
def OnPasswdgenButton(self, event):
try:
dlg = pswgen_gui.PswGenWindow(self.bg, "随机密码生成器", (430,300))
self.frame.Show(False)
dlg.ShowModal()
dlg.Destroy()
finally:
dlg.Destroy()
self.frame.Show(True)
return
def OnChsidgenButton(self, event):
try:
dlg = idnum_gui.IdNumWindow(self.bg, "身份证号码生成器", (430,300))
self.frame.Show(False)
dlg.ShowModal()
dlg.Destroy()
finally:
dlg.Destroy()
self.frame.Show(True)
return
def OnWatermarkButton(self, event):
try:
dlg = watermark_gui.WatermarkWindow(self.bg, "批量图片嵌水印", (600,500))
self.frame.Show(False)
dlg.ShowModal()
dlg.Destroy()
except Exception as e:
print(e)
finally:
dlg.Destroy()
self.frame.Show(True)
return
def OnUpdateButton(self, event):
try:
config = self.config
cmdpath = os.path.join(G_HOME_PATH, "update.bat")
with open(cmdpath, "w") as f:
f.write("ping 127.0.0.1 -n 2 >nul\n")
f.write("copy /Y %s %s >nul\n" % (config["latest_facility"]["path"], config["facility"]["path"]))
f.write("start %s >nul\n" % config["facility"]["path"])
f.write("exit\n")
subprocess.Popen("start " + cmdpath, shell=True)
except Exception as e:
print(e)
with open(G_LOG_PATH, "at") as f:
f.write(str(e))
wx.Exit()
def main():
app = MainWindow()
app.MainLoop()
if __name__ == '__main__':
main()