def OnInit(self): util.timing.begin("wxApplication OnInit") #@@@Temporary testing tool written by Morgen -- DJA """ Main application initialization. """ self.needsUpdateUI = True self.ignoreSynchronizeWidget = True self.focus = None wx.InitAllImageHandlers() """ Disable automatic calling of UpdateUIEvents. We will call them manually when blocks get rendered, change visibility, etc. """ wx.UpdateUIEvent.SetUpdateInterval (-1) """ Install a custom displayhook to keep Python from setting the global _ (underscore) to the value of the last evaluated expression. If we don't do this, our mapping of _ to gettext can get overwritten. This is useful in interactive debugging with PyShell. """ def _displayHook(obj): if obj is not None: print repr(obj) sys.displayhook = _displayHook assert Globals.wxApplication == None, "We can have only one application" Globals.wxApplication = self """ Initialize PARCELPATH and sys.path """ parcelPath = Utility.initParcelEnv(Globals.chandlerDirectory, Globals.options.parcelPath) """ Splash Screen. We don't show the splash screen when nosplash is set """ splash = None if not Globals.options.nosplash: splashBitmap = self.GetImage ("splash.png") splash=StartupSplash(None, splashBitmap) splash.Show() wx.Yield() #let the splash screen render itself """ Setup internationalization To experiment with a different locale, try 'fr' and wx.LANGUAGE_FRENCH """ os.environ['LANGUAGE'] = 'en' # self.locale = wx.Locale(wx.LANGUAGE_ENGLISH) """ @@@ Sets the python locale, used by wx.CalendarCtrl for month and weekday names. When running on Linux, 'en' is not understood as a locale, nor is 'fr'. On Windows, you can try 'fr'. locale.setlocale(locale.LC_ALL, 'en') """ # wx.Locale_AddCatalogLookupPathPrefix('locale') # self.locale.AddCatalog('Chandler.mo') gettext.install('chandler', 'locale') """ Crypto initialization """ if splash: splash.updateGauge('crypto') Utility.initCrypto(Globals.options.profileDir) if splash: splash.updateGauge('repository') # The repository opening code was moved to a method so that it can # be called again if there is a schema mismatch and the user chooses # to reopen the repository in create mode. repoDir = Utility.locateRepositoryDirectory(Globals.options.profileDir) try: view = Utility.initRepository(repoDir, Globals.options) except RepositoryVersionError: if self.ShowSchemaMismatchWindow(): Globals.options.create = True view = Utility.initRepository(repoDir, Globals.options) else: raise Utility.SchemaMismatchError self.repository = view.repository """ Verify Schema Version """ if not Utility.verifySchema(view): if self.ShowSchemaMismatchWindow(): # Blow away the repository self.repository.close() Globals.options.create = True view = Utility.initRepository(repoDir, Globals.options) self.repository = view.repository else: raise Utility.SchemaMismatchError self.UIRepositoryView = view # make our view be the default for schema API # so when we say myClass.iterItems() and leave off the view # we get the UI repository view. schema.reset(self.UIRepositoryView) """ Load Parcels """ if splash: splash.updateGauge('parcels') wx.Yield() Utility.initParcels(view, parcelPath) EVT_MAIN_THREAD_CALLBACK(self, self.OnMainThreadCallbackEvent) """ The Twisted Reactor should be started before other Managers and stopped last. """ if splash: splash.updateGauge('twisted') Utility.initTwisted() mainViewRoot = self.LoadMainViewRoot(delete=Globals.options.refreshui) if (mainViewRoot.position.x == -1 and mainViewRoot.position.y == -1): position = wx.DefaultPosition else: position = (mainViewRoot.position.x, mainViewRoot.position.y) # arel: fix for bug involving window size and toolbar on MacOS (bug 3411). # The problem is that mainFrame gets resized when it is rendered # (particularly when the toolbar gets rendered), increasing the window's # height by the height of the toolbar. We fix by remembering the # (correct) size before rendering and resizing. rememberSize = (mainViewRoot.size.width, mainViewRoot.size.height) self.mainFrame = MainFrame(None, -1, "Chandler", pos=position, size=(mainViewRoot.size.width, mainViewRoot.size.height), style=wx.DEFAULT_FRAME_STYLE) mainViewRoot.frame = self.mainFrame """ Register to some global events for name lookup. """ if splash: splash.updateGauge('globalevents') globalEvents = self.UIRepositoryView.findPath('//parcels/osaf/framework/blocks/GlobalEvents') from osaf.framework.blocks.Block import Block Block.addToNameToItemUUIDDictionary (globalEvents.eventsForNamedLookup, Block.eventNameToItemUUID) self.ignoreSynchronizeWidget = False if splash: splash.updateGauge('mainview') self.RenderMainView () if Globals.options.profile: import hotshot, hotshot.stats prof = hotshot.Profile(os.path.join(Globals.options.profileDir, 'commit.log')) prof.runcall(self.UIRepositoryView.commit) prof.close() stats = hotshot.stats.load(os.path.join(Globals.options.profileDir, 'commit.log')) stats.strip_dirs() stats.sort_stats('time', 'calls') stats.print_stats(125) else: wx.Yield() self.UIRepositoryView.commit() if splash: splash.Destroy() #OnDestroyWindow Binding has to appear after splash.Destroy self.Bind(wx.EVT_IDLE, self.OnIdle) self.Bind(wx.EVT_MENU, self.OnCommand, id=-1) self.Bind(wx.EVT_TOOL, self.OnCommand, id=-1) self.Bind(wx.EVT_UPDATE_UI, self.OnCommand, id=-1) self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroyWindow, id=-1) self.Bind(wx.EVT_SHOW, self.OnShow, id=-1) self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) # resize to intended size. (bug 3411) self.mainFrame.SetSize(rememberSize) self.mainFrame.Show() """Start the WakeupCaller Service""" Utility.initWakeup(self.UIRepositoryView.repository) """Start the Chandler Mail Service""" from osaf.mail.mailservice import MailService Globals.mailService = MailService(self.UIRepositoryView.repository) Globals.mailService.startup() util.timing.end("wxApplication OnInit") #@@@Temporary testing tool written by Morgen -- DJA # data loading script execution if Globals.options.createData: import tools.GenerateItemsFromFile as GenerateItemsFromFile GenerateItemsFromFile.RunScript(Globals.mainViewRoot.itsView, Globals.views[0]) return True #indicates we succeeded with initialization
def OnInit(self): util.timing.begin( "wxApplication OnInit" ) #@@@Temporary testing tool written by Morgen -- DJA """ Main application initialization. """ self.needsUpdateUI = True self.ignoreSynchronizeWidget = True self.focus = None wx.InitAllImageHandlers() """ Disable automatic calling of UpdateUIEvents. We will call them manually when blocks get rendered, change visibility, etc. """ wx.UpdateUIEvent.SetUpdateInterval(-1) """ Install a custom displayhook to keep Python from setting the global _ (underscore) to the value of the last evaluated expression. If we don't do this, our mapping of _ to gettext can get overwritten. This is useful in interactive debugging with PyShell. """ def _displayHook(obj): if obj is not None: print repr(obj) sys.displayhook = _displayHook assert Globals.wxApplication == None, "We can have only one application" Globals.wxApplication = self """ Initialize PARCELPATH and sys.path """ parcelPath = Utility.initParcelEnv(Globals.chandlerDirectory, Globals.options.parcelPath) """ Splash Screen. We don't show the splash screen when nosplash is set """ splash = None if not Globals.options.nosplash: splashBitmap = self.GetImage("splash.png") splash = StartupSplash(None, splashBitmap) splash.Show() wx.Yield() #let the splash screen render itself """ Setup internationalization To experiment with a different locale, try 'fr' and wx.LANGUAGE_FRENCH """ os.environ['LANGUAGE'] = 'en' # self.locale = wx.Locale(wx.LANGUAGE_ENGLISH) """ @@@ Sets the python locale, used by wx.CalendarCtrl for month and weekday names. When running on Linux, 'en' is not understood as a locale, nor is 'fr'. On Windows, you can try 'fr'. locale.setlocale(locale.LC_ALL, 'en') """ # wx.Locale_AddCatalogLookupPathPrefix('locale') # self.locale.AddCatalog('Chandler.mo') gettext.install('chandler', 'locale') """ Crypto initialization """ if splash: splash.updateGauge('crypto') Utility.initCrypto(Globals.options.profileDir) if splash: splash.updateGauge('repository') # The repository opening code was moved to a method so that it can # be called again if there is a schema mismatch and the user chooses # to reopen the repository in create mode. repoDir = Utility.locateRepositoryDirectory(Globals.options.profileDir) try: view = Utility.initRepository(repoDir, Globals.options) except RepositoryVersionError: if self.ShowSchemaMismatchWindow(): Globals.options.create = True view = Utility.initRepository(repoDir, Globals.options) else: raise Utility.SchemaMismatchError self.repository = view.repository """ Verify Schema Version """ if not Utility.verifySchema(view): if self.ShowSchemaMismatchWindow(): # Blow away the repository self.repository.close() Globals.options.create = True view = Utility.initRepository(repoDir, Globals.options) self.repository = view.repository else: raise Utility.SchemaMismatchError self.UIRepositoryView = view # make our view be the default for schema API # so when we say myClass.iterItems() and leave off the view # we get the UI repository view. schema.reset(self.UIRepositoryView) """ Load Parcels """ if splash: splash.updateGauge('parcels') wx.Yield() Utility.initParcels(view, parcelPath) EVT_MAIN_THREAD_CALLBACK(self, self.OnMainThreadCallbackEvent) """ The Twisted Reactor should be started before other Managers and stopped last. """ if splash: splash.updateGauge('twisted') Utility.initTwisted() mainViewRoot = self.LoadMainViewRoot(delete=Globals.options.refreshui) if (mainViewRoot.position.x == -1 and mainViewRoot.position.y == -1): position = wx.DefaultPosition else: position = (mainViewRoot.position.x, mainViewRoot.position.y) # arel: fix for bug involving window size and toolbar on MacOS (bug 3411). # The problem is that mainFrame gets resized when it is rendered # (particularly when the toolbar gets rendered), increasing the window's # height by the height of the toolbar. We fix by remembering the # (correct) size before rendering and resizing. rememberSize = (mainViewRoot.size.width, mainViewRoot.size.height) self.mainFrame = MainFrame(None, -1, "Chandler", pos=position, size=(mainViewRoot.size.width, mainViewRoot.size.height), style=wx.DEFAULT_FRAME_STYLE) mainViewRoot.frame = self.mainFrame """ Register to some global events for name lookup. """ if splash: splash.updateGauge('globalevents') globalEvents = self.UIRepositoryView.findPath( '//parcels/osaf/framework/blocks/GlobalEvents') from osaf.framework.blocks.Block import Block Block.addToNameToItemUUIDDictionary(globalEvents.eventsForNamedLookup, Block.eventNameToItemUUID) self.ignoreSynchronizeWidget = False if splash: splash.updateGauge('mainview') self.RenderMainView() if Globals.options.profile: import hotshot, hotshot.stats prof = hotshot.Profile( os.path.join(Globals.options.profileDir, 'commit.log')) prof.runcall(self.UIRepositoryView.commit) prof.close() stats = hotshot.stats.load( os.path.join(Globals.options.profileDir, 'commit.log')) stats.strip_dirs() stats.sort_stats('time', 'calls') stats.print_stats(125) else: wx.Yield() self.UIRepositoryView.commit() if splash: splash.Destroy() #OnDestroyWindow Binding has to appear after splash.Destroy self.Bind(wx.EVT_IDLE, self.OnIdle) self.Bind(wx.EVT_MENU, self.OnCommand, id=-1) self.Bind(wx.EVT_TOOL, self.OnCommand, id=-1) self.Bind(wx.EVT_UPDATE_UI, self.OnCommand, id=-1) self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroyWindow, id=-1) self.Bind(wx.EVT_SHOW, self.OnShow, id=-1) self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) # resize to intended size. (bug 3411) self.mainFrame.SetSize(rememberSize) self.mainFrame.Show() """Start the WakeupCaller Service""" Utility.initWakeup(self.UIRepositoryView.repository) """Start the Chandler Mail Service""" from osaf.mail.mailservice import MailService Globals.mailService = MailService(self.UIRepositoryView.repository) Globals.mailService.startup() util.timing.end("wxApplication OnInit" ) #@@@Temporary testing tool written by Morgen -- DJA # data loading script execution if Globals.options.createData: import tools.GenerateItemsFromFile as GenerateItemsFromFile GenerateItemsFromFile.RunScript(Globals.mainViewRoot.itsView, Globals.views[0]) return True #indicates we succeeded with initialization