Path: blob/main/tools/contributed/sumopy/agilepy/lib_wx/objbrowser.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 objbrowser.py15# @author Joerg Schweizer16# @date 20121718import wx19from objpanel import *20from mainframe import AgileMainframe, AgileStatusbar, AgileMenubar212223class ObjBrowserMainframe(AgileMainframe):24def __init__(self, obj=None, table=None, _id=None, parent=None,25title='Object browser', appname='Object browser app',26moduledirs=[], args=[], appdir='',27is_maximize=False, is_centerscreen=True,28pos=wx.DefaultPosition, size=wx.DefaultSize,29style=wx.DEFAULT_FRAME_STYLE, logger=None,30name='Object browser frame', size_toolbaricons=(24, 24)):3132# print 'AgileMainframe.__init__',title,appdir3334# Forcing a specific style on the window.35# Should this include styles passed?3637if appname is not None:38self.appname = appname39else:40self.appname = title41wx.Frame.__init__(self, parent, wx.ID_ANY, self.appname,42pos, size=size, style=style, name=name)4344if obj is not None:45# print ' init ObjPanel'46#self.browser = ObjPanel(self, obj)47self.browser = NaviPanel(self, obj, _id)48elif table is not None:49# print ' init TablePanel'50self.browser = TablePanel(self, table)51else:52obj = cm.BaseObjman('empty')53self.browser = NaviPanel(self, obj, _id)5455if logger is not None:56self._logger = logger57else:58self._logger = Logger()5960if is_maximize:61self.Maximize()62if is_centerscreen:63self.CenterOnScreen()6465#################################################################66# create statusbar67self.statusbar = AgileStatusbar(self)68self.SetStatusBar(self.statusbar)69# self.count=0.07071#################################################################72# create toolbar7374self.init_toolbar(size=size_toolbaricons)75#76#new_bmp = wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_TOOLBAR, tsize)77#open_bmp = wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR, tsize)78#save_bmp= wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_TOOLBAR, tsize)79#cut_bmp = wx.ArtProvider.GetBitmap(wx.ART_CUT, wx.ART_TOOLBAR, tsize)80#copy_bmp = wx.ArtProvider.GetBitmap(wx.ART_COPY, wx.ART_TOOLBAR, tsize)81#paste_bmp= wx.ArtProvider.GetBitmap(wx.ART_PASTE, wx.ART_TOOLBAR, tsize)8283#self.add_tool('new',self.on_open,new_bmp,'create new doc')84#self.add_tool('open',self.on_open,open_bmp,'Open doc')85#self.add_tool('save',self.on_save,save_bmp,'Save doc')86# self.toolbar.AddSeparator()87# self.add_tool('cut',self.on_open,cut_bmp,'Cut')88# self.add_tool('copy',self.on_open,copy_bmp,'Copy')89# self.add_tool('paste',self.on_open,paste_bmp,'Paste')9091# self.SetToolBar(self.toolbar)9293#################################################################94# create the menu bar9596self.menubar = AgileMenubar(self)97self.make_menu()98# self.menubar.append_menu('tools')99self.SetMenuBar(self.menubar)100101#################################################################102# init logger103#self._logger = Logger()104#self._logger.add_callback(self.write_message, 'message')105#self._logger.add_callback(self.write_action, 'action')106#self._logger.add_callback(self.show_progress, 'progress')107#################################################################108109#################################################################110# event section: specify in App111112self.MsgWindow = py.shell.Shell(self)113# Create a sizer to manage the Canvas and message window114MainSizer = wx.BoxSizer(wx.VERTICAL)115MainSizer.Add(self.browser, 4, wx.EXPAND)116MainSizer.Add(self.MsgWindow, 1, wx.EXPAND | wx.ALL, 5)117118self.SetSizer(MainSizer)119#self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)120121self.EventsAreBound = False122123#wx.EVT_BUTTON(self, 1003, self.on_close)124# wx.EVT_CLOSE(self, self.on_close)125#wx.EVT_IDLE(self, self.on_idle)126def show_progress(self, percent, **kwargs):127pass128129def get_args(self):130pass131132def browse_obj(self, obj, **kwargs):133self.browser.change_obj(obj, **kwargs)134135def get_obj(self):136return self.browser.get_obj()137138def make_menu(self):139# event section140#wx.EVT_BUTTON(self._mainframe, 1003, self.on_close)141wx.EVT_CLOSE(self, self.on_close)142#wx.EVT_IDLE(self._mainframe, self.on_idle)143144# print 'make_menu'145menubar = self.menubar146menubar.append_menu('Object')147148menubar.append_item('Object/open...',149self.on_open,150info='Open a object from a Python binary file.',151bitmap=wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_MENU),152)153154menubar.append_item('Object/browse',155self.on_browse_obj, # common function in modulegui156info='View and browse object in object panel.',157bitmap=wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, wx.ART_MENU),158)159160menubar.append_item('Object/safe as',161self.on_save_as, shortkey='Ctrl+S',162info='Save current scenario in a Python binary file.',163bitmap=wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_MENU),164)165166self.make_menu_specific()167168def make_menu_specific(self):169"""Here we can add App specific main menu items"""170pass171172def on_close(self, event):173self.destroy()174175def on_exit(self, event):176"""Close browser application"""177dlg = wx.MessageDialog(self,178'Browser is about to close.\nDo you want to SAVE the current object before closing?',179'Closing Browser',180wx.YES_NO | wx.CANCEL | wx.ICON_QUESTION)181ans = dlg.ShowModal()182dlg.Destroy()183# print ' ans,wx.ID_CANCEL,wx.ID_YES,wx.ID_NO',ans,wx.ID_CANCEL,wx.ID_YES,wx.ID_NO184if ans == wx.ID_CANCEL:185# print ' do not quit!'186pass187188elif ans == wx.ID_YES:189# print ' save and quit'190self.on_save_as(event)191self.destroy()192193elif ans == wx.ID_NO:194# print 'quit immediately'195self._mainframe.destroy()196197def on_open(self, event=None):198"""199Opens object from a binary file.200"""201wildcards_all = "All files (*.*)|*.*"202wildcards_obj = "Python binary files (*.obj)|*.obj"203wildcards = wildcards_obj+"|"+wildcards_all204205# Finally, if the directory is changed in the process of getting files, this206# dialog is set up to change the current working directory to the path chosen.207dlg = wx.FileDialog(self, message="Open object file",208#defaultDir = scenario.get_workdirpath(),209#defaultFile = os.path.join(scenario.get_workdirpath(), scenario.format_ident()+'.obj'),210wildcard=wildcards,211style=wx.OPEN | wx.CHANGE_DIR212)213214# Show the dialog and retrieve the user response. If it is the OK response,215# process the data.216if dlg.ShowModal() == wx.ID_OK:217# This returns a Python list of files that were selected.218filepath = dlg.GetPath()219if len(filepath) > 0:220obj = cm.load_obj(filepath)221self.browse_obj(obj)222223# Destroy the dialog. Don't do this until you are done with it!224dlg.Destroy()225226def on_browse_obj(self, event=None):227"""228Browse main object.229"""230self.browse_obj(self.get_obj())231232def on_save_as(self, event=None):233"""234Saves current object into a binary file.235"""236obj = self.get_obj()237wildcards_all = "All files (*.*)|*.*"238wildcards_obj = "Python binary files (*.obj)|*.obj"239wildcards = wildcards_obj+"|"+wildcards_all240241# Finally, if the directory is changed in the process of getting files, this242# dialog is set up to change the current working directory to the path chosen.243dlg = wx.FileDialog(244self, message="Save Object to file",245#defaultDir = scenario.get_workdirpath(),246#defaultFile = scenario.get_rootfilepath()+'.obj',247wildcard=wildcards,248style=wx.SAVE | wx.CHANGE_DIR249)250251# Show the dialog and retrieve the user response. If it is the OK response,252# process the data.253if dlg.ShowModal() == wx.ID_OK:254# This returns a Python list of files that were selected.255filepath = dlg.GetPath()256if len(filepath) > 0:257# now set new filename and workdir258259cm.save_obj(obj, filepath)260261# Destroy the dialog. Don't do this until you are done with it!262# BAD things can happen otherwise!263dlg.Destroy()264265def add_view(self, name, ViewClass, **args):266pass267268def select_view(self, ind=0, name=None):269pass270271def on_size(self, event=None):272pass273274275class ObjBrowserApp(wx.App):276"""277278"""279280def OnInit(self):281wx.InitAllImageHandlers()282#DrawFrame = BuildDrawFrame()283#frame = ObjBrowserMainframe(None, -1, "Object browser",wx.DefaultPosition,(700,700),obj=self._obj, _id = self._id)284frame = ObjBrowserMainframe(obj=self._obj, table=None, parent=None,285title='Object browser', appname='Object browser app',286logger=self._logger,287appdir='', is_maximize=False, is_centerscreen=True,288pos=wx.DefaultPosition, size=wx.DefaultSize,289style=wx.DEFAULT_FRAME_STYLE,290name='Object browser frame', size_toolbaricons=(24, 24))291self.SetTopWindow(frame)292frame.Show()293294return True295296297