我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用wx.TR_DEFAULT_STYLE。
def __init__(self, parent): wx.Frame.__init__(self, parent, -1, "CustomTreeCtrl Demo") # Create a CustomTreeCtrl instance custom_tree = CT.CustomTreeCtrl(self, agwStyle=wx.TR_DEFAULT_STYLE) # Add a root node to it root = custom_tree.AddRoot("The Root Item") # Create an image list to add icons next to an item il = wx.ImageList(16, 16) fldridx = il.Add(wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, (16, 16))) fldropenidx = il.Add(wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, (16, 16))) fileidx = il.Add(wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, (16, 16))) custom_tree.SetImageList(il) custom_tree.SetItemImage(root, fldridx, wx.TreeItemIcon_Normal) custom_tree.SetItemImage(root, fldropenidx, wx.TreeItemIcon_Expanded) list = [ 'http://app.finance.china.com.cn/forex', 'http://app.finance.china.com.cn/report/list.php', 'http://app.finance.china.com.cn/stock/bill'] for x in list: child = custom_tree.AppendItem(root, "Item %s" % x) custom_tree.SetItemImage(child, fldridx, wx.TreeItemIcon_Normal) custom_tree.SetItemImage(child, fldropenidx, wx.TreeItemIcon_Expanded) for y in list: last = custom_tree.AppendItem(child, "item-%s-%s" % (x,y)) custom_tree.SetItemImage(last, fldridx, wx.TreeItemIcon_Normal) custom_tree.SetItemImage(last, fldropenidx, wx.TreeItemIcon_Expanded) for z in list: item = custom_tree.AppendItem(last, "item %s-%s-%s" % (x,y,z)) custom_tree.SetItemImage(item, fileidx, wx.TreeItemIcon_Normal) custom_tree.Expand(root) # our normal wxApp-derived class, as usual
def __init__(self, parent, sheets_directory): """Initalize InvalidSampleSheetsPanel. Args: parent: the owning Window sheets_directory: the parent directory for searching sample sheets. This argument is used in the error message that's displayed to the user to tell them where to look to fix any issues. """ wx.Panel.__init__(self, parent) self._sizer = wx.BoxSizer(wx.VERTICAL) self.SetSizer(self._sizer) header = wx.StaticText(self, label=u"? Looks like some sample sheets are not valid.") header.SetFont(wx.Font(18, wx.DEFAULT, wx.NORMAL, wx.BOLD)) header.SetForegroundColour(wx.Colour(255, 0, 0)) header.Wrap(350) self._sizer.Add(header,flag=wx.TOP | wx.BOTTOM | wx.ALIGN_CENTER, border=5) self._sizer.Add(wx.StaticText(self, label=wordwrap(( "I found the following sample sheets in {}, but I couldn't understand " "their contents. Check these sample sheets in an editor outside " "of the uploader, then click the 'Scan Again' button below.").format(sheets_directory), 350, wx.ClientDC(self))), flag=wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, border=5) self._errors_tree = wx.TreeCtrl(self, style=wx.TR_DEFAULT_STYLE | wx.TR_FULL_ROW_HIGHLIGHT | wx.TR_LINES_AT_ROOT | wx.TR_HIDE_ROOT) self._errors_tree_root = self._errors_tree.AddRoot("") self._sizer.Add(self._errors_tree, flag=wx.EXPAND, proportion=1) scan_again_button = wx.Button(self, label="Scan Again") self.Bind(wx.EVT_BUTTON, lambda evt: send_message(SettingsDialog.settings_closed_topic), id=scan_again_button.GetId()) self._sizer.Add(scan_again_button, flag=wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, border=5) pub.subscribe(self._sample_sheet_error, DirectoryScannerTopics.garbled_sample_sheet) pub.subscribe(self._sample_sheet_error, DirectoryScannerTopics.missing_files)
def __init__(self, controller_uid): UIViewBase.__init__(self, controller_uid) UIM = UIManager() controller = UIM.get(self._controller_uid) parent_controller_uid = UIM._getparentuid(self._controller_uid) parent_controller = UIM.get(parent_controller_uid) wx.TreeCtrl.__init__(self, parent_controller.view, -1, wx.Point(0, 0), wx.Size(200, 250), wx.TR_DEFAULT_STYLE | wx.NO_BORDER) self._rootid = self.AddRoot(wx.EmptyString) self._set_project_name() self.SetItemData(self._rootid, (controller._PSEUDOROOTUID, None)) self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.on_rightclick) ''' imglist = wx.ImageList(16, 16, True, 2) imglist.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, wx.Size(16,16))) tree.AssignImageList(imglist) items.append(tree.AppendItem(root, "Item 1", 0)) ''' parent_controller.view._mgr.AddPane(self, wx.aui.AuiPaneInfo().Name("tree"). Caption("Object Manager").Left().Layer(1).Position(1). PinButton(True).MinimizeButton(True). CloseButton(False).MaximizeButton(True) ) parent_controller.view._mgr.Update() self.Bind(wx.EVT_TREE_BEGIN_DRAG, self._on_begin_drag)
def __init__(self, parent, id, title): wx.Frame.__init__(self,parent,wx.ID_ANY, title, size=(600, 600), pos=(200, 200)) self.splitter_window = wx.SplitterWindow(self, -1, style=wx.SP_3D|wx.SP_BORDER) self.splitter_window.SetMinimumPaneSize(20) self.left_panel = wx.Panel(self.splitter_window, -1) self.right_panel = wx.Panel(self.splitter_window, -1) self.tree = CT.CustomTreeCtrl(self.left_panel, 1002, pos=(0, 0), style=wx.TR_DEFAULT_STYLE | wx.TR_HAS_VARIABLE_ROW_HEIGHT | wx.TR_HAS_BUTTONS | wx.TR_FULL_ROW_HIGHLIGHT | wx.TR_MULTIPLE | wx.TR_EDIT_LABELS) self.root = self.tree.AddRoot("Root Item") offset_lists = ["Clearance Reports", "Other Offsets"] offset_list_combo_box = wx.ComboBox(self.right_panel, -1, choices=offset_lists) #Sizers offset_sizer = wx.BoxSizer(wx.VERTICAL) offset_sizer.Add(offset_list_combo_box, 0, wx.EXPAND) vbox = wx.BoxSizer(wx.VERTICAL) vbox.Add(self.tree, 1, wx.EXPAND) self.left_panel.SetSizer(vbox) vbox2 = wx.BoxSizer(wx.VERTICAL) vbox2.Add(offset_sizer, 1, wx.EXPAND) self.right_panel.SetSizer(vbox2) main_sizer = wx.BoxSizer(wx.HORIZONTAL) self.splitter_window.SplitVertically(self.left_panel, self.right_panel) main_sizer.Add(self.splitter_window, 1, wx.EXPAND) self.SetSizer(main_sizer) self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnEndLabelEdit) self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnBeginLabelEdit) self.Bind(wx.EVT_KEY_DOWN, self.enterpressed) self.tree.Bind(wx.EVT_KEY_DOWN, self.enterpressed) self.Bind(wx.EVT_KEY_DOWN, self.enterpressed, self.tree) self.Bind(wx.EVT_COMMAND_ENTER, self.enterpressed) self.Bind(wx.EVT_TEXT_ENTER, self.enterpressed) self.Show(True)
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])