async def AsyncShowDialog(dlg): closed = Event() def end_dialog(return_code): dlg.SetReturnCode(return_code) dlg.Hide() closed.set() async def on_button(event): # Same code as in wxwidgets:/src/common/dlgcmn.cpp:OnButton # to automatically handle OK, CANCEL, APPLY,... buttons id = event.GetId() if id == dlg.GetAffirmativeId(): if dlg.Validate() and dlg.TransferDataFromWindow(): end_dialog(id) elif id == wx.ID_APPLY: if dlg.Validate(): dlg.TransferDataFromWindow() elif id == dlg.GetEscapeId() or (id == wx.ID_CANCEL and dlg.GetEscapeId() == wx.ID_ANY): end_dialog(wx.ID_CANCEL) else: event.Skip() async def on_close(event): closed.set() dlg.Hide() AsyncBind(wx.EVT_CLOSE, on_close, dlg) AsyncBind(wx.EVT_BUTTON, on_button, dlg) dlg.Show() await closed.wait() return dlg.GetReturnCode()
def __init__(self): super().__init__(parent=None, title='Pyssenger') panelMain = wx.Panel(self) stIPInfo = wx.StaticText(panelMain, label="You are connected to: ", pos=(5, 10)) stIP = wx.TextCtrl(panelMain, value=PyssMain.IP, pos=(125, 5), style=wx.TE_READONLY) self.txtConversation = wx.TextCtrl(panelMain, value="", pos=(5, 50), size=(350, 80), style=wx.TE_MULTILINE | wx.TE_READONLY) self.txtInputMessage = wx.TextCtrl(panelMain, value="Hey there!", pos=(5, 135), style=wx.TE_PROCESS_ENTER) btnSendMsg = wx.Button(panelMain, label='Send', pos=(200, 135)) # Asynchronous bindings on "Send" button click and "enter" key hit - Both call on_press AsyncBind(wx.EVT_BUTTON, self.on_press, btnSendMsg) AsyncBind(wx.EVT_TEXT_ENTER, self.on_press, self.txtInputMessage) # Show gui self.Show() # Asynchronous coroutine running in the background while gui runs StartCoroutine(self.runClient, self)
def make_settings_zone(self): self.preferHeadshotsChk = wx.CheckBox( self.panel, label="Prefer headshot sounds over killstreak sounds" ) openSoundDirBtn = wx.Button(self.panel, label="Open sounds directory") self.updateSoundsBtn = wx.Button(self.panel, label="Update sounds") AsyncBind(wx.EVT_BUTTON, self.OpenSoundsDir, openSoundDirBtn) AsyncBind(wx.EVT_BUTTON, self.UpdateSounds, self.updateSoundsBtn) soundBtns = wx.BoxSizer(wx.HORIZONTAL) soundBtns.Add(openSoundDirBtn) soundBtns.Add(self.updateSoundsBtn) settingsBox = wx.StaticBoxSizer(wx.VERTICAL, self.panel, label="Settings") settingsBox.Add(self.preferHeadshotsChk, border=5, flag=wx.ALL) settingsBox.Add(soundBtns, border=5, flag=wx.ALIGN_CENTER | wx.UP | wx.DOWN) preferHeadshots = config.config["Sounds"].getboolean("PreferHeadshots", False) self.preferHeadshotsChk.SetValue(preferHeadshots) self.Bind( wx.EVT_CHECKBOX, lambda e: config.set( "Sounds", "PreferHeadshots", self.preferHeadshotsChk.Value ), self.preferHeadshotsChk, ) return settingsBox
def __init__(self, *args, **kw): super().__init__(*args, **kw) self.panel = wx.Panel(self) self.SetIcon(wx.Icon("icon.ico")) self.CreateStatusBar() self.SetStatusText("Loading sounds...") self.client = client.Client(self) vbox = wx.BoxSizer(wx.VERTICAL) vbox.AddStretchSpacer() vbox.Add( self.make_volume_zone(), border=5, flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ALL ) vbox.Add( self.make_settings_zone(), border=5, flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, ) vbox.AddStretchSpacer() self.panel.SetSizer(vbox) self.panel.Layout() self.taskbarIcon = TaskbarIcon(self) AsyncBind(wx.EVT_ICONIZE, self.OnMinimize, self) AsyncBind(wx.EVT_SHOW, self.OnUnMinimize, self) AsyncBind(wx.EVT_CLOSE, self.OnClose, self) self.Centre() self.Show() StartCoroutine(self.UpdateSounds(None), self)
def InitMenus(self): menuBar = wx.MenuBar() menu1 = wx.Menu() id = wx.NewIdRef() menu1.Append(id, "AsyncBind (original wxasync example)\tCtrl-1") AsyncBind(wx.EVT_MENU, self.async_callback, menu1, id=id) id = wx.NewIdRef() menu1.Append(id, "Start/stop clock via StartCoroutine()\tCtrl-2") self.Bind(wx.EVT_MENU, self.regular_func_starts_coroutine, id=id) id = wx.NewIdRef() menu1.Append(id, "Emit Custom Event (sync)\tCtrl-3") self.Bind(wx.EVT_MENU, self.regular_func_raises_custom_event, id=id) self.Bind(EVT_SOME_NEW_EVENT, self.callback ) # bind custom event to synchronous handler - works OK id = wx.NewIdRef() menu1.Append(id, "Emit Custom Event (async)\tCtrl-4") self.Bind(wx.EVT_MENU, self.regular_func_raises_custom_async_event, id=id) AsyncBind(EVT_SOME_NEW_EVENT_ASYNC, self.async_callback, self.frame) # don't specify id, and use self.frame not self # Finalise menu menuBar.Append(menu1, "&Experiments") self.frame.SetMenuBar(menuBar)
def __init__(self, parent, id, title, size, reader, writer): '''初始化,添加控件并绑定事件''' wx.Frame.__init__(self, parent, id, title) self.reader, self.writer = reader, writer self.SetSize(size) self.Center() self.chatFrame = wx.TextCtrl(self, pos=(5, 5), size=(445, 320), style=wx.TE_MULTILINE | wx.TE_READONLY) self.message = wx.TextCtrl(self, pos=(5, 330), size=(300, 25), style=wx.TE_PROCESS_ENTER) self.sendButton = wx.Button(self, label="发送", pos=(310, 330), size=(65, 25)) self.closeButton = wx.Button(self, label="注销", pos=(380, 330), size=(65, 25)) self.userlist = wx.TextCtrl(self, pos=(455, 5), size=(150, 350), style=wx.TE_MULTILINE | wx.TE_READONLY) AsyncBind(wx.EVT_BUTTON, self.send, self.sendButton) AsyncBind(wx.EVT_TEXT_ENTER, self.send, self.message) AsyncBind(wx.EVT_BUTTON, self.close, self.closeButton) StartCoroutine(self.receive, self) StartCoroutine(self.lookUsers, self) self.Show()
def __init__(self, parent=None): super(TestFrame, self).__init__(parent) vbox = wx.BoxSizer(wx.VERTICAL) button1 = wx.Button(self, label="AsyncBind (original wxasync example)") button2 = wx.Button(self, label="Start/stop clock via StartCoroutine()") button3 = wx.Button(self, label="Emit Custom Event (sync)") button4 = wx.Button(self, label="Emit Custom Event (async)") button5 = wx.Button(self, label="Show Frame") self.edit = wx.StaticText(self, style=wx.ALIGN_CENTRE_HORIZONTAL | wx.ST_NO_AUTORESIZE) self.edit_timer = wx.StaticText(self, style=wx.ALIGN_CENTRE_HORIZONTAL | wx.ST_NO_AUTORESIZE) vbox.Add(button1, 2, wx.EXPAND | wx.ALL) vbox.Add(button2, 2, wx.EXPAND | wx.ALL) vbox.Add(button3, 2, wx.EXPAND | wx.ALL) vbox.Add(button4, 2, wx.EXPAND | wx.ALL) vbox.Add(button5, 2, wx.EXPAND | wx.ALL) vbox.AddStretchSpacer(1) vbox.Add(self.edit, 1, wx.EXPAND | wx.ALL) vbox.Add(self.edit_timer, 1, wx.EXPAND | wx.ALL) self.SetSizer(vbox) self.Layout() self.clock_on = False """Original direct binding - works ok""" AsyncBind(wx.EVT_BUTTON, self.async_callback, button1) """ Regular method calls StartCoroutine() - works ok No need for async/await syntax except on the final async method! Turtle avoidance success because no need for async/await syntax turtles all the way up the calling chain. PROVISO: WxAsyncApp() object must be created first, frame creation within OnInit fails. """ self.Bind(wx.EVT_BUTTON, self.regular_func_starts_coroutine, button2) """ Regular method broadcast a custom event - works ok But this is the synchronous version. Its the async version we want to get working. """ self.Bind(wx.EVT_BUTTON, self.regular_func_raises_custom_event, button3) self.Bind(EVT_SOME_NEW_EVENT, self.callback ) # bind custom event to synchronous handler - works OK """ Regular method broadcast a custom event - doesn't work bind custom event to asynchronous handler - doesn't work """ self.Bind(wx.EVT_BUTTON, self.regular_func_raises_custom_async_event, button4) AsyncBind(EVT_SOME_NEW_EVENT_ASYNC, self.async_callback, self) # don't specify id """Show popup frame""" self.Bind(wx.EVT_BUTTON, self.on_show_frame, button5)
def __init__(self, parent=None): super(TestFrame, self).__init__(parent) vbox = wx.BoxSizer(wx.VERTICAL) button1 = wx.Button(self, label="Submit") self.edit = wx.StaticText(self, style=wx.ALIGN_CENTRE_HORIZONTAL|wx.ST_NO_AUTORESIZE) vbox.Add(button1, 2, wx.EXPAND|wx.ALL) vbox.AddStretchSpacer(1) vbox.Add(self.edit, 1, wx.EXPAND|wx.ALL) self.SetSizer(vbox) self.Layout() AsyncBind(wx.EVT_BUTTON, self.async_callback, button1) AsyncBind(wx.EVT_BUTTON, self.async_callback2, button1) StartCoroutine(self.async_job, self)
def InitUI(self): self.InitMenu() panel = wx.Panel(self) # labels = ['标签名'] box_sizer = wx.BoxSizer(wx.VERTICAL) grid_sizer = wx.FlexGridSizer(1, 4, 10, 20) self.tag_ctrl = wx.TextCtrl(panel, value='TAG HERE', size=(300, -1)) self.begin = wx.TextCtrl(panel, value='起始页', size=(50, -1)) self.end = wx.TextCtrl(panel, value='结束页', size=(50, -1)) self.dwbtn = wx.Button(panel, label='下载', size=(-1, 27)) grid_sizer.AddMany([(self.tag_ctrl, 1, wx.EXPAND), (self.begin), (self.end), (self.dwbtn)]) AsyncBind(wx.EVT_BUTTON, self.download, self.dwbtn) box_sizer.Add(grid_sizer, 1, wx.ALL | wx.CENTER, 20) self.img_list = wx.ListCtrl(panel, -1, style=wx.LC_REPORT) self.img_list.InsertColumn(0, '图片名') box_sizer.Add(self.img_list, 1, wx.EXPAND | wx.ALL ^ wx.TOP, 20) panel.SetSizer(box_sizer) self.Centre()
def init(self, parent: wx.Window): """Initialize this item.""" self.ui_item.Create(parent, label=str(self._label)) if iscoroutinefunction(self._call_back): AsyncBind(wx.EVT_BUTTON, self._call_back, self.ui_item) else: self.ui_item.Bind(wx.EVT_BUTTON, self._call_back) self._init()
def make_volume_zone(self): with self.client.sounds.lock: self.volumeSlider = wx.Slider( self.panel, value=self.client.sounds.volume, size=(272, 25) ) AsyncBind(wx.EVT_COMMAND_SCROLL_CHANGED, self.OnVolumeSlider, self.volumeSlider) volumeZone = wx.StaticBoxSizer(wx.VERTICAL, self.panel, label="Volume") volumeZone.Add(self.volumeSlider) return volumeZone
def __init__(self, keys, algorithms, parent=None, title="Select a Key", HandleNewKey=NullCoroutine): super().__init__(parent, title=title, size=(550, 250), style=wx.RESIZE_BORDER | wx.DEFAULT_DIALOG_STYLE) self.algorithms = algorithms self.HandleNewKey = HandleNewKey self.key_label = wx.StaticText(self, label="Key:") self.combo = KeySelectCombo(keys, parent=self) self.checkbox_default = wx.CheckBox(self, label="Save as Default") self.error_message = wx.StaticText(self, label="") self.error_message.SetForegroundColour(Colour("Red")) self.submit = wx.Button(self, label="Submit") self.submit.SetId(wx.ID_OK) self.submit.SetFocus() self.cancel = wx.Button(self, label="Cancel") self.cancel.SetId(wx.ID_CANCEL) self.newkey = wx.Button(self, label="Create New") vbox = wx.BoxSizer(wx.VERTICAL) vbox.AddSpacer(40) vbox.Add(self.key_label, 0, wx.EXPAND | wx.RIGHT | wx.LEFT, border=20) hbox1 = wx.BoxSizer(wx.HORIZONTAL) hbox1.Add(self.combo, 1, wx.EXPAND) hbox1.Add(self.newkey, 0) vbox.Add(hbox1, 0, wx.RIGHT | wx.LEFT | wx.EXPAND, border=20) vbox.AddSpacer(20) vbox.Add(self.checkbox_default, 0, wx.RIGHT | wx.LEFT | wx.ALIGN_RIGHT, border=20) vbox.Add(self.error_message, 0, wx.RIGHT | wx.LEFT, border=20) vbox.AddStretchSpacer(1) button_sizer = wx.BoxSizer(wx.HORIZONTAL) #button_sizer = wx.StdDialogButtonSizer() button_sizer.Add(self.cancel) button_sizer.Add(self.submit) vbox.Add(button_sizer, 1, wx.ALIGN_RIGHT | wx.RIGHT | wx.LEFT | wx.BOTTOM, border=20) self.SetSizer(vbox) self.Layout() AsyncBind(wx.EVT_BUTTON, self.OnNewKey, self.newkey)
def InitMenus(self): menuBar = wx.MenuBar() menu1 = wx.Menu() id = wx.NewIdRef() menu1.Append(id, "test - async call\tCtrl-1") # self.Bind(wx.EVT_MENU, self.callback, id=id) # AsyncBind(wx.EVT_MENU, self.async_callback, id) AsyncBind(wx.EVT_MENU, self.async_callback, menu1, id=id) menuBar.Append(menu1, "&Experiments") self.frame.SetMenuBar(menuBar)
def OnInit(self): self.frame = MyFrame(None, wx.ID_ANY, "") self.SetTopWindow(self.frame) self.frame.Show() self.frame.Bind(wx.EVT_CLOSE, lambda event: app.ExitMainLoop()) self.frame.hostname.SetValue(f"127.0.0.1:{args.port}") self.ftp_client = FTPClient(self.frame.ftp_output) StartCoroutine(self.run_file_server_in_background, self) AsyncBind(wx.EVT_BUTTON, self.OnConnect, self.frame.connect_button) AsyncBind(wx.EVT_BUTTON, self.OnDisconnect, self.frame.disconnect_button) AsyncBind(wx.EVT_BUTTON, self.GetAndDisplayFiles, self.frame.search_button) AsyncBind(wx.EVT_TEXT_ENTER, self.GetAndDisplayFiles, self.frame.search_input) AsyncBind(wx.EVT_BUTTON, self.OnFTPCommand, self.frame.ftp_button) AsyncBind(wx.EVT_TEXT_ENTER, self.OnFTPCommand, self.frame.ftp_input) self.update_gui() return True
def __init__(self, parent=None): super(WxAsyncAppMessageThroughputTest, self).__init__(parent) vbox = wx.BoxSizer(wx.VERTICAL) button1 = wx.Button(self, label="Submit") vbox.Add(button1, 1, wx.EXPAND | wx.ALL) self.SetSizer(vbox) self.Layout() AsyncBind(EVT_TEST_EVENT, self.async_callback, self) wx.PostEvent(self, TestEvent(t1=time.time())) self.latency_sum = 0 self.wx_events_pending = 1 # the first one is sent in constructor self.total_events_sent = 0 self.total_to_send = 100000 self.tstart = time.time()
def __init__(self, loop=None): super(WxAsyncAppCombinedThroughputTest, self).__init__() self.loop = loop AsyncBind(EVT_TEST_EVENT, self.wx_loop_func, self) self.wx_latency_sum = 0 self.aio_latency_sum = 0 self.wx_events_pending = 1 # the first one is sent in constructor self.aio_events_pending = 1 # the first one is sent in constructor self.total_events_sent = 0 self.total_to_send = 2000000 self.total_wx_sent = 0 self.total_aio_sent = 0 self.tstart = time.time() wx.PostEvent(self, TestEvent(t1=self.tstart)) self.loop.call_soon(self.aio_loop_func, self.tstart) #, *args
def InitUI(self): self.InitMenu() panel = wx.Panel(self) # labels = ['标签名'] box_sizer = wx.BoxSizer(wx.VERTICAL) grid_sizer = wx.FlexGridSizer(1, 4, 10, 20) self.path_ctrl = wx.TextCtrl(panel, value=os.getcwd()+'\\') box_sizer.Add(self.path_ctrl, 1, wx.ALL|wx.EXPAND, 20) self.tag_ctrl = wx.TextCtrl(panel, value='TAG HERE', size=(300, -1)) self.begin = wx.TextCtrl(panel, value='1', size=(50, -1)) self.end = wx.TextCtrl(panel, value='1', size=(50, -1)) self.dwbtn = wx.Button(panel, label='下载', size=(-1, 27)) grid_sizer.AddMany([(self.tag_ctrl, 1, wx.EXPAND), (self.begin), (self.end),(self.dwbtn)]) AsyncBind(wx.EVT_BUTTON, self.download, self.dwbtn) self.dwbtn.SetDefault() box_sizer.Add(grid_sizer, 1, wx.LEFT|wx.RIGHT|wx.CENTER, 20) self.img_list = wx.ListCtrl(panel, -1, style=wx.LC_REPORT) self.img_list.InsertColumn(0, '任务列表', width=400) self.img_list.InsertColumn(1, '状态', width=130) box_sizer.Add(self.img_list, 1, wx.EXPAND|wx.ALL^wx.TOP, 20) panel.SetSizer(box_sizer) self.tag_ctrl.SetFocus() # 当焦点为自身时会失效 self.path_ctrl.SetInsertionPoint(0) self.sb = self.CreateStatusBar() self.sb.SetFieldsCount(3) self.sb.SetStatusWidths([-1, -2, -1]) self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer) self.sb.SetStatusText('等待下载', 0) self.Bind(wx.EVT_CLOSE, self.OnClose) self.SetTitle('SankakuComplexDownloader') self.Centre()
def __init__(self, parent=None, title="2FA Required", Handle2FACoroutine=NullCoroutine): super(Dialog2FA, self).__init__(parent, title=title, size=(350, 250), style=wx.RESIZE_BORDER|wx.DEFAULT_DIALOG_STYLE) self.Handle2FACoroutine = Handle2FACoroutine self.panel = Panel2FA(self) self.error_message = wx.StaticText(self, label="") self.error_message.SetForegroundColour(Colour("Red")) self.submit = wx.Button(self, label="Submit") AsyncBind(wx.EVT_BUTTON, self.OnSubmit, self.submit) #self.submit.SetId(wx.ID_OK) vbox = wx.BoxSizer(wx.VERTICAL) vbox.AddSpacer(40) vbox.Add(self.panel, 1, wx.EXPAND|wx.RIGHT|wx.LEFT, border=20 ) vbox.Add(self.error_message, 0, wx.RIGHT|wx.LEFT, border=20 ) vbox.AddStretchSpacer(1) vbox.Add(self.submit, 0, wx.ALIGN_RIGHT|wx.RIGHT|wx.LEFT|wx.BOTTOM, border=20) self.SetSizer(vbox) self.Layout()
def __init__(self, parent=None): super(TestFrame, self).__init__(parent) # Add a button. vbox = wx.BoxSizer(wx.VERTICAL) self.button = wx.Button(self, label="Press to Run") vbox.Add(self.button, 1, wx.CENTRE) # Add N sliders. self.sliders = [] for i in range(SLIDERS_COUNT): s = wx.Slider(self) self.sliders.append(s) vbox.Add(s, 1, wx.EXPAND | wx.ALL) # Layout the gui elements in the frame. self.SetSizer(vbox) self.Layout() # bind an asyncio coroutine to the button event. AsyncBind(wx.EVT_BUTTON, self.async_slider_demo, self.button)
def __init__(self, parent=None, title="Crypt Client", HandleLogin=NullCoroutine, HandleCreateAccountStep1=NullCoroutine, HandleCreateAccountStep2=NullCoroutine): super(LoginDialog, self).__init__(parent, title=title, size=(380, 450), style=wx.RESIZE_BORDER|wx.DEFAULT_DIALOG_STYLE) self.title = wx.StaticText(self) font = self.title.GetFont() font.SetPointSize(16) self.title.SetFont(font) self.login_panel = LoginPanel(self) self.error_message = wx.StaticText(self, label="") self.error_message.SetForegroundColour(Colour("Red")) self.create_account_panel_step1 = CreateAccountPanelStep1(self) self.create_account_panel_step2 = CreateAccountPanelStep2(self) self.link = HyperlinkCtrl(self, label="Go to Login") self.SetState(LoginState.Login) #vbox.Add(self.login, 0, wx.ALIGN_RIGHT) #self.create_acount_link = HyperlinkCtrl(self, label="Create new account") self.submit = wx.Button(self, label="Submit") vbox = wx.BoxSizer(wx.VERTICAL) vbox.Add(self.title, 0, wx.TOP|wx.RIGHT|wx.LEFT, border=20 ) vbox.AddSpacer(10) vbox.Add(self.create_account_panel_step1, 3, wx.EXPAND|wx.RIGHT|wx.LEFT, border=20 ) vbox.Add(self.create_account_panel_step2, 3, wx.EXPAND|wx.RIGHT|wx.LEFT, border=20 ) vbox.Add(self.login_panel, 3, wx.EXPAND|wx.RIGHT|wx.LEFT, border=20 ) vbox.Add(self.error_message, 0, wx.RIGHT|wx.LEFT, border=20 ) vbox.AddStretchSpacer(0) vbox.Add(self.link, 0, wx.EXPAND|wx.RIGHT|wx.LEFT, border=20) vbox.Add(self.submit, 0, wx.ALIGN_RIGHT|wx.RIGHT|wx.LEFT|wx.BOTTOM, border=20) self.SetSizer(vbox) self.link.Bind(EVT_HYPERLINK, lambda event: self.OnLink()) #self.create_account_panel_step1.login_link.Bind(EVT_HYPERLINK, lambda event: self.SetState(LoginState.Login)) #self.create_account_panel.create_account.Bind(wx.EVT_BUTTON, self.SubmitCreateAccount) AsyncBind(wx.EVT_BUTTON, self.Submit, self.submit) #AsyncBind(wx.EVT_BUTTON, self.SubmitLogin, self.login_panel.login) self.HandleCreateAccountStep1 = HandleCreateAccountStep1 self.HandleCreateAccountStep2 = HandleCreateAccountStep2 self.HandleLogin = HandleLogin self.Layout()
def __init__(self, parent, id, title, size): '''初始化,添加控件并绑定事件''' wx.Frame.__init__(self, parent, id, title) self.loop = asyncio.get_event_loop() self.reader, self.writer = None, None self.SetSize(size) self.Center() self.serverAddressLabel = wx.StaticText(self, label="Server Address", pos=(10, 50), size=(120, 25)) self.userNameLabel = wx.StaticText(self, label="UserName", pos=(40, 100), size=(120, 25)) self.serverAddress = wx.TextCtrl(self, pos=(120, 47), size=(150, 25)) self.userName = wx.TextCtrl(self, pos=(120, 97), size=(150, 25)) self.loginButton = wx.Button(self, label='Login', pos=(80, 145), size=(130, 30)) AsyncBind(wx.EVT_BUTTON, self.login, self.loginButton) self.Show()
def bind_events(self): AsyncBind( wx.EVT_BUTTON, self.handle_mod_list_refresh, self.main_frame.mod_list_refresh_button, ) self.main_frame.downloaded_mods_group_version_checkbox.Bind( wx.EVT_CHECKBOX, self.refresh_downloaded_mod_list) self.main_frame.selection_thunderstore_button.Bind( wx.EVT_BUTTON, self.handle_selection_thunderstore_button) AsyncBind( wx.EVT_LIST_ITEM_SELECTED, self.handle_installed_mod_list_select, self.main_frame.installed_mods_list, ) AsyncBind( wx.EVT_LIST_ITEM_SELECTED, self.handle_downloaded_mod_list_select, self.main_frame.downloaded_mods_list, ) AsyncBind( wx.EVT_LIST_ITEM_SELECTED, self.handle_remote_mod_list_select, self.main_frame.mod_list_list, ) AsyncBind( wx.EVT_BUTTON, self.handle_installed_mod_list_uninstall, self.main_frame.installed_mods_uninstall_button, ) AsyncBind( wx.EVT_BUTTON, self.handle_downloaded_mod_list_install, self.main_frame.downloaded_mods_install_button, ) AsyncBind( wx.EVT_BUTTON, self.handle_downloaded_mod_list_delete, self.main_frame.downloaded_mods_delete_button, ) AsyncBind( wx.EVT_BUTTON, self.handle_mod_list_install, self.main_frame.mod_list_install_button, ) AsyncBind( wx.EVT_BUTTON, self.handle_installed_mod_list_export, self.main_frame.installed_mods_export_button, ) AsyncBind( wx.EVT_BUTTON, self.handle_installed_mod_list_import, self.main_frame.installed_mods_import_button, ) AsyncBind( wx.EVT_BUTTON, self.handle_installed_mod_list_update_button, self.main_frame.installed_mods_update_button, ) AsyncBind(wx.EVT_TEXT, self.handle_mod_list_search, self.main_frame.mod_list_search) AsyncBind( wx.EVT_BUTTON, self.handle_launch_game_button, self.main_frame.launch_game_button, )
def InitLayout(self): sizer = wx.GridBagSizer(1, 1) self.SetSizer(sizer) # Defines the fixed width font self.fwfont = wx.Font(9, wx.FONTFAMILY_TELETYPE, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL) # Text box where users insert the raw HTTP data data_box = wx.TextCtrl(self, style=wx.TE_MULTILINE) data_box.SetFont(self.fwfont) data_box.SetValue(DEFAULT_REQUEST_DATA) self.ops.data = data_box sizer.Add(data_box, pos=(0, 1), span=(30, 2), flag=wx.EXPAND) sizer.AddGrowableCol(1) sizer.AddGrowableRow(18) # Button that runs the engine, binds using # AsyncBind function to allow engine to run # asynchronously run_btn = wx.Button(self, label="Run", size=(120,25)) run_btn.SetFont(self.hfont) sizer.Add(run_btn, pos=(0, 4)) AsyncBind(run_btn, wx.EVT_BUTTON, self.OnRun) # Button that stops the engine stop_btn = wx.Button(self, label="Stop", size=(120,25)) stop_btn.SetFont(self.hfont) sizer.Add(stop_btn, pos=(0,5)) stop_btn.Bind(wx.EVT_BUTTON, self.OnStop) # Empty cells added for formatting sizer.Add((120, 25), pos=(0, 6)) sizer.Add((10, 0), pos=(0, 7)) # Host text box and label host_lbl = wx.StaticText(self, label="Host: ") host_lbl.SetFont(self.hfont) sizer.Add(host_lbl, pos=(3,4), flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL) host_txt = wx.TextCtrl(self) host_txt.SetFont(self.hfont) host_txt.SetValue(DEFAULT_HOST) self.ops.host = host_txt sizer.Add(host_txt, pos=(3, 5), span=(1, 2), flag=wx.EXPAND) # Port text box and label port_lbl = wx.StaticText(self, label="Port: ") port_lbl.SetFont(self.hfont) sizer.Add(port_lbl, pos=(4, 4), flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL) port_txt = wx.TextCtrl(self) port_txt.SetFont(self.hfont) port_txt.SetValue(DEFAULT_PORT) self.ops.port = port_txt sizer.Add(port_txt, pos=(4, 5), flag=wx.EXPAND) # SSL check box and label ssl_chk = wx.CheckBox(self, label="HTTPS") ssl_chk.SetFont(self.hfont) ssl_chk.SetValue(DEFAULT_HTTPS) self.ops.https = ssl_chk sizer.Add(ssl_chk, pos=(4, 6)) # Cosmetic horizontal separator line sep1 = wx.StaticLine(self, size=(300, 1)) sizer.Add(sep1, pos=(6, 4), span=(1, 4), flag=wx.ALIGN_CENTER) # Mode drop down box and label mode_lbl = wx.StaticText(self, label="Mode:") mode_lbl.SetFont(self.hfont) sizer.Add(mode_lbl, pos=(8, 4), flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL) mode_names = ['Serial', 'Concurrent', 'Multiplex'] mode_cb = \ wx.ComboBox(self, choices=mode_names, style=wx.CB_READONLY) mode_cb.SetFont(self.hfont) mode_cb.SetValue(DEFAULT_MODE) self.ops.mode = mode_cb sizer.Add(mode_cb, pos=(8, 5), span=(1, 2)) # Marker number drop down box and label mark_lbl = wx.StaticText(self, label="Marker #:") mark_lbl.SetFont(self.hfont) sizer.Add(mark_lbl, pos=(9, 4), flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL) mark_numbers = [str(i) for i in range(1, 17)] mark_cb = \ wx.ComboBox(self, choices=mark_numbers, style=wx.CB_READONLY) mark_cb.SetValue(DEFAULT_MARKER) mark_cb.SetFont(self.hfont) self.ops.marker_no = mark_cb sizer.Add(mark_cb, pos=(9, 5)) mark_cb.Bind(wx.EVT_COMBOBOX, self.OnSelectPS) # Load list of parameters from file load_ps_btn = wx.Button(self, label="Load File", size=(90, 25)) load_ps_btn.SetFont(self.hfont) sizer.Add(load_ps_btn, pos=(9, 6)) load_ps_btn.Bind(wx.EVT_BUTTON, self.OnLoadParamFile) # List box to show currently selected parameter # list. ps_label = wx.StaticText(self, label="Parameter list:") sizer.Add(ps_label, pos=(11, 4)) ps_lb = wx.ListBox(self) ps_lb.SetFont(self.hfont) self.ops.ps_box = ps_lb sizer.Add(ps_lb, pos=(10, 5), span=(5, 2), flag=wx.EXPAND) # Clears the current parameter list. ps_clr_btn = wx.Button(self, label="Clear", size=(90, 25)) ps_clr_btn.Bind(wx.EVT_BUTTON, self.OnClearPS) ps_clr_btn.SetFont(self.hfont) sizer.Add(ps_clr_btn, pos=(13, 4), flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL) # Deletes the currently selected parameter. If no # parameter is selected, delete the last one. ps_del_btn = wx.Button(self, label="Delete", size=(90, 25)) ps_del_btn.Bind(wx.EVT_BUTTON, self.OnDelP) ps_del_btn.SetFont(self.hfont) sizer.Add(ps_del_btn, pos=(14, 4), flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL) # Button, textbox, and label to add parameter to # parameter list. add_pl_btn = wx.Button(self, label="Add", size=(90, 25)) add_pl_btn.SetFont(self.hfont) sizer.Add(add_pl_btn, pos=(15, 4), flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL) add_pl_txt = wx.TextCtrl(self) add_pl_txt.SetFont(self.hfont) self.ops.add_p = add_pl_txt sizer.Add(add_pl_txt, pos=(15, 5), span=(1, 2), flag=wx.EXPAND) add_pl_btn.Bind(wx.EVT_BUTTON, self.OnAddP) # Encoder label and drop down box. Will encode # all parameters with selected encoder. encdr_lbl = wx.StaticText(self, label="Encoder: ") encdr_lbl.SetFont(self.hfont) sizer.Add(encdr_lbl, pos=(16, 4), flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL) encdrs = ["None", "Hexadecimal", "Base 64", "MD5"] encdr_cb = wx.ComboBox(self, choices=encdrs, style=wx.CB_READONLY) encdr_cb.SetFont(self.hfont) encdr_cb.SetValue(DEFAULT_ENCODER) self.ops.encoder =encdr_cb sizer.Add(encdr_cb, pos=(16, 5), span=(1, 2), flag=wx.EXPAND) # Cosmetic horizontal separator line sep2 = wx.StaticLine(self, size=(300, 1)) sizer.Add(sep2, pos=(18, 4), span=(1, 4), flag=wx.ALIGN_CENTER) # Timeout label and textbox timeout_lbl = wx.StaticText(self, label="Timeout: ") timeout_lbl.SetFont(self.hfont) sizer.Add(timeout_lbl, pos=(20, 4), flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL) timeout_txt = wx.TextCtrl(self) timeout_txt.SetFont(self.hfont) timeout_txt.SetValue(DEFAULT_TIMEOUT) self.ops.timeout = timeout_txt sizer.Add(timeout_txt, pos=(20, 5), span=(1, 1), flag=wx.EXPAND) # Checkbox to either enable or disable the updating of # the Content-Length HTTP header. This should probably # be used if the length of the parameters vary and the # PUT or POST methods are being used update_cl = wx.CheckBox(self, label="Update Content Length Header") update_cl.SetFont(self.hfont) update_cl.SetValue(DEFAULT_UPDATE_CL) self.ops.update_cl = update_cl sizer.Add(update_cl, pos=(21, 5), span=(1, 2)) # Checkbox to enable or disable the use of an HTTP proxy proxy = wx.CheckBox(self, label="Use Proxy") proxy.SetFont(self.hfont) proxy.SetValue(DEFAULT_USE_PROXY) self.ops.proxy = proxy sizer.Add(proxy, pos=(22, 5), span=(1, 2)) # Textbox and label to define the domain name # or IP address of the proxy server to connect to phost_lbl = wx.StaticText(self, label="Proxy Host: ") phost_lbl.SetFont(self.hfont) sizer.Add(phost_lbl, pos=(23,4), flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL) phost_txt = wx.TextCtrl(self) phost_txt.SetFont(self.hfont) phost_txt.SetValue(DEFAULT_PROXY_HOST) self.ops.proxy_host = phost_txt sizer.Add(phost_txt, pos=(23, 5), span=(1, 2), flag=wx.EXPAND) # Textbox and label to define the TCP port # of the proxy server. pport_lbl = wx.StaticText(self, label="Proxy Port: ") pport_lbl.SetFont(self.hfont) sizer.Add(pport_lbl, pos=(24,4), flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL) pport_txt = wx.TextCtrl(self) pport_txt.SetFont(self.hfont) pport_txt.SetValue(DEFAULT_PROXY_PORT) self.ops.proxy_port = pport_txt sizer.Add(pport_txt, pos=(24, 5), span=(1, 2), flag=wx.EXPAND) # Checkbox to enable or disable proxy authentication # If enabled, Proxy-Authorization header will be added # to the request. proxy_auth = wx.CheckBox(self, label="Authenticate Proxy") proxy_auth.SetFont(self.hfont) proxy_auth.SetValue(DEFAULT_AUTHENTICATE_PROXY) self.ops.proxy_auth = proxy_auth sizer.Add(proxy_auth, pos=(25, 5), span=(1, 2)) # Proxy username used for proxy authentication puser_lbl = wx.StaticText(self, label="Proxy User: "******"Proxy Pass: "******"Reconnect Attempts: ") ra_lbl.SetFont(self.hfont) sizer.Add(ra_lbl, pos=(28,4), span=(1, 2), flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL) ra_txt = wx.TextCtrl(self) ra_txt.SetFont(self.hfont) ra_txt.SetValue(DEFAULT_RA) self.ops.reconnects = ra_txt sizer.Add(ra_txt, pos=(28, 6), span=(1, 1), flag=wx.EXPAND) # Number of milliseconds to wait between reconnect attempts # upon a network failure. rcd_lbl = wx.StaticText(self, label="Reconnect Delay (ms): ") rcd_lbl.SetFont(self.hfont) sizer.Add(rcd_lbl, pos=(29,4), span=(1, 2), flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL) rcd_txt = wx.TextCtrl(self) rcd_txt.SetFont(self.hfont) rcd_txt.SetValue(DEFAULT_RCD) self.ops.recon_delay = rcd_txt sizer.Add(rcd_txt, pos=(29, 6), span=(1, 1), flag=wx.EXPAND) # Maximum number of connections to have open with the server. # Be careful as high values for this can trigger # IDS or possibly a DoS. Maximum recommended value # over the Internet is 10. threads_lbl = wx.StaticText(self, label="Network Threads: ") threads_lbl.SetFont(self.hfont) sizer.Add(threads_lbl, pos=(30,4), span=(1, 2), flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL) threads_txt = wx.TextCtrl(self) threads_txt.SetFont(self.hfont) threads_txt.SetValue(DEFAULT_THREADS) self.ops.threads = threads_txt sizer.Add(threads_txt, pos=(30, 6), span=(1, 1), flag=wx.EXPAND) # Number of milliseconds to wait between opening a new # connection to the server. If there are currently the # max number of connections open with the server, this # defines the number of milliseconds to wait # after a connection slot has opened up. rqd_lbl = wx.StaticText(self, label="Requests Delay (ms):") rqd_lbl.SetFont(self.hfont) sizer.Add(rqd_lbl, pos=(31,4), span=(1, 2), flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL) rqd_txt = wx.TextCtrl(self) rqd_txt.SetFont(self.hfont) rqd_txt.SetValue(DEFAULT_RQD) self.ops.request_delay = rqd_txt sizer.Add(rqd_txt, pos=(31, 6), span=(1, 1), flag=wx.EXPAND) # Button to add parameter markers, these markers will be added # at the position of the text cursor in the data box. # In the future I'll try to add the ability to place markers # at the beginning and end of a selection of text. add_mark_btn = wx.Button(self, label="Add Markers", size=(120, 25)) add_mark_btn.SetFont(self.hfont) add_mark_btn.Bind(wx.EVT_BUTTON, self.OnAddMarkers) sizer.Add(add_mark_btn, pos=(30, 1), flag=wx.ALIGN_RIGHT) # Clear all the markers from the data text box. clr_mark_btn = wx.Button(self, label="Clear Markers", size=(120, 25)) clr_mark_btn.Bind(wx.EVT_BUTTON, self.OnClearMarkers) clr_mark_btn.SetFont(self.hfont) sizer.Add(clr_mark_btn, pos=(30, 2)) # This defines the progress bar for the current engine job. progress_bar = wx.Gauge(self, range=100) sizer.Add(progress_bar, pos=(31, 1), flag=wx.EXPAND, span=(1, 2)) self.ops.progress_bar = progress_bar sizer.Add((10, 10), pos=(35, 1))
def __init__(self): """Initialise widgets and layout.""" super().__init__( parent=None, title="NRFIS Data Collection System", size=(1000, 800) ) # Initialise client self.client = x55Client() # Configure the file menu file_menu = wx.Menu() menu_bar = wx.MenuBar() file_menu.Append(wx.ID_ABOUT, "About") file_menu.Append(wx.ID_EXIT, "Quit") menu_bar.Append(file_menu, "File") self.SetMenuBar(menu_bar) # Configure the widgets self.title = wx.StaticText(self, wx.ID_ANY, self.client.name) self.connect = wx.Button(self, wx.ID_ANY, "Connect") self.stream = wx.Button(self, wx.ID_ANY, "Start streaming") self.stream.Disable() # Streaming button disabled until client has connected self.configuration = wx.Button(self, wx.ID_ANY, "Upload config file") self.host = wx.TextCtrl(self, wx.ID_ANY, self.client.host) self.setup = wx.Choice( self, wx.ID_ANY, choices=[str(option) for option in SetupOptions] ) self.setup.SetSelection(self.client.configuration.setup) self.laser_scan_speed_choice = wx.Choice( self, wx.ID_ANY, choices=[str(x) for x in self.client.available_laser_scan_speeds], ) self.laser_scan_speed_choice.Disable() self.divider = wx.Choice( self, wx.ID_ANY, choices=[str(x) for x in self.client.divider_options] ) self.divider.Disable() # Status information self.statuses = { "instrument_name": "Instrument name", "firmware_version": "Firmware version", "is_ready": "Ready", "dut_channel_count": "DUT channel count", "peak_data_streaming_status": "Streaming status", "laser_scan_speed": "Laser scan speed", "peak_data_streaming_divider": "Streaming divider", "effective_sampling_rate": "Effective sampling rate", "peak_data_streaming_available_buffer": "Available streaming buffer", "instrument_time": "Instrument time", "ntp_enabled": "NTP server enabled", "ntp_server": "NTP server address", } for status in self.statuses: setattr(self, status, wx.StaticText(self, wx.ID_ANY, "None")) # Log widget self.log = LogList(self, wx.ID_ANY, size=(300, 100), style=wx.LC_REPORT) # Bind events to widgets self.Bind(wx.EVT_MENU, self.on_menu) AsyncBind(wx.EVT_BUTTON, self.on_connect, self.connect) AsyncBind(wx.EVT_BUTTON, self.on_stream, self.stream) AsyncBind(wx.EVT_BUTTON, self.on_configuration, self.configuration) AsyncBind(wx.EVT_TEXT, self.on_change_host, self.host) AsyncBind( wx.EVT_CHOICE, self.on_change_laser_scan_speed, self.laser_scan_speed_choice ) AsyncBind(wx.EVT_CHOICE, self.on_change_divider, self.divider) AsyncBind(wx.EVT_CHOICE, self.on_change_setup, self.setup) # Configure sizers for layout main_sizer = wx.BoxSizer(wx.HORIZONTAL) client_sizer = wx.BoxSizer(wx.VERTICAL) control_sizer = wx.GridSizer(4, 2, 0, 10) status_sizer = wx.GridSizer(len(self.statuses), 2, 0, 10) log_sizer = wx.StaticBoxSizer(wx.HORIZONTAL, self) main_sizer.Add(client_sizer, 0.5, wx.ALL | wx.EXPAND, 5) main_sizer.Add(log_sizer, 1, wx.ALL | wx.EXPAND, 5) client_sizer.Add(self.title, 0, wx.ALL, 5) client_sizer.Add(self.connect, 0, wx.ALL | wx.EXPAND, 5) client_sizer.Add(self.stream, 0, wx.ALL | wx.EXPAND, 5) client_sizer.Add(self.configuration, 0, wx.ALL | wx.EXPAND, 5) client_sizer.Add(control_sizer, 0, wx.ALL | wx.EXPAND, 5) client_sizer.Add(status_sizer, 0, wx.ALL | wx.EXPAND, 5) control_sizer.Add( wx.StaticText(self, wx.ID_ANY, "Host:"), 0, wx.ALL | wx.EXPAND, 5, ) control_sizer.Add( self.host, 0, wx.ALL | wx.EXPAND, 5, ) control_sizer.Add( wx.StaticText(self, wx.ID_ANY, "Laser scan speed (Hz):"), 0, wx.ALL | wx.EXPAND, 5, ) control_sizer.Add( self.laser_scan_speed_choice, 0, wx.ALL | wx.EXPAND, 5, ) control_sizer.Add( wx.StaticText(self, wx.ID_ANY, "Peak data streaming divider:"), 0, wx.ALL | wx.EXPAND, 5, ) control_sizer.Add( self.divider, 0, wx.ALL | wx.EXPAND, 5, ) control_sizer.Add( wx.StaticText(self, wx.ID_ANY, "Setup:"), 0, wx.ALL | wx.EXPAND, 5, ) control_sizer.Add( self.setup, 0, wx.ALL | wx.EXPAND, 5, ) for status in self.statuses: status_sizer.Add( wx.StaticText(self, wx.ID_ANY, self.statuses[status]), 0, wx.ALL | wx.EXPAND, 5, ) status_sizer.Add(getattr(self, status), 0, wx.ALL | wx.EXPAND, 5) log_sizer.Add(self.log, 1, wx.ALL | wx.EXPAND, 5) self.SetSizeHints(600, 600) # Sets the minimum window size self.SetSizer(main_sizer) # Add tooltips self.connect.SetToolTip("Connect/disconnect to the specified host and port") self.stream.SetToolTip("Start/stop streaming data from specified analyser") self.configuration.SetToolTip( "Uploads and extracts sensor metadata from a .moi Enlight configuration file" ) self.host.SetToolTip("Set the host name of the instrument") self.setup.SetToolTip( "Select the current package(s) that are connected to the instrument" ) self.laser_scan_speed_choice.SetToolTip( "Set the laser scan speed of the instrument" ) self.divider.SetToolTip("Set the data rate divider of the instrument")
def __init__(self, parent=None, title="New Key", algorithms=[], HandleNewKey=NullCoroutine): super().__init__(parent, title=title, size=(550, 300), style=wx.RESIZE_BORDER | wx.DEFAULT_DIALOG_STYLE) self.HandleNewKey = HandleNewKey self.key_label_label = wx.StaticText(self, label="Label:") self.key_label = wx.TextCtrl(self) self.algorithm_label = wx.StaticText(self, label="Algorithm:") self.algorithm = wx.ComboBox(self, choices=algorithms, style=wx.CB_READONLY) self.security_label = wx.StaticText(self, label="Security:") self.security = wx.ComboBox(self, choices=[str(i) for i in range(1, 5)], style=wx.CB_READONLY) self.gauge = wx.Gauge(self) self.gauge.Hide() self.error_message = wx.StaticText(self, label="") self.error_message.SetForegroundColour(Colour("Red")) self.submit = wx.Button(self, label="Submit") self.submit.SetId(wx.ID_OK) self.submit.SetFocus() AsyncBind(wx.EVT_BUTTON, self.OnSubmit, self.submit) self.cancel = wx.Button(self, label="Cancel") self.cancel.SetId(wx.ID_CANCEL) # spacers vbox = wx.BoxSizer(wx.VERTICAL) vbox.AddSpacer(40) vbox.Add(self.key_label_label, 0, wx.EXPAND | wx.RIGHT | wx.LEFT, border=20) vbox.Add(self.key_label, 0, wx.EXPAND | wx.RIGHT | wx.LEFT, border=20) vbox.Add(self.algorithm_label, 0, wx.EXPAND | wx.RIGHT | wx.LEFT, border=20) vbox.Add(self.algorithm, 0, wx.EXPAND | wx.RIGHT | wx.LEFT, border=20) vbox.Add(self.security_label, 0, wx.EXPAND | wx.RIGHT | wx.LEFT, border=20) vbox.Add(self.security, 0, wx.EXPAND | wx.RIGHT | wx.LEFT, border=20) vbox.AddSpacer(20) vbox.Add(self.gauge, 0, wx.EXPAND | wx.RIGHT | wx.LEFT, border=20) vbox.Add(self.error_message, 0, wx.RIGHT | wx.LEFT, border=20) vbox.AddStretchSpacer(1) button_sizer = wx.BoxSizer(wx.HORIZONTAL) button_sizer.Add(self.cancel) button_sizer.Add(self.submit) vbox.Add(button_sizer, 1, wx.ALIGN_RIGHT | wx.RIGHT | wx.LEFT | wx.BOTTOM, border=20) self.SetSizer(vbox) self.Layout()
def __init__(self, title, buffer, msg_queue): wx.Frame.__init__(self, None, -1, title=title or 'wxVLC', pos=wx.DefaultPosition, size=(550, 500)) self.buffer = buffer self.msg_queue = msg_queue self.running = True self.playing = False self.selected = False # Menu Bar # File Menu self.frame_menubar = wx.MenuBar() self.file_menu = wx.Menu() self.menu_open = self.file_menu.Append(1, "&Open", "Open distant file") self.menu_open.Enable(False) # self.file_menu.AppendSeparator() # self.file_menu.Append(2, "&Close", "Quit") self.frame_menubar.Append(self.file_menu, "File") self.SetMenuBar(self.frame_menubar) AsyncBind(wx.EVT_MENU, self.OnOpen, self, id=1) # AsyncBind(wx.EVT_MENU, self.OnExit, self, id=2) # Panels # The first panel holds the video and it's all black self.videopanel = wx.Panel(self, -1) self.videopanel.SetBackgroundColour(wx.BLACK) # The second panel holds controls ctrlpanel = wx.Panel(self, -1) # self.timeslider = wx.Slider(ctrlpanel, -1, 0, 0, 1000) # self.timeslider.SetRange(0, 1000) self.pause = wx.Button(ctrlpanel, label="Pause") self.pause.Disable() self.play = wx.Button(ctrlpanel, label="Play") self.play.Disable() self.stop = wx.Button(ctrlpanel, label="Stop") self.stop.Disable() self.mute = wx.Button(ctrlpanel, label="Mute") self.volslider = wx.Slider(ctrlpanel, -1, 0, 0, 100, size=(100, -1)) # Bind controls to events AsyncBind(wx.EVT_BUTTON, self.OnPlay, self.play) AsyncBind(wx.EVT_BUTTON, self.OnPause, self.pause) AsyncBind(wx.EVT_BUTTON, self.OnStop, self.stop) AsyncBind(wx.EVT_BUTTON, self.OnMute, self.mute) AsyncBind(wx.EVT_SLIDER, self.OnVolume, self.volslider) # Give a pretty layout to the controls ctrlbox = wx.BoxSizer(wx.VERTICAL) box1 = wx.BoxSizer(wx.HORIZONTAL) box2 = wx.BoxSizer(wx.HORIZONTAL) # box1 contains the timeslider # box1.Add(self.timeslider, 1) # box2 contains some buttons and the volume controls box2.Add(self.play, flag=wx.RIGHT, border=5) box2.Add(self.pause) box2.Add(self.stop) box2.Add((-1, -1), 1) box2.Add(self.mute) box2.Add(self.volslider, flag=wx.TOP | wx.LEFT, border=5) # Merge box1 and box2 to the ctrlsizer ctrlbox.Add(box1, flag=wx.EXPAND | wx.BOTTOM, border=10) ctrlbox.Add(box2, 1, wx.EXPAND) ctrlpanel.SetSizer(ctrlbox) # Put everything togheter sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.videopanel, 1, flag=wx.EXPAND) sizer.Add(ctrlpanel, flag=wx.EXPAND | wx.BOTTOM | wx.TOP, border=10) self.SetSizer(sizer) self.SetMinSize((350, 300)) # finally create the timer, which updates the timeslider # StartCoroutine(self.OnTimer, self) # VLC player controls self.Instance = vlc.Instance() self.player = self.Instance.media_player_new() print("Created") StartCoroutine(self.WaitConnection, self)
def __init__(self, username, token): self.username = username # exchange the token for a praw reddit instance that is logged in. self.reddit_instance = reddit_instance_factory.new_reddit_instance( token) super().__init__(None, wx.ID_ANY, title=f"UtopiaForReddit ({self.username})", style=wx.MAXIMIZE) # menu application_menu = wx.Menu() application_menu.Append(CustomIDS.ACCOUNT_MANAGER, "Account Manager", "Add and remove reddit accounts.") application_menu.Append( wx.ID_PREFERENCES, "&Preferences" + "\tCTRL+SHIFT+P" if platform.system() == "Windows" else "&Preferences" + "\tCTRL+,", "Open the preferences.") application_menu.Append(wx.ID_EXIT, "Exit") application_menu.Bind(wx.EVT_MENU, self.on_show_account_manager, id=CustomIDS.ACCOUNT_MANAGER) application_menu.Bind(wx.EVT_MENU, self.on_show_preferences, id=wx.ID_PREFERENCES) application_menu.Bind(wx.EVT_MENU, lambda event: self.Close(), id=wx.ID_EXIT) help_menu = wx.Menu() help_menu.Append(CustomIDS.LICENSE, "License") help_menu.Append(CustomIDS.CHECK_FOR_UPDATES, "Check for updates") help_menu.Append(CustomIDS.DONATE, "Donate") help_menu.Append(CustomIDS.SHOW_TIPS, "Show Utopia Program Tips") AsyncBind(wx.EVT_MENU, updater.menu_check_for_updates, self, id=CustomIDS.CHECK_FOR_UPDATES) help_menu.Bind( wx.EVT_MENU, lambda event: webbrowser.open("https://accessiware.com/donate"), id=CustomIDS.DONATE) help_menu.Bind(wx.EVT_MENU, lambda event: tips.show_tips(self, True), id=CustomIDS.SHOW_TIPS) menuBar = wx.MenuBar() menuBar.Append(application_menu, "Application") menuBar.Append(help_menu, "&Help") self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame content. self.panel = wx.Panel(self) self.book = wx.Notebook(self.panel, style=wx.NB_TOP | wx.NB_NOPAGETHEME) AsyncBind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.on_notebook_page_change, self) AsyncBind(wx.EVT_NOTEBOOK_PAGE_CHANGING, self.on_notebook_page_changing, self) self.book.AddPage( main_ui_pages.HomePanel(self.book, self.reddit_instance), "HOME") self.book.AddPage( main_ui_pages.SubredditsPanel(self.book, self.reddit_instance), "My Subreddits") self.book.AddPage( main_ui_pages.ProfilePanel(self.book, self.reddit_instance), "My Profile") StartCoroutine(self.book.GetPage(0).on_gain_focus(), self) self.Maximize() mainsizer = wx.BoxSizer() mainsizer.Add(self.book, 1, wx.EXPAND) self.SetSizer(mainsizer) mainsizer.Fit(self)
def __init__(self, parent=None): super(TestFrame, self).__init__(parent, size=(600, 800)) vbox = wx.BoxSizer(wx.VERTICAL) button1 = wx.Button(self, label="ColourDialog") button2 = wx.Button(self, label="DirDialog") button3 = wx.Button(self, label="FileDialog") # FindReplaceDialog is always modless button5 = wx.Button(self, label="FontDialog") # GenericProgressDialog does not input data button7 = wx.Button(self, label="HtmlHelpDialog") button8 = wx.Button(self, label="MessageDialog") button9 = wx.Button(self, label="MultiChoiceDialog") button10 = wx.Button(self, label="NumberEntryDialog") button12 = wx.Button(self, label="PrintAbortDialog") button13 = wx.Button(self, label="PropertySheetDialog") button14 = wx.Button(self, label="RearrangeDialog") button16 = wx.Button(self, label="SingleChoiceDialog") button18 = wx.Button(self, label="TextEntryDialog") self.edit_timer = wx.StaticText(self, style=wx.ALIGN_CENTRE_HORIZONTAL | wx.ST_NO_AUTORESIZE) vbox.Add(button1, 2, wx.EXPAND | wx.ALL) vbox.Add(button2, 2, wx.EXPAND | wx.ALL) vbox.Add(button3, 2, wx.EXPAND | wx.ALL) vbox.Add(button5, 2, wx.EXPAND | wx.ALL) vbox.Add(button7, 2, wx.EXPAND | wx.ALL) vbox.Add(button8, 2, wx.EXPAND | wx.ALL) vbox.Add(button9, 2, wx.EXPAND | wx.ALL) vbox.Add(button10, 2, wx.EXPAND | wx.ALL) vbox.Add(button12, 2, wx.EXPAND | wx.ALL) vbox.Add(button13, 2, wx.EXPAND | wx.ALL) vbox.Add(button14, 2, wx.EXPAND | wx.ALL) vbox.Add(button16, 2, wx.EXPAND | wx.ALL) vbox.Add(button18, 2, wx.EXPAND | wx.ALL) AsyncBind(wx.EVT_BUTTON, self.on_ColourDialog, button1) AsyncBind(wx.EVT_BUTTON, self.on_DirDialog, button2) AsyncBind(wx.EVT_BUTTON, self.on_FileDialog, button3) AsyncBind(wx.EVT_BUTTON, self.on_FontDialog, button5) AsyncBind(wx.EVT_BUTTON, self.on_HtmlHelpDialog, button7) AsyncBind(wx.EVT_BUTTON, self.on_MessageDialog, button8) AsyncBind(wx.EVT_BUTTON, self.on_MultiChoiceDialog, button9) AsyncBind(wx.EVT_BUTTON, self.on_NumberEntryDialog, button10) AsyncBind(wx.EVT_BUTTON, self.on_PrintAbortDialog, button12) AsyncBind(wx.EVT_BUTTON, self.on_PropertySheetDialog, button13) AsyncBind(wx.EVT_BUTTON, self.on_RearrangeDialog, button14) AsyncBind(wx.EVT_BUTTON, self.on_SingleChoiceDialog, button16) AsyncBind(wx.EVT_BUTTON, self.on_TextEntryDialog, button18) button5 = wx.Button(self, label="FontDialog") button7 = wx.Button(self, label="HtmlHelpDialog") button8 = wx.Button(self, label="MessageDialog") button9 = wx.Button(self, label="MultiChoiceDialog") button10 = wx.Button(self, label="NumberEntryDialog") button12 = wx.Button(self, label="PrintAbortDialog") button13 = wx.Button(self, label="PropertySheetDialog") button14 = wx.Button(self, label="RearrangeDialog") button16 = wx.Button(self, label="SingleChoiceDialog") button18 = wx.Button(self, label="TextEntryDialog") self.SetSizer(vbox) self.Layout() vbox.AddStretchSpacer(1) vbox.Add(self.edit_timer, 1, wx.EXPAND | wx.ALL) self.SetSizer(vbox) self.Layout() StartCoroutine(self.update_clock, self)