Attachment 'AuiNotebook_Demo_2.py'

Download

   1 """
   2 AuiNotebook ( AGW ) ( last edited 2009-12-14 18 :36 :49 by MikeDriscoll ) ( AGW ) @ 
   3 http ://wiki.wxpython.org/AuiNotebook%20%28AGW%29
   4 
   5 This [second] example shows you how to change a few notebook settings.
   6 ( And yes, it's a doozy ! )
   7 
   8 [ Note : All menu items are nonfunctional. ]
   9 
  10 """
  11 import wx
  12 import wx.lib.agw.aui as aui
  13 
  14 #------------------------------------------------------------------------------
  15 
  16 class TabPanel( wx.Panel ) :
  17     """ A simple wx.Panel class. """
  18     
  19     def __init__( self, parent ) :
  20         """  """
  21         wx.Panel.__init__( self, parent=parent )
  22         
  23         sizer = wx.BoxSizer( wx.VERTICAL )
  24         txtOne = wx.TextCtrl( self, wx.ID_ANY, "" )
  25         txtTwo = wx.TextCtrl( self, wx.ID_ANY, "" )
  26         
  27         sizer = wx.BoxSizer( wx.VERTICAL )
  28         sizer.Add( txtOne, 0, wx.ALL, 5 )
  29         sizer.Add( txtTwo, 0, wx.ALL, 5 )
  30         
  31         self.SetSizer( sizer )
  32         
  33  #end class
  34 
  35 #------------------------------------------------------------------------------
  36 
  37 class AUIManager( aui.AuiManager ) :
  38     """ AUI Manager class """
  39 
  40     def __init__( self, managed_window ) :
  41         """  """
  42         
  43         aui.AuiManager.__init__( self )
  44         self.SetManagedWindow( managed_window )
  45         
  46 #end class
  47 
  48 #------------------------------------------------------------------------------
  49 
  50 class AUINotebook( aui.AuiNotebook ) :
  51     """ AUI Notebook class """
  52 
  53     def __init__( self, parent ) :
  54         """  """
  55         
  56         aui.AuiNotebook.__init__( self, parent=parent )
  57         
  58         self.default_style = aui.AUI_NB_DEFAULT_STYLE | aui.AUI_NB_TAB_EXTERNAL_MOVE | wx.NO_BORDER
  59         self.SetWindowStyleFlag( self.default_style )
  60         
  61         #----
  62 
  63         # add some pages to the notebook
  64         pages = [TabPanel, TabPanel, TabPanel]
  65 
  66         pageCtr = 1
  67         for page in pages :
  68             label = "Tab #%i" % pageCtr
  69             tab = page( self )
  70             self.AddPage( tab, label, False )
  71             pageCtr += 1
  72         #end for
  73         
  74     #end __init__
  75     
  76 #end AUINotebook class
  77 
  78 #------------------------------------------------------------------------------
  79 
  80 class DemoFrame( wx.Frame ) :
  81     """ The demo app Frame. """
  82     
  83     ID_NotebookArtGloss     = wx.NewId()
  84     ID_NotebookArtSimple    = wx.NewId()
  85     ID_NotebookArtVC71      = wx.NewId()
  86     ID_NotebookArtFF2       = wx.NewId()
  87     ID_NotebookArtVC8       = wx.NewId()
  88     ID_NotebookArtChrome    = wx.NewId()
  89     
  90     #----------------------------------
  91     
  92     def __init__( self ) :
  93         """Constructor"""
  94         
  95         title = "AGW AUI Notebook Feature Tutorial"
  96         wx.Frame.__init__( self, None, wx.ID_ANY,
  97                           title=title, size=( 600, 400 ) )
  98         #-----
  99         
 100         self.themeDict = { "Glossy Theme (Default)" : 0,
 101                            "Simple Theme"           : 1,
 102                            "VC71 Theme"             : 2,
 103                            "Firefox 2 Theme"        : 3,
 104                            "VC8 Theme"              : 4,
 105                            "Chrome Theme"           : 5,
 106                           }
 107 
 108         # create the AUI manager
 109         self.aui_mgr = AUIManager( self )
 110 
 111         # create the AUI Notebook
 112         self.notebook = AUINotebook( self )
 113 
 114         self._notebook_style = self.notebook.default_style
 115 
 116         # add notebook to AUI manager
 117         self.aui_mgr.AddPane( self.notebook,
 118                              aui.AuiPaneInfo().Name( "notebook_content" ).
 119                              CenterPane().PaneBorder( False ) )
 120         self.aui_mgr.Update()
 121 
 122         # create menu and tool bars
 123         self.CreateMenu()
 124         self.CreateTB()
 125         
 126     #end __init__
 127 
 128     #----------------------------------
 129     
 130     def CreateMenu( self ) :
 131         """
 132         Create the menu
 133         """
 134         def doBind( item, handler ) :
 135             """ Create menu events. """
 136             self.Bind( wx.EVT_MENU, handler, item )
 137 
 138         menubar = wx.MenuBar()
 139 
 140         fileMenu = wx.Menu()
 141 
 142         doBind( fileMenu.Append( wx.ID_ANY, "&Exit\tAlt+F4",
 143                                  "Exit Program" ), self.OnExit )
 144 
 145         optionsMenu = wx.Menu()
 146 
 147         doBind( optionsMenu.Append( wx.ID_ANY,
 148                                    "Disable Current Tab" ),
 149                 self.OnDisableTab )
 150 
 151         # add the menus to the menubar
 152         menubar.Append( fileMenu, "File" )
 153         menubar.Append( optionsMenu, "Options" )
 154 
 155         self.SetMenuBar( menubar )
 156     
 157     #end CreateMenu def
 158     
 159     #----------------------------------
 160     
 161     def CreateTB( self ) :
 162         """
 163         Create the toolbar
 164         """
 165         TBFLAGS = ( wx.TB_HORIZONTAL |
 166                     wx.NO_BORDER     |
 167                     wx.TB_FLAT )
 168                     
 169         tb = self.CreateToolBar( TBFLAGS )
 170         keys = self.themeDict.keys()
 171         keys.sort()
 172         choices = keys
 173         cb = wx.ComboBox( tb, wx.ID_ANY, "Glossy Theme ( Default )",
 174                           choices=choices,
 175                           size=wx.DefaultSize,
 176                           style=wx.CB_DROPDOWN )
 177                           
 178         cb.Bind( wx.EVT_COMBOBOX, self.OnChangeTheme )
 179         tb.AddControl( cb )
 180         tb.AddSeparator()
 181 
 182         self.closeChoices = [ "No Close Button", "Close Button At Right",
 183                               "Close Button On All Tabs",
 184                               "Close Button On Active Tab" ]
 185                               
 186         cb = wx.ComboBox( tb, wx.ID_ANY,
 187                           self.closeChoices[3],
 188                           choices=self.closeChoices,
 189                           size=wx.DefaultSize,
 190                           style=wx.CB_DROPDOWN )
 191                           
 192         cb.Bind( wx.EVT_COMBOBOX, self.OnChangeTabClose )
 193         tb.AddControl( cb )
 194 
 195         tb.Realize()
 196 
 197     #end CreateTB def
 198     
 199     #----------------------------------
 200     
 201     def OnChangeTabClose( self, event ) :
 202         """
 203         Change how the close button behaves on a tab
 204  
 205         Note : Based partially on the agw AUI demo
 206         """
 207         choice = event.GetString()
 208         self._notebook_style &= ~( aui.AUI_NB_CLOSE_BUTTON |
 209                                    aui.AUI_NB_CLOSE_ON_ACTIVE_TAB |
 210                                    aui.AUI_NB_CLOSE_ON_ALL_TABS )
 211 
 212         # note that this close button doesn't work for some reason
 213         if choice == "Close Button At Right" :
 214             self._notebook_style ^= aui.AUI_NB_CLOSE_BUTTON
 215             
 216         elif choice == "Close Button On All Tabs" :
 217             self._notebook_style ^= aui.AUI_NB_CLOSE_ON_ALL_TABS
 218             
 219         elif choice == "Close Button On Active Tab" :
 220             self._notebook_style ^= aui.AUI_NB_CLOSE_ON_ACTIVE_TAB
 221 
 222         self.notebook.SetWindowStyleFlag( self._notebook_style )
 223         self.notebook.Refresh()
 224         self.notebook.Update()
 225     
 226     #end OnChangeTabClose def
 227     
 228     #----------------------------------
 229     
 230     def OnChangeTheme( self, event ) :
 231         """
 232         Changes the notebook's theme
 233  
 234         Note : Based partially on the agw AUI demo
 235         """
 236 
 237         print event.GetString()
 238         evId = self.themeDict[event.GetString()]
 239         print evId
 240 
 241         all_panes = self.aui_mgr.GetAllPanes()
 242 
 243         for pane in all_panes :
 244 
 245             if isinstance( pane.window, aui.AuiNotebook ) :
 246                 nb = pane.window
 247 
 248                 if evId == ID_NotebookArtGloss :
 249 
 250                     nb.SetArtProvider( aui.AuiDefaultTabArt() )
 251                     self._notebook_theme = 0
 252 
 253                 elif evId == ID_NotebookArtSimple :
 254                     nb.SetArtProvider( aui.AuiSimpleTabArt() )
 255                     self._notebook_theme = 1
 256 
 257                 elif evId == ID_NotebookArtVC71 :
 258                     nb.SetArtProvider( aui.VC71TabArt() )
 259                     self._notebook_theme = 2
 260 
 261                 elif evId == ID_NotebookArtFF2 :
 262                     nb.SetArtProvider( aui.FF2TabArt() )
 263                     self._notebook_theme = 3
 264 
 265                 elif evId == ID_NotebookArtVC8 :
 266                     nb.SetArtProvider( aui.VC8TabArt() )
 267                     self._notebook_theme = 4
 268 
 269                 elif evId == ID_NotebookArtChrome :
 270                     nb.SetArtProvider( aui.ChromeTabArt() )
 271                     self._notebook_theme = 5
 272 
 273                 #nb.SetWindowStyleFlag( self._notebook_style )
 274                 nb.Refresh()
 275                 nb.Update()
 276                 
 277             #end if
 278             
 279         # end for
 280         
 281     #end OnChangeTheme def
 282     
 283     #----------------------------------
 284     
 285     def OnDisableTab( self, event ) :
 286         """ Disables the current tab. """
 287         
 288         page = self.notebook.GetCurrentPage()
 289         page_idx = self.notebook.GetPageIndex( page )
 290 
 291         self.notebook.EnableTab( page_idx, False )
 292         self.notebook.AdvanceSelection()
 293 
 294     #----------------------------------
 295     
 296     def OnExit( self, event ) :
 297         """ Close the demo. """
 298         
 299         self.Close()
 300 
 301 #end DemoFrame class
 302 
 303 #==============================================================================
 304 
 305 if __name__ == "__main__" :
 306     
 307     app = wx.PySimpleApp()
 308     frame = DemoFrame().Show()
 309     app.MainLoop()
 310 
 311 #end if

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2010-09-11 19:38:00, 9.4 KB) [[attachment:AuiNotebook_Demo_2.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.