Пример #1
0
def print_info():
    logger.debug('Python version: {}'.format(sys.version))
    logger.debug('wxPython version: {}'.format(wx.__version__))
    logger.debug('Current OutWiker API version: {}.{}'.format(
        outwiker.__api_version__[0], outwiker.__api_version__[1]))
    logger.debug(u'Current working directory: {}'.format(os.getcwd()))
    for n, dirname in enumerate(getSpecialDirList(u'')):
        logger.debug(u'Special directory [{}]: {}'.format(n, dirname))
Пример #2
0
def print_info():
    logger.debug('OutWiker version: {}'.format(outwiker.getVersionStr()))
    logger.debug('Current OutWiker API version: {}.{}'.format(
        outwiker.__api_version__[0], outwiker.__api_version__[1]))
    logger.debug('Python version: {}'.format(sys.version))
    logger.debug('wxPython version: {}'.format(wx.__version__))
    logger.debug('Current locale: {}'.format(locale.setlocale(locale.LC_ALL, None)))
    logger.debug('Decimal point: "{}"'.format(locale.localeconv()['decimal_point']))
    logger.debug('Current working directory: {}'.format(os.getcwd()))
    for n, dirname in enumerate(getSpecialDirList('')):
        logger.debug('Special directory [{}]: {}'.format(n, dirname))
Пример #3
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
Пример #4
0
    def __init__(self, parser):
        self.parser = parser
        self._custom_styles_on_page = {}

        styles_from_page_params = loadCustomStylesFromConfig(
            parser.page.params, CONFIG_STYLES_SECTION,
            self._getOptionNameForCustomStylesFromPage())

        styles_folder_name = self._getStylesFolder()
        dir_list = getSpecialDirList(styles_folder_name)
        custom_styles = loadCustomStyles(dir_list)

        styles = {**styles_from_page_params, **custom_styles}
        self._style_generator = StyleGenerator(styles)
Пример #5
0
    def __init__(self, parser):
        self.parser = parser
        self._custom_styles_on_page = {}

        styles_from_page_params = loadCustomStylesFromConfig(
            parser.page.params,
            CONFIG_STYLES_SECTION,
            self._getOptionNameForCustomStylesFromPage()
        )

        styles_folder_name = self._getStylesFolder()
        dir_list = getSpecialDirList(styles_folder_name)
        custom_styles = loadCustomStyles(dir_list)

        styles = {**styles_from_page_params, **custom_styles}
        self._style_generator = StyleGenerator(styles)
Пример #6
0
    def initialize(self):
        """
        Инициализация контроллера при активации плагина.
        Подписка на нужные события
        """
        global _
        _ = get_()

        snippets_dir_list = getSpecialDirList(SNIPPETS_DIR)
        assert len(snippets_dir_list) != 0
        if not os.path.exists(snippets_dir_list[-1]):
            os.mkdir(snippets_dir_list[-1])

        if self._application.mainWindow is not None:
            self._registerActions()
            self._guiController.initialize()

        self._application.onWikiParserPrepare += self.__onWikiParserPrepare
Пример #7
0
    def initialize(self):
        """
        Инициализация контроллера при активации плагина.
        Подписка на нужные события
        """
        global _
        _ = get_()

        snippets_dir_list = getSpecialDirList(SNIPPETS_DIR)
        assert len(snippets_dir_list) != 0
        if not os.path.exists(snippets_dir_list[-1]):
            os.mkdir(snippets_dir_list[-1])

        if self._application.mainWindow is not None:
            self._registerActions()
            self._guiController.initialize()

        self._application.onWikiParserPrepare += self.__onWikiParserPrepare
