def _setTextBackgroundColor(self, param): config = GeneralGuiConfig(self._application.config) recent_colors = config.recentBackgroundColors.value color = selectColor(self, _('Select text background color'), recent_colors) editor = self._application.mainWindow.pagePanel.pageView.codeEditor if color: recent_colors = update_recent(recent_colors, color.lower(), RECENT_COLORS_COUNT) config.recentBackgroundColors.value = recent_colors color_str = (StandardColors[color] if color in StandardColors else color) if color_str.startswith('#') or color_str.startswith('rgb('): text_begin = '%bgcolor={color}%'.format(color=color_str) else: text_begin = '%bg-{color}%'.format(color=color_str) text_end = '%%' turnBlockOrInline(editor, text_begin, text_end)
def _setTextBackgroundColor(self, param): config = GeneralGuiConfig(self._application.config) recent_colors = config.recentBackgroundColors.value color = selectColor(self, _('Select text background color'), recent_colors) editor = self._application.mainWindow.pagePanel.pageView.codeEditor if color: recent_colors = update_recent(recent_colors, color.lower(), RECENT_COLORS_COUNT) config.recentBackgroundColors.value = recent_colors color_str = (StandardColors[color] if color in StandardColors else color) if color_str.startswith('#') or color_str.startswith('rgb('): text_begin = '%bgcolor={color}%'.format(color=color_str) else: text_begin = '%bg-{color}%'.format(color=color_str) text_end = '%%' turnBlockOrInline(editor, text_begin, text_end)
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)
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)