我们从Python开源项目中,提取了以下32个代码示例,用于说明如何使用wx.PostEvent()。
def OnKeyUp(self, event): event.Skip() if not self.selectedNode or not self.hot_map: return if event.KeyCode == wx.WXK_HOME: self.SetSelected(HotMapNavigator.firstNode(self.hot_map)) return elif event.KeyCode == wx.WXK_END: self.SetSelected(HotMapNavigator.lastNode(self.hot_map)) return parent, children, index = HotMapNavigator.findNode(self.hot_map, self.selectedNode) if event.KeyCode == wx.WXK_DOWN: self.SetSelected(HotMapNavigator.nextChild(children, index)) elif event.KeyCode == wx.WXK_UP: self.SetSelected(HotMapNavigator.previousChild(children, index)) elif event.KeyCode == wx.WXK_RIGHT: self.SetSelected(HotMapNavigator.firstChild(children, index)) elif event.KeyCode == wx.WXK_LEFT and parent: self.SetSelected(parent) elif event.KeyCode == wx.WXK_RETURN: wx.PostEvent(self, SquareActivationEvent(node=self.selectedNode, map=self))
def onDNSEvent(self, event): if self.proxy_master is not None: self.proxy_master.shutdown() if event.message.startswith('api-na'): region = 'NA' else: region = 'JP' config = wx.ConfigBase.Get() host = config.Read("host") or socket.gethostbyname(socket.gethostname()) httpsport = config.Read("httpsport") or "443" try: proxy_config = proxy.ProxyConfig(port=int(httpsport), host=host, mode='reverse', upstream_server=cmdline.parse_server_spec('https://%s:443/' % event.message)) proxy_server = ProxyServer(proxy_config) except Exception as e: evt = custom_events.wxStatusEvent(message='Error starting HTTPS proxy: %s' % e) wx.PostEvent(self.main_tab, evt) return self.proxy_master = PadMaster(proxy_server, self, region) thread.start_new_thread(self.proxy_master.run, ())
def is_out_of_date(main_tab): session = requests.Session() session.headers = { 'accept': 'application/vnd.github.v3+json', 'user-agent': 'jgoldshlag-padherder_sync_' + PH_PROXY_VERSION, } session.mount('https://', requests.adapters.HTTPAdapter(pool_connections=1, pool_maxsize=1)) try: r = session.get('https://api.github.com/repos/jgoldshlag/padherder_proxy/releases') except Exception as e: evt = custom_events.wxStatusEvent(message='Error checking for updates: %s' % e) wx.PostEvent(main_tab, evt) if r.status_code != requests.codes.ok: evt = custom_events.wxStatusEvent(message='Error checking for updates: %s %s' % (r.status_code, r.content)) wx.PostEvent(main_tab, evt) releases = json.loads(r.content) current_ver = LooseVersion(PH_PROXY_VERSION) for rel in releases: rel_version = LooseVersion(rel['tag_name'][1:]) if rel_version > current_ver: return True return False
def resolve(self,request,handler): reply = request.reply() qname = request.q.qname qtype = QTYPE[request.q.qtype] if qname.matchGlob("api-*padsv.gungho.jp."): config = wx.ConfigBase.Get() host = config.Read("host") or socket.gethostbyname(socket.gethostname()) reply.add_answer(RR(qname,QTYPE.A,rdata=A(host))) evt = custom_events.wxStatusEvent(message="Got DNS Request") wx.PostEvent(self.status_ctrl,evt) evt = custom_events.wxDNSEvent(message=str(qname)[:-1]) wx.PostEvent(self.main_frame,evt) time.sleep(0.5) # we need to sleep until the proxy is up, half a second should do it... # Otherwise proxy if not reply.rr: if handler.protocol == 'udp': proxy_r = request.send(self.address,self.port) else: proxy_r = request.send(self.address,self.port,tcp=True) reply = DNSRecord.parse(proxy_r) return reply
def OnReadComplete(self): evt = ResultEvent(self._log_analyzer.msg_logs) wx.PostEvent(wx.GetApp().frame, evt)
def onKeyUp(self, event): """Handle keypress events. """ key = event.GetKeyCode() # check for F11 to start full screen mode if key == wx.WXK_F11: # post a an EVT_FULL_SCREEN event # the change should be handled by the parent wx.PostEvent(self, events.FullScreenEvent(id=wx.ID_ANY))
def setSource(self, srcName): self.src.delBuffer() # buffer is only active for current source self.src = self.sources[srcName] self.src.initBuffer() self.updateSources() if self.statusPanel is not None: wx.PostEvent(self.statusPanel, events.UpdateStatusEvent(id=wx.ID_ANY))
def addRunningPage(self, page): """Add a page and start current source if when number of running pages goes above zero. """ if self.getNRunningPages() == 0: self.src.start() self.runningPages.append(page) if self.statusPanel is not None: wx.PostEvent(self.statusPanel, events.UpdateStatusEvent(id=wx.ID_ANY))
def remRunningPage(self, page): """Remove a page and stop current source if number of running pages reaches zero. """ self.runningPages.remove(page) if self.getNRunningPages() == 0: self.src.stop() if self.statusPanel is not None: wx.PostEvent(self.statusPanel, events.UpdateStatusEvent(id=wx.ID_ANY))
def closeAllPages(self): # should probably be stopping sources instead of pages if this is only for cleanup? This still hangs sometimes XXX - idfah if self.getNRunningPages() > 0: for pg in self.runningPages: pg.close() self.runningPages = [] if self.statusPanel is not None: wx.PostEvent(self.statusPanel, events.UpdateStatusEvent(id=wx.ID_ANY))
def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) #self.Bind(wx.EVT_KEY_UP, self.onKeyUp) self.Bind(events.EVT_FULLSCREEN, self.toggleFullScreen) #def onKeyUp(self, event): # key = event.GetKeyCode() # if key == wx.WXK_F11: # wx.PostEvent(self, events.FullScreenEvent(id=wx.ID_ANY))
def growBar(self, choice, amount, refresh=True): """Grow a selection bar toward a menu cell. Args: choice: String name of the menu cell to grow the bar toward. amount: Floating point amount to grow the bar. Must be between 0.0 and 1.0 with 1.0 growing the bar all the way to the cell and 0.0 not growing the bar at all. Returns: True if the bar for choice meets or exceeds 1.0 and False otherwise. Events: A PieMenuSelectEvent is posted if the bar length for choice meets or exceeds 1.0. """ self.bars[choice] += amount if self.bars[choice] < 0.0: self.bars[choice] = 0.0 if refresh: self.refresh() if np.isclose(self.bars[choice], 1.0) or self.bars[choice] > 1.0: self.bars[choice] = 1.0 wx.PostEvent(self, PieMenuSelectEvent(choice=choice, id=wx.ID_ANY)) return True else: return False
def render(self): while self.running: if self.requests: request = self.requests.pop(0) # Make the CPU work for i in range(100000): pass self.counter += 1 wx.PostEvent(self.parent.log,PrintEvent("%s\n"%self.counter)) else: time.sleep(.01)
def OnDoubleClick(self, event): """Double click on a given square in the map""" node = HotMapNavigator.findNodeAtPosition(self.hot_map, event.GetPosition()) if node: wx.PostEvent( self, SquareActivationEvent( node=node, point=event.GetPosition(), map=self ) )
def OnKeyUp(self, event): event.Skip() if not self.selectedNode or not self.hot_map: return if event.KeyCode == wx.WXK_HOME: self.SetSelected(HotMapNavigator.firstNode(self.hot_map)) return elif event.KeyCode == wx.WXK_END: self.SetSelected(HotMapNavigator.lastNode(self.hot_map)) return try: parent, children, index = HotMapNavigator.findNode(self.hot_map, self.selectedNode) except TypeError: log.info( 'Unable to find hot-map record for node %s', self.selectedNode ) else: if event.KeyCode == wx.WXK_DOWN: self.SetSelected(HotMapNavigator.nextChild(children, index)) elif event.KeyCode == wx.WXK_UP: self.SetSelected(HotMapNavigator.previousChild(children, index)) elif event.KeyCode == wx.WXK_RIGHT: self.SetSelected(HotMapNavigator.firstChild(children, index)) elif event.KeyCode == wx.WXK_LEFT and parent: self.SetSelected(parent) elif event.KeyCode == wx.WXK_RETURN: wx.PostEvent(self, SquareActivationEvent(node=self.selectedNode, map=self))
def SetSelected( self, node, point=None, propagate=True ): """Set the given node selected in the square-map""" if node == self.selectedNode: return self.selectedNode = node self.UpdateDrawing() if node: wx.PostEvent( self, SquareSelectionEvent( node=node, point=point, map=self ) )
def SetHighlight( self, node, point=None, propagate=True ): """Set the currently-highlighted node""" if node == self.highlightedNode: return self.highlightedNode = node # TODO: restrict refresh to the squares for previous node and new node... self.UpdateDrawing() if node and propagate: wx.PostEvent( self, SquareHighlightEvent( node=node, point=point, map=self ) )
def post_string_event(self, eventtype, eventval, panel): """ Triggers an event """ event = wx.PyCommandEvent(eventtype.typeId, panel.GetId()) event.SetString(str(eventval)) wx.PostEvent(self.GetEventHandler(),event)
def post_slide_event(self,eventval): """ Updated positions triggers an event to let the parent know scroll position has been changed """ event = wx.PyCommandEvent(wx.EVT_COMMAND_SCROLL_CHANGED.typeId, self.GetId()) event.SetInt(eventval) wx.PostEvent(self.GetEventHandler(),event)
def set_template(self): template = self._entities[self._selected_index].template event = EntityPicker.PickEvent(template=template) wx.PostEvent(self.GetEventHandler(), event)
def mouse_left_up(self, event): if not self._tilemap: return if not self._select_end: return x1, y1 = self._select_start x2, y2 = self._select_end if x2 < x1: x2, x1 = x1, x2 if y2 < y1: y2, y1 = y1, y2 width = x2 - x1 + 1 height = y2 - y1 + 1 self._select_start = None self._select_end = None self.Viewport.Refresh(False) if width and height: selection = Tilemap.from_tilemap(self._tilemap, x1, y1, x2 + 1, y2 + 1) else: selection = None event = TileSelector.SelectEvent(selection=selection) wx.PostEvent(self.GetEventHandler(), event)
def OnLinkClicked(self, linkinfo): wx.PostEvent(self, HtmlWindowUrlClick(linkinfo))
def SetSelected( self, node, point=None, propagate=True ): """Set the given node selected in the square-map""" if node == self.selectedNode: return self.selectedNode = node self.Refresh() if node: wx.PostEvent( self, SquareSelectionEvent( node=node, point=point, map=self ) )
def SetHighlight( self, node, point=None, propagate=True ): """Set the currently-highlighted node""" if node == self.highlightedNode: return self.highlightedNode = node self.Refresh() if node and propagate: wx.PostEvent( self, SquareHighlightEvent( node=node, point=point, map=self ) )
def OnNodeActivated(self, event): """We have double-clicked for hit enter on a node refocus squaremap to this node""" try: node = self.sorted[event.GetIndex()] except IndexError, err: log.warn(_('Invalid index in node activated: %(index)s'), index=event.GetIndex()) else: wx.PostEvent( self, squaremap.SquareActivationEvent(node=node, point=None, map=None) )
def OnMouseMove(self, event): point = event.GetPosition() item, where = self.HitTest(point) if item > -1: try: node = self.sorted[item] except IndexError, err: log.warn(_('Invalid index in mouse move: %(index)s'), index=event.GetIndex()) else: wx.PostEvent( self, squaremap.SquareHighlightEvent(node=node, point=point, map=None) )
def run(self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range(6): time.sleep(10) amtOfTime = (i + 1) * 10 wx.PostEvent(self.wxObject, ResultEvent(amtOfTime)) time.sleep(5) wx.PostEvent(self.wxObject, ResultEvent("Thread finished!"))
def add_status_msg(msg, status_ctrl, simulate): if status_ctrl and not simulate: evt = custom_events.wxStatusEvent(message=msg) wx.PostEvent(status_ctrl, evt) else: print msg.encode('ascii', errors='ignore')
def handle_request(self, f): if f.client_conn.ssl_established: f.request.scheme = "https" sni = f.client_conn.connection.get_servername() port = 443 else: f.request.scheme = "http" sni = None port = 80 host_header = f.request.pretty_host m = parse_host_header.match(host_header) if m: host_header = m.group("host").strip("[]") if m.group("port"): port = int(m.group("port")) f.request.host = sni or host_header f.request.port = port evt = custom_events.wxStatusEvent(message="Got HTTPS request, forwarding") wx.PostEvent(self.status_ctrl,evt) flow.FlowMaster.handle_request(self, f) if f: f.reply() return f
def main(): app = wx.App(False) if len(sys.argv) >= 2 and sys.argv[1] == '-test': config = wx.Config("padherder_proxy_test") print "In test mode" else: config = wx.Config("padherder_proxy") wx.ConfigBase.Set(config) frame = MainWindow(None, "Padherder Proxy v%s" % PH_PROXY_VERSION) host = config.Read("host") or socket.gethostbyname(socket.gethostname()) logger = dnsproxy.MyDNSLogger(frame.dns_tab) thread.start_new_thread(dnsproxy.serveDNS, (logger, frame.main_tab, frame)) try: app_config = proxy.ProxyConfig(port=8080, host=host) app_server = ProxyServer(app_config) app_master = dump.DumpMaster(app_server, dump.Options(app_host='mitm.it', app_port=80, app=True)) frame.app_master = app_master thread.start_new_thread(app_master.run, ()) except: evt = custom_events.wxStatusEvent(message='Error initalizing mitm proxy:\n' + traceback.format_exc() + '\n\nYou probably put in an incorrect IP address in Settings') wx.PostEvent(frame.main_tab, evt) app.MainLoop()
def serveDNS(logger, status_ctrl, main_frame): resolver = InterceptResolver('8.8.8.8', 53, '60s', status_ctrl, main_frame) DNSHandler.log = { 'log_request', # DNS Request 'log_reply', # DNS Response 'log_truncated', # Truncated 'log_error', # Decoding error } config = wx.ConfigBase.Get() host = config.Read("host") or socket.gethostbyname(socket.gethostname()) dnsport = config.Read("dnsport") or "53" try: udp_server = DNSServer(resolver, port=int(dnsport), address=host, logger=logger) except Exception as e: evt = custom_events.wxStatusEvent(message='Error starting DNS proxy: %s' % e) wx.PostEvent(status_ctrl,evt) return udp_server.start_thread() evt = custom_events.wxStatusEvent(message="proxy started") wx.PostEvent(status_ctrl,evt) try: while udp_server.isAlive(): time.sleep(1) except KeyboardInterrupt: sys.exit()