def MainLoop(self): event_loop = wx.EventLoop() old = wx.EventLoop.GetActive() wx.EventLoop.SetActive(event_loop) while self.triggerServer.trigger(): self.update(event_loop) wx.EventLoop.SetActive(old)
def MainLoop(self): # Create an event loop and make it active. If you are # only going to temporarily have a nested event loop then # you should get a reference to the old one and set it as # the active event loop when you are done with this one... evtloop = wx.EventLoop() old = wx.EventLoop.GetActive() wx.EventLoop.SetActive(evtloop) # This outer loop determines when to exit the application, # for this example we let the main frame reset this flag # when it closes. while self.keepGoing: # At this point in the outer loop you could do # whatever you implemented your own MainLoop for. It # should be quick and non-blocking, otherwise your GUI # will freeze. # call_your_code_here() # This inner loop will process any GUI events # until there are no more waiting. while evtloop.Pending(): evtloop.Dispatch() # Send idle events to idle handlers. You may want to # throttle this back a bit somehow so there is not too # much CPU time spent in the idle handlers. For this # example, I'll just snooze a little... time.sleep(0.10) self.ProcessIdle() wx.EventLoop.SetActive(old)
def run(self): eWindows._APP = wx.App(False) eWindows._WX = self.Frame("eVHDL", (1000, 600)) eWindows._WX.Show(True) menubar = wx.MenuBar() eWindows._WX.SetMenuBar(menubar) eWindows._WX.CreateStatusBar() evtloop = wx.EventLoop() old = wx.EventLoop.GetActive() wx.EventLoop.SetActive(evtloop) while eWindows._RUNNING: while eWindows._APP.Pending(): eWindows._APP.Dispatch() while not self.inQueue.empty(): e, arg = self.inQueue.get() if e == eWindows.EVT_WINDOW: f = eWindows.Panel(eWindows._WX, "", (670, 300)) f.Show(True) self.outQueue.put(f) elif e == eWindows.EVT_WIDGET_CREATE: parent, widget, pos, span = arg w = widget(parent) setattr(parent, "w" + str(widget.__name__), w) parent.sizer.Add(w, pos, span, wx.EXPAND) parent.sizer.Fit(parent) sleep(0.01) eWindows._APP.ProcessIdle() wx.EventLoop.SetActive(old)
def MainLoop(self): eventLoop = wx.EventLoop() old = wx.EventLoop.GetActive() wx.EventLoop.SetActive(eventLoop) while True: while eventLoop.Pending(): eventLoop.Dispatch() if self.mainFrame.showCollage == True: print "Showing Collage" self.mainFrame.showCollageInner() self.mainFrame.showCollage = False print "Finished Showing Collage" elif self.mainFrame.panel.updatePicture == True: print "Updating picture" self.mainFrame.updatePicturesInPanel() self.mainFrame.panel.updatePicture = False elif self.mainFrame.panel.reset == True: self.mainFrame.panel.resetPanelInner() elif self.mainFrame.panel.updateCountdownImage == True: self.mainFrame.panel.updateCountdownInner() else: self.ProcessIdle()
def update(self): "process events - call in main loop" if self.adminFrame: # Check avoids PyDeadObjectError if self.adminFrame.bGui: # Create an event loop and make it active. # save the old one evtloop = wx.EventLoop() old = wx.EventLoop.GetActive() wx.EventLoop.SetActive(evtloop) # Update our view self.adminFrame.update() # This inner loop will process any GUI events # until there are no more waiting. while evtloop.Pending(): evtloop.Dispatch() # Send idle events to idle handlers. time.sleep(0.1) # Orig value was 0.01 self.ProcessIdle() # restore old event handler wx.EventLoop.SetActive(old) else: if self.adminFrame: # Check avoids PyDeadObjectError self.adminFrame.update()
def OnInit(self): #prepare and start the p3d-wx hybrid-engine mainloop self.wxevt_loop = wx.EventLoop() self.wxevt_old_loop = wx.EventLoop.GetActive() wx.EventLoop.SetActive(self.wxevt_loop) base.taskMgr.add(self._mainLoop, "MainLoopTask") #instantiate and assign the wx UI object self.win = P3dWxWindow(size=wx.Size(640, 480)) self.SetTopWindow(self.win) #show the wx window self.win.Show(True) # is essential to let make up wx window before P3D stuff self._mainLoop() #bind wx events self.win.Bind(wx.EVT_SIZE, self.onSize) self.win.Bind(wx.EVT_CLOSE, self.onClose) self.vetoActivate = False self.win.Bind(wx.EVT_ACTIVATE, self.onActivate) #open the p3d window undecorated to use in the wx frame window wp = WindowProperties().getDefault() wp.setUndecorated(True) wp.setOpen(True) wp.setParentWindow(self.win.getP3DSurface()) wp.setOrigin(0, 0) wp.setForeground(True) wp.setSize(*self.win.getP3DSurfaceSize()) print ">>>opening p3dsurface" assert base.openDefaultWindow(props=wp) == True # return True
def appInit(self): """Overridden from WxAppShell.py.""" # Create a new event loop (to overide default wxEventLoop) self.evtLoop = wx.EventLoop() self.oldLoop = wx.EventLoop.GetActive() wx.EventLoop.SetActive(self.evtLoop) taskMgr.add(self.wxStep, "evtLoopTask")
def input_handler2(): """Run the wx event loop by processing pending events only. This is like inputhook_wx1, but it keeps processing pending events until stdin is ready. After processing all pending events, a call to time.sleep is inserted. This is needed, otherwise, CPU usage is at 100%. This sleep time should be tuned though for best performance. """ app = wx.GetApp() global POLLTIME, ON_INTERRUPT if app is not None: if not wx.Thread_IsMain(): raise Exception('wx thread is not the main thread') evtloop = wx.EventLoop() activator = wx.EventLoopActivator(evtloop) while not stdin_ready(): while evtloop.Pending(): evtloop.Dispatch() app.ProcessIdle() try: sleep(POLLTIME) except KeyboardInterrupt: if hasattr(ON_INTERRUPT, '__call__'): ON_INTERRUPT() activator = None # del activator return 0
def update(): app = wx.GetApp() evtloop = wx.EventLoop() activator = wx.EventLoopActivator(evtloop) while evtloop.Pending(): evtloop.Dispatch() app.ProcessIdle()
def active_event_loop(self): # With wxPython 2.9.1, ProgressBar.Pulse breaks if there's no active # event loop. # See http://code.google.com/p/robotframework-ride/issues/detail?id=798 loop = wx.EventLoop() wx.EventLoop.SetActive(loop) yield del loop
def inputhook_wx3(): """Run the wx event loop by processing pending events only. This is like inputhook_wx1, but it keeps processing pending events until stdin is ready. After processing all pending events, a call to time.sleep is inserted. This is needed, otherwise, CPU usage is at 100%. This sleep time should be tuned though for best performance. """ # We need to protect against a user pressing Control-C when IPython is # idle and this is running. We trap KeyboardInterrupt and pass. try: app = wx.GetApp() if app is not None: assert wx.Thread_IsMain() # The import of wx on Linux sets the handler for signal.SIGINT # to 0. This is a bug in wx or gtk. We fix by just setting it # back to the Python default. if not isinstance(signal.getsignal(signal.SIGINT), collections.Callable): signal.signal(signal.SIGINT, signal.default_int_handler) evtloop = wx.EventLoop() ea = wx.EventLoopActivator(evtloop) t = clock() while not stdin_ready(): while evtloop.Pending(): t = clock() evtloop.Dispatch() app.ProcessIdle() # We need to sleep at this point to keep the idle CPU load # low. However, if sleep to long, GUI response is poor. As # a compromise, we watch how often GUI events are being processed # and switch between a short and long sleep time. Here are some # stats useful in helping to tune this. # time CPU load # 0.001 13% # 0.005 3% # 0.01 1.5% # 0.05 0.5% used_time = clock() - t if used_time > 5 * 60.0: # print 'Sleep for 5 s' # dbg time.sleep(5.0) elif used_time > 10.0: # print 'Sleep for 1 s' # dbg time.sleep(1.0) elif used_time > 0.1: # Few GUI events coming in, so we can sleep longer # print 'Sleep for 0.05 s' # dbg time.sleep(0.05) else: # Many GUI events coming in, so sleep only very little time.sleep(0.001) del ea except KeyboardInterrupt: pass return 0
def onUpdate(self, event=None): symtable = self.symtable if symtable.get_symbol('_builtin.force_wxupdate', create=True): app = wx.GetApp() evtloop = wx.EventLoop() while evtloop.Pending(): evtloop.Dispatch() app.ProcessIdle() symtable.set_symbol('_builtin.force_wxupdate', False)
def OnInit(self): frame = MainWindowFrame() frame.SetApplication(self) frame.Show(True) self.SetTopWindow(frame) self.keepGoing = True # Set up our very own event loop... self.eventLoop = wx.EventLoop() wx.EventLoop.SetActive(self.eventLoop) return True
def OnInit(self): global mainFrame mainFrame = MainFrame(self) self.SetTopWindow(mainFrame) mainFrame.Show(True) self.isRunning = True self.eventLoop = wx.EventLoop() wx.EventLoop.SetActive(self.eventLoop) nebula.setTrigger(self.Trigger) return True
def ShowModal(self): if hasattr(self, "MakeModal"): self.MakeModal() self.Show() self.Canvas.Canvas.ZoomToBB() # now to stop execution start a event loop self.eventLoop = wx.EventLoop() self.eventLoop.Run() self.Destroy() return self.checked
def make_callback(): evt_loop = wx.EventLoop() def event_callback(): while evt_loop.Pending(): evt_loop.Dispatch() app.ProcessPendingEvents() wx.EventLoop.SetActive(evt_loop) return event_callback
def process_events(self): wx = self.wx # This bit is really needed old = wx.EventLoop.GetActive() eventLoop = wx.EventLoop() wx.EventLoop.SetActive(eventLoop) while eventLoop.Pending(): eventLoop.Dispatch() # Process and reset self.app.ProcessIdle() # otherwise frames do not close wx.EventLoop.SetActive(old)
def MainLoop(self): evtloop = wx.EventLoop() old = wx.EventLoop.GetActive() wx.EventLoop.SetActive(evtloop) while self.keepGoing: while evtloop.Pending(): evtloop.Dispatch() time.sleep(0.02) self.ProcessIdle() self.check_keys() wx.EventLoop.SetActive(old)
def _spin_wx(self): """Process all pending events in the wx event loop. This is for internal IPython use only and user code should not call this. Instead, they should issue the raw GUI calls themselves. """ import wx app = wx.GetApp() if app is not None and wx.Thread_IsMain(): evtloop = wx.EventLoop() ea = wx.EventLoopActivator(evtloop) while evtloop.Pending(): evtloop.Dispatch() app.ProcessIdle() del ea
def MainLoop(self): self.looping = True myEventLoop = wx.EventLoop() prevEventLoop = wx.EventLoop.GetActive() wx.EventLoop.SetActive(myEventLoop) lastCheck = 0 while self.looping: # Process GUI events last while myEventLoop.Pending(): myEventLoop.Dispatch() time.sleep(0.1) self.ProcessIdle() wx.EventLoop.SetActive(prevEventLoop)
def _ProcessEvents(self): # Get app app = self._GetNativeApp() # Keep reference of old eventloop instance old = wx.EventLoop.GetActive() # Create new eventloop and process eventLoop = wx.EventLoop() wx.EventLoop.SetActive(eventLoop) while eventLoop.Pending(): eventLoop.Dispatch() # Process idle app.ProcessIdle() # otherwise frames do not close # Set back the original wx.EventLoop.SetActive(old)
def init_wx(video): controls = Controls(video) controls.Show() event_loop = wx.EventLoop() wx.EventLoop.SetActive(event_loop) def process_tasklet(): while True: while event_loop.Pending(): event_loop.Dispatch() wxapp.ProcessPendingEvents() wxapp.ProcessIdle() uthread2.Yield() uthread2.StartTasklet(process_tasklet)
def system_call(self, command_string): self._input_state = 'subprocess' event_loop = wx.EventLoop() def _end_system_call(): self._input_state = 'buffering' self._running_process = False event_loop.Exit() self._running_process = PipedProcess(command_string, out_callback=self.buffered_write, end_callback=_end_system_call) self._running_process.start() # XXX: Running a separate event_loop. Ugly. event_loop.Run() # Be sure to flush the buffer. self._buffer_flush(event=None)
def show(self, value=True, modal=None): "Display or hide the window, optionally disabling all other windows" self.wx_obj.Show(value) if modal: # disable all top level windows of this application (MakeModal) disabler = wx.WindowDisabler(self.wx_obj) # create an event loop to stop execution eventloop = wx.EventLoop() def on_close_modal(evt): evt.Skip() eventloop.Exit() self.wx_obj.Bind(wx.EVT_CLOSE, on_close_modal) # start the event loop to wait user interaction eventloop.Run() # reenable the windows disabled and return control to the caller del disabler
def wait_for_cursor(self, timeout=60.0): """wait for and return most recent cursor position""" self.has_cursor = False t0 = time.time() if self.symtable.has_symbol(self.xval): self.symtable.del_symbol(self.xval) app = wx.GetApp() # note that evtloop.Dispatch() seems to be very # important for allowing other windows to update! evtloop = wx.EventLoop() while (not self.has_cursor and time.time() - t0 < timeout): time.sleep(0.1) wx.Yield() app.ProcessIdle() while evtloop.Pending(): evtloop.Dispatch() self.thread.Stop()
def MainLoop(self): evtloop = wx.EventLoop() wx.EventLoop.SetActive(evtloop) # This outer loop determines when to exit the application, # for this example we let the main frame reset this flag # when it closes. if sys.platform == "darwin": while self.keepGoing: while self.keepGoing and evtloop.Pending(): evtloop.Dispatch() gevent.sleep(1.0 / 60) self.ProcessIdle() else: while self.keepGoing: while evtloop.Pending(): evtloop.Dispatch() gevent.sleep(1.0 / 30) self.ProcessIdle()
def inputhook_wx1(context): """Run the wx event loop by processing pending events only. This approach seems to work, but its performance is not great as it relies on having PyOS_InputHook called regularly. """ app = wx.GetApp() if app is not None: assert wx.Thread_IsMain() # Make a temporary event loop and process system events until # there are no more waiting, then allow idle events (which # will also deal with pending or posted wx events.) evtloop = wx.EventLoop() ea = wx.EventLoopActivator(evtloop) while evtloop.Pending(): evtloop.Dispatch() app.ProcessIdle() del ea return 0
def raw_input(self, prompt=''): """ A replacement from python's raw_input. """ self.new_prompt(prompt) self._input_state = 'raw_input' if hasattr(self, '_cursor'): del self._cursor self.SetCursor(wx.StockCursor(wx.CURSOR_CROSS)) self.__old_on_enter = self._on_enter event_loop = wx.EventLoop() def my_on_enter(): event_loop.Exit() self._on_enter = my_on_enter # XXX: Running a separate event_loop. Ugly. event_loop.Run() self._on_enter = self.__old_on_enter self._input_state = 'buffering' self._cursor = wx.BusyCursor() return self.input_buffer.rstrip('\n')
def MainLoop(self): eventLoop = wx.EventLoop() old = wx.EventLoop.GetActive() wx.EventLoop.SetActive(eventLoop) while True: while eventLoop.Pending(): eventLoop.Dispatch() if self.mainFrame.showCollage == True: self.logger.debug("Showing Collage") self.mainFrame.showCollageInner() self.mainFrame.showCollage = False self.logger.debug("Finished Showing Collage") elif self.mainFrame.panel.reset == True: self.mainFrame.panel.resetPanelInner() elif self.mainFrame.panel.updateCountdownImage == True: self.mainFrame.panel.updateCountdownInner() else: self.ProcessIdle()
def update(self): "process events - call in main loop" # Create an event loop and make it active. # save the old one evtloop = wx.EventLoop() old = wx.EventLoop.GetActive() wx.EventLoop.SetActive(evtloop) # Update our view self.adminFrame.update() # This inner loop will process any GUI events # until there are no more waiting. while evtloop.Pending(): evtloop.Dispatch() # Send idle events to idle handlers. time.sleep(0.01) self.ProcessIdle() # restore old event handler wx.EventLoop.SetActive(old)