98 lines
3.5 KiB
Python
98 lines
3.5 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: UTF-8 -*-
|
|
|
|
import wx
|
|
import subprocess
|
|
from util import read_default_dir, store_default_dir
|
|
|
|
defaultSrcDir = ""
|
|
defaultDstDir = ""
|
|
|
|
|
|
def run(srcDir, dstDir, kind, writer):
|
|
proc = subprocess.Popen(['python', 'tran.py', srcDir, dstDir, kind], stdout=subprocess.PIPE)
|
|
for line in iter(proc.stdout.readline, ''):
|
|
print line.rstrip()
|
|
writer(line)
|
|
|
|
|
|
class MainFrame(wx.Frame):
|
|
def __init__(self, *args, **kw):
|
|
super(MainFrame, self).__init__(*args, **kw)
|
|
panel = wx.Panel(self)
|
|
self.childMap = dict()
|
|
|
|
src_dir_text = wx.StaticText(panel, label="源文件夹路径:", pos=(25, 25))
|
|
dst_dir_text = wx.StaticText(panel, label="目的文件夹路径:", pos=(25, 50))
|
|
|
|
src_dir_input = wx.TextCtrl(panel, 0, defaultSrcDir, pos=(120, 22), size=(400, 25))
|
|
dst_dir_input = wx.TextCtrl(panel, 1, defaultDstDir, pos=(120, 48), size=(400, 25))
|
|
self.SaveChildById(0, src_dir_input)
|
|
self.SaveChildById(1, dst_dir_input)
|
|
|
|
src_dir_button = wx.Button(panel, 2, "...", pos=(530, 22), size=(25, 25))
|
|
self.SaveChildById(2, src_dir_button)
|
|
src_dir_button.Bind(wx.EVT_BUTTON, self.Onclicked)
|
|
|
|
dst_dir_button = wx.Button(panel, 3, "...", pos=(530, 48), size=(25, 25))
|
|
self.SaveChildById(3, dst_dir_button)
|
|
dst_dir_button.Bind(wx.EVT_BUTTON, self.Onclicked)
|
|
|
|
export_button = wx.Button(panel, 4, "新格式导表", pos=(25, 85), size=(80, 25))
|
|
old_button = wx.Button(panel, 5, "旧格式导表", pos=(120, 85), size=(80, 25))
|
|
transform_button = wx.Button(panel, 6, "旧格式->新格式", pos=(215, 85), size=(120, 25))
|
|
self.SaveChildById(4, export_button)
|
|
self.SaveChildById(5, old_button)
|
|
self.SaveChildById(6, transform_button)
|
|
export_button.Bind(wx.EVT_BUTTON, self.Onclicked)
|
|
old_button.Bind(wx.EVT_BUTTON, self.Onclicked)
|
|
transform_button.Bind(wx.EVT_BUTTON, self.Onclicked)
|
|
|
|
output_text = wx.TextCtrl(panel, 7, "", pos=(25, 120), size=(800, 600),
|
|
style=wx.TE_CHARWRAP | wx.TE_READONLY | wx.TE_MULTILINE)
|
|
self.SaveChildById(7, output_text)
|
|
|
|
def Onclicked(self, event):
|
|
_id = event.GetEventObject().GetId()
|
|
text = self.GetChildById(7)
|
|
|
|
def writer(message):
|
|
text.AppendText(message)
|
|
if _id == 2: # src_dir_button
|
|
path = self.DirPicker()
|
|
self.GetChildById(0).SetValue(path)
|
|
elif _id == 3: # dst_dir_button
|
|
path = self.DirPicker()
|
|
self.GetChildById(1).SetValue(path)
|
|
elif _id in (4, 5, 6):
|
|
srcDir = self.GetChildById(0).GetValue().encode('utf-8')
|
|
dstDir = self.GetChildById(1).GetValue().encode('utf-8')
|
|
store_default_dir("default_path.txt", srcDir, dstDir)
|
|
kind = ['export', 'oldExport', 'transform'][_id-4]
|
|
run(srcDir, dstDir, kind, writer)
|
|
|
|
def DirPicker(self):
|
|
dialog = wx.DirDialog(self, "Open", ".", wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST)
|
|
dialog.ShowModal()
|
|
path = dialog.GetPath()
|
|
dialog.Destroy()
|
|
return path
|
|
|
|
def GetChildById(self, _id):
|
|
return self.childMap[_id]
|
|
|
|
def SaveChildById(self, _id, child):
|
|
self.childMap[_id] = child
|
|
|
|
|
|
if __name__ == "__main__":
|
|
defaultSrcDir, defaultDstDir = read_default_dir("default_path.txt")
|
|
app = wx.App()
|
|
frame = MainFrame(parent=None, title="hello", size=(840, 780))
|
|
frame.Show()
|
|
app.MainLoop()
|
|
|
|
|
|
|
|
|