def update_plot(*args): """ hmm """ global control, loopcount, localisation if update_plot.background is None: update_plot.background = canvas.copy_from_bbox(ax.bbox) starttime = time.time() localisation.update(control, None) x.append(localisation.State[0]) y.append(localisation.State[1]) o.append(localisation.State[2]) loopcount += 1 if loopcount == 2: print "Starting" control = numpy.array([-1, 0.3, 0]) elif loopcount == 50: control = numpy.array([0, 0, 0]) canvas.restore_region(update_plot.background) estimateplot.set_data(x, y) particleplot.set_data( numpy.array(localisation.States[:, Localisation.Y]), numpy.array(localisation.States[:, Localisation.X])) ax.draw_artist(particleplot) #ax.draw_artist(estimateplot) canvas.blit(ax.bbox) time.sleep(max(0, 0.1 - (time.time() - starttime))) wx.WakeUpIdle()
def update_line(*args): global blit_time if update_line.background is None: update_line.background = canvas.copy_from_bbox(ax.bbox) # restore the clean slate background canvas.restore_region(update_line.background) # update the data line.set_ydata(npy.sin(x + update_line.cnt / 10.0)) # just draw the animated artist ax.draw_artist(line) # just redraw the axes rectangle t = time.time() canvas.blit(ax.bbox) blit_time += time.time() - t if update_line.cnt == NBLITS: # print the timing info and quit frame_time = time.time() - tstart print '%d frames: %.2f seconds' % (NBLITS, frame_time) print '%d blits: %.2f seconds' % (NBLITS, blit_time) print print 'FPS: %.2f' % (NBLITS / frame_time) print 'BPS: %.2f' % (NBLITS / blit_time) sys.exit() update_line.cnt += 1 wx.WakeUpIdle()
def messageCB(self, con, msg): """Called when a message is recieved""" if msg.getBody(): ## Dont show blank messages ## print '<' + str(msg.getFrom()) + '>' + ' ' + msg.getBody() txt = msg.getBody() self._parent.msgQueue.put((msg.getFrom(), txt)) wx.WakeUpIdle()
def cleanup(): for tlw in wx.GetTopLevelWindows(): if tlw: if isinstance(tlw, wx.Dialog) and tlw.IsModal(): tlw.EndModal(0) else: tlw.Close(force=True) wx.CallAfter(tlw.Destroy) wx.WakeUpIdle()
def _cleanup(): for win in wx.GetTopLevelWindows(): if win: if isinstance(win, wx.Dialog) and win.IsModal(): win.EndModal(0) else: win.Close(force=True) wx.WakeUpIdle()
def log_message(self, format, *args): msg = "%s - - [%s] %s\n" % (self.address_string(), self.log_date_time_string(), format % args) if format.startswith('"%s"'): self.server._notify_window.msgQueue.put(msg) wx.WakeUpIdle() # just log to the GUI now, this could go to a file as well else: # don't put CGI error and exit status messages in the main log print msg
def onTimerTick(self, event): cur_pos, end_pos = self.contentTextCtrl.GetInsertionPoint(), self.contentTextCtrl.GetLastPosition() if not end_pos: return if cur_pos == end_pos: wx.WakeUpIdle() if (time.perf_counter() - self._last_page_turn) < 0.9: return self._nav_provider.navigate_to_page("next") self._last_page_turn = time.perf_counter()
def __init__(self, parent, id): pydirctrl.PyDirCtrl.__init__(self, parent, id, initialDir="/mnt/flac") self.frame = parent self.id = id # wx.EVT_TREE_BEGIN_DRAG(self, self.id, self.OnBeginDrag) wx.EVT_TREE_SEL_CHANGED(self, self.id, self.OnSelChanged) # wx.EVT_RIGHT_DOWN(self, self.OnRightDown) # wx.EVT_MENU(self, self.menuRefreshId, self.OnRefresh) # wx.PostEvent(self.frame, events.ShowDirectoryEvent(config.persistDirControlPath)) wx.WakeUpIdle()
def execute(self, cmd): self.process = wx.Process(self.handler) self.process.Redirect() self.pid = wx.Execute(cmd, wx.EXEC_NOHIDE, self.process) self.inputStream = self.process.GetOutputStream() self.errorStream = self.process.GetErrorStream() self.outputStream = self.process.GetInputStream() #self.OnIdle() wx.WakeUpIdle()
def sendPendingEvents(self): """ Send any events due for playback to the main thread """ for seq in self.sequences: ev_found = True while ev_found is True: ev = seq.getNextByTime() if isinstance(ev, parclasses.ControlEvent): self.ev_q.put(ev) wx.WakeUpIdle() else: if ev == True and self.out_q: self.out_q.put("stopped|" + seq.name) ev_found = False
def _wx_callback(cls, *args): out = [] for ppp in cls.autoupdate: if pl.fignum_exists(ppp.figure.number): res = ppp.update() if res: out.append(res) else: cls.autoupdate.remove(ppp) if out and hasattr(cls, 'on_update'): for ppp in out: cls.on_update(ppp) wx.WakeUpIdle()
def __call__(self, event_queue, in_queue, out_queue): """ called as a target of a threaded.Thread object, this will run the sequencing functions, communicating through the queues """ running = True self.in_q = in_queue # command received from the main thread self.out_q = out_queue # responses, commands to the main thread self.ev_q = event_queue # return pending events to the main thread shutdown = False self.light_state = False # current state of beat light # send first beat light message if self.btic.BeatLight() is True: self.out_q.put("beaton") else: self.out_q.put("beatoff") # run thread loop while running is True: if self.die_pending is False: self.sendPendingEvents() self.processCommands() """ if self.btic.BeatLightToggle() == True: self.out_q.put("beat") wx.WakeUpIdle() """ # display beat light on UI light = self.btic.BeatLight() if light != self.light_state: self.light_state = light if light is True: self.out_q.put("beatoff") else: self.out_q.put("beaton") wx.WakeUpIdle() if self.allClear() is True: time.sleep(.01) #pass else: # stop the loop/thread when all is cleaned up self.sendPendingEvents() if self.allClear() is True: self.clearBank() self.die_pending = False running = False else: time.sleep(.01)
def onSize(self, event): wp = WindowProperties() wp.setSize(*self.GetClientSize()) self.win.requestProperties(wp) # Apparently, sometimes on Linux we get the onSize event # before the size has actually changed, and the size we # report in GetClientSize() is the *previous* size. To # work around this unfortunate circumstance, we'll also # ensure an idle event comes in later, and check the size # again then. wx.WakeUpIdle() event.Skip()
def loadBank(self, bank_name): """ Loads all sequences found in a folder. Bank_name is a subfolder under the folder name """ result = False if self.allClear() == True: self.bank_load_pending = False self.next_bank = "" # load default bank? if self.autoload == True: for filename in os.listdir(self.seq_dir): parts = filename.rpartition('.') if parts[2] == "seqx": #path = self.seq_dir + "\\" + filename path = str(self.seq_dir + filename) # casting to str fixes win2k bug print filename seq = parclasses.ControlList(path) seq.name = parts[0] self.sequences.append(seq) if (self.out_q): self.out_q.put("newseq|" + parts[0]) wx.WakeUpIdle() result = True # load the selected bank if len(bank_name) > 0: #folder = self.seq_dir + "\\" + bank_name folder = self.seq_dir + bank_name for filename in os.listdir(folder): parts = filename.rpartition('.') if parts[2] == "seqx": path = str(folder + "\\" + filename) # casting to str fixes win2k bug print filename seq = parclasses.ControlList(path) seq.name = parts[0] seq.stop() # force a stop condition self.sequences.append(seq) if (self.out_q): self.out_q.put("newseq|" + parts[0]) result = True else: self.stop() return result
def DispatchEvent(self, callback, *args): """"Queue a net event to be handled on the GUI thread. Many wxPython functions do not work when invoked from a thread other than the main GUI thread. This is a problem for network events, because they occur during the listen thread that was spawned by simClient.py. The solution is to register a meta-callback, this method, with the network model. When DispatchEvent is invoked by the network model, it puts the original GUI callback, along with the arguments, on self.queue and then calls wx.WakeUpIdle(). This causes OnIdle to be invoked on the main GUI thread, which in turn invokes every callback that is on the queue, and these callbacks can invoke wxPython functions without fear of being on the wrong thread. This greatly simplifies the implementation of the callbacks (trust me).""" self.queue.put((callback, args)) # Cause an idle event to occur, which will invoke our idle handler. wx.WakeUpIdle()
def updateRosterDisplay(self): roster = self.roster items = {} for key in roster: jid = str(key) status = roster[key][0].lower() show = roster[key][1] if show is None: show = "" else: # I noticed that some clients might let in a CR/LF on the end # so might as well get rid of leading and trailing whitespace show = show.strip() items[jid] = (status, show) self._parent.rosterQueue.put((None, items)) wx.WakeUpIdle() """
def OnScreenshotTimer(self): oldpos = self.Parent.Position try: top = self.Top top.Move((-top.Size.width - 50, -top.Size.height - 50)) wx.BeginBusyCursor() wx.WakeUpIdle() wx.MilliSleep(500) global num_screenshots num_screenshots += 1 log.info('taking screenshot %d', num_screenshots) screen_full, screen = app_windows_image() diag = ScreenshotDialog(self, screen_full, screen, pos=oldpos + Point(40, 40)) except: print_exc() screen = None finally: wx.EndBusyCursor() self.Top.Move(oldpos) if screen is None: return try: if diag.ShowModal() == wx.ID_OK: self.screenshot = diag.SelectedScreenshot self.screenshot_link.Label = _("Remove Screenshot") else: self.screenshot_link.Label = _('Take Screenshot') finally: diag.Destroy() self.Layout() self.Refresh()
def server(self): # make a TCP socket object sockobj = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # bind it to server port number sockobj.bind((myHost, myPort)) # listen, allow 5 pending connects sockobj.listen(5) # listen until process killed while self.keepRunning: #print 'outer loop' connection, address = sockobj.accept( ) # wait for next client connect #print 'Server connected by', address # connection is a new socket while self.keepRunning: #print 'inner loop' # read next line on client socket data = connection.recv(1024) if not data: break self._parent.msgQueue.put(data) wx.WakeUpIdle() connection.close()
def idleWatchdog(self, evt): wx.WakeUpIdle()
def onIdle(self, event): if self.needs_resize: self.figureCanvas.SetSize(self.plotPanel.GetSize()) self.needs_resize = False wx.WakeUpIdle()
def _cleanup(): for tlw in wx.GetTopLevelWindows(): if tlw: # tlw.Close(force=True) tlw.Destroy() wx.WakeUpIdle()
def RefreshListCtrl(self): self.f_refresh_listctrl = True wx.WakeUpIdle()
def _cleanup(): for tlw in wx.GetTopLevelWindows(): if tlw: tlw.Destroy() wx.WakeUpIdle()
def WakeUp(self): wx.WakeUpIdle()
def destroy(self, *args): if self.isdestory is False: dp.send('frame.delete_panel', panel=self) wx.WakeUpIdle()
def presenceCB(self, con, prs): """Called when a presence is recieved""" who = str(prs.getFrom()) type = prs.getType() if type is None: type = 'available' txt = None # subscription request: # - accept their subscription # - send request for subscription to their presence if type == 'subscribe': print "subscribe request from %s" % (who) con.send(jabber.Presence(to=who, type='subscribed')) con.send(jabber.Presence(to=who, type='subscribe')) txt = "subscribe request from %s" % (who) # unsubscription request: # - accept their unsubscription # - send request for unsubscription to their presence elif type == 'unsubscribe': print "unsubscribe request from %s" % (who) con.send(jabber.Presence(to=who, type='unsubscribed')) con.send(jabber.Presence(to=who, type='unsubscribe')) txt = "unsubscribe request from %s" % (who) elif type == 'subscribed': print "we are now subscribed to %s" % (who) txt = "we are now subscribed to %s" % (who) elif type == 'unsubscribed': print "we are now unsubscribed to %s" % (who) txt = "we are now unsubscribed to %s" % (who) elif type == 'available': print "%s is available (%s / %s)" % (who, prs.getShow(), prs.getStatus()) txt = "%s is available (%s / %s)" % (who, prs.getShow(), prs.getStatus()) # who is of the form 'username@domain/resource' jid = str(who.split('/')[0]) # KEA 2002-11-30 # should presences for the same jid such as [email protected]/Exodus # and [email protected]/default be treated separately? # for now, skip duplicate jids for both # available and unavailable # # I'm not showing gateways either # and still need to figure out the proper handling # of them if '@' in jid and jid != self.shortJID: if jid in self.groupchatJIDS: nickname = str(who.split('/')[1]) print "*******GROUPCHAT", jid, who, prs.getStatus( ), prs.getShow() self.groupchatJIDS[jid][nickname] = (prs.getStatus(), prs.getShow()) self._parent.rosterQueue.put( (jid, self.groupchatJIDS[jid])) wx.WakeUpIdle() else: self.roster[jid] = [ 'online', prs.getStatus(), prs.getShow() ] self.updateRosterDisplay() elif type == 'unavailable': print "%s is unavailable (%s / %s)" % (who, prs.getShow(), prs.getStatus()) txt = "%s is unavailable (%s / %s)" % (who, prs.getShow(), prs.getStatus()) # who is of the form 'username@domain/resource' jid = str(who.split('/')[0]) if '@' in jid and jid != self.shortJID: if jid in self.groupchatJIDS: nickname = str(who.split('/')[1]) print "*******GROUPCHAT", jid, who, prs.getStatus( ), prs.getShow() try: del self.groupchatJIDS[jid][nickname] self._parent.rosterQueue.put( (jid, self.groupchatJIDS[jid])) wx.WakeUpIdle() except: pass else: self.roster[jid] = [ 'offline', prs.getStatus(), prs.getShow() ] self.updateRosterDisplay() if txt is not None: # need to decide whether we want a separate queue for # status messages, for now just let the messages be # printed to the console #self._parent.msgQueue.put(txt) #wx.WakeUpIdle() pass
def Destroy(self): map(lambda x: x.Close(), filter(lambda x: isinstance(x, wx.Frame), self.GetChildren())) wx.WakeUpIdle() #print 'destroying MainWindow' super(wx.Frame, self).Destroy()
def destroy(self, *args): self.frame.Destroy() self.canvas.Destroy() import wx wx.WakeUpIdle()
def callback(*args): H.set_array(pylab.random((10,10))) pylab.draw() wx.WakeUpIdle() # ensure that the idle event keeps firing