Path: blob/main/tools/contributed/sumopy/agilepy/lib_wx/test_notebook.py
169689 views
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo1# Copyright (C) 2016-2025 German Aerospace Center (DLR) and others.2# SUMOPy module3# Copyright (C) 2012-2021 University of Bologna - DICAM4# This program and the accompanying materials are made available under the5# terms of the Eclipse Public License 2.0 which is available at6# https://www.eclipse.org/legal/epl-2.0/7# This Source Code may also be made available under the following Secondary8# Licenses when the conditions for such availability set forth in the Eclipse9# Public License 2.0 are satisfied: GNU General Public License, version 210# or later which is available at11# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html12# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later1314# @file test_notebook.py15# @author Joerg Schweizer16# @date 2012171819#import images20import wx212223class PanelOne(wx.Panel):24"""25This will be the first notebook tab26"""27# ----------------------------------------------------------------------2829def __init__(self, parent):30""""""3132wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY)3334sizer = wx.BoxSizer(wx.VERTICAL)35txtOne = wx.TextCtrl(self, wx.ID_ANY, "")36txtTwo = wx.TextCtrl(self, wx.ID_ANY, "")3738sizer = wx.BoxSizer(wx.VERTICAL)39sizer.Add(txtOne, 0, wx.ALL, 5)40sizer.Add(txtTwo, 0, wx.ALL, 5)4142self.SetSizer(sizer)434445class NestedPanel(wx.Panel):46"""47This will be the first notebook tab48"""49# ----------------------------------------------------------------------5051def __init__(self, parent):52""""""5354wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY)5556sizer = wx.BoxSizer(wx.VERTICAL)5758# Create some nested tabs on the first tab59nestedNotebook = wx.Notebook(self, wx.ID_ANY)60nestedTabOne = PanelOne(nestedNotebook)61nestedTabTwo = PanelOne(nestedNotebook)62nestedNotebook.AddPage(nestedTabOne, "NestedTabOne")63nestedNotebook.AddPage(nestedTabTwo, "NestedTabTwo")6465sizer = wx.BoxSizer(wx.VERTICAL)66sizer.Add(nestedNotebook, 1, wx.ALL | wx.EXPAND, 5)6768self.SetSizer(sizer)697071########################################################################72class NestedNotebookDemo(wx.Notebook):73"""74Notebook class75"""7677# ----------------------------------------------------------------------78def __init__(self, parent):79wx.Notebook.__init__(self, parent, id=wx.ID_ANY, style=wx.BK_DEFAULT80# wx.BK_TOP81# wx.BK_BOTTOM82# wx.BK_LEFT83# wx.BK_RIGHT84)8586# Create the first tab and add it to the notebook87tabOne = NestedPanel(self)88self.AddPage(tabOne, "TabOne")8990# Show how to put an image on one of the notebook tabs,91# first make the image list:92il = wx.ImageList(16, 16)93idx1 = il.Add(images.Smiles.GetBitmap())94self.AssignImageList(il)9596# now put an image on the first tab we just created:97self.SetPageImage(0, idx1)9899# Create and add the second tab100tabTwo = PanelOne(self)101self.AddPage(tabTwo, "TabTwo")102103# Create and add the third tab104self.AddPage(PanelOne(self), "TabThree")105106self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)107self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING, self.OnPageChanging)108109def OnPageChanged(self, event):110old = event.GetOldSelection()111new = event.GetSelection()112sel = self.GetSelection()113print 'OnPageChanged, old:%d, new:%d, sel:%d\n' % (old, new, sel)114event.Skip()115116def OnPageChanging(self, event):117old = event.GetOldSelection()118new = event.GetSelection()119sel = self.GetSelection()120print 'OnPageChanging, old:%d, new:%d, sel:%d\n' % (old, new, sel)121event.Skip()122123124########################################################################125class DemoFrame(wx.Frame):126"""127Frame that holds all other widgets128"""129130# ----------------------------------------------------------------------131def __init__(self):132"""Constructor"""133wx.Frame.__init__(self, None, wx.ID_ANY,134"Notebook Tutorial",135size=(600, 400)136)137panel = wx.Panel(self)138139notebook = NestedNotebookDemo(panel)140sizer = wx.BoxSizer(wx.VERTICAL)141sizer.Add(notebook, 1, wx.ALL | wx.EXPAND, 5)142panel.SetSizer(sizer)143self.Layout()144145self.Show()146147148# ----------------------------------------------------------------------149if __name__ == "__main__":150app = wx.PySimpleApp()151frame = DemoFrame()152app.MainLoop()153154155