├── README.md ├── demo ├── AllControls.py ├── AnalogClock.py ├── BitmapButton.py ├── CalendarCtrl.py ├── ContextMenu.py ├── ControlDemo.py ├── DirectoryDialog.py ├── DragFrame.py ├── Execute.py ├── FileBrowser.py ├── FileDialog.py ├── Gauge.py ├── IdleEvent.py ├── Layout.py ├── LedNumber.py ├── ListCtrl.py ├── MediaCtrl.py ├── MenuBar.py ├── MultiSplitWindow.py ├── NoFrame.py ├── Notebook.py ├── PdfView.py ├── PickerCtrl.py ├── PopupWindow.py ├── ProgressDialog.py ├── ProgressIndicator.py ├── SimpleFrame.py ├── Simplebook.py ├── SplitWindow.py ├── StatusBar.py ├── StyledTextCtrlDemo.py ├── TextCtrl.py ├── TextEntryDialog.py ├── Thread.py ├── Ticker.py ├── TimerEvent.py ├── ToolbarText.py ├── TreeCtrl.py ├── TreeCtrlDynamic.py └── Web.py ├── example ├── FtpServer.py ├── IconMaker.py └── VideoPlayer.py └── src └── ezWxPython.py /README.md: -------------------------------------------------------------------------------- 1 | 2 | # ezWxPython 3 | 4 | ezWxPython is inspired by the pySimpleGUI project and is a wrapper project that makes it easy to create a wxPython Application. It is built on an event driven approach while pySimpleGUI is based on message driven. 5 | 6 | Since the ordered dict used in menubar generation is supported from python 3.6, you have to use with phtyon 3.6+ if you want to use menubar. 7 | 8 | ## Example Application 9 | 10 | Full source : /demo/BasicForm.py 11 | 12 | ```python 13 | import ezWxPython as ezwx 14 | 15 | ###################################################################### 16 | # Layout 17 | ###################################################################### 18 | 19 | exit_png='eJwBZgWZ+olQTkcNChoKAAAADUlIRFIAAAAgAAAAIAgGAAAAc3p69AAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAUISURBVHjavFfdaxxVFP/de/cj28221hpBTIlNX6qQ9EUNQg1RKKYsfRBfFIL2oeC70AdBfPBJqIr/QLHEKMWH+hFrsxQCarVfVNFEDNU0pGlTTGJTapO4M3Pv9Zw7dze7ss3OImaTk8nOzL3nN7/zOx8DbO5HTF/4srg690P0wZF+S98zqc1yfKn04a5HdnZ+KmF6RSoNJSSfz8tNcK7mfyp9sru7a3pt6bfeubPHYKIIQgi+lm7GQOqjNwY/y2VkUdICkdCjsRZBEKC7Zx+6HnsK4eot3Jj4DtHqMkDXjDVQKn72ZgBy2ZQovnVqjYJFABIiMMZi5e8Alw/tw7Wfx3F3aRZCkisya0JYTQzIZADaRIwCbXRnKwCsTeP69yNYKxtax27IIT05/cIQAOU3awZACCvA9DNgmRAAB0spBUuLjOCQwFEPG4dH67CiASTIAgtJ8WoFAH/4fnZGzxwDAHz86XwUuj0TARBGgu+V0iYHQPcRAUQ3h8K6h68AsJ6BSggapWHm4Huwzx3FSQYoNYdAEWWyZdMEwGjrNFFnTUSY1ySU/l14/q83sSLKyqFVxEBSEXKsJdFlbQMG6EeHodPVvRhIBxp4oe91PNuLobHCOSibpQUp2lS2YMrlu9OBN81HzgIqRKqGgXTxHSyGGtvcRUK7VqYjchjsfREldQK/L38DOzkAmQkJsk4iAacZ7fczLgEEOSdWSFORC8F6FuTZ+fFXj+FW+XOunLSQbrD3Y2L+BA70vgyZHsZ5+TXUL8/QxgHtbhKEwMYiNHEI2Hn3QzPo2DqPuWiw0gscgAw/+Z3yAr698sV6uRWj5BiY/GMYgz2HKG2O46IcR9vUAO0exV42AMBZoI1xT6+tcNQ/eN8ShkuPYqCoqwxUNbCi5ykYcCYyZHwkeJY2uvLnx3hizx5EnTfdSady2cxUjQh9LSCf+VwaJgycTqpZwFhW7Q2oLKoMWFNTUFIBLk1PITPf6WoCmD5hNy5EwhciW9GBcSxsyaYRUiHyEYgZ4E1DdRPZPMVjC5GQowuZ2FJtwOwicKHURfTvJwKotis4CpuZ9nlvybMlAAu3d+DAkz9SIYrqNMAA7h4dPtfOCFkwlCV45aU4ylevA5fHulC4uh8yG3jIsqkIlRJx57PC7UkqwNS1nTh9Po++p8t1zSg4dQT9dNzuo5EefBunmYVfp4HF8Q4Upkm1GcpNaZs7r4ZA1IXAoaLd2/OpuBn5XsB/V8hmyCbJJvh/VvDMHFA6ia8Glh6HzRrOzgTCWzcWmTE1qegtT609IhHW9gKqLrhNtuBtmQSMM6M4e/F9vKup8PB3qURrlZCewpj6SsiWSVGPoBhLee92HI6+hr3+/yiSsWJ5QeJmyIXINugFflxjBnIbNCMOySzfS1bQdHC0CosWehFpQLrarxsACHWw4TwQeHMzIS9WFANmTMAmHQcotipuxdrWrXL9hhgQqYQTEeewiz9EawxwA+IZ0P4LNjMQUh3ItzCSudLr+plNPBJxCOIuiPWRzI+GJipTWHPJAKRFRG8PirOwhfcCXhfrJpaSqILgg2OgRoSZoaGhcsONaOHYMqt6yX9LHgJtJc7MFLAjF6GzECKfMoiHY86CcnUicgPJyMjIbp4LGhHgz2f+6/vZA9tyucPFnoMPd7T3bS9gb6UbCr953jv7315O/f7tZFvJqOXhDlddgc37KP+wWQ+Gp5qVfwQYAOMRch38qZCKAAAAAElFTkSuQmCCWbl5kg==' 20 | save_png="eJyVVH1MG2UYPyhjjJWvhOgkQY5Dp9nW3l2/e6Urd70eNK4dKSXUMEOP9kpvbe9ud1daiBFly3RmH0TjmAnJNjRRM2ec0T8WTEAxOuIfw49E58KoJJqpW0A0jmWVecUWiTEkvsm97/s87+/3fL7vHWv3tlaU15UDAFDhbiN9ygrmvrJSZZYGB39XlodkV0Du4CNyihYZAA/zvQzoTtB9jI+hwwOHZphmAFBdZP0BOeDZh4X4hJbOYbTphADkRrMjLdChGCODvUwfy9mhxYlJCGTDdqjL6EE8gpOJsm2DItMx6PWHBmMhaxhy7AWb05hiIMHINJhOxDkJS9uhNbuYss+pYQhcg8gxO/R3UAFPO+jkRQY0ahFNCDEhoAnVonqD2WzeA+oQFIERHYzqNKgZ0+swBAHzA1K8ieEI5iOpvC9FskNRWRYwGE6lUtqUXsuLfTBqtVpzNnQ6jYLQSAOcTKc1nNRUsEAyUkhkBZnlOTAn0718UrZDUCGFhOBj+6KytG6ck/LFUsoGp2kBRrUILK5h4A0sj2dzRiKxjpZkHxPZHC35BwQG9jESnxRDShcjTRtcbU7NAfM5YB5ajDFKFyk6LjFrBx4Ptl8JnuXoOMmHkgmGk92kHUom2TCGu/SUwYRYLJTFSrpQFLeYEKuVQnUorkMMOmvBwEaiotGGFa6FxC0oSZkIo4tCURdC4LieIFwG0kygeiNKFrhuTpJpLsQUuOw/XOOmXMwpMrTMi36ejxduU3uUl3kpygugs8MIdrFcmE9JuUbn42REtp8JUyKfANdqjrH/4V2vcxFWg4F0UYp/BEWtOGHAKdKK6K2U3ugioDw3/L/LBSuRwP+6cwWVcpFz2/UXpAjrb5DhlJaJygubCe63AUDRhJvE/enverP37zumW4o/xX949ugHfb/gtfW3EtEyE1eCBmYfne184O6O9nj3/Ont6sCtj34G1EtVO4jdp27svL4sxDo/XH68cuXqUsMFFXHRf6UfaHOYpEu2jCNBAD1YqwScrl7Zqi56opwA3mzo8YbwO5pIGYLsscmH41vJa2zQOHqzeuW3xQbnmRN11yqBnx7bW7JK78pur+1+OqMoXkjOfnxQu61x6Wzjl96Xh6vPIRXZLaXfZ+dGr/S3jF94+FcWiNUCxs8u33zpNjDyzPhrmYaTccuhafd79SMNQe+TZQeGsicbq6Jll4HXzx6pXnn+fCbzSmtw3+4WpCRaUfqq6l2y6Kn6pZShfJU+NTzDasPdI7ZYlS6lr763IE8tTg5dGo3UHlFr9UpSV3vGOnepw575Y5BZ81X9pGp15EfgOFhsyywOjZVCn9cIU5H4F1PDB791OITrtRVZopw6VzcmBpxV52+MButWVOjxmrmaydWss+twZ+WEqv3rewsnih/5ZtyycGd+yOLMKPMnRwF0S82LvSNNpucO/PngW5irY3pptGV+Gf7j7TnEYntDVQQUq4Hbxp13z7zPbMv9Zd0uL/kOERz+C2G1BH0=" 21 | 22 | menu_def = { 23 | "File" : { 24 | "Option" : { 25 | "Settings" : None, # Disabled menu item 26 | "Copy": onCopy 27 | }, 28 | "-" : None, # Menu separator 29 | "Exit" : [onExit, exit_png], # Menu item with base64-encoded icon image 30 | "-2" : None, # Menu separator (should have different name from other menu separator) 31 | }, 32 | "Help" : { 33 | "About" : onAbout 34 | }, 35 | } 36 | 37 | tool_def = [ #icon, text, handler 38 | [exit_png, onExit, "Exit" ], 39 | [None], # Tool separator 40 | [save_png, None, "Save", ], # Disabled toolbar item 41 | ] 42 | 43 | status_def = [ 44 | ["Ready", -6], # width will have space with proportion 6 45 | ["Status", -4], # width will have space with proportion 4 46 | ["Code:1", 20] # fixed width 47 | ] 48 | 49 | body_def = [ 50 | [ ezwx.Label ("Folder: "), 51 | ezwx.Text ("Default Text",key="folder",expand=True,password=True,proportion=1), 52 | ezwx.Button("Folder", handler=onBrowse, key="browse"), 53 | ezwx.Button("Files", handler=onFileBrowse, key="file_browse" ), ], 54 | [ ezwx.Check("Check1", handler=onCheck, key='check1'), 55 | ezwx.Check("Check2", key='check2'), 56 | ezwx.Link("Google", "https://www.google.com"), ], 57 | [ ezwx.Label ("Choices: "), ezwx.Choice(['apple','orange','grape'],0,handler=onChoice,key="choice"), 58 | ezwx.Label (" ComboBox: "), ezwx.Combo (['apple','orange','grape'],"orange",handler=onCombo,key="combo"), 59 | ezwx.Label (" Date: "), ezwx.Date (key='date'), 60 | ezwx.Label (" Time: "), ezwx.Time (key='time'), ], 61 | [ ezwx.List (['apple','orange','grape'],2,expand=True,proportion=0,handler=onList,key="list"), 62 | ezwx.List (['apple','orange','grape'],2,expand=True,proportion=0,handler=onCheckList,check=True,key="checklist"), 63 | ezwx.Scroll( [ 64 | [ezwx.Radio("Group",["Item1","item2","item3"],"item2",handler=onRadio,key='radio')], 65 | [ezwx.Button("1")],[ezwx.Button("2")],[ezwx.Button("3")],[ezwx.Button("4")], 66 | [ezwx.Button("5")],[ezwx.Button("6")],[ezwx.Button("7")],[ezwx.Button("8")], 67 | [ezwx.Button("9")],[ezwx.Button("10")], 68 | ], expand=True, proportion=1), 69 | ezwx.Notebook([ 70 | [ 71 | "StyledText", 72 | [ ezwx.StyledText ("Default\nMulti Line\nText",expand=True,proportion=1,key="stc"), 73 | { 'expand' : True, 'proportion' : 1 } ], 74 | ], 75 | [ 76 | "Text", 77 | [ ezwx.Text ("Default\nMulti Line\nText",expand=True,proportion=1,multiline=True,key="text"), 78 | { 'expand' : True, 'proportion' : 1 } ], 79 | ], 80 | ], expand=True, proportion=2), 81 | ezwx.List([[('Name',100,-1),('Sex',32,0),('Age',64,1)], #label, width, align 82 | ["Willy","M","32"], 83 | ["Jane","F","28"], 84 | ], expand=True, proportion=2, multicol=True), 85 | ezwx.List(expand=False,proportion=1,label="Editable List", edit=True,key='editlist'), 86 | { 'proportion' : 1 } 87 | ], 88 | [ ezwx.Panel([ 89 | [ ezwx.Button("A"), ezwx.Button("B")], 90 | [ ezwx.Ticker("This is a ticker example text", expand=True, proportion=1, key='ticker')], 91 | [ ezwx.Line(expand=True, proportion=1)], 92 | [ ezwx.Slider(value=20,expand=True, proportion=1, key='slider')], 93 | [ ezwx.Spin(value=20,expand=True, proportion=1, key='spin')], 94 | ]), 95 | ezwx.Spliter([ 96 | 200, #sashpos 97 | [ 98 | [ ezwx.Bitmap(filename="D:\\Lenna.png",expand=True,proportion=1,key="bitmap")], 99 | ], #panel1 100 | 240, 101 | [ 102 | [ ezwx.Calendar(key='calendar',expand=True,proportion=1)], 103 | ], #panel2 104 | 160, 105 | [ 106 | [ ezwx.Tree( [ 'Root', 107 | ['Item-1', [ 'Item-1.1', 'Item-1.2' ], 108 | 'Item-2', 109 | 'Item-3', [ 'Item-3.1', 'Item-3.2', 'Item-3.3' ], 110 | ] 111 | ] ,expand=True,proportion=1,key="tree"), 112 | { 'expand' : True, 'proportion' : 1 } ], 113 | ], #panel2 114 | ], expand=True, proportion=1, style='vertical'), 115 | { 'expand' : True, 'proportion' : 1 } 116 | ], 117 | [ None, #Insert Spacer with proportion 1 118 | ezwx.Button("ImageView", handler=onImageViewButton), 119 | ezwx.Button("Calendar", handler=onCalendarButton), 120 | ezwx.Button("Date", handler=onDateButton), 121 | ezwx.Button("Time", handler=onTimeButton), 122 | ezwx.Button("StartThread", handler=onThreadButton), 123 | ezwx.Button("StartTimer", handler=onTimerButton, key="button") ], 124 | ] 125 | 126 | layout = { 127 | "menu" : menu_def, 128 | "tool" : tool_def, 129 | "status" : status_def, 130 | "body" : body_def, 131 | } 132 | 133 | ###################################################################### 134 | # Main 135 | ###################################################################### 136 | 137 | def threadTarget(): 138 | ezwx.runAfter(onThread) 139 | 140 | if __name__ == "__main__": 141 | window = ezwx.WxApp(u"ezwxApp", 900, 620) 142 | window.makeLayout(layout) 143 | window.closeHandle(onClose) 144 | window.idleHandle(onIdle) 145 | window.timerHandle(onTimer, key='timer') 146 | window.run() 147 | ``` 148 | 149 | Generated Form. 150 | 151 | ![basic_form](https://3.bp.blogspot.com/-Ql19xAnsDzE/XIJusJqjHjI/AAAAAAAAAio/YMPtZcLIyD8dQql5VI0KEHVz99PmTPFsgCLcBGAs/s1600/win9.png) 152 | 153 | 154 | ## Status 155 | 156 | ### Implemented features. 157 | 158 | * Menubar generation from dict with text menu items + optional icon. 159 | * Toolbar generation from list with icon buttons + optional text. 160 | * Statusbar generation from list 161 | * Body (Client Area) generation from 2-dimentional list. (single VBox + multiple HBoxes) 162 | * Open Event Handler : initializing controls dynamically. 163 | * Close Event Handler : to save data before exit. 164 | * Idle Event Handler 165 | * Timer Event Handler 166 | * Thread interface : callLater(), WxAppClose() 167 | * TextArea with Drag and Drop files 168 | * Support Popup window which can be created same way as main window. 169 | * Fixed size and dynamic size support for controls. 170 | * ArtProvider Icon Support 171 | * StaticBoxSizer Support 172 | * Tooltip support 173 | * ContextMenu support 174 | * Custom PopupWin supports Modal 175 | * Window Caption Hide : Maximize, Minimize, Close, Titlebar ... 176 | * Drag Frame by Control 177 | * Clipboard get text, html, filelist 178 | 179 | ### Implemented Controls 180 | 181 | * Bitmap : wx.StaticBitmap 182 | * Button : wx.Button, wx.BitmapButton 183 | * Calendar : wx.CalendarCtrl 184 | * Check : wx.CheckBox 185 | * Choice : wx.ChoiceBox 186 | * Clock : wx.lib.analogclock.analogclock.AnalogClock 187 | * Combo : wx.ComboBox 188 | * Date : wx.DatePickerCtrl -> moved to Picker 189 | * Gauge : wx.Gauge (same as Progress) 190 | * Label : wx.StaticText 191 | * LedNumber : wx.lib.gizmos.ledctrl.LEDNumberCtrl 192 | * Line : wx.StaticLine 193 | * Link : wx.adv.HyperlinkCtrl 194 | * List : wx.ListBox, wx.CheckListBox, wx.ListCtrl, wx.adv.EditableListBox 195 | * Picker : wx.DirPickerCtrl, wx.FilePickerCtrl, wx.ColourPickerCtrl, wx.FontPickerCtrl, wx.adv.DatePickerCtrl, wx.adv.TimePickerCtrl 196 | * DirPicker, FilePicker, ColorPicker, FontPicker, DatePicker, TimePicker 197 | * Progress : wx.lib.progressindicator.ProgressIndicator 198 | * Radio : wx.RadioBox 199 | * Spin : wx.SpinCtrl 200 | * StyledText : wx.StyledTextCtrl 201 | * Text : wx.TextArea + drag and drop files 202 | * Ticker : wx.lib.tivker.Ticker : wx.lib.gizmos.ledctrl.LEDNumberCtrl 203 | * Time : wx.TimePickerCtrl -> moved to Picker 204 | * Tree : wx.TreeCtrl 205 | * Web : wx.lib.iewin.IEHtmlWindow 206 | 207 | ### Compound Controls 208 | 209 | * FileBrowser : wx.Label + wx.TextCtrl + wx.Button 210 | * ToolbarText : wx.Toolbar + wx.TextCtrl 211 | 212 | ### Implemented Containers 213 | 214 | * Book : wx.Notebook, wx.Choicebook, wx.Simplebook 215 | * Panel : wx.Panel, wx.CollapsiblePane 216 | * Splitter : wx.SplitterWindow, wx.lib.splitter.MultiSplitterWindow 217 | * Scroll : wx.ScrolledWindow 218 | 219 | ### Implemented Sizers 220 | 221 | * VBox, HBox : BoxSiver, StaticBoxSizer 222 | 223 | ### Implemented Dialogs 224 | 225 | * Directory Choose Dialog 226 | * Open File Dialog with multiple file selection support (return full path) 227 | * Save File Dialog (return full path) 228 | * MessageBox 229 | * MessageYesNo : True, False 230 | * MessageYesNoCancel : True, False, None 231 | * ProgressDialog 232 | * Custom Popup Window : WxPopup 233 | 234 | ## Todo 235 | 236 | * More controls support 237 | * More Containers and Sizers support 238 | * Command shell interface 239 | * Network interface support : ssh, sftp, ftp, telnet and etc 240 | * 3rd party library support : matplotlib, PIL, FPDF and etc. 241 | -------------------------------------------------------------------------------- /demo/AllControls.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import ezWxPython as ezwx 5 | 6 | ###################################################################### 7 | # Handler 8 | ###################################################################### 9 | 10 | def AppendToText(text): 11 | ctrl = ezwx.getWxCtrl('text') 12 | if ctrl is not None: 13 | ctrl.write( text + "\n" ) 14 | 15 | def onExit(event): 16 | ezwx.WxAppClose() 17 | 18 | def onClose(event): #return True if want to exit 19 | rv = ezwx.MessageYesNo("Alert", "Do you want to quit ?" ) 20 | if rv is True: 21 | ticker = ezwx.getWxCtrl('ticker') 22 | ticker.Stop() 23 | return rv 24 | 25 | idle_time = 0 26 | idle_count = 0 27 | def onIdle(event): 28 | global idle_time 29 | global idle_count 30 | curr_time = int(time.time()) 31 | idle_count += 1 32 | if idle_time != curr_time: 33 | print(idle_time, idle_count) 34 | idle_time = curr_time 35 | idle_count = 0 36 | 37 | def onTimer(event): 38 | AppendToText('[Timer] ' + time.ctime()) 39 | 40 | def onThreadAction(arg1): 41 | AppendToText('[Thread] ' + str(arg1)) 42 | 43 | def onThread(): 44 | from time import sleep 45 | while True: 46 | ezwx.callAfter(onThreadAction,(time.ctime())) 47 | sleep(1.0) 48 | 49 | def onAbout(event): 50 | ezwx.MessageBox("About", "eezWxPython Demo\nzdiv") 51 | 52 | def onCopy(event): 53 | print("onCopy()") 54 | 55 | def onBrowse(event): 56 | folder = ezwx.DirectoryDialog() 57 | text = ezwx.getWxCtrl('folder') 58 | if text is not None and folder is not None: 59 | text.Clear() 60 | text.write(folder) 61 | 62 | def onFileBrowse(event): 63 | files = ezwx.OpenFileDialog() 64 | if files is not None: 65 | if type(files) is list: 66 | for file in files: 67 | AppendToText(file) 68 | else: 69 | AppendToText(files) 70 | 71 | def onCalendarButton(event): 72 | ctrl = ezwx.getWxCtrl('calendar') 73 | date = ctrl.GetDate() 74 | AppendToText(date.Format('%Y-%m-%d')) 75 | 76 | def onDateButton(event): 77 | ctrl = ezwx.getWxCtrl('date') 78 | date = ctrl.GetValue() 79 | AppendToText(date.Format('%Y-%m-%d')) 80 | 81 | def onTimeButton(event): 82 | ctrl = ezwx.getWxCtrl('time') 83 | h, m, s = ctrl.GetTime() 84 | AppendToText('%04d:%02d:%02d' % (h,m,s)) 85 | 86 | def onThreadButton(event): 87 | ezwx.threadHandle(onThread, key='thread') 88 | ezwx.threadStart('thread') 89 | 90 | def onTimerButton(event): 91 | timer = ezwx.getWxTimer('timer') 92 | button = ezwx.getWxCtrl('button') 93 | if button.GetLabel() == 'StartTimer': 94 | button.SetLabel('StopTimer') 95 | timer.Start(1000) 96 | else: 97 | button.SetLabel('StartTimer') 98 | timer.Stop() 99 | 100 | def onChoice(event): 101 | ctrl = ezwx.getWxCtrl('choice') 102 | AppendToText(str(ctrl.GetSelection()) + " " + ctrl.GetStringSelection()) 103 | 104 | def onCombo(event): 105 | ctrl = ezwx.getWxCtrl('combo') 106 | AppendToText(str(ctrl.GetSelection()) + " " + ctrl.GetStringSelection()) 107 | 108 | def onList(event): 109 | ctrl = ezwx.getWxCtrl('list') 110 | AppendToText(str(ctrl.GetSelection()) + " " + ctrl.GetStringSelection()) 111 | 112 | def onCheckList(event): 113 | ctrl = ezwx.getWxCtrl('checklist') 114 | AppendToText(str(ctrl.GetSelection()) + " " + ctrl.GetStringSelection()) 115 | 116 | def onCheck(event): 117 | ctrl = ezwx.getWxCtrl('check1') 118 | value = ctrl.GetValue() 119 | print( 'Check1: ' + str(value)) 120 | 121 | def onRadio(event): 122 | ctrl = ezwx.getWxCtrl('radio') 123 | print( 'Radio: ' + ctrl.GetString(ctrl.GetSelection())) 124 | 125 | ###################################################################### 126 | # Popup 127 | ###################################################################### 128 | 129 | popup_window = None 130 | 131 | def onPopupExit(event): 132 | popup_window.close() 133 | 134 | popup_menu_def = { 135 | "Exit" : [onPopupExit, None], # Menu item with base64-encoded icon image 136 | } 137 | 138 | popup_body_def = [ 139 | [ ezwx.Bitmap(filename="D:\\Lenna.png",expand=True,proportion=1,key="bitmap"), 140 | { 'proportion' : 1 } ], 141 | ] 142 | 143 | popup_layout = { 144 | "body" : popup_body_def, 145 | } 146 | 147 | def onImageViewButton(event): 148 | global popup_window 149 | popup_window = ezwx.WxPopup(u"ezwxApp", 600, 480) 150 | popup_window.makeLayout(popup_layout) 151 | #window.NoMinimize() 152 | #window.NoMaximize() 153 | popup_window.noResize() 154 | popup_window.noCaption() 155 | popup_window.noBorder() 156 | popup_window.dragEnable(key='bitmap') 157 | popup_window.contextMenu(popup_menu_def, key='bitmap') 158 | popup_window.toolTip("Popup Test Image", key='bitmap') 159 | popup_window.makeModal() 160 | popup_window.Show() 161 | 162 | ###################################################################### 163 | # Layout 164 | ###################################################################### 165 | 166 | exit_png='eJwBZgWZ+olQTkcNChoKAAAADUlIRFIAAAAgAAAAIAgGAAAAc3p69AAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAUISURBVHjavFfdaxxVFP/de/cj28221hpBTIlNX6qQ9EUNQg1RKKYsfRBfFIL2oeC70AdBfPBJqIr/QLHEKMWH+hFrsxQCarVfVNFEDNU0pGlTTGJTapO4M3Pv9Zw7dze7ss3OImaTk8nOzL3nN7/zOx8DbO5HTF/4srg690P0wZF+S98zqc1yfKn04a5HdnZ+KmF6RSoNJSSfz8tNcK7mfyp9sru7a3pt6bfeubPHYKIIQgi+lm7GQOqjNwY/y2VkUdICkdCjsRZBEKC7Zx+6HnsK4eot3Jj4DtHqMkDXjDVQKn72ZgBy2ZQovnVqjYJFABIiMMZi5e8Alw/tw7Wfx3F3aRZCkisya0JYTQzIZADaRIwCbXRnKwCsTeP69yNYKxtax27IIT05/cIQAOU3awZACCvA9DNgmRAAB0spBUuLjOCQwFEPG4dH67CiASTIAgtJ8WoFAH/4fnZGzxwDAHz86XwUuj0TARBGgu+V0iYHQPcRAUQ3h8K6h68AsJ6BSggapWHm4Huwzx3FSQYoNYdAEWWyZdMEwGjrNFFnTUSY1ySU/l14/q83sSLKyqFVxEBSEXKsJdFlbQMG6EeHodPVvRhIBxp4oe91PNuLobHCOSibpQUp2lS2YMrlu9OBN81HzgIqRKqGgXTxHSyGGtvcRUK7VqYjchjsfREldQK/L38DOzkAmQkJsk4iAacZ7fczLgEEOSdWSFORC8F6FuTZ+fFXj+FW+XOunLSQbrD3Y2L+BA70vgyZHsZ5+TXUL8/QxgHtbhKEwMYiNHEI2Hn3QzPo2DqPuWiw0gscgAw/+Z3yAr698sV6uRWj5BiY/GMYgz2HKG2O46IcR9vUAO0exV42AMBZoI1xT6+tcNQ/eN8ShkuPYqCoqwxUNbCi5ykYcCYyZHwkeJY2uvLnx3hizx5EnTfdSady2cxUjQh9LSCf+VwaJgycTqpZwFhW7Q2oLKoMWFNTUFIBLk1PITPf6WoCmD5hNy5EwhciW9GBcSxsyaYRUiHyEYgZ4E1DdRPZPMVjC5GQowuZ2FJtwOwicKHURfTvJwKotis4CpuZ9nlvybMlAAu3d+DAkz9SIYrqNMAA7h4dPtfOCFkwlCV45aU4ylevA5fHulC4uh8yG3jIsqkIlRJx57PC7UkqwNS1nTh9Po++p8t1zSg4dQT9dNzuo5EefBunmYVfp4HF8Q4Upkm1GcpNaZs7r4ZA1IXAoaLd2/OpuBn5XsB/V8hmyCbJJvh/VvDMHFA6ia8Glh6HzRrOzgTCWzcWmTE1qegtT609IhHW9gKqLrhNtuBtmQSMM6M4e/F9vKup8PB3qURrlZCewpj6SsiWSVGPoBhLee92HI6+hr3+/yiSsWJ5QeJmyIXINugFflxjBnIbNCMOySzfS1bQdHC0CosWehFpQLrarxsACHWw4TwQeHMzIS9WFANmTMAmHQcotipuxdrWrXL9hhgQqYQTEeewiz9EawxwA+IZ0P4LNjMQUh3ItzCSudLr+plNPBJxCOIuiPWRzI+GJipTWHPJAKRFRG8PirOwhfcCXhfrJpaSqILgg2OgRoSZoaGhcsONaOHYMqt6yX9LHgJtJc7MFLAjF6GzECKfMoiHY86CcnUicgPJyMjIbp4LGhHgz2f+6/vZA9tyucPFnoMPd7T3bS9gb6UbCr953jv7315O/f7tZFvJqOXhDlddgc37KP+wWQ+Gp5qVfwQYAOMRch38qZCKAAAAAElFTkSuQmCCWbl5kg==' 167 | save_png="eJyVVH1MG2UYPyhjjJWvhOgkQY5Dp9nW3l2/e6Urd70eNK4dKSXUMEOP9kpvbe9ud1daiBFly3RmH0TjmAnJNjRRM2ec0T8WTEAxOuIfw49E58KoJJqpW0A0jmWVecUWiTEkvsm97/s87+/3fL7vHWv3tlaU15UDAFDhbiN9ygrmvrJSZZYGB39XlodkV0Du4CNyihYZAA/zvQzoTtB9jI+hwwOHZphmAFBdZP0BOeDZh4X4hJbOYbTphADkRrMjLdChGCODvUwfy9mhxYlJCGTDdqjL6EE8gpOJsm2DItMx6PWHBmMhaxhy7AWb05hiIMHINJhOxDkJS9uhNbuYss+pYQhcg8gxO/R3UAFPO+jkRQY0ahFNCDEhoAnVonqD2WzeA+oQFIERHYzqNKgZ0+swBAHzA1K8ieEI5iOpvC9FskNRWRYwGE6lUtqUXsuLfTBqtVpzNnQ6jYLQSAOcTKc1nNRUsEAyUkhkBZnlOTAn0718UrZDUCGFhOBj+6KytG6ck/LFUsoGp2kBRrUILK5h4A0sj2dzRiKxjpZkHxPZHC35BwQG9jESnxRDShcjTRtcbU7NAfM5YB5ajDFKFyk6LjFrBx4Ptl8JnuXoOMmHkgmGk92kHUom2TCGu/SUwYRYLJTFSrpQFLeYEKuVQnUorkMMOmvBwEaiotGGFa6FxC0oSZkIo4tCURdC4LieIFwG0kygeiNKFrhuTpJpLsQUuOw/XOOmXMwpMrTMi36ejxduU3uUl3kpygugs8MIdrFcmE9JuUbn42REtp8JUyKfANdqjrH/4V2vcxFWg4F0UYp/BEWtOGHAKdKK6K2U3ugioDw3/L/LBSuRwP+6cwWVcpFz2/UXpAjrb5DhlJaJygubCe63AUDRhJvE/enverP37zumW4o/xX949ugHfb/gtfW3EtEyE1eCBmYfne184O6O9nj3/Ont6sCtj34G1EtVO4jdp27svL4sxDo/XH68cuXqUsMFFXHRf6UfaHOYpEu2jCNBAD1YqwScrl7Zqi56opwA3mzo8YbwO5pIGYLsscmH41vJa2zQOHqzeuW3xQbnmRN11yqBnx7bW7JK78pur+1+OqMoXkjOfnxQu61x6Wzjl96Xh6vPIRXZLaXfZ+dGr/S3jF94+FcWiNUCxs8u33zpNjDyzPhrmYaTccuhafd79SMNQe+TZQeGsicbq6Jll4HXzx6pXnn+fCbzSmtw3+4WpCRaUfqq6l2y6Kn6pZShfJU+NTzDasPdI7ZYlS6lr763IE8tTg5dGo3UHlFr9UpSV3vGOnepw575Y5BZ81X9pGp15EfgOFhsyywOjZVCn9cIU5H4F1PDB791OITrtRVZopw6VzcmBpxV52+MButWVOjxmrmaydWss+twZ+WEqv3rewsnih/5ZtyycGd+yOLMKPMnRwF0S82LvSNNpucO/PngW5irY3pptGV+Gf7j7TnEYntDVQQUq4Hbxp13z7zPbMv9Zd0uL/kOERz+C2G1BH0=" 168 | 169 | menu_def = { 170 | "File" : { 171 | "Option" : { 172 | "Settings" : None, # Disabled menu item 173 | "Copy": onCopy 174 | }, 175 | "-" : None, # Menu separator 176 | "Exit" : [onExit, exit_png], # Menu item with base64-encoded icon image 177 | "-2" : None, # Menu separator (should have different name from other menu separator) 178 | }, 179 | "Help" : { 180 | "About" : onAbout 181 | }, 182 | } 183 | 184 | tool_def = [ #icon, text, handler 185 | [exit_png, onExit, "Exit", "Close Window" ], 186 | [None], # Tool separator 187 | [save_png, None, "Save", ], # Disabled toolbar item 188 | ] 189 | 190 | status_def = [ 191 | ["Ready", -6], # width will have space with proportion 6 192 | ["Status", -4], # width will have space with proportion 4 193 | ["Code:1", 20] # fixed width 194 | ] 195 | 196 | body_def = [ 197 | "ezWxPython Layout Demo", 198 | [ ezwx.Label ("Folder: "), 199 | ezwx.Text ("Default Text",key="folder",expand=True,password=True,proportion=1), 200 | ezwx.Button("Folder", handler=onBrowse, key="browse"), 201 | ezwx.Button("Files", handler=onFileBrowse, key="file_browse" ), ], 202 | [ ezwx.Check("Check1", handler=onCheck, key='check1'), 203 | ezwx.Check("Check2", key='check2'), 204 | ezwx.ColorPicker(), 205 | ezwx.FontPicker(), 206 | ezwx.Link("Google", "https://www.google.com"), ], 207 | [ ezwx.Label ("Choices: "), ezwx.Choice(['apple','orange','grape'],0,handler=onChoice,key="choice"), 208 | ezwx.Label (" ComboBox: "), ezwx.Combo (['apple','orange','grape'],"orange",handler=onCombo,key="combo"), 209 | ezwx.Label (" Date: "), ezwx.Date (key='date'), 210 | ezwx.Label (" Time: "), ezwx.Time (key='time'), ], 211 | [ ezwx.List (['apple','orange','grape'],2,expand=True,proportion=0,handler=onList,key="list"), 212 | ezwx.List (['apple','orange','grape'],2,expand=True,proportion=0,handler=onCheckList,check=True,key="checklist"), 213 | ezwx.Notebook([ 214 | "StyledText", #notebook title1 215 | [ 216 | [ ezwx.StyledText ("Default\nMulti Line\nText",expand=True,proportion=1,key="stc"), 217 | { 'expand' : True, 'proportion' : 1 } ], 218 | ], 219 | "Text", #notebook title2 220 | [ 221 | [ ezwx.Text ("Default\nMulti Line\nText",expand=True,proportion=1,multiline=True,key="text"), 222 | { 'expand' : True, 'proportion' : 1 } ], 223 | ], 224 | ], expand=True, proportion=2), 225 | ezwx.List([[('Name',100,-1),('Sex',32,0),('Age',64,1)], #label, width, align 226 | ["Willy","M","32"], 227 | ["Jane","F","28"], 228 | ], expand=True, proportion=2, style='multicol'), 229 | ezwx.List(expand=True,proportion=1,label="Editable List", style='edit',key='editlist'), 230 | { 'expand' : True, 'proportion' : 1 } 231 | ], 232 | [ ezwx.Panel([ 233 | "Panel Demo", 234 | [ ezwx.Button("A"), ezwx.Button("B")], 235 | [ ezwx.Ticker("This is a ticker example text", expand=True, proportion=1, key='ticker')], 236 | [ ezwx.Line(expand=True, proportion=1)], 237 | [ ezwx.Slider(value=20,expand=True, proportion=1, key='slider')], 238 | [ ezwx.Spin(value=20,expand=True, proportion=1, key='spin')], 239 | ], expand=True, proportion=1, label='Panel Demo'), 240 | ezwx.ScrolledPanel( [ 241 | [ezwx.Radio("Group",["Item1","item2","item3"],"item2",handler=onRadio,key='radio')], 242 | [ezwx.Button("1")],[ezwx.Button("2")],[ezwx.Button("3")],[ezwx.Button("4")], 243 | ], expand=True, proportion=1), 244 | ezwx.VerticalSpliter([ 245 | 200, #sashpos1 246 | [ #panel1 247 | "Lenna Image", 248 | [ "Lenna Image II", 249 | ezwx.Bitmap(filename="D:\\Lenna.png",expand=True,proportion=1,key="bitmap")], 250 | ], 251 | 240, #sashpos2 252 | [ #panel2 253 | [ ezwx.Calendar(key='calendar',expand=True,proportion=1)], 254 | ], 255 | 160, #sashpos3 256 | [ #panel3 257 | [ ezwx.Tree( [ 'Root', 258 | ['Item-1', [ 'Item-1.1', 'Item-1.2' ], 259 | 'Item-2', 260 | 'Item-3', [ 'Item-3.1', 'Item-3.2', 'Item-3.3' ], 261 | ] 262 | ] ,expand=True,proportion=1,key="tree"), 263 | { 'expand' : True, 'proportion' : 1 } 264 | ], 265 | ], 266 | ], expand=True, proportion=1), 267 | { 'expand' : True, 'proportion' : 1 } 268 | ], 269 | [ None, #Insert Spacer with proportion 1 270 | ezwx.Button("ImageView", handler=onImageViewButton,tooltip="Show Popup Window"), 271 | ezwx.Button("Calendar", handler=onCalendarButton), 272 | ezwx.Button("Date", handler=onDateButton), 273 | ezwx.Button("Time", handler=onTimeButton), 274 | ezwx.Button("StartThread", handler=onThreadButton), 275 | ezwx.Button("StartTimer", handler=onTimerButton, key="button") ], 276 | ] 277 | 278 | layout = { 279 | "menu" : menu_def, 280 | "tool" : tool_def, 281 | "status" : status_def, 282 | "body" : body_def, 283 | } 284 | 285 | ###################################################################### 286 | # Main 287 | ###################################################################### 288 | 289 | def threadTarget(): 290 | ezwx.runAfter(onThread) 291 | 292 | if __name__ == "__main__": 293 | window = ezwx.WxApp(u"ezwxApp", 900, 620) 294 | window.makeLayout(layout) 295 | window.closeHandle(onClose) 296 | window.idleHandle(onIdle) 297 | window.timerHandle(onTimer, key='timer') 298 | window.run() 299 | -------------------------------------------------------------------------------- /demo/AnalogClock.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | def initCtrls(): 8 | global cal 9 | cal = ew.getWxCtrl('cal') 10 | cal.SetBackgroundColour(wx.Colour(200,200,240)) 11 | 12 | def onExit(event): 13 | appWin.close() 14 | 15 | def onClose(event): #return True if want to exit 16 | rv = appWin.messageYesNo("Alert", "Do you want to quit ?" ) 17 | return rv 18 | 19 | def onAbout(event): 20 | appWin.messageBox("About", "Menu Demo\nzdiv") 21 | 22 | menu_def = { 23 | "File" : { 24 | "Exit" : [ onExit, wx.ART_QUIT ], 25 | }, 26 | "Help" : { 27 | "About" : onAbout 28 | }, 29 | } 30 | 31 | body_def = [ 32 | [ ew.Clock(expand=True,proportion=1,key='cal'), 33 | { 'expand' : True, 'proportion' : 1 } 34 | ], 35 | ] 36 | 37 | status_def = [ 38 | ["Ready", -1], 39 | ] 40 | 41 | layout = { 42 | "menu" : menu_def, 43 | "body" : body_def, 44 | "status" : status_def, 45 | } 46 | 47 | ###################################################################### 48 | # Main 49 | ###################################################################### 50 | 51 | if __name__ == "__main__": 52 | appWin = ew.WxApp(u"Menu Demo", 320, 320) 53 | appWin.makeLayout(layout) 54 | initCtrls() 55 | appWin.closeHandle(onClose) 56 | appWin.run() 57 | -------------------------------------------------------------------------------- /demo/BitmapButton.py: -------------------------------------------------------------------------------- 1 | 2 | wx_addr = None 3 | wx_output = None 4 | wx_text = None 5 | 6 | def onExit(event): 7 | ew.WxAppClose() 8 | 9 | def onClose(event): 10 | return ew.MessageYesNo("Alert", "Do you want to quit ?" ) 11 | 12 | def onAbout(event): 13 | ew.MessageBox("About", "eezWxPython Demo\nzdiv") 14 | 15 | def onGo(event): 16 | url = wx_addr.GetValue() 17 | output_dir = wx_output.GetValue() 18 | ew.threadHandle(saveTookKor, args=(home_url, url, output_dir), key='thread') 19 | ew.threadStart('thread') 20 | saveTookKor() 21 | 22 | def onFolder(event): 23 | folder = ew.DirectoryDialog() 24 | if wx_output is not None and folder is not None: 25 | wx_output.Clear() 26 | wx_output.write(folder) 27 | 28 | def AppendToText(text): 29 | if wx_text is not None: 30 | wx_text.AppendText( str(text) ) 31 | wx_text.AppendText( '\r\n' ) 32 | lines = wx_text.GetNumberOfLines() 33 | wx_text.ScrollLines( lines + 1 ) 34 | 35 | 36 | def printf(text): 37 | if gui_enabled is True: 38 | ew.callAfter(AppendToText,text) 39 | else: 40 | print(text) 41 | 42 | def findCtrls(): 43 | global wx_addr, wx_output, wx_text 44 | wx_addr = ew.getWxCtrl('addr') 45 | wx_output = ew.getWxCtrl('output') 46 | wx_text = ew.getWxCtrl('text') 47 | 48 | menu_def = { 49 | "File" : { 50 | "Exit" : [onExit, wx.ART_QUIT], 51 | }, 52 | "Help" : { 53 | "About" : [onAbout, wx.ART_HELP], 54 | }, 55 | } 56 | 57 | tool_def = [ #icon, text, handler 58 | [wx.ART_QUIT, onExit, "Exit" ], 59 | ] 60 | 61 | status_def = [ 62 | ["Ready", -1], 63 | ] 64 | 65 | body_def = [ 66 | [ ew.Label ("Address: "), 67 | ew.Text ("https://gogle.com",key="addr",expand=True,proportion=1), 68 | ew.Button(wx.ART_GO_FORWARD,handler=onGo), 69 | ], 70 | [ ew.Label ("Output Folder: "), 71 | ew.Text ("D:/",key="output",expand=True,proportion=1), 72 | ew.Button(wx.ART_FOLDER_OPEN,handler=onFolder), 73 | ], 74 | [ ew.StyledText(key='text',expand=True,proportion=1), 75 | { 'expand':True, 'proportion':1 } 76 | ] 77 | ] 78 | 79 | layout = { 80 | "menu" : menu_def, 81 | "tool" : tool_def, 82 | "status" : status_def, 83 | "body" : body_def, 84 | } 85 | 86 | 87 | if __name__ == "__main__": 88 | gui_enabled = True 89 | window = ew.WxApp(u"ezwxApp", 900, 620) 90 | window.makeLayout(layout) 91 | window.closeHandle(onClose) 92 | findCtrls() 93 | window.run() 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /demo/CalendarCtrl.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | def initCtrls(): 8 | global cal 9 | cal = ew.getWxCtrl('cal') 10 | cal.SetBackgroundColour(wx.Colour(200,200,240)) 11 | 12 | def onExit(event): 13 | appWin.close() 14 | 15 | def onClose(event): #return True if want to exit 16 | rv = appWin.messageYesNo("Alert", "Do you want to quit ?" ) 17 | return rv 18 | 19 | def onAbout(event): 20 | appWin.messageBox("About", "Menu Demo\nzdiv") 21 | 22 | def onCalendar(event): 23 | appWin.appendText('text', appWin.getCalendarDate('cal') + '\n') 24 | 25 | def onGetDate(event): 26 | date = cal.GetDate() 27 | appWin.appendText('text', date.Format('[%Y-%m-%d]\n')) 28 | 29 | menu_def = { 30 | "File" : { 31 | "Exit" : [ onExit, wx.ART_QUIT ], 32 | }, 33 | "Help" : { 34 | "About" : onAbout 35 | }, 36 | } 37 | 38 | body_def = [ 39 | [ ew.Calendar(handler=onCalendar,expand=True,proportion=1,key='cal'), ], 40 | [ ew.Button('GetDate',handler=onGetDate,expand=True,proportion=1), ], 41 | [ ew.Text("",multiline=True,expand=True,proportion=1,key='text'), 42 | { 'expand' : True, 'proportion' : 1 } 43 | ], 44 | ] 45 | 46 | status_def = [ 47 | ["Ready", -1], 48 | ] 49 | 50 | layout = { 51 | "menu" : menu_def, 52 | "body" : body_def, 53 | "status" : status_def, 54 | } 55 | 56 | ###################################################################### 57 | # Main 58 | ###################################################################### 59 | 60 | if __name__ == "__main__": 61 | appWin = ew.WxApp(u"Menu Demo", 320, 480) 62 | appWin.makeLayout(layout) 63 | initCtrls() 64 | appWin.closeHandle(onClose) 65 | appWin.run() 66 | -------------------------------------------------------------------------------- /demo/ContextMenu.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | def initCtrls(): 8 | global label, idlecount, timercount 9 | label = ew.getWxCtrl('label') 10 | label.SetBackgroundColour(wx.Colour(200,200,240)) 11 | idlecount = 0 12 | timercount = 0 13 | 14 | def onExit(event): 15 | appWin.close() 16 | 17 | def onClose(event): #return True if want to exit 18 | rv = appWin.messageYesNo("Alert", "Do you want to quit ?" ) 19 | return rv 20 | 21 | def onAbout(event): 22 | appWin.messageBox("About", "Menu Demo\nzdiv") 23 | 24 | menu_def = { 25 | "File" : { 26 | "Exit" : [ onExit, wx.ART_QUIT ], 27 | }, 28 | "Help" : { 29 | "About" : onAbout 30 | }, 31 | } 32 | 33 | body_def = [ 34 | [ ew.Label("Hello ezWxPython",expand=True,proportion=1,key='label'), 35 | { 'expand' : True, 'proportion' : 1 } ], 36 | ] 37 | 38 | status_def = [ 39 | ["Ready", -1], 40 | ] 41 | 42 | layout = { 43 | "menu" : menu_def, 44 | "body" : body_def, 45 | "status" : status_def, 46 | } 47 | 48 | ###################################################################### 49 | # Main 50 | ###################################################################### 51 | 52 | if __name__ == "__main__": 53 | appWin = ew.WxApp(u"Menu Demo", 320, 240) 54 | appWin.makeLayout(layout) 55 | initCtrls() 56 | appWin.closeHandle(onClose) 57 | appWin.contextMenu(menu_def,'label') 58 | appWin.run() 59 | -------------------------------------------------------------------------------- /demo/ControlDemo.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | def initCtrls(): 8 | ew.getWxCtrl('top1').SetBackgroundColour(wx.Colour(200,200,240)) 9 | 10 | def onExit(event): 11 | appWin.close() 12 | 13 | def onAbout(event): 14 | appWin.messageBox("About", "Control Demo\nzdiv") 15 | 16 | def onGo(event): 17 | kind = ew.getValue('kind') 18 | action = ew.getValue('action') 19 | if action == 'getLabel': 20 | ew.setValue('value',ew.getLabel(kind)) 21 | elif action == 'setLabel': 22 | ew.setLabel(kind,ew.getValue('value')) 23 | elif action == 'getValue': 24 | ew.setValue('value',str(ew.getValue(kind))) 25 | elif action == 'setValue': 26 | ew.setValue(kind,ew.castValue(kind,ew.getValue('value'))) 27 | elif action == 'appendValue': 28 | ew.appendValue(kind,ew.getValue('value')) 29 | elif action == 'removeValue': 30 | ew.removeValue(kind,ew.getValue('value')) 31 | elif action == 'setFgColor': 32 | ew.setFgColor(kind,wx.Colour(0,0,255)) 33 | elif action == 'setBgColor': 34 | ew.setBgColor(kind,wx.Colour(255,0,0)) 35 | 36 | menu_def = { 37 | "File" : { 38 | "Exit" : [ onExit, wx.ART_QUIT ], 39 | }, 40 | "Help" : { 41 | "About" : onAbout 42 | }, 43 | } 44 | 45 | body_def = [ 46 | [ ew.Choice(['label','button','toggle','check','text','choice','combo','list','date','time'], key='kind'), 47 | ew.Choice(['getLabel','setLabel','getValue','setValue','appendValue','removeValue','setFgColor','setBgColor'], key='action'), 48 | ew.Text("",key='value'), 49 | ew.Button("Go",handler=onGo), 50 | ], 51 | [ ew.Label("Label: ",expand=True), 52 | ew.Label("Value",expand=True,proportion=1,key='label',size=(64,-1)), ], 53 | [ ew.Label("Button: ",expand=True), 54 | ew.Button("Button",expand=True,proportion=1,key='button',size=(64,-1)), ], 55 | [ ew.Label("ToggleButton: ",expand=True), 56 | ew.ToggleButton("ToggleButton",value=True,expand=True,proportion=1,key='toggle',size=(64,-1)), ], 57 | [ ew.Label("CheckButton: ",expand=True), 58 | ew.CheckButton("CheckButton",value=True,expand=True,proportion=1,key='check',size=(64,-1)), ], 59 | [ ew.Label("Text: ",expand=True), 60 | ew.Text("Text",expand=True,proportion=1,key='text',size=(64,-1)), ], 61 | [ ew.Label("Choice: ",expand=True), 62 | ew.Choice(['apple','lemon'],expand=True,size=(64,-1),proportion=1,key='choice'), ], 63 | [ ew.Label("Combo: ",expand=True), 64 | ew.Combo(['apple','lemon'],expand=True,size=(64,-1),proportion=1,key='combo'),], 65 | [ ew.Label("List: ",expand=True), 66 | ew.List(['apple','lemon'],expand=True,size=(64,-1),proportion=1,key='list'),], 67 | [ ew.Label("Date: ",expand=True), 68 | ew.Date(expand=True,size=(64,-1),proportion=1,key='date'),], 69 | [ ew.Label("Time: ",expand=True), 70 | ew.Time(expand=True,size=(64,-1),proportion=1,key='time'),], 71 | ] 72 | 73 | status_def = [ 74 | ["Ready", -1], 75 | ] 76 | 77 | layout = { 78 | "menu" : menu_def, 79 | "body" : body_def, 80 | "status" : status_def, 81 | } 82 | 83 | ###################################################################### 84 | # Main 85 | ###################################################################### 86 | 87 | if __name__ == "__main__": 88 | appWin = ew.WxApp(u"Control Demo", 400, 480) 89 | appWin.makeLayout(layout) 90 | appWin.run() 91 | -------------------------------------------------------------------------------- /demo/DirectoryDialog.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | def onExit(event): 8 | appWin.close() 9 | 10 | def onAbout(event): 11 | appWin.messageBox("About", "Menu Demo\nzdiv") 12 | 13 | def onButton(event): 14 | defaultDir = appWin.getText('dir') 15 | directory = appWin.directoryDialog(defaultPath=defaultDir); 16 | appWin.appendText('text',directory + '\n') 17 | 18 | menu_def = { 19 | "File" : { 20 | "Exit" : [ onExit, wx.ART_QUIT ], 21 | }, 22 | "Help" : { 23 | "About" : onAbout 24 | }, 25 | } 26 | 27 | body_def = [ 28 | [ ew.Label("Default Dir:"), 29 | ew.Text("D:\\",expand=True,proportion=1,key='dir'), 30 | ew.Button("Open", handler=onButton), ], 31 | [ ew.Text('',multiline=True,expand=True,proportion=1,key='text'), 32 | { 'expand' : True, 'proportion' : 1 } ], 33 | ] 34 | 35 | status_def = [ 36 | ["Ready", -1], 37 | ] 38 | 39 | layout = { 40 | "menu" : menu_def, 41 | "body" : body_def, 42 | "status" : status_def, 43 | } 44 | 45 | ###################################################################### 46 | # Main 47 | ###################################################################### 48 | 49 | if __name__ == "__main__": 50 | appWin = ew.WxApp(u"Directory Dialog Demo", 320, 240) 51 | appWin.makeLayout(layout) 52 | appWin.run() 53 | -------------------------------------------------------------------------------- /demo/DragFrame.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | def initCtrls(): 8 | global label, idlecount, timercount 9 | label = ew.getWxCtrl('label') 10 | label.SetBackgroundColour(wx.Colour(200,200,240)) 11 | idlecount = 0 12 | timercount = 0 13 | 14 | def onExit(event): 15 | appWin.close() 16 | 17 | def onClose(event): #return True if want to exit 18 | rv = appWin.messageYesNo("Alert", "Do you want to quit ?" ) 19 | return rv 20 | 21 | def onAbout(event): 22 | appWin.messageBox("About", "Menu Demo\nzdiv") 23 | 24 | menu_def = { 25 | "File" : { 26 | "Exit" : [ onExit, wx.ART_QUIT ], 27 | }, 28 | "Help" : { 29 | "About" : onAbout 30 | }, 31 | } 32 | 33 | body_def = [ 34 | [ ew.Label("Hello ezWxPython",expand=True,proportion=1,key='label'), 35 | { 'expand' : True, 'proportion' : 1 } ], 36 | ] 37 | 38 | status_def = [ 39 | ["Ready", -1], 40 | ] 41 | 42 | layout = { 43 | "menu" : menu_def, 44 | "body" : body_def, 45 | "status" : status_def, 46 | } 47 | 48 | ###################################################################### 49 | # Main 50 | ###################################################################### 51 | 52 | if __name__ == "__main__": 53 | appWin = ew.WxApp(u"Menu Demo", 320, 240) 54 | appWin.makeLayout(layout) 55 | initCtrls() 56 | appWin.closeHandle(onClose) 57 | appWin.dragEnable('label') 58 | appWin.run() 59 | -------------------------------------------------------------------------------- /demo/Execute.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | def initCtrls(): 8 | global label, idlecount, timercount 9 | label = ew.getWxCtrl('label') 10 | label.SetBackgroundColour(wx.Colour(200,200,240)) 11 | idlecount = 0 12 | timercount = 0 13 | 14 | def onExit(event): 15 | appWin.close() 16 | 17 | def onClose(event): #return True if want to exit 18 | rv = appWin.messageYesNo("Alert", "Do you want to quit ?" ) 19 | return rv 20 | 21 | def onAbout(event): 22 | appWin.messageBox("About", "Menu Demo\nzdiv") 23 | 24 | def onExecute(event): 25 | #ew.Execute("cmd.exe /C dir /s C:\\", sync=False, show=True) 26 | os.system("start dir /s C:\\") 27 | 28 | menu_def = { 29 | "File" : { 30 | "Exit" : [ onExit, wx.ART_QUIT ], 31 | }, 32 | "Help" : { 33 | "About" : onAbout 34 | }, 35 | } 36 | 37 | body_def = [ 38 | [ ew.Label("Hello ezWxPython",expand=True,proportion=1,key='label'), 39 | { 'expand' : True, 'proportion' : 1 } ], 40 | [ ew.Button("Execute",handler=onExecute,expand=True,proportion=1,), 41 | ], 42 | ] 43 | 44 | status_def = [ 45 | ["Ready", -1], 46 | ] 47 | 48 | layout = { 49 | "menu" : menu_def, 50 | "body" : body_def, 51 | "status" : status_def, 52 | } 53 | 54 | ###################################################################### 55 | # Main 56 | ###################################################################### 57 | 58 | if __name__ == "__main__": 59 | appWin = ew.WxApp(u"Menu Demo", 320, 240) 60 | appWin.makeLayout(layout) 61 | initCtrls() 62 | appWin.closeHandle(onClose) 63 | appWin.run() 64 | -------------------------------------------------------------------------------- /demo/FileBrowser.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import ezWxPython as ew 5 | 6 | ###################################################################### 7 | # Handler 8 | ###################################################################### 9 | 10 | def onExit(event): 11 | appWin.close() 12 | 13 | def onClose(event): 14 | rv = appWin.messageYesNo("Alert", "Do you want to quit ?" ) 15 | return rv 16 | 17 | def onAbout(event): 18 | appWin.messageBox("About", "TextFileBrowser Demo\nzdiv") 19 | 20 | def onFileBrowse(filename): 21 | browser = ew.getWxCtrl('file') 22 | text = ew.getWxCtrl('text') 23 | text.AppendText(browser.GetValue() + "\n") 24 | text.AppendText(filename + "\n") 25 | 26 | def onDirBrowse(filename): 27 | browser = ew.getWxCtrl('dir') 28 | text = ew.getWxCtrl('text') 29 | text.AppendText(browser.GetValue() + "\n") 30 | text.AppendText(filename + "\n") 31 | 32 | ###################################################################### 33 | # Layout 34 | ###################################################################### 35 | 36 | menu_def = { 37 | "File" : { 38 | "Exit" : onExit, 39 | }, 40 | "Help" : { 41 | "About" : onAbout 42 | }, 43 | } 44 | 45 | status_def = [ 46 | ["Ready", -1], 47 | ] 48 | 49 | body_def = [ 50 | [ ew.FileBrowser("Input File: ", "", "Open", handler=onFileBrowse, key='file', save=False, expand=True, proportion=1, border=1 ) ], 51 | [ ew.FileBrowser("Output Folder: ", "", "Browse", handler=onDirBrowse, key='dir', directory=True, expand=True, proportion=1, border=0 ) ], 52 | [ ew.Text(expand=True,proportion=1,multiline=True,readonly=True,key="text"), 53 | { 'expand' : True, 'proportion': 1 } 54 | ], 55 | ] 56 | 57 | layout = { 58 | "menu" : menu_def, 59 | "status" : status_def, 60 | "body" : body_def, 61 | } 62 | 63 | ###################################################################### 64 | # Main 65 | ###################################################################### 66 | 67 | if __name__ == "__main__": 68 | appWin = ew.WxApp("TextFileBrowser Demo", 600, 480) 69 | appWin.makeLayout(layout) 70 | appWin.closeHandle(onClose) 71 | appWin.run() 72 | -------------------------------------------------------------------------------- /demo/FileDialog.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | def onExit(event): 8 | appWin.close() 9 | 10 | def onAbout(event): 11 | appWin.messageBox("About", "Menu Demo\nzdiv") 12 | 13 | def onButton(event): 14 | multiple = appWin.getCheckState('multiple') 15 | files = appWin.openFileDialog( multiple = multiple ); 16 | if multiple: 17 | for f in files: 18 | appWin.appendText('text',f + '\n') 19 | else: 20 | appWin.appendText('text',files + '\n') 21 | 22 | menu_def = { 23 | "File" : { 24 | "Exit" : [ onExit, wx.ART_QUIT ], 25 | }, 26 | "Help" : { 27 | "About" : onAbout 28 | }, 29 | } 30 | 31 | body_def = [ 32 | [ ew.Check("Enable multiple selection",expand=True,proportion=1,key='multiple'), 33 | ew.Button("Open", handler=onButton), ], 34 | [ ew.Text('',multiline=True,expand=True,proportion=1,key='text'), 35 | { 'expand' : True, 'proportion' : 1 } ], 36 | ] 37 | 38 | status_def = [ 39 | ["Ready", -1], 40 | ] 41 | 42 | layout = { 43 | "menu" : menu_def, 44 | "body" : body_def, 45 | "status" : status_def, 46 | } 47 | 48 | ###################################################################### 49 | # Main 50 | ###################################################################### 51 | 52 | if __name__ == "__main__": 53 | appWin = ew.WxApp(u"File Dialog Demo", 320, 240) 54 | appWin.makeLayout(layout) 55 | appWin.run() 56 | -------------------------------------------------------------------------------- /demo/Gauge.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import threading 5 | import ezWxPython as ezwx 6 | 7 | ###################################################################### 8 | # Global 9 | ###################################################################### 10 | 11 | title = u"Gauge Demo" 12 | window = None 13 | 14 | def setStatusText(text,index=0): 15 | if window is not None and window.statusbar is not None: 16 | if index < window.statusbar.GetFieldsCount(): 17 | window.statusbar.SetStatusText(text,index) 18 | 19 | ###################################################################### 20 | # Handler 21 | ###################################################################### 22 | 23 | def onExit(event): 24 | ezwx.WxAppClose() 25 | 26 | def onClose(event): #return True if want to exit 27 | rv = ezwx.MessageYesNo("Alert", "Do you want to quit ?" ) 28 | return rv 29 | 30 | def onAbout(event): 31 | ezwx.MessageBox("About", title + "\nzdiv") 32 | 33 | def threadProgress(progress): 34 | for i in range(0,301): 35 | #if i % 50 == 49: 36 | # progress.pulse() 37 | progress.update(i) 38 | time.sleep(0.01) 39 | 40 | def onButton(event): 41 | progress = ezwx.getCtrl('progress') 42 | progress.setMaxValue(300) 43 | thread = threading.Thread(target=threadProgress, args=(progress,)) 44 | thread.daemon = True 45 | thread.start() 46 | 47 | ###################################################################### 48 | # Layout 49 | ###################################################################### 50 | 51 | menu_def = { 52 | "File" : { 53 | "Exit" : onExit, 54 | }, 55 | "Help" : { 56 | "About" : onAbout 57 | }, 58 | } 59 | 60 | status_def = [ 61 | ["Ready", -1], 62 | ] 63 | 64 | body_def = [ 65 | [ ezwx.Gauge(expand=True,proportion=1,key="progress"), ], 66 | [ ezwx.Button("Show Progress",expand=True,proportion=1,handler=onButton,key="button"), 67 | { 'expand' : True, 'proportion' : 1 } ], 68 | ] 69 | 70 | layout = { 71 | "menu" : menu_def, 72 | "status" : status_def, 73 | "body" : body_def, 74 | } 75 | 76 | ###################################################################### 77 | # Main 78 | ###################################################################### 79 | 80 | if __name__ == "__main__": 81 | window = ezwx.WxApp(title, 120, 160) 82 | window.makeLayout(layout) 83 | window.closeHandle(onClose) 84 | window.run() 85 | -------------------------------------------------------------------------------- /demo/IdleEvent.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | def initCtrls(): 8 | global label, runcount 9 | label = ew.getWxCtrl('label') 10 | label.SetBackgroundColour(wx.Colour(200,200,240)) 11 | runcount = 0 12 | 13 | def onExit(event): 14 | appWin.close() 15 | 16 | def onClose(event): #return True if want to exit 17 | rv = appWin.messageYesNo("Alert", "Do you want to quit ?" ) 18 | return rv 19 | 20 | def onAbout(event): 21 | appWin.messageBox("About", "Menu Demo\nzdiv") 22 | 23 | def onIdle(event): 24 | global runcount 25 | appWin.setStatusText("Idle Count : " + str(runcount)) 26 | runcount += 1 27 | 28 | menu_def = { 29 | "File" : { 30 | "Exit" : [ onExit, wx.ART_QUIT ], 31 | }, 32 | "Help" : { 33 | "About" : onAbout 34 | }, 35 | } 36 | 37 | body_def = [ 38 | [ ew.Label("Hello ezWxPython",expand=True,proportion=1,key='label'), 39 | { 'expand' : True, 'proportion' : 1 } ], 40 | ] 41 | 42 | status_def = [ 43 | ["Ready", -1], 44 | ] 45 | 46 | layout = { 47 | "menu" : menu_def, 48 | "body" : body_def, 49 | "status" : status_def, 50 | } 51 | 52 | ###################################################################### 53 | # Main 54 | ###################################################################### 55 | 56 | if __name__ == "__main__": 57 | appWin = ew.WxApp(u"Menu Demo", 320, 240) 58 | appWin.makeLayout(layout) 59 | initCtrls() 60 | appWin.closeHandle(onClose) 61 | appWin.idleHandle(onIdle) 62 | appWin.run() 63 | -------------------------------------------------------------------------------- /demo/Layout.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | def initCtrls(): 8 | ew.getWxCtrl('top1').SetBackgroundColour(wx.Colour(200,200,240)) 9 | ew.getWxCtrl('top2').SetBackgroundColour(wx.Colour(180,180,240)) 10 | ew.getWxCtrl('top3').SetBackgroundColour(wx.Colour(160,160,240)) 11 | ew.getWxCtrl('mid').SetBackgroundColour(wx.Colour(200,240,200)) 12 | ew.getWxCtrl('bottom1').SetBackgroundColour(wx.Colour(240,200,200)) 13 | ew.getWxCtrl('bottom21').SetBackgroundColour(wx.Colour(240,180,180)) 14 | ew.getWxCtrl('bottom22').SetBackgroundColour(wx.Colour(240,180,180)) 15 | ew.getWxCtrl('bottom23').SetBackgroundColour(wx.Colour(240,180,180)) 16 | ew.getWxCtrl('bottom3').SetBackgroundColour(wx.Colour(240,160,160)) 17 | 18 | def setStatusText(text,index=0): 19 | appWin.setStatusText(text,index) 20 | 21 | def onExit(event): 22 | appWin.close() 23 | 24 | def onClose(event): #return True if want to exit 25 | rv = appWin.messageYesNo("Alert", "Do you want to quit ?" ) 26 | return rv 27 | 28 | def onAbout(event): 29 | appWin.messageBox("About", "Menu Demo\nzdiv") 30 | 31 | def getMenuHandler(text): 32 | def onMenu(event): 33 | appWin.messageBox("Alert", text + ' Pressed') 34 | return onMenu 35 | 36 | menu_def = { 37 | "File" : { 38 | "Exit" : [ onExit, wx.ART_QUIT ], 39 | }, 40 | "Help" : { 41 | "About" : onAbout 42 | }, 43 | } 44 | 45 | body_def = [ 46 | [ ew.Label("Top1",expand=True,proportion=1,key='top1'), 47 | ew.Label("Top2",expand=True,proportion=2,key='top2'), 48 | ew.Label("Top3",expand=True,proportion=3,key='top3'), 49 | { 'expand' : True, 'proportion' : 1 } ], 50 | [ ew.Label("Mid",expand=True,proportion=1,key='mid'), 51 | { 'expand' : True, 'proportion' : 2 } ], 52 | [ ew.Line() ], 53 | [ ew.Label("Bottom1",expand=True,proportion=1,border=0,key='bottom1'), 54 | ew.Panel( [ 55 | [ ew.Label("Bottom21",expand=True,proportion=1,border=1, key='bottom21'), 56 | ew.Label("Bottom22",expand=True,proportion=1,border=1, key='bottom22'), 57 | ew.Label("Bottom23",expand=True,proportion=1,border=1, key='bottom23'), 58 | { 'expand' : True, 'proportion' : 1, 'border' : 0 } 59 | ], 60 | [ ew.Label("Bottom3",expand=True,proportion=1,border=0,key='bottom3'), 61 | { 'expand' : True, 'proportion' : 2, 'border' : 0 } 62 | ], 63 | ], expand=True,proportion=1, border=0), 64 | { 'expand' : True, 'proportion' : 3, 'border' : 0 } ], 65 | ] 66 | 67 | status_def = [ 68 | ["Ready", -1], 69 | ] 70 | 71 | layout = { 72 | "menu" : menu_def, 73 | "body" : body_def, 74 | "status" : status_def, 75 | } 76 | 77 | ###################################################################### 78 | # Main 79 | ###################################################################### 80 | 81 | if __name__ == "__main__": 82 | appWin = ew.WxApp(u"Menu Demo", 320, 240) 83 | appWin.makeLayout(layout) 84 | appWin.closeHandle(onClose) 85 | initCtrls() 86 | appWin.run() 87 | -------------------------------------------------------------------------------- /demo/LedNumber.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | number = 10 8 | 9 | def initCtrls(): 10 | global number 11 | number = 10 12 | 13 | def onExit(event): 14 | appWin.close() 15 | 16 | def onClose(event): #return True if want to exit 17 | rv = appWin.messageYesNo("Alert", "Do you want to quit ?" ) 18 | return rv 19 | 20 | def onAbout(event): 21 | appWin.messageBox("About", "Menu Demo\nzdiv") 22 | 23 | def onTimer(event): 24 | global number 25 | led = ew.getWxCtrl('led') 26 | led.SetValue("00:" + str(number)) 27 | number += 1 28 | 29 | menu_def = { 30 | "File" : { 31 | "Exit" : [ onExit, wx.ART_QUIT ], 32 | }, 33 | "Help" : { 34 | "About" : onAbout 35 | }, 36 | } 37 | 38 | body_def = [ 39 | [ ew.LedNumber(str(number),expand=True,proportion=1,key='led'), 40 | { 'expand' : True, 'proportion' : 1 } 41 | ], 42 | ] 43 | 44 | status_def = [ 45 | ["Ready", -1], 46 | ] 47 | 48 | layout = { 49 | "menu" : menu_def, 50 | "body" : body_def, 51 | "status" : status_def, 52 | } 53 | 54 | ###################################################################### 55 | # Main 56 | ###################################################################### 57 | 58 | if __name__ == "__main__": 59 | appWin = ew.WxApp(u"Menu Demo", 320, 320) 60 | appWin.makeLayout(layout) 61 | initCtrls() 62 | appWin.closeHandle(onClose) 63 | appWin.timerHandle(onTimer,1000,start=True,key='timer') 64 | appWin.run() 65 | -------------------------------------------------------------------------------- /demo/ListCtrl.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import ezWxPython as ezwx 5 | 6 | ###################################################################### 7 | # Global 8 | ###################################################################### 9 | 10 | window = None 11 | 12 | def findControls(): 13 | pass 14 | 15 | def setStatusText(text,index=0): 16 | if window is not None and window.statusbar is not None: 17 | if index < window.statusbar.GetFieldsCount(): 18 | window.statusbar.SetStatusText(text,index) 19 | 20 | ###################################################################### 21 | # Handler 22 | ###################################################################### 23 | 24 | def onExit(event): 25 | ezwx.WxAppClose() 26 | 27 | def onClose(event): #return True if want to exit 28 | rv = ezwx.MessageYesNo("Alert", "Do you want to quit ?" ) 29 | return rv 30 | 31 | def onAbout(event): 32 | ezwx.MessageBox("About", "StyledTextCtrl Demo\nzdiv") 33 | 34 | ###################################################################### 35 | # Layout 36 | ###################################################################### 37 | 38 | menu_def = { 39 | "File" : { 40 | "Exit" : onExit, 41 | }, 42 | "Help" : { 43 | "About" : onAbout 44 | }, 45 | } 46 | 47 | status_def = [ 48 | ["Ready", -1], 49 | ] 50 | 51 | body_def = [ 52 | [ ezwx.List([[('Name',100,-1),('Sex',32,0),('Age',64,1)], #label, width, align 53 | ["Willy","M","32"], 54 | ["Jane","F","28"], 55 | ], expand=True, proportion=1, multicol=True), 56 | { 'expand' : True, 'proportion' : 1 } ], 57 | ] 58 | 59 | layout = { 60 | "menu" : menu_def, 61 | "status" : status_def, 62 | "body" : body_def, 63 | } 64 | 65 | ###################################################################### 66 | # Main 67 | ###################################################################### 68 | 69 | if __name__ == "__main__": 70 | window = ezwx.WxApp(u"wxPython Template", 300, 200) 71 | window.makeLayout(layout) 72 | window.closeHandle(onClose) 73 | findControls() 74 | window.run() 75 | -------------------------------------------------------------------------------- /demo/MediaCtrl.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | addr = None 8 | web = None 9 | text = None 10 | 11 | def onExit(event): 12 | ew.WxAppClose() 13 | 14 | def onClose(event): 15 | return ew.MessageYesNo("Alert", "Do you want to quit ?" ) 16 | 17 | def onAbout(event): 18 | ew.MessageBox("About", "eezWxPython Demo\nzdiv") 19 | 20 | def onHome(event): 21 | web.Stop() 22 | 23 | def onForward(event): 24 | web.Play() 25 | 26 | def onGo(event): 27 | web.Load(addr.GetValue()) 28 | 29 | def findCtrls(): 30 | global addr, web, text 31 | addr = ew.getWxCtrl('addr') 32 | web = ew.getWxCtrl('web') 33 | text = ew.getWxCtrl('text') 34 | 35 | menu_def = { 36 | "File" : { 37 | "Exit" : [onExit, wx.ART_QUIT], 38 | }, 39 | "Help" : { 40 | "About" : [onAbout, wx.ART_HELP], 41 | }, 42 | } 43 | 44 | tool_def = [ #icon, text, handler 45 | [wx.ART_GO_HOME, onHome, "Home" ], 46 | [wx.ART_GO_FORWARD, onForward, "Forward" ], 47 | ] 48 | 49 | status_def = [ 50 | ["Ready", -1], 51 | ] 52 | 53 | url = r'D:/video.mp4' 54 | 55 | body_def = [ 56 | [ ew.Label ("Address: "), 57 | ew.Text (url,key="addr",expand=True,proportion=1), 58 | ew.Button("Go",handler=onGo), 59 | ], 60 | [ ew.VerticalSpliter([ 61 | 600, 62 | [ 63 | [ ew.Media(url,key='web',expand=True,proportion=1), 64 | { 'expand':True, 'proportion':1 } ], 65 | ], 66 | ], expand=True,proportion=1), 67 | { 'expand':True, 'proportion':1 } 68 | ], 69 | ] 70 | 71 | layout = { 72 | "menu" : menu_def, 73 | "tool" : tool_def, 74 | "status" : status_def, 75 | "body" : body_def, 76 | } 77 | 78 | 79 | if __name__ == "__main__": 80 | window = ew.WxApp(u"ezwxApp", 900, 620) 81 | window.makeLayout(layout) 82 | window.closeHandle(onClose) 83 | findCtrls() 84 | window.run() 85 | 86 | -------------------------------------------------------------------------------- /demo/MenuBar.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | def initCtrls(): 8 | global label 9 | label = ew.getWxCtrl('label') 10 | label.SetBackgroundColour(wx.Colour(200,200,240)) 11 | 12 | def setStatusText(text,index=0): 13 | appWin.setStatusText(text,index) 14 | 15 | def onExit(event): 16 | appWin.close() 17 | 18 | def onClose(event): #return True if want to exit 19 | rv = appWin.messageYesNo("Alert", "Do you want to quit ?" ) 20 | return rv 21 | 22 | def onAbout(event): 23 | appWin.messageBox("About", "Menu Demo\nzdiv") 24 | 25 | def getMenuHandler(text): 26 | def onMenu(event): 27 | appWin.messageBox("Alert", text + ' Pressed') 28 | return onMenu 29 | 30 | menu_def = { 31 | "File" : { 32 | "Options" : { "Option1" : getMenuHandler("Option1"), 33 | "Option2" : { 34 | "Option2-1" : getMenuHandler("Option2-1"), 35 | "Option2-2" : getMenuHandler("Option2-2"), 36 | } 37 | }, 38 | "Settings" : None, 39 | "-" : None, 40 | "Exit" : [ onExit, wx.ART_QUIT ], 41 | }, 42 | "Help" : { 43 | "About" : onAbout 44 | }, 45 | } 46 | 47 | body_def = [ 48 | [ ew.Label("Hello ezWxPython",expand=True,proportion=1,key='label'), 49 | { 'expand' : True, 'proportion' : 1 } ], 50 | ] 51 | 52 | status_def = [ 53 | ["Ready", -1], 54 | ] 55 | 56 | layout = { 57 | "menu" : menu_def, 58 | "body" : body_def, 59 | "status" : status_def, 60 | } 61 | 62 | ###################################################################### 63 | # Main 64 | ###################################################################### 65 | 66 | if __name__ == "__main__": 67 | appWin = ew.WxApp(u"Menu Demo", 320, 240) 68 | appWin.makeLayout(layout) 69 | appWin.closeHandle(onClose) 70 | initCtrls() 71 | appWin.run() 72 | -------------------------------------------------------------------------------- /demo/MultiSplitWindow.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | def initCtrls(): 8 | ew.getWxCtrl('top1').SetBackgroundColour(wx.Colour(200,200,240)) 9 | ew.getWxCtrl('top2').SetBackgroundColour(wx.Colour(180,180,240)) 10 | ew.getWxCtrl('top3').SetBackgroundColour(wx.Colour(160,160,240)) 11 | ew.getWxCtrl('mid').SetBackgroundColour(wx.Colour(200,240,200)) 12 | ew.getWxCtrl('mid2').SetBackgroundColour(wx.Colour(200,240,240)) 13 | ew.getWxCtrl('bottom1').SetBackgroundColour(wx.Colour(240,200,200)) 14 | ew.getWxCtrl('bottom21').SetBackgroundColour(wx.Colour(240,180,180)) 15 | ew.getWxCtrl('bottom22').SetBackgroundColour(wx.Colour(240,180,180)) 16 | ew.getWxCtrl('bottom23').SetBackgroundColour(wx.Colour(240,180,180)) 17 | ew.getWxCtrl('bottom3').SetBackgroundColour(wx.Colour(240,160,160)) 18 | ew.getWxCtrl('extra1').SetBackgroundColour(wx.Colour(240,240,200)) 19 | ew.getWxCtrl('extra21').SetBackgroundColour(wx.Colour(240,240,180)) 20 | ew.getWxCtrl('extra22').SetBackgroundColour(wx.Colour(240,240,180)) 21 | ew.getWxCtrl('extra23').SetBackgroundColour(wx.Colour(240,240,180)) 22 | ew.getWxCtrl('extra3').SetBackgroundColour(wx.Colour(240,240,160)) 23 | 24 | def onExit(event): 25 | appWin.close() 26 | 27 | def onClose(event): #return True if want to exit 28 | rv = appWin.messageYesNo("Alert", "Do you want to quit ?" ) 29 | return rv 30 | 31 | def onAbout(event): 32 | appWin.messageBox("About", "Splitter Demo\nzdiv") 33 | 34 | menu_def = { 35 | "File" : { 36 | "Exit" : [ onExit, wx.ART_QUIT ], 37 | }, 38 | "Help" : { 39 | "About" : onAbout 40 | }, 41 | } 42 | 43 | body_def_1 = [ 44 | ew.HorizontalMultiSpliter( [ 45 | 120, 46 | [ 47 | [ 48 | ew.Label("Top1",expand=True,proportion=1,key='top1'), 49 | ew.Label("Top2",expand=True,proportion=2,key='top2'), 50 | ew.Label("Top3",expand=True,proportion=3,key='top3'), 51 | { 'expand' : True, 'proportion' : 1 } 52 | ] 53 | ], 54 | 60, 55 | [ 56 | [ 57 | ew.Label("Mid",expand=True,proportion=1,key='mid'), 58 | { 'expand' : True, 'proportion' : 1 } 59 | ] 60 | ], 61 | 60, 62 | [ 63 | [ 64 | ew.Label("Mid2",expand=True,proportion=1,key='mid2'), 65 | { 'expand' : True, 'proportion' : 1 } 66 | ] 67 | ], 68 | ], expand=True,proportion=1 ), 69 | { 'expand' : True, 'proportion' : 1 } 70 | ] 71 | 72 | body_def_2 = [ 73 | ew.Label("Bottom1",expand=True,proportion=1,border=0,key='bottom1'), 74 | ew.Panel( [ 75 | [ ew.Label("Bottom21",expand=True,proportion=1,border=1, key='bottom21'), 76 | ew.Label("Bottom22",expand=True,proportion=1,border=1, key='bottom22'), 77 | ew.Label("Bottom23",expand=True,proportion=1,border=1, key='bottom23'), 78 | { 'expand' : True, 'proportion' : 1, 'border' : 0 } 79 | ], 80 | [ ew.Label("Bottom3",expand=True,proportion=1,border=0,key='bottom3'), 81 | { 'expand' : True, 'proportion' : 2, 'border' : 0 } 82 | ], 83 | ], expand=True,proportion=1, border=0), 84 | { 'expand' : True, 'proportion' : 1, 'border' : 0 } 85 | ] 86 | 87 | 88 | body_def_3 = [ 89 | ew.Label("Extra1",expand=True,proportion=1,border=0,key='extra1'), 90 | ew.Panel( [ 91 | [ ew.Label("Extra21",expand=True,proportion=1,border=1, key='extra21'), 92 | ew.Label("Extra22",expand=True,proportion=1,border=1, key='extra22'), 93 | ew.Label("Extra23",expand=True,proportion=1,border=1, key='extra23'), 94 | { 'expand' : True, 'proportion' : 1, 'border' : 0 } 95 | ], 96 | [ ew.Label("Extra3",expand=True,proportion=1,border=0,key='extra3'), 97 | { 'expand' : True, 'proportion' : 2, 'border' : 0 } 98 | ], 99 | ], expand=True,proportion=1, border=0), 100 | { 'expand' : True, 'proportion' : 1, 'border' : 0 } 101 | ] 102 | 103 | body_def = [ 104 | [ 105 | ew.VerticalMultiSpliter( [ 106 | 160, 107 | [ body_def_1 ], 108 | 160, 109 | [ body_def_2 ], 110 | 160, 111 | [ body_def_3 ], 112 | ], expand=True, proportion=1, key='book'), 113 | { 'expand' : True, 'proportion' : 1, 'border' : 0 } 114 | ], 115 | ] 116 | 117 | status_def = [ 118 | ["Ready", -1], 119 | ] 120 | 121 | layout = { 122 | "menu" : menu_def, 123 | "body" : body_def, 124 | "status" : status_def, 125 | } 126 | 127 | ###################################################################### 128 | # Main 129 | ###################################################################### 130 | 131 | if __name__ == "__main__": 132 | appWin = ew.WxApp(u"Splitter Demo", 480, 360) 133 | appWin.makeLayout(layout) 134 | appWin.closeHandle(onClose) 135 | initCtrls() 136 | appWin.run() 137 | -------------------------------------------------------------------------------- /demo/NoFrame.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | def initCtrls(): 8 | global label, idlecount, timercount 9 | label = ew.getWxCtrl('label') 10 | label.SetBackgroundColour(wx.Colour(200,200,240)) 11 | idlecount = 0 12 | timercount = 0 13 | 14 | def onExit(event): 15 | appWin.close() 16 | 17 | def onClose(event): #return True if want to exit 18 | rv = appWin.messageYesNo("Alert", "Do you want to quit ?" ) 19 | return rv 20 | 21 | def onAbout(event): 22 | appWin.messageBox("About", "Menu Demo\nzdiv") 23 | 24 | menu_def = { 25 | "File" : { 26 | "Exit" : [ onExit, wx.ART_QUIT ], 27 | }, 28 | "Help" : { 29 | "About" : onAbout 30 | }, 31 | } 32 | 33 | body_def = [ 34 | [ ew.Label("Hello ezWxPython",expand=True,proportion=1,key='label'), 35 | { 'expand' : True, 'proportion' : 1 } ], 36 | ] 37 | 38 | layout = { 39 | "body" : body_def, 40 | } 41 | 42 | ###################################################################### 43 | # Main 44 | ###################################################################### 45 | 46 | if __name__ == "__main__": 47 | appWin = ew.WxApp(u"Menu Demo", 320, 240) 48 | appWin.makeLayout(layout) 49 | initCtrls() 50 | appWin.closeHandle(onClose) 51 | appWin.noCaption() 52 | appWin.dragEnable('label') 53 | appWin.contextMenu(menu_def,'label') 54 | appWin.run() 55 | -------------------------------------------------------------------------------- /demo/Notebook.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | def initCtrls(): 8 | ew.getWxCtrl('top1').SetBackgroundColour(wx.Colour(200,200,240)) 9 | ew.getWxCtrl('top2').SetBackgroundColour(wx.Colour(180,180,240)) 10 | ew.getWxCtrl('top3').SetBackgroundColour(wx.Colour(160,160,240)) 11 | ew.getWxCtrl('mid').SetBackgroundColour(wx.Colour(200,240,200)) 12 | ew.getWxCtrl('bottom1').SetBackgroundColour(wx.Colour(240,200,200)) 13 | ew.getWxCtrl('bottom21').SetBackgroundColour(wx.Colour(240,180,180)) 14 | ew.getWxCtrl('bottom22').SetBackgroundColour(wx.Colour(240,180,180)) 15 | ew.getWxCtrl('bottom23').SetBackgroundColour(wx.Colour(240,180,180)) 16 | ew.getWxCtrl('bottom3').SetBackgroundColour(wx.Colour(240,160,160)) 17 | 18 | def setStatusText(text,index=0): 19 | appWin.setStatusText(text,index) 20 | 21 | def onExit(event): 22 | appWin.close() 23 | 24 | def onClose(event): #return True if want to exit 25 | rv = appWin.messageYesNo("Alert", "Do you want to quit ?" ) 26 | return rv 27 | 28 | def onAbout(event): 29 | appWin.messageBox("About", "Menu Demo\nzdiv") 30 | 31 | def getMenuHandler(text): 32 | def onMenu(event): 33 | appWin.messageBox("Alert", text + ' Pressed') 34 | return onMenu 35 | 36 | menu_def = { 37 | "File" : { 38 | "Exit" : [ onExit, wx.ART_QUIT ], 39 | }, 40 | "Help" : { 41 | "About" : onAbout 42 | }, 43 | } 44 | 45 | body_def = [ 46 | [ ew.Notebook( [ 47 | "Note1", [ 48 | [ ew.Label("Top1",expand=True,proportion=1,key='top1'), 49 | ew.Label("Top2",expand=True,proportion=2,key='top2'), 50 | ew.Label("Top3",expand=True,proportion=3,key='top3'), 51 | { 'expand' : True, 'proportion' : 1 } 52 | ], 53 | [ ew.Label("Mid",expand=True,proportion=1,key='mid'), 54 | { 'expand' : True, 'proportion' : 2 } 55 | ], 56 | ], 57 | "Note2", [ 58 | [ ew.Label("Bottom1",expand=True,proportion=1,border=0,key='bottom1'), 59 | ew.Panel( [ 60 | [ ew.Label("Bottom21",expand=True,proportion=1,border=1, key='bottom21'), 61 | ew.Label("Bottom22",expand=True,proportion=1,border=1, key='bottom22'), 62 | ew.Label("Bottom23",expand=True,proportion=1,border=1, key='bottom23'), 63 | { 'expand' : True, 'proportion' : 1, 'border' : 0 } 64 | ], 65 | [ ew.Label("Bottom3",expand=True,proportion=1,border=0,key='bottom3'), 66 | { 'expand' : True, 'proportion' : 2, 'border' : 0 } 67 | ], 68 | ], expand=True,proportion=1, border=0), 69 | { 'expand' : True, 'proportion' : 3, 'border' : 0 } 70 | ], 71 | ], 72 | ], expand=True, proportion=1), 73 | { 'expand' : True, 'proportion' : 3, 'border' : 0 } 74 | ] 75 | ] 76 | 77 | status_def = [ 78 | ["Ready", -1], 79 | ] 80 | 81 | layout = { 82 | "menu" : menu_def, 83 | "body" : body_def, 84 | "status" : status_def, 85 | } 86 | 87 | ###################################################################### 88 | # Main 89 | ###################################################################### 90 | 91 | if __name__ == "__main__": 92 | appWin = ew.WxApp(u"Menu Demo", 320, 240) 93 | appWin.makeLayout(layout) 94 | appWin.closeHandle(onClose) 95 | initCtrls() 96 | appWin.run() 97 | -------------------------------------------------------------------------------- /demo/PdfView.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | addr = None 8 | web = None 9 | text = None 10 | 11 | def onExit(event): 12 | ew.WxAppClose() 13 | 14 | def onClose(event): 15 | return ew.MessageYesNo("Alert", "Do you want to quit ?" ) 16 | 17 | def onAbout(event): 18 | ew.MessageBox("About", "eezWxPython Demo\nzdiv") 19 | 20 | def onBack(event): 21 | web.PageUp() 22 | 23 | def onForward(event): 24 | web.PageDown() 25 | 26 | def onGo(event): 27 | web.LoadFile(addr.GetValue()) 28 | 29 | def findCtrls(): 30 | global addr, web, text 31 | addr = ew.getWxCtrl('addr') 32 | web = ew.getWxCtrl('web') 33 | text = ew.getWxCtrl('text') 34 | 35 | menu_def = { 36 | "File" : { 37 | "Exit" : [onExit, wx.ART_QUIT], 38 | }, 39 | "Help" : { 40 | "About" : [onAbout, wx.ART_HELP], 41 | }, 42 | } 43 | 44 | tool_def = [ #icon, text, handler 45 | [wx.ART_GO_BACK, onBack, "Back" ], 46 | [wx.ART_GO_FORWARD, onForward, "Forward" ], 47 | ] 48 | 49 | status_def = [ 50 | ["Ready", -1], 51 | ] 52 | 53 | url = r'D:/a.pdf' 54 | 55 | body_def = [ 56 | [ ew.Label ("Address: "), 57 | ew.Text (url,key="addr",expand=True,proportion=1), 58 | ew.Button("Go",handler=onGo), 59 | ], 60 | [ ew.VerticalSpliter([ 61 | 600, 62 | [ 63 | [ ew.PdfView(url,key='web',expand=True,proportion=1), 64 | { 'expand':True, 'proportion':1 } ], 65 | ], 66 | 300, 67 | [ 68 | [ ew.StyledText(key='text',expand=True,proportion=1), 69 | { 'expand':True, 'proportion':1 }], 70 | ], 71 | ], expand=True,proportion=1), 72 | { 'expand':True, 'proportion':1 } 73 | ], 74 | ] 75 | 76 | layout = { 77 | "menu" : menu_def, 78 | "tool" : tool_def, 79 | "status" : status_def, 80 | "body" : body_def, 81 | } 82 | 83 | 84 | if __name__ == "__main__": 85 | window = ew.WxApp(u"ezwxApp", 900, 620) 86 | window.makeLayout(layout) 87 | window.closeHandle(onClose) 88 | findCtrls() 89 | window.run() 90 | 91 | -------------------------------------------------------------------------------- /demo/PickerCtrl.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import ezWxPython as ezwx 5 | 6 | ###################################################################### 7 | # Global 8 | ###################################################################### 9 | 10 | window = None 11 | 12 | def setStatusText(text,index=0): 13 | if window is not None and window.statusbar is not None: 14 | if index < window.statusbar.GetFieldsCount(): 15 | window.statusbar.SetStatusText(text,index) 16 | 17 | ###################################################################### 18 | # Handler 19 | ###################################################################### 20 | 21 | def onExit(event): 22 | ezwx.WxAppClose() 23 | 24 | def onClose(event): #return True if want to exit 25 | rv = ezwx.MessageYesNo("Alert", "Do you want to quit ?" ) 26 | return rv 27 | 28 | def onAbout(event): 29 | ezwx.MessageBox("About", "StyledTextCtrl Demo\nzdiv") 30 | 31 | def onDirSelect(event): 32 | ctrl = ezwx.getWxCtrl('dir') 33 | print(event.GetPath()) 34 | print(ctrl.GetPath()) 35 | 36 | def onFileSelect(event): 37 | ctrl = ezwx.getWxCtrl('file') 38 | print(event.GetPath()) 39 | print(ctrl.GetPath()) 40 | 41 | def onDateSelect(event): 42 | ctrl = ezwx.getWxCtrl('date') 43 | print(event.GetDate()) 44 | print(ctrl.GetValue()) 45 | 46 | def onTimeSelect(event): 47 | ctrl = ezwx.getWxCtrl('time') 48 | print(event.GetDate()) 49 | print(ctrl.GetValue()) 50 | 51 | def onColorSelect(event): 52 | ctrl = ezwx.getWxCtrl('color') 53 | print(event.GetColour()) 54 | print(ctrl.GetColour()) 55 | 56 | def onFontSelect(event): 57 | ctrl = ezwx.getWxCtrl('font') 58 | font = event.GetFont() 59 | print(font.GetFaceName(), font.GetFamily(), font.GetPixelSize(), font.GetPointSize()) 60 | font = ctrl.GetSelectedFont() 61 | print(font.GetFaceName(), font.GetFamily(), font.GetPixelSize(), font.GetPointSize()) 62 | font = ctrl.GetFont() 63 | print(font.GetFaceName(), font.GetFamily(), font.GetPixelSize(), font.GetPointSize()) 64 | 65 | 66 | def onDirSelect2(event): 67 | ctrl = ezwx.getWxCtrl('dir2') 68 | print(event.GetPath()) 69 | print(ctrl.GetPath()) 70 | 71 | def onFileSelect2(event): 72 | ctrl = ezwx.getWxCtrl('file2') 73 | print(event.GetPath()) 74 | print(ctrl.GetPath()) 75 | 76 | def onDateSelect2(event): 77 | ctrl = ezwx.getWxCtrl('date2') 78 | print(event.GetDate()) 79 | print(ctrl.GetValue()) 80 | 81 | def onTimeSelect2(event): 82 | ctrl = ezwx.getWxCtrl('time2') 83 | print(event.GetDate()) 84 | print(ctrl.GetValue()) 85 | 86 | def onColorSelect2(event): 87 | ctrl = ezwx.getWxCtrl('color2') 88 | print(event.GetColour()) 89 | print(ctrl.GetColour()) 90 | 91 | def onFontSelect2(event): 92 | ctrl = ezwx.getWxCtrl('font2') 93 | font = event.GetFont() 94 | print(font.GetFaceName(), font.GetFamily(), font.GetPixelSize(), font.GetPointSize()) 95 | font = ctrl.GetSelectedFont() 96 | print(font.GetFaceName(), font.GetFamily(), font.GetPixelSize(), font.GetPointSize()) 97 | font = ctrl.GetFont() 98 | print(font.GetFaceName(), font.GetFamily(), font.GetPixelSize(), font.GetPointSize()) 99 | 100 | ###################################################################### 101 | # Layout 102 | ###################################################################### 103 | 104 | menu_def = { 105 | "File" : { 106 | "Exit" : onExit, 107 | }, 108 | "Help" : { 109 | "About" : onAbout 110 | }, 111 | } 112 | 113 | status_def = [ 114 | ["Ready", -1], 115 | ] 116 | 117 | body_def = [ 118 | [ ezwx.Picker("dir", expand=True, proportion=1, handler=onDirSelect, key="dir"),], 119 | [ ezwx.Picker("file", expand=True, proportion=1, handler=onFileSelect, key="file"),], 120 | [ ezwx.Picker("date",expand=True, handler=onDateSelect, key="date"),], 121 | [ ezwx.Picker("time",expand=True, handler=onTimeSelect, key="time"),], 122 | [ ezwx.Picker("color",expand=True, handler=onColorSelect, key="color"),], 123 | [ ezwx.Picker("font", expand=True, size=(240,72), handler=onFontSelect, key="font"),], 124 | [ ezwx.Line(),], 125 | [ ezwx.DirPicker(expand=True, proportion=1, handler=onDirSelect2, key="dir2"),], 126 | [ ezwx.FilePicker(expand=True, proportion=1, handler=onFileSelect2, key="file2"),], 127 | [ ezwx.DatePicker(expand=True, handler=onDateSelect2, key="date2"),], 128 | [ ezwx.TimePicker(expand=True, handler=onTimeSelect2, key="time2"),], 129 | [ ezwx.ColorPicker(expand=True, handler=onColorSelect2, key="color2"),], 130 | [ ezwx.FontPicker(expand=True, size=(240,72), handler=onFontSelect2, key="font2"),], 131 | ] 132 | 133 | 134 | layout = { 135 | "menu" : menu_def, 136 | "status" : status_def, 137 | "body" : body_def, 138 | } 139 | 140 | ###################################################################### 141 | # Main 142 | ###################################################################### 143 | 144 | if __name__ == "__main__": 145 | window = ezwx.WxApp(u"wxPython Template", 480, 480) 146 | window.makeLayout(layout) 147 | window.closeHandle(onClose) 148 | window.run() 149 | -------------------------------------------------------------------------------- /demo/PopupWindow.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | def initCtrls(): 8 | global label, idlecount, timercount 9 | label = ew.getWxCtrl('label') 10 | label.SetBackgroundColour(wx.Colour(200,200,240)) 11 | idlecount = 0 12 | timercount = 0 13 | 14 | def onExit(event): 15 | appWin.close() 16 | 17 | def onClose(event): #return True if want to exit 18 | rv = appWin.messageYesNo("Alert", "Do you want to quit ?" ) 19 | return rv 20 | 21 | def onAbout(event): 22 | appWin.messageBox("About", "Menu Demo\nzdiv") 23 | 24 | # Popup Window 25 | 26 | def onPopupExit(event): 27 | popup_window.close() 28 | 29 | popup_menu_def = { 30 | "Exit" : [onPopupExit, None], # Menu item with base64-encoded icon image 31 | } 32 | 33 | popup_body_def = [ 34 | [ ew.Label("Hello ezWxPython",expand=True,proportion=1,key='popup_label'), 35 | { 'expand' : True, 'proportion' : 1 } ], 36 | ] 37 | 38 | popup_layout = { 39 | "body" : popup_body_def, 40 | } 41 | 42 | def onPopup(event): 43 | global popup_window 44 | popup_window = ew.WxPopup(u"Popup Window", 200, 160) 45 | popup_window.makeLayout(popup_layout) 46 | label = ew.getWxCtrl('popup_label') 47 | label.SetBackgroundColour(wx.Colour(200,240,240)) 48 | popup_window.show() 49 | 50 | def onMini(event): 51 | appWin.messageBox("About", "Menu Demo\nzdiv") 52 | 53 | menu_def = { 54 | "File" : { 55 | "Exit" : [ onExit, wx.ART_QUIT ], 56 | }, 57 | "Help" : { 58 | "About" : onAbout 59 | }, 60 | } 61 | 62 | body_def = [ 63 | [ ew.Label("Hello ezWxPython",expand=True,proportion=1,key='label'), 64 | { 'expand' : True, 'proportion' : 1 } ], 65 | [ ew.Button("Popup Window",handler=onPopup,expand=True,proportion=1,), 66 | ], 67 | ] 68 | 69 | status_def = [ 70 | ["Ready", -1], 71 | ] 72 | 73 | layout = { 74 | "menu" : menu_def, 75 | "body" : body_def, 76 | "status" : status_def, 77 | } 78 | 79 | ###################################################################### 80 | # Main 81 | ###################################################################### 82 | 83 | if __name__ == "__main__": 84 | appWin = ew.WxApp(u"Menu Demo", 320, 240) 85 | appWin.makeLayout(layout) 86 | initCtrls() 87 | appWin.closeHandle(onClose) 88 | appWin.run() 89 | -------------------------------------------------------------------------------- /demo/ProgressDialog.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import threading 5 | import ezWxPython as ezwx 6 | 7 | ###################################################################### 8 | # Global 9 | ###################################################################### 10 | 11 | title = u"Progress Dialog Demo" 12 | window = None 13 | 14 | def setStatusText(text,index=0): 15 | if window is not None and window.statusbar is not None: 16 | if index < window.statusbar.GetFieldsCount(): 17 | window.statusbar.SetStatusText(text,index) 18 | 19 | ###################################################################### 20 | # Handler 21 | ###################################################################### 22 | 23 | def onExit(event): 24 | ezwx.WxAppClose() 25 | 26 | def onClose(event): #return True if want to exit 27 | rv = ezwx.MessageYesNo("Alert", "Do you want to quit ?" ) 28 | return rv 29 | 30 | def onAbout(event): 31 | ezwx.MessageBox("About", title + "\nzdiv") 32 | 33 | def threadProgress(progress): 34 | for i in range(0,101): 35 | ezwx.progressDialogUpdate(progress,i) 36 | time.sleep(0.05) 37 | 38 | def onButton(event): 39 | progress = ezwx.ProgressDialog("Progress","Progress Dialog Demo") 40 | thread = threading.Thread(target=threadProgress, args=(progress,)) 41 | thread.daemon = True 42 | thread.start() 43 | 44 | ###################################################################### 45 | # Layout 46 | ###################################################################### 47 | 48 | menu_def = { 49 | "File" : { 50 | "Exit" : onExit, 51 | }, 52 | "Help" : { 53 | "About" : onAbout 54 | }, 55 | } 56 | 57 | status_def = [ 58 | ["Ready", -1], 59 | ] 60 | 61 | body_def = [ 62 | [ ezwx.Button("Show Progress",expand=True,proportion=1,handler=onButton,key="button"), 63 | { 'expand' : True, 'proportion' : 1 } ], 64 | ] 65 | 66 | layout = { 67 | "menu" : menu_def, 68 | "status" : status_def, 69 | "body" : body_def, 70 | } 71 | 72 | ###################################################################### 73 | # Main 74 | ###################################################################### 75 | 76 | if __name__ == "__main__": 77 | window = ezwx.WxApp(title, 120, 120) 78 | window.makeLayout(layout) 79 | window.closeHandle(onClose) 80 | window.run() 81 | -------------------------------------------------------------------------------- /demo/ProgressIndicator.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import threading 5 | import ezWxPython as ezwx 6 | 7 | ###################################################################### 8 | # Global 9 | ###################################################################### 10 | 11 | title = u"Progress Dialog Demo" 12 | window = None 13 | 14 | def setStatusText(text,index=0): 15 | if window is not None and window.statusbar is not None: 16 | if index < window.statusbar.GetFieldsCount(): 17 | window.statusbar.SetStatusText(text,index) 18 | 19 | ###################################################################### 20 | # Handler 21 | ###################################################################### 22 | 23 | def onExit(event): 24 | ezwx.WxAppClose() 25 | 26 | def onClose(event): #return True if want to exit 27 | rv = ezwx.MessageYesNo("Alert", "Do you want to quit ?" ) 28 | return rv 29 | 30 | def onAbout(event): 31 | ezwx.MessageBox("About", title + "\nzdiv") 32 | 33 | def threadProgress(progress): 34 | for i in range(0,301): 35 | progress.update(i) 36 | time.sleep(0.01) 37 | 38 | def onButton(event): 39 | progress = ezwx.getCtrl('progress') 40 | progress.setMaxValue(300) 41 | thread = threading.Thread(target=threadProgress, args=(progress,)) 42 | thread.daemon = True 43 | thread.start() 44 | 45 | ###################################################################### 46 | # Layout 47 | ###################################################################### 48 | 49 | menu_def = { 50 | "File" : { 51 | "Exit" : onExit, 52 | }, 53 | "Help" : { 54 | "About" : onAbout 55 | }, 56 | } 57 | 58 | status_def = [ 59 | ["Ready", -1], 60 | ] 61 | 62 | body_def = [ 63 | [ ezwx.Progress(expand=True,proportion=1,key="progress"), ], 64 | [ ezwx.Button("Show Progress",expand=True,proportion=1,handler=onButton,key="button"), 65 | { 'expand' : True, 'proportion' : 1 } ], 66 | ] 67 | 68 | layout = { 69 | "menu" : menu_def, 70 | "status" : status_def, 71 | "body" : body_def, 72 | } 73 | 74 | ###################################################################### 75 | # Main 76 | ###################################################################### 77 | 78 | if __name__ == "__main__": 79 | window = ezwx.WxApp(title, 120, 160) 80 | window.makeLayout(layout) 81 | window.closeHandle(onClose) 82 | window.run() 83 | -------------------------------------------------------------------------------- /demo/SimpleFrame.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | def initCtrls(): 8 | global label, idlecount, timercount 9 | label = ew.getWxCtrl('label') 10 | label.SetBackgroundColour(wx.Colour(200,200,240)) 11 | idlecount = 0 12 | timercount = 0 13 | 14 | def onExit(event): 15 | appWin.close() 16 | 17 | def onClose(event): #return True if want to exit 18 | rv = appWin.messageYesNo("Alert", "Do you want to quit ?" ) 19 | return rv 20 | 21 | def onAbout(event): 22 | appWin.messageBox("About", "Menu Demo\nzdiv") 23 | 24 | menu_def = { 25 | "File" : { 26 | "Exit" : [ onExit, wx.ART_QUIT ], 27 | }, 28 | "Help" : { 29 | "About" : onAbout 30 | }, 31 | } 32 | 33 | body_def = [ 34 | [ ew.Label("Hello ezWxPython",expand=True,proportion=1,key='label'), 35 | { 'expand' : True, 'proportion' : 1 } ], 36 | ] 37 | 38 | status_def = [ 39 | ["Ready", -1], 40 | ] 41 | 42 | layout = { 43 | "menu" : menu_def, 44 | "body" : body_def, 45 | "status" : status_def, 46 | } 47 | 48 | ###################################################################### 49 | # Main 50 | ###################################################################### 51 | 52 | if __name__ == "__main__": 53 | appWin = ew.WxApp(u"Menu Demo", 320, 240) 54 | appWin.makeLayout(layout) 55 | initCtrls() 56 | appWin.closeHandle(onClose) 57 | appWin.run() 58 | -------------------------------------------------------------------------------- /demo/Simplebook.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | def initCtrls(): 8 | ew.getWxCtrl('top1').SetBackgroundColour(wx.Colour(200,200,240)) 9 | ew.getWxCtrl('top2').SetBackgroundColour(wx.Colour(180,180,240)) 10 | ew.getWxCtrl('top3').SetBackgroundColour(wx.Colour(160,160,240)) 11 | ew.getWxCtrl('mid').SetBackgroundColour(wx.Colour(200,240,200)) 12 | ew.getWxCtrl('bottom1').SetBackgroundColour(wx.Colour(240,200,200)) 13 | ew.getWxCtrl('bottom21').SetBackgroundColour(wx.Colour(240,180,180)) 14 | ew.getWxCtrl('bottom22').SetBackgroundColour(wx.Colour(240,180,180)) 15 | ew.getWxCtrl('bottom23').SetBackgroundColour(wx.Colour(240,180,180)) 16 | ew.getWxCtrl('bottom3').SetBackgroundColour(wx.Colour(240,160,160)) 17 | 18 | def onExit(event): 19 | appWin.close() 20 | 21 | def onClose(event): #return True if want to exit 22 | rv = appWin.messageYesNo("Alert", "Do you want to quit ?" ) 23 | return rv 24 | 25 | def onAbout(event): 26 | appWin.messageBox("About", "SimpleBook Demo\nzdiv") 27 | 28 | def onBook1(event): 29 | effect = appWin.getSelectedText('effect') 30 | appWin.setBookEffect('book',effect) 31 | appWin.setBookPage('book',0) 32 | 33 | def onBook2(event): 34 | effect = appWin.getSelectedText('effect') 35 | appWin.setBookEffect('book',effect) 36 | appWin.setBookPage('book',1) 37 | 38 | menu_def = { 39 | "File" : { 40 | "Exit" : [ onExit, wx.ART_QUIT ], 41 | }, 42 | "Help" : { 43 | "About" : onAbout 44 | }, 45 | } 46 | 47 | body_def = [ 48 | [ ew.Choice(['slide_to_left','slide_to_right','slide_to_top','slide_to_bottom', 49 | 'roll_to_left','roll_to_right','roll_to_top','roll_to_bottom', 50 | 'blend', 'expand', 'none', ], key='effect'), 51 | ew.Button('Book1', handler=onBook1), 52 | ew.Button('Book2', handler=onBook2), 53 | ], 54 | [ ew.Simplebook( [ 55 | [ 56 | [ ew.Label("Top1",expand=True,proportion=1,key='top1'), 57 | ew.Label("Top2",expand=True,proportion=2,key='top2'), 58 | ew.Label("Top3",expand=True,proportion=3,key='top3'), 59 | { 'expand' : True, 'proportion' : 1 } 60 | ], 61 | [ ew.Label("Mid",expand=True,proportion=1,key='mid'), 62 | { 'expand' : True, 'proportion' : 2 } 63 | ], 64 | ], 65 | [ 66 | [ ew.Label("Bottom1",expand=True,proportion=1,border=0,key='bottom1'), 67 | ew.Panel( [ 68 | [ ew.Label("Bottom21",expand=True,proportion=1,border=1, key='bottom21'), 69 | ew.Label("Bottom22",expand=True,proportion=1,border=1, key='bottom22'), 70 | ew.Label("Bottom23",expand=True,proportion=1,border=1, key='bottom23'), 71 | { 'expand' : True, 'proportion' : 1, 'border' : 0 } 72 | ], 73 | [ ew.Label("Bottom3",expand=True,proportion=1,border=0,key='bottom3'), 74 | { 'expand' : True, 'proportion' : 2, 'border' : 0 } 75 | ], 76 | ], expand=True,proportion=1, border=0), 77 | { 'expand' : True, 'proportion' : 3, 'border' : 0 } 78 | ], 79 | ], 80 | ], expand=True, proportion=1, key='book'), 81 | { 'expand' : True, 'proportion' : 1, 'border' : 0 } 82 | ] 83 | ] 84 | 85 | status_def = [ 86 | ["Ready", -1], 87 | ] 88 | 89 | layout = { 90 | "menu" : menu_def, 91 | "body" : body_def, 92 | "status" : status_def, 93 | } 94 | 95 | ###################################################################### 96 | # Main 97 | ###################################################################### 98 | 99 | if __name__ == "__main__": 100 | appWin = ew.WxApp(u"SimpleBook Demo", 320, 240) 101 | appWin.makeLayout(layout) 102 | appWin.closeHandle(onClose) 103 | initCtrls() 104 | appWin.run() 105 | -------------------------------------------------------------------------------- /demo/SplitWindow.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | def initCtrls(): 8 | ew.getWxCtrl('top1').SetBackgroundColour(wx.Colour(200,200,240)) 9 | ew.getWxCtrl('top2').SetBackgroundColour(wx.Colour(180,180,240)) 10 | ew.getWxCtrl('top3').SetBackgroundColour(wx.Colour(160,160,240)) 11 | ew.getWxCtrl('mid').SetBackgroundColour(wx.Colour(200,240,200)) 12 | ew.getWxCtrl('bottom1').SetBackgroundColour(wx.Colour(240,200,200)) 13 | ew.getWxCtrl('bottom21').SetBackgroundColour(wx.Colour(240,180,180)) 14 | ew.getWxCtrl('bottom22').SetBackgroundColour(wx.Colour(240,180,180)) 15 | ew.getWxCtrl('bottom23').SetBackgroundColour(wx.Colour(240,180,180)) 16 | ew.getWxCtrl('bottom3').SetBackgroundColour(wx.Colour(240,160,160)) 17 | 18 | def onExit(event): 19 | appWin.close() 20 | 21 | def onClose(event): #return True if want to exit 22 | rv = appWin.messageYesNo("Alert", "Do you want to quit ?" ) 23 | return rv 24 | 25 | def onAbout(event): 26 | appWin.messageBox("About", "Splitter Demo\nzdiv") 27 | 28 | menu_def = { 29 | "File" : { 30 | "Exit" : [ onExit, wx.ART_QUIT ], 31 | }, 32 | "Help" : { 33 | "About" : onAbout 34 | }, 35 | } 36 | 37 | body_def_1 = [ 38 | ew.HorizontalSpliter( [ 39 | 120, 40 | [ 41 | [ 42 | ew.Label("Top1",expand=True,proportion=1,key='top1'), 43 | ew.Label("Top2",expand=True,proportion=2,key='top2'), 44 | ew.Label("Top3",expand=True,proportion=3,key='top3'), 45 | { 'expand' : True, 'proportion' : 1 } 46 | ] 47 | ], 48 | [ 49 | [ 50 | ew.Label("Mid",expand=True,proportion=1,key='mid'), 51 | { 'expand' : True, 'proportion' : 1 } 52 | ] 53 | ], 54 | ], expand=True,proportion=1 ), 55 | { 'expand' : True, 'proportion' : 1 } 56 | ] 57 | 58 | body_def_2 = [ 59 | ew.Label("Bottom1",expand=True,proportion=1,border=0,key='bottom1'), 60 | ew.Panel( [ 61 | [ ew.Label("Bottom21",expand=True,proportion=1,border=1, key='bottom21'), 62 | ew.Label("Bottom22",expand=True,proportion=1,border=1, key='bottom22'), 63 | ew.Label("Bottom23",expand=True,proportion=1,border=1, key='bottom23'), 64 | { 'expand' : True, 'proportion' : 1, 'border' : 0 } 65 | ], 66 | [ ew.Label("Bottom3",expand=True,proportion=1,border=0,key='bottom3'), 67 | { 'expand' : True, 'proportion' : 2, 'border' : 0 } 68 | ], 69 | ], expand=True,proportion=1, border=0), 70 | { 'expand' : True, 'proportion' : 1, 'border' : 0 } 71 | ] 72 | 73 | body_def = [ 74 | [ 75 | ew.VerticalSpliter( [ 76 | 160, 77 | [ body_def_1 ], 78 | [ body_def_2 ], 79 | ], expand=True, proportion=1, key='book'), 80 | { 'expand' : True, 'proportion' : 1, 'border' : 0 } 81 | ], 82 | ] 83 | 84 | status_def = [ 85 | ["Ready", -1], 86 | ] 87 | 88 | layout = { 89 | "menu" : menu_def, 90 | "body" : body_def, 91 | "status" : status_def, 92 | } 93 | 94 | ###################################################################### 95 | # Main 96 | ###################################################################### 97 | 98 | if __name__ == "__main__": 99 | appWin = ew.WxApp(u"Splitter Demo", 480, 360) 100 | appWin.makeLayout(layout) 101 | appWin.closeHandle(onClose) 102 | initCtrls() 103 | appWin.run() 104 | -------------------------------------------------------------------------------- /demo/StatusBar.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | def initCtrls(): 8 | global label, idlecount, timercount 9 | label = ew.getWxCtrl('label') 10 | label.SetBackgroundColour(wx.Colour(200,200,240)) 11 | idlecount = 0 12 | timercount = 0 13 | 14 | def onExit(event): 15 | appWin.close() 16 | 17 | def onClose(event): #return True if want to exit 18 | rv = appWin.messageYesNo("Alert", "Do you want to quit ?" ) 19 | return rv 20 | 21 | def onAbout(event): 22 | appWin.messageBox("About", "Menu Demo\nzdiv") 23 | 24 | def onIdle(event): 25 | global idlecount 26 | appWin.setStatusText("Idle Count : " + str(idlecount), 0) 27 | idlecount += 1 28 | 29 | def onTimer(event): 30 | global timercount 31 | appWin.setStatusText("Timer Count : " + str(timercount), 1) 32 | timercount += 1 33 | 34 | menu_def = { 35 | "File" : { 36 | "Exit" : [ onExit, wx.ART_QUIT ], 37 | }, 38 | "Help" : { 39 | "About" : onAbout 40 | }, 41 | } 42 | 43 | body_def = [ 44 | [ ew.Label("Hello ezWxPython",expand=True,proportion=1,key='label'), 45 | { 'expand' : True, 'proportion' : 1 } ], 46 | ] 47 | 48 | status_def = [ 49 | ["Idle", -1], 50 | ["Timer", -1], 51 | ] 52 | 53 | layout = { 54 | "menu" : menu_def, 55 | "body" : body_def, 56 | "status" : status_def, 57 | } 58 | 59 | ###################################################################### 60 | # Main 61 | ###################################################################### 62 | 63 | if __name__ == "__main__": 64 | appWin = ew.WxApp(u"Menu Demo", 320, 240) 65 | appWin.makeLayout(layout) 66 | initCtrls() 67 | appWin.closeHandle(onClose) 68 | appWin.idleHandle(onIdle) 69 | appWin.timerHandle(onTimer,1000,start=True,key='timer') 70 | appWin.run() 71 | -------------------------------------------------------------------------------- /demo/StyledTextCtrlDemo.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import ezWxPython as ezwx 5 | 6 | ###################################################################### 7 | # Global 8 | ###################################################################### 9 | 10 | window = None 11 | 12 | def setStatusText(text,index=0): 13 | if window is not None and window.statusbar is not None: 14 | if index < window.statusbar.GetFieldsCount(): 15 | window.statusbar.SetStatusText(text,index) 16 | 17 | ###################################################################### 18 | # Handler 19 | ###################################################################### 20 | 21 | def onExit(event): 22 | ezwx.WxAppClose() 23 | 24 | def onClose(event): #return True if want to exit 25 | rv = ezwx.MessageYesNo("Alert", "Do you want to quit ?" ) 26 | return rv 27 | 28 | def onOpen(event): 29 | filename = ezwx.OpenFileDialog() 30 | if filename is not None: 31 | stc = ezwx.getWxCtrl('stc') 32 | 33 | def onClear(event): 34 | setStatusText("Clear",0) 35 | stc = ezwx.getWxCtrl('stc') 36 | if stc is not None: 37 | stc.ClearAll() 38 | 39 | def onCopy(event): 40 | setStatusText("Copy",0) 41 | stc = ezwx.getWxCtrl('stc') 42 | if stc is not None: 43 | stc.Copy() 44 | 45 | def onPaste(event): 46 | setStatusText("Paste",0) 47 | stc = ezwx.getWxCtrl('stc') 48 | if stc is not None: 49 | stc.Paste() 50 | 51 | def onAbout(event): 52 | ezwx.MessageBox("About", "StyledTextCtrl Demo\nzdiv") 53 | 54 | ###################################################################### 55 | # Layout 56 | ###################################################################### 57 | 58 | menu_def = { 59 | "File" : { 60 | "Open" : onOpen, 61 | "-" : None, 62 | "Exit" : onExit, 63 | }, 64 | "Edit" : { 65 | "Clear" : onClear, 66 | "Copy" : onCopy, 67 | "Paste" : onPaste, 68 | }, 69 | "Help" : { 70 | "About" : onAbout 71 | }, 72 | } 73 | 74 | status_def = [ 75 | ["Ready", -1], 76 | ] 77 | 78 | body_def = [ 79 | [ ezwx.StyledText(expand=True,proportion=1,key="stc"), 80 | { 'expand' : True, 'proportion' : 1 } ], 81 | ] 82 | 83 | layout = { 84 | "menu" : menu_def, 85 | "status" : status_def, 86 | "body" : body_def, 87 | } 88 | 89 | 90 | ###################################################################### 91 | # Main 92 | ###################################################################### 93 | 94 | if __name__ == "__main__": 95 | window = ezwx.WxApp(u"StyledTextCtrl Demo", 600, 480) 96 | window.makeLayout(layout) 97 | window.closeHandle(onClose) 98 | window.run() 99 | 100 | -------------------------------------------------------------------------------- /demo/TextCtrl.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import ezWxPython as ezwx 5 | 6 | ###################################################################### 7 | # Global 8 | ###################################################################### 9 | 10 | window = None 11 | 12 | def setStatusText(text,index=0): 13 | if window is not None and window.statusbar is not None: 14 | if index < window.statusbar.GetFieldsCount(): 15 | window.statusbar.SetStatusText(text,index) 16 | 17 | ###################################################################### 18 | # Handler 19 | ###################################################################### 20 | 21 | def onExit(event): 22 | ezwx.WxAppClose() 23 | 24 | def onClose(event): #return True if want to exit 25 | rv = ezwx.MessageYesNo("Alert", "Do you want to quit ?" ) 26 | return rv 27 | 28 | def onAbout(event): 29 | ezwx.MessageBox("About", "StyledTextCtrl Demo\nzdiv") 30 | 31 | ###################################################################### 32 | # Layout 33 | ###################################################################### 34 | 35 | menu_def = { 36 | "File" : { 37 | "Exit" : onExit, 38 | }, 39 | "Help" : { 40 | "About" : onAbout 41 | }, 42 | } 43 | 44 | status_def = [ 45 | ["Ready", -1], 46 | ] 47 | 48 | body_def = [ 49 | [ ezwx.Text("",expand=True,proportion=1,key="text"), 50 | { 'expand' : True, 'proportion' : 1 } ], 51 | ] 52 | 53 | layout = { 54 | "menu" : menu_def, 55 | "status" : status_def, 56 | "body" : body_def, 57 | } 58 | 59 | ###################################################################### 60 | # Main 61 | ###################################################################### 62 | 63 | if __name__ == "__main__": 64 | window = ezwx.WxApp(u"wxPython Template", 600, 480) 65 | window.makeLayout(layout) 66 | window.closeHandle(onClose) 67 | window.run() 68 | -------------------------------------------------------------------------------- /demo/TextEntryDialog.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | def onExit(event): 8 | appWin.close() 9 | 10 | def onAbout(event): 11 | appWin.messageBox("About", "TextEntry Demo\nzdiv") 12 | 13 | def onButton(event): 14 | value = appWin.getText('deftext') 15 | value = appWin.textEntryDialog("Text Entry Demo", "Enter your name", value=value) 16 | appWin.appendText('text',value + '\n') 17 | 18 | 19 | menu_def = { 20 | "File" : { 21 | "Exit" : [ onExit, wx.ART_QUIT ], 22 | }, 23 | "Help" : { 24 | "About" : onAbout 25 | }, 26 | } 27 | 28 | body_def = [ 29 | [ ew.Text('Default Value', expand=True,proportion=1,key='deftext'), 30 | ew.Button("Dialog",handler=onButton,key='button'), ], 31 | [ ew.Line() ], 32 | [ ew.Text('',multiline=True,expand=True,proportion=1,key='text'), 33 | { 'expand' : True, 'proportion' : 1 } ], 34 | ] 35 | 36 | status_def = [ 37 | ["Ready", -1], 38 | ] 39 | 40 | layout = { 41 | "menu" : menu_def, 42 | "body" : body_def, 43 | "status" : status_def, 44 | } 45 | 46 | ###################################################################### 47 | # Main 48 | ###################################################################### 49 | 50 | if __name__ == "__main__": 51 | appWin = ew.WxApp(u"Menu Demo", 320, 240) 52 | appWin.makeLayout(layout) 53 | appWin.run() 54 | -------------------------------------------------------------------------------- /demo/Thread.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | def initCtrls(): 8 | global label, runcount 9 | label = ew.getWxCtrl('label') 10 | label.SetBackgroundColour(wx.Colour(200,200,240)) 11 | runcount = 0 12 | 13 | def onExit(event): 14 | appWin.close() 15 | 16 | def onClose(event): #return True if want to exit 17 | rv = appWin.messageYesNo("Alert", "Do you want to quit ?" ) 18 | return rv 19 | 20 | def onAbout(event): 21 | appWin.messageBox("About", "Thread Demo\nzdiv") 22 | 23 | def threadGuiAction(status_text): 24 | def action(): 25 | appWin.setStatusText(status_text) 26 | return action 27 | 28 | def threadWorker(args): 29 | global runcount 30 | while True: 31 | ew.callAfter(threadGuiAction(args + ": " + str(runcount))) 32 | runcount += 1 33 | time.sleep(0.1) 34 | 35 | menu_def = { 36 | "File" : { 37 | "Exit" : [ onExit, wx.ART_QUIT ], 38 | }, 39 | "Help" : { 40 | "About" : onAbout 41 | }, 42 | } 43 | 44 | body_def = [ 45 | [ ew.Label("Hello ezWxPython",expand=True,proportion=1,key='label'), 46 | { 'expand' : True, 'proportion' : 1 } ], 47 | ] 48 | 49 | status_def = [ 50 | ["Ready", -1], 51 | ] 52 | 53 | layout = { 54 | "menu" : menu_def, 55 | "body" : body_def, 56 | "status" : status_def, 57 | } 58 | 59 | ###################################################################### 60 | # Main 61 | ###################################################################### 62 | 63 | if __name__ == "__main__": 64 | appWin = ew.WxApp(u"Thread Demo", 320, 240) 65 | appWin.makeLayout(layout) 66 | initCtrls() 67 | appWin.closeHandle(onClose) 68 | ew.threadHandle(threadWorker, start=True, key='thread', args=("Worker",)) 69 | appWin.run() 70 | -------------------------------------------------------------------------------- /demo/Ticker.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | def onExit(event): 8 | appWin.close() 9 | 10 | def onClose(event): #return True if want to exit 11 | rv = appWin.messageYesNo("Alert", "Do you want to quit ?" ) 12 | if rv is True: 13 | appWin.setTickerStop('ticker') 14 | return rv 15 | 16 | def onAbout(event): 17 | appWin.messageBox("About", "Ticker Demo\nzdiv") 18 | 19 | def onTextApply(event): 20 | text = appWin.getText('deftext') 21 | appWin.setTickerText('ticker',text) 22 | 23 | def onPPFApply(event): 24 | text = appWin.getText('ppf') 25 | appWin.setTickerPPF('ticker',int(text)) 26 | 27 | def onFPSApply(event): 28 | text = appWin.getText('fps') 29 | appWin.setTickerFPS('ticker',int(text)) 30 | 31 | def onFont(event): 32 | font = ew.getWxCtrl('font') 33 | appWin.setTickerFont('ticker',font.GetSelectedFont()) 34 | 35 | def onStart(event): 36 | appWin.setTickerStart('ticker') 37 | 38 | def onStop(event): 39 | appWin.setTickerStop('ticker') 40 | 41 | def onRight(event): 42 | appWin.setTickerDirection('ticker','right') 43 | 44 | def onLeft(event): 45 | appWin.setTickerDirection('ticker','left') 46 | 47 | menu_def = { 48 | "File" : { 49 | "Exit" : [ onExit, wx.ART_QUIT ], 50 | }, 51 | "Help" : { 52 | "About" : onAbout 53 | }, 54 | } 55 | 56 | body_def = [ 57 | [ ew.Ticker(text="Default Ticker Text",fgcolor=wx.BLACK,bgcolor=wx.WHITE,key='ticker',expand=True,proportion=1,) ], 58 | [ ew.Line() ], 59 | [ ew.Text('New Ticker Value', expand=True,proportion=1,key='deftext'), 60 | ew.Button("Apply",handler=onTextApply), ], 61 | [ ew.Label("PPF: "), 62 | ew.Text('2', expand=True,key='ppf',size=(32,-1)), 63 | ew.Button("Apply",handler=onPPFApply,size=(64,-1)), 64 | ew.Label("FPS: "), 65 | ew.Text('20', expand=True,key='fps',size=(64,-1)), 66 | ew.Button("Apply",handler=onFPSApply,size=(64,-1)), 67 | ew.Label("Font: "), 68 | ew.FontPicker(handler=onFont,key='font'), 69 | ], 70 | [ None, 71 | ew.Button("Start",handler=onStart), 72 | ew.Button("Stop",handler=onStop), 73 | ew.Button("L > R",handler=onRight), 74 | ew.Button("L < R",handler=onLeft), 75 | ], 76 | ] 77 | 78 | status_def = [ 79 | ["Ready", -1], 80 | ] 81 | 82 | layout = { 83 | "menu" : menu_def, 84 | "body" : body_def, 85 | "status" : status_def, 86 | } 87 | 88 | ###################################################################### 89 | # Main 90 | ###################################################################### 91 | 92 | if __name__ == "__main__": 93 | appWin = ew.WxApp(u"Ticker Demo", 480, 240) 94 | appWin.makeLayout(layout) 95 | appWin.closeHandle(onClose) 96 | appWin.run() 97 | -------------------------------------------------------------------------------- /demo/TimerEvent.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | def initCtrls(): 8 | global label, runcount 9 | label = ew.getWxCtrl('label') 10 | label.SetBackgroundColour(wx.Colour(200,200,240)) 11 | runcount = 0 12 | 13 | def onExit(event): 14 | appWin.close() 15 | 16 | def onClose(event): #return True if want to exit 17 | rv = appWin.messageYesNo("Alert", "Do you want to quit ?" ) 18 | return rv 19 | 20 | def onAbout(event): 21 | appWin.messageBox("About", "Menu Demo\nzdiv") 22 | 23 | def onTimer(event): 24 | global runcount 25 | appWin.setStatusText("Timer Count : " + str(runcount)) 26 | runcount += 1 27 | 28 | menu_def = { 29 | "File" : { 30 | "Exit" : [ onExit, wx.ART_QUIT ], 31 | }, 32 | "Help" : { 33 | "About" : onAbout 34 | }, 35 | } 36 | 37 | body_def = [ 38 | [ ew.Label("Hello ezWxPython",expand=True,proportion=1,key='label'), 39 | { 'expand' : True, 'proportion' : 1 } ], 40 | ] 41 | 42 | status_def = [ 43 | ["Ready", -1], 44 | ] 45 | 46 | layout = { 47 | "menu" : menu_def, 48 | "body" : body_def, 49 | "status" : status_def, 50 | } 51 | 52 | ###################################################################### 53 | # Main 54 | ###################################################################### 55 | 56 | if __name__ == "__main__": 57 | appWin = ew.WxApp(u"Menu Demo", 320, 240) 58 | appWin.makeLayout(layout) 59 | initCtrls() 60 | appWin.closeHandle(onClose) 61 | appWin.timerHandle(onTimer,1000,start=True,key='timer') 62 | appWin.run() 63 | -------------------------------------------------------------------------------- /demo/ToolbarText.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | ''' 8 | Silk icon set 1.3 : http://www.famfamfam.com/lab/icons/silk/ 9 | ''' 10 | page_white_png = 'eJzrDPBz5+WS4mJgYOD19HAJAtICIMzBAiS3/jJ/BaRY0h19HRkY1p8wZ+16CeRLlrhGlATnp5WUJxalMjim5CelKnjmJqanBqUmplQWnky1ASra4eniGKJxvnRiNN8hBQHX5esOq71rbKud9aJd+sqPrq3+GldeO8RfmzbnYbtlop4k08VpLCfty7YwWsZwTp11Lcnp4QZ5kfBLW1i9zkvrx0TufHBD20XQs1tqln+vjGaeTohGQVKqyJblz9zaflt0bXbZm/Cn9eHLvDPN8ZbnWxv9TlqcLI59MaVrc4riwUUPTUSFRXr411xjeZwpISo2a+IBfbW61vM2rv7em267LvK+rXfbSv0ip6Fqd6k1y9EF+kZLoz+sq9zmD/QDg6ern8s6p4QmAJikcj4=' 11 | page_copy_png = 'eJwBlwJo/YlQTkcNChoKAAAADUlIRFIAAAAQAAAAEAgGAAAAH/P/YQAAAARnQU1BAACvyDcFiukAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAACKUlEQVQ4y3XTPWhUQRSG4ffMzN1ssm52FX+CkkIwSSVWQYsYUYsUmkobQTClKFqJoJ2gsbCXYCEErLROJxITURIMqGWIaZKIJLjGuP937hyLu4KS3dNMM+djzjMzMnbvw8vefHTMGIqKJiCIKg2vlZ1q83mzVHo2PzVep0PJ5UeLn17dH85tloMVIKgSJwFnYXphm6XFjTff1zduzz29UG0XYIxIT6mqdmVL+fojsLyZ8Hk9Zk+XY2SoyOhI/7nc/sLdTicwCmIFsg4yVshYIZsxbG7XGNoLEycL9Pf1XO0U4ABEILKgCmqFrDPMLv8+2vAe7wPHBw9xa/pLRYLKTt2vr63VXzRLpSfzU+M1p4AgWGNaKkoISiOOuX72MFvlQGrT19OyGZhe2H6wtLgxPHpj5opThZB2IgSsQMYZkkT5WVVWthRjlNgHdmqeM4PdjAwVyWXMxZnX5cdOVRHAGTBiCApWQEnXrEtnFP3XJuLEwQKzc103DWpIgm9/xy0bJ+BaNqsl4d1qg181JXIGJ2ptw5eB4n/NnWzosogRrLUo4OJmoxKZfK6QjVEFI4JImtDORlQJQRARVMH5RL9dm/x4oOkpgNYg7c4XLBOnj+yyMQHIQLcDVcXNTJ4aazf/pYdLcRK8az2VXRXUQxBMx0+i1qU27avhy0gw4jptqNbqpcjk9+2yIR3Sml6C+qaoatuA83fev7VGBsD0gVb+2rRYJWhSLuSi7j8Xl/8bKe2kegAAAABJRU5ErkJggsgkKIY=' 12 | page_paste_png = 'eJwBvwJA/YlQTkcNChoKAAAADUlIRFIAAAAQAAAAEAgGAAAAH/P/YQAAAARnQU1BAACvyDcFiukAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAACUUlEQVQYGQXBMYiWZRwA8N/zvu99npymHUFXpJVgXqEgRbZoDTa0XEPQ0hQUGQ1ODhGEjW0FLQoORRAFKQ3V0lJYgUEQRAQV3lbhWZ7yndf3vc/z//f7lcwE519+8BH8AgCAm6curO8FAAAo51564FG8hbVdy3d74Y2ztq7/AJbuOubDs6/b3roFH+HSqQvrFwFgwKVnXjmzb/mee/3z1fsyU5ttgcx04sg+S0dPysy1z86/9ywuAsCA+5dX7rP5+xUx3rb+yTtkIl3PH6W08fN3lleP7QYAgAGyzkUddfsPi1Zlpo/baS1DBHDzty3l+NNefffzvDFb+fXP9b8eu3xubXuAaKOooxhn2uw/pDaEN59btTENBZFpbGHoj/jgyubDfemvPvnaFwcHiDoTrZKhFDLpu86N2+mPjdR1aazh1nb11EM7HT+019KkW/k2208dRJ2LOtfGuahN1Ab6wuLApC8mfbE46Vzb3HboTl58Yo865oEBYpzJcS5riLGRqS2mUljoyST7YnHoXP03Tf+eeXz/DgtDZ4Coc1GbGJuoQaTIVBR91wElRSQ7eqUr+r6XGCDHJudN1CZqI4AARRH6wmTolEwRRSlFJgPUsWpjE62JsZFESwVDR1c6kfSFLjBh50BmGiDnVYxNtiZryEjQomIAAACRlSgGXN6eTk/s2rcqaxO1kYnBrE6xFwAAzOpUia4MePvrLz/djaMAcO3w8xa6A/YsjjLpSlEKUNB3d4is85KZAADg5Jnvv+m7cpBuhdyiIEFRSmSb7lla2Pk/rzVJEzgz/YUAAAAASUVORK5CYIIjiEct' 13 | 14 | def findCtrls(): 15 | global status, text 16 | status = appWin.statusbar 17 | text = ew.getWxCtrl('text') 18 | 19 | def onExit(event): 20 | appWin.close() 21 | 22 | def onClose(event): 23 | rv = appWin.messageYesNo("Alert", "Do you want to quit ?" ) 24 | return rv 25 | 26 | def onOpen(event): 27 | pass 28 | 29 | def onAbout(event): 30 | appWin.messageBox("About", "ToolbarText Demo\nzdiv") 31 | 32 | def onIdle(event): 33 | pass 34 | 35 | def onTimer(event): 36 | pass 37 | 38 | def onClear(event): 39 | text.Clear() 40 | def onCopy(event): 41 | text.Copy() 42 | def onPaste(event): 43 | text.Paste() 44 | def onPasteHtml(event): 45 | text.AppendText(ew.GetClipboardHtmlText()) 46 | def onPasteFile(event): 47 | files = ew.GetClipboardFilenames() 48 | for f in files: 49 | text.AppendText(f + '\n') 50 | 51 | menu_def = { 52 | "File" : { 53 | "Exit" : [onExit, wx.ART_QUIT], 54 | }, 55 | "Help" : { 56 | "About" : [onAbout, wx.ART_HELP], 57 | }, 58 | } 59 | 60 | tool_def = [ #icon, text, handler, tooltip 61 | [wx.ART_QUIT, onExit, "Exit" ], 62 | [wx.ART_HELP, onAbout, "About" ], 63 | ] 64 | 65 | status_def = [ 66 | ["Ready", -1], 67 | ] 68 | 69 | text_tool_def = [ 70 | [page_white_png, onClear , None, "Clear all text"], 71 | [page_copy_png , onCopy , None, "Copy text to clipboard"], 72 | [page_paste_png, onPaste , None, "Paste text from clipboard"], 73 | [page_paste_png, onPasteHtml , None, "Paste html text from clipboard"], 74 | [page_paste_png, onPasteFile , None, "Paste filenames from clipboard"], 75 | ] 76 | 77 | body_def = [ 78 | [ 79 | ew.Notebook([ 80 | "Default Toolbar", 81 | [ 82 | [ 83 | ew.ToolbarText(expand=True,proportion=1,key="text"), 84 | { 'expand' : True, 'proportion' : 1 } 85 | ] 86 | ], 87 | "Custom Toolbar", 88 | [ 89 | [ 90 | ew.ToolbarText(tool_def=text_tool_def, expand=True,proportion=1,key="text"), 91 | { 'expand' : True, 'proportion' : 1 } 92 | ] 93 | ], 94 | ] , expand=True, proportion=1), 95 | { 'expand' : True, 'proportion' : 1 } 96 | ], 97 | ] 98 | 99 | layout = { 100 | "menu" : menu_def, 101 | "tool" : tool_def, 102 | "status" : status_def, 103 | "body" : body_def, 104 | } 105 | 106 | 107 | if __name__ == "__main__": 108 | appWin = ew.WxApp(u"ToolbarText Demo", 480, 320) 109 | appWin.makeLayout(layout) 110 | findCtrls() 111 | appWin.closeHandle(onClose) 112 | appWin.openHandle(onOpen) 113 | appWin.idleHandle(onIdle) 114 | appWin.timerHandle(onTimer,100,start=True,key='timer') 115 | appWin.run() 116 | 117 | -------------------------------------------------------------------------------- /demo/TreeCtrl.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import ezWxPython as ezwx 5 | 6 | ###################################################################### 7 | # Global 8 | ###################################################################### 9 | 10 | window = None 11 | 12 | def setStatusText(text,index=0): 13 | if window is not None and window.statusbar is not None: 14 | if index < window.statusbar.GetFieldsCount(): 15 | window.statusbar.SetStatusText(text,index) 16 | 17 | ###################################################################### 18 | # Handler 19 | ###################################################################### 20 | 21 | def onExit(event): 22 | ezwx.WxAppClose() 23 | 24 | def onClose(event): #return True if want to exit 25 | rv = ezwx.MessageYesNo("Alert", "Do you want to quit ?" ) 26 | return rv 27 | 28 | def onAbout(event): 29 | ezwx.MessageBox("About", "StyledTextCtrl Demo\nzdiv") 30 | 31 | ###################################################################### 32 | # Layout 33 | ###################################################################### 34 | 35 | tree_data = [ 'Root', 36 | ['Item-1', [ 'Item-1.1', 'Item-1.2' ], 37 | 'Item-2', 38 | 'Item-3', [ 'Item-3.1', 'Item-3.2', 'Item-3.3' ], 39 | ] 40 | ] 41 | 42 | menu_def = { 43 | "File" : { 44 | "Exit" : onExit, 45 | }, 46 | "Help" : { 47 | "About" : onAbout 48 | }, 49 | } 50 | 51 | status_def = [ 52 | ["Ready", -1], 53 | ] 54 | 55 | body_def = [ 56 | [ ezwx.Tree(data=tree_data,expand=True,proportion=1,key="tree"), 57 | { 'expand' : True, 'proportion' : 1 } ], 58 | ] 59 | 60 | layout = { 61 | "menu" : menu_def, 62 | "status" : status_def, 63 | "body" : body_def, 64 | } 65 | 66 | ###################################################################### 67 | # Main 68 | ###################################################################### 69 | 70 | if __name__ == "__main__": 71 | window = ezwx.WxApp(u"wxPython Template", 600, 480) 72 | window.makeLayout(layout) 73 | window.closeHandle(onClose) 74 | window.run() 75 | -------------------------------------------------------------------------------- /demo/TreeCtrlDynamic.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import ezWxPython as ezwx 5 | 6 | ###################################################################### 7 | # Global 8 | ###################################################################### 9 | 10 | window = None 11 | 12 | def setStatusText(text,index=0): 13 | if window is not None and window.statusbar is not None: 14 | if index < window.statusbar.GetFieldsCount(): 15 | window.statusbar.SetStatusText(text,index) 16 | 17 | ###################################################################### 18 | # Handler 19 | ###################################################################### 20 | 21 | def onExit(event): 22 | ezwx.WxAppClose() 23 | 24 | def onOpen(event): 25 | tree = ezwx.getWxCtrl('tree') 26 | if tree is not None: 27 | root = tree.AddRoot('Root') 28 | for i in range(10): 29 | name1 = 'Item_' + str(i) 30 | node = tree.AppendItem(root,name1) 31 | for k in range(10): 32 | name2 = name1 + '_' + str(k) 33 | tree.AppendItem(node,name2) 34 | tree.ExpandAllChildren(root) 35 | 36 | def onClose(event): #return True if want to exit 37 | rv = ezwx.MessageYesNo("Alert", "Do you want to quit ?" ) 38 | return rv 39 | 40 | def onAbout(event): 41 | ezwx.MessageBox("About", "StyledTextCtrl Demo\nzdiv") 42 | 43 | ###################################################################### 44 | # Layout 45 | ###################################################################### 46 | 47 | menu_def = { 48 | "File" : { 49 | "Exit" : onExit, 50 | }, 51 | "Help" : { 52 | "About" : onAbout 53 | }, 54 | } 55 | 56 | status_def = [ 57 | ["Ready", -1], 58 | ] 59 | 60 | body_def = [ 61 | [ ezwx.Tree(expand=True,proportion=1,key="tree"), 62 | { 'expand' : True, 'proportion' : 1 } ], 63 | ] 64 | 65 | layout = { 66 | "menu" : menu_def, 67 | "status" : status_def, 68 | "body" : body_def, 69 | } 70 | 71 | ###################################################################### 72 | # Main 73 | ###################################################################### 74 | 75 | if __name__ == "__main__": 76 | window = ezwx.WxApp(u"wxPython Template", 600, 480) 77 | window.makeLayout(layout) 78 | window.closeHandle(onClose) 79 | window.openHandle(onOpen) 80 | window.run() 81 | -------------------------------------------------------------------------------- /demo/Web.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import ezWxPython as ezwx 5 | 6 | ###################################################################### 7 | # Global 8 | ###################################################################### 9 | 10 | window = None 11 | web = None 12 | addr = None 13 | 14 | def findControls(): 15 | global web 16 | global addr 17 | web = ezwx.getWxCtrl('web') 18 | addr = ezwx.getWxCtrl('addr') 19 | 20 | def setStatusText(text,index=0): 21 | if window is not None and window.statusbar is not None: 22 | if index < window.statusbar.GetFieldsCount(): 23 | window.statusbar.SetStatusText(text,index) 24 | 25 | ###################################################################### 26 | # Handler 27 | ###################################################################### 28 | 29 | def onExit(event): 30 | ezwx.WxAppClose() 31 | 32 | def onClose(event): #return True if want to exit 33 | rv = ezwx.MessageYesNo("Alert", "Do you want to quit ?" ) 34 | return rv 35 | 36 | def onAbout(event): 37 | ezwx.MessageBox("About", "StyledTextCtrl Demo\nzdiv") 38 | 39 | def onHome(event): 40 | global web 41 | web.GoHome() 42 | 43 | def onBack(event): 44 | global web 45 | if web.CanGoBack(): 46 | web.GoBack() 47 | 48 | def onForward(event): 49 | global web 50 | if web.CanGoForward(): 51 | web.GoForward() 52 | 53 | def onGo(event): 54 | global web, addr 55 | web.LoadUrl(addr.GetValue()) 56 | 57 | ###################################################################### 58 | # Layout 59 | ###################################################################### 60 | 61 | menu_def = { 62 | "File" : { 63 | "Exit" : onExit, 64 | }, 65 | "Help" : { 66 | "About" : onAbout 67 | }, 68 | } 69 | 70 | status_def = [ 71 | ["Ready", -1], 72 | ] 73 | 74 | body_def = [ 75 | [ ezwx.Button('Home',handler=onHome), 76 | ezwx.Button('Back',handler=onBack), 77 | ezwx.Button('Forward',handler=onForward), 78 | ], 79 | [ ezwx.Label('Address: '), 80 | ezwx.Text('https://www.google.com',proportion=1,key='addr'), 81 | ezwx.Button('Go',handler=onGo), 82 | ], 83 | [ ezwx.Web("https://www.google.com",expand=True,proportion=1,key="web"), 84 | { 'expand' : True, 'proportion' : 1 } ], 85 | ] 86 | 87 | layout = { 88 | "menu" : menu_def, 89 | "status" : status_def, 90 | "body" : body_def, 91 | } 92 | 93 | ###################################################################### 94 | # Main 95 | ###################################################################### 96 | 97 | if __name__ == "__main__": 98 | window = ezwx.WxApp(u"wxPython Template", 600, 480) 99 | window.makeLayout(layout) 100 | window.closeHandle(onClose) 101 | findControls() 102 | window.run() 103 | -------------------------------------------------------------------------------- /example/FtpServer.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import ezWxPython as ezwx 5 | 6 | ###################################################################### 7 | # Global 8 | ###################################################################### 9 | 10 | window = None 11 | 12 | def setStatusText(text,index=0): 13 | if window is not None and window.statusbar is not None: 14 | if index < window.statusbar.GetFieldsCount(): 15 | window.statusbar.SetStatusText(text,index) 16 | 17 | 18 | def getTextValue(key): 19 | ctrl = ezwx.getWxCtrl(key) 20 | if ctrl is not None: 21 | return ctrl.GetLineText(0) 22 | return None 23 | 24 | def AppendToText(text): 25 | ctrl = ezwx.getWxCtrl('text') 26 | if ctrl is not None: 27 | ctrl.write( text + "\n" ) 28 | 29 | def printLog(text): 30 | AppendToText(text) 31 | 32 | def onThread(): 33 | from time import sleep 34 | while ezwx.isWxAppRun(): 35 | ezwx.callAfter(printLog,text) 36 | sleep(1.0) 37 | 38 | ###################################################################### 39 | # FTPServer 40 | ###################################################################### 41 | 42 | import logging 43 | class logHandler(logging.Handler): 44 | terminator = '\n' 45 | def __init__(self, stream=None): 46 | logging.Handler.__init__(self) 47 | #def flush(self): 48 | # pass 49 | def emit(self, record): 50 | msg = self.format(record) 51 | ezwx.callAfter(printLog,(msg)) 52 | #print( 'PYLOG:' + msg) 53 | #print(self.terminator) 54 | #self.flush() 55 | def __repr__(self): 56 | return "PYLOG" 57 | 58 | def runFtpServer(host,port,user,passwd,home): 59 | from pyftpdlib.authorizers import DummyAuthorizer 60 | from pyftpdlib.handlers import FTPHandler 61 | from pyftpdlib.servers import FTPServer 62 | 63 | authorizer = DummyAuthorizer() 64 | authorizer.add_user(user,passwd,home, perm="elradfmwMT") 65 | authorizer.add_anonymous("D:/Temp1") 66 | 67 | handler = FTPHandler 68 | handler.authorizer = authorizer 69 | 70 | server = FTPServer((host,int(port)), handler) 71 | 72 | logger = logging.getLogger('pyftpdlib') 73 | logger.setLevel(logging.INFO) 74 | logger.addHandler(logHandler()) 75 | 76 | server.serve_forever() 77 | 78 | ###################################################################### 79 | # Handler 80 | ###################################################################### 81 | 82 | def onExit(event): 83 | ezwx.WxAppClose() 84 | 85 | def onClose(event): #return True if want to exit 86 | rv = ezwx.MessageYesNo("Alert", "Do you want to quit ?" ) 87 | return rv 88 | 89 | def onAbout(event): 90 | ezwx.MessageBox("About", "Easy FTPServer\nzdiv") 91 | 92 | def onHomeButton(event): 93 | folder = ezwx.DirectoryDialog() 94 | if folder is not None: 95 | ctrl = ezwx.getWxCtrl('home') 96 | if ctrl is not None: 97 | ctrl.write( folder ) 98 | 99 | def onStartButton(event): 100 | host = getTextValue('host') 101 | port = getTextValue('port') 102 | user = getTextValue('user') 103 | passwd = getTextValue('passwd') 104 | home = getTextValue('home') 105 | ezwx.threadHandle(runFtpServer, start=True, args=(host,port,user,passwd,home)) 106 | 107 | ###################################################################### 108 | # Layout 109 | ###################################################################### 110 | 111 | menu_def = { 112 | "File" : { 113 | "Exit" : onExit, 114 | }, 115 | "Help" : { 116 | "About" : onAbout 117 | }, 118 | } 119 | 120 | status_def = [ 121 | ["Ready", -1], 122 | ] 123 | 124 | body_def = [ 125 | [ ezwx.Label("IP Address: "), 126 | ezwx.Text("127.0.0.1",key='host'), 127 | ezwx.Label("Port: "), 128 | ezwx.Text("21",key='port',size=(32,12)), 129 | ezwx.Label("Id: "), 130 | ezwx.Text("user",key='user'), 131 | ezwx.Label("Password: "), 132 | ezwx.Text("1234",key='passwd',password=True), 133 | ], 134 | [ ezwx.Label("Home Folder: "), 135 | ezwx.Text("",key='home',proportion=1), 136 | ezwx.Button("Browse",handler=onHomeButton), 137 | ezwx.Button("Start",handler=onStartButton), 138 | ], 139 | [ ezwx.Text(expand=True,proportion=1,multiline=True,readonly=True,key="text"), 140 | { 'expand' : True, 'proportion': 1 } 141 | ], 142 | ] 143 | 144 | layout = { 145 | "menu" : menu_def, 146 | "status" : status_def, 147 | "body" : body_def, 148 | } 149 | 150 | ###################################################################### 151 | # Main 152 | ###################################################################### 153 | 154 | if __name__ == "__main__": 155 | window = ezwx.WxApp("Easy FTPServer", 600, 480) 156 | window.makeLayout(layout) 157 | window.closeHandle(onClose) 158 | window.run() 159 | -------------------------------------------------------------------------------- /example/IconMaker.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import ezWxPython as ew 5 | 6 | ###################################################################### 7 | # Handler 8 | ###################################################################### 9 | 10 | def onExit(event): 11 | appWin.close() 12 | 13 | def onClose(event): 14 | rv = appWin.messageYesNo("Alert", "Do you want to quit ?" ) 15 | return rv 16 | 17 | def onAbout(event): 18 | appWin.messageBox("About", "Icon Maker\nzdiv (2018.4.1)") 19 | 20 | def guiUpdate(text): 21 | def textAppend(): 22 | appWin.appendText('text',text) 23 | return textAppend 24 | 25 | def worker(args): 26 | files = os.listdir(args) 27 | for f in files: 28 | name,ext = os.path.splitext(f) 29 | if ext != '.png': 30 | continue 31 | icon_name = f.replace('.','_') 32 | icon_data = ew.encodeIconToStr(os.path.join(args,f)) 33 | data = "%-32s = '%s'\n" % (icon_name, icon_data) 34 | ew.callAfter(guiUpdate(data)) 35 | 36 | def onMake(event): 37 | folder = appWin.getText('folder') 38 | ew.threadHandle(worker, start=True, daemon=True, args=(folder,), key='worker') 39 | 40 | def onThreadAction(arg1): 41 | AppendToText('[Thread] ' + str(arg1)) 42 | 43 | 44 | ###################################################################### 45 | # Layout 46 | ###################################################################### 47 | 48 | menu_def = { 49 | "File" : { 50 | "Exit" : onExit, 51 | }, 52 | "Help" : { 53 | "About" : onAbout 54 | }, 55 | } 56 | 57 | status_def = [ 58 | ["Ready", -1], 59 | ] 60 | 61 | body_def = [ 62 | [ ew.FileBrowser("Icon Folder: ", "", "Browse", key='folder', directory=True, expand=True, proportion=1 ) ], 63 | [ ew.Text(expand=True,proportion=1,multiline=True,readonly=True,key="text"), 64 | { 'expand' : True, 'proportion': 1 } 65 | ], 66 | [ None, 67 | ew.Button("Make",handler=onMake,expand=True) ], 68 | ] 69 | 70 | layout = { 71 | "menu" : menu_def, 72 | "status" : status_def, 73 | "body" : body_def, 74 | } 75 | 76 | ###################################################################### 77 | # Main 78 | ###################################################################### 79 | 80 | if __name__ == "__main__": 81 | appWin = ew.WxApp("Icon Maker", 600, 480) 82 | appWin.makeLayout(layout) 83 | appWin.closeHandle(onClose) 84 | appWin.run() 85 | -------------------------------------------------------------------------------- /example/VideoPlayer.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import ezWxPython as ew 6 | 7 | window = None 8 | 9 | def findCtrls(): 10 | global status, addr, video, url, progress, volume, timer, time 11 | status = window.statusbar 12 | addr = ew.getWxCtrl('addr') 13 | video = ew.getWxCtrl('media') 14 | video.SetVolume(0.5) 15 | url = ew.getWxCtrl('url') 16 | progress = ew.getWxCtrl('progress') 17 | progress.SetRange(0,1000) 18 | progress.SetValue(0) 19 | volume = ew.getWxCtrl('volume') 20 | volume.SetRange(0,100) 21 | volume.SetValue(100*video.GetVolume()) 22 | time = ew.getWxCtrl('time') 23 | 24 | def onExit(event): 25 | ew.WxAppClose() 26 | 27 | def onClose(event): 28 | rv = ew.MessageYesNo("Alert", "Do you want to quit ?" ) 29 | if rv == True: 30 | window.timerStop('timer') 31 | return rv 32 | 33 | def onAbout(event): 34 | ew.MessageBox("About", "MediaCtrl Demo\nzdiv") 35 | 36 | def onIdle(event): 37 | pass 38 | 39 | def onTimer(event): 40 | state = video.GetState() 41 | if state == wx.media.MEDIASTATE_PLAYING: 42 | length = video.Length() 43 | if length != 0: 44 | tell = video.Tell() 45 | ss = tell / 1000; 46 | hh = ss / 3600 47 | mm = (ss % 3600) / 60 48 | ss = ss % 60 49 | time.SetLabel("%02d:%02d.%02d" % (hh, mm, ss)) 50 | progress.SetValue(1000*tell/length) 51 | 52 | def onProgress(event): 53 | length = video.Length() 54 | p = progress.GetValue() 55 | video.Seek(p*length/1000) 56 | 57 | def onHome(event): 58 | state = video.GetState() 59 | if state != wx.media.MEDIASTATE_STOPPED: 60 | video.Stop() 61 | status.SetStatusText("Stopped") 62 | 63 | def onBack(event): 64 | state = video.GetState() 65 | if state == wx.media.MEDIASTATE_PLAYING: 66 | video.Pause() 67 | status.SetStatusText("Paused") 68 | 69 | def onForward(event): 70 | state = video.GetState() 71 | if state != wx.media.MEDIASTATE_PLAYING: 72 | video.Play() 73 | status.SetStatusText("Playing") 74 | 75 | def onLoad(event): 76 | video.Load(url.GetValue()) 77 | 78 | menu_def = { 79 | "File" : { 80 | "Exit" : [onExit, wx.ART_QUIT], 81 | }, 82 | "Help" : { 83 | "About" : [onAbout, wx.ART_HELP], 84 | }, 85 | } 86 | 87 | tool_def = [ #icon, text, handler 88 | [wx.ART_GO_HOME, onHome, "Stop" ], 89 | [wx.ART_GO_BACK, onBack, "Pause" ], 90 | [wx.ART_GO_FORWARD, onForward, "Play" ], 91 | ] 92 | 93 | status_def = [ 94 | ["Ready", -1], 95 | ] 96 | 97 | def_url = r'D:/video.wmv' 98 | 99 | body_def = [ 100 | [ ew.Label ("Address: "), 101 | ew.Text (def_url,expand=True,proportion=1,key="url"), 102 | ew.Button("Load",handler=onLoad), 103 | ], 104 | [ ew.Media(def_url,expand=True,proportion=1,key='media'), 105 | { 'expand':True, 'proportion':1 } 106 | ], 107 | [ ew.Label("00:00:00", key='time'), ew.Slider(expand=True,proportion=1,handler=onProgress,key='progress'), 108 | ew.Label("Volume: "), ew.Slider(expand=True,key='volume'), 109 | ], 110 | ] 111 | 112 | layout = { 113 | "menu" : menu_def, 114 | "tool" : tool_def, 115 | "status" : status_def, 116 | "body" : body_def, 117 | } 118 | 119 | 120 | if __name__ == "__main__": 121 | window = ew.WxApp(u"ezwxApp", 900, 620) 122 | window.makeLayout(layout) 123 | findCtrls() 124 | window.closeHandle(onClose) 125 | window.idleHandle(onIdle) 126 | window.timerHandle(onTimer,100,start=True,key='timer') 127 | window.run() 128 | 129 | -------------------------------------------------------------------------------- /src/ezWxPython.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import wx 5 | import wx.adv 6 | 7 | from threading import Thread 8 | 9 | ###################################################################### 10 | # Library 11 | ###################################################################### 12 | 13 | ID_START = 1000 14 | CtrlTable = {} 15 | 16 | def getId(): 17 | global ID_START 18 | ID_START += 1 19 | return ID_START 20 | 21 | def registerCtrl(name,ctrl): 22 | global CtrlTable 23 | CtrlTable[name] = ctrl 24 | 25 | def getCtrl(name): 26 | global CtrlTable 27 | if name in CtrlTable: 28 | return CtrlTable[name] 29 | else: 30 | return None 31 | 32 | def getWxCtrl(name): 33 | global CtrlTable 34 | if name in CtrlTable: 35 | return CtrlTable[name].ctrl 36 | else: 37 | return None 38 | 39 | def getWxTimer(name): 40 | return getCtrl(name) 41 | 42 | def getWxAppCtrl(): 43 | global CtrlTable 44 | name = 'WxApp' 45 | if name in CtrlTable: 46 | return CtrlTable[name].ctrl 47 | else: 48 | return None 49 | 50 | def clearValue(key): 51 | ctrl = getCtrl(key) 52 | if ctrl is not None: 53 | return ctrl.clearValue() 54 | else: 55 | return None 56 | 57 | def getLabel(key): 58 | ctrl = getCtrl(key) 59 | if ctrl is not None: 60 | return ctrl.getLabel() 61 | else: 62 | return None 63 | 64 | def setLabel(key,value): 65 | ctrl = getCtrl(key) 66 | if ctrl is not None: 67 | ctrl.setLabel(value) 68 | 69 | def getValue(key): 70 | ctrl = getCtrl(key) 71 | if ctrl is not None: 72 | return ctrl.getValue() 73 | else: 74 | return None 75 | 76 | def setValue(key,value): 77 | ctrl = getCtrl(key) 78 | if ctrl is not None: 79 | ctrl.setValue(value) 80 | 81 | def appendValue(key,value): 82 | ctrl = getCtrl(key) 83 | if ctrl is not None: 84 | return ctrl.appendValue(value) 85 | else: 86 | return None 87 | 88 | def removeValue(key,value): 89 | ctrl = getCtrl(key) 90 | if ctrl is not None: 91 | return ctrl.removeValue(value) 92 | else: 93 | return None 94 | 95 | def setFgColor(key,color): 96 | ctrl = getCtrl(key) 97 | if ctrl is not None: 98 | ctrl.setFgColor(color) 99 | 100 | def setBgColor(key,color): 101 | ctrl = getCtrl(key) 102 | if ctrl is not None: 103 | ctrl.setBgColor(color) 104 | 105 | def castValue(key,value): 106 | ctrl = getCtrl(key) 107 | if ctrl is not None: 108 | return ctrl.castValue(value) 109 | else: 110 | return value 111 | 112 | def encodeIcon(filename): 113 | from zlib import compress 114 | from base64 import b64encode 115 | with open(filename, "rb") as f: 116 | data = b64encode(compress(f.read())) 117 | return data 118 | 119 | def encodeIconToStr(filename): 120 | icon = encodeIcon(filename) 121 | return icon.decode('utf-8') 122 | 123 | def decodeIcon(data): 124 | from base64 import b64decode 125 | from zlib import decompress 126 | image_data = decompress(b64decode(data)) 127 | return image_data 128 | 129 | def getBitmap(data): 130 | from io import BytesIO 131 | image_data = decodeIcon(data) 132 | stream = BytesIO(bytearray(image_data)) # just bytes() for py3 133 | image = wx.Image(stream, wx.BITMAP_TYPE_ANY) # wx.ImageFromStream for legacy wx 134 | bitmap = wx.Bitmap(image) # wx.BitmapFromImage for legacy wx 135 | return bitmap 136 | 137 | def getMenuBitmap(data, size=(16,16)): 138 | if data[0] == b'w'[0] and data[1] == b'x'[0]: 139 | return wx.ArtProvider.GetBitmap(data, wx.ART_MENU, size) 140 | else: 141 | return getBitmap(data) 142 | 143 | def getToolbarBitmap(data, size=(32,32)): 144 | if data[0] == b'w'[0] and data[1] == b'x'[0]: 145 | return wx.ArtProvider.GetBitmap(data, wx.ART_TOOLBAR, size) 146 | else: 147 | return getBitmap(data) 148 | 149 | def getButtonBitmap(data, size=(16,16)): 150 | if data[0] == b'w'[0] and data[1] == b'x'[0]: 151 | return wx.ArtProvider.GetBitmap(data, wx.ART_BUTTON, size) 152 | else: 153 | return getBitmap(data) 154 | 155 | def threadHandle(handler,start=False,key=None,daemon=True,args=()): 156 | #from threading import * 157 | import threading 158 | thread = threading.Thread(target=handler,args=args) 159 | thread.daemon = daemon 160 | if key is not None: 161 | registerCtrl(key,thread) 162 | if start is True: 163 | thread.start() 164 | 165 | def threadStart(key): 166 | thread = getCtrl(key) 167 | if thread is not None: 168 | thread.start() 169 | 170 | def threadJoin(key): 171 | thread = getCtrl(key) 172 | if thread is not None: 173 | thread.join() 174 | 175 | def callAfter(handler,*args): 176 | wx.CallAfter(handler,*args) 177 | 178 | def doBusyJob(job,args=(),message="Please wait ...",parent=None,bgColor=None,fgColor=None): 179 | import wx.lib.busy 180 | with wx.lib.busy.BusyInfo(message,parent,bgColor,fgColor): 181 | job(args) 182 | 183 | ###################################################################### 184 | # Layouts 185 | ###################################################################### 186 | 187 | class VBox(): 188 | def __init__(self,parent=None,label=None,orient=wx.VERTICAL,proportion=0): 189 | if label is None: 190 | self.ctrl = wx.BoxSizer( orient ) 191 | else: 192 | self.ctrl = wx.StaticBoxSizer( wx.StaticBox( parent, wx.ID_ANY, label ), orient ) 193 | 194 | def add(self,child,proportion=0,expand=True,border=5,align=0): 195 | flags = align 196 | flags |= wx.EXPAND if expand == True else 0 197 | flags |= wx.ALL if border > 0 else 0 198 | self.ctrl.Add( child, proportion, flags, border ) 199 | 200 | def addSpacer(self,proportion=1): 201 | self.ctrl.Add( ( 0, 0), proportion, wx.EXPAND|wx.ALL, 5 ) 202 | 203 | class HBox(VBox): 204 | def __init__(self,parent=None,label=None,orient=wx.HORIZONTAL,proportion=0): 205 | super().__init__(parent,label,orient,proportion) 206 | 207 | class Control(): 208 | def __init__(self,key=None,expand=False,proportion=0,border=2,size=wx.DefaultSize,pos=wx.DefaultPosition,tooltip=None): 209 | self.ctrl = None 210 | self.key = key 211 | self.tooltip = tooltip 212 | self.expand = expand 213 | self.proportion = proportion 214 | self.border = border 215 | self.size = size 216 | self.pos = pos 217 | def getLabel(self): #button 218 | return self.ctrl.GetLabel() 219 | def setLabel(self,value): #button 220 | self.ctrl.SetLabel(value) 221 | def getValue(self): 222 | return self.ctrl.GetValue() 223 | def setValue(self,value): 224 | self.ctrl.SetValue(value) 225 | def clearValue(self): 226 | self.ctrl.SetValue('') 227 | def appendValue(self,value): 228 | self.ctrl.Append(value) 229 | def deleteValue(self,value): 230 | if type(value) is str: 231 | n = self.ctrl.FindString(value) 232 | if n != wx.NOT_FOUND: 233 | self.ctrl.Delete(n) 234 | elif type(value) is int: 235 | self.ctrl.Delete(value) 236 | def removeValue(self,value): 237 | self.deleteValue(value) 238 | def setFgColor(self,value): 239 | self.ctrl.SetForegroundColour(value) 240 | self.ctrl.Refresh() 241 | def setBgColor(self,value): 242 | self.ctrl.SetBackgroundColour(value) 243 | self.ctrl.Refresh() 244 | def castValue(self,value): 245 | return value 246 | 247 | ###################################################################### 248 | # Containers 249 | ###################################################################### 250 | 251 | def wrapSizer(widget): 252 | sizer = wx.BoxSizer() 253 | sizer.Add( widget, 1, wx.EXPAND, 0 ) 254 | sizer.Fit( widget ) 255 | return sizer 256 | 257 | def dictValue(new_value,old_value): 258 | try: 259 | if new_value is not None: 260 | return new_value 261 | except: 262 | pass 263 | return old_value 264 | 265 | def makeLayout(layout,parent): 266 | if type(layout) is not list: 267 | return VBox(); 268 | vbox_label = None; 269 | if type(layout[0]) is str: 270 | vbox_label = layout[0] 271 | layout.remove(layout[0]) 272 | vbox = VBox(parent,vbox_label) 273 | for row in layout: 274 | hbox_label = None; 275 | if type(row[0]) is str: 276 | hbox_label = row[0] 277 | row.remove(row[0]) 278 | hbox = HBox(parent,hbox_label) 279 | prop = 0 280 | expand = True 281 | border = 2 282 | if type(row) is list: 283 | for col in row: 284 | if type(col) is dict: 285 | prop = dictValue( col.get('proportion'), prop ) 286 | expand = dictValue( col.get('expand'), expand ) 287 | border = dictValue( col.get('border'), border ) 288 | elif col is None: 289 | hbox.addSpacer(proportion=1) 290 | else: 291 | col.create(parent) 292 | hbox.add(col.ctrl,proportion=col.proportion,expand=col.expand,border=col.border,align=wx.ALIGN_CENTER_VERTICAL|wx.ALL) 293 | else: #compound control 294 | row.create(parent) 295 | vbox.add(hbox.ctrl,proportion=prop,expand=expand,border=border,align=wx.ALIGN_LEFT|wx.ALL) 296 | return vbox 297 | 298 | class Book(Control): 299 | def __init__(self,layouts,parent=None,create=False,horizontal=True,expand=False,proportion=0,border=2, 300 | size=wx.DefaultSize,pos=wx.DefaultPosition,style='note',key=None): 301 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 302 | self.layouts = layouts 303 | self.style = style 304 | self.simplePages = [] 305 | if create is True and parent is not None: 306 | self.create(parent) 307 | def create(self,parent): 308 | if self.style == 'note': 309 | self.ctrl = wx.Notebook( parent, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0 ) 310 | elif self.style == 'choice': 311 | self.ctrl = wx.Choicebook( parent, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0 ) 312 | else: #simple 313 | self.ctrl = wx.Simplebook( parent, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0 ) 314 | self.titles = [] 315 | self.panels = [] 316 | for layout in self.layouts: 317 | if type(layout) == str: 318 | self.titles.append(layout) 319 | elif type(layout) == list: 320 | self.panels.append(Panel(layout, self.ctrl, create=True)) 321 | for i in range(len(self.panels)): 322 | if self.style == 'simple': 323 | self.simplePages.append(self.panels[i].ctrl); 324 | else: 325 | self.ctrl.AddPage( self.panels[i].ctrl, self.titles[i], False ) 326 | if self.style == 'simple': 327 | self.setPage(0) 328 | if self.key is not None: 329 | registerCtrl( self.key, self ) 330 | def setEffect(self,effect=None): 331 | if self.style == 'simple': 332 | if effect == 'roll_to_left': 333 | self.ctrl.SetEffect(wx.SHOW_EFFECT_ROLL_TO_LEFT) 334 | elif effect == 'roll_to_right': 335 | self.ctrl.SetEffect(wx.SHOW_EFFECT_ROLL_TO_RIGHT) 336 | elif effect == 'roll_to_top': 337 | self.ctrl.SetEffect(wx.SHOW_EFFECT_ROLL_TO_TOP) 338 | elif effect == 'roll_to_bottom': 339 | self.ctrl.SetEffect(wx.SHOW_EFFECT_ROLL_TO_BOTTOM) 340 | elif effect == 'slide_to_left': 341 | self.ctrl.SetEffect(wx.SHOW_EFFECT_SLIDE_TO_LEFT) 342 | elif effect == 'slide_to_right': 343 | self.ctrl.SetEffect(wx.SHOW_EFFECT_SLIDE_TO_RIGHT) 344 | elif effect == 'slide_to_top': 345 | self.ctrl.SetEffect(wx.SHOW_EFFECT_SLIDE_TO_TOP) 346 | elif effect == 'slide_to_bottom': 347 | self.ctrl.SetEffect(wx.SHOW_EFFECT_SLIDE_TO_BOTTOM) 348 | elif effect == 'blend': 349 | self.ctrl.SetEffect(wx.SHOW_EFFECT_BLEND) 350 | elif effect == 'expand': 351 | self.ctrl.SetEffect(wx.SHOW_EFFECT_EXPAND) 352 | else: 353 | self.ctrl.SetEffect(wx.SHOW_EFFECT_NONE) 354 | def setPage(self,index): 355 | if self.style == 'simple': 356 | if index >= len(self.simplePages): 357 | index = 0 358 | self.ctrl.ShowNewPage(self.simplePages[index]) 359 | 360 | class Notebook(Book): 361 | def __init__(self,layouts,parent=None,create=False,horizontal=True,expand=False,proportion=0,size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 362 | super().__init__(layouts,parent,create,horizontal,expand,proportion,style='note',size=size,pos=pos,key=key) 363 | 364 | class Choicebook(Book): 365 | def __init__(self,layouts,parent=None,create=False,horizontal=True,expand=False,proportion=0,size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 366 | super().__init__(layouts,parent,create,horizontal,expand,proportion,style='choice',size=size,pos=pos,key=key) 367 | 368 | class Simplebook(Book): 369 | def __init__(self,layouts,parent=None,create=False,horizontal=True,expand=False,proportion=0,size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 370 | super().__init__(layouts,parent,create,horizontal,expand,proportion,style='simple',size=size,pos=pos,key=key) 371 | 372 | class Panel(Control): 373 | import wx.lib.scrolledpanel 374 | def __init__(self,layout,parent=None,create=False,expand=False,proportion=0,border=2, 375 | size=wx.DefaultSize,pos=wx.DefaultPosition,label="",style=None,key=None): 376 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 377 | self.layout = layout 378 | self.label = label 379 | self.style = style 380 | if create is True and parent is not None: 381 | self.create(parent) 382 | def create(self,parent): 383 | if self.style is None: 384 | self.ctrl = wx.Panel( parent, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL ) 385 | self.sizer = makeLayout(self.layout,self.ctrl) 386 | self.ctrl.SetSizer( self.sizer.ctrl ) 387 | self.ctrl.Layout() 388 | elif self.style == 'scroll': 389 | self.ctrl = wx.lib.scrolledpanel.ScrolledPanel( parent, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.HSCROLL|wx.VSCROLL|wx.TAB_TRAVERSAL ) 390 | self.sizer = makeLayout(self.layout,self.ctrl) 391 | self.ctrl.SetSizer( self.sizer.ctrl ) 392 | #begin for scrolledwindow 393 | self.ctrl.SetAutoLayout(1) 394 | #self.ctrl.SetupScrolling(scroll_y = True) 395 | width = self.ctrl.GetBestSize().width 396 | height = self.ctrl.GetBestSize().height 397 | self.ctrl.SetSize((width, height)) 398 | self.ctrl.SetScrollbars( 1, 1, 1, 1 ) 399 | self.sizer.ctrl.SetSizeHints(self.ctrl) 400 | #end 401 | self.ctrl.Layout() 402 | elif self.style == 'collapsible': 403 | self.ctrl = wx.CollapsiblePane( parent, wx.ID_ANY, self.label, wx.DefaultPosition, wx.DefaultSize, wx.CP_DEFAULT_STYLE|wx.CP_NO_TLW_RESIZE ) 404 | pane = self.ctrl.GetPane() 405 | self.sizer = makeLayout(self.layout,pane) 406 | pane.SetSizer( self.sizer.ctrl ) 407 | self.ctrl.Expand() 408 | self.sizer.ctrl.SetSizeHints(pane) 409 | pane.Layout() 410 | 411 | class ScrolledPanel(Panel): 412 | def __init__(self,layout,parent=None,create=False,expand=False,proportion=0,size=wx.DefaultSize,pos=wx.DefaultPosition,label="",key=None): 413 | super().__init__(layout,parent=parent,create=create,expand=expand,proportion=proportion,size=size,pos=pos,label=label,style='scroll',key=key) 414 | 415 | class CollapsiblePanel(Panel): 416 | def __init__(self,layout,parent=None,create=False,expand=False,proportion=0,size=wx.DefaultSize,pos=wx.DefaultPosition,label="",key=None): 417 | super().__init__(layout,parent=parent,create=create,expand=expand,proportion=proportion,size=size,pos=pos,label=label,style='collapsible',key=key) 418 | 419 | ##class Scroll(Control): #TODO: Change ScrolledWindow -> ScrolledPane 420 | ## def __init__(self,layout,parent=None,create=False,horizontal=True,expand=False,proportion=0,key=None): 421 | ## super().__init__(key,expand,proportion) 422 | ## self.layout = layout 423 | ## if create is True and parent is not None: 424 | ## self.create(parent) 425 | ## def create(self,parent): 426 | ## self.ctrl = wx.ScrolledWindow( parent, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.HSCROLL|wx.VSCROLL ) 427 | ## #self.ctrl.EnableScrolling(True,True) 428 | ## #self.ctrl.SetAutoLayout(1) 429 | ## #self.ctrl.ShowScrollbars( True, True ) 430 | ## self.sizer = makeLayout(self.layout,self.ctrl) 431 | ## self.ctrl.SetSizer( self.sizer.ctrl ) 432 | ## width = self.ctrl.GetBestSize().width 433 | ## height = self.ctrl.GetBestSize().height 434 | ## self.ctrl.SetSize((width, height)) 435 | ## self.ctrl.SetScrollbars( 1, 1, 1, 1 ) 436 | ## #self.ctrl.SetScrollRate( 5, 5 ) 437 | ## #panel = Panel(self.layout, self.ctrl, create=True) 438 | ## #self.ctrl.SetSizer( wrapSizer(panel.ctrl) ) 439 | ## self.ctrl.Layout() 440 | 441 | class Spliter(Control): 442 | def __init__(self,layouts,parent=None,create=False,style='vertical',expand=False,proportion=0,border=2,size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 443 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 444 | self.layouts = layouts #left(top),right(bottom) 445 | self.style = style 446 | if create is True and parent is not None: 447 | self.create(parent) 448 | def create(self,parent): 449 | self.ctrl = wx.SplitterWindow( parent, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.SP_3D ) 450 | self.sashpos = 0 451 | self.panels = [] 452 | for layout in self.layouts: 453 | if type(layout) is int: 454 | self.sashpos = layout 455 | else: 456 | self.panels.append(Panel(layout, self.ctrl, create=True)) 457 | if self.style == 'vertical': 458 | self.ctrl.SplitVertically( self.panels[0].ctrl, self.panels[1].ctrl, self.sashpos ) 459 | else: 460 | self.ctrl.SplitHorizontally( self.panels[0].ctrl, self.panels[1].ctrl, self.sashpos ) 461 | 462 | class VerticalSpliter(Spliter): 463 | def __init__(self,layouts,parent=None,create=False,expand=False,proportion=0,border=2,size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 464 | super().__init__(layouts,parent=parent,create=create,style='vertical',expand=expand,proportion=proportion,border=border,size=size,pos=pos,key=key) 465 | 466 | class HorizontalSpliter(Spliter): 467 | def __init__(self,layouts,parent=None,create=False,expand=False,proportion=0,border=2,size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 468 | super().__init__(layouts,parent=parent,create=create,style='horizontal',expand=expand,proportion=proportion,border=border,size=size,pos=pos,key=key) 469 | 470 | class MultiSpliter(Control): 471 | import wx.lib.splitter 472 | def __init__(self,layouts,parent=None,create=False,style='vertical',expand=False,proportion=0,border=2,size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 473 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 474 | self.layouts = layouts #left(top),right(bottom) 475 | self.style = style 476 | if create is True and parent is not None: 477 | self.create(parent) 478 | def create(self,parent): 479 | self.ctrl = wx.lib.splitter.MultiSplitterWindow( parent, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0 ) 480 | self.sashpos = [] 481 | self.panels = [] 482 | for layout in self.layouts: 483 | if type(layout) is int: 484 | self.sashpos.append(layout) 485 | else: 486 | self.panels.append(Panel(layout, self.ctrl, create=True)) 487 | if self.style == 'vertical': # reverted concept compared with Splitter 488 | self.ctrl.SetOrientation(wx.HORIZONTAL) 489 | else: 490 | self.ctrl.SetOrientation(wx.VERTICAL) 491 | for i in range(len(self.panels)): 492 | self.ctrl.AppendWindow(self.panels[i].ctrl, self.sashpos[i]) 493 | 494 | class VerticalMultiSpliter(MultiSpliter): 495 | def __init__(self,layouts,parent=None,create=False,expand=False,proportion=0,border=2,size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 496 | super().__init__(layouts,parent=parent,create=create,style='vertical',expand=expand,proportion=proportion,border=border,size=size,pos=pos,key=key) 497 | 498 | class HorizontalMultiSpliter(MultiSpliter): 499 | def __init__(self,layouts,parent=None,create=False,expand=False,proportion=0,border=2,size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 500 | super().__init__(layouts,parent=parent,create=create,style='horizontal',expand=expand,proportion=proportion,border=border,size=size,pos=pos,key=key) 501 | 502 | 503 | ###################################################################### 504 | # Controls 505 | ###################################################################### 506 | 507 | class FileDrop(wx.FileDropTarget): 508 | def __init__(self, window): 509 | wx.FileDropTarget.__init__(self) 510 | self.window = window 511 | def OnDropFiles(self, x, y, filenames): 512 | self.window.drop_handle(filenames) 513 | return True 514 | 515 | class Bitmap(Control): 516 | def __init__(self,filename=None,bitmap=None,expand=False,proportion=0,border=2, 517 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None,tooltip=None): 518 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos,tooltip=tooltip) 519 | self.bitmap = bitmap 520 | self.filename = filename 521 | def create(self,parent): 522 | flags = wx.ALIGN_CENTER 523 | if self.filename is not None: 524 | self.bitmap = wx.Bitmap( self.filename, wx.BITMAP_TYPE_ANY ) 525 | self.ctrl = wx.StaticBitmap( parent, wx.ID_ANY, self.bitmap, self.pos, self.size, 0|flags ) 526 | self.ctrl.Bind( wx.EVT_SIZE, self.onEvtBitmapSize ) 527 | if self.key is not None: 528 | registerCtrl( self.key, self ) 529 | def onEvtBitmapSize(self,event): 530 | #print("onEvtBitmapSize()",event.GetSize()) #(width, height) 531 | event.Skip() 532 | #TODO: getValue,setValue check 533 | 534 | class Button(Control): 535 | def __init__(self,label="",handler=None,expand=False,proportion=0,border=2, 536 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None,tooltip=None): 537 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos,tooltip=tooltip) 538 | self.label = label 539 | self.handler = handler 540 | def create(self,parent): 541 | id = getId() 542 | if type(self.label) is str: 543 | self.ctrl = wx.Button( parent, id, self.label, self.pos, self.size, 0 ) 544 | else: 545 | self.ctrl = wx.BitmapButton( parent, id, getButtonBitmap(self.label), self.pos, self.size, 0 ) 546 | if self.handler: 547 | self.ctrl.Bind( wx.EVT_BUTTON, self.handler, id=id ) 548 | if self.tooltip: 549 | self.ctrl.SetToolTip(wx.ToolTip(self.tooltip)) 550 | if self.key: 551 | registerCtrl( self.key, self ) 552 | def getValue(self): 553 | pass 554 | def setValue(self,value): 555 | pass 556 | def clearValue(self): 557 | pass 558 | def appendValue(self,value): 559 | pass 560 | def removeValue(self,value): 561 | pass 562 | 563 | class Calendar(Control): 564 | def __init__(self,handler=None,date=None,expand=False,proportion=0,border=2, 565 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 566 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 567 | self.date = date 568 | self.handler = handler 569 | def create(self,parent): 570 | self.ctrl = wx.adv.CalendarCtrl( parent, wx.ID_ANY, wx.DefaultDateTime, self.pos, self.size, wx.adv.TP_DEFAULT ) 571 | self.ctrl.Bind( wx.adv.EVT_CALENDAR, self.handler ) #double click 572 | self.ctrl.Bind( wx.adv.EVT_CALENDAR_SEL_CHANGED, self.handler ) 573 | if self.key is not None: 574 | registerCtrl( self.key, self ) 575 | #TODO: getValue,setValue check 576 | 577 | class CheckButton(Control): 578 | def __init__(self,label="",value=None,handler=None,expand=False,proportion=0,border=2, 579 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None,tooltip=None): 580 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos,tooltip=tooltip) 581 | self.label = label 582 | self.handler = handler 583 | self.value = value 584 | def create(self,parent): 585 | id = getId() 586 | self.ctrl = wx.CheckBox( parent, id, self.label, self.pos, self.size, 0 ) 587 | self.ctrl.Bind( wx.EVT_CHECKBOX, self.handler, id=id ) 588 | if self.value is not None: 589 | self.setValue(self.value) 590 | if self.tooltip is not None: 591 | self.ctrl.SetToolTip(wx.ToolTip(self.tooltip)) 592 | if self.key is not None: 593 | registerCtrl( self.key, self ) 594 | def clearValue(self): 595 | pass 596 | def appendValue(self,value): 597 | pass 598 | def removeValue(self,value): 599 | pass 600 | def castValue(self,value): 601 | return bool(value) 602 | 603 | class Check(CheckButton): 604 | def __init__(self,label="",value=None,handler=None,expand=False,proportion=0,border=2, 605 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None,tooltip=None): 606 | super().__init__(label,value,handler,expand,proportion,border,size,pos,key,tooltip) 607 | 608 | class Choice(Control): 609 | def __init__(self,choices=[],select=0,handler=None,expand=False,proportion=0,border=2, 610 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 611 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 612 | self.choices = choices 613 | self.select = select 614 | self.handler = handler 615 | def create(self,parent): 616 | id = getId() 617 | self.ctrl = wx.Choice( parent, id, self.pos, self.size, self.choices, 0 ) 618 | self.ctrl.SetSelection(self.select) 619 | self.ctrl.Bind( wx.EVT_CHOICE, self.handler, id=id ) 620 | if self.key is not None: 621 | registerCtrl( self.key, self ) 622 | def getValue(self,): 623 | return self.ctrl.GetString(self.ctrl.GetCurrentSelection()) 624 | def setValue(self,value): 625 | n = self.ctrl.FindString(value) 626 | if n != wx.NOT_FOUND: 627 | self.ctrl.SetSelection(n) 628 | 629 | class Clock(Control): 630 | import wx.lib.analogclock 631 | def __init__(self,handler=None,date=None,expand=False,proportion=0,border=2, 632 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 633 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 634 | self.date = date 635 | self.handler = handler 636 | def create(self,parent): 637 | self.ctrl = wx.lib.analogclock.analogclock.AnalogClock( parent, wx.ID_ANY, self.pos, self.size, wx.NO_BORDER) 638 | if self.key is not None: 639 | registerCtrl( self.key, self ) 640 | #TODO: getValue,setValue check 641 | 642 | class Combo(Control): 643 | def __init__(self,choices=[],value=None,handler=None,expand=False,proportion=0,border=2, 644 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 645 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 646 | self.choices = choices 647 | self.value = value 648 | self.handler = handler 649 | def create(self,parent): 650 | id = getId() 651 | if self.value is None: 652 | self.value = self.choices[0] 653 | self.ctrl = wx.ComboBox( parent, id, self.value, self.pos, self.size, self.choices, 0 ) 654 | #self.ctrl.SetValue(self.value) 655 | self.ctrl.Bind( wx.EVT_COMBOBOX, self.handler, id=id ) 656 | if self.key is not None: 657 | registerCtrl( self.key, self ) 658 | 659 | class Date(Control): 660 | def __init__(self,date=None,expand=False,proportion=0,border=2, 661 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 662 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 663 | self.date = date 664 | def create(self,parent): 665 | self.ctrl = wx.adv.DatePickerCtrl( parent, wx.ID_ANY, wx.DefaultDateTime, self.pos, self.size, wx.adv.TP_DEFAULT ) 666 | if self.key is not None: 667 | registerCtrl( self.key, self ) 668 | #TODO: getValue,setValue check 669 | 670 | class Gauge(Control): #842 671 | def __init__(self,expand=False,proportion=0,border=2, 672 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 673 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 674 | def create(self,parent): 675 | self.ctrl = wx.Gauge(parent=parent,pos=self.pos,size=self.size) 676 | if self.key is not None: 677 | registerCtrl( self.key, self ) 678 | def setMaxValue(self,maxValue): 679 | self.ctrl.SetRange(maxValue) 680 | def update(self,percent): 681 | wx.CallAfter(self.updateAfter, percent) 682 | def updateAfter(self,percent): 683 | self.ctrl.SetValue(percent) 684 | def pulse(self): 685 | wx.CallAfter(self.pulseAfter) 686 | def pulseAfter(self): 687 | self.ctrl.Pulse() 688 | #TODO: getValue,setValue check 689 | 690 | class Label(Control): 691 | def __init__(self,text="",expand=False,proportion=0,border=2,multiline=False, 692 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None,tooltip=None,align='center'): 693 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos,tooltip=tooltip) 694 | self.text = text 695 | self.multiline = multiline 696 | self.align = align 697 | def create(self,parent): 698 | flags = wx.ALIGN_CENTER 699 | if self.align == 'left': flags = wx.ALIGN_LEFT 700 | if self.align == 'right': flags = wx.ALIGN_RIGHT 701 | flags |= wx.ALIGN_CENTER_VERTICAL 702 | if self.multiline == True: flags |= wx.TE_MULTILINE 703 | self.ctrl = wx.StaticText( parent, wx.ID_ANY, self.text, self.pos, self.size, 0|flags ) 704 | if self.tooltip is not None: 705 | self.ctrl.SetToolTip(wx.ToolTip(self.tooltip)) 706 | if self.key is not None: 707 | registerCtrl( self.key, self ) 708 | def getValue(self): 709 | return self.ctrl.GetLabel() 710 | def setValue(self,item): 711 | self.ctrl.SetLabel(item) 712 | def clearValue(self): 713 | pass 714 | def appendValue(self,value): 715 | pass 716 | def removeValue(self,value): 717 | pass 718 | 719 | class LedNumber(Control): 720 | import wx.lib.gizmos.ledctrl 721 | def __init__(self,text="",expand=False,proportion=0,border=2, 722 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 723 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 724 | self.text = text 725 | def create(self,parent): 726 | flags = wx.lib.gizmos.ledctrl.LED_ALIGN_LEFT|wx.lib.gizmos.ledctrl.LED_DRAW_FADED 727 | self.ctrl = wx.lib.gizmos.ledctrl.LEDNumberCtrl( parent, wx.ID_ANY, self.pos, self.size, flags ) 728 | self.ctrl.SetValue(self.text) 729 | if self.key is not None: 730 | registerCtrl( self.key, self ) 731 | #TODO: getValue,setValue check 732 | 733 | class Line(Control): 734 | def __init__(self,text="",expand=False,proportion=0,border=2,style="horizontal", 735 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 736 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 737 | self.style = style 738 | def create(self,parent): 739 | flags = wx.LI_HORIZONTAL if self.style == "horizontal" else wx.LI_VERTICAL 740 | self.ctrl = wx.StaticLine( parent, wx.ID_ANY, self.pos, self.size, 0|flags ) 741 | if self.key is not None: 742 | registerCtrl( self.key, self ) 743 | #TODO: getValue,setValue check 744 | 745 | class Link(Control): 746 | def __init__(self,text="",url="",expand=False,proportion=0,border=2, 747 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None,tooltip=None): 748 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos,tooltip=tooltip) 749 | self.text = text 750 | self.url = url 751 | def create(self,parent): 752 | self.ctrl = wx.adv.HyperlinkCtrl( parent, wx.ID_ANY, self.text, self.url, self.pos, self.size) 753 | if self.tooltip is not None: 754 | self.ctrl.SetToolTip(wx.ToolTip(self.tooltip)) 755 | if self.key is not None: 756 | registerCtrl( self.key, self ) 757 | #TODO: getValue,setValue check 758 | 759 | class List(Control): 760 | def __init__(self,choices=[],select=0,handler=None,expand=False,proportion=0,border=2, 761 | size=wx.DefaultSize,pos=wx.DefaultPosition,check=False,label="",style=None,key=None): 762 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 763 | self.choices = choices 764 | self.select = select 765 | self.handler = handler 766 | self.check = check 767 | self.label = label 768 | self.style = style 769 | def create(self,parent): 770 | import sys 771 | id = getId() 772 | if self.style is None: 773 | if self.check is True: 774 | self.ctrl = wx.CheckListBox( parent, id, self.pos, self.size, self.choices, 0 ) 775 | else: 776 | self.ctrl = wx.ListBox( parent, id, self.pos, self.size, self.choices, 0 ) 777 | if self.select < len(self.choices): 778 | self.ctrl.SetSelection(self.select) 779 | self.ctrl.SetDropTarget(FileDrop(self)) 780 | self.ctrl.Bind( wx.EVT_LISTBOX, self.handler, id=id ) 781 | elif self.style == 'multicol': 782 | self.ctrl = wx.ListCtrl(parent, id, style = wx.LC_REPORT) 783 | widths = [] 784 | if len(self.choices) > 1: 785 | aligns = (wx.LIST_FORMAT_LEFT, wx.LIST_FORMAT_CENTER, wx.LIST_FORMAT_RIGHT) 786 | cols = len(self.choices[0]) 787 | for col in range(cols): 788 | label = self.choices[0][col][0] 789 | width = self.choices[0][col][1] 790 | align = aligns[self.choices[0][col][2]+1] 791 | self.ctrl.AppendColumn(label, align, width) 792 | #self.ctrl.InsertColumn(col, label, align, width) 793 | for row in range(1,len(self.choices)): 794 | self.ctrl.Append(self.choices[row]) 795 | elif self.style == 'edit': 796 | self.ctrl = wx.adv.EditableListBox( parent, id, self.label, self.pos, self.size, 0 ) 797 | #TODO: 798 | if self.key is not None: 799 | registerCtrl( self.key, self ) 800 | def drop_handle(self,filenames): 801 | for filename in filenames: 802 | self.ctrl.Append(filename) 803 | def getValue(self,): 804 | return self.ctrl.GetString(self.ctrl.GetSelection()) 805 | def setValue(self,item): 806 | n = self.ctrl.FindString(item) 807 | if n != wx.NOT_FOUND: 808 | self.ctrl.SetSelection(n) 809 | 810 | class Picker(Control): 811 | def __init__(self,style="",value=None,handler=None,expand=False,proportion=0,border=2, 812 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 813 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 814 | self.style = style 815 | self.value = value 816 | self.handler = handler 817 | def create(self,parent): 818 | id = getId() 819 | if self.style == 'dir': #value: path str 820 | self.value = "" if self.value is None else self.value 821 | self.ctrl = wx.DirPickerCtrl( parent, id, self.value, pos=self.pos, size=self.size, style=wx.DIRP_DEFAULT_STYLE ) 822 | self.ctrl.Bind( wx.EVT_DIRPICKER_CHANGED, self.handler, id=id ) 823 | elif self.style == 'file': 824 | self.value = "" if self.value is None else self.value 825 | self.ctrl = wx.FilePickerCtrl( parent, id, self.value, pos=self.pos, size=self.size, style=wx.FLP_DEFAULT_STYLE ) 826 | self.ctrl.Bind( wx.EVT_FILEPICKER_CHANGED, self.handler, id=id ) 827 | elif self.style == 'color': 828 | self.value = wx.BLACK if self.value is None else self.value 829 | self.ctrl = wx.ColourPickerCtrl( parent, id, self.value, pos=self.pos, size=self.size, style=wx.CLRP_DEFAULT_STYLE ) 830 | self.ctrl.Bind( wx.EVT_COLOURPICKER_CHANGED, self.handler, id=id ) 831 | elif self.style == 'font': 832 | self.value = wx.NullFont if self.value is None else self.value 833 | self.ctrl = wx.FontPickerCtrl( parent, id, self.value, pos=self.pos, size=self.size, style=wx.FNTP_DEFAULT_STYLE ) 834 | self.ctrl.Bind( wx.EVT_FONTPICKER_CHANGED, self.handler, id=id ) 835 | elif self.style == 'date': 836 | self.value = wx.DefaultDateTime if self.value is None else self.value 837 | self.ctrl = wx.adv.DatePickerCtrl( parent, id, self.value, pos=self.pos, size=self.size, style=wx.adv.TP_DEFAULT ) 838 | self.ctrl.Bind( wx.adv.EVT_DATE_CHANGED, self.handler, id=id ) 839 | elif self.style == 'time': 840 | self.value = wx.DefaultDateTime if self.value is None else self.value 841 | self.ctrl = wx.adv.TimePickerCtrl( parent, id, self.value, pos=self.pos, size=self.size, style=wx.adv.TP_DEFAULT ) 842 | self.ctrl.Bind( wx.adv.EVT_TIME_CHANGED, self.handler, id=id ) 843 | else: #TODO: throw exception 844 | pass 845 | if self.key is not None: 846 | registerCtrl( self.key, self ) 847 | #TODO: getValue,setValue check 848 | 849 | class DirPicker(Picker): 850 | def __init__(self,style="",value=None,handler=None,expand=False,proportion=0,border=2, 851 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 852 | super().__init__('dir',value,handler,expand,proportion,border,size,pos,key) 853 | 854 | class FilePicker(Picker): 855 | def __init__(self,style="",value=None,handler=None,expand=False,proportion=0,border=2, 856 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 857 | super().__init__('file',value,handler,expand,proportion,border,size,pos,key) 858 | 859 | class ColorPicker(Picker): 860 | def __init__(self,style="",value=None,handler=None,expand=False,proportion=0,border=2, 861 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 862 | super().__init__('color',value,handler,expand,proportion,border,size,pos,key) 863 | 864 | class FontPicker(Picker): 865 | def __init__(self,style="",value=None,handler=None,expand=False,proportion=0,border=2, 866 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 867 | super().__init__('font',value,handler,expand,proportion,border,size,pos,key) 868 | 869 | class DatePicker(Picker): 870 | def __init__(self,style="",value=None,handler=None,expand=False,proportion=0,border=2, 871 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 872 | super().__init__('date',value,handler,expand,proportion,border,size,pos,key) 873 | 874 | class TimePicker(Picker): 875 | def __init__(self,style="",value=None,handler=None,expand=False,proportion=0,border=2, 876 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 877 | super().__init__('time',value,handler,expand,proportion,border,size,pos,key) 878 | 879 | class Progress(Control): 880 | import wx.lib.progressindicator as pi 881 | def __init__(self,expand=False,proportion=0,border=2, 882 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 883 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 884 | def create(self,parent): 885 | self.ctrl = wx.lib.progressindicator.ProgressIndicator(parent=parent,pos=self.pos,size=self.size) 886 | if self.key is not None: 887 | registerCtrl( self.key, self ) 888 | def setMaxValue(self,maxValue): 889 | self.ctrl.SetRange(maxValue) 890 | def update(self,percent): 891 | wx.CallAfter(self.callAfter, percent) 892 | def callAfter(self,percent): 893 | self.ctrl.SetValue(percent) 894 | #TODO: getValue,setValue check 895 | 896 | class Radio(Control): 897 | def __init__(self,label="",choices=[],value="",handler=None,expand=False,proportion=0,border=2, 898 | size=wx.DefaultSize,pos=wx.DefaultPosition,style='row',key=None): 899 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 900 | self.label = label 901 | self.choices = choices 902 | self.value = value 903 | self.handler = handler 904 | self.style = wx.RA_SPECIFY_ROWS if style == 'row' else wx.RA_SPECIFY_COLS 905 | def create(self,parent): 906 | id = getId() 907 | self.ctrl = wx.RadioBox( parent, id, self.label, self.pos, self.size, self.choices, 0, self.style ) 908 | self.ctrl.Bind( wx.EVT_RADIOBOX, self.handler, id=id ) 909 | for i in range(len(self.choices)): 910 | if self.value == self.choices[i]: 911 | self.ctrl.SetSelection(i) 912 | break 913 | if self.key is not None: 914 | registerCtrl( self.key, self ) 915 | #TODO: getValue,setValue check 916 | 917 | class Slider(Control): 918 | def __init__(self,text="",value=0,minValue=0,maxValue=100,handler=None,expand=False,proportion=0,border=2, 919 | size=wx.DefaultSize,pos=wx.DefaultPosition,style="horizontal",key=None): 920 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 921 | self.value = value 922 | self.minValue = minValue 923 | self.maxValue = maxValue 924 | self.handler = handler 925 | self.style = style 926 | def create(self,parent): 927 | id = getId() 928 | flags = wx.SL_HORIZONTAL if self.style == "horizontal" else wx.SL_VERTICAL 929 | self.ctrl = wx.Slider( parent, id, self.value, self.minValue, self.maxValue, self.pos, self.size, 0|flags ) 930 | self.ctrl.Bind( wx.EVT_SLIDER, self.handler, id=id ) 931 | if self.key is not None: 932 | registerCtrl( self.key, self ) 933 | #TODO: getValue,setValue check 934 | 935 | class Spin(Control): 936 | def __init__(self,text="",value="",minValue=0,maxValue=100,handler=None,expand=False,proportion=0,border=2, 937 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 938 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 939 | self.value = str(value) 940 | self.minValue = minValue 941 | self.maxValue = maxValue 942 | self.handler = handler 943 | def create(self,parent): 944 | id = getId() 945 | flags = wx.SP_ARROW_KEYS 946 | self.ctrl = wx.SpinCtrl( parent, id, self.value, self.pos, self.size, 0|flags, self.minValue, self.maxValue ) 947 | self.ctrl.Bind( wx.EVT_SPIN, self.handler, id=id ) 948 | if self.key is not None: 949 | registerCtrl( self.key, self ) 950 | #TODO: getValue,setValue check 951 | 952 | class StyledText(Control): 953 | import wx.stc 954 | def __init__(self,text="",handler=None,expand=True,proportion=1,border=2, 955 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 956 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 957 | self.text = text 958 | self.handler = handler 959 | def create(self,parent): 960 | flags = 0 961 | self.ctrl = wx.stc.StyledTextCtrl( parent, wx.ID_ANY, self.pos, self.size, 0|flags ) 962 | self.enableLineNumber() 963 | self.ctrl.SetText(self.text) 964 | drop_target = FileDrop(self) 965 | self.ctrl.SetDropTarget(drop_target) 966 | if self.key is not None: 967 | registerCtrl( self.key, self ) 968 | def drop_handle(self,filenames): 969 | for filename in filenames: 970 | self.ctrl.AppendText( filename + '\n' ) 971 | def enableLineNumber(self): 972 | #self.stc.SetProperty("fold", "1") 973 | #self.stc.SetProperty("fold.html", "1") 974 | self.ctrl.SetMargins(0, 0) 975 | self.ctrl.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER) 976 | self.ctrl.SetMarginMask(2, wx.stc.STC_MASK_FOLDERS) 977 | self.ctrl.SetMarginSensitive(2, True) 978 | self.ctrl.SetMarginWidth(1, 32) # 2,25 979 | self.ctrl.SetMarginWidth(2, 16) # 2,25 980 | #TODO: getValue,setValue check 981 | 982 | class Text(Control): 983 | def __init__(self,text="",handler=None,expand=True,proportion=0,border=2, 984 | size=wx.DefaultSize,pos=wx.DefaultPosition, 985 | multiline=False,password=False,readonly=False,wrap=True,key=None): 986 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 987 | self.text = text 988 | self.multiline = multiline 989 | self.password = password 990 | self.readonly = readonly 991 | self.wrap = wrap 992 | self.handler = handler 993 | #self.expand = True if multiline == True else False 994 | def create(self,parent): 995 | id = getId() 996 | flags = 0 997 | flags |= wx.TE_MULTILINE if self.multiline is True else 0 998 | flags |= wx.TE_PASSWORD if self.password is True else 0 999 | flags |= wx.TE_READONLY if self.readonly is True else 0 1000 | flags |= wx.TE_DONTWRAP if self.wrap is False else 0 1001 | self.ctrl = wx.TextCtrl( parent, id, self.text, self.pos, self.size, 0|flags ) 1002 | self.ctrl.Bind( wx.EVT_TEXT, self.handler, id=id ) 1003 | #self.ctrl.Bind( wx.EVT_CHAR, self.handler ) 1004 | drop_target = FileDrop(self) 1005 | self.ctrl.SetDropTarget(drop_target) 1006 | if self.key is not None: 1007 | registerCtrl( self.key, self ) 1008 | def drop_handle(self,filenames): 1009 | for filename in filenames: 1010 | self.ctrl.AppendText( filename ) 1011 | if self.multiline is False: 1012 | break 1013 | self.ctrl.AppendText( '\n' ) 1014 | def appendValue(self,value): 1015 | self.ctrl.AppendText(value) 1016 | 1017 | class Ticker(Control): 1018 | import wx.lib.ticker 1019 | def __init__(self,text="",fgcolor=wx.BLACK,bgcolor=wx.WHITE,expand=True,proportion=0,border=2, 1020 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 1021 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 1022 | self.text = text 1023 | self.fgcolor = fgcolor 1024 | self.bgcolor = bgcolor 1025 | def create(self,parent): 1026 | self.ctrl = wx.lib.ticker.Ticker( parent, wx.ID_ANY, self.text, self.fgcolor, self.bgcolor, True, pos=self.pos, size=self.size, style=wx.NO_BORDER ) 1027 | self.ctrl.Bind(wx.EVT_CLOSE, self.onClose) 1028 | if self.key is not None: 1029 | registerCtrl( self.key, self ) 1030 | def onClose(self,event): 1031 | self.ctrl.Stop() 1032 | event.Skip() 1033 | #TODO: getValue,setValue check 1034 | 1035 | class Time(Control): 1036 | def __init__(self,date=None,expand=False,proportion=0,border=2, 1037 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 1038 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 1039 | self.date = date 1040 | def create(self,parent): 1041 | self.ctrl = wx.adv.TimePickerCtrl( parent, wx.ID_ANY, wx.DefaultDateTime, self.pos, self.size, wx.adv.TP_DEFAULT ) 1042 | if self.key is not None: 1043 | registerCtrl( self.key, self ) 1044 | #TODO: getValue,setValue check 1045 | 1046 | class ToggleButton(Control): 1047 | def __init__(self,label="",value=None,handler=None,expand=False,proportion=0,border=2, 1048 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None,tooltip=None): 1049 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos,tooltip=tooltip) 1050 | self.label = label 1051 | self.value = value 1052 | self.handler = handler 1053 | def create(self,parent): 1054 | id = getId() 1055 | if type(self.label) is str: 1056 | self.ctrl = wx.ToggleButton( parent, id, self.label, self.pos, self.size, 0 ) 1057 | self.ctrl.Bind( wx.EVT_TOGGLEBUTTON, self.handler, id=id ) 1058 | else: #byte[] 1059 | self.ctrl = wx.BitmapToggleButton( parent, id, getButtonBitmap(self.label), self.pos, self.size, 0 ) 1060 | self.ctrl.Bind( wx.EVT_TOGGLEBUTTON, self.handler, id=id ) 1061 | if self.value is not None: 1062 | self.setValue(self.value) 1063 | if self.tooltip is not None: 1064 | self.ctrl.SetToolTip(wx.ToolTip(self.tooltip)) 1065 | if self.key is not None: 1066 | registerCtrl( self.key, self ) 1067 | def clearValue(self): 1068 | pass 1069 | def appendValue(self,value): 1070 | pass 1071 | def removeValue(self,value): 1072 | pass 1073 | def castValue(self,value): 1074 | return bool(value) 1075 | 1076 | class Tree(Control): 1077 | def __init__(self,data=None,collapse=False,handler=None,expand=False,proportion=0,border=2, 1078 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 1079 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 1080 | self.data = data 1081 | self.collapse = collapse 1082 | self.handler = handler 1083 | def create(self,parent): 1084 | id = getId() 1085 | self.ctrl = wx.TreeCtrl( parent, id, self.pos, self.size, wx.TR_DEFAULT_STYLE ) 1086 | self.ctrl.Bind( wx.EVT_TREE_SEL_CHANGED, self.handler, id=id ) 1087 | if self.data is not None: 1088 | root = self.ctrl.AddRoot(self.data[0]) 1089 | if type(self.data[1]) is list: 1090 | self.addItems(root,self.data[1]) 1091 | if self.collapse is not True: 1092 | self.ctrl.ExpandAllChildren(root) 1093 | if self.key is not None: 1094 | registerCtrl( self.key, self ) 1095 | def addItems(self,parent,data): 1096 | node = None 1097 | for item in data: 1098 | if type(item) is list and node is not None: 1099 | self.addItems(node,item) 1100 | else: #list 1101 | node = self.ctrl.AppendItem(parent,item) 1102 | #TODO: getValue,setValue check 1103 | 1104 | class Web(Control): 1105 | import wx.lib.iewin 1106 | def __init__(self,url=None,engine='ie',expand=False,proportion=0,border=2, 1107 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 1108 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 1109 | self.url = url 1110 | self.engine = engine 1111 | def create(self,parent): 1112 | if self.engine == 'ie': 1113 | self.ctrl = wx.lib.iewin.IEHtmlWindow( parent, wx.ID_ANY, self.pos, self.size, 0 ) 1114 | if self.url is not None: 1115 | self.ctrl.LoadUrl(self.url) 1116 | if self.key is not None: 1117 | registerCtrl( self.key, self ) 1118 | #TODO: getValue,setValue check 1119 | 1120 | class PdfWin(Control): 1121 | import wx.lib.pdfwin 1122 | def __init__(self,url=None,expand=False,proportion=0,border=2, 1123 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 1124 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 1125 | self.url = url 1126 | def create(self,parent): 1127 | self.ctrl = wx.lib.pdfwin.PDFWindow( parent, wx.ID_ANY, self.pos, self.size, 0 ) 1128 | if self.url is not None: 1129 | self.ctrl.LoadFile(self.url) 1130 | if self.key is not None: 1131 | registerCtrl( self.key, self ) 1132 | #TODO: getValue,setValue check 1133 | 1134 | class PdfView(Control): 1135 | import wx.lib.pdfviewer 1136 | def __init__(self,url=None,expand=False,proportion=0,border=2, 1137 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 1138 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 1139 | self.url = url 1140 | def create(self,parent): 1141 | self.ctrl = wx.lib.pdfviewer.pdfViewer( parent, wx.ID_ANY, self.pos, self.size, wx.HSCROLL|wx.VSCROLL|wx.SUNKEN_BORDER ) 1142 | #self.ctrl.SetSizerProps(expand=True, proportion=1) 1143 | #self.buttonpanel = wx.lib.pdfviewer.pdfButtonPanel(parent, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0) 1144 | #self.buttonpanel.SetSizerProps(expand=True) 1145 | #self.buttonpanel.viewer = self.ctrl 1146 | #self.ctrl.buttonpanel = self.buttonpanel 1147 | if self.url is not None: 1148 | self.ctrl.LoadFile(self.url) 1149 | if self.key is not None: 1150 | registerCtrl( self.key, self ) 1151 | #TODO: getValue,setValue check 1152 | 1153 | class Media(Control): 1154 | import wx.media 1155 | def __init__(self,url=None,expand=False,proportion=0,border=2, 1156 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 1157 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 1158 | self.url = url 1159 | def create(self,parent): 1160 | self.ctrl = wx.media.MediaCtrl( parent, wx.ID_ANY, szBackend=wx.media.MEDIABACKEND_WMP10, pos=self.pos, size=self.size ) 1161 | self.ctrl.Bind(wx.media.EVT_MEDIA_LOADED, self.onLoaded) 1162 | if self.url is not None: 1163 | self.ctrl.Load(self.url) 1164 | if self.key is not None: 1165 | registerCtrl( self.key, self ) 1166 | def onLoaded(self,event): 1167 | self.ctrl.Play() 1168 | #TODO: getValue,setValue check 1169 | 1170 | ###################################################################### 1171 | # Clipboard 1172 | ###################################################################### 1173 | def GetClipboardText(): 1174 | if not wx.TheClipboard.IsOpened(): 1175 | do = wx.TextDataObject() 1176 | wx.TheClipboard.Open() 1177 | success = wx.TheClipboard.GetData(do) 1178 | wx.TheClipboard.Close() 1179 | if success: 1180 | return do.GetText() 1181 | return '' 1182 | 1183 | def GetClipboardHtmlText(): 1184 | if not wx.TheClipboard.IsOpened(): 1185 | do = wx.HTMLDataObject() 1186 | wx.TheClipboard.Open() 1187 | success = wx.TheClipboard.GetData(do) 1188 | wx.TheClipboard.Close() 1189 | if success: 1190 | return do.GetHTML() 1191 | return 'No Html Data' 1192 | 1193 | def GetClipboardFilenames(): 1194 | if not wx.TheClipboard.IsOpened(): 1195 | do = wx.FileDataObject() 1196 | wx.TheClipboard.Open() 1197 | success = wx.TheClipboard.GetData(do) 1198 | wx.TheClipboard.Close() 1199 | if success: 1200 | return do.Filenames 1201 | return [] 1202 | 1203 | 1204 | ###################################################################### 1205 | # Compound Control 1206 | ###################################################################### 1207 | class Toolbar(Control): 1208 | def __init__(self,tool_def, largeButton=False,expand=False,proportion=0,border=2,size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 1209 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 1210 | self.ctrl = None 1211 | self.tool_def = tool_def 1212 | self.largeButton = largeButton 1213 | def create(self, parent): #icon, text, handler 1214 | flags = wx.TB_FLAT|wx.TB_HORIZONTAL 1215 | if len(self.tool_def[0]) >= 3: 1216 | flags |= wx.TB_TEXT 1217 | self.ctrl = wx.ToolBar( parent, wx.ID_ANY, pos=wx.DefaultPosition, size=wx.DefaultSize, style=flags) 1218 | for value in self.tool_def: 1219 | if value[0] is None: 1220 | self.ctrl.AddSeparator() 1221 | else: 1222 | text = handler = tooltip = None 1223 | if len(value) >= 2: 1224 | handler = value[1] 1225 | if len(value) >= 3: 1226 | text = value[2] 1227 | if len(value) >= 4: 1228 | tooltip = value[3] 1229 | if self.largeButton: 1230 | icon = getToolbarBitmap(value[0],size=(32,32)) 1231 | else: 1232 | icon = getToolbarBitmap(value[0],size=(24,24)) 1233 | id = getId() 1234 | if text is not None: 1235 | tool = self.ctrl.AddTool( id, text, icon, wx.NullBitmap, wx.ITEM_NORMAL, wx.EmptyString, wx.EmptyString, None ) 1236 | else: 1237 | tool = self.ctrl.AddTool( id, '', icon, wx.NullBitmap, wx.ITEM_NORMAL, wx.EmptyString, wx.EmptyString, None ) 1238 | #tool = self.ctrl.AddSimpleTool( id, icon, wx.EmptyString, wx.EmptyString, None ) 1239 | if tooltip is not None: 1240 | self.ctrl.SetToolShortHelp(id, tooltip); 1241 | if handler is None: 1242 | tool.Enable( False ) 1243 | else: 1244 | self.ctrl.Bind( wx.EVT_TOOL, handler, id = id ) 1245 | self.ctrl.Realize() 1246 | def getValue(self): 1247 | pass 1248 | def setValue(self,item): 1249 | pass 1250 | def clearValue(self): 1251 | pass 1252 | def appendValue(self,value): 1253 | pass 1254 | def removeValue(self,value): 1255 | pass 1256 | 1257 | class FileBrowser(Control): 1258 | def __init__(self,label=None,text=None,buttonText="Browse",handler=None,save=False,directory=False,expand=False,proportion=0,border=2, 1259 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 1260 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 1261 | self.ctrl = None 1262 | self.layout = [[]] 1263 | self.label = label 1264 | self.text = text 1265 | self.buttonText = buttonText 1266 | self.handler = handler 1267 | self.save = save 1268 | self.directory = directory 1269 | def create(self,parent): 1270 | self.textCtrl = Text(self.text, expand=True, proportion=1, border=2) 1271 | self.buttonCtrl = Button(self.buttonText, handler=self.onBrowse, border=2 ) 1272 | if self.label: 1273 | self.layout[0].append( Label(self.label, border=2) ) 1274 | self.layout[0].append( self.textCtrl ) 1275 | self.layout[0].append( self.buttonCtrl ) 1276 | self.layout[0].append( { 'expand' : True, 'border' : 0 } ) 1277 | vbox = makeLayout(self.layout,parent) 1278 | self.ctrl = vbox.ctrl 1279 | if self.key is not None: 1280 | registerCtrl( self.key, self.textCtrl ) 1281 | def onBrowse(self,event): 1282 | if self.directory: 1283 | f = DirectoryDialog(defaultPath=self.text) 1284 | else: 1285 | f = OpenFileDialog(defaultDir=self.text, save=self.save) 1286 | if f is not None: 1287 | self.textCtrl.ctrl.Clear() 1288 | self.textCtrl.ctrl.AppendText(f) 1289 | if self.handler: self.handler(f) 1290 | def getValue(self): 1291 | pass 1292 | def setValue(self,item): 1293 | pass 1294 | def clearValue(self): 1295 | pass 1296 | def appendValue(self,value): 1297 | pass 1298 | def removeValue(self,value): 1299 | pass 1300 | 1301 | class DirectoryBrowser(FileBrowser): 1302 | def __init__(self,label=None,text=None,buttonText="Browse",handler=None,save=False,expand=False,proportion=0,border=2, 1303 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 1304 | super().__init__(label=label,text=text,buttonText=buttonText,handler=handler,save=save,directory=True,expand=expand,proportion=proportion,border=border, 1305 | size=size,pos=pos,key=key) 1306 | 1307 | class ToolbarText(Control): 1308 | def __init__(self,tool_def=None,text='',largeButton=False,multiline=True,handler=None,expand=False,proportion=0,border=2, 1309 | size=wx.DefaultSize,pos=wx.DefaultPosition,key=None): 1310 | super().__init__(key=key,expand=expand,proportion=proportion,border=border,size=size,pos=pos) 1311 | self.ctrl = None 1312 | self.layout = [[], []] #toolbar, text 1313 | self.tool_def = tool_def 1314 | self.text = text 1315 | self.largeButton = largeButton 1316 | self.multiline = multiline 1317 | self.handler = handler 1318 | def create(self,parent): 1319 | if self.tool_def is None: 1320 | self.largeButton = False 1321 | self.tool_def = [ 1322 | [wx.ART_NEW , self.onClear , None, "Clear all text"], 1323 | [wx.ART_COPY , self.onCopy , None, "Copy text to clipboard"], 1324 | [wx.ART_PASTE, self.onPaste , None, "Paste text from clipboard"], 1325 | [wx.ART_PASTE, self.onPasteHtml , None, "Paste html text from clipboard"], 1326 | ] 1327 | self.toolbar = Toolbar(self.tool_def,self.largeButton) 1328 | self.textCtrl = Text(self.text, multiline=self.multiline, expand=True, proportion=1, border=0) 1329 | self.layout[0].append( self.toolbar ) 1330 | self.layout[0].append( { 'expand' : True, 'border' : 0 } ) 1331 | self.layout[1].append( self.textCtrl ) 1332 | self.layout[1].append( { 'expand' : True, 'proportion' : 1, 'border' : 0 } ) 1333 | vbox = makeLayout(self.layout,parent) 1334 | self.ctrl = vbox.ctrl 1335 | if self.key is not None: 1336 | registerCtrl( self.key, self.textCtrl ) 1337 | def onClear(self,event): 1338 | self.textCtrl.ctrl.Clear() 1339 | def onCopy(self,event): 1340 | self.textCtrl.ctrl.Copy() 1341 | def onPaste(self,event): 1342 | self.textCtrl.ctrl.Paste() 1343 | def onPasteHtml(self,event): 1344 | self.textCtrl.ctrl.AppendText(GetClipboardHtmlText()) 1345 | 1346 | 1347 | ###################################################################### 1348 | # Dialogs : deprecated use wxApp.* 1349 | ###################################################################### 1350 | 1351 | def OpenFileDialog(defaultDir="",multiple=False,save=False): 1352 | if not defaultDir: defaultDir = '' 1353 | style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST if save is False else wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT 1354 | style |= wx.FD_MULTIPLE if multiple is True else 0 1355 | dlg = wx.FileDialog(None,defaultDir=defaultDir,style=style) 1356 | rv = dlg.ShowModal() 1357 | if rv == wx.ID_OK: 1358 | if multiple == True: 1359 | files = [] 1360 | for file in dlg.GetFilenames(): 1361 | files.append( os.path.join(dlg.GetDirectory(), file) ) 1362 | return files 1363 | else: 1364 | return os.path.join(dlg.GetDirectory(), dlg.GetFilename()) 1365 | else: 1366 | return None 1367 | 1368 | def SaveFileDialog(defaultDir=""): 1369 | return OpenFileDialog(defaultDir=defaultDir, multiple=False, save=True) 1370 | 1371 | def DirectoryDialog(defaultPath=""): 1372 | dlg = wx.DirDialog(None,defaultPath=defaultPath) 1373 | rv = dlg.ShowModal() 1374 | if rv == wx.ID_OK: 1375 | return dlg.GetPath() 1376 | else: 1377 | return None 1378 | 1379 | def MessageBox(title,message): 1380 | dlg = wx.MessageDialog(None, message, caption=title, style=wx.OK|wx.CENTER, pos=wx.DefaultPosition) 1381 | dlg.ShowModal() 1382 | 1383 | def MessageYesNo(title,message): 1384 | dlg = wx.MessageDialog(None, message, caption=title, style=wx.YES|wx.NO|wx.CENTER, pos=wx.DefaultPosition) 1385 | rv = dlg.ShowModal() 1386 | if rv == wx.ID_OK or rv == wx.ID_YES: 1387 | return True 1388 | else: #wx.ID_CANCEL, wx.ID_NO 1389 | return False 1390 | 1391 | def MessageYesNoCancel(title,message): 1392 | dlg = wx.MessageDialog(None, message, caption=title, style=wx.YES|wx.NO|wx.CANCEL|wx.CENTER, pos=wx.DefaultPosition) 1393 | rv = dlg.ShowModal() 1394 | if rv == wx.ID_OK or rv == wx.ID_YES: 1395 | return True 1396 | elif rv == wx.ID_NO: 1397 | return False 1398 | else: #wx.ID_CANCEL, 1399 | return None 1400 | 1401 | def ProgressDialog(title,message,maxValue=100): 1402 | dlg = wx.ProgressDialog(title, message, maximum=100, parent=None, style=wx.PD_APP_MODAL|wx.PD_AUTO_HIDE) 1403 | return dlg 1404 | 1405 | def _onProgressDialog(dlg,percent): 1406 | dlg.Update(percent) 1407 | 1408 | def ProgressDialogUpdate(dlg,percent): 1409 | wx.CallAfter(_onProgressDialog, dlg, percent) 1410 | 1411 | def progressDialogUpdate(dlg,percent): #deprecated 1412 | wx.CallAfter(_onProgressDialog, dlg, percent) 1413 | 1414 | def CalendarDialog(parent=None,year=None,month=None,day=None): 1415 | dlg = wx.lib.CalenDlg(parent,month,day,year) 1416 | #TODO 1417 | 1418 | class _process(wx.Process): 1419 | def __init__(self,event_id,handler=None): 1420 | super().__init__() 1421 | self.event_id = event_id 1422 | self.handler = handler 1423 | self.Redirect() 1424 | def OnTerminate(self,pid,status): 1425 | print( pid, status ) 1426 | if self.handler is not None: 1427 | self.handler(self.event_id,status) 1428 | 1429 | def Execute(command,sync=False,show=False): #TODO 1430 | #process = _process(event_id,handler) 1431 | flags = 0 1432 | if sync is True: 1433 | flags |= wx.EXEC_SYNC 1434 | else: 1435 | flags |= wx.EXEC_ASYNC 1436 | if show is True: 1437 | flags |= wx.EXEC_SHOW_CONSOLE 1438 | else: 1439 | flags |= wx.EXEC_HIDE_CONSOLE 1440 | #wx.Execute(command, flags=flags, callback=process) 1441 | wx.Execute(command, flags=flags) 1442 | 1443 | ###################################################################### 1444 | # WxApp 1445 | ###################################################################### 1446 | 1447 | class WxApp(): 1448 | def __init__( self, title, width=800, height=600, popup=False ): 1449 | if popup is False: 1450 | self.app = wx.App() 1451 | self.app.locale = wx.Locale(wx.Locale.GetSystemLanguage()) 1452 | self.frame = wx.Frame( parent=None, id = wx.ID_ANY, title = title, pos = wx.DefaultPosition, size = wx.Size( width,height ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL ) 1453 | self.frame.Bind(wx.EVT_CLOSE, self.closeEvent) 1454 | registerCtrl( 'WxApp', self ) 1455 | else: 1456 | self.frame = wx.Frame( parent=None, id = wx.ID_ANY, title = title, pos = wx.DefaultPosition, size = wx.Size( width,height ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL ) 1457 | self.frame.Bind(wx.EVT_CLOSE, self.popupCloseEvent) 1458 | self.frame.Center(); 1459 | self.frame.Bind(wx.EVT_SHOW, self.openEvent) 1460 | self.frame.SetSizeHints( wx.DefaultSize, wx.DefaultSize ) 1461 | self.openHandler = None 1462 | self.closeHandler = None 1463 | self.lastMousePos = wx.Point(0,0) 1464 | self.menubar = None 1465 | self.statusbar = None 1466 | 1467 | def run(self): 1468 | self.frame.Center() 1469 | self.frame.Show() 1470 | self.app.MainLoop() 1471 | 1472 | def close(self): 1473 | self.frame.Close() 1474 | 1475 | def show(self): 1476 | self.frame.Show() 1477 | 1478 | def Show(self): #TODO: remove 1479 | self.frame.Show() 1480 | 1481 | def getCtrl(self,key): 1482 | return getCtrl(key) 1483 | 1484 | def getWxCtrl(self,key): 1485 | return getWxCtrl(key) 1486 | 1487 | def getWxTimer(self,key): 1488 | return getWxTimer(key) 1489 | 1490 | def openEvent(self,event): 1491 | if self.openHandler is not None: 1492 | self.openHandler(event) 1493 | self.openHandler = None 1494 | self.frame.Unbind(wx.EVT_SHOW) 1495 | event.Skip() 1496 | 1497 | def openHandle(self,handler): 1498 | self.openHandler = handler 1499 | 1500 | def closeEvent(self,event): 1501 | if self.closeHandler is not None: 1502 | if self.closeHandler(event) == True: 1503 | event.Skip() 1504 | else: 1505 | event.Skip() 1506 | 1507 | def popupCloseEvent(self,event): 1508 | self.makeModal(False) 1509 | if self.closeHandler is not None: #841 1510 | if self.closeHandler(event) == True: 1511 | event.Skip() 1512 | else: 1513 | event.Skip() 1514 | 1515 | def closeHandle(self,handler): 1516 | self.closeHandler = handler 1517 | 1518 | def idleHandle(self,handler): 1519 | self.frame.Bind(wx.EVT_IDLE, handler) 1520 | 1521 | def timerHandle(self,handler,interval=1000,start=False,key=None): 1522 | timer = wx.Timer(self.frame) 1523 | self.frame.Bind(wx.EVT_TIMER, handler, timer) 1524 | if key is not None: 1525 | registerCtrl(key,timer) 1526 | if start is True and interval > 0: 1527 | timer.Start(interval) 1528 | 1529 | def timerStart(self,key,interval): 1530 | timer = getWxTimer(key) 1531 | if timer is not None and interval > 0: 1532 | timer.Start(interval) 1533 | 1534 | def timerStop(self,key): 1535 | timer = getWxTimer(key) 1536 | if timer is not None: 1537 | timer.Stop() 1538 | 1539 | def makeMenu(self, value): 1540 | menu = wx.Menu() 1541 | for k, v in value.items(): 1542 | if k[0] == '-': 1543 | menu.AppendSeparator() 1544 | else: 1545 | if type(v) is dict: 1546 | submenu = self.makeMenu(v) 1547 | menu.AppendSubMenu(submenu, k) 1548 | else: 1549 | if type(v) is list: 1550 | handler = v[0] 1551 | icon = v[1] 1552 | else: 1553 | handler = v 1554 | icon = None 1555 | item = wx.MenuItem( menu, getId(), k, wx.EmptyString, wx.ITEM_NORMAL ) 1556 | if icon is not None: 1557 | item.SetBitmap(getMenuBitmap(icon)) 1558 | if handler is None: 1559 | item.Enable( False ) 1560 | else: 1561 | self.frame.Bind(wx.EVT_MENU, handler, item) 1562 | menu.Append(item) 1563 | return menu 1564 | 1565 | def makeMenuBar(self, menu_def): 1566 | self.menubar = wx.MenuBar(0) 1567 | for key, value in menu_def.items(): 1568 | if type(value) is dict: 1569 | menu = self.makeMenu(value) 1570 | self.menubar.Append( menu, key ) 1571 | self.frame.SetMenuBar(self.menubar) 1572 | 1573 | def makeStatusBar(self, status_def): 1574 | self.statusbar = self.frame.CreateStatusBar( len(status_def), wx.STB_SIZEGRIP, wx.ID_ANY ) 1575 | widths = [] 1576 | for i in range(len(status_def)): 1577 | self.statusbar.SetStatusText( status_def[i][0], i) 1578 | widths.append(status_def[i][1]) 1579 | self.statusbar.SetStatusWidths(widths) 1580 | 1581 | def makeToolBar(self, tool_def): #icon, text, handler 1582 | flags = wx.TB_FLAT|wx.TB_HORIZONTAL 1583 | if len(tool_def[0]) >= 3: 1584 | flags |= wx.TB_TEXT 1585 | self.toolbar = self.frame.CreateToolBar( flags, wx.ID_ANY ) 1586 | for value in tool_def: 1587 | if value[0] is None: 1588 | self.toolbar.AddSeparator() 1589 | else: 1590 | text = handler = tooltip = None 1591 | if len(value) >= 2: 1592 | handler = value[1] 1593 | if len(value) >= 3: 1594 | text = value[2] 1595 | if len(value) >= 4: 1596 | tooltip = value[3] 1597 | icon = getToolbarBitmap(value[0]) 1598 | id = getId() 1599 | if text is not None: 1600 | tool = self.toolbar.AddTool( id, text, icon, wx.NullBitmap, wx.ITEM_NORMAL, wx.EmptyString, wx.EmptyString, None ) 1601 | else: 1602 | tool = self.toolbar.AddSimpleTool( id, icon, wx.EmptyString, wx.EmptyString, None ) 1603 | if tooltip is not None: 1604 | self.toolbar.SetToolShortHelp(id, tooltip); 1605 | if handler is None: 1606 | tool.Enable( False ) 1607 | else: 1608 | self.toolbar.Bind( wx.EVT_TOOL, handler, id = id ) 1609 | self.toolbar.Realize() 1610 | 1611 | def makeBody(self,body_def): 1612 | self.panel = Panel(body_def,self.frame,create=True) 1613 | self.frame.SetSizer( wrapSizer(self.panel.ctrl) ) 1614 | self.frame.Layout() 1615 | 1616 | def makeLayout(self,layout): 1617 | if 'menu' in layout: 1618 | self.makeMenuBar(layout['menu']) 1619 | if 'tool' in layout: 1620 | self.makeToolBar(layout['tool']) 1621 | if 'status' in layout: 1622 | self.makeStatusBar(layout['status']) 1623 | if 'body' in layout: 1624 | self.makeBody(layout['body']) 1625 | 1626 | def makeModal(self, modal=True): 1627 | if modal and not hasattr(self.frame, '_disabler'): 1628 | self.frame._disabler = wx.WindowDisabler(self.frame) 1629 | if not modal and hasattr(self.frame, '_disabler'): 1630 | del self.frame._disabler 1631 | 1632 | def noMinimize(self): 1633 | style = self.frame.GetWindowStyle() 1634 | self.frame.SetWindowStyle(style & (~wx.MINIMIZE_BOX)) 1635 | self.frame.Refresh() 1636 | 1637 | def noMaximize(self): 1638 | style = self.frame.GetWindowStyle() 1639 | self.frame.SetWindowStyle(style & (~wx.MAXIMIZE_BOX)) 1640 | self.frame.Refresh() 1641 | 1642 | def NoClose(self): 1643 | style = self.frame.GetWindowStyle() 1644 | self.frame.SetWindowStyle(style & (~wx.CLOSE_BOX)) 1645 | self.frame.Refresh() 1646 | 1647 | def noResize(self): 1648 | style = self.frame.GetWindowStyle() 1649 | self.frame.SetWindowStyle(style & (~wx.RESIZE_BORDER)) 1650 | self.frame.Refresh() 1651 | 1652 | def noSystemMenu(self): 1653 | style = self.frame.GetWindowStyle() 1654 | self.frame.SetWindowStyle(style & (~wx.SYSTEM_MENU)) 1655 | self.frame.Refresh() 1656 | 1657 | def noCaption(self): 1658 | style = self.frame.GetWindowStyle() 1659 | self.frame.SetWindowStyle(style & (~wx.CAPTION)) 1660 | self.frame.Refresh() 1661 | 1662 | def noBorder(self): 1663 | style = self.frame.GetWindowStyle() 1664 | self.frame.SetWindowStyle(style & (~wx.BORDER)) 1665 | self.frame.Refresh() 1666 | 1667 | def _dragMotionHandle(self, event): 1668 | if event.LeftIsDown(): 1669 | currMousePos = wx.GetMousePosition() 1670 | dx = currMousePos[0] - self.lastMousePos[0] 1671 | dy = currMousePos[1] - self.lastMousePos[1] 1672 | self.frame.Move(wx.Point(self.lastWinPos[0] + dx, self.lastWinPos[1] + dy)) 1673 | event.Skip() 1674 | 1675 | def _dragLeftDownHandle(self, event): 1676 | self.lastWinPos = self.frame.GetScreenPosition() 1677 | self.lastMousePos = wx.GetMousePosition() 1678 | event.Skip() 1679 | 1680 | def dragEnable(self,key): 1681 | ctrl = getWxCtrl(key) 1682 | if ctrl is not None: 1683 | ctrl.Bind(wx.EVT_MOTION, self._dragMotionHandle) 1684 | ctrl.Bind(wx.EVT_LEFT_DOWN, self._dragLeftDownHandle) 1685 | 1686 | def _getContextMenuHandler(self,menu): 1687 | def _contextMenuRightDown(event): #closure 1688 | self.frame.PopupMenu( menu, event.GetPosition() ) 1689 | return _contextMenuRightDown 1690 | 1691 | def contextMenu(self,menu_def,key): 1692 | ctrl = getWxCtrl(key) 1693 | if ctrl is not None: 1694 | ctrl.Bind(wx.EVT_RIGHT_DOWN, self._getContextMenuHandler(self.makeMenu(menu_def))) 1695 | 1696 | def toolTip(self,text,key): 1697 | ctrl = getWxCtrl(key) 1698 | if ctrl is not None: 1699 | ctrl.SetToolTip(wx.ToolTip(text)) 1700 | 1701 | def setStatusText(self,text,index=0): 1702 | if self.statusbar is not None: 1703 | if index < self.statusbar.GetFieldsCount(): 1704 | self.statusbar.SetStatusText(text,index) 1705 | 1706 | # Dialog 1707 | def openFileDialog(self,defaultDir="",defaultFile="",multiple=False,save=False): 1708 | style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST if save is False else wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT 1709 | style |= wx.FD_MULTIPLE if multiple is True else 0 1710 | dlg = wx.FileDialog(self.frame,defaultDir=defaultDir,defaultFile=defaultFile,style=style) 1711 | rv = dlg.ShowModal() 1712 | if rv == wx.ID_OK: 1713 | if multiple == True: 1714 | files = [] 1715 | for file in dlg.GetFilenames(): 1716 | files.append( os.path.join(dlg.GetDirectory(), file) ) 1717 | return files 1718 | else: 1719 | return os.path.join(dlg.GetDirectory(), dlg.GetFilename()) 1720 | else: 1721 | return None 1722 | 1723 | def saveFileDialog(self,defaultDir="",defaultFile=""): 1724 | return OpenFileDialog(defaultDir=defaultDir,defaultFile=defaultFile, multiple=False, save=True) 1725 | 1726 | def directoryDialog(self,defaultPath=""): 1727 | dlg = wx.DirDialog(self.frame,defaultPath=defaultPath) 1728 | rv = dlg.ShowModal() 1729 | if rv == wx.ID_OK: 1730 | return dlg.GetPath() 1731 | else: 1732 | return None 1733 | 1734 | def messageBox(self,title,message): 1735 | dlg = wx.MessageDialog(self.frame, message, caption=title, style=wx.OK|wx.CENTER, pos=wx.DefaultPosition) 1736 | dlg.ShowModal() 1737 | 1738 | def messageYesNo(self,title,message): 1739 | dlg = wx.MessageDialog(self.frame, message, caption=title, style=wx.YES|wx.NO|wx.CENTER, pos=wx.DefaultPosition) 1740 | rv = dlg.ShowModal() 1741 | if rv == wx.ID_OK or rv == wx.ID_YES: 1742 | return True 1743 | else: 1744 | return False 1745 | 1746 | def messageYesNoCancel(self,title,message): 1747 | dlg = wx.MessageDialog(self.frame, message, caption=title, style=wx.YES|wx.NO|wx.CANCEL|wx.CENTER, pos=wx.DefaultPosition) 1748 | rv = dlg.ShowModal() 1749 | if rv == wx.ID_OK or rv == wx.ID_YES: 1750 | return True 1751 | elif rv == wx.ID_NO: 1752 | return False 1753 | else: #wx.ID_CANCEL, 1754 | return None 1755 | 1756 | def progressDialog(self,title,message,maxValue=100): 1757 | dlg = wx.ProgressDialog(title, message, maximum=100, parent=self.frame, style=wx.PD_APP_MODAL|wx.PD_AUTO_HIDE) 1758 | return dlg 1759 | 1760 | def onProgressDialog(self,dlg,percent): 1761 | dlg.Update(percent) 1762 | 1763 | def progressDialogUpdate(self,dlg,percent): 1764 | wx.CallAfter(self.onProgressDialog, dlg, percent) 1765 | 1766 | def textEntryDialog(self,title,message,value=''): 1767 | dlg = wx.TextEntryDialog(self.frame, message, title, value=value) 1768 | if dlg.ShowModal() == wx.ID_OK: 1769 | value = dlg.GetValue() 1770 | dlg.Destroy() 1771 | return value 1772 | 1773 | def dialog(self,title,layout,size=(400,300)): #TODO 1774 | dlg = wx.Dialog( parent=self.frame, title=title, size=size ) 1775 | panel = Panel(layout,dlg,create=True) 1776 | dlg.ShowModal() 1777 | dlg.Destroy() 1778 | 1779 | # Control 1780 | def clearValue(self,key): 1781 | ctrl = self.getCtrl(key) 1782 | if ctrl is not None: 1783 | return ctrl.clearValue() 1784 | else: 1785 | return None 1786 | 1787 | def getValue(self,key): 1788 | ctrl = self.getCtrl(key) 1789 | if ctrl is not None: 1790 | return ctrl.getValue() 1791 | else: 1792 | return None 1793 | 1794 | def setValue(self,key,value): 1795 | ctrl = self.getCtrl(key) 1796 | if ctrl is not None: 1797 | ctrl.setValue(value) 1798 | 1799 | def appendValue(self,key,value): 1800 | ctrl = self.getCtrl(key) 1801 | if ctrl is not None: 1802 | return ctrl.appendValue(value) 1803 | else: 1804 | return None 1805 | 1806 | def removeValue(self,key,value): 1807 | ctrl = self.getCtrl(key) 1808 | if ctrl is not None: 1809 | return ctrl.removeValue(value) 1810 | else: 1811 | return None 1812 | 1813 | # Check Button Control 1814 | def getCheckState(self,key): #deprecated 1815 | ctrl = getWxCtrl(key) 1816 | if ctrl is not None: 1817 | return ctrl.GetValue() 1818 | else: 1819 | return None 1820 | 1821 | # Choice, Bombo, List Control 1822 | def getSelectedText(self,key): #deprecated 1823 | ctrl = getWxCtrl(key) 1824 | if ctrl is not None: 1825 | return ctrl.GetString(ctrl.GetSelection()) 1826 | else: 1827 | return None 1828 | 1829 | # Text Control 1830 | def getText(self,key): #deprecated 1831 | ctrl = getWxCtrl(key) 1832 | if ctrl is not None: 1833 | return ctrl.GetValue() 1834 | else: 1835 | return None 1836 | 1837 | def setText(self,key,text): #deprecated 1838 | ctrl = getWxCtrl(key) 1839 | if ctrl is not None: 1840 | ctrl.Clear() 1841 | ctrl.AppendText(text) 1842 | 1843 | def appendText(self,key,text): #deprecated 1844 | ctrl = getWxCtrl(key) 1845 | if ctrl is not None: 1846 | ctrl.AppendText(text) 1847 | 1848 | #def setWrap(self,key,wrap=True): 1849 | # ctrl = getWxCtrl(key) 1850 | # if ctrl is not None: 1851 | # ws = ctrl.GetWindowStyle() 1852 | # if wrap is True: 1853 | # ctrl.SetWindowStyle(ws & ~wx.TE_DONTWRAP ) #| wx.TE_BESTWRAP 1854 | # else: 1855 | # ctrl.SetWindowStyle(ws | wx.TE_DONTWRAP) #& ~wx.TE_BESTWRAP 1856 | 1857 | # Ticker Control 1858 | def setTickerText(self,key,text): 1859 | ctrl = getWxCtrl(key) 1860 | if ctrl is not None: 1861 | ctrl.SetText(text) 1862 | 1863 | def setTickerFont(self,key,font): 1864 | ctrl = getWxCtrl(key) 1865 | if ctrl is not None: 1866 | ctrl.SetFont(font) 1867 | 1868 | def setTickerPPF(self,key,text): 1869 | ctrl = getWxCtrl(key) 1870 | if ctrl is not None: 1871 | ctrl.SetPPF(int(text)) 1872 | 1873 | def setTickerFPS(self,key,text): 1874 | ctrl = getWxCtrl(key) 1875 | if ctrl is not None: 1876 | ctrl.SetFPS(int(text)) 1877 | 1878 | def setTickerStart(self,key): 1879 | ctrl = getWxCtrl(key) 1880 | if ctrl is not None: 1881 | ctrl.Start() 1882 | 1883 | def setTickerStop(self,key): 1884 | ctrl = getWxCtrl(key) 1885 | if ctrl is not None: 1886 | ctrl.Stop() 1887 | 1888 | def setTickerDirection(self,key,direction='right'): 1889 | ctrl = getWxCtrl(key) 1890 | if ctrl is not None: 1891 | if direction == 'right': 1892 | ctrl.SetDirection('ltr') 1893 | elif direction == 'left': 1894 | ctrl.SetDirection('rtl') 1895 | 1896 | # Book Control 1897 | def setBookPage(self,key,index): 1898 | ctrl = getCtrl(key) 1899 | if ctrl is not None: 1900 | ctrl.setPage(index) 1901 | def setBookEffect(self,key,effect="slide_to_left"): 1902 | ctrl = getCtrl(key) 1903 | if ctrl is not None: 1904 | ctrl.setEffect(effect) 1905 | 1906 | #Calendar Control 1907 | def getCalendarDate(self,key): 1908 | ctrl = getWxCtrl(key) 1909 | if ctrl is not None: 1910 | date = ctrl.GetDate() 1911 | return date.Format('%Y-%m-%d') 1912 | 1913 | class WxPopup(WxApp): 1914 | def __init__( self, title, width=800, height=600 ): 1915 | super().__init__( title, width=width, height=height, popup=True ) 1916 | 1917 | 1918 | --------------------------------------------------------------------------------