示例#1
0
class OutWikerApplication(wx.App):
    """
    OutWiker application class
    """
    def __init__(self, application):
        self.logFileName = u"outwiker.log"
        self._application = application

        config = TextPrintConfig(self._application.config)
        self.normalFont = config.fontName.value
        self.monoFont = config.fontName.value

        if APP_DATA_DEBUG not in self._application.sharedData:
            config = GeneralGuiConfig(self._application.config)
            self._application.sharedData[APP_DATA_DEBUG] = config.debug.value

        super().__init__()

    def OnInit(self):
        self.Bind(wx.EVT_QUERY_END_SESSION, self._onEndSession)
        NullTranslations().install()
        return True

    def initMainWindow(self):
        self.mainWnd = MainWindow(self._application)
        self.SetTopWindow(self.mainWnd)

        self._application.mainWindow = self.mainWnd
        self._application.actionController = ActionController(
            self.mainWnd, self._application.config)

        registerActions(self._application)
        self.mainWnd.createGui()
        self.initPrinting()

    def initPrinting(self):
        self.printing = wx.html.HtmlEasyPrinting(parentWindow=self.mainWnd)
        self.printing.SetFonts(self.normalFont, self.monoFont,
                               list(range(10, 17)))

    def destroyMainWindow(self):
        self.mainWnd.Destroy()
        self.mainWnd = None
        self._application.mainWindow = None
        self._application = None

    def loadPlugins(self):
        self._application.plugins.load(getPluginsDirList())

    def showMainWindow(self):
        config = TrayConfig(self._application.config)
        if (config.startIconized.value
                and not self._application.sharedData.get(
                    APP_DATA_DISABLE_MINIMIZING, False)):
            self.mainWnd.Iconize(True)
        else:
            self.mainWnd.Show()

        self.mainWnd.taskBarIconController.updateTrayIcon()

    def initLogger(self):
        level = (logging.DEBUG if self._application.sharedData.get(
            APP_DATA_DEBUG, False) else logging.WARNING)

        redirector = LogRedirector(
            self.getLogFileName(self._application.fullConfigPath), level)

        redirector.init()
        wx.Log.SetLogLevel(0)

    def _onEndSession(self, event):
        self.Unbind(wx.EVT_QUERY_END_SESSION, handler=self._onEndSession)
        self.mainWnd.Destroy()

    def getLogFileName(self, configPath):
        return os.path.join(os.path.split(configPath)[0], self.logFileName)

    def bindActivateApp(self):
        """
        Подключиться к событию при потере фокуса приложением
        """
        self.Bind(wx.EVT_ACTIVATE_APP, self._onActivate)

    def unbindActivateApp(self):
        """
        Отключиться от события при потере фокуса приложением
        """
        self.Unbind(wx.EVT_ACTIVATE_APP)

    def _onActivate(self, event):
        self._application.onForceSave()

    @property
    def application(self):
        return self._application
示例#2
0
class OutWikerApplication(wx.App):
    """
    OutWiker application class
    """
    def __init__(self, application):
        super().__init__()
        self.logFileName = u"outwiker.log"
        self._application = application

        self.use_fake_html_render = False

    def OnInit(self):
        self.Bind(wx.EVT_QUERY_END_SESSION, self._onEndSession)
        NullTranslations().install()
        return True

    def initMainWindow(self):
        self.mainWnd = MainWindow(self._application)
        self.SetTopWindow(self.mainWnd)

        self._application.mainWindow = self.mainWnd
        self._application.actionController = ActionController(
            self.mainWnd, self._application.config)

        registerActions(self._application)
        self.mainWnd.createGui()

    def destroyMainWindow(self):
        self.mainWnd.Destroy()
        self.mainWnd = None
        self._application.mainWindow = None
        self._application = None

    def loadPlugins(self):
        self._application.plugins.load(getPluginsDirList())

    def showMainWindow(self, allowMinimizingMainWindow=True):
        config = TrayConfig(self._application.config)
        if config.startIconized.value and allowMinimizingMainWindow:
            self.mainWnd.Iconize(True)
        else:
            self.mainWnd.Show()

        self.mainWnd.taskBarIconController.updateTrayIcon()

    def initLogger(self, debugMode=False):
        level = logging.DEBUG if debugMode else logging.WARNING

        redirector = LogRedirector(
            self.getLogFileName(self._application.fullConfigPath),
            level)

        redirector.init()
        wx.Log.SetLogLevel(0)

    def _onEndSession(self, event):
        self.Unbind(wx.EVT_QUERY_END_SESSION, handler=self._onEndSession)
        self.mainWnd.Destroy()

    def getLogFileName(self, configPath):
        return os.path.join(os.path.split(configPath)[0], self.logFileName)

    def bindActivateApp(self):
        """
        Подключиться к событию при потере фокуса приложением
        """
        self.Bind(wx.EVT_ACTIVATE_APP, self._onActivate)

    def unbindActivateApp(self):
        """
        Отключиться от события при потере фокуса приложением
        """
        self.Unbind(wx.EVT_ACTIVATE_APP)

    def _onActivate(self, event):
        self._application.onForceSave()

    @property
    def application(self):
        return self._application
