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