diff -r 273323ba9d2d -r 0922aa829e5e Preferences/PreferencesLexer.py --- a/Preferences/PreferencesLexer.py Mon Mar 11 19:14:32 2019 +0100 +++ b/Preferences/PreferencesLexer.py Mon Mar 11 19:15:34 2019 +0100 @@ -4,14 +4,13 @@ # """ -Module implementing a special QextScintilla lexer to handle the preferences. +Module implementing a special QScintilla lexer to handle the preferences. """ from __future__ import unicode_literals from PyQt5.QtCore import QCoreApplication -from PyQt5.QtGui import QColor, QFont -from PyQt5.Qsci import QsciLexer +from PyQt5.Qsci import QsciLexer, QsciScintillaBase import Preferences import Globals @@ -34,6 +33,7 @@ Special method returning a representation of the exception. @return string representing the error message + @rtype str """ return repr(self._errorMessage) @@ -42,6 +42,7 @@ Special method returning a string representation of the exception. @return string representing the error message + @rtype str """ return self._errorMessage @@ -54,7 +55,8 @@ """ Constructor - @param language lexer language (string) + @param language lexer language + @rtype str """ PreferencesLexerError.__init__(self) self._errorMessage = QCoreApplication.translate( @@ -64,14 +66,16 @@ class PreferencesLexer(QsciLexer): """ - Subclass of QsciLexer to implement preferences specific lexer methods. + Subclass of QsciLexer to implement preferences specific lexer methods and + delegate some methods to the real lexer object. """ def __init__(self, language, parent=None): """ Constructor - @param language The lexer language. (string) - @param parent The parent widget of this lexer. (QextScintilla) + @param language language of the lexer + @type str + @param parent parent widget of this lexer (QWidget) @exception PreferencesLexerLanguageError raised to indicate an invalid lexer language """ @@ -87,183 +91,181 @@ # instantiate a lexer object for the given language import QScintilla.Lexers - lex = QScintilla.Lexers.getLexer(language) - if lex is None: + self.__lex = QScintilla.Lexers.getLexer(language) + if self.__lex is None: raise PreferencesLexerLanguageError(language) + # TODO: get rid of 'styles' and 'ind2style' # define the local store - self.colours = {} - self.defaultColours = {} - self.papers = {} - self.defaultPapers = {} - self.eolFills = {} - self.defaultEolFills = {} - self.fonts = {} - self.defaultFonts = {} - self.descriptions = {} self.ind2style = {} self.styles = [] - - # fill local store with default values from lexer - # and built up styles list and conversion table from index to style - self.__language = lex.language() - index = 0 - for i in range(128): - desc = lex.description(i) + for i in range(QsciScintillaBase.STYLE_MAX): + desc = self.__lex.description(i) if desc: - self.descriptions[i] = desc self.styles.append(desc) - - self.colours[i] = lex.defaultColor(i) - self.papers[i] = lex.defaultPaper(i) - self.eolFills[i] = lex.defaultEolFill(i) - self.fonts[i] = lex.defaultFont(i) - # Override QScintilla's default font family to - # always use a monospaced font - self.fonts[i].setFamily(self.__defaultFontFamily) - - self.defaultColours[i] = lex.defaultColor(i) - self.defaultPapers[i] = lex.defaultPaper(i) - self.defaultEolFills[i] = lex.defaultEolFill(i) - self.defaultFonts[i] = lex.defaultFont(i) - self.defaultFonts[i].setFamily(self.__defaultFontFamily) - self.ind2style[index] = i index += 1 - self.colorChanged.connect(self.setColor) - self.eolFillChanged.connect(self.setEolFill) - self.fontChanged.connect(self.setFont) - self.paperChanged.connect(self.setPaper) - # read the last stored values from preferences file - self.readSettings(Preferences.Prefs.settings, "Scintilla") - + self.__lex.readSettings(Preferences.Prefs.settings, "Scintilla") + # TODO: add substyles + + def writeSettings(self): + """ + Public method to write the lexer settings. + """ + self.__lex.writeSettings(Preferences.Prefs.settings, "Scintilla") + # TODO: add substyles + def defaultColor(self, style): """ - Public method to get the default colour of a style. + Public method to get the default color of a style. - @param style the style number (int) - @return colour + @param style style number + @type int + @return default color + @rtype QColor """ - return self.defaultColours[style] - + return self.__lex.defaultColor(style) + def color(self, style): """ - Public method to get the colour of a style. + Public method to get the color of a style. - @param style the style number (int) - @return colour + @param style style number + @type int + @return color + @rtype QColor """ - return self.colours[style] - + return self.__lex.color(style) + def setColor(self, c, style): """ - Public method to set the colour for a style. + Public method to set the color for a style. - @param c colour (int) - @param style the style number (int) + @param c color + @type QColor + @param style style number + @type int """ - self.colours[style] = QColor(c) - + self.__lex.setColor(c, style) + def defaultPaper(self, style): """ Public method to get the default background for a style. - @param style the style number (int) - @return colour + @param style style number + @type int + @return default background color + @rtype QColor """ - return self.defaultPapers[style] - + return self.__lex.defaultPaper(style) + def paper(self, style): """ Public method to get the background for a style. - @param style the style number (int) - @return colour + @param style the style number + @type int + @return background color + @rtype QColor """ - return self.papers[style] - + return self.__lex.paper(style) + def setPaper(self, c, style): """ Public method to set the background for a style. - @param c colour (int) - @param style the style number (int) + @param c background color + @type QColor + @param style style number + @type int """ - self.papers[style] = QColor(c) - + self.__lex.setPaper(c, style) + def defaulEolFill(self, style): """ Public method to get the default eolFill flag for a style. - @param style the style number (int) - @return eolFill flag + @param style style number + @type int + @return default eolFill flag + @rtype bool """ - return self.defaultEolFills[style] - + return self.__lex.defaultEolFill(style) + def eolFill(self, style): """ Public method to get the eolFill flag for a style. - @param style the style number (int) + @param style style number + @type int @return eolFill flag + @rtype bool """ - return self.eolFills[style] - + return self.__lex.eolFill(style) + def setEolFill(self, eolfill, style): """ Public method to set the eolFill flag for a style. - @param eolfill eolFill flag (boolean) - @param style the style number (int) + @param eolfill eolFill flag + @type bool + @param style style number + @type int """ - self.eolFills[style] = eolfill - + self.__lex.setEolFill(eolfill, style) + def defaultFont(self, style): """ Public method to get the default font for a style. - @param style the style number (int) - @return font + @param style style number + @type int + @return default font + @rtype QFont """ - return self.defaultFonts[style] - + return self.__lex.defaultFont(style) + def font(self, style): """ Public method to get the font for a style. - @param style the style number (int) + @param style style number + @type int @return font + @rtype QFont """ - return self.fonts[style] - + return self.__lex.font(style) + def setFont(self, f, style): """ Public method to set the font for a style. @param f font - @param style the style number (int) + @type QFont + @param style style number + @type int """ - self.fonts[style] = QFont(f) - + self.__lex.setFont(f, style) + def language(self): """ Public method to get the lexers programming language. - @return language + @return lexer programming language + @rtype str """ - return self.__language + return self.__lex.language() def description(self, style): """ Public method to get a descriptive string for a style. - @param style the style number (int) - @return description of the style (string) + @param style style number + @type int + @return description of the style + @rtype str """ - if style in self.descriptions: - return self.descriptions[style] - else: - return "" + return self.__lex.description(style)