Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/contributed/sumopy/agilepy/lib_wx/objbrowser.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 objbrowser.py
16
# @author Joerg Schweizer
17
# @date 2012
18
19
import wx
20
from objpanel import *
21
from mainframe import AgileMainframe, AgileStatusbar, AgileMenubar
22
23
24
class ObjBrowserMainframe(AgileMainframe):
25
def __init__(self, obj=None, table=None, _id=None, parent=None,
26
title='Object browser', appname='Object browser app',
27
moduledirs=[], args=[], appdir='',
28
is_maximize=False, is_centerscreen=True,
29
pos=wx.DefaultPosition, size=wx.DefaultSize,
30
style=wx.DEFAULT_FRAME_STYLE, logger=None,
31
name='Object browser frame', size_toolbaricons=(24, 24)):
32
33
# print 'AgileMainframe.__init__',title,appdir
34
35
# Forcing a specific style on the window.
36
# Should this include styles passed?
37
38
if appname is not None:
39
self.appname = appname
40
else:
41
self.appname = title
42
wx.Frame.__init__(self, parent, wx.ID_ANY, self.appname,
43
pos, size=size, style=style, name=name)
44
45
if obj is not None:
46
# print ' init ObjPanel'
47
#self.browser = ObjPanel(self, obj)
48
self.browser = NaviPanel(self, obj, _id)
49
elif table is not None:
50
# print ' init TablePanel'
51
self.browser = TablePanel(self, table)
52
else:
53
obj = cm.BaseObjman('empty')
54
self.browser = NaviPanel(self, obj, _id)
55
56
if logger is not None:
57
self._logger = logger
58
else:
59
self._logger = Logger()
60
61
if is_maximize:
62
self.Maximize()
63
if is_centerscreen:
64
self.CenterOnScreen()
65
66
#################################################################
67
# create statusbar
68
self.statusbar = AgileStatusbar(self)
69
self.SetStatusBar(self.statusbar)
70
# self.count=0.0
71
72
#################################################################
73
# create toolbar
74
75
self.init_toolbar(size=size_toolbaricons)
76
#
77
#new_bmp = wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_TOOLBAR, tsize)
78
#open_bmp = wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR, tsize)
79
#save_bmp= wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_TOOLBAR, tsize)
80
#cut_bmp = wx.ArtProvider.GetBitmap(wx.ART_CUT, wx.ART_TOOLBAR, tsize)
81
#copy_bmp = wx.ArtProvider.GetBitmap(wx.ART_COPY, wx.ART_TOOLBAR, tsize)
82
#paste_bmp= wx.ArtProvider.GetBitmap(wx.ART_PASTE, wx.ART_TOOLBAR, tsize)
83
84
#self.add_tool('new',self.on_open,new_bmp,'create new doc')
85
#self.add_tool('open',self.on_open,open_bmp,'Open doc')
86
#self.add_tool('save',self.on_save,save_bmp,'Save doc')
87
# self.toolbar.AddSeparator()
88
# self.add_tool('cut',self.on_open,cut_bmp,'Cut')
89
# self.add_tool('copy',self.on_open,copy_bmp,'Copy')
90
# self.add_tool('paste',self.on_open,paste_bmp,'Paste')
91
92
# self.SetToolBar(self.toolbar)
93
94
#################################################################
95
# create the menu bar
96
97
self.menubar = AgileMenubar(self)
98
self.make_menu()
99
# self.menubar.append_menu('tools')
100
self.SetMenuBar(self.menubar)
101
102
#################################################################
103
# init logger
104
#self._logger = Logger()
105
#self._logger.add_callback(self.write_message, 'message')
106
#self._logger.add_callback(self.write_action, 'action')
107
#self._logger.add_callback(self.show_progress, 'progress')
108
#################################################################
109
110
#################################################################
111
# event section: specify in App
112
113
self.MsgWindow = py.shell.Shell(self)
114
# Create a sizer to manage the Canvas and message window
115
MainSizer = wx.BoxSizer(wx.VERTICAL)
116
MainSizer.Add(self.browser, 4, wx.EXPAND)
117
MainSizer.Add(self.MsgWindow, 1, wx.EXPAND | wx.ALL, 5)
118
119
self.SetSizer(MainSizer)
120
#self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
121
122
self.EventsAreBound = False
123
124
#wx.EVT_BUTTON(self, 1003, self.on_close)
125
# wx.EVT_CLOSE(self, self.on_close)
126
#wx.EVT_IDLE(self, self.on_idle)
127
def show_progress(self, percent, **kwargs):
128
pass
129
130
def get_args(self):
131
pass
132
133
def browse_obj(self, obj, **kwargs):
134
self.browser.change_obj(obj, **kwargs)
135
136
def get_obj(self):
137
return self.browser.get_obj()
138
139
def make_menu(self):
140
# event section
141
#wx.EVT_BUTTON(self._mainframe, 1003, self.on_close)
142
wx.EVT_CLOSE(self, self.on_close)
143
#wx.EVT_IDLE(self._mainframe, self.on_idle)
144
145
# print 'make_menu'
146
menubar = self.menubar
147
menubar.append_menu('Object')
148
149
menubar.append_item('Object/open...',
150
self.on_open,
151
info='Open a object from a Python binary file.',
152
bitmap=wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_MENU),
153
)
154
155
menubar.append_item('Object/browse',
156
self.on_browse_obj, # common function in modulegui
157
info='View and browse object in object panel.',
158
bitmap=wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, wx.ART_MENU),
159
)
160
161
menubar.append_item('Object/safe as',
162
self.on_save_as, shortkey='Ctrl+S',
163
info='Save current scenario in a Python binary file.',
164
bitmap=wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_MENU),
165
)
166
167
self.make_menu_specific()
168
169
def make_menu_specific(self):
170
"""Here we can add App specific main menu items"""
171
pass
172
173
def on_close(self, event):
174
self.destroy()
175
176
def on_exit(self, event):
177
"""Close browser application"""
178
dlg = wx.MessageDialog(self,
179
'Browser is about to close.\nDo you want to SAVE the current object before closing?',
180
'Closing Browser',
181
wx.YES_NO | wx.CANCEL | wx.ICON_QUESTION)
182
ans = dlg.ShowModal()
183
dlg.Destroy()
184
# print ' ans,wx.ID_CANCEL,wx.ID_YES,wx.ID_NO',ans,wx.ID_CANCEL,wx.ID_YES,wx.ID_NO
185
if ans == wx.ID_CANCEL:
186
# print ' do not quit!'
187
pass
188
189
elif ans == wx.ID_YES:
190
# print ' save and quit'
191
self.on_save_as(event)
192
self.destroy()
193
194
elif ans == wx.ID_NO:
195
# print 'quit immediately'
196
self._mainframe.destroy()
197
198
def on_open(self, event=None):
199
"""
200
Opens object from a binary file.
201
"""
202
wildcards_all = "All files (*.*)|*.*"
203
wildcards_obj = "Python binary files (*.obj)|*.obj"
204
wildcards = wildcards_obj+"|"+wildcards_all
205
206
# Finally, if the directory is changed in the process of getting files, this
207
# dialog is set up to change the current working directory to the path chosen.
208
dlg = wx.FileDialog(self, message="Open object file",
209
#defaultDir = scenario.get_workdirpath(),
210
#defaultFile = os.path.join(scenario.get_workdirpath(), scenario.format_ident()+'.obj'),
211
wildcard=wildcards,
212
style=wx.OPEN | wx.CHANGE_DIR
213
)
214
215
# Show the dialog and retrieve the user response. If it is the OK response,
216
# process the data.
217
if dlg.ShowModal() == wx.ID_OK:
218
# This returns a Python list of files that were selected.
219
filepath = dlg.GetPath()
220
if len(filepath) > 0:
221
obj = cm.load_obj(filepath)
222
self.browse_obj(obj)
223
224
# Destroy the dialog. Don't do this until you are done with it!
225
dlg.Destroy()
226
227
def on_browse_obj(self, event=None):
228
"""
229
Browse main object.
230
"""
231
self.browse_obj(self.get_obj())
232
233
def on_save_as(self, event=None):
234
"""
235
Saves current object into a binary file.
236
"""
237
obj = self.get_obj()
238
wildcards_all = "All files (*.*)|*.*"
239
wildcards_obj = "Python binary files (*.obj)|*.obj"
240
wildcards = wildcards_obj+"|"+wildcards_all
241
242
# Finally, if the directory is changed in the process of getting files, this
243
# dialog is set up to change the current working directory to the path chosen.
244
dlg = wx.FileDialog(
245
self, message="Save Object to file",
246
#defaultDir = scenario.get_workdirpath(),
247
#defaultFile = scenario.get_rootfilepath()+'.obj',
248
wildcard=wildcards,
249
style=wx.SAVE | wx.CHANGE_DIR
250
)
251
252
# Show the dialog and retrieve the user response. If it is the OK response,
253
# process the data.
254
if dlg.ShowModal() == wx.ID_OK:
255
# This returns a Python list of files that were selected.
256
filepath = dlg.GetPath()
257
if len(filepath) > 0:
258
# now set new filename and workdir
259
260
cm.save_obj(obj, filepath)
261
262
# Destroy the dialog. Don't do this until you are done with it!
263
# BAD things can happen otherwise!
264
dlg.Destroy()
265
266
def add_view(self, name, ViewClass, **args):
267
pass
268
269
def select_view(self, ind=0, name=None):
270
pass
271
272
def on_size(self, event=None):
273
pass
274
275
276
class ObjBrowserApp(wx.App):
277
"""
278
279
"""
280
281
def OnInit(self):
282
wx.InitAllImageHandlers()
283
#DrawFrame = BuildDrawFrame()
284
#frame = ObjBrowserMainframe(None, -1, "Object browser",wx.DefaultPosition,(700,700),obj=self._obj, _id = self._id)
285
frame = ObjBrowserMainframe(obj=self._obj, table=None, parent=None,
286
title='Object browser', appname='Object browser app',
287
logger=self._logger,
288
appdir='', is_maximize=False, is_centerscreen=True,
289
pos=wx.DefaultPosition, size=wx.DefaultSize,
290
style=wx.DEFAULT_FRAME_STYLE,
291
name='Object browser frame', size_toolbaricons=(24, 24))
292
self.SetTopWindow(frame)
293
frame.Show()
294
295
return True
296
297