示例#3
0
class OutWikerApplication(wx.App):
    """
    OutWiker application class
    """

    def __init__(self, application):
        super().__init__()

        self.logFileName = 'outwiker.log'
        self._application = application
        self.use_fake_html_render = False

        self._locale = initLocale(self._application.config)
        self._initLocale()

    def _initLocale(self):
        # Fix a locale problem with Python 3.8 and wxPython 4.1
        # Overwrite InitLocale from the wx.App class
        if sys.platform.startswith('win'):
            # Very dirty hack
            locale.setlocale(locale.LC_ALL, '')
            try:
                wx.Locale.GetInfo(wx.LOCALE_DECIMAL_POINT)
            except Exception:
                locale.setlocale(locale.LC_ALL, 'C')

    def OnInit(self):
        self.Bind(wx.EVT_QUERY_END_SESSION, self._onEndSession)
        NullTranslations().install()
        return True

    def initMainWindow(self):
        self._initLocale()
        self.mainWnd = MainWindow(self._application)
        self.SetTopWindow(self.mainWnd)

        self._application.mainWindow = self.mainWnd
        self._application.actionController = ActionController(
            self.mainWnd, self._application.config)

        self._registerActions(self._application)
        self.mainWnd.createGui()

    def destroyMainWindow(self):
        self.mainWnd.Destroy()
        self.mainWnd = None
        self._application.mainWindow = None
        self._application = None

    def loadPlugins(self):
        self._application.plugins.load(getPluginsDirList())

    def showMainWindow(self, allowMinimizingMainWindow=True):
        config = TrayConfig(self._application.config)
        if config.startIconized.value and allowMinimizingMainWindow:
            self.mainWnd.Iconize(True)
        else:
            self.mainWnd.Show()

        self.mainWnd.taskBarIconController.updateTrayIcon()

    def initLogger(self, debugMode=False):
        level = logging.DEBUG if debugMode else logging.WARNING

        redirector = LogRedirector(
            self.getLogFileName(self._application.fullConfigPath),
            level)

        redirector.init()
        wx.Log.SetLogLevel(0)

    def _onEndSession(self, event):
        self.Unbind(wx.EVT_QUERY_END_SESSION, handler=self._onEndSession)
        self.mainWnd.Destroy()

    def getLogFileName(self, configPath):
        return os.path.join(os.path.split(configPath)[0], self.logFileName)

    def bindActivateApp(self):
        """
        Подключиться к событию при потере фокуса приложением
        """
        self.Bind(wx.EVT_ACTIVATE_APP, self._onActivate)

    def unbindActivateApp(self):
        """
        Отключиться от события при потере фокуса приложением
        """
        self.Unbind(wx.EVT_ACTIVATE_APP)

    def _onActivate(self, event):
        self._application.onForceSave()

    @property
    def application(self):
        return self._application

    def _registerActions(self, application):
        """
        Зарегистрировать действия
        """
        # Действия, связанные с разными типами страниц
        from outwiker.pages.html.htmlpage import HtmlPageFactory
        HtmlPageFactory.registerActions(application)

        from outwiker.pages.wiki.wikipage import WikiPageFactory
        WikiPageFactory.registerActions(application)

        actionController = application.actionController
        from outwiker.gui.actionslist import actionsList, polyactionsList

        # Register the normal actions
        [actionController.register(item.action_type(application),
                                   item.hotkey,
                                   item.area,
                                   item.hidden)
         for item in actionsList]

        # Register the polyactions
        [actionController.register(PolyAction(application,
                                              item.stringId,
                                              item.title,
                                              item.description),
                                   item.hotkey) for item in polyactionsList]