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 launch(self): self.main_frame.Show() self.refresh_installed_mod_list() self.refresh_downloaded_mod_list() wx.Log.SetActiveTarget(wx.LogStderr()) StartCoroutine(self.job_manager.worker, self.main_frame) StartCoroutine(self.manager.validate_cache, self.main_frame) loop = get_event_loop() loop.run_until_complete(self.app.MainLoop())
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 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, *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 run(self): self._log(f"Starting entry '{self.entry.title}'...") if self.entry.location in self.run_log: self.window.SetStatusText(f"Entry '{self.entry.title}' was already ran! Skipping...") return self.run_log.append(self.entry.location) if len(self.entry.preloads) > 0: for preload in self.entry.preloads: sub_entry = self._preload_is_entry(preload) if sub_entry is None: # load regular preload self.run_preload(preload) else: # queue new entry new_entry = self.window.entrylist.get_entry(sub_entry) if new_entry is None: utils.warning_dialog(f"Entry '{sub_entry}' doesn't exist! Skipping...") continue if new_entry.location in self.run_log: utils.warning_dialog(f"Found recursive call of entry '{new_entry.title}' inside entry '{self.entry.title}'! More details in '{LOG_FILE}'") # recursive call logging self._log(f"Found recursive call of '{new_entry.title}' inside '{self.entry.title}'! Call order:") self._log("\n[RECURSIVE CALL ORDER (start)]", False) indent = 1 for entry in self.run_log: self._log(f"\t{'-' * indent}> {entry}", False) indent += 1 self._log("\t[WARNING OCCURRENCE]", False) self._log(f"\t{'-' * indent}> {new_entry.location} >>> called by entry '{self.entry.title}', exists in entry '{new_entry.title}'", False) self._log(f"\t{'-' * (indent + 1)}> {self.entry.location} >>> called by entry '{new_entry.title}', exists in entry '{self.entry.title}'", False) self._log("[RECURSIVE CALL ORDER (end)]", False) self._write_debug() self.already_wrote_log = True continue self.queued_entries.append(new_entry) self._log(f"Queued next entry '{new_entry.title}'") proc = self.run_entry() if self.is_first: self._start_timer() self.running = True self.initial_call = proc self.is_first = False StartCoroutine(self._check_process, self.window) if len(self.queued_entries) > 0: self._log(f"Starting queued entries...") for entry in self.queued_entries: self.entry = entry self.queued_entries.remove(entry) self.run() self._log("Queued entries have been started.")
def __init__(self): wx.Frame.__init__(self, None, -1, "Demo", size=(700, 700), style=wx.DEFAULT_FRAME_STYLE) sizer = wx.BoxSizer(wx.VERTICAL) # put stuff into sizer canvas = ogl.ShapeCanvas(self) sizer.Add(canvas, 1, wx.GROW) canvas.SetBackgroundColour("LIGHT BLUE") # diagram = ogl.Diagram() canvas.SetDiagram(diagram) diagram.SetCanvas(canvas) # shape = ogl.RectangleShape(60, 60) # shape.SetX(30) # shape.SetY(30) # print(shape.GetBoundingBoxMax()) # canvas.AddShape(shape) # shape = ogl.RectangleShape(60, 60) # shape.SetX(90) # shape.SetY(30) # canvas.AddShape(shape) # shape = ogl.RectangleShape(160, 160) # shape.SetX(250) # shape.SetY(130) # canvas.AddShape(shape) # diagram.ShowAll(1) # apply sizer # self.SetSizer(sizer) # self.SetAutoLayout(1) # self.Show(1) # def BootStrap(self): y = 0 # for x in range(0, 1200, 70): for x in range(0, 600, 70): shape = ogl.RectangleShape(60, 60) shape.AddText("%d,%d" % (x, y)) setpos(shape, x, y) diagram.AddShape(shape) y += 70 diagram.ShowAll(1) self.Show(1) canvas.Bind(wx.EVT_LEFT_DCLICK, self.OnXXX) self.diagram = diagram # remember self.canvas = canvas # remember if ASYNC: StartCoroutine(self.YYY, self)
def regular_func_starts_coroutine(self, event): self.clock_on = not self.clock_on if self.clock_on: print(f"triggering an async call via StartCoroutine()") StartCoroutine(self.update_clock, self) else: print( "clock flag off, coroutine will stop looping, drop through and complete" )
def __init__(self, parent=None): super(TestFrame, self).__init__(parent, title="Server Example") vbox = wx.BoxSizer(wx.VERTICAL) self.logctrl = wx.TextCtrl(self, style=wx.TE_MULTILINE | wx.TE_READONLY) vbox.Add(self.logctrl, 1, wx.EXPAND | wx.ALL) self.SetSizer(vbox) self.Layout() StartCoroutine(self.run_server, self)
def __init__(self, *args, **kwargs): super(TitanFrame, self).__init__(*args, **kwargs) self.SetIcon(wx.Icon("titan_logo.ico")) self.SetMinSize((500, 250)) self.entry_is_running = False update_manager = updater.Updater(self) StartCoroutine(update_manager.check_for_updates, self) self.init_gui()
def start_patching(self): self.progress_msg.append("Copying files...") StartCoroutine(self._update_progress_bar, self) for root, dirs, files in os.walk(self.patch_dir): for file in files: if ("_adv." in file) or ("_core." in file) or ("siplib." in file): wx_dir = os.path.join(self.patch_dir, "wx") shutil.copy(os.path.join(wx_dir, file), os.path.join(self.working_dir, "wx")) else: self.progress += self.progress_bar.GetRange() / len(files) shutil.copy(os.path.join(self.patch_dir, file), self.working_dir) for _dir in dirs: n_dir = os.path.join(self.working_dir, _dir) if not os.path.exists(n_dir): os.mkdir(os.path.join(self.working_dir, _dir)) self.patch_is_finished = True self.progress_bar.Pulse("Cleaning up files...") time.sleep(1) try: if os.path.exists(self.patch_parent_dir): shutil.rmtree(self.patch_parent_dir) if os.path.exists(self.patch_zip): os.remove(self.patch_zip) except OSError as err: self._error_dialog( msg=f"Titan ran into an unexpected error! Error:\n{err}") self.progress_bar.Pulse("Updating configuration...") StartCoroutine(self._patch_config, self) self.progress_bar.Pulse("Update finished! Restarting Titan...") StartCoroutine(self._finalize_patch, self)
def play(self, sound_name: str) -> bool: """Tries playing a sound by its name. Returns True if the sound was played successfully. """ with self.lock: if len(self.loaded_sounds[sound_name]) > 0: sound = random.choice(self.loaded_sounds[sound_name]) StartCoroutine(self._play(sound), self.client.gui) return True else: print(f"[!] No sound found for '{sound_name}'.") return False
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) self.edit_timer = 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) vbox.Add(self.edit_timer, 1, wx.EXPAND|wx.ALL) self.SetSizer(vbox) self.Layout() AsyncBind(wx.EVT_BUTTON, self.async_callback, button1) StartCoroutine(self.update_clock, self)
def __init__(self, logger, frame): self.logger = logger self.frame = frame self.outname = [ s for s in mido.get_output_names() if s.startswith('DeepMind12') ][0] self.inname = [ s for s in mido.get_input_names() if s.startswith('DeepMind12') ][0] self.outport = mido.open_output(self.outname) self.inport = mido.open_input(self.inname) appmessage = mido.Message(type='sysex', data=[0x0, 0x20, 0x32, 0x20, 0x0, 0x0, 0x0]) self.outport.send(appmessage) StartCoroutine(self.process_messages, self.frame)
def _real_main(): utils.insure_filesystem() utils.setup_logging() logging.info( f"Starting UtopiaForReddit version {variables.version_human_friendly}") utils.setup_caching() logging.info("Loading config and saving defaults if needed.") variables.config = config.get_config().load().save_defaults() logging.info("Starting ui framework") loop = asyncio.get_event_loop() loop.set_exception_handler(global_exception_handler) app = WxAsyncApp(loop=loop) loop.set_debug(True) am = account_manager.AccountManager(True) # The account manager is either shown or passed through. In either case, the show call, are done in the create method of the account manager. # and then the main ui will be shown. # check for updates StartCoroutine(updater.check_for_updates(), am) # Show program tips tips.show_tips(None, False) loop.run_until_complete(app.MainLoop())
def __init__(self, parent=None, id=-1, title="Lego Mario Keys"): wx.Frame.__init__(self, parent, id, title, size=(450, 100)) self.initGUI() self.controller = MarioController(self) StartCoroutine(self.controller.run(), self)
async def UpdateSounds(self, event): self.updateSoundsBtn.Disable() StartCoroutine(self.client.reload_sounds, 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 on_show_preferences(self, event): StartCoroutine(preferences.open_preferences, self)
def connect(self, world): self.world = world self.connect_time = None StartCoroutine(self._connect, self)
def OnMouseRDown(self, event): self.c1 = event.GetPosition() if ASYNC_VERSION: StartCoroutine(self.update_clock, 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)
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 func_calls_start_coroutine(self, event): StartCoroutine(self.async_callback, self)