示例#1
0
    def OnInit(self):
        getOS().migrateConfig()
        self._fullConfigPath = getConfigPath()
        Application.init(self._fullConfigPath)

        try:
            starter = Starter()
            starter.processConsole()
        except StarterExit:
            return True

        redirector = LogRedirector(self.getLogFileName(self._fullConfigPath))
        redirector.init()

        from outwiker.gui.mainwindow import MainWindow

        self.mainWnd = MainWindow(None, -1, "")
        self.SetTopWindow(self.mainWnd)

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

        registerActions(Application)
        self.mainWnd.createGui()

        Application.plugins.load(getPluginsDirList())

        self.bindActivateApp()
        self.Bind(wx.EVT_QUERY_END_SESSION, self._onEndSession)

        starter.processGUI()

        return True
示例#2
0
    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()
示例#3
0
class BaseMainWndTest(unittest.TestCase):
    def _processEvents(self):
        """
        Обработать накопившиеся сообщения
        """
        count = 0

        app = wx.GetApp()

        while app.Pending():
            count += 1
            app.Dispatch()

        return count

    def setUp(self):
        self.path = mkdtemp(prefix=u'OutWiker_Абырвалг абырвалг_' +
                            unicode(self.__class__.__name__, 'utf-8'))

        Application.config.remove_section(MainWindowConfig.MAIN_WINDOW_SECTION)

        generalConfig = GeneralGuiConfig(Application.config)
        generalConfig.askBeforeExit.value = False

        self.wnd = MainWindow(None, -1, "")
        Application.mainWindow = self.wnd
        Application.actionController = ActionController(
            self.wnd, Application.config)
        wx.GetApp().SetTopWindow(self.wnd)

        registerActions(Application)
        self.wnd.createGui()

        self.wikiroot = WikiDocument.create(self.path)

        Tester.dialogTester.clear()
        Application.wikiroot = None

    def tearDown(self):
        # obj = Application.actionController

        wx.GetApp().Yield()
        self.wnd.Close()
        self.wnd.Hide()
        self._processEvents()

        Application.mainWindow = None
        Application.selectedPage = None
        Application.wikiroot = None
        Application.actionController.destroy()
        Application.actionController = None
        removeDir(self.path)
        self.wnd = None
示例#4
0
class BaseMainWndTest(unittest.TestCase):
    def _processEvents (self):
        """
        Обработать накопившиеся сообщения
        """
        count = 0

        app = wx.GetApp()

        while app.Pending():
            count += 1
            app.Dispatch()

        return count


    def setUp(self):
        self.path = mkdtemp (prefix=u'OutWiker_Абырвалг абырвалг_' + unicode (self.__class__.__name__, 'utf-8'))

        Application.config.remove_section (MainWindowConfig.MAIN_WINDOW_SECTION)

        generalConfig = GeneralGuiConfig (Application.config)
        generalConfig.askBeforeExit.value = False

        self.wnd = MainWindow (None, -1, "")
        Application.mainWindow = self.wnd
        Application.actionController = ActionController (self.wnd, Application.config)
        wx.GetApp().SetTopWindow (self.wnd)

        registerActions (Application)
        self.wnd.createGui()

        self.wikiroot = WikiDocument.create (self.path)

        Tester.dialogTester.clear()
        Application.wikiroot = None


    def tearDown (self):
        # obj = Application.actionController

        wx.GetApp().Yield()
        self.wnd.Close()
        self.wnd.Hide()
        self._processEvents()

        Application.mainWindow = None
        Application.selectedPage = None
        Application.wikiroot = None
        Application.actionController.destroy()
        Application.actionController = None
        removeDir (self.path)
        self.wnd = None
示例#5
0
    def OnInit(self):
        getOS().init()
        getOS().migrateConfig()

        self._fullConfigPath = getConfigPath()
        Application.init(self._fullConfigPath)
        self._locale = wx.Locale(wx.LANGUAGE_DEFAULT)

        try:
            starter = Starter()
            starter.processConsole()
        except StarterExit:
            return True

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

        level = (logging.DEBUG
                 if Application.sharedData.get(APP_DATA_DEBUG, False)
                 else logging.WARNING)

        redirector = LogRedirector(self.getLogFileName(self._fullConfigPath),
                                   level)
        redirector.init()
        wx.Log.SetLogLevel(0)

        logger = logging.getLogger('outwiker')
        for n, dirname in enumerate(getSpecialDirList(u'')):
            logger.info(u'Special directory [{}]: {}'.format(n, dirname))

        from outwiker.gui.mainwindow import MainWindow

        self.mainWnd = MainWindow(None, -1, "")
        self.SetTopWindow(self.mainWnd)

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

        registerActions(Application)
        self.mainWnd.createGui()

        Application.plugins.load(getPluginsDirList())

        self.bindActivateApp()
        self.Bind(wx.EVT_QUERY_END_SESSION, self._onEndSession)

        starter.processGUI()

        return True
