Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import wx
- import wx.calendar
- import wx.grid
- import inspect
- ########################################################################
- class MyPanel(wx.Panel):
- def __init__(self, parent):
- wx.Panel.__init__(self, parent)
- self.button = wx.Button(self, -1, "Button")
- self.checkbox = wx.CheckBox(self, -1, "Checkbox")
- self.calendar_ctrl = wx.calendar.CalendarCtrl(self, -1)
- self.grid = wx.grid.Grid(self, -1, size=(1, 1))
- self.choice = wx.Choice(self, -1, choices=["One", "Two", "Three"])
- self.listbox = wx.ListBox(self, -1, choices=["One", "Two", "Three"])
- self.SetProperties()
- self.DoLayout()
- self.BindEvents()
- def BindEvents(self):
- self.Bind(wx.EVT_BUTTON, self.OnEvent, self.button)
- self.Bind(wx.EVT_CHECKBOX, self.OnEvent, self.checkbox)
- self.Bind(wx.calendar.EVT_CALENDAR_WEEKDAY_CLICKED, self.OnEvent, self.calendar_ctrl)
- self.Bind(wx.calendar.EVT_CALENDAR_YEAR, self.OnEvent, self.calendar_ctrl)
- self.Bind(wx.calendar.EVT_CALENDAR, self.OnEvent, self.calendar_ctrl)
- self.Bind(wx.calendar.EVT_CALENDAR_MONTH, self.OnEvent, self.calendar_ctrl)
- self.Bind(wx.calendar.EVT_CALENDAR_DAY, self.OnEvent, self.calendar_ctrl)
- self.Bind(wx.grid.EVT_GRID_CMD_CELL_CHANGE, self.OnEvent, self.grid)
- self.Bind(wx.grid.EVT_GRID_CMD_CELL_RIGHT_DCLICK, self.OnEvent, self.grid)
- self.Bind(wx.grid.EVT_GRID_CMD_CELL_LEFT_CLICK, self.OnEvent, self.grid)
- self.Bind(wx.grid.EVT_GRID_CMD_COL_SIZE, self.OnEvent, self.grid)
- self.Bind(wx.grid.EVT_GRID_CMD_ROW_SIZE, self.OnEvent, self.grid)
- self.Bind(wx.grid.EVT_GRID_CMD_SELECT_CELL, self.OnEvent, self.grid)
- self.Bind(wx.grid.EVT_GRID_CMD_CELL_LEFT_DCLICK, self.OnEvent, self.grid)
- self.Bind(wx.grid.EVT_GRID_CMD_CELL_RIGHT_CLICK, self.OnEvent, self.grid)
- self.Bind(wx.EVT_CHOICE, self.OnEvent, self.choice)
- self.Bind(wx.EVT_LISTBOX_DCLICK, self.OnEvent, self.listbox)
- self.Bind(wx.EVT_LISTBOX, self.OnEvent, self.listbox)
- self.Bind(wx.EVT_LEFT_DCLICK, self.OnEvent)
- self.Bind(wx.EVT_RIGHT_DOWN, self.OnEvent)
- def SetProperties(self):
- self.grid.CreateGrid(10, 3)
- self.choice.SetSelection(0)
- self.listbox.SetSelection(0)
- def DoLayout(self):
- flag = wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL
- grid_sizer = wx.GridSizer(3, 3, 0, 0)
- grid_sizer.Add(self.button, 0, flag, 0)
- grid_sizer.Add(self.checkbox, 0, flag, 0)
- grid_sizer.Add(self.calendar_ctrl, 0, flag, 0)
- grid_sizer.Add(self.grid, 1, wx.EXPAND|flag, 0)
- grid_sizer.Add(self.choice, 0, flag, 0)
- grid_sizer.Add(self.listbox, 0, flag, 0)
- self.SetSizer(grid_sizer)
- grid_sizer.Fit(self)
- #----------------------------------------------------------------------
- def OnEvent(self, event):
- """
- Print out what event was fired
- """
- widget = event.GetEventObject()
- eventId = event.GetEventType()
- self.HuntEvent(widget, eventId)
- def HuntEvent(self, widget, eventId):
- moduleStr = widget.__module__
- if "__main__" in moduleStr:
- classes = inspect.getmro(self.__class__)
- moduleStr = str(classes[1])
- if "._core" in moduleStr or "._windows" in moduleStr or \
- "._controls" in moduleStr:
- module = __import__("wx")
- else:
- local = moduleStr.replace("wx.", "")
- module = __import__(moduleStr, fromlist=local)
- evtNames = [x for x in dir(module) if x.startswith("EVT_")]
- printStr = "You got event %-30s id = %5d, module = %s"
- for name in evtNames:
- evt = getattr(module, name)
- if not isinstance(evt, wx.PyEventBinder):
- continue
- if evt.typeId == eventId:
- print printStr%(name+":", eventId, moduleStr)
- break
- class MyForm(wx.Frame):
- #----------------------------------------------------------------------
- def __init__(self):
- wx.Frame.__init__(self, None, size=(600, 500), title="Tutorial 2")
- # Add a panel so it looks the correct on all platforms
- panel = MyPanel(self)
- #----------------------------------------------------------------------
- # Run the program
- if __name__ == "__main__":
- app = wx.App(False)
- frame = MyForm().Show()
- app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement