-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgui_run.py
More file actions
372 lines (294 loc) · 12.3 KB
/
Copy pathgui_run.py
File metadata and controls
372 lines (294 loc) · 12.3 KB
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# -*- coding: utf-8 -*-
import platform
import time
import wx
import sys, random
import os
# from win32ctypes import win32api
from excel2wordByJiarui import start_switch
APP_TITLE = u'会议文件转换 - MZSWB专用'
APP_ICON = './resources/switch_16.png'
TMP_PATH = "/tmp/template.docx"
ITEM_ICON = "./resources/img.png"
OUTPUT_PATH = "/output"
WILD_CARD = u"Python 文件 (*.py)|*.py|" \
u"编译的 Python 文件 (*.pyc)|*.pyc|" \
u" 垃圾邮件文件 (*.spam)|*.spam|" \
"Egg file (*.egg)|*.egg|" \
"All files (*.*)|*.*"
class mainFrame(wx.Frame):
"""程序主窗口类,继承自wx.Frame"""
id_open = wx.NewIdRef(count=1)
id_save = wx.NewIdRef(count=1)
id_quit = wx.NewIdRef(count=1)
id_help = wx.NewIdRef(count=1)
id_about = wx.NewIdRef(count=1)
def __init__(self, parent):
"""构造函数"""
wx.Frame.__init__(self, parent, -1, APP_TITLE,
style=wx.MAXIMIZE_BOX|wx.MAXIMIZE_BOX)
self.SetBackgroundColour(wx.Colour(250, 250, 250))
self.SetSize((900, 600))
self.SetMaxSize((900, 600))
self.Center()
# if hasattr(sys, "frozen") and getattr(sys, "frozen") == "windows_exe":
# exeName = win32api.GetModuleFileName(win32api.GetModuleHandle(None))
# icon = wx.Icon(exeName, wx.BITMAP_TYPE_ICO)
# else :
# icon = wx.Icon(APP_ICON, wx.BITMAP_TYPE_ICO)
# self.SetIcon(icon)
icon = wx.Icon(APP_ICON, wx.BITMAP_TYPE_PNG)
self.SetIcon(icon)
# self.Maximize()
self.SetWindowStyle(wx.DEFAULT_FRAME_STYLE)
# self._CreateMenuBar() # 菜单栏
# self._CreateToolBar() # 工具栏
self._CreateStatusBar() # 状态栏
b1 = wx.Button(self, -1, u"打开模板", (10, 10))
self.Bind(wx.EVT_BUTTON, self.OnButton1, b1)
b2 = wx.Button(self, -1, u"选择文件", (100, 10))
self.Bind(wx.EVT_BUTTON, self.__OpenSingleFile, b2)
self.__file_label = wx.StaticText(self, label="", style=wx.ALIGN_CENTER_VERTICAL, pos=(185, 12))
self.__file_path = None
b4 = wx.Button(self, -1, u"开始转换", (800, 10))
self.Bind(wx.EVT_BUTTON, self.OnButton4, b4)
# panel = wx.Panel(self)
# my_button = MyButton(self, title="点我", pos=(410, 2))
# b4.SetBackgroundColour("#0288d1") # 设置按钮的背景颜色
# b4.SetForegroundColour("#fff")
b4.SetSize(75, 25)
self.list = wx.ListCtrl(self,
-1,
style=wx.LC_REPORT,
pos=(10, 40),
size=(862, 486)) # 创建列表
self.list.InsertColumn(0, "文件名")
self.list.InsertColumn(1, "创建时间") # 添加表头
self.list.SetColumnWidth(0, 700) # 设置列的宽度
self.list.SetColumnWidth(1, 142)
self.list.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnDclick)
self.list.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnLeftClick)
self.render_list()
def _CreateMenuBar(self):
"""创建菜单栏"""
self.mb = wx.MenuBar()
# 文件菜单
m = wx.Menu()
m.Append(self.id_open, u"打开文件")
m.Append(self.id_save, u"保存文件")
m.AppendSeparator()
m.Append(self.id_quit, u"退出系统")
self.mb.Append(m, u"文件")
self.Bind(wx.EVT_MENU, self.OnOpen, id=self.id_open)
self.Bind(wx.EVT_MENU, self.OnSave, id=self.id_save)
self.Bind(wx.EVT_MENU, self.OnQuit, id=self.id_quit)
# 帮助菜单
m = wx.Menu()
m.Append(self.id_help, u"帮助主题")
m.Append(self.id_about, u"关于...")
self.mb.Append(m, u"帮助")
self.Bind(wx.EVT_MENU, self.OnHelp, id=self.id_help)
self.Bind(wx.EVT_MENU, self.OnAbout, id=self.id_about)
self.SetMenuBar(self.mb)
def _CreateToolBar(self):
"""创建工具栏"""
# bmp_open = wx.Bitmap('open_16.png', wx.BITMAP_TYPE_ANY) # 请自备按钮图片
# bmp_save = wx.Bitmap('save_16.png', wx.BITMAP_TYPE_ANY) # 请自备按钮图片
# bmp_help = wx.Bitmap('help_16.png', wx.BITMAP_TYPE_ANY) # 请自备按钮图片
bmp_about = wx.Bitmap('aboutus.png', wx.BITMAP_TYPE_ANY) # 请自备按钮图片
self.tb = wx.ToolBar(self)
self.tb.SetToolBitmapSize((16, 16))
self.tb.AddTool(self.id_about, u'关于', bmp_about)
# self.Bind(wx.EVT_TOOL_RCLICKED, self.OnOpen, id=self.id_open)
self.tb.Realize()
def _CreateStatusBar(self):
"""创建状态栏"""
self.sb = self.CreateStatusBar()
self.sb.SetFieldsCount(3)
self.sb.SetStatusWidths([-3, 0, -1])
self.sb.SetStatusStyles([wx.SB_RAISED, wx.SB_RAISED, wx.SB_RAISED])
self.sb.SetStatusText(u'V1.0.0', 0)
self.sb.SetStatusText(u'', 1)
self.sb.SetStatusText(u'樱桃智库 15008201329', 2)
def OnOpen(self, evt):
"""打开文件"""
self.sb.SetStatusText(u'打开文件', 1)
def OnSave(self, evt):
"""保存文件"""
self.sb.SetStatusText(u'保存文件', 1)
def OnQuit(self, evt):
"""退出系统"""
self.sb.SetStatusText(u'退出系统', 1)
self.Destroy()
def OnHelp(self, evt):
"""帮助"""
self.sb.SetStatusText(u'帮助', 1)
def OnAbout(self, evt):
"""关于"""
self.sb.SetStatusText(u'成都樱桃智库', 1)
def OnDclick(self, evt):
"""
双击触发事件
:param evt:
:return:
"""
itemText = evt.GetText()
self.sb.SetStatusText(u'正在打开' + itemText, 0)
sys = platform.system()
if sys == "Windows":
print("OS is Windows!!!")
os.startfile(itemText)
elif sys == "Linux":
import subprocess, sys
opener = "open" if sys.platform == "darwin" else "xdg-open"
subprocess.call([opener, itemText])
else:
print("====")
def OnLeftClick(self, evt):
"""
:param evt:
:return:
"""
itemText = evt.GetText()
self.sb.SetStatusText(u'选中' + itemText, 0)
def OnButton1(self, evt):
# path = r'C:\Documents and Settings\liushen\Application Data\Macromedia\Flash Player\#SharedObjects'
# os.startfile(path)
import subprocess, sys
filename = os.getcwd() + TMP_PATH
sys = platform.system()
if sys == "Windows":
print("OS is Windows!!!")
os.startfile(filename)
elif sys == "Linux":
# https://stackoverflow.com/questions/29823028/attributeerror-module-object-has-no-attribute-startfile
opener = "open" if sys.platform == "darwin" else "xdg-open"
subprocess.call([opener, filename])
else:
print("====")
def __OpenSingleFile(self, event):
filesFilter = "Excel (*.xlsx)|*.xlsx|" "Excel (*.xls)|*.xls|" "All files (*.*)|*.*"
fileDialog = wx.FileDialog(self, message="选择单个文件", wildcard=filesFilter, style=wx.FD_OPEN)
dialogResult = fileDialog.ShowModal()
if dialogResult != wx.ID_OK:
return
path = fileDialog.GetPath()
self.__file_path = path
file = fileDialog.GetFilename()
print(os.path.splitext(file))
if os.path.splitext(file)[-1][1:] == "xls" or os.path.splitext(file)[-1][1:] == "xlsx":
self.__file_label.SetLabel(file)
self.sb.SetStatusText(u'准备转换' + path, 0)
self.filename = os.path.splitext(file)[0]
else:
self.__file_label.SetLabel(file)
self.sb.SetStatusText(u'准备转换' + path, 0)
self.filename = None
print(self.filename)
fileDialog.Destroy()
def OnButton4(self, evt):
if self.__file_path is None:
self.sb.SetStatusText("转换文件为空!")
return
if os.path.exists(self.__file_path) is False:
self.sb.SetStatusText("转换文件不存在,请更换!")
return
if self.filename is None:
return
self.sb.SetStatusText("正在转换" + self.__file_path)
if start_switch(self.__file_path, self.filename):
self.sb.SetStatusText("转换完毕" + self.__file_path)
else:
self.sb.SetStatusText(self.__file_path + "转换失败,请检查")
self.__file_label.SetLabel("")
self.render_list()
def render_list(self):
self.list.DeleteAllItems()
path = os.getcwd() + "\output"
g = os.walk(path)
rows_list = []
for path, dir_list, file_list in g:
for file_name in file_list:
t = os.path.getctime(os.path.join(path, file_name))
rows_list.append([os.path.join(path, file_name), TimeStampToTime(t)])
rows_list.reverse()
print(rows_list)
data1 = {
"columns": ['文件名', '创建时间'],
"rows": rows_list
}
image_list = wx.ImageList(16, 16, True)
bmp = wx.Bitmap(ITEM_ICON, wx.BITMAP_TYPE_PNG)
il_max = image_list.Add(bmp)
# 添加图标
self.list.AssignImageList(image_list, wx.IMAGE_LIST_SMALL)
data = Dict(data1)
for index, item in enumerate(data.rows): # 增加行
# index = self.list.InsertItem(sys.maxsize, item[0])
index = self.list.InsertItem(index, item[0])
for col, text in enumerate(item[1:]):
self.list.SetItem(index, col + 1, text)
# give each item a random image
img = random.randint(0, il_max)
self.list.SetItemImage(index, img, img)
class mainApp(wx.App):
def OnInit(self):
self.SetAppName(APP_TITLE)
self.Frame = mainFrame(None)
self.Frame.Show()
return True
class Dict(dict):
__setattr__ = dict.__setitem__
__getattr__ = dict.__getitem__
class BlockWindow(wx.Panel):
def __init__(self, parent, ID=-1, label="", pos=wx.DefaultPosition, size=(100, 25)):
wx.Panel.__init__(self, parent, ID, pos, size, wx.RAISED_BORDER, label)
self.label = label
self.SetBackgroundColour("white")
self.SetMinSize(size)
self.Bind(wx.EVT_PAINT, self.OnPaint)
def OnPaint(self, evt):
sz = self.GetClientSize()
dc = wx.PaintDC(self)
w, h = dc.GetTextExtent(self.label)
dc.SetFont(self.GetFont())
dc.DrawText(self.label, (sz.width - w) / 2, (sz.height - h) / 2)
def TimeStampToTime(timestamp):
"""
把时间戳转化为时间: 1479264792 to 2016-11-16 10:53:12
:param timestamp:
:return:
"""
timeStruct = time.localtime(timestamp)
return time.strftime('%Y-%m-%d %H:%M:%S', timeStruct)
class MyButton(wx.Button, wx.EvtHandler):
"""自定义按钮"""
def __init__(self, parent, title, pos, size=(60, 35), borderColor='#EAEAEA', borderSize=1):
self.button, self.border = self.__CreateButton(parent, title, pos, size, borderColor, borderSize)
def __CreateButton(self, parent, title, pos, size, borderColor, borderSize):
"""创建自定义按钮"""
border = wx.StaticText(parent, -1, '', pos=pos, size=size)
border.SetBackgroundColour(borderColor)
# 设置按钮在border上的位置,使其刚好露出borderSize大小的边框
button = wx.Button(border, -1, title, size=((size[0] - borderSize * 2), (size[1] - borderSize * 2)),
pos=(borderSize, borderSize), style=wx.NO_BORDER)
button.SetBackgroundColour('white')
button.SetForegroundColour('black')
return button, border
def SetForegroundColour(self, colour):
self.button.SetForegroundColour(colour)
self.button.Refresh()
def SetBackgroundColour(self, colour):
self.button.SetBackgroundColour(colour)
def SetBorderColour(self, colour):
self.border.SetBackgroundColour(colour)
self.border.Refresh()
def Disable(self):
self.button.Disable()
def Enable(self, enable=True):
self.button.Enable(enable)
def Bind(self, event, handler, source=None, id=wx.ID_ANY, id2=wx.ID_ANY):
self.button.Bind(event, handler)
if __name__ == "__main__":
app = mainApp()
app.MainLoop()