我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用wx.EVT_TREE_SEL_CHANGED。
def __init__(self, parent): """Constructor""" wx.Panel.__init__(self, parent=parent) B = wx.StaticBox(self, -1) self.BSizer = wx.StaticBoxSizer(B, wx.VERTICAL) self.tree = XMLTree(parent=self, ID=-1) self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.onSelectItem) self.tree.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.getFullXpath) self.BSizer.Add(self.tree, 5, wx.EXPAND, 5) self.SetSizer(self.BSizer) cDir = os.getcwd() self.xmlPath = os.path.join(cDir,"Hierarchy","window_dump.xml") pub.subscribe(self.updateTree, "updateTree") pub.subscribe(self.setSelectedNode, "setSelectedNode") pub.subscribe(self.DoSearch, "DoSearch")
def _init_Editor(self, parent): self.Editor = wx.Panel(parent) main_sizer = wx.BoxSizer(wx.HORIZONTAL) left_sizer = wx.BoxSizer(wx.VERTICAL) main_sizer.AddSizer(left_sizer, 1, border=5, flag=wx.GROW | wx.ALL) managed_dir_label = wx.StaticText(self.Editor, label=_(self.TagName) + ":") left_sizer.AddWindow(managed_dir_label, border=5, flag=wx.GROW | wx.BOTTOM) self.ManagedDir = FolderTree(self.Editor, self.Folder, FILTER) left_sizer.AddWindow(self.ManagedDir, 1, flag=wx.GROW) managed_treectrl = self.ManagedDir.GetTreeCtrl() self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnTreeItemChanged, managed_treectrl) if self.EnableDragNDrop: self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnTreeBeginDrag, managed_treectrl) button_sizer = wx.BoxSizer(wx.VERTICAL) main_sizer.AddSizer(button_sizer, border=5, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL) for idx, (name, bitmap, help) in enumerate([ ("DeleteButton", "remove_element", _("Remove file from left folder")), ("LeftCopyButton", "LeftCopy", _("Copy file from right folder to left")), ("RightCopyButton", "RightCopy", _("Copy file from left folder to right")), ("EditButton", "edit", _("Edit file"))]): button = wx.lib.buttons.GenBitmapButton( self.Editor, bitmap=GetBitmap(bitmap), size=wx.Size(28, 28), style=wx.NO_BORDER) button.SetToolTipString(help) setattr(self, name, button) if idx > 0: flag = wx.TOP else: flag = 0 self.Bind(wx.EVT_BUTTON, getattr(self, "On" + name), button) button_sizer.AddWindow(button, border=20, flag=flag) right_sizer = wx.BoxSizer(wx.VERTICAL) main_sizer.AddSizer(right_sizer, 1, border=5, flag=wx.GROW | wx.ALL) if wx.Platform == '__WXMSW__': system_dir_label = wx.StaticText(self.Editor, label=_("My Computer:")) else: system_dir_label = wx.StaticText(self.Editor, label=_("Home Directory:")) right_sizer.AddWindow(system_dir_label, border=5, flag=wx.GROW | wx.BOTTOM) self.SystemDir = FolderTree(self.Editor, self.HomeDirectory, FILTER, False) right_sizer.AddWindow(self.SystemDir, 1, flag=wx.GROW) system_treectrl = self.SystemDir.GetTreeCtrl() self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnTreeItemChanged, system_treectrl) self.Editor.SetSizer(main_sizer)
def __init__( self, parent ): wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = "Plugins Tree", pos = wx.DefaultPosition, size = wx.Size( 452,300 ), 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.DefaultSize, wx.DefaultSize ) bSizer1 = wx.BoxSizer( wx.HORIZONTAL ) self.tre_plugins = wx.TreeCtrl( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TR_DEFAULT_STYLE ) self.tre_plugins.SetMinSize( wx.Size( 200,-1 ) ) bSizer1.Add( self.tre_plugins, 0, wx.ALL|wx.EXPAND, 5 ) bSizer3 = wx.BoxSizer( wx.VERTICAL ) bSizer4 = wx.BoxSizer( wx.HORIZONTAL ) self.m_staticText2 = wx.StaticText( self, wx.ID_ANY, "Plugin Infomation:", wx.DefaultPosition, wx.DefaultSize, 0 ) self.m_staticText2.Wrap( -1 ) bSizer4.Add( self.m_staticText2, 0, wx.ALL, 5 ) self.m_staticText3 = wx.StaticText( self, wx.ID_ANY, "[SourceCode]", wx.DefaultPosition, wx.DefaultSize, 0 ) self.m_staticText3.Wrap( -1 ) self.m_staticText3.SetForegroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_HIGHLIGHT ) ) bSizer4.Add( self.m_staticText3, 0, wx.ALL, 5 ) bSizer3.Add( bSizer4, 0, wx.EXPAND, 5 ) self.txt_info = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.TE_MULTILINE ) bSizer3.Add( self.txt_info, 1, wx.ALL|wx.EXPAND, 5 ) bSizer1.Add( bSizer3, 1, wx.EXPAND, 5 ) self.SetSizer( bSizer1 ) self.Layout() self.Centre( wx.BOTH ) # Connect Events self.tre_plugins.Bind( wx.EVT_TREE_ITEM_ACTIVATED, self.on_run ) self.tre_plugins.Bind( wx.EVT_TREE_SEL_CHANGED, self.on_select ) self.m_staticText3.Bind( wx.EVT_LEFT_DOWN, self.on_source ) self.plg = None self.load()
def __init__( self, parent ): wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = "Tools Tree", pos = wx.DefaultPosition, size = wx.Size( 452,300 ), 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.DefaultSize, wx.DefaultSize ) bSizer1 = wx.BoxSizer( wx.HORIZONTAL ) self.tre_plugins = wx.TreeCtrl( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TR_DEFAULT_STYLE ) self.tre_plugins.SetMinSize( wx.Size( 200,-1 ) ) bSizer1.Add( self.tre_plugins, 0, wx.ALL|wx.EXPAND, 5 ) bSizer3 = wx.BoxSizer( wx.VERTICAL ) bSizer4 = wx.BoxSizer( wx.HORIZONTAL ) self.m_staticText2 = wx.StaticText( self, wx.ID_ANY, "Tool Infomation:", wx.DefaultPosition, wx.DefaultSize, 0 ) self.m_staticText2.Wrap( -1 ) bSizer4.Add( self.m_staticText2, 0, wx.ALL, 5 ) self.m_staticText3 = wx.StaticText( self, wx.ID_ANY, "[SourceCode]", wx.DefaultPosition, wx.DefaultSize, 0 ) self.m_staticText3.Wrap( -1 ) self.m_staticText3.SetForegroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_HIGHLIGHT ) ) bSizer4.Add( self.m_staticText3, 0, wx.ALL, 5 ) bSizer3.Add( bSizer4, 0, wx.EXPAND, 5 ) self.txt_info = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.TE_MULTILINE ) bSizer3.Add( self.txt_info, 1, wx.ALL|wx.EXPAND, 5 ) bSizer1.Add( bSizer3, 1, wx.EXPAND, 5 ) self.SetSizer( bSizer1 ) self.Layout() self.Centre( wx.BOTH ) # Connect Events self.tre_plugins.Bind( wx.EVT_TREE_ITEM_ACTIVATED, self.on_run ) self.tre_plugins.Bind( wx.EVT_TREE_SEL_CHANGED, self.on_select ) self.m_staticText3.Bind( wx.EVT_LEFT_DOWN, self.on_source ) self.plg = None self.load()
def create_layout(self): self.main_grid = wx.BoxSizer(wx.HORIZONTAL) style = wx.TR_DEFAULT_STYLE | wx.TR_HIDE_ROOT | wx.TR_TWIST_BUTTONS | wx.TR_NO_LINES # style = wx.TR_HAS_BUTTONS | wx.TR_SINGLE | wx.TR_HIDE_ROOT image_list = wx.ImageList(16, 16) tree_ctrl_id = id_renew('settings.tree', update=True) tree_ctrl = wx.TreeCtrl(self, id=tree_ctrl_id, style=style) root_key = MODULE_KEY.join(['settings', 'tree', 'root']) root_node = tree_ctrl.AddRoot(translate_key(root_key)) for cat_name, category in self.categories.iteritems(): item_key = MODULE_KEY.join(['settings', cat_name]) item_data = wx.TreeItemData() item_data.SetData(item_key) item_node = tree_ctrl.AppendItem(root_node, translate_key(item_key), data=item_data) for module_name, module_settings in category.iteritems(): if not module_name == cat_name: if module_settings.get('gui', {}).get('icon'): icon = wx.Bitmap(module_settings['gui']['icon']) self.tree_ctrl_image_dict[module_name] = image_list.GetImageCount() image_list.Add(icon) else: self.tree_ctrl_image_dict[module_name] = -1 f_item_key = MODULE_KEY.join([item_key, module_name]) f_item_data = wx.TreeItemData() f_item_data.SetData(f_item_key) tree_ctrl.AppendItem(item_node, translate_key(module_name), image=self.tree_ctrl_image_dict[module_name], data=f_item_data) if self.show_icons: tree_ctrl.AssignImageList(image_list) tree_ctrl.ExpandAll() self.tree_ctrl = tree_ctrl self.Bind(wx.EVT_TREE_SEL_CHANGED, self.on_tree_ctrl_changed, id=tree_ctrl_id) self.main_grid.Add(tree_ctrl, 7, wx.EXPAND | wx.ALL, 7) content_page_id = id_renew(MODULE_KEY.join(['settings', 'content'])) self.content_page = wx.Panel(self, id=content_page_id) self.main_grid.Add(self.content_page, 15, wx.EXPAND) self.main_grid.Layout() self.SetSizer(self.main_grid) tree_ctrl.SelectItem(tree_ctrl.GetFirstChild(root_node)[0])