Python wx 模块,EVT_TOOL 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用wx.EVT_TOOL

项目:i3ColourChanger    作者:PMunch    | 项目源码 | 文件源码
def InitUI(self,config=None):
        artprovider = wx.ArtProvider()
        toolbar = self.CreateToolBar(style=wx.TB_TEXT|wx.TB_HORZ_LAYOUT)
        toolOpen = toolbar.AddTool(wx.ID_ANY, 'Open', artprovider.GetBitmap(wx.ART_FILE_OPEN,client=wx.ART_TOOLBAR),"Open an i3 config file")
        toolSave = toolbar.AddTool(wx.ID_ANY, 'Save', artprovider.GetBitmap(wx.ART_FILE_SAVE,client=wx.ART_TOOLBAR),"Save the current settings to the open file")
        toolApply = toolbar.AddTool(wx.ID_ANY, 'Apply', artprovider.GetBitmap(wx.ART_TICK_MARK,client=wx.ART_TOOLBAR),"Apply the changes without changing file")
        toolUpdateLocal = toolbar.AddTool(wx.ID_ANY, 'Save to config', artprovider.GetBitmap(wx.ART_FILE_SAVE_AS,client=wx.ART_TOOLBAR),"Save the current colour scheme into your current config")
        toolSnippet = toolbar.AddTool(wx.ID_ANY, 'Create colour snippet', artprovider.GetBitmap(wx.ART_NEW,client=wx.ART_TOOLBAR),"Save the current colour scheme as a standalone colour file you can send to others")
        toolVariable = toolbar.AddTool(wx.ID_ANY, 'Create colour variable', artprovider.GetBitmap(wx.ART_PLUS,client=wx.ART_TOOLBAR),"Create a new colour variable")
        toolbar.AddStretchableSpace()
        toolQuit = toolbar.AddTool(wx.ID_ANY, 'Quit', artprovider.GetBitmap(wx.ART_QUIT,client=wx.ART_TOOLBAR),"Quit the program")

        self.Bind(wx.EVT_TOOL, self.OnQuit,toolQuit)
        self.Bind(wx.EVT_TOOL, self.OnOpen,toolOpen)
        self.Bind(wx.EVT_TOOL, self.OnApply,toolApply)
        self.Bind(wx.EVT_TOOL, self.OnSave,toolSave)
        self.Bind(wx.EVT_TOOL, self.OnUpdateLocal,toolUpdateLocal)
        self.Bind(wx.EVT_TOOL, self.OnCreateSnippet,toolSnippet)
        self.Bind(wx.EVT_TOOL, self.OnCreateVariable,toolVariable)

        self.scrolled = wx.lib.scrolledpanel.ScrolledPanel(self,-1)
        self.scrolled.SetupScrolling()
        self.scrolled.Show()

        self.Centre()
        self.Show(True)

        if config!=None:
            self.LoadConfig(config)
项目:fritzchecksum    作者:mementum    | 项目源码 | 文件源码
def _unbindfuncs(self):
    # I would need a list of the functions that been bound to unbind them
    while True:
        try:
            widget, event, dynboundmethod = self._dynbindings.pop()
        except IndexError:
            break  # no more items in the list
        else:
            if event in [wx.EVT_MENU, wx.EVT_TOOL]:
                self.Unbind(event, handler=dynboundmethod, id=widget.GetId())
            elif event in [wx.EVT_SIZE]:
                self.Unbind(event, handler=dynboundmethod)
            else:
                widget.Unbind(event, handler=dynboundmethod)
项目:fritzchecksum    作者:mementum    | 项目源码 | 文件源码
def _bindfuncs(self):
    # wx classes throw exception if getmember is applied to the instance (self)
    methods = inspect.getmembers(self.__class__, inspect.ismethod)
    for mname, method in methods:
        dynbindings = getattr(method, '_dynbinding', None)
        if dynbindings is None:
            continue
        for dynbinding in dynbindings:
            if dynbinding:
                eventname, widgetprefix, widgetname = dynbinding
                event = getattr(wx, eventname, None)
                if event is None:
                    print 'Method', mname
                    print 'Failed to find eventname', eventname
                    continue

                name = 'm_' + widgetprefix.lower() + widgetname.lower()
                widget = None
                for attrname in dir(self):
                    if attrname.lower() == name:
                        widget = getattr(self, attrname)
                        break

                if not widget:
                    print 'Method', mname
                    print 'Failed to find widget', name
                    continue

                boundmethod = method.__get__(self, self.__class__)
                self._dynbindings.append((widget, event, boundmethod))
                if event in [wx.EVT_MENU, wx.EVT_TOOL]:
                    self.Bind(event, boundmethod, id=widget.GetId())
                elif event in [wx.EVT_SIZE]:
                    self.Bind(event, boundmethod)
                else:
                    widget.Bind(event, boundmethod)
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def AddToMenuToolBar(self, items):
        MenuToolBar = self.Panes["MenuToolBar"]
        if MenuToolBar.GetToolsCount() > 0:
            MenuToolBar.AddSeparator()
        for toolbar_item in items:
            if toolbar_item is None:
                MenuToolBar.AddSeparator()
            else:
                id, bitmap, help, callback = toolbar_item
                MenuToolBar.AddSimpleTool(id=id, shortHelpString=help, bitmap=GetBitmap(bitmap))
                if callback is not None:
                    self.Bind(wx.EVT_TOOL, callback, id=id)
        MenuToolBar.Realize()
        self.AUIManager.GetPane("MenuToolBar").BestSize(MenuToolBar.GetBestSize())
