树状分级框架UI实例;(内容参考https://zhuanlan.zhihu.com/p/108485875)
#coding:utf8 #!/usr/bin/env python #@author: 9527 import wx import wx.aui from pubsub import pub import PicturepackageUI from note_tree import NoteTree from Header_Panel import HeaderPanel class NavPanel(wx.Panel): def __init__(self, parent): super().__init__(parent) v_sizer = wx.BoxSizer(wx.VERTICAL) self.btn_new_note = wx.Button(self,style=wx.NO_BORDER) self.btn_new_note.SetLabelMarkup('<span bgcolor="white" fgcolor="#ea5455" weight="bold" size="large">服务端管理系统</span>') v_sizer.Add(self.btn_new_note, flag=wx.ALIGN_CENTER|wx.TOP, border=40) v_sizer.AddSpacer(20) self.note_tree = NoteTree(self) v_sizer.Add(self.note_tree, proportion=1,flag=wx.EXPAND) self.SetSizer(v_sizer) self.SetBackgroundColour("#2d4059") class ListPanel(wx.Panel): def __init__(self, parent): super().__init__(parent,style=wx.BORDER_NONE) self.SetBackgroundColour('#8f8787') #self.SetPosition(wx.Point(-1, 60)) #********************************************** main_sizer = wx.BoxSizer(wx.VERTICAL) self.header_panel = HeaderPanel(self) main_sizer.Add(self.header_panel,flag=wx.EXPAND) self.SetSizer(main_sizer) #********************************************** class TextEditor(wx.Panel): def __init__(self, parent): super().__init__(parent) self.SetBackgroundColour('#086972') class MainFrame(wx.Frame): def __init__(self): super().__init__(None, title='服务端管理系统',size=(800,600)) self.aui_manager = wx.aui.AuiManager(self,wx.aui.AUI_MGR_TRANSPARENT_HINT) #********************************************* ''' bSizer1 = wx.BoxSizer( wx.VERTICAL ) self.m_toolBar1 = wx.ToolBar( self, wx.ID_ANY, wx.DefaultPosition, wx.Size( -1,-1 ), wx.TB_HORIZONTAL ) self.m_toolBar1.Realize() bSizer1.Add( self.m_toolBar1, 0, wx.EXPAND, 5 ) ''' #*********************************** self.nav_panel = NavPanel(self) self.list_panel = ListPanel(self) self.detail_panel = TextEditor(self) self.aui_manager.AddPane(self.nav_panel, self._get_default_pane_info().Left().Row(0).BestSize(300,-1)) self.aui_manager.AddPane(self.list_panel, self._get_default_pane_info().Left().Row(1).BestSize(-1, 250).MinSize(-1,250)) self.aui_manager.AddPane(self.detail_panel, self._get_default_pane_info().CenterPane().Position(0).BestSize(400,-1)) self.aui_manager.Update() self.Maximize(True) self._register_listeners() def _get_default_pane_info(self): #改变窗体样式 return wx.aui.AuiPaneInfo().CaptionVisible(False).PaneBorder(False).CloseButton(False).PinButton(False).Gripper( False) def on_frame_closing(self, e): self.aui_manager.UnInit() del self.aui_manager self.Destroy() def _register_listeners(self): self.Bind(wx.EVT_CLOSE, self.on_frame_closing) if __name__ == '__main__': app = wx.App() frame = MainFrame() frame.Show() app.MainLoop()
note_tree
#coding:utf8 #!/usr/bin/env python #@author: 9527 import wx.lib.agw.customtreectrl as customtreectrl class NoteTree(customtreectrl.CustomTreeCtrl): def __init__(self, parent): super().__init__(parent,agwStyle=customtreectrl.TR_HAS_BUTTONS|customtreectrl.TR_FULL_ROW_HIGHLIGHT|customtreectrl.TR_ELLIPSIZE_LONG_ITEMS|customtreectrl.TR_TOOLTIP_ON_LONG_ITEMS) self.root = self.AddRoot("后台管理分类") self._load_note_books() self._init_ui() def _load_note_books(self): root_note_books = ['权限','示例2','示例3'] for note_book in root_note_books: root_node = self.AppendItem(self.root, note_book) self.AppendItem(root_node, "笔记本") self.ExpandAll() def _init_ui(self): panel_font = self.GetFont() panel_font.SetPointSize(panel_font.GetPointSize() + 1) self.SetFont(panel_font) self.EnableSelectionGradient(False) self.EnableSelectionGradient(False) self.SetForegroundColour("#ececec") self.SetBackgroundColour("#2a2a2a") self.SetHilightFocusColour("#ea5455") self.SetHilightNonFocusColour("#f07b3f") self.SetSpacing(20) self.SetIndent(10)
Header_Panel
#coding:utf8 #!/usr/bin/env python #@author: 9527 import wx class HeaderPanel(wx.Panel): def __init__(self, parent): super().__init__(parent, style=wx.BORDER_NONE) self._init_ui() def _init_ui(self): self.main_sizer = wx.BoxSizer(wx.VERTICAL) self.st_notebook_name = wx.StaticText(self, label='笔记本名称') self.main_sizer.Add(self.st_notebook_name, flag=wx.ALL, border=10) self._build_note_actions() self._build_search_bar() self.main_sizer.AddSpacer(10) self.SetSizer(self.main_sizer) self.SetBackgroundColour("#ebebeb") def _build_note_actions(self): note_action_sizer = wx.BoxSizer(wx.HORIZONTAL) self.st_note_count = wx.StaticText(self, label="10条笔记") note_action_sizer.Add(self.st_note_count) note_action_sizer.AddStretchSpacer() self.btn_display_order_options = wx.Button(self,label='sort') note_action_sizer.Add(self.btn_display_order_options) self.btn_display_notebook_options = wx.Button(self, label='more') note_action_sizer.Add(self.btn_display_notebook_options,flag=wx.LEFT,border=10) self.main_sizer.Add(note_action_sizer, flag=wx.ALL|wx.EXPAND, border=10) def _build_search_bar(self): self.search_bar = wx.SearchCtrl(self,style=wx.TE_PROCESS_ENTER) self.search_bar.ShowCancelButton(True) search_menu = wx.Menu() search_menu.AppendCheckItem(wx.ID_ANY, '搜索所有笔记本') self.search_bar.SetMenu(search_menu) self.search_bar.SetHint('搜索当前笔记本') self.main_sizer.Add(self.search_bar, flag=wx.EXPAND|wx.LEFT|wx.RIGHT, border=8)
标签:__,sizer,树状,self,note,init,实例,UI,wx From: https://www.cnblogs.com/babashi9527/p/17146645.html