Mon, 26 Nov 2012 19:07:40 +0100
Optimized the colour selection code of configuration pages.
--- a/Preferences/ConfigurationPages/ConfigurationPageBase.py Sun Nov 25 20:22:02 2012 +0100 +++ b/Preferences/ConfigurationPages/ConfigurationPageBase.py Mon Nov 26 19:07:40 2012 +0100 @@ -7,6 +7,7 @@ Module implementing the base class for all configuration pages. """ +from PyQt4.QtCore import pyqtSlot from PyQt4.QtGui import QWidget, QIcon, QPixmap, QColor, QColorDialog, QFontDialog @@ -20,6 +21,8 @@ """ super().__init__() + self.__coloursDict = {} + def polishPage(self): """ Public slot to perform some polishing actions. @@ -40,66 +43,59 @@ """ return - def initColour(self, colourstr, button, prefMethod): + def initColour(self, colourKey, button, prefMethod, byName=False, hasAlpha=False): """ Public method to initialize a colour selection button. - @param colourstr colour to be set (string) + @param colourKey key of the colour resource (string) @param button reference to a button to show the colour on (QPushButton) @param prefMethod preferences method to get the colour - @return reference to the created colour (QColor) + @keyparam byName flag indicating to retrieve/save by colour name (boolean) + @keyparam hasAlpha flag indicating to allow alpha channel (boolean) """ - colour = QColor(prefMethod(colourstr)) + colour = QColor(prefMethod(colourKey)) size = button.size() pm = QPixmap(size.width() / 2, size.height() / 2) pm.fill(colour) button.setIconSize(pm.size()) button.setIcon(QIcon(pm)) - return colour - - def initColour2(self, colourDict, colourstr, button, prefMethod, selectSlot): - """ - Public method to initialize a colour selection button. + button.setProperty("colorKey", colourKey) + button.setProperty("hasAlpha", hasAlpha) + button.clicked[()].connect(self.__selectColourSlot) + self.__coloursDict[colourKey] = [colour, byName] - @param colourDict reference to the dictionary storing the colors - @param colourstr colour to be set (string) - @param button reference to a button to show the colour on (QPushButton) - @param prefMethod preferences method to get the colour - @param selectSlot method to select the color + @pyqtSlot() + def __selectColourSlot(self): """ - colour = QColor(prefMethod(colourstr)) - size = button.size() - pm = QPixmap(size.width() / 2, size.height() / 2) - pm.fill(colour) - button.setIconSize(pm.size()) - button.setIcon(QIcon(pm)) - button.setProperty("colorName", colourstr) - button.clicked[()].connect(selectSlot) - colourDict[colourstr] = colour + Private slot to select a color. + """ + button = self.sender() + colorKey = button.property("colorKey") + hasAlpha = button.property("hasAlpha") - def selectColour(self, button, colourVar, showAlpha=False): - """ - Public method used by the colour selection buttons. - - @param button reference to a button to show the colour on (QPushButton) - @param colourVar reference to the variable containing the colour (QColor) - @param showAlpha flag indicating to show a selection for the alpha - channel (boolean) - @return selected colour (QColor) - """ - if showAlpha: - colour = QColorDialog.getColor(colourVar, None, "", + if hasAlpha: + colour = QColorDialog.getColor(self.__coloursDict[colorKey][0], None, "", QColorDialog.ShowAlphaChannel) else: - colour = QColorDialog.getColor(colourVar) + colour = QColorDialog.getColor(self.__coloursDict[colorKey][0]) if colour.isValid(): size = button.iconSize() pm = QPixmap(size.width(), size.height()) pm.fill(colour) button.setIcon(QIcon(pm)) - else: - colour = colourVar - return colour + self.__coloursDict[colorKey][0] = colour + + def saveColours(self, prefMethod): + """ + Public method to save the colour selections. + + @param prefMethod preferences method to set the colour + """ + for key in self.__coloursDict: + if self.__coloursDict[key][1]: + prefMethod(key, self.__coloursDict[key][0].name()) + else: + prefMethod(key, self.__coloursDict[key][0]) def selectFont(self, fontSample, fontVar, showFontInfo=False): """
--- a/Preferences/ConfigurationPages/EditorCalltipsPage.py Sun Nov 25 20:22:02 2012 +0100 +++ b/Preferences/ConfigurationPages/EditorCalltipsPage.py Mon Nov 26 19:07:40 2012 +0100 @@ -7,8 +7,6 @@ Module implementing the Editor Calltips configuration page. """ -from PyQt4.QtCore import pyqtSlot - from .ConfigurationPageBase import ConfigurationPageBase from .Ui_EditorCalltipsPage import Ui_EditorCalltipsPage @@ -33,9 +31,8 @@ self.ctVisibleSlider.setValue( Preferences.getEditor("CallTipsVisible")) - self.callTipsBackgroundColour = \ - self.initColour("CallTipsBackground", self.calltipsBackgroundButton, - Preferences.getEditorColour) + self.initColour("CallTipsBackground", self.calltipsBackgroundButton, + Preferences.getEditorColour) self.ctScintillaCheckBox.setChecked( Preferences.getEditor("CallTipsScintillaOnFail")) @@ -49,19 +46,10 @@ Preferences.setEditor("CallTipsVisible", self.ctVisibleSlider.value()) - Preferences.setEditorColour("CallTipsBackground", self.callTipsBackgroundColour) + self.saveColours(Preferences.setEditorColour) Preferences.setEditor("CallTipsScintillaOnFail", self.ctScintillaCheckBox.isChecked()) - - @pyqtSlot() - def on_calltipsBackgroundButton_clicked(self): - """ - Private slot to set the background colour for calltips. - """ - self.callTipsBackgroundColour = \ - self.selectColour(self.calltipsBackgroundButton, - self.callTipsBackgroundColour) def create(dlg):
--- a/Preferences/ConfigurationPages/EditorSearchPage.py Sun Nov 25 20:22:02 2012 +0100 +++ b/Preferences/ConfigurationPages/EditorSearchPage.py Mon Nov 26 19:07:40 2012 +0100 @@ -7,8 +7,6 @@ Module implementing the Editor Search configuration page. """ -from PyQt4.QtCore import pyqtSlot - from .ConfigurationPageBase import ConfigurationPageBase from .Ui_EditorSearchPage import Ui_EditorSearchPage @@ -40,9 +38,8 @@ self.markOccurrencesTimeoutSpinBox.setValue( Preferences.getEditor("MarkOccurrencesTimeout")) - self.editorColours["SearchMarkers"] = \ - self.initColour("SearchMarkers", self.searchMarkerButton, - Preferences.getEditorColour) + self.initColour("SearchMarkers", self.searchMarkerButton, + Preferences.getEditorColour, hasAlpha=True) def save(self): """ @@ -58,17 +55,7 @@ Preferences.setEditor("MarkOccurrencesTimeout", self.markOccurrencesTimeoutSpinBox.value()) - for key in list(self.editorColours.keys()): - Preferences.setEditorColour(key, self.editorColours[key]) - - @pyqtSlot() - def on_searchMarkerButton_clicked(self): - """ - Private slot to set the colour of the search markers. - """ - self.editorColours["SearchMarkers"] = \ - self.selectColour(self.searchMarkerButton, - self.editorColours["SearchMarkers"], True) + self.saveColours(Preferences.setEditorColour) def create(dlg):
--- a/Preferences/ConfigurationPages/EditorSpellCheckingPage.py Sun Nov 25 20:22:02 2012 +0100 +++ b/Preferences/ConfigurationPages/EditorSpellCheckingPage.py Mon Nov 26 19:07:40 2012 +0100 @@ -33,8 +33,6 @@ self.setupUi(self) self.setObjectName("EditorSpellCheckingPage") - self.editorColours = {} - languages = sorted(SpellChecker.getAvailableLanguages()) self.defaultLanguageCombo.addItems(languages) if languages: @@ -58,9 +56,8 @@ self.minimumWordSizeSlider.setValue( Preferences.getEditor("SpellCheckingMinWordSize")) - self.editorColours["SpellingMarkers"] = \ - self.initColour("SpellingMarkers", self.spellingMarkerButton, - Preferences.getEditorColour) + self.initColour("SpellingMarkers", self.spellingMarkerButton, + Preferences.getEditorColour, hasAlpha=True) self.pwlEdit.setText(Preferences.getEditor("SpellCheckingPersonalWordList")) self.pelEdit.setText(Preferences.getEditor("SpellCheckingPersonalExcludeList")) @@ -87,8 +84,7 @@ Preferences.setEditor("SpellCheckingMinWordSize", self.minimumWordSizeSlider.value()) - for key in list(self.editorColours.keys()): - Preferences.setEditorColour(key, self.editorColours[key]) + self.saveColours(Preferences.setEditorColour) Preferences.setEditor("SpellCheckingPersonalWordList", self.pwlEdit.text()) Preferences.setEditor("SpellCheckingPersonalExcludeList", self.pelEdit.text()) @@ -96,15 +92,6 @@ Preferences.setEditor("AutoSpellCheckingEnabled", self.enabledCheckBox.isChecked()) Preferences.setEditor("AutoSpellCheckChunkSize", self.chunkSizeSpinBox.value()) - - @pyqtSlot() - def on_spellingMarkerButton_clicked(self): - """ - Private slot to set the colour of the spelling markers. - """ - self.editorColours["SpellingMarkers"] = \ - self.selectColour(self.spellingMarkerButton, - self.editorColours["SpellingMarkers"], True) @pyqtSlot() def on_pwlButton_clicked(self):
--- a/Preferences/ConfigurationPages/EditorStylesPage.py Sun Nov 25 20:22:02 2012 +0100 +++ b/Preferences/ConfigurationPages/EditorStylesPage.py Mon Nov 26 19:07:40 2012 +0100 @@ -47,8 +47,6 @@ QsciScintilla.EdgeBackground ] - self.editorColours = {} - # set initial values try: self.foldingStyleComboBox.setCurrentIndex( @@ -83,40 +81,30 @@ self.extentSelEolCheckBox.setChecked( Preferences.getEditor("ExtendSelectionToEol")) - self.editorColours["CaretForeground"] = \ - self.initColour("CaretForeground", self.caretForegroundButton, - Preferences.getEditorColour) - self.editorColours["CaretLineBackground"] = \ - self.initColour("CaretLineBackground", self.caretlineBackgroundButton, - Preferences.getEditorColour) - self.editorColours["SelectionForeground"] = \ - self.initColour("SelectionForeground", self.selectionForegroundButton, - Preferences.getEditorColour) - self.editorColours["SelectionBackground"] = \ - self.initColour("SelectionBackground", self.selectionBackgroundButton, - Preferences.getEditorColour) - self.editorColours["CurrentMarker"] = \ - self.initColour("CurrentMarker", self.currentLineMarkerButton, - Preferences.getEditorColour) - self.editorColours["ErrorMarker"] = \ - self.initColour("ErrorMarker", self.errorMarkerButton, - Preferences.getEditorColour) - self.editorColours["MarginsForeground"] = \ - self.initColour("MarginsForeground", self.marginsForegroundButton, - Preferences.getEditorColour) - self.editorColours["MarginsBackground"] = \ - self.initColour("MarginsBackground", self.marginsBackgroundButton, - Preferences.getEditorColour) - self.editorColours["FoldmarginBackground"] = \ - self.initColour("FoldmarginBackground", self.foldmarginBackgroundButton, - Preferences.getEditorColour) - self.editorColours["FoldMarkersForeground"] = \ - self.initColour("FoldMarkersForeground", self.foldmarkersForegroundButton, - Preferences.getEditorColour) - self.editorColours["FoldMarkersBackground"] = \ - self.initColour("FoldMarkersBackground", self.foldmarkersBackgroundButton, - Preferences.getEditorColour) + self.initColour("CaretForeground", self.caretForegroundButton, + Preferences.getEditorColour) + self.initColour("CaretLineBackground", self.caretlineBackgroundButton, + Preferences.getEditorColour, hasAlpha=True) + self.initColour("SelectionForeground", self.selectionForegroundButton, + Preferences.getEditorColour) + self.initColour("SelectionBackground", self.selectionBackgroundButton, + Preferences.getEditorColour, hasAlpha=True) + self.initColour("CurrentMarker", self.currentLineMarkerButton, + Preferences.getEditorColour, hasAlpha=True) + self.initColour("ErrorMarker", self.errorMarkerButton, + Preferences.getEditorColour, hasAlpha=True) + self.initColour("MarginsForeground", self.marginsForegroundButton, + Preferences.getEditorColour) + self.initColour("MarginsBackground", self.marginsBackgroundButton, + Preferences.getEditorColour) + self.initColour("FoldmarginBackground", self.foldmarginBackgroundButton, + Preferences.getEditorColour) + self.initColour("FoldMarkersForeground", self.foldmarkersForegroundButton, + Preferences.getEditorColour) + self.initColour("FoldMarkersBackground", self.foldmarkersBackgroundButton, + Preferences.getEditorColour) + self.editorColours = {} self.editorColours["AnnotationsWarningForeground"] = \ QColor(Preferences.getEditorColour("AnnotationsWarningForeground")) self.editorColours["AnnotationsWarningBackground"] = \ @@ -134,24 +122,19 @@ self.edgeModes.index(Preferences.getEditor("EdgeMode"))) self.edgeLineColumnSlider.setValue( Preferences.getEditor("EdgeColumn")) - self.editorColours["Edge"] = \ - self.initColour("Edge", self.edgeBackgroundColorButton, - Preferences.getEditorColour) + self.initColour("Edge", self.edgeBackgroundColorButton, + Preferences.getEditorColour) self.bracehighlightingCheckBox.setChecked( Preferences.getEditor("BraceHighlighting")) - self.editorColours["MatchingBrace"] = \ - self.initColour("MatchingBrace", self.matchingBracesButton, - Preferences.getEditorColour) - self.editorColours["MatchingBraceBack"] = \ - self.initColour("MatchingBraceBack", self.matchingBracesBackButton, - Preferences.getEditorColour) - self.editorColours["NonmatchingBrace"] = \ - self.initColour("NonmatchingBrace", self.nonmatchingBracesButton, - Preferences.getEditorColour) - self.editorColours["NonmatchingBraceBack"] = \ - self.initColour("NonmatchingBraceBack", self.nonmatchingBracesBackButton, - Preferences.getEditorColour) + self.initColour("MatchingBrace", self.matchingBracesButton, + Preferences.getEditorColour) + self.initColour("MatchingBraceBack", self.matchingBracesBackButton, + Preferences.getEditorColour) + self.initColour("NonmatchingBrace", self.nonmatchingBracesButton, + Preferences.getEditorColour) + self.initColour("NonmatchingBraceBack", self.nonmatchingBracesBackButton, + Preferences.getEditorColour) self.zoomfactorSlider.setValue( Preferences.getEditor("ZoomFactor")) @@ -160,12 +143,10 @@ Preferences.getEditor("ShowWhitespace")) self.whitespaceSizeSpinBox.setValue( Preferences.getEditor("WhitespaceSize")) - self.editorColours["WhitespaceForeground"] = \ - self.initColour("WhitespaceForeground", self.whitespaceForegroundButton, - Preferences.getEditorColour) - self.editorColours["WhitespaceBackground"] = \ - self.initColour("WhitespaceBackground", self.whitespaceBackgroundButton, - Preferences.getEditorColour) + self.initColour("WhitespaceForeground", self.whitespaceForegroundButton, + Preferences.getEditorColour) + self.initColour("WhitespaceBackground", self.whitespaceBackgroundButton, + Preferences.getEditorColour) if not hasattr(QsciScintilla, "setWhitespaceForegroundColor"): self.whitespaceSizeSpinBox.setEnabled(False) self.whitespaceForegroundButton.setEnabled(False) @@ -179,25 +160,21 @@ self.editAreaOverrideCheckBox.setChecked( Preferences.getEditor("OverrideEditAreaColours")) - self.editorColours["EditAreaForeground"] = \ - self.initColour("EditAreaForeground", self.editAreaForegroundButton, - Preferences.getEditorColour) - self.editorColours["EditAreaBackground"] = \ - self.initColour("EditAreaBackground", self.editAreaBackgroundButton, - Preferences.getEditorColour) + self.initColour("EditAreaForeground", self.editAreaForegroundButton, + Preferences.getEditorColour) + self.initColour("EditAreaBackground", self.editAreaBackgroundButton, + Preferences.getEditorColour) self.enableChangeTraceCheckBox.setChecked( Preferences.getEditor("OnlineChangeTrace")) self.changeTraceTimeoutSpinBox.setValue( Preferences.getEditor("OnlineChangeTraceInterval")) - self.editorColours["OnlineChangeTraceMarkerUnsaved"] = \ - self.initColour("OnlineChangeTraceMarkerUnsaved", - self.changeMarkerUnsavedColorButton, - Preferences.getEditorColour) - self.editorColours["OnlineChangeTraceMarkerSaved"] = \ - self.initColour("OnlineChangeTraceMarkerSaved", - self.changeMarkerSavedColorButton, - Preferences.getEditorColour) + self.initColour("OnlineChangeTraceMarkerUnsaved", + self.changeMarkerUnsavedColorButton, + Preferences.getEditorColour) + self.initColour("OnlineChangeTraceMarkerSaved", + self.changeMarkerSavedColorButton, + Preferences.getEditorColour) def save(self): """ @@ -266,6 +243,7 @@ Preferences.setEditor("OnlineChangeTraceInterval", self.changeTraceTimeoutSpinBox.value()) + self.saveColours(Preferences.setEditorColour) for key in list(self.editorColours.keys()): Preferences.setEditorColour(key, self.editorColours[key]) @@ -291,149 +269,6 @@ self.monospacedFont = \ self.selectFont(self.monospacedFontSample, self.monospacedFont) - @pyqtSlot() - def on_caretForegroundButton_clicked(self): - """ - Private slot to set the foreground colour of the caret. - """ - self.editorColours["CaretForeground"] = \ - self.selectColour(self.caretForegroundButton, - self.editorColours["CaretForeground"]) - - @pyqtSlot() - def on_caretlineBackgroundButton_clicked(self): - """ - Private slot to set the background colour of the caretline. - """ - self.editorColours["CaretLineBackground"] = \ - self.selectColour(self.caretlineBackgroundButton, - self.editorColours["CaretLineBackground"], True) - - @pyqtSlot() - def on_selectionForegroundButton_clicked(self): - """ - Private slot to set the foreground colour of the selection. - """ - self.editorColours["SelectionForeground"] = \ - self.selectColour(self.selectionForegroundButton, - self.editorColours["SelectionForeground"]) - - @pyqtSlot() - def on_selectionBackgroundButton_clicked(self): - """ - Private slot to set the background colour of the selection. - """ - self.editorColours["SelectionBackground"] = \ - self.selectColour(self.selectionBackgroundButton, - self.editorColours["SelectionBackground"], True) - - @pyqtSlot() - def on_currentLineMarkerButton_clicked(self): - """ - Private slot to set the colour for the highlight of the current line. - """ - self.editorColours["CurrentMarker"] = \ - self.selectColour(self.currentLineMarkerButton, - self.editorColours["CurrentMarker"], True) - - @pyqtSlot() - def on_errorMarkerButton_clicked(self): - """ - Private slot to set the colour for the highlight of the error line. - """ - self.editorColours["ErrorMarker"] = \ - self.selectColour(self.errorMarkerButton, - self.editorColours["ErrorMarker"], True) - - @pyqtSlot() - def on_marginsForegroundButton_clicked(self): - """ - Private slot to set the foreground colour for the margins. - """ - self.editorColours["MarginsForeground"] = \ - self.selectColour(self.marginsForegroundButton, - self.editorColours["MarginsForeground"]) - - @pyqtSlot() - def on_marginsBackgroundButton_clicked(self): - """ - Private slot to set the background colour for the margins. - """ - self.editorColours["MarginsBackground"] = \ - self.selectColour(self.marginsBackgroundButton, - self.editorColours["MarginsBackground"]) - - @pyqtSlot() - def on_foldmarginBackgroundButton_clicked(self): - """ - Private slot to set the background colour for the foldmargin. - """ - self.editorColours["FoldmarginBackground"] = \ - self.selectColour(self.foldmarginBackgroundButton, - self.editorColours["FoldmarginBackground"]) - - @pyqtSlot() - def on_edgeBackgroundColorButton_clicked(self): - """ - Private slot to set the colour for the edge background or line. - """ - self.editorColours["Edge"] = \ - self.selectColour(self.edgeBackgroundColorButton, self.editorColours["Edge"]) - - @pyqtSlot() - def on_matchingBracesButton_clicked(self): - """ - Private slot to set the colour for highlighting matching braces. - """ - self.editorColours["MatchingBrace"] = \ - self.selectColour(self.matchingBracesButton, - self.editorColours["MatchingBrace"]) - - @pyqtSlot() - def on_matchingBracesBackButton_clicked(self): - """ - Private slot to set the background colour for highlighting matching braces. - """ - self.editorColours["MatchingBraceBack"] = \ - self.selectColour(self.matchingBracesBackButton, - self.editorColours["MatchingBraceBack"]) - - @pyqtSlot() - def on_nonmatchingBracesButton_clicked(self): - """ - Private slot to set the colour for highlighting nonmatching braces. - """ - self.editorColours["NonmatchingBrace"] = \ - self.selectColour(self.nonmatchingBracesButton, - self.editorColours["NonmatchingBrace"]) - - @pyqtSlot() - def on_nonmatchingBracesBackButton_clicked(self): - """ - Private slot to set the background colour for highlighting nonmatching braces. - """ - self.editorColours["NonmatchingBraceBack"] = \ - self.selectColour(self.nonmatchingBracesBackButton, - self.editorColours["NonmatchingBraceBack"]) - - @pyqtSlot() - def on_foldmarkersForegroundButton_clicked(self): - """ - Private slot to set the foreground colour for the foldmarkers. - """ - self.editorColours["FoldMarkersForeground"] = \ - self.selectColour(self.foldmarkersForegroundButton, - self.editorColours["FoldMarkersForeground"]) - - @pyqtSlot() - def on_foldmarkersBackgroundButton_clicked(self): - """ - Private slot to set the background colour for the margins. - """ - self.editorColours["FoldMarkersBackground"] = \ - self.selectColour(self.foldmarkersBackgroundButton, - self.editorColours["FoldMarkersBackground"]) - def polishPage(self): """ Public slot to perform some polishing actions. @@ -505,60 +340,6 @@ self.annotationsErrorSample.setPalette(pl) self.annotationsErrorSample.repaint() self.editorColours["AnnotationsErrorBackground"] = colour - - @pyqtSlot() - def on_whitespaceForegroundButton_clicked(self): - """ - Private slot to set the foreground colour of visible whitespace. - """ - self.editorColours["WhitespaceForeground"] = \ - self.selectColour(self.whitespaceForegroundButton, - self.editorColours["WhitespaceForeground"]) - - @pyqtSlot() - def on_whitespaceBackgroundButton_clicked(self): - """ - Private slot to set the background colour of visible whitespace. - """ - self.editorColours["WhitespaceBackground"] = \ - self.selectColour(self.whitespaceBackgroundButton, - self.editorColours["WhitespaceBackground"]) - - @pyqtSlot() - def on_editAreaForegroundButton_clicked(self): - """ - Private slot to set the foreground colour of the edit area. - """ - self.editorColours["EditAreaForeground"] = \ - self.selectColour(self.editAreaForegroundButton, - self.editorColours["EditAreaForeground"]) - - @pyqtSlot() - def on_editAreaBackgroundButton_clicked(self): - """ - Private slot to set the background colour of the edit area. - """ - self.editorColours["EditAreaBackground"] = \ - self.selectColour(self.editAreaBackgroundButton, - self.editorColours["EditAreaBackground"]) - - @pyqtSlot() - def on_changeMarkerUnsavedColorButton_clicked(self): - """ - Private slot to set the colour of the change marker for unsaved changes. - """ - self.editorColours["OnlineChangeTraceMarkerUnsaved"] = \ - self.selectColour(self.changeMarkerUnsavedColorButton, - self.editorColours["OnlineChangeTraceMarkerUnsaved"]) - - @pyqtSlot() - def on_changeMarkerSavedColorButton_clicked(self): - """ - Private slot to set the colour of the change marker for saved changes. - """ - self.editorColours["OnlineChangeTraceMarkerSaved"] = \ - self.selectColour(self.changeMarkerSavedColorButton, - self.editorColours["OnlineChangeTraceMarkerSaved"]) def create(dlg):
--- a/Preferences/ConfigurationPages/HelpAppearancePage.py Sun Nov 25 20:22:02 2012 +0100 +++ b/Preferences/ConfigurationPages/HelpAppearancePage.py Mon Nov 26 19:07:40 2012 +0100 @@ -35,7 +35,6 @@ self.styleSheetCompleter = E5FileCompleter(self.styleSheetEdit) - self.helpColours = {} self.__displayMode = None # set initial values @@ -51,9 +50,8 @@ .format(self.fixedFont.family(), self.fixedFont.pointSize())) - self.helpColours["SaveUrlColor"] = \ - self.initColour("SaveUrlColor", self.secureURLsColourButton, - Preferences.getHelp) + self.initColour("SaveUrlColor", self.secureURLsColourButton, + Preferences.getHelp) self.autoLoadImagesCheckBox.setChecked(Preferences.getHelp("AutoLoadImages")) @@ -95,8 +93,7 @@ Preferences.setHelp("UserStyleSheet", self.styleSheetEdit.text()) - for key in list(self.helpColours.keys()): - Preferences.setHelp(key, self.helpColours[key]) + self.saveColours(Preferences.setHelp) if self.__displayMode == ConfigurationWidget.HelpBrowserMode: Preferences.setUI("SingleCloseButton", @@ -122,15 +119,6 @@ self.selectFont(self.fixedFontSample, self.fixedFont, True) @pyqtSlot() - def on_secureURLsColourButton_clicked(self): - """ - Private slot to set the colour for secure URLs. - """ - self.helpColours["SaveUrlColor"] = \ - self.selectColour(self.secureURLsColourButton, - self.helpColours["SaveUrlColor"]) - - @pyqtSlot() def on_styleSheetButton_clicked(self): """ Private slot to handle the user style sheet selection.
--- a/Preferences/ConfigurationPages/InterfacePage.py Sun Nov 25 20:22:02 2012 +0100 +++ b/Preferences/ConfigurationPages/InterfacePage.py Mon Nov 26 19:07:40 2012 +0100 @@ -39,8 +39,6 @@ self.styleSheetCompleter = E5FileCompleter(self.styleSheetEdit) - self.uiColours = {} - # set initial values self.__populateStyleCombo() self.__populateLanguageCombo() @@ -105,9 +103,8 @@ self.tabsCloseButtonCheckBox.setChecked( Preferences.getUI("SingleCloseButton")) - self.uiColours["LogStdErrColour"] = \ - self.initColour("LogStdErrColour", self.stderrTextColourButton, - Preferences.getUI) + self.initColour("LogStdErrColour", self.stderrTextColourButton, + Preferences.getUI) def save(self): """ @@ -181,8 +178,7 @@ Preferences.setUI("SingleCloseButton", self.tabsCloseButtonCheckBox.isChecked()) - for key in list(self.uiColours.keys()): - Preferences.setUI(key, self.uiColours[key]) + self.saveColours(Preferences.setUI) def __populateStyleCombo(self): """ @@ -258,15 +254,6 @@ Private method to reset layout to factory defaults """ Preferences.resetLayout() - - @pyqtSlot() - def on_stderrTextColourButton_clicked(self): - """ - Private slot to set the foreground colour of the caret. - """ - self.uiColours["LogStdErrColour"] = \ - self.selectColour(self.stderrTextColourButton, - self.uiColours["LogStdErrColour"]) def create(dlg):
--- a/Preferences/ConfigurationPages/IrcPage.py Sun Nov 25 20:22:02 2012 +0100 +++ b/Preferences/ConfigurationPages/IrcPage.py Mon Nov 26 19:07:40 2012 +0100 @@ -7,8 +7,6 @@ Module implementing the IRC configuration page. """ -from PyQt4.QtCore import pyqtSlot - from .ConfigurationPageBase import ConfigurationPageBase from .Ui_IrcPage import Ui_IrcPage @@ -34,8 +32,6 @@ self.timeFormatCombo.addItems(IrcPage.TimeFormats) self.dateFormatCombo.addItems(IrcPage.DateFormats) - self.ircColours = {} - # set initial values # timestamps self.timestampGroup.setChecked(Preferences.getIrc("ShowTimestamps")) @@ -46,40 +42,28 @@ self.dateFormatCombo.findText(Preferences.getIrc("DateFormat"))) # colours - # TODO: convert this to the code style below - self.ircColours["NetworkMessageColour"] = \ - self.initColour("NetworkMessageColour", self.networkButton, - Preferences.getIrc) - self.ircColours["ServerMessageColour"] = \ - self.initColour("ServerMessageColour", self.serverButton, - Preferences.getIrc) - self.ircColours["ErrorMessageColour"] = \ - self.initColour("ErrorMessageColour", self.errorButton, - Preferences.getIrc) - self.ircColours["TimestampColour"] = \ - self.initColour("TimestampColour", self.timestampButton, - Preferences.getIrc) - self.ircColours["HyperlinkColour"] = \ - self.initColour("HyperlinkColour", self.hyperlinkButton, - Preferences.getIrc) - self.ircColours["ChannelMessageColour"] = \ - self.initColour("ChannelMessageColour", self.channelButton, - Preferences.getIrc) - self.ircColours["OwnNickColour"] = \ - self.initColour("OwnNickColour", self.ownNickButton, - Preferences.getIrc) - self.ircColours["NickColour"] = \ - self.initColour("NickColour", self.nickButton, - Preferences.getIrc) - self.ircColours["JoinChannelColour"] = \ - self.initColour("JoinChannelColour", self.joinButton, - Preferences.getIrc) - self.ircColours["LeaveChannelColour"] = \ - self.initColour("LeaveChannelColour", self.leaveButton, - Preferences.getIrc) - self.ircColours["ChannelInfoColour"] = \ - self.initColour("ChannelInfoColour", self.infoButton, - Preferences.getIrc) + self.initColour("NetworkMessageColour", self.networkButton, + Preferences.getIrc, byName=True) + self.initColour("ServerMessageColour", self.serverButton, + Preferences.getIrc, byName=True) + self.initColour("ErrorMessageColour", self.errorButton, + Preferences.getIrc, byName=True) + self.initColour("TimestampColour", self.timestampButton, + Preferences.getIrc, byName=True) + self.initColour("HyperlinkColour", self.hyperlinkButton, + Preferences.getIrc, byName=True) + self.initColour("ChannelMessageColour", self.channelButton, + Preferences.getIrc, byName=True) + self.initColour("OwnNickColour", self.ownNickButton, + Preferences.getIrc, byName=True) + self.initColour("NickColour", self.nickButton, + Preferences.getIrc, byName=True) + self.initColour("JoinChannelColour", self.joinButton, + Preferences.getIrc, byName=True) + self.initColour("LeaveChannelColour", self.leaveButton, + Preferences.getIrc, byName=True) + self.initColour("ChannelInfoColour", self.infoButton, + Preferences.getIrc, byName=True) # notifications self.notificationsGroup.setChecked(Preferences.getIrc("ShowNotifications")) @@ -88,39 +72,38 @@ self.ownNickCheckBox.setChecked(Preferences.getIrc("NotifyNick")) # IRC text colors - # TODO: optimize further: put colour dict and select slot in base class - self.initColour2(self.ircColours, "IrcColor0", self.ircColor0Button, - Preferences.getIrc, self.__selectColour) - self.initColour2(self.ircColours, "IrcColor1", self.ircColor1Button, - Preferences.getIrc, self.__selectColour) - self.initColour2(self.ircColours, "IrcColor2", self.ircColor2Button, - Preferences.getIrc, self.__selectColour) - self.initColour2(self.ircColours, "IrcColor3", self.ircColor3Button, - Preferences.getIrc, self.__selectColour) - self.initColour2(self.ircColours, "IrcColor4", self.ircColor4Button, - Preferences.getIrc, self.__selectColour) - self.initColour2(self.ircColours, "IrcColor5", self.ircColor5Button, - Preferences.getIrc, self.__selectColour) - self.initColour2(self.ircColours, "IrcColor6", self.ircColor6Button, - Preferences.getIrc, self.__selectColour) - self.initColour2(self.ircColours, "IrcColor7", self.ircColor7Button, - Preferences.getIrc, self.__selectColour) - self.initColour2(self.ircColours, "IrcColor8", self.ircColor8Button, - Preferences.getIrc, self.__selectColour) - self.initColour2(self.ircColours, "IrcColor9", self.ircColor9Button, - Preferences.getIrc, self.__selectColour) - self.initColour2(self.ircColours, "IrcColor10", self.ircColor10Button, - Preferences.getIrc, self.__selectColour) - self.initColour2(self.ircColours, "IrcColor11", self.ircColor11Button, - Preferences.getIrc, self.__selectColour) - self.initColour2(self.ircColours, "IrcColor12", self.ircColor12Button, - Preferences.getIrc, self.__selectColour) - self.initColour2(self.ircColours, "IrcColor13", self.ircColor13Button, - Preferences.getIrc, self.__selectColour) - self.initColour2(self.ircColours, "IrcColor14", self.ircColor14Button, - Preferences.getIrc, self.__selectColour) - self.initColour2(self.ircColours, "IrcColor15", self.ircColor15Button, - Preferences.getIrc, self.__selectColour) + self.initColour("IrcColor0", self.ircColor0Button, + Preferences.getIrc, byName=True) + self.initColour("IrcColor1", self.ircColor1Button, + Preferences.getIrc, byName=True) + self.initColour("IrcColor2", self.ircColor2Button, + Preferences.getIrc, byName=True) + self.initColour("IrcColor3", self.ircColor3Button, + Preferences.getIrc, byName=True) + self.initColour("IrcColor4", self.ircColor4Button, + Preferences.getIrc, byName=True) + self.initColour("IrcColor5", self.ircColor5Button, + Preferences.getIrc, byName=True) + self.initColour("IrcColor6", self.ircColor6Button, + Preferences.getIrc, byName=True) + self.initColour("IrcColor7", self.ircColor7Button, + Preferences.getIrc, byName=True) + self.initColour("IrcColor8", self.ircColor8Button, + Preferences.getIrc, byName=True) + self.initColour("IrcColor9", self.ircColor9Button, + Preferences.getIrc, byName=True) + self.initColour("IrcColor10", self.ircColor10Button, + Preferences.getIrc, byName=True) + self.initColour("IrcColor11", self.ircColor11Button, + Preferences.getIrc, byName=True) + self.initColour("IrcColor12", self.ircColor12Button, + Preferences.getIrc, byName=True) + self.initColour("IrcColor13", self.ircColor13Button, + Preferences.getIrc, byName=True) + self.initColour("IrcColor14", self.ircColor14Button, + Preferences.getIrc, byName=True) + self.initColour("IrcColor15", self.ircColor15Button, + Preferences.getIrc, byName=True) def save(self): """ @@ -139,117 +122,7 @@ Preferences.setIrc("NotifyNick", self.ownNickCheckBox.isChecked()) # colours - for key in self.ircColours: - Preferences.setIrc(key, self.ircColours[key].name()) - - @pyqtSlot() - def on_networkButton_clicked(self): - """ - Private slot to set the color for network messages. - """ - self.ircColours["NetworkMessageColour"] = \ - self.selectColour(self.networkButton, - self.ircColours["NetworkMessageColour"]) - - @pyqtSlot() - def on_nickButton_clicked(self): - """ - Private slot to set the color for nick names. - """ - self.ircColours["NickColour"] = \ - self.selectColour(self.nickButton, - self.ircColours["NickColour"]) - - @pyqtSlot() - def on_serverButton_clicked(self): - """ - Private slot to set the color for server messages. - """ - self.ircColours["ServerMessageColour"] = \ - self.selectColour(self.serverButton, - self.ircColours["ServerMessageColour"]) - - @pyqtSlot() - def on_ownNickButton_clicked(self): - """ - Private slot to set the color for own nick name. - """ - self.ircColours["OwnNickColour"] = \ - self.selectColour(self.ownNickButton, - self.ircColours["OwnNickColour"]) - - @pyqtSlot() - def on_channelButton_clicked(self): - """ - Private slot to set the color for channel messages. - """ - self.ircColours["ChannelMessageColour"] = \ - self.selectColour(self.channelButton, - self.ircColours["ChannelMessageColour"]) - - @pyqtSlot() - def on_joinButton_clicked(self): - """ - Private slot to set the color for join events. - """ - self.ircColours["JoinChannelColour"] = \ - self.selectColour(self.joinButton, - self.ircColours["JoinChannelColour"]) - - @pyqtSlot() - def on_errorButton_clicked(self): - """ - Private slot to set the color for error messages. - """ - self.ircColours["ErrorMessageColour"] = \ - self.selectColour(self.errorButton, - self.ircColours["ErrorMessageColour"]) - - @pyqtSlot() - def on_leaveButton_clicked(self): - """ - Private slot to set the color for leave events. - """ - self.ircColours["LeaveChannelColour"] = \ - self.selectColour(self.leaveButton, - self.ircColours["LeaveChannelColour"]) - - @pyqtSlot() - def on_timestampButton_clicked(self): - """ - Private slot to set the color for timestamps. - """ - self.ircColours["TimestampColour"] = \ - self.selectColour(self.timestampButton, - self.ircColours["TimestampColour"]) - - @pyqtSlot() - def on_infoButton_clicked(self): - """ - Private slot to set the color for info messages. - """ - self.ircColours["ChannelInfoColour"] = \ - self.selectColour(self.infoButton, - self.ircColours["ChannelInfoColour"]) - - @pyqtSlot() - def on_hyperlinkButton_clicked(self): - """ - Private slot to set the color for hyperlinks. - """ - self.ircColours["HyperlinkColour"] = \ - self.selectColour(self.hyperlinkButton, - self.ircColours["HyperlinkColour"]) - - @pyqtSlot() - def __selectColour(self): - """ - Private slot to select a color. - """ - button = self.sender() - colorKey = button.property("colorName") - self.ircColours[colorKey] = self.selectColour( - button, self.ircColours[colorKey]) + self.saveColours(Preferences.setIrc) def create(dlg):
--- a/Preferences/ConfigurationPages/ProjectBrowserPage.py Sun Nov 25 20:22:02 2012 +0100 +++ b/Preferences/ConfigurationPages/ProjectBrowserPage.py Mon Nov 26 19:07:40 2012 +0100 @@ -33,7 +33,6 @@ self.setupUi(self) self.setObjectName("ProjectBrowserPage") - self.projectBrowserColours = {} self.__currentProjectTypeIndex = 0 # set initial values @@ -49,9 +48,8 @@ except KeyError: self.pbGroup.setEnabled(False) - self.projectBrowserColours["Highlighted"] = \ - self.initColour("Highlighted", self.pbHighlightedButton, - Preferences.getProjectBrowserColour) + self.initColour("Highlighted", self.pbHighlightedButton, + Preferences.getProjectBrowserColour) self.followEditorCheckBox.setChecked( Preferences.getProject("FollowEditor")) @@ -62,8 +60,7 @@ """ Public slot to save the Project Browser configuration. """ - for key in list(self.projectBrowserColours.keys()): - Preferences.setProjectBrowserColour(key, self.projectBrowserColours[key]) + self.saveColours(Preferences.setProjectBrowserColour) Preferences.setProject("FollowEditor", self.followEditorCheckBox.isChecked()) @@ -77,16 +74,6 @@ if projectType != '': Preferences.setProjectBrowserFlags(projectType, flags) - @pyqtSlot() - def on_pbHighlightedButton_clicked(self): - """ - Private slot to set the colour for highlighted entries of the - project others browser. - """ - self.projectBrowserColours["Highlighted"] = \ - self.selectColour(self.pbHighlightedButton, - self.projectBrowserColours["Highlighted"]) - def __storeProjectBrowserFlags(self, projectType): """ Private method to store the flags for the selected project type.
--- a/Preferences/ConfigurationPages/TasksPage.py Sun Nov 25 20:22:02 2012 +0100 +++ b/Preferences/ConfigurationPages/TasksPage.py Mon Nov 26 19:07:40 2012 +0100 @@ -7,8 +7,6 @@ Module implementing the Tasks configuration page. """ -from PyQt4.QtCore import pyqtSlot - from .ConfigurationPageBase import ConfigurationPageBase from .Ui_TasksPage import Ui_TasksPage @@ -27,8 +25,6 @@ self.setupUi(self) self.setObjectName("TasksPage") - self.tasksColours = {} - # set initial values self.tasksMarkerFixmeEdit.setText( Preferences.getTasks("TasksFixmeMarkers")) @@ -39,18 +35,14 @@ self.tasksMarkerNoteEdit.setText( Preferences.getTasks("TasksNoteMarkers")) - self.tasksColours["TasksFixmeColor"] = \ - self.initColour("TasksFixmeColor", self.tasksFixmeColourButton, - Preferences.getTasks) - self.tasksColours["TasksWarningColor"] = \ - self.initColour("TasksWarningColor", self.tasksWarningColourButton, - Preferences.getTasks) - self.tasksColours["TasksTodoColor"] = \ - self.initColour("TasksTodoColor", self.tasksTodoColourButton, - Preferences.getTasks) - self.tasksColours["TasksNoteColor"] = \ - self.initColour("TasksNoteColor", self.tasksNoteColourButton, - Preferences.getTasks) + self.initColour("TasksFixmeColor", self.tasksFixmeColourButton, + Preferences.getTasks) + self.initColour("TasksWarningColor", self.tasksWarningColourButton, + Preferences.getTasks) + self.initColour("TasksTodoColor", self.tasksTodoColourButton, + Preferences.getTasks) + self.initColour("TasksNoteColor", self.tasksNoteColourButton, + Preferences.getTasks) self.clearCheckBox.setChecked(Preferences.getTasks("ClearOnFileClose")) @@ -66,44 +58,9 @@ self.tasksMarkerTodoEdit.text()) Preferences.setTasks("TasksNoteMarkers", self.tasksMarkerNoteEdit.text()) - for key in list(self.tasksColours.keys()): - Preferences.setTasks(key, self.tasksColours[key]) Preferences.setTasks("ClearOnFileClose", self.clearCheckBox.isChecked()) - @pyqtSlot() - def on_tasksFixmeColourButton_clicked(self): - """ - Private slot to set the colour for standard tasks. - """ - self.tasksColours["TasksColour"] = \ - self.selectColour(self.tasksColourButton, self.tasksColours["TasksColour"]) - - @pyqtSlot() - def on_tasksWarningColourButton_clicked(self): - """ - Private slot to set the colour for bugfix tasks. - """ - self.tasksColours["TasksBugfixColour"] = \ - self.selectColour(self.tasksBugfixColourButton, - self.tasksColours["TasksBugfixColour"]) - - @pyqtSlot() - def on_tasksTodoColourButton_clicked(self): - """ - Private slot to set the background colour for global tasks. - """ - self.tasksColours["TasksBgColour"] = \ - self.selectColour(self.tasksBgColourButton, - self.tasksColours["TasksBgColour"]) - - @pyqtSlot() - def on_tasksNoteColourButton_clicked(self): - """ - Private slot to set the backgroundcolour for project tasks. - """ - self.tasksColours["TasksProjectBgColour"] = \ - self.selectColour(self.tasksProjectBgColourButton, - self.tasksColours["TasksProjectBgColour"]) + self.saveColours(Preferences.setTasks) def create(dlg):
--- a/Preferences/ConfigurationPages/VcsPage.py Sun Nov 25 20:22:02 2012 +0100 +++ b/Preferences/ConfigurationPages/VcsPage.py Mon Nov 26 19:07:40 2012 +0100 @@ -7,8 +7,6 @@ Module implementing the VCS configuration page. """ -from PyQt4.QtCore import pyqtSlot - from .ConfigurationPageBase import ConfigurationPageBase from .Ui_VcsPage import Ui_VcsPage @@ -27,8 +25,6 @@ self.setupUi(self) self.setObjectName("VcsPage") - self.projectBrowserColours = {} - # set initial values self.vcsAutoCloseCheckBox.setChecked(Preferences.getVCS("AutoClose")) self.vcsAutoSaveCheckBox.setChecked(Preferences.getVCS("AutoSaveFiles")) @@ -41,27 +37,18 @@ self.autoUpdateCheckBox.setChecked( Preferences.getVCS("AutoUpdate")) - self.projectBrowserColours["VcsAdded"] = \ - self.initColour("VcsAdded", self.pbVcsAddedButton, - Preferences.getProjectBrowserColour) - self.projectBrowserColours["VcsConflict"] = \ - self.initColour("VcsConflict", self.pbVcsConflictButton, - Preferences.getProjectBrowserColour) - self.projectBrowserColours["VcsModified"] = \ - self.initColour("VcsModified", self.pbVcsModifiedButton, - Preferences.getProjectBrowserColour) - self.projectBrowserColours["VcsReplaced"] = \ - self.initColour("VcsReplaced", self.pbVcsReplacedButton, - Preferences.getProjectBrowserColour) - self.projectBrowserColours["VcsUpdate"] = \ - self.initColour("VcsUpdate", self.pbVcsUpdateButton, - Preferences.getProjectBrowserColour) - self.projectBrowserColours["VcsConflict"] = \ - self.initColour("VcsConflict", self.pbVcsConflictButton, - Preferences.getProjectBrowserColour) - self.projectBrowserColours["VcsRemoved"] = \ - self.initColour("VcsRemoved", self.pbVcsRemovedButton, - Preferences.getProjectBrowserColour) + self.initColour("VcsAdded", self.pbVcsAddedButton, + Preferences.getProjectBrowserColour) + self.initColour("VcsConflict", self.pbVcsConflictButton, + Preferences.getProjectBrowserColour) + self.initColour("VcsModified", self.pbVcsModifiedButton, + Preferences.getProjectBrowserColour) + self.initColour("VcsReplaced", self.pbVcsReplacedButton, + Preferences.getProjectBrowserColour) + self.initColour("VcsUpdate", self.pbVcsUpdateButton, + Preferences.getProjectBrowserColour) + self.initColour("VcsRemoved", self.pbVcsRemovedButton, + Preferences.getProjectBrowserColour) def save(self): """ @@ -80,68 +67,7 @@ Preferences.setVCS("AutoUpdate", self.autoUpdateCheckBox.isChecked()) - for key in list(self.projectBrowserColours.keys()): - Preferences.setProjectBrowserColour(key, self.projectBrowserColours[key]) - - @pyqtSlot() - def on_pbVcsAddedButton_clicked(self): - """ - Private slot to set the background colour for entries with VCS - status "added". - """ - self.projectBrowserColours["VcsAdded"] = \ - self.selectColour(self.pbVcsAddedButton, - self.projectBrowserColours["VcsAdded"]) - - @pyqtSlot() - def on_pbVcsConflictButton_clicked(self): - """ - Private slot to set the background colour for entries with VCS - status "conflict". - """ - self.projectBrowserColours["VcsConflict"] = \ - self.selectColour(self.pbVcsConflictButton, - self.projectBrowserColours["VcsConflict"]) - - @pyqtSlot() - def on_pbVcsModifiedButton_clicked(self): - """ - Private slot to set the background colour for entries with VCS - status "modified". - """ - self.projectBrowserColours["VcsModified"] = \ - self.selectColour(self.pbVcsModifiedButton, - self.projectBrowserColours["VcsModified"]) - - @pyqtSlot() - def on_pbVcsReplacedButton_clicked(self): - """ - Private slot to set the background colour for entries with VCS - status "replaced". - """ - self.projectBrowserColours["VcsReplaced"] = \ - self.selectColour(self.pbVcsReplacedButton, - self.projectBrowserColours["VcsReplaced"]) - - @pyqtSlot() - def on_pbVcsRemovedButton_clicked(self): - """ - Private slot to set the background colour for entries with VCS - status "removed". - """ - self.projectBrowserColours["VcsRemoved"] = \ - self.selectColour(self.pbVcsRemovedButton, - self.projectBrowserColours["VcsRemoved"]) - - @pyqtSlot() - def on_pbVcsUpdateButton_clicked(self): - """ - Private slot to set the background colour for entries with VCS - status "needs update". - """ - self.projectBrowserColours["VcsUpdate"] = \ - self.selectColour(self.pbVcsUpdateButton, - self.projectBrowserColours["VcsUpdate"]) + self.saveColours(Preferences.setProjectBrowserColour) def create(dlg):