1# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo 2# Copyright (C) 2016-2019 German Aerospace Center (DLR) and others. 3# SUMOPy module 4# Copyright (C) 2012-2017 University of Bologna - DICAM 5# This program and the accompanying materials 6# are made available under the terms of the Eclipse Public License v2.0 7# which accompanies this distribution, and is available at 8# http://www.eclipse.org/legal/epl-v20.html 9# SPDX-License-Identifier: EPL-2.0 10 11# @file test_notebook.py 12# @author Joerg Schweizer 13# @date 14# @version $Id$ 15 16 17#import images 18import wx 19 20 21class PanelOne(wx.Panel): 22 """ 23 This will be the first notebook tab 24 """ 25 # ---------------------------------------------------------------------- 26 27 def __init__(self, parent): 28 """""" 29 30 wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY) 31 32 sizer = wx.BoxSizer(wx.VERTICAL) 33 txtOne = wx.TextCtrl(self, wx.ID_ANY, "") 34 txtTwo = wx.TextCtrl(self, wx.ID_ANY, "") 35 36 sizer = wx.BoxSizer(wx.VERTICAL) 37 sizer.Add(txtOne, 0, wx.ALL, 5) 38 sizer.Add(txtTwo, 0, wx.ALL, 5) 39 40 self.SetSizer(sizer) 41 42 43class NestedPanel(wx.Panel): 44 """ 45 This will be the first notebook tab 46 """ 47 # ---------------------------------------------------------------------- 48 49 def __init__(self, parent): 50 """""" 51 52 wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY) 53 54 sizer = wx.BoxSizer(wx.VERTICAL) 55 56 # Create some nested tabs on the first tab 57 nestedNotebook = wx.Notebook(self, wx.ID_ANY) 58 nestedTabOne = PanelOne(nestedNotebook) 59 nestedTabTwo = PanelOne(nestedNotebook) 60 nestedNotebook.AddPage(nestedTabOne, "NestedTabOne") 61 nestedNotebook.AddPage(nestedTabTwo, "NestedTabTwo") 62 63 sizer = wx.BoxSizer(wx.VERTICAL) 64 sizer.Add(nestedNotebook, 1, wx.ALL | wx.EXPAND, 5) 65 66 self.SetSizer(sizer) 67 68 69######################################################################## 70class NestedNotebookDemo(wx.Notebook): 71 """ 72 Notebook class 73 """ 74 75 # ---------------------------------------------------------------------- 76 def __init__(self, parent): 77 wx.Notebook.__init__(self, parent, id=wx.ID_ANY, style=wx.BK_DEFAULT 78 # wx.BK_TOP 79 # wx.BK_BOTTOM 80 # wx.BK_LEFT 81 # wx.BK_RIGHT 82 ) 83 84 # Create the first tab and add it to the notebook 85 tabOne = NestedPanel(self) 86 self.AddPage(tabOne, "TabOne") 87 88 # Show how to put an image on one of the notebook tabs, 89 # first make the image list: 90 il = wx.ImageList(16, 16) 91 idx1 = il.Add(images.Smiles.GetBitmap()) 92 self.AssignImageList(il) 93 94 # now put an image on the first tab we just created: 95 self.SetPageImage(0, idx1) 96 97 # Create and add the second tab 98 tabTwo = PanelOne(self) 99 self.AddPage(tabTwo, "TabTwo") 100 101 # Create and add the third tab 102 self.AddPage(PanelOne(self), "TabThree") 103 104 self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged) 105 self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING, self.OnPageChanging) 106 107 def OnPageChanged(self, event): 108 old = event.GetOldSelection() 109 new = event.GetSelection() 110 sel = self.GetSelection() 111 print 'OnPageChanged, old:%d, new:%d, sel:%d\n' % (old, new, sel) 112 event.Skip() 113 114 def OnPageChanging(self, event): 115 old = event.GetOldSelection() 116 new = event.GetSelection() 117 sel = self.GetSelection() 118 print 'OnPageChanging, old:%d, new:%d, sel:%d\n' % (old, new, sel) 119 event.Skip() 120 121 122######################################################################## 123class DemoFrame(wx.Frame): 124 """ 125 Frame that holds all other widgets 126 """ 127 128 # ---------------------------------------------------------------------- 129 def __init__(self): 130 """Constructor""" 131 wx.Frame.__init__(self, None, wx.ID_ANY, 132 "Notebook Tutorial", 133 size=(600, 400) 134 ) 135 panel = wx.Panel(self) 136 137 notebook = NestedNotebookDemo(panel) 138 sizer = wx.BoxSizer(wx.VERTICAL) 139 sizer.Add(notebook, 1, wx.ALL | wx.EXPAND, 5) 140 panel.SetSizer(sizer) 141 self.Layout() 142 143 self.Show() 144 145 146# ---------------------------------------------------------------------- 147if __name__ == "__main__": 148 app = wx.PySimpleApp() 149 frame = DemoFrame() 150 app.MainLoop() 151