我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用wx.TR_HIDE_ROOT。
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, parent, name, library, default=None): wx.Dialog.__init__(self, name='BrowseValueDialog', parent=parent, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, title=_('Browse %s values library') % name) self.staticText1 = wx.StaticText( label=_('Choose a value for %s:') % name, name='staticText1', parent=self, pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) self.ValuesLibrary = wx.TreeCtrl( name='ValuesLibrary', parent=self, pos=wx.Point(0, 0), size=wx.Size(400, 200), style=wx.TR_HAS_BUTTONS | wx.TR_SINGLE | wx.SUNKEN_BORDER | wx.TR_HIDE_ROOT | wx.TR_LINES_AT_ROOT) self.ButtonSizer = self.CreateButtonSizer(wx.OK | wx.CANCEL | wx.CENTRE) self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10) self.flexGridSizer1.AddWindow(self.staticText1, 0, border=20, flag=wx.GROW | wx.TOP | wx.LEFT | wx.RIGHT) self.flexGridSizer1.AddWindow(self.ValuesLibrary, 0, border=20, flag=wx.GROW | wx.LEFT | wx.RIGHT) self.flexGridSizer1.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT) self.flexGridSizer1.AddGrowableCol(0) self.flexGridSizer1.AddGrowableRow(1) self.SetSizer(self.flexGridSizer1) self.Fit() root = self.ValuesLibrary.AddRoot("") self.GenerateValuesLibraryBranch(root, library, default)
def __init__(self, parent, folder, filter=None, editable=True): wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL) main_sizer = wx.BoxSizer(wx.VERTICAL) self.Tree = wx.TreeCtrl(self, style=(wx.TR_HAS_BUTTONS | wx.TR_SINGLE | wx.SUNKEN_BORDER | wx.TR_HIDE_ROOT | wx.TR_LINES_AT_ROOT | wx.TR_EDIT_LABELS)) if wx.Platform == '__WXMSW__': self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnTreeItemExpanded, self.Tree) self.Tree.Bind(wx.EVT_LEFT_DOWN, self.OnTreeLeftDown) else: self.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.OnTreeItemExpanded, self.Tree) self.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.OnTreeItemCollapsed, self.Tree) self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnTreeBeginLabelEdit, self.Tree) self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnTreeEndLabelEdit, self.Tree) main_sizer.AddWindow(self.Tree, 1, flag=wx.GROW) if filter is not None: self.Filter = wx.ComboBox(self, style=wx.CB_READONLY) self.Bind(wx.EVT_COMBOBOX, self.OnFilterChanged, self.Filter) main_sizer.AddWindow(self.Filter, flag=wx.GROW) else: self.Filter = None self.SetSizer(main_sizer) self.Folder = folder self.Editable = editable self.TreeImageList = wx.ImageList(16, 16) self.TreeImageDict = {} for item_type, bitmap in [(DRIVE, "tree_drive"), (FOLDER, "tree_folder"), (FILE, "tree_file")]: self.TreeImageDict[item_type] = self.TreeImageList.Add(GetBitmap(bitmap)) self.Tree.SetImageList(self.TreeImageList) self.Filters = {} if self.Filter is not None: filter_parts = filter.split("|") for idx in xrange(0, len(filter_parts), 2): if filter_parts[idx + 1] == "*.*": self.Filters[filter_parts[idx]] = "" else: self.Filters[filter_parts[idx]] = filter_parts[idx + 1].replace("*", "") self.Filter.Append(filter_parts[idx]) if idx == 0: self.Filter.SetStringSelection(filter_parts[idx]) self.CurrentFilter = self.Filters[self.Filter.GetStringSelection()] else: self.CurrentFilter = ""
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])