示例#6
0
    def OnInit (self):
        getOS().migrateConfig()
        self._fullConfigPath = getConfigPath ()
        Application.init(self._fullConfigPath)

        try:
            starter = Starter()
            starter.processConsole()
        except StarterExit:
            return True

        redirector = LogRedirector (self.getLogFileName (self._fullConfigPath))
        redirector.init()

        from outwiker.gui.mainwindow import MainWindow

        self.mainWnd = MainWindow(None, -1, "")
        self.SetTopWindow (self.mainWnd)

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

        registerActions(Application)
        self.mainWnd.createGui()

        Application.plugins.load (getPluginsDirList())

        self.bindActivateApp()
        self.Bind (wx.EVT_QUERY_END_SESSION, self._onEndSession)

        starter.processGUI()

        return True
示例#7
0
    def OnInit(self):
        self._fullConfigPath = getConfigPath ()
        Application.init(self._fullConfigPath)

        # Если программа запускается в виде exe-шника, то перенаправить вывод ошибок в лог
        exepath = unicode (sys.argv[0], getOS().filesEncoding)
        if exepath.endswith (u".exe"):
            # Закоментировать следующую строку, если не надо выводить strout/strerr в лог-файл
            self.RedirectStdio (self.getLogFileName (self._fullConfigPath))
            pass

        from outwiker.gui.mainwindow import MainWindow
        
        wx.InitAllImageHandlers()
        self.mainWnd = MainWindow(None, -1, "")
        self.SetTopWindow (self.mainWnd)

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

        registerActions(Application)
        self.mainWnd.createGui()

        Application.plugins.load (getPluginsDirList())

        self.bindActivateApp()
        self.Bind (wx.EVT_QUERY_END_SESSION, self._onEndSession)

        starter = Starter()
        starter.process()
        
        return True
示例#8
0
    def setUp(self):
        Application.config.remove_section (MainWindowConfig.MAIN_WINDOW_SECTION)

        generalConfig = GeneralGuiConfig (Application.config)
        generalConfig.askBeforeExit.value = False

        self.wnd = MainWindow (None, -1, "")
        Application.mainWindow = self.wnd
        Application.actionController = ActionController (self.wnd, Application.config)
        wx.GetApp().SetTopWindow (self.wnd)

        registerActions (Application)
        self.wnd.createGui()
示例#9
0
    def setUp(self):
        self.path = mkdtemp(prefix=u'OutWiker_Абырвалг абырвалг_' +
                            unicode(self.__class__.__name__, 'utf-8'))

        Application.config.remove_section(MainWindowConfig.MAIN_WINDOW_SECTION)

        generalConfig = GeneralGuiConfig(Application.config)
        generalConfig.askBeforeExit.value = False

        self.wnd = MainWindow(None, -1, "")
        Application.mainWindow = self.wnd
        Application.actionController = ActionController(
            self.wnd, Application.config)
        wx.GetApp().SetTopWindow(self.wnd)

        registerActions(Application)
        self.wnd.createGui()

        self.wikiroot = WikiDocument.create(self.path)

        Tester.dialogTester.clear()
        Application.wikiroot = None
示例#10
0
class BaseMainWndTest(unittest.TestCase):
    def _processEvents (self):
        """
        Обработать накопившиеся сообщения
        """
        count = 0

        loop = wx.EventLoop.GetActive()
        app = wx.GetApp()
        
        while app.Pending():
            count += 1
            app.Dispatch()

        return count


    def setUp(self):
        Application.config.remove_section (MainWindowConfig.MAIN_WINDOW_SECTION)

        generalConfig = GeneralGuiConfig (Application.config)
        generalConfig.askBeforeExit.value = False

        self.wnd = MainWindow (None, -1, "")
        Application.mainWindow = self.wnd
        Application.actionController = ActionController (self.wnd, Application.config)
        wx.GetApp().SetTopWindow (self.wnd)

        registerActions (Application)
        self.wnd.createGui()


    def tearDown (self):
        self.wnd.Close()
        self.wnd.Hide()
        self._processEvents()