项目:LalkaChat    作者:DeForce    | 项目源码 | 文件源码
def create_tool(self, name, binding=None, style=wx.ITEM_NORMAL, s_help="", l_help=""):
        l_id = id_renew(name)
        IDS[l_id] = name
        label_text = translate_key(IDS[l_id])
        button = self.AddLabelTool(l_id, label_text, wx.NullBitmap, wx.NullBitmap,
                                   style, s_help, l_help)
        if binding:
            self.main_class.Bind(wx.EVT_TOOL, binding, id=l_id)
        return button
项目:BigBrotherBot-For-UrT43    作者:ptitbigorneau    | 项目源码 | 文件源码
def SetupToolBar(self):
        """Create the toolbar for common actions"""
        tb = self.CreateToolBar(self.TBFLAGS)
        tsize = (24, 24)
        tb.ToolBitmapSize = tsize
        open_bmp = wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR,
                                            tsize)
        tb.AddLabelTool(ID_OPEN, "Open", open_bmp, shortHelp="Open",
                        longHelp="Open a (c)Profile trace file")
        tb.AddSeparator()
#        self.Bind(wx.EVT_TOOL, self.OnOpenFile, id=ID_OPEN)
        self.rootViewTool = tb.AddLabelTool(
            ID_ROOT_VIEW, _("Root View"),
            wx.ArtProvider.GetBitmap(wx.ART_GO_HOME, wx.ART_TOOLBAR, tsize),
            shortHelp=_("Display the root of the current view tree (home view)")
        )
        self.rootViewTool = tb.AddLabelTool(
            ID_BACK_VIEW, _("Back"),
            wx.ArtProvider.GetBitmap(wx.ART_GO_BACK, wx.ART_TOOLBAR, tsize),
            shortHelp=_("Back to the previously activated node in the call tree")
        )
        self.upViewTool = tb.AddLabelTool(
            ID_UP_VIEW, _("Up"),
            wx.ArtProvider.GetBitmap(wx.ART_GO_UP, wx.ART_TOOLBAR, tsize),
            shortHelp=_("Go one level up the call tree (highest-percentage parent)")
        )
        tb.AddSeparator()
        # TODO: figure out why the control is sizing the label incorrectly on Linux
        self.percentageViewTool = wx.CheckBox(tb, -1, _("Percent    "))
        self.percentageViewTool.SetToolTip(wx.ToolTip(
            _("Toggle display of percentages in list views")))
        tb.AddControl(self.percentageViewTool)
        wx.EVT_CHECKBOX(self.percentageViewTool,
                        self.percentageViewTool.GetId(), self.OnPercentageView)

        self.packageViewTool = wx.CheckBox(tb, -1, _("File View    "))
        self.packageViewTool.SetToolTip(wx.ToolTip(
            _("Switch between call-hierarchy and package/module/function hierarchy")))
        tb.AddControl(self.packageViewTool)
        wx.EVT_CHECKBOX(self.packageViewTool, self.packageViewTool.GetId(),
                        self.OnPackageView)
        tb.Realize()
项目:GRIPy    作者:giruenf    | 项目源码 | 文件源码
def PostInit(self):
        logging.debug('{}.AfterInit started'.format(self.name))
        UIM = UIManager()
        root_ctrl = UIM.get_root_controller()

        if not isinstance(root_ctrl, MainWindowController):
            raise Exception()

        # DetachPane if granpa object has a AuiManager...    
        parent_uid = UIM._getparentuid(self.uid)
        grampa_uid = UIM._getparentuid(parent_uid)
        parent = UIM.get(parent_uid)
        grampa =  UIM.get(grampa_uid)
        if isinstance(grampa, MainWindowController):  
            mgr = wx.aui.AuiManager.GetManager(root_ctrl.view)
            if mgr is not None:
                mgr.DetachPane(parent.view)

        if self.model.pos == -1:
            # Appending - Not needed to declare pos
            self.model.pos =  parent.view.GetToolsCount()
        if self.model.pos >  parent.view.GetToolsCount():
            # If pos was setted out of range for inserting in parent Menu
            msg = 'Invalid tool position for ToolBarTool with text={}. Position will be setting to {}'.format(self.model.label, parent.view.GetToolsCount())
            logging.warning(msg)
            self.model.pos = parent.view.GetToolsCount() 

        if self.model.bitmap is None:
            bitmap = wx.Bitmap()
        else:
            bitmap = wx.Bitmap(self.model.bitmap)

        # TODO: Rever isso
        try:
            tool = parent.view.InsertTool(self.model.pos, self.model.id,
                                            self.model.label, bitmap, 
                                            wx.NullBitmap, self.model.kind,
                                            self.model.help, 
                                            self.model.long_help, None
            )
        except Exception:
            msg = 'Error in creating ToolBarTool.'
            logging.exception(msg)
            raise
        if self.model.callback and tool:
            root_ctrl.view.Bind(wx.EVT_TOOL, self.model.callback, tool)
            parent.view.Realize()

        # AtachPane again if granpa object had it detached...    
        if isinstance(grampa, MainWindowController):        
            mgr.AddPane(parent.view, parent.view.paneinfo)
            mgr.Update()

        logging.debug('{}.AfterInit ended'.format(self.name))