我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用wx.EVT_CHAR。
def BindEvents(self): self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_ERASE_BACKGROUND, lambda e: None) self.Bind(wx.EVT_RIGHT_DOWN, self.OnButtonDown) self.Bind(wx.EVT_LEFT_DOWN, self.OnButtonDown) self.Bind(wx.EVT_MIDDLE_DOWN, self.OnButtonDown) self.Bind(wx.EVT_RIGHT_UP, self.OnButtonUp) self.Bind(wx.EVT_LEFT_UP, self.OnButtonUp) self.Bind(wx.EVT_MIDDLE_UP, self.OnButtonUp) self.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel) self.Bind(wx.EVT_MOTION, self.OnMotion) self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnter) self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave) self.Bind(wx.EVT_CHAR, self.OnKeyDown) self.Bind(wx.EVT_KEY_UP, self.OnKeyUp) if wx.Platform == "__WXGTK__": # wxGTK requires that the window be created before you can # set its shape, so delay the call to SetWindowShape until # this event. self.Bind(wx.EVT_WINDOW_CREATE, self.OnWindowCreate) else: # On wxMSW and wxMac the window has already been created. self.Bind(wx.EVT_SIZE, self.OnSize) if _useCapture and hasattr(wx, 'EVT_MOUSE_CAPTURE_LOST'): self.Bind(wx.EVT_MOUSE_CAPTURE_LOST, self.OnMouseCaptureLost)
def _bindEvents(self): """ Binding events to the gui widgets. """ wx.EVT_BUTTON(self, self.buttonPing.GetId(), self.OnPing) wx.EVT_BUTTON(self, self.buttonUpdate.GetId(), self.OnUpdate) wx.EVT_BUTTON(self, self.buttonClose.GetId(), self.OnClose) wx.EVT_BUTTON(self, self.buttonDeleteGroup.GetId(), self.OnDeleteGroup) wx.EVT_BUTTON(self, self.buttonCreateGroup.GetId(), self.OnCreateGroup) wx.EVT_BUTTON(self, self.buttonDeleteSelected.GetId(), self.OnDelete) wx.EVT_BUTTON(self, self.buttonRegisterItem.GetId(), self.OnRegisterItem) wx.EVT_BUTTON(self, self.buttonShowMeta.GetId(), self.OnShowMeta) wx.EVT_BUTTON(self, self.buttonSetMeta.GetId(), self.OnSetMeta) wx.EVT_TEXT_ENTER(self, self.txtCtrlNSHost.GetId(), self.OnCheckNS) wx.EVT_TEXT_ENTER(self, self.txtCtrlNSPort.GetId(), self.OnCheckNS) wx.EVT_CHAR(self.treeCtrlItems, self.OnKeyPressed)
def __init__(self, parent): wx.Panel.__init__(self, parent, -1) # ????? self.response_text = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE) response_sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Response")) response_sizer.Add(self.response_text, 1, wx.EXPAND) # ??????? self.doc_text = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE | wx.TE_READONLY) doc_sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Document")) doc_sizer.Add(self.doc_text, 1, wx.EXPAND) main_box = wx.BoxSizer(wx.VERTICAL) main_box.Add(response_sizer, 1, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 5) main_box.Add(doc_sizer, 1, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 5) self.SetSizer(main_box) self.response_text.Bind(wx.EVT_CHAR, self.on_key_down) self.doc_text.Bind(wx.EVT_CHAR, self.on_key_down)
def __init__(self, charmap=None, minlength=None, maxlength=None): wx.PyValidator.__init__(self) self.charmap = charmap self.minlength = minlength self.maxlength = maxlength wx.EVT_CHAR(self, self.OnChar)
def init_gl(self): print('creating Frame') self.window = wx.Frame ( parent=None, id=wx.ID_ANY, title=self.title, style=wx.DEFAULT_FRAME_STYLE|wx.WS_EX_PROCESS_IDLE ) print('creating GLCanvas') self.canvas = glcanvas.GLCanvas ( self.window, glcanvas.WX_GL_RGBA ) print('creating GLContext') self.context = glcanvas.GLContext(self.canvas) self.canvas.SetFocus() self.window.SetSize ( (self.renderer.window_size[0], self.renderer.window_size[1]) ) print('showing Frame') self.window.Show(True) print('calling SetTopWindow') self.SetTopWindow(self.window) self.Bind ( wx.EVT_CHAR, self.OnChar ) self.canvas.Bind ( wx.EVT_SIZE, self.OnCanvasSize ) self.canvas.Bind ( wx.EVT_PAINT, self.OnCanvasPaint ) wx.IdleEvent.SetMode ( wx.IDLE_PROCESS_SPECIFIED ) self.Bind ( wx.EVT_IDLE, self.OnIdle ) print('making context current') self.canvas.SetCurrent ( self.context ) self.renderer.init_gl()
def __init__(self, parent, title): style = wx.DEFAULT_FRAME_STYLE & ~( wx.RESIZE_BORDER | wx.MAXIMIZE_BOX | wx.MINIMIZE_BOX|wx.CLOSE_BOX) wx.Frame.__init__(self, parent, title=title, style=style, size=(400,60)) self.textbox = wx.TextCtrl(self) img = wx.Image("matags.png", wx.BITMAP_TYPE_ANY) bmp = wx.Bitmap(img) self.icon = wx.Icon() self.icon.CopyFromBitmap(bmp) self.SetIcon(self.icon) self.tbIcon = wx.adv.TaskBarIcon() self.tbIcon.SetIcon(self.icon) self.Show(True) self.Centre() self.reg_hot_keys() self.Bind(wx.EVT_HOTKEY, self.on_extract_tag, id=self.hotkeys['extract_tag'][0]) self.Bind(wx.EVT_HOTKEY, self.on_close, id=self.hotkeys['quit'][0]) self.Bind(wx.EVT_HOTKEY, self.on_activate, id=self.hotkeys['activate'][0]) self.Bind(wx.EVT_HOTKEY, self.on_refresh, id=self.hotkeys['refresh'][0]) self.textbox.Bind(wx.EVT_CHAR, self.check_key) # do not use EVT_KEY_DOWN, # it becomes difficult to get lower case # self.textbox.Bind(wx.EVT_KEY_DOWN, self.check_key) # self.Bind(wx.EVT_CLOSE, self.on_close) self.Bind(wx.EVT_ICONIZE, self.on_iconify) self.matags = MaTags() # try: # except Exception as e: # self.textbox.ChangeValue(e.args[0].decode('utf8', 'ignore')) # self.textbox.Disable()
def InitUI(self): # these need to be set by whoever calls the dialog box before it's created device = config_ctrl_pnl.device_toedit gpio = config_ctrl_pnl.gpio_toedit wiring = config_ctrl_pnl.wiring_toedit # draw the pannel pnl = wx.Panel(self) wx.StaticText(self, label='Device GPIO Config', pos=(20, 10)) #background image png = wx.Image('./relaydialogue.png', wx.BITMAP_TYPE_ANY).ConvertToBitmap() wx.StaticBitmap(self, -1, png, (0, 0), (png.GetWidth(), png.GetHeight())) # devices combo box switch_list = self.list_switch_scripts() unlinked_devices = self.list_unused_devices(switch_list) wx.StaticText(self, label='Device;', pos=(20, 50)) self.devices_combo = wx.ComboBox(self, choices = unlinked_devices, pos=(90,50), size=(175, 25)) self.devices_combo.SetValue(device) # gpio text box wx.StaticText(self, label='GPIO', pos=(10, 100)) self.gpio_tc = wx.TextCtrl(self, pos=(56, 98), size=(40, 25)) self.gpio_tc.SetValue(gpio) self.gpio_tc.Bind(wx.EVT_CHAR, self.onChar) #limit to valid gpio numbers # wiring direction combo box wiring_choices = ['low', 'high'] wx.StaticText(self, label='Wiring side;', pos=(100, 100)) self.wiring_combo = wx.ComboBox(self, choices = wiring_choices, pos=(200,98), size=(110, 25)) self.wiring_combo.SetValue(wiring) #Buttom Row of Buttons okButton = wx.Button(self, label='Ok', pos=(200, 250)) closeButton = wx.Button(self, label='Cancel', pos=(300, 250)) okButton.Bind(wx.EVT_BUTTON, self.set_new_gpio_link) closeButton.Bind(wx.EVT_BUTTON, self.OnClose)
def __attach_events(self): # register events at the controls self.Bind(wx.EVT_MENU, self.OnClear, id=ID_CLEAR) self.Bind(wx.EVT_MENU, self.OnSaveAs, id=ID_SAVEAS) self.Bind(wx.EVT_MENU, self.OnExit, id=ID_EXIT) self.Bind(wx.EVT_MENU, self.OnPortSettings, id=ID_SETTINGS) self.Bind(wx.EVT_MENU, self.OnTermSettings, id=ID_TERM) self.text_ctrl_output.Bind(wx.EVT_CHAR, self.OnKey) self.Bind(EVT_SERIALRX, self.OnSerialRead) self.Bind(wx.EVT_CLOSE, self.OnClose)
def __attach_events(self): #register events at the controls self.Bind(wx.EVT_MENU, self.OnClear, id = ID_CLEAR) self.Bind(wx.EVT_MENU, self.OnSaveAs, id = ID_SAVEAS) self.Bind(wx.EVT_MENU, self.OnExit, id = ID_EXIT) self.Bind(wx.EVT_MENU, self.OnPortSettings, id = ID_SETTINGS) self.Bind(wx.EVT_MENU, self.OnTermSettings, id = ID_TERM) self.text_ctrl_output.Bind(wx.EVT_CHAR, self.OnKey) self.Bind(EVT_SERIALRX, self.OnSerialRead) self.Bind(wx.EVT_CLOSE, self.OnClose)
def __init__(self): wx.Frame.__init__(self, None, title="Char Event Tutorial") # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) btn = wx.TextCtrl(panel, value="") btn.Bind(wx.EVT_CHAR, self.onCharEvent)
def __init__(self, parent=None): wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( -1,-1 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL ) logopath = os.path.join(root_dir, 'data/logo.ico') self.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_3DLIGHT ) ) self.SetIcon(wx.Icon(logopath, wx.BITMAP_TYPE_ICO)) self.SetSizeHints( wx.Size( 560,-1 ), wx.DefaultSize ) WindowsManager.add(self) print('frame added') self.SetSizeHints( wx.DefaultSize, wx.DefaultSize ) self.SetBackgroundColour( wx.Colour( 255, 255, 255 ) ) sizer = wx.BoxSizer( wx.VERTICAL ) self.txt_info = wx.StaticText( self, wx.ID_ANY, '500*500 pixels 173k', wx.DefaultPosition, wx.DefaultSize, 0 ) self.txt_info.Wrap( -1 ) sizer.Add( self.txt_info, 0, wx.ALL, 0 ) self.canvas = Canvas(self) self.canvas.fit = self sizer.Add( self.canvas, 1, wx.EXPAND |wx.ALL, 0 ) self.page = wx.ScrollBar( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.SB_HORIZONTAL) self.page.SetScrollbar(0,0,0,0, refresh=True) sizer.Add( self.page, 0, wx.ALL|wx.EXPAND, 0 ) #self.page.Hide() self.SetSizer(sizer) self.Layout() self.Bind(wx.EVT_IDLE, self.on_idle) self.Bind(wx.EVT_SCROLL, self.on_scroll) self.Bind(wx.EVT_ACTIVATE, self.on_valid) self.Bind(wx.EVT_CLOSE, self.on_close) self.canvas.Bind(wx.EVT_CHAR, self.on_key) self.canvas.SetFocus() # panel.Bind(wx.EVT_CHAR, self.OnKeyDown) self.opage = 0 self.Fit() self.SetAcceleratorTable(IPy.curapp.shortcut)