def _highlight_match(self, position, length, color): ''' Changes attributes in text area to show highlighting. ''' attribs = self.match_attribs['black'] StyleConstants.setBackground(attribs, color) self.styledoc.setCharacterAttributes(position, length, attribs, True)
def get_attribs(color, error=False): ''' Closure to make the generation of font styling cleaner. Note closures need to be defined before being invoked. ''' attribs = SimpleAttributeSet() StyleConstants.setFontFamily(attribs, self.font.getFamily()) StyleConstants.setFontSize(attribs, self.font.getSize()) StyleConstants.setForeground(attribs, Color(*self.colorlut[color])) # Add yellow background to error line styling # White if no error, otherwise it'll keep on being yellow forever if error: StyleConstants.setBackground(attribs, Color.yellow) else: StyleConstants.setBackground(attribs, Color.white) return attribs
def setTheme(self, themeName): """ Updates all the existing styles, and recolors the command window to match the new styles if any text is present. """ # Pick our fonts! self.defaultFontFamily = \ UIManager.getDefaults().getFont("EditorPane.font").getFamily() self.monoFontFamily = 'Monospaced' # Check that the theme exists if themeName not in THEMES: themeName = DEFAULT_THEME_NAME self.themeName = themeName self.theme = theme = THEMES[themeName] # Set the default style baseStyle = self.getStyle('default') StyleConstants.setBackground(baseStyle, theme.backgroundColor) self._setStyle(baseStyle, theme.defaultStyle) # Set the pretty text styles existingStyles = set(self.getStyleNames()) for name in ALL_STYLES: if name in existingStyles: style = self.getStyle(name) else: style = self.addStyle(name, baseStyle) styleSpec = theme.styles.get(name, (None, None)) styleSpec = ( (theme.defaultStyle[0] if styleSpec[0] is None else styleSpec[0]), (theme.defaultStyle[1] if styleSpec[1] is None else styleSpec[1]) ) self._setStyle(style, styleSpec) self._recolorDocument() self.onThemeSet.send(self)
def setTheme(self, themeName): """ Updates all the existing styles, and recolors the command window to match the new styles if any text is present. """ # Pick our fonts! self.defaultFontFamily = \ UIManager.getDefaults().getFont("EditorPane.font").getFamily() self.monoFontFamily = 'Monospaced' # Check that the theme exists if themeName not in THEMES: themeName = DEFAULT_THEME_NAME self.themeName = themeName self.theme = theme = THEMES[themeName] # Set the default style baseStyle = self.getStyle('default') StyleConstants.setBackground(baseStyle, theme.backgroundColor) self._setStyle(baseStyle, theme.defaultStyle) # Set the pretty text styles existingStyles = set(self.getStyleNames()) for name in ALL_STYLES: if name in existingStyles: style = self.getStyle(name) else: style = self.addStyle(name, baseStyle) styleSpec = theme.styles.get(name, (None, None)) styleSpec = ((theme.defaultStyle[0] if styleSpec[0] is None else styleSpec[0]), (theme.defaultStyle[1] if styleSpec[1] is None else styleSpec[1])) self._setStyle(style, styleSpec) self._recolorDocument() self.onThemeSet.send(self)
def get_attribs(color, error=False, match=False): ''' Closure to make the generation of font styling cleaner. Note closures need to be defined before being invoked. ''' attribs = SimpleAttributeSet() StyleConstants.setFontFamily(attribs, self.font.getFamily()) StyleConstants.setFontSize(attribs, self.font.getSize()) StyleConstants.setForeground(attribs, Color(*self.colorlut[color])) # Add yellow background to error line styling # White if no error, otherwise it'll keep on being yellow forever if error: StyleConstants.setBackground(attribs, Color.yellow) elif match: # TODO: Change to another background colour Eleanor likes StyleConstants.setBackground(attribs, Color.yellow) else: StyleConstants.setBackground(attribs, Color.white) return attribs