示例#11
0
    def OnInit(self):
        getOS().init()
        getOS().migrateConfig()

        self._fullConfigPath = getConfigPath()
        Application.init(self._fullConfigPath)
        self._locale = wx.Locale(wx.LANGUAGE_DEFAULT)

        try:
            starter = Starter()
            starter.processConsole()
        except StarterExit:
            return True

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

        level = (logging.INFO
                 if Application.sharedData.get(APP_DATA_DEBUG, False)
                 else logging.WARNING)

        redirector = LogRedirector(self.getLogFileName(self._fullConfigPath),
                                   level)
        redirector.init()
        wx.Log.SetLogLevel(0)

        from outwiker.gui.mainwindow import MainWindow

        self.mainWnd = MainWindow(None, -1, "")
        self.SetTopWindow(self.mainWnd)

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

        registerActions(Application)
        self.mainWnd.createGui()

        Application.plugins.load(getPluginsDirList())

        self.bindActivateApp()
        self.Bind(wx.EVT_QUERY_END_SESSION, self._onEndSession)

        starter.processGUI()

        return True
示例#12
0
    def setUp(self):
        self.path = mkdtemp (prefix=u'OutWiker_Абырвалг абырвалг_' + unicode (self.__class__.__name__, 'utf-8'))

        Application.config.remove_section (MainWindowConfig.MAIN_WINDOW_SECTION)

        generalConfig = GeneralGuiConfig (Application.config)
        generalConfig.askBeforeExit.value = False

        self.wnd = MainWindow (None, -1, "")
        Application.mainWindow = self.wnd
        Application.actionController = ActionController (self.wnd, Application.config)
        wx.GetApp().SetTopWindow (self.wnd)

        registerActions (Application)
        self.wnd.createGui()

        self.wikiroot = WikiDocument.create (self.path)

        Tester.dialogTester.clear()
        Application.wikiroot = None
示例#13
0
    def OnInit (self):
        getOS().migrateConfig()
        self._fullConfigPath = getConfigPath ()
        Application.init(self._fullConfigPath)

        try:
            starter = Starter()
            starter.processConsole()
        except StarterExit:
            return True

        # Если программа запускается в виде exe-шника, то перенаправить вывод ошибок в лог
        if getExeFile().endswith (u".exe"):
            # Закоментировать следующую строку, если не надо выводить strout/strerr в лог-файл
            self.RedirectStdio (self.getLogFileName (self._fullConfigPath))
            pass

        from outwiker.gui.mainwindow import MainWindow

        self.mainWnd = MainWindow(None, -1, "")
        self.SetTopWindow (self.mainWnd)

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

        registerActions(Application)
        self.mainWnd.createGui()

        Application.plugins.load (getPluginsDirList())

        self.bindActivateApp()
        self.Bind (wx.EVT_QUERY_END_SESSION, self._onEndSession)

        starter.processGUI()

        return True
示例#14
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
示例#15
0
class OutWiker(wx.App):
    """
    OutWiker application class
    """
    def __init__(self, *args, **kwds):
        self.logFileName = u"outwiker.log"
        self._locale = None

        wx.App.__init__(self, *args, **kwds)

    def OnInit(self):
        getOS().init()
        getOS().migrateConfig()

        self._fullConfigPath = getConfigPath()
        Application.init(self._fullConfigPath)
        self._locale = wx.Locale(wx.LANGUAGE_DEFAULT)

        try:
            starter = Starter()
            starter.processConsole()
        except StarterExit:
            return True

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

        level = (logging.INFO
                 if Application.sharedData.get(APP_DATA_DEBUG, False)
                 else logging.WARNING)

        redirector = LogRedirector(self.getLogFileName(self._fullConfigPath),
                                   level)
        redirector.init()
        wx.Log.SetLogLevel(0)

        from outwiker.gui.mainwindow import MainWindow

        self.mainWnd = MainWindow(None, -1, "")
        self.SetTopWindow(self.mainWnd)

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

        registerActions(Application)
        self.mainWnd.createGui()

        Application.plugins.load(getPluginsDirList())

        self.bindActivateApp()
        self.Bind(wx.EVT_QUERY_END_SESSION, self._onEndSession)

        starter.processGUI()

        return True

    def _onEndSession(self, event):
        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):
        Application.onForceSave()
