コード例 #1
0
ファイル: raven.py プロジェクト: mpm2050/Raven
    def __init__(self):
        self._initGlobalSettings()
        self.systemProfile = self._createSystemProfile()
        self.resourceRegistry = ZSystemResourceRegistry(self.systemProfile)

        self.applicationModel = ZBlogApplicationModel()
        self.applicationModel.setSystemProfile(self.systemProfile)
        self.applicationModel.setResourceRegistry(self.resourceRegistry)

        setApplicationModel(self.applicationModel)
コード例 #2
0
ファイル: raven.py プロジェクト: Tidosho/zoundryraven
    def __init__(self):
        self._initGlobalSettings()
        self.systemProfile = self._createSystemProfile()
        self.resourceRegistry = ZSystemResourceRegistry(self.systemProfile)

        self.applicationModel = ZBlogApplicationModel()
        self.applicationModel.setSystemProfile(self.systemProfile)
        self.applicationModel.setResourceRegistry(self.resourceRegistry)

        setApplicationModel(self.applicationModel)
コード例 #3
0
ファイル: raven.py プロジェクト: Tidosho/zoundryraven
class RavenApplication:

    def __init__(self):
        self._initGlobalSettings()
        self.systemProfile = self._createSystemProfile()
        self.resourceRegistry = ZSystemResourceRegistry(self.systemProfile)

        self.applicationModel = ZBlogApplicationModel()
        self.applicationModel.setSystemProfile(self.systemProfile)
        self.applicationModel.setResourceRegistry(self.resourceRegistry)

        setApplicationModel(self.applicationModel)

    # end __init__()

    # Set up global settings like path to bundle files, etc.
    def _initGlobalSettings(self):
        cmdLineParams = ZCommandLineParameters(sys.argv[1:])
        setCommandLineParameters(cmdLineParams)

        # Add an uncaught exception hook so that we can display a dialog if something bad happens.
        sys.excepthook = self.handleException

        # If the application is installed (not in dev-mode), redirect stderr and stdout.
        # FIXME (EPW) hook up the stderr/stdout to the logger at some point
        if getOSUtil().isInstalledAsExe():
            stdPath = getOSUtil().getApplicationDataDirectory()
            if isPortableEnabled():
                stdPath = getOSUtil().getInstallDirectory()

            stdoutFile = os.path.join(stdPath, u"stdout.txt") #$NON-NLS-1$
            stderrFile = os.path.join(stdPath, u"stderr.txt") #$NON-NLS-1$
            sys.stderr = open(stderrFile, u"w")  #$NON-NLS-1$
            sys.stdout = open(stdoutFile, u"w") #$NON-NLS-1$

        # Set up the string bundle path.
        installDir = os.path.join(getOSUtil().getInstallDirectory(), u"system/bundles") #$NON-NLS-1$
        os.environ[IZI18NConstants.BUNDLE_PATH_ENV_VAR] = installDir

        # The MakeActiveXClass wrapper must be explicitely imported or
        # else instantiating the mshtml wrapper will hard-crash :(
        # FIXME (EPW) move this into an osutil init phase - to eliminate a dependency on Win32 stuff
        from wx.lib.activexwrapper import MakeActiveXClass #@UnusedImport
                
    # end _initGlobalSettings()
    
    def _initProxyConfiguration(self):
        # Get proxy settings from user prefs.        
        userProfile = self.applicationModel.getUserProfile()
        prefs = userProfile.getPreferences()
        enabled = prefs.getUserPreferenceBool(IZAppUserPrefsKeys.PROXY_ENABLE, False)
        host = prefs.getUserPreference(IZAppUserPrefsKeys.PROXY_HOST, u"") #$NON-NLS-1$
        port = prefs.getUserPreferenceInt(IZAppUserPrefsKeys.PROXY_PORT, u"") #$NON-NLS-1$
        username = prefs.getUserPreference(IZAppUserPrefsKeys.PROXY_USERNAME, u"") #$NON-NLS-1$
        password = prefs.getUserPreference(IZAppUserPrefsKeys.PROXY_PASSWORD, u"") #$NON-NLS-1$
        if password:
            password = crypt.decryptCipherText(password, PASSWORD_ENCRYPTION_KEY)
        proxy = ZHttpProxyConfiguration()
        proxy.setEnable(enabled)
        proxy.setHost(host)
        if port > 0:
            proxy.setPort(port)
        proxy.setProxyAuthorization(username, password)
    # end _initProxyConfiguration()

    def handleException(self, type, value, tb):
        # Log the exception in the logger
        zexception = None
        if isinstance(value, ZException):
            zexception = value
        elif isinstance(value, Exception):
            zexception = ZException(rootCause = value)
        else:
            zexception = ZException(unicode(value), None, (type, value, tb))
        getLoggerService().exception(zexception)
        # Show the error to the user.
        ZShowExceptionWithFeedback(getApplicationModel().getTopWindow(), zexception)
    # end handleException()

    def run(self):
        from zoundry.blogapp.startup import RavenApplicationStartup
        from zoundry.blogapp.ui.appwindow import ZRavenApplicationWindow
        from zoundry.blogapp.ui.splash import ZStartupWindow

        client = ZRavenRPCClient()

        # First, check for blogThis
        blogThisInfo = checkCmdLineForBlogThis()
        if blogThisInfo is not None:
            client.blogThis(blogThisInfo)

        # Only allow one instance of the application to be running.
        if client.getVersion() is not None:
            client.bringToFront()
            return

        # Create the user profile (return if none is found/chosen)
        userProfile = self._createUserProfile()
        if not userProfile:
            return
        self.applicationModel.setUserProfile(userProfile)
        
        # set http proxy settings based on userprofile config
        self._initProxyConfiguration()

        # Startup the Engine (load plugins, etc...)
        splashApp = wx.PySimpleApp()
        try:
            splashWindow = ZStartupWindow()
            appStartup = RavenApplicationStartup(self.applicationModel, splashWindow)
            appStartup.start()
            splashApp.MainLoop()

            if appStartup.hasStartupErrors():
                raise ZBlogAppException(_extstr(u"raven.StartupErrorsFoundMsg")) #$NON-NLS-1$
        except Exception, e:
            ZShowExceptionMessage(None, e)
        del splashApp

        # Create the main application window.
        mainApp = wx.PySimpleApp()
        try:
            mainWindow = ZRavenApplicationWindow()
            self.applicationModel.setTopWindow(mainWindow)
            mainApp.MainLoop()
        except Exception, e:
            ZShowExceptionMessage(None, e)
