def __init__(self, parent=None, title='mainframe', moduledirs=[], args=[], is_maximize=False, is_centerscreen=True, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE, name='theframe', size_toolbaricons=(24, 24)): self._args = args # Forcing a specific style on the window. # Should this include styles passed? wx.Frame.__init__(self, parent, wx.ID_ANY, title, pos, size=size, style=style, name=name) #super(GLFrame, self).__init__(parent, id, title, pos, size, style, name) self._splitter = MainSplitter(self) self._views = {} #wx.EVT_SIZE (self, self.on_size) #sizer=wx.BoxSizer(wx.VERTICAL) #sizer.Add(p1,0, wx.ALL | wx.ALIGN_LEFT | wx.GROW, 4)# from NaviPanelTest #sizer.Add(self.canvas,1,wx.GROW)# from NaviPanelTest # finish panel setup #self.SetSizer(sizer) #sizer.Fit(self) #self.Show() # this is needed to initialize GL projections for unproject #wx.CallAfter(self.on_size) #width,height = self.GetSize() #self._splitter.SetSashPosition(300, True) #maximize the frame if is_maximize: self.Maximize() if is_centerscreen: self.CenterOnScreen() ################################################################# # create statusbar #self.statusbar = AgileStatusbar(self) self.statusbar = AgileStatusbar(self) self.SetStatusBar(self.statusbar) #self.count=0.0 ################################################################# # create toolbar self.init_toolbar(size=size_toolbaricons) # #new_bmp = wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_TOOLBAR, tsize) #open_bmp = wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR, tsize) #save_bmp= wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_TOOLBAR, tsize) #cut_bmp = wx.ArtProvider.GetBitmap(wx.ART_CUT, wx.ART_TOOLBAR, tsize) #copy_bmp = wx.ArtProvider.GetBitmap(wx.ART_COPY, wx.ART_TOOLBAR, tsize) #paste_bmp= wx.ArtProvider.GetBitmap(wx.ART_PASTE, wx.ART_TOOLBAR, tsize) #self.add_tool('new',self.on_open,new_bmp,'create new doc') #self.add_tool('open',self.on_open,open_bmp,'Open doc') #self.add_tool('save',self.on_save,save_bmp,'Save doc') #self.toolbar.AddSeparator() #self.add_tool('cut',self.on_open,cut_bmp,'Cut') #self.add_tool('copy',self.on_open,copy_bmp,'Copy') #self.add_tool('paste',self.on_open,paste_bmp,'Paste') #self.SetToolBar(self.toolbar) ################################################################# #create the menu bar self.menubar = AgileMenubar(self) #self.make_menu() #self.menubar.append_menu('tools') self.SetMenuBar(self.menubar) #self.Show(True) #NO!! ################################################################# # init logger self._logger = Logger() self._logger.add_callback(self.write_message, 'message') self._logger.add_callback(self.write_action, 'action') ################################################################# self._moduleguis = make_moduleguis(moduledirs) for modulename, modulegui in self._moduleguis.iteritems(): #print ' init gui of module',modulename modulegui.init_widgets(self)
def __init__( self, parent, process, title=None, func_close=None, is_close_after_completion=True, ): if title is None: title = process.get_name() wx.Frame.__init__(self, parent, -1, title=title, pos=wx.DefaultPosition, size=wx.DefaultSize) self.parent = parent self.process = process self.func_close = func_close #if self.func_close is None: self.is_close_after_completion = is_close_after_completion #else: # self.is_close_after_completion = False #self._is_run = False self.Bind(wx.EVT_TIMER, self.on_step) self.timer = wx.Timer(self) ## Set up the MenuBar #MenuBar = wx.MenuBar() #file_menu = wx.Menu() #item = file_menu.Append(-1, "&Import CSV...","Import OD data from a CSV text file with format <zonename orig>, <zonename dest>,<number of trips>") #self.Bind(wx.EVT_MENU, self.on_import_csv, item) #item = file_menu.Append(-1, "&Import Exel...","Import OD data from an Exel file.") #self.Bind(wx.EVT_MENU, self.on_import_exel, item) #help_menu = wx.Menu() #item = help_menu.Append(-1, "&About", # "More information About this program") #self.Bind(wx.EVT_MENU, self.on_menu, item) #MenuBar.Append(help_menu, "&Help") #self.SetMenuBar(MenuBar) ################################################################# # create statusbar #self.statusbar = AgileStatusbar(self) self.statusbar = AgileStatusbar( self, fields=[ # ('action',-4), ('message', -10), #('coords',-1), #('zoom',-1), ('progress', -3), ('status', -1), #('coords',-1), ]) self.SetStatusBar(self.statusbar) #self.count=0.0 logger = process.get_logger() self.oldprogressfunc = logger.get_clallbackfunc('progress') logger.add_callback(self.show_progress, 'progress') self.oldmessagefunc = logger.get_clallbackfunc('message') logger.add_callback(self.write_message, 'message') ################################################################# # create toolbar #self.init_toolbar(size=size_toolbaricons) self.browser = self.make_browser() ##Create a sizer to manage the Canvas and message window MainSizer = wx.BoxSizer(wx.VERTICAL) MainSizer.Add(self.browser, 4, wx.EXPAND) self.SetSizer(MainSizer) self.Bind(wx.EVT_CLOSE, self.on_close) #self.Bind(wx.EVT_IDLE, self.on_idle) self.EventsAreBound = False ## getting all the colors for random objects #wxlib.colourdb.updateColourDB() #self.colors = wxlib.colourdb.getColourList() return None
class AgileMainframe(AgileToolbarFrameMixin, wx.Frame): """ Simple wx frame with some special features. """ def __init__(self, parent=None, title='mainframe', moduledirs=[], args=[], is_maximize=False, is_centerscreen=True, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE, name='theframe', size_toolbaricons=(24, 24)): self._args = args # Forcing a specific style on the window. # Should this include styles passed? wx.Frame.__init__(self, parent, wx.ID_ANY, title, pos, size=size, style=style, name=name) #super(GLFrame, self).__init__(parent, id, title, pos, size, style, name) self._splitter = MainSplitter(self) self._views = {} #wx.EVT_SIZE (self, self.on_size) #sizer=wx.BoxSizer(wx.VERTICAL) #sizer.Add(p1,0, wx.ALL | wx.ALIGN_LEFT | wx.GROW, 4)# from NaviPanelTest #sizer.Add(self.canvas,1,wx.GROW)# from NaviPanelTest # finish panel setup #self.SetSizer(sizer) #sizer.Fit(self) #self.Show() # this is needed to initialize GL projections for unproject #wx.CallAfter(self.on_size) #width,height = self.GetSize() #self._splitter.SetSashPosition(300, True) #maximize the frame if is_maximize: self.Maximize() if is_centerscreen: self.CenterOnScreen() ################################################################# # create statusbar #self.statusbar = AgileStatusbar(self) self.statusbar = AgileStatusbar(self) self.SetStatusBar(self.statusbar) #self.count=0.0 ################################################################# # create toolbar self.init_toolbar(size=size_toolbaricons) # #new_bmp = wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_TOOLBAR, tsize) #open_bmp = wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR, tsize) #save_bmp= wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_TOOLBAR, tsize) #cut_bmp = wx.ArtProvider.GetBitmap(wx.ART_CUT, wx.ART_TOOLBAR, tsize) #copy_bmp = wx.ArtProvider.GetBitmap(wx.ART_COPY, wx.ART_TOOLBAR, tsize) #paste_bmp= wx.ArtProvider.GetBitmap(wx.ART_PASTE, wx.ART_TOOLBAR, tsize) #self.add_tool('new',self.on_open,new_bmp,'create new doc') #self.add_tool('open',self.on_open,open_bmp,'Open doc') #self.add_tool('save',self.on_save,save_bmp,'Save doc') #self.toolbar.AddSeparator() #self.add_tool('cut',self.on_open,cut_bmp,'Cut') #self.add_tool('copy',self.on_open,copy_bmp,'Copy') #self.add_tool('paste',self.on_open,paste_bmp,'Paste') #self.SetToolBar(self.toolbar) ################################################################# #create the menu bar self.menubar = AgileMenubar(self) #self.make_menu() #self.menubar.append_menu('tools') self.SetMenuBar(self.menubar) #self.Show(True) #NO!! ################################################################# # init logger self._logger = Logger() self._logger.add_callback(self.write_message, 'message') self._logger.add_callback(self.write_action, 'action') ################################################################# self._moduleguis = make_moduleguis(moduledirs) for modulename, modulegui in self._moduleguis.iteritems(): #print ' init gui of module',modulename modulegui.init_widgets(self) ################################################################# ## event section: specify in App #wx.EVT_BUTTON(self, 1003, self.on_close) # wx.EVT_CLOSE(self, self.on_close) #wx.EVT_IDLE(self, self.on_idle) def refresh_moduleguis(self): #print 'refresh_moduleguis',len(self._moduleguis) self.browse_obj(None) for modulename, modulegui in self._moduleguis.iteritems(): #print ' refresh gui of module',modulename modulegui.refresh_widgets() def get_modulegui(self, modulename): return self._moduleguis[modulename] def write_message(self, text, **kwargs): self.statusbar.write_message(text) def write_action(self, text, **kwargs): self.statusbar.write_action(text) self.statusbar.write_message('') def get_logger(self): return self._logger def set_logger(self, logger): self._logger = logger def get_args(self): return self._args def browse_obj(self, obj, **kwargs): self._splitter.browse_obj(obj, **kwargs) def make_menu(self): """ Creates manu. To be overridden. """ self.menubar.append_menu('file') self.menubar.append_menu('file/doc') self.menubar.append_item('file/doc/open',self.on_open,\ shortkey='Ctrl+o',info='open it out') self.menubar.append_item('file/doc/save',self.on_save,\ shortkey='Ctrl+s',info='save it out') #self.menubar.append_menu('edit') #self.menubar.append_item('edit/cut',self.cut,\ # shortkey='Ctrl+c',info='cut it out') #self.menubar.append_item('edit/toggle',self.toggle_tools,\ # shortkey='Ctrl+t',info='toggle tools') def add_view(self, name, ViewClass, **args): """ Add a new view to the notebook. """ #print 'context.add_view',ViewClass #print ' args',args view = self._splitter.add_view(name, ViewClass, **args) self._views[name] = view #self._viewtabs.SetSelection(p) #self._splitter._viewtabs.Show(True) return view def select_view(self, ind=0): self._splitter.select_view(ind=ind) def on_size(self, event=None): print 'Mainframe.on_size' #self.tc.SetSize(self.GetSize()) #self.tc.SetSize(self.GetSize()) #self._viewtabs.SetSize(self.GetSize()) #pass #wx.LayoutAlgorithm().LayoutWindow(self, self.p1) #wx.LayoutAlgorithm().LayoutWindow(self, self.p1) # important: #wx.LayoutAlgorithm().LayoutWindow(self, self._viewtabs) wx.LayoutAlgorithm().LayoutWindow(self, self._splitter) if event: event.Skip() def on_save(self, event): print 'save it!!' def on_open(self, event): """Open a document""" #wildcards = CreateWildCards() + "All files (*.*)|*.*" print 'open it!!' def destroy(self): """Destroy this object""" ##self.theDocManager.theDestructor() #imgPreferences.saveXml(self.GetStartDirectory() + "/" + imgINI_FILE_NAME) ##del self.thePrint self.Destroy() def on_close(self, event): #self.Close(True) print 'Mainframe.on_close' #pass self.destroy() def on_exit(self, event): """Called when the application is to be finished""" self.destroy() def on_idle(self, event): pass #self.count = self.count + 1 #if self.count >= 100: # self.count = 0 #self.statusbar.set_progress(self.count) def on_about(self, event): """Display the information about this application""" #dlg = imgDlgAbout(self, -1, "") #dlg.ShowModal() #dlg.Destroy() pass def write_to_statusbar(self, data, key='message'): self.statusbar[key] = str(data)
class ProcessDialogInteractive(ProcessDialogMixin, wx.Frame): """ A frame used for the ObjBrowser Demo """ def __init__( self, parent, process, title=None, func_close=None, is_close_after_completion=True, ): if title is None: title = process.get_name() wx.Frame.__init__(self, parent, -1, title=title, pos=wx.DefaultPosition, size=wx.DefaultSize) self.parent = parent self.process = process self.func_close = func_close #if self.func_close is None: self.is_close_after_completion = is_close_after_completion #else: # self.is_close_after_completion = False #self._is_run = False self.Bind(wx.EVT_TIMER, self.on_step) self.timer = wx.Timer(self) ## Set up the MenuBar #MenuBar = wx.MenuBar() #file_menu = wx.Menu() #item = file_menu.Append(-1, "&Import CSV...","Import OD data from a CSV text file with format <zonename orig>, <zonename dest>,<number of trips>") #self.Bind(wx.EVT_MENU, self.on_import_csv, item) #item = file_menu.Append(-1, "&Import Exel...","Import OD data from an Exel file.") #self.Bind(wx.EVT_MENU, self.on_import_exel, item) #help_menu = wx.Menu() #item = help_menu.Append(-1, "&About", # "More information About this program") #self.Bind(wx.EVT_MENU, self.on_menu, item) #MenuBar.Append(help_menu, "&Help") #self.SetMenuBar(MenuBar) ################################################################# # create statusbar #self.statusbar = AgileStatusbar(self) self.statusbar = AgileStatusbar( self, fields=[ # ('action',-4), ('message', -10), #('coords',-1), #('zoom',-1), ('progress', -3), ('status', -1), #('coords',-1), ]) self.SetStatusBar(self.statusbar) #self.count=0.0 logger = process.get_logger() self.oldprogressfunc = logger.get_clallbackfunc('progress') logger.add_callback(self.show_progress, 'progress') self.oldmessagefunc = logger.get_clallbackfunc('message') logger.add_callback(self.write_message, 'message') ################################################################# # create toolbar #self.init_toolbar(size=size_toolbaricons) self.browser = self.make_browser() ##Create a sizer to manage the Canvas and message window MainSizer = wx.BoxSizer(wx.VERTICAL) MainSizer.Add(self.browser, 4, wx.EXPAND) self.SetSizer(MainSizer) self.Bind(wx.EVT_CLOSE, self.on_close) #self.Bind(wx.EVT_IDLE, self.on_idle) self.EventsAreBound = False ## getting all the colors for random objects #wxlib.colourdb.updateColourDB() #self.colors = wxlib.colourdb.getColourList() return None def _get_buttons(self): if hasattr(self.process, 'step'): buttons = [ ('Start', self.on_start, 'Start the process!'), ('Stop', self.on_stop, 'Stop process.'), ('Step', self.on_singlestep, 'Make a single step.'), ('Done', self.on_done, 'Stop process and close window.'), ] defaultbutton = 'Start' else: if self.is_close_after_completion: buttons = [ ('Run', self.on_start, 'Start the process!'), ] else: buttons = [ ('Run', self.on_start, 'Start the process!'), ('Done', self.on_done, 'Finish with process and close window.'), ] defaultbutton = 'Run' buttons.append(('Cancel', self.on_close, 'Close window, without running the process.')) #standartbuttons=['cancel'] # uses also standard on_cancel :( standartbuttons = [] return buttons, defaultbutton, standartbuttons #def on_idle(self,event): # print 'on_idle' # # if self._is_run: # self.process.step() # if self.process.status=='success': # self._is_run = False # self.Destroy() def on_start(self, event=None): self.browser.apply() if self.process.status != 'running': self.process.update_params() #self.refresh_browser() # TODO: check whether to use ALWAYS run to put process in running mode if hasattr(self.process, 'step'): self.process.do() else: self.process.run() # no closing function defined if self.is_close_after_completion: self.on_close(event) #print 'on_start: after preparation self.process.status=',self.process.status if hasattr(self.process, 'step'): self.timer.Start(1) #while self.process.status=='running': # print 'call step' # self.process.step() #if self.process.status=='running': # # this will call step method in on_idle # self._is_run = True # #elif self.process.status=='preparation': # self.process.update_params() # self.refresh_browser() # self.process.run() def on_step(self, event=None): if self.process.status == 'running': #print 'call step' self.process.step() else: print ' Simulation finished' self.timer.Stop() def on_stop(self, event=None): self.timer.Stop() def on_singlestep(self, event=None): if self.process.status == 'running': if hasattr(self.process, 'step'): wx.FutureCall(1, self.process.step) def on_close(self, event=None): #print 'on_close',self.process.status if self.process.status == 'running': self.process.aboard() #print ' aboarded.' self.MakeModal(False) #print ' call func_close',self.func_close if self.func_close is not None: self.func_close(self) #print ' reput callbacks to main' if self.oldprogressfunc is not None: self.process.get_logger().add_callback(self.oldprogressfunc, 'progress') if self.oldmessagefunc is not None: self.process.get_logger().add_callback(self.oldmessagefunc, 'message') #print ' call destroy' self.Destroy() #self.Close() # no effect def on_done(self, event=None): #print 'on_done',self.process.status self.on_close(event) def on_cancel(self, event): """ Apply values, destroy itself and parent """ #print 'on_cancel' self.on_close(event) def on_kill(self, event=None): #self.process.kill() pass def show_progress(self, percent, **kwargs): """ Shows progress on progress bar. Plug-in funcion for logger. """ #print 'show_progress',percent self.statusbar.set_progress(percent) #self.Refresh() #wx.Yield() #self.Update() def write_message(self, text, **kwargs): print 'write_message', text self.statusbar.write_message(text) def make_browser(self): buttons, defaultbutton, standartbuttons = self._get_buttons() browser = objpanel.ObjPanel( self, self.process, attrconfigs=None, id=None, ids=None, groupnames=['options', 'inputparameters'], func_change_obj=None, show_groupnames=False, show_title=False, is_modal=True, mainframe=None, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.MAXIMIZE_BOX | wx.RESIZE_BORDER, immediate_apply=False, #True, panelstyle='default', buttons=buttons, standartbuttons=standartbuttons, defaultbutton=defaultbutton, ) return browser def refresh_browser(self): """ Deletes previous conents Builds panel for obj Updates path window and history """ #print 'Wizzard.refresh_panel with',obj.ident # remove previous obj panel sizer = self.GetSizer() sizer.Remove(0) self.browser.Destroy() #del self.browser self.browser = self.make_browser() sizer.Add(self.browser, 1, wx.GROW) self.Refresh() #sizer.Fit(self) sizer.Layout()
def __init__(self, parent=None, title='mainframe', moduledirs=[], args=[], appdir='', is_maximize=False, is_centerscreen=True, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE, name='theframe', size_toolbaricons=(24, 24)): self._args = args # print 'AgileMainframe.__init__',title,appdir # Forcing a specific style on the window. # Should this include styles passed? wx.Frame.__init__(self, parent, wx.ID_ANY, title, pos, size=size, style=style, name=name) #super(GLFrame, self).__init__(parent, id, title, pos, size, style, name) self._splitter = MainSplitter(self) self._views = {} #wx.EVT_SIZE (self, self.on_size) # sizer=wx.BoxSizer(wx.VERTICAL) # sizer.Add(p1,0, wx.ALL | wx.ALIGN_LEFT | wx.GROW, 4)# from NaviPanelTest # sizer.Add(self.canvas,1,wx.GROW)# from NaviPanelTest # finish panel setup # self.SetSizer(sizer) # sizer.Fit(self) # self.Show() # this is needed to initialize GL projections for unproject # wx.CallAfter(self.on_size) #width,height = self.GetSize() #self._splitter.SetSashPosition(300, True) # maximize the frame if is_maximize: self.Maximize() if is_centerscreen: self.CenterOnScreen() ################################################################# # create statusbar #self.statusbar = AgileStatusbar(self) self.statusbar = AgileStatusbar(self) self.SetStatusBar(self.statusbar) # self.count=0.0 ################################################################# # create toolbar self.init_toolbar(size=size_toolbaricons) # #new_bmp = wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_TOOLBAR, tsize) #open_bmp = wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR, tsize) #save_bmp= wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_TOOLBAR, tsize) #cut_bmp = wx.ArtProvider.GetBitmap(wx.ART_CUT, wx.ART_TOOLBAR, tsize) #copy_bmp = wx.ArtProvider.GetBitmap(wx.ART_COPY, wx.ART_TOOLBAR, tsize) #paste_bmp= wx.ArtProvider.GetBitmap(wx.ART_PASTE, wx.ART_TOOLBAR, tsize) #self.add_tool('new',self.on_open,new_bmp,'create new doc') #self.add_tool('open',self.on_open,open_bmp,'Open doc') #self.add_tool('save',self.on_save,save_bmp,'Save doc') # self.toolbar.AddSeparator() # self.add_tool('cut',self.on_open,cut_bmp,'Cut') # self.add_tool('copy',self.on_open,copy_bmp,'Copy') # self.add_tool('paste',self.on_open,paste_bmp,'Paste') # self.SetToolBar(self.toolbar) ################################################################# # create the menu bar self.menubar = AgileMenubar(self) # self.make_menu() # self.menubar.append_menu('tools') self.SetMenuBar(self.menubar) # self.Show(True) #NO!! ################################################################# # init logger self._logger = Logger() self._logger.add_callback(self.write_message, 'message') self._logger.add_callback(self.write_action, 'action') self._logger.add_callback(self.show_progress, 'progress') ################################################################# self._moduleguis = make_moduleguis(appdir, moduledirs) for modulename, modulegui in self._moduleguis.iteritems(): # print ' init gui of module',modulename modulegui.init_widgets(self)
class AgileMainframe(AgileToolbarFrameMixin, wx.Frame): """ Simple wx frame with some special features. """ def __init__(self, parent=None, title='mainframe', moduledirs=[], args=[], appdir='', is_maximize=False, is_centerscreen=True, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE, name='theframe', size_toolbaricons=(24, 24)): self._args = args # print 'AgileMainframe.__init__',title,appdir # Forcing a specific style on the window. # Should this include styles passed? wx.Frame.__init__(self, parent, wx.ID_ANY, title, pos, size=size, style=style, name=name) #super(GLFrame, self).__init__(parent, id, title, pos, size, style, name) self._splitter = MainSplitter(self) self._views = {} #wx.EVT_SIZE (self, self.on_size) # sizer=wx.BoxSizer(wx.VERTICAL) # sizer.Add(p1,0, wx.ALL | wx.ALIGN_LEFT | wx.GROW, 4)# from NaviPanelTest # sizer.Add(self.canvas,1,wx.GROW)# from NaviPanelTest # finish panel setup # self.SetSizer(sizer) # sizer.Fit(self) # self.Show() # this is needed to initialize GL projections for unproject # wx.CallAfter(self.on_size) #width,height = self.GetSize() #self._splitter.SetSashPosition(300, True) # maximize the frame if is_maximize: self.Maximize() if is_centerscreen: self.CenterOnScreen() ################################################################# # create statusbar #self.statusbar = AgileStatusbar(self) self.statusbar = AgileStatusbar(self) self.SetStatusBar(self.statusbar) # self.count=0.0 ################################################################# # create toolbar self.init_toolbar(size=size_toolbaricons) # #new_bmp = wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_TOOLBAR, tsize) #open_bmp = wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR, tsize) #save_bmp= wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_TOOLBAR, tsize) #cut_bmp = wx.ArtProvider.GetBitmap(wx.ART_CUT, wx.ART_TOOLBAR, tsize) #copy_bmp = wx.ArtProvider.GetBitmap(wx.ART_COPY, wx.ART_TOOLBAR, tsize) #paste_bmp= wx.ArtProvider.GetBitmap(wx.ART_PASTE, wx.ART_TOOLBAR, tsize) #self.add_tool('new',self.on_open,new_bmp,'create new doc') #self.add_tool('open',self.on_open,open_bmp,'Open doc') #self.add_tool('save',self.on_save,save_bmp,'Save doc') # self.toolbar.AddSeparator() # self.add_tool('cut',self.on_open,cut_bmp,'Cut') # self.add_tool('copy',self.on_open,copy_bmp,'Copy') # self.add_tool('paste',self.on_open,paste_bmp,'Paste') # self.SetToolBar(self.toolbar) ################################################################# # create the menu bar self.menubar = AgileMenubar(self) # self.make_menu() # self.menubar.append_menu('tools') self.SetMenuBar(self.menubar) # self.Show(True) #NO!! ################################################################# # init logger self._logger = Logger() self._logger.add_callback(self.write_message, 'message') self._logger.add_callback(self.write_action, 'action') self._logger.add_callback(self.show_progress, 'progress') ################################################################# self._moduleguis = make_moduleguis(appdir, moduledirs) for modulename, modulegui in self._moduleguis.iteritems(): # print ' init gui of module',modulename modulegui.init_widgets(self) ################################################################# # event section: specify in App #wx.EVT_BUTTON(self, 1003, self.on_close) # wx.EVT_CLOSE(self, self.on_close) #wx.EVT_IDLE(self, self.on_idle) def refresh_moduleguis(self): # print 'refresh_moduleguis',len(self._moduleguis) self.browse_obj(None) for modulename, modulegui in self._moduleguis.iteritems(): # print ' refresh gui of module',modulename modulegui.refresh_widgets() def get_modulegui(self, modulename): return self._moduleguis[modulename] def write_message(self, text, **kwargs): self.statusbar.write_message(text) def write_action(self, text, **kwargs): self.statusbar.write_action(text) self.statusbar.write_message('') def show_progress(self, percent, **kwargs): self.statusbar.set_progress(percent) def get_logger(self): return self._logger def set_logger(self, logger): self._logger = logger def get_args(self): return self._args def browse_obj(self, obj, **kwargs): self._splitter.browse_obj(obj, **kwargs) def make_menu(self): """ Creates manu. To be overridden. """ self.menubar.append_menu('file') self.menubar.append_menu('file/doc') self.menubar.append_item('file/doc/open', self.on_open, shortkey='Ctrl+o', info='open it out') self.menubar.append_item('file/doc/save', self.on_save, shortkey='Ctrl+s', info='save it out') # self.menubar.append_menu('edit') # self.menubar.append_item('edit/cut',self.cut,\ # shortkey='Ctrl+c',info='cut it out') # self.menubar.append_item('edit/toggle',self.toggle_tools,\ # shortkey='Ctrl+t',info='toggle tools') def add_view(self, name, ViewClass, **args): """ Add a new view to the notebook. """ # print 'context.add_view',ViewClass # print ' args',args view = self._splitter.add_view(name, ViewClass, **args) self._views[name] = view # self._viewtabs.SetSelection(p) # self._splitter._viewtabs.Show(True) return view def select_view(self, ind=0, name=None): self._splitter.select_view(ind=ind, name=name) def on_size(self, event=None): # print 'Mainframe.on_size' # self.tc.SetSize(self.GetSize()) # self.tc.SetSize(self.GetSize()) # self._viewtabs.SetSize(self.GetSize()) # pass #wx.LayoutAlgorithm().LayoutWindow(self, self.p1) #wx.LayoutAlgorithm().LayoutWindow(self, self.p1) # important: #wx.LayoutAlgorithm().LayoutWindow(self, self._viewtabs) wx.LayoutAlgorithm().LayoutWindow(self, self._splitter) # if event: # event.Skip() def on_save(self, event): print 'save it!!' def on_open(self, event): """Open a document""" #wildcards = CreateWildCards() + "All files (*.*)|*.*" print 'open it!!' def destroy(self): """Destroy this object""" # self.theDocManager.theDestructor() #imgPreferences.saveXml(self.GetStartDirectory() + "/" + imgINI_FILE_NAME) ##del self.thePrint self.Destroy() def on_close(self, event): # self.Close(True) print 'Mainframe.on_close' # pass self.destroy() def on_exit(self, event): """Called when the application is to be finished""" self.destroy() def on_idle(self, event): pass #self.count = self.count + 1 # if self.count >= 100: # self.count = 0 # self.statusbar.set_progress(self.count) def on_about(self, event): """Display the information about this application""" #dlg = imgDlgAbout(self, -1, "") # dlg.ShowModal() # dlg.Destroy() pass def write_to_statusbar(self, data, key='message'): self.statusbar[key] = str(data)
def __init__(self, parent, process, title='Process Dialog', func_close=None): wx.Frame.__init__(self, parent, -1, title=title, pos=wx.DefaultPosition, size=wx.DefaultSize) self.parent = parent self.process = process self.func_close = func_close #self._is_run = False self.Bind(wx.EVT_TIMER, self.on_step) self.timer = wx.Timer(self) # Set up the MenuBar #MenuBar = wx.MenuBar() #file_menu = wx.Menu() #item = file_menu.Append(-1, "&Import CSV...","Import OD data from a CSV text file with format <zonename orig>, <zonename dest>,<number of trips>") #self.Bind(wx.EVT_MENU, self.on_import_csv, item) #item = file_menu.Append(-1, "&Import Exel...","Import OD data from an Exel file.") #self.Bind(wx.EVT_MENU, self.on_import_exel, item) #help_menu = wx.Menu() # item = help_menu.Append(-1, "&About", # "More information About this program") #self.Bind(wx.EVT_MENU, self.on_menu, item) #MenuBar.Append(help_menu, "&Help") # self.SetMenuBar(MenuBar) ################################################################# # create statusbar #self.statusbar = AgileStatusbar(self) self.statusbar = AgileStatusbar(self, fields=[ # ('action',-4), ('message', -10), # ('coords',-1), # ('zoom',-1), ('progress', -3), ('status', -1), # ('coords',-1), ]) self.SetStatusBar(self.statusbar) # self.count=0.0 logger = process.get_logger() self.oldprogressfunc = logger.get_clallbackfunc('progress') logger.add_callback(self.show_progress, 'progress') self.oldmessagefunc = logger.get_clallbackfunc('message') logger.add_callback(self.write_message, 'message') ################################################################# # create toolbar # self.init_toolbar(size=size_toolbaricons) self.browser = self.make_browser() # Create a sizer to manage the Canvas and message window MainSizer = wx.BoxSizer(wx.VERTICAL) MainSizer.Add(self.browser, 4, wx.EXPAND) self.SetSizer(MainSizer) self.Bind(wx.EVT_CLOSE, self.on_close) #self.Bind(wx.EVT_IDLE, self.on_idle) self.EventsAreBound = False # getting all the colors for random objects # wxlib.colourdb.updateColourDB() #self.colors = wxlib.colourdb.getColourList() return None
class ProcessDialogInteractive(ProcessDialogMixin, wx.Frame): """ A frame used for the ObjBrowser Demo """ def __init__(self, parent, process, title='Process Dialog', func_close=None): wx.Frame.__init__(self, parent, -1, title=title, pos=wx.DefaultPosition, size=wx.DefaultSize) self.parent = parent self.process = process self.func_close = func_close #self._is_run = False self.Bind(wx.EVT_TIMER, self.on_step) self.timer = wx.Timer(self) # Set up the MenuBar #MenuBar = wx.MenuBar() #file_menu = wx.Menu() #item = file_menu.Append(-1, "&Import CSV...","Import OD data from a CSV text file with format <zonename orig>, <zonename dest>,<number of trips>") #self.Bind(wx.EVT_MENU, self.on_import_csv, item) #item = file_menu.Append(-1, "&Import Exel...","Import OD data from an Exel file.") #self.Bind(wx.EVT_MENU, self.on_import_exel, item) #help_menu = wx.Menu() # item = help_menu.Append(-1, "&About", # "More information About this program") #self.Bind(wx.EVT_MENU, self.on_menu, item) #MenuBar.Append(help_menu, "&Help") # self.SetMenuBar(MenuBar) ################################################################# # create statusbar #self.statusbar = AgileStatusbar(self) self.statusbar = AgileStatusbar(self, fields=[ # ('action',-4), ('message', -10), # ('coords',-1), # ('zoom',-1), ('progress', -3), ('status', -1), # ('coords',-1), ]) self.SetStatusBar(self.statusbar) # self.count=0.0 logger = process.get_logger() self.oldprogressfunc = logger.get_clallbackfunc('progress') logger.add_callback(self.show_progress, 'progress') self.oldmessagefunc = logger.get_clallbackfunc('message') logger.add_callback(self.write_message, 'message') ################################################################# # create toolbar # self.init_toolbar(size=size_toolbaricons) self.browser = self.make_browser() # Create a sizer to manage the Canvas and message window MainSizer = wx.BoxSizer(wx.VERTICAL) MainSizer.Add(self.browser, 4, wx.EXPAND) self.SetSizer(MainSizer) self.Bind(wx.EVT_CLOSE, self.on_close) #self.Bind(wx.EVT_IDLE, self.on_idle) self.EventsAreBound = False # getting all the colors for random objects # wxlib.colourdb.updateColourDB() #self.colors = wxlib.colourdb.getColourList() return None def _get_buttons(self): if hasattr(self.process, 'step'): buttons = [('Start', self.on_start, 'Start the process!'), ('Stop', self.on_stop, 'Stop process.'), ('Step', self.on_singlestep, 'Make a single step.'), ('Done', self.on_done, 'Stop process and close window.'), ] defaultbutton = 'Start' standartbuttons = [] else: buttons = [('Run', self.on_start, 'Start the process!'), ('Done', self.on_done, 'Finish with process and close window.'), ] defaultbutton = 'Start' standartbuttons = [] return buttons, defaultbutton, standartbuttons # def on_idle(self,event): # print 'on_idle' # # if self._is_run: # self.process.step() # if self.process.status=='success': # self._is_run = False # self.Destroy() def on_start(self, event=None): self.browser.apply() if self.process.status != 'running': self.process.update_params() # self.refresh_browser() # TODO: check whether to use ALWAYS run to put process in running mode if hasattr(self.process, 'step'): self.process.do() else: self.process.run() # print 'on_start: after preparation self.process.status=',self.process.status if hasattr(self.process, 'step'): self.timer.Start(1) # while self.process.status=='running': # print 'call step' # self.process.step() # if self.process.status=='running': # # this will call step method in on_idle # self._is_run = True # # elif self.process.status=='preparation': # self.process.update_params() # self.refresh_browser() # self.process.run() def on_step(self, event=None): if self.process.status == 'running': # print 'call step' self.process.step() else: print ' Simulation finished' self.timer.Stop() def on_stop(self, event=None): self.timer.Stop() def on_singlestep(self, event=None): if self.process.status == 'running': if hasattr(self.process, 'step'): wx.FutureCall(1, self.process.step) def on_close(self, event=None): print 'on_close', self.process.status if self.process.status == 'running': self.process.aboard() print ' aboarded.' self.MakeModal(False) if self.func_close is not None: self.func_close(self) if self.oldprogressfunc is not None: self.process.get_logger().add_callback(self.oldprogressfunc, 'progress') if self.oldmessagefunc is not None: self.process.get_logger().add_callback(self.oldmessagefunc, 'message') self.Destroy() def on_done(self, event=None): # print 'on_done',self.process.status self.on_close(event) def on_kill(self, event=None): # self.process.kill() pass def show_progress(self, percent, **kwargs): print 'show_progress', percent self.statusbar.set_progress(percent) # self.Refresh() # wx.Yield() # self.Update() def write_message(self, text, **kwargs): print 'write_message', text self.statusbar.write_message(text) def make_browser(self): buttons, defaultbutton, standartbuttons = self._get_buttons() browser = objpanel.ObjPanel(self, self.process, attrconfigs=None, id=None, ids=None, groupnames=['options', 'inputparameters'], func_change_obj=None, show_groupnames=False, show_title=False, is_modal=True, mainframe=None, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.MAXIMIZE_BOX | wx.RESIZE_BORDER, immediate_apply=False, # True, panelstyle='default', buttons=buttons, standartbuttons=standartbuttons, defaultbutton=defaultbutton, ) return browser def refresh_browser(self): """ Deletes previous conents Builds panel for obj Updates path window and history """ # print 'Wizzard.refresh_panel with',obj.ident # remove previous obj panel sizer = self.GetSizer() sizer.Remove(0) self.browser.Destroy() #del self.browser self.browser = self.make_browser() sizer.Add(self.browser, 1, wx.GROW) self.Refresh() # sizer.Fit(self) sizer.Layout()