示例#16
0
class OutWiker(wx.App):
    def __init__(self, *args, **kwds):
        self.logFileName = u"outwiker.log"

        wx.App.__init__ (self, *args, **kwds)


    def OnInit (self):
        getOS().migrateConfig()
        self._fullConfigPath = getConfigPath ()
        Application.init(self._fullConfigPath)

        try:
            starter = Starter()
            starter.processConsole()
        except StarterExit:
            return True

        # Если программа запускается в виде exe-шника, то перенаправить вывод ошибок в лог
        if getExeFile().endswith (u".exe"):
            # Закоментировать следующую строку, если не надо выводить strout/strerr в лог-файл
            self.RedirectStdio (self.getLogFileName (self._fullConfigPath))
            pass

        from outwiker.gui.mainwindow import MainWindow

        self.mainWnd = MainWindow(None, -1, "")
        self.SetTopWindow (self.mainWnd)

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

        registerActions(Application)
        self.mainWnd.createGui()

        Application.plugins.load (getPluginsDirList())

        self.bindActivateApp()
        self.Bind (wx.EVT_QUERY_END_SESSION, self._onEndSession)

        starter.processGUI()

        return True


    def _onEndSession (self, event):
        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):
        Application.onForceSave()
示例#17
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]
示例#18
0
class OutWiker(wx.App):
    def __init__(self, *args, **kwds):
        self.logFileName = u"outwiker.log"

        wx.App.__init__ (self, *args, **kwds)


    def OnInit (self):
        getOS().migrateConfig()
        self._fullConfigPath = getConfigPath ()
        Application.init(self._fullConfigPath)

        try:
            starter = Starter()
            starter.processConsole()
        except StarterExit:
            return True

        redirector = LogRedirector (self.getLogFileName (self._fullConfigPath))
        redirector.init()

        from outwiker.gui.mainwindow import MainWindow

        self.mainWnd = MainWindow(None, -1, "")
        self.SetTopWindow (self.mainWnd)

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

        registerActions(Application)
        self.mainWnd.createGui()

        Application.plugins.load (getPluginsDirList())

        self.bindActivateApp()
        self.Bind (wx.EVT_QUERY_END_SESSION, self._onEndSession)

        starter.processGUI()

        return True


    def _onEndSession (self, event):
        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):
        Application.onForceSave()
示例#19
0
class OutWiker(wx.App):
    """
    OutWiker application class
    """
    def __init__(self, *args, **kwds):
        self.logFileName = u"outwiker.log"
        self._locale = None

        wx.App.__init__(self, *args, **kwds)

    def OnInit(self):
        getOS().init()
        getOS().migrateConfig()

        self._fullConfigPath = getConfigPath()
        Application.init(self._fullConfigPath)
        self._locale = wx.Locale(wx.LANGUAGE_DEFAULT)

        try:
            starter = Starter()
            starter.processConsole()
        except StarterExit:
            return True

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

        level = (logging.DEBUG
                 if Application.sharedData.get(APP_DATA_DEBUG, False)
                 else logging.WARNING)

        redirector = LogRedirector(self.getLogFileName(self._fullConfigPath),
                                   level)
        redirector.init()
        wx.Log.SetLogLevel(0)

        logger = logging.getLogger('outwiker')
        for n, dirname in enumerate(getSpecialDirList(u'')):
            logger.info(u'Special directory [{}]: {}'.format(n, dirname))

        from outwiker.gui.mainwindow import MainWindow

        self.mainWnd = MainWindow(None, -1, "")
        self.SetTopWindow(self.mainWnd)

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

        registerActions(Application)
        self.mainWnd.createGui()

        Application.plugins.load(getPluginsDirList())

        self.bindActivateApp()
        self.Bind(wx.EVT_QUERY_END_SESSION, self._onEndSession)

        starter.processGUI()

        return True

    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):
        Application.onForceSave()
示例#20
0
class OutWiker(wx.App):
    def __init__(self, *args, **kwds):
        self.logFileName = u"outwiker.log"

        wx.App.__init__(self, *args, **kwds)

    def OnInit(self):
        getOS().migrateConfig()
        self._fullConfigPath = getConfigPath()
        Application.init(self._fullConfigPath)

        try:
            starter = Starter()
            starter.processConsole()
        except StarterExit:
            return True

        redirector = LogRedirector(self.getLogFileName(self._fullConfigPath))
        redirector.init()

        from outwiker.gui.mainwindow import MainWindow

        self.mainWnd = MainWindow(None, -1, "")
        self.SetTopWindow(self.mainWnd)

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

        registerActions(Application)
        self.mainWnd.createGui()

        Application.plugins.load(getPluginsDirList())

        self.bindActivateApp()
        self.Bind(wx.EVT_QUERY_END_SESSION, self._onEndSession)

        starter.processGUI()

        return True

    def _onEndSession(self, event):
        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):
        Application.onForceSave()
示例#21
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