コード例 #4
0
ファイル: raven.py プロジェクト: mpm2050/Raven
class RavenApplication:
    def __init__(self):
        self._initGlobalSettings()
        self.systemProfile = self._createSystemProfile()
        self.resourceRegistry = ZSystemResourceRegistry(self.systemProfile)

        self.applicationModel = ZBlogApplicationModel()
        self.applicationModel.setSystemProfile(self.systemProfile)
        self.applicationModel.setResourceRegistry(self.resourceRegistry)

        setApplicationModel(self.applicationModel)

    # end __init__()

    # Set up global settings like path to bundle files, etc.
    def _initGlobalSettings(self):
        cmdLineParams = ZCommandLineParameters(sys.argv[1:])
        setCommandLineParameters(cmdLineParams)

        # Add an uncaught exception hook so that we can display a dialog if something bad happens.
        sys.excepthook = self.handleException

        # If the application is installed (not in dev-mode), redirect stderr and stdout.
        # FIXME (EPW) hook up the stderr/stdout to the logger at some point
        if getOSUtil().isInstalledAsExe():
            stdPath = getOSUtil().getApplicationDataDirectory()
            if isPortableEnabled():
                stdPath = getOSUtil().getInstallDirectory()

            stdoutFile = os.path.join(stdPath, u"stdout.txt")  #$NON-NLS-1$
            stderrFile = os.path.join(stdPath, u"stderr.txt")  #$NON-NLS-1$
            sys.stderr = open(stderrFile, u"w")  #$NON-NLS-1$
            sys.stdout = open(stdoutFile, u"w")  #$NON-NLS-1$

        # Set up the string bundle path.
        installDir = os.path.join(getOSUtil().getInstallDirectory(),
                                  u"system/bundles")  #$NON-NLS-1$
        os.environ[IZI18NConstants.BUNDLE_PATH_ENV_VAR] = installDir

        # The MakeActiveXClass wrapper must be explicitely imported or
        # else instantiating the mshtml wrapper will hard-crash :(
        # FIXME (EPW) move this into an osutil init phase - to eliminate a dependency on Win32 stuff
        from wx.lib.activexwrapper import MakeActiveXClass  #@UnusedImport

    # end _initGlobalSettings()

    def _initProxyConfiguration(self):
        # Get proxy settings from user prefs.
        userProfile = self.applicationModel.getUserProfile()
        prefs = userProfile.getPreferences()
        enabled = prefs.getUserPreferenceBool(IZAppUserPrefsKeys.PROXY_ENABLE,
                                              False)
        host = prefs.getUserPreference(IZAppUserPrefsKeys.PROXY_HOST,
                                       u"")  #$NON-NLS-1$
        port = prefs.getUserPreferenceInt(IZAppUserPrefsKeys.PROXY_PORT,
                                          u"")  #$NON-NLS-1$
        username = prefs.getUserPreference(IZAppUserPrefsKeys.PROXY_USERNAME,
                                           u"")  #$NON-NLS-1$
        password = prefs.getUserPreference(IZAppUserPrefsKeys.PROXY_PASSWORD,
                                           u"")  #$NON-NLS-1$
        if password:
            password = crypt.decryptCipherText(password,
                                               PASSWORD_ENCRYPTION_KEY)
        proxy = ZHttpProxyConfiguration()
        proxy.setEnable(enabled)
        proxy.setHost(host)
        if port > 0:
            proxy.setPort(port)
        proxy.setProxyAuthorization(username, password)

    # end _initProxyConfiguration()

    def handleException(self, type, value, tb):
        # Log the exception in the logger
        zexception = None
        if isinstance(value, ZException):
            zexception = value
        elif isinstance(value, Exception):
            zexception = ZException(rootCause=value)
        else:
            zexception = ZException(unicode(value), None, (type, value, tb))
        getLoggerService().exception(zexception)
        # Show the error to the user.
        ZShowExceptionWithFeedback(getApplicationModel().getTopWindow(),
                                   zexception)

    # end handleException()

    def run(self):
        from zoundry.blogapp.startup import RavenApplicationStartup
        from zoundry.blogapp.ui.appwindow import ZRavenApplicationWindow
        from zoundry.blogapp.ui.splash import ZStartupWindow

        client = ZRavenRPCClient()

        # First, check for blogThis
        blogThisInfo = checkCmdLineForBlogThis()
        if blogThisInfo is not None:
            client.blogThis(blogThisInfo)

        # Only allow one instance of the application to be running.
        if client.getVersion() is not None:
            client.bringToFront()
            return

        # Create the user profile (return if none is found/chosen)
        userProfile = self._createUserProfile()
        if not userProfile:
            return
        self.applicationModel.setUserProfile(userProfile)

        # set http proxy settings based on userprofile config
        self._initProxyConfiguration()

        # Startup the Engine (load plugins, etc...)
        splashApp = wx.PySimpleApp()
        try:
            splashWindow = ZStartupWindow()
            appStartup = RavenApplicationStartup(self.applicationModel,
                                                 splashWindow)
            appStartup.start()
            splashApp.MainLoop()

            if appStartup.hasStartupErrors():
                raise ZBlogAppException(
                    _extstr(u"raven.StartupErrorsFoundMsg"))  #$NON-NLS-1$
        except Exception, e:
            ZShowExceptionMessage(None, e)
        del splashApp

        # Create the main application window.
        mainApp = wx.PySimpleApp()
        try:
            mainWindow = ZRavenApplicationWindow()
            self.applicationModel.setTopWindow(mainWindow)
            mainApp.MainLoop()
        except Exception, e:
            ZShowExceptionMessage(None, e)