Пример #8
0
    def run(self, params):
        assert self._application.mainWindow is not None
        assert self._application.mainWindow.pagePanel is not None
        assert self._application.selectedPage is not None

        editor = self._application.mainWindow.pagePanel.pageView.codeEditor
        is_block = isSelectedBlock(editor)

        # Load custom styles from folders
        styles_folder = (STYLES_BLOCK_FOLDER_NAME
                         if is_block else STYLES_INLINE_FOLDER_NAME)
        dir_list = getSpecialDirList(styles_folder)
        custom_styles = getCustomStylesNames(dir_list)

        # Load custom styles from page options
        option_name = (CONFIG_STYLES_BLOCK_OPTION
                       if is_block else CONFIG_STYLES_INLINE_OPTION)
        styles_from_page = list(
            loadCustomStylesFromConfig(self._application.selectedPage.params,
                                       CONFIG_STYLES_SECTION,
                                       option_name).keys())

        styles = sorted(list(set(custom_styles + styles_from_page)))

        config = WikiConfig(self._application.selectedPage.params)
        recent_style = config.recentStyleName.value

        title = _('Select style')
        message = _('Styles')
        mainWindow = self._application.mainWindow

        with TestedSingleChoiceDialog(mainWindow, message, title,
                                      styles) as dlg:
            dlg.SetSize((300, 400))
            if recent_style in styles:
                dlg.SetSelection(styles.index(recent_style))

            if dlg.ShowModal() == wx.ID_OK:
                style = dlg.GetStringSelection()
                config.recentStyleName.value = style
                text_begin = '%{style}%'.format(style=style)
                text_end = '%%'
                turnBlockOrInline(editor, text_begin, text_end)
Пример #9
0
    def run(self, params):
        assert self._application.mainWindow is not None
        assert self._application.mainWindow.pagePanel is not None
        assert self._application.selectedPage is not None

        editor = self._application.mainWindow.pagePanel.pageView.codeEditor
        is_block = isSelectedBlock(editor)

        # Load custom styles from folders
        styles_folder = (STYLES_BLOCK_FOLDER_NAME if is_block
                         else STYLES_INLINE_FOLDER_NAME)
        dir_list = getSpecialDirList(styles_folder)
        custom_styles = getCustomStylesNames(dir_list)

        # Load custom styles from page options
        option_name = (CONFIG_STYLES_BLOCK_OPTION if is_block
                       else CONFIG_STYLES_INLINE_OPTION)
        styles_from_page = list(loadCustomStylesFromConfig(
            self._application.selectedPage.params,
            CONFIG_STYLES_SECTION,
            option_name).keys())

        styles = sorted(list(set(custom_styles + styles_from_page)))

        config = WikiConfig(self._application.selectedPage.params)
        recent_style = config.recentStyleName.value

        title = _('Select style')
        message = _('Styles')
        mainWindow = self._application.mainWindow

        with TestedSingleChoiceDialog(mainWindow, message, title, styles) as dlg:
            dlg.SetSize((300, 400))
            if recent_style in styles:
                dlg.SetSelection(styles.index(recent_style))

            if dlg.ShowModal() == wx.ID_OK:
                style = dlg.GetStringSelection()
                config.recentStyleName.value = style
                text_begin = '%{style}%'.format(style=style)
                text_end = '%%'
                turnBlockOrInline(editor, text_begin, text_end)
Пример #10
0
def getSnippetsDir():
    return getSpecialDirList(SNIPPETS_DIR)[-1]
Пример #11
0
 def _loadSnippetsTree(self):
     rootdir = getSpecialDirList(defines.SNIPPETS_DIR)[-1]
     sl = SnippetsLoader(rootdir)
     snippets_tree = sl.getSnippets()
     return snippets_tree
Пример #12
0
 def _loadSnippetsTree(self):
     rootdir = getSpecialDirList(defines.SNIPPETS_DIR)[-1]
     sl = SnippetsLoader(rootdir)
     snippets_tree = sl.getSnippets()
     return snippets_tree
