#!/usr/bin/python
#-*-coding:utf-8-*-
import wx
import os
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import wx
ID_BROWSE_1 = wx.NewId()
ID_BROWSE_2 = wx.NewId()
ID_BROWSE_3 = wx.NewId()
ID_BEGIN_RUN = wx.NewId()
class Example(wx.Frame):
def __init__(self,parent,title):
super(Example,self).__init__(parent,title=title,size=(550,350))
self.file1 = ''
self.file2 = ''
self.file3 = ''
self.InitUI()
self.Centre()
self.Show()
def InitUI(self):
panel = wx.Panel(self)
sizer = wx.GridBagSizer(5,5)
text1 = wx.StaticText(panel,label=u"UDN9813 ")
font=wx.Font(18,wx.DECORATIVE,wx.NORMAL, wx.BOLD)
text1.SetFont(font)
sizer.Add(text1, pos=(0,2.5),flag=wx.TOP|wx.CENTER|wx.BOTTOM,border=15)
#icon = wx.StaticBitmap(panel,bitmap=wx.Bitmap("exit.png"))
#sizer.Add(icon,pos=(0,4),flag=wx.TOP|wx.RIGHT|wx.ALIGN_RIGHT,border=5)
line = wx.StaticLine(panel)
sizer.Add(line,pos=(1,0),span=(1,5),flag=wx.EXPAND|wx.BOTTOM,border=10)
text2 = wx.StaticText(panel,label=u"1. ")
sizer.Add(text2,pos=(2,0),flag=wx.LEFT|wx.TOP,border=10)
self.tc1 = wx.TextCtrl(panel)
sizer.Add(self.tc1,pos=(2,1),span=(1,3),flag=wx.TOP|wx.EXPAND, border=5)
button0 = wx.Button(panel, ID_BROWSE_1, label="Browse...")
sizer.Add(button0, pos=(2, 4), flag=wx.TOP|wx.RIGHT, border=5)
text3 = wx.StaticText(panel, label=u"2. ")
sizer.Add(text3, pos=(3, 0), flag=wx.LEFT|wx.TOP, border=10)
self.tc2 = wx.TextCtrl(panel)
sizer.Add(self.tc2, pos=(3, 1), span=(1, 3), flag=wx.TOP|wx.EXPAND, border=5)
button1 = wx.Button(panel, ID_BROWSE_2, label="Browse...")
sizer.Add(button1, pos=(3, 4), flag=wx.TOP|wx.RIGHT, border=5)
text4 = wx.StaticText(panel, label=u"3. ")
sizer.Add(text4, pos=(4, 0), flag=wx.TOP|wx.LEFT, border=10)
self.tc3 = wx.TextCtrl(panel)
sizer.Add(self.tc3, pos=(4, 1), span=(1, 3), flag=wx.TOP|wx.EXPAND, border=5)
button2 = wx.Button(panel, ID_BROWSE_3, label="Browse...")
#dir = wx.FilePickerCtrl( panel, wx.ID_ANY, wx.EmptyString, u" ", u".bat")
sizer.Add(button2, pos=(4, 4), flag=wx.TOP|wx.RIGHT, border=5)
button4 = wx.Button(panel, ID_BEGIN_RUN, label=u" ")
sizer.Add(button4, pos = (6, 4))
lambda evt, mark=1 : self.OnOpenFile(evt,mark)
#self.Bind(wx.EVT_MENU, lambda evt, mark=i : self.OnMenusClick(evt,mark) ,btn )
self.Bind(wx.EVT_BUTTON, lambda evt, mark=1 : self.OnOpenFile(evt,mark) ,id = ID_BROWSE_1 )
self.Bind(wx.EVT_BUTTON, lambda evt, mark=2 : self.OnOpenFile(evt,mark) ,id = ID_BROWSE_2 )
self.Bind(wx.EVT_BUTTON, lambda evt, mark=3 : self.OnOpenFile(evt,mark) ,id = ID_BROWSE_3 )
#self.Bind(wx.EVT_BUTTON, self.OnOpenFile, id = ID_BROWSE_1)
#self.Bind(wx.EVT_BUTTON, self.OnBeginRun, id = ID_BROWSE_2)
#self.Bind(wx.EVT_BUTTON, self.OnBeginRun, id = ID_BROWSE_3)
self.Bind(wx.EVT_BUTTON, self.OnBeginRun, id = ID_BEGIN_RUN)
sizer.AddGrowableCol(2)
panel.SetSizer(sizer)
def OnBeginRun(self, event):
str1 = self.tc1.GetValue()
str2 = self.tc2.GetValue()
str3 = self.tc3.GetValue()
print str1, str2, str3
self.Close()
def OnOpenFile(self, event, mark):
file_wildcard = "All files(*.*)|*.*"
dlg = wx.FileDialog(self, "Open paint file...",
os.getcwd(),
style = wx.OPEN,
wildcard = file_wildcard)
if dlg.ShowModal() == wx.ID_OK:
filename = dlg.GetPath()
dlg.Destroy()
if mark == 1:
self.file1 = filename
self.tc1.SetValue(filename)
elif mark == 2:
self.file2 = filename
self.tc2.SetValue(filename)
else:
self.file3 = filename
self.tc3.SetValue(filename)
if __name__ == '__main__':
app = wx.App()
Example(None,title=u" ")
app.MainLoop()