Пример #13
0
    def run(self, params):
        assert self._application.mainWindow is not None
        assert self._application.mainWindow.pagePanel is not None
        assert self._application.selectedPage is not None

        config = GeneralGuiConfig(self._application.config)
        recent_text_colors = config.recentTextColors.value
        recent_background_colors = config.recentBackgroundColors.value

        editor = self._application.mainWindow.pagePanel.pageView.codeEditor
        is_block = isSelectedBlock(editor)

        if is_block:
            styles_folder = STYLES_BLOCK_FOLDER_NAME
            example_html = '''<div class="{css_class}">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi maximus vel tortor a dictum. Sed elit ipsum, consectetur quis dui vitae, pretium dapibus lorem. Duis mattis sagittis magna, suscipit cursus ante sodales sed. Sed id orci in ipsum laoreet maximus.</div>'''
            tag = 'div'
            option_name = CONFIG_STYLES_BLOCK_OPTION
        else:
            styles_folder = STYLES_INLINE_FOLDER_NAME
            example_html = '''Lorem ipsum dolor sit amet, consectetur adipiscing elit. <span class="{css_class}">Morbi maximus vel tortor a dictum. Sed elit ipsum, consectetur quis dui vitae, pretium dapibus lorem.</span> Duis mattis sagittis magna, suscipit cursus ante sodales sed. Sed id orci in ipsum laoreet maximus.'''
            tag = 'span'
            option_name = CONFIG_STYLES_INLINE_OPTION

        # Load custom styles from dirs
        dir_list = getSpecialDirList(styles_folder)
        custom_styles = loadCustomStyles(dir_list)

        # Load custom dirs from page params
        styles_from_page = loadCustomStylesFromConfig(
            self._application.selectedPage.params, CONFIG_STYLES_SECTION,
            option_name)

        styles = {**styles_from_page, **custom_styles}

        title = _('Advanced style...')
        mainWindow = self._application.mainWindow

        with StyleDialog(mainWindow, title, styles, example_html, tag) as dlg:
            dlg.setCustomTextColors(recent_text_colors)
            dlg.setCustomBackgroundColors(recent_background_colors)

            if dlg.ShowModal() == wx.ID_OK:
                color = dlg.getTextColor()
                background_color = dlg.getBackgroundColor()
                custom_style_name = dlg.getCustomStyleName()
                custom_css = dlg.getCustomCSS()

                begin = ''
                if custom_style_name:
                    begin += ' {}'.format(custom_style_name)

                if color:
                    color_str = self._color2str(color)
                    if (color_str.startswith('#')
                            or color_str.startswith('rgb(')):
                        begin += ' color="{}"'.format(color_str)
                    else:
                        begin += ' {}'.format(color_str)

                    recent_text_colors = update_recent(
                        recent_text_colors,
                        color.GetAsString(wx.C2S_HTML_SYNTAX).lower(),
                        RECENT_COLORS_COUNT)
                    config.recentTextColors.value = recent_text_colors

                if background_color:
                    background_color_str = self._color2str(background_color)
                    if (background_color_str.startswith('#')
                            or background_color_str.startswith('rgb(')):
                        begin += ' bgcolor="{}"'.format(background_color_str)
                    else:
                        begin += ' bg-{}'.format(background_color_str)

                    recent_background_colors = update_recent(
                        recent_background_colors,
                        background_color.GetAsString(
                            wx.C2S_HTML_SYNTAX).lower(), RECENT_COLORS_COUNT)
                    config.recentBackgroundColors.value = recent_background_colors

                if custom_css:
                    begin += ' style="{}"'.format(custom_css.replace(
                        '\n', ' '))

                begin = '%' + begin.strip() + '%'
                end = '%%'
                turnBlockOrInline(editor, begin, end)
Пример #14
0
def print_info():
    logger.debug(u'Current working directory: {}'.format(os.getcwd()))
    for n, dirname in enumerate(getSpecialDirList(u'')):
        logger.debug(u'Special directory [{}]: {}'.format(n, dirname))
Пример #15
0
 def _updateMenu(self):
     self._removeSnippetsFromMenu()
     sl = SnippetsLoader(getSpecialDirList(defines.SNIPPETS_DIR))
     snippets_tree = sl.getSnippets()
     self._buildTree(snippets_tree, self._menu)
Пример #16
0
    def run(self, params):
        assert self._application.mainWindow is not None
        assert self._application.mainWindow.pagePanel is not None
        assert self._application.selectedPage is not None

        config = GeneralGuiConfig(self._application.config)
        recent_text_colors = config.recentTextColors.value
        recent_background_colors = config.recentBackgroundColors.value

        editor = self._application.mainWindow.pagePanel.pageView.codeEditor
        is_block = isSelectedBlock(editor)

        if is_block:
            styles_folder = STYLES_BLOCK_FOLDER_NAME
            example_html = '''<div class="{css_class}">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi maximus vel tortor a dictum. Sed elit ipsum, consectetur quis dui vitae, pretium dapibus lorem. Duis mattis sagittis magna, suscipit cursus ante sodales sed. Sed id orci in ipsum laoreet maximus.</div>'''
            tag = 'div'
            option_name = CONFIG_STYLES_BLOCK_OPTION
        else:
            styles_folder = STYLES_INLINE_FOLDER_NAME
            example_html = '''Lorem ipsum dolor sit amet, consectetur adipiscing elit. <span class="{css_class}">Morbi maximus vel tortor a dictum. Sed elit ipsum, consectetur quis dui vitae, pretium dapibus lorem.</span> Duis mattis sagittis magna, suscipit cursus ante sodales sed. Sed id orci in ipsum laoreet maximus.'''
            tag = 'span'
            option_name = CONFIG_STYLES_INLINE_OPTION

        # Load custom styles from dirs
        dir_list = getSpecialDirList(styles_folder)
        custom_styles = loadCustomStyles(dir_list)

        # Load custom dirs from page params
        styles_from_page = loadCustomStylesFromConfig(
            self._application.selectedPage.params,
            CONFIG_STYLES_SECTION,
            option_name)

        styles = {**styles_from_page, **custom_styles}

        title = _('Advanced style...')
        mainWindow = self._application.mainWindow

        with StyleDialog(mainWindow, title, styles, example_html, tag) as dlg:
            dlg.setCustomTextColors(recent_text_colors)
            dlg.setCustomBackgroundColors(recent_background_colors)

            if dlg.ShowModal() == wx.ID_OK:
                color = dlg.getTextColor()
                background_color = dlg.getBackgroundColor()
                custom_style_name = dlg.getCustomStyleName()
                custom_css = dlg.getCustomCSS()

                begin = ''
                if custom_style_name:
                    begin += ' {}'.format(custom_style_name)

                if color:
                    color_str = self._color2str(color)
                    if (color_str.startswith('#') or
                            color_str.startswith('rgb(')):
                        begin += ' color="{}"'.format(color_str)
                    else:
                        begin += ' {}'.format(color_str)

                    recent_text_colors = update_recent(
                        recent_text_colors,
                        color.GetAsString(wx.C2S_HTML_SYNTAX).lower(),
                        RECENT_COLORS_COUNT
                    )
                    config.recentTextColors.value = recent_text_colors

                if background_color:
                    background_color_str = self._color2str(background_color)
                    if (background_color_str.startswith('#') or
                            background_color_str.startswith('rgb(')):
                        begin += ' bgcolor="{}"'.format(background_color_str)
                    else:
                        begin += ' bg-{}'.format(background_color_str)

                    recent_background_colors = update_recent(
                        recent_background_colors,
                        background_color.GetAsString(wx.C2S_HTML_SYNTAX).lower(),
                        RECENT_COLORS_COUNT)
                    config.recentBackgroundColors.value = recent_background_colors

                if custom_css:
                    begin += ' style="{}"'.format(custom_css.replace('\n', ' '))

                begin = '%' + begin.strip() + '%'
                end = '%%'
                turnBlockOrInline(editor, begin, end)