~ubuntu-branches/ubuntu/karmic/eric/karmic

« back to all changes in this revision

Viewing changes to eric/Preferences/ConfigurationPages/EditorColoursPage.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2008-01-28 18:02:25 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080128180225-6nrox6yrworh2c4v
Tags: 4.0.4-1ubuntu1
* Add python-qt3 to build-depends becuase that's where Ubuntu puts 
  pyqtconfig
* Change maintainer to MOTU

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
# Copyright (c) 2006 - 2007 Detlev Offenbach <detlev@die-offenbachs.de>
 
4
#
 
5
 
 
6
"""
 
7
Module implementing the Editor Colours configuration page.
 
8
"""
 
9
 
 
10
from PyQt4.QtCore import pyqtSignature
 
11
from PyQt4.QtGui import QPixmap, QIcon, QColor
 
12
 
 
13
from KdeQt import KQColorDialog
 
14
 
 
15
from ConfigurationPageBase import ConfigurationPageBase
 
16
from Ui_EditorColoursPage import Ui_EditorColoursPage
 
17
 
 
18
import Preferences
 
19
 
 
20
class EditorColoursPage(ConfigurationPageBase, Ui_EditorColoursPage):
 
21
    """
 
22
    Class implementing the Editor Colours configuration page.
 
23
    """
 
24
    def __init__(self):
 
25
        """
 
26
        Constructor
 
27
        """
 
28
        ConfigurationPageBase.__init__(self)
 
29
        self.setupUi(self)
 
30
        self.setObjectName("EditorColoursPage")
 
31
        
 
32
        self.editorColours = {}
 
33
        
 
34
        # set initial values
 
35
        self.__initEditorColoursColour("CurrentMarker", 
 
36
            self.currentLineMarkerButton)
 
37
        self.__initEditorColoursColour("ErrorMarker", 
 
38
            self.errorMarkerButton)
 
39
        self.__initEditorColoursColour("MatchingBrace", 
 
40
            self.matchingBracesButton)
 
41
        self.__initEditorColoursColour("MatchingBraceBack", 
 
42
            self.matchingBracesBackButton)
 
43
        self.__initEditorColoursColour("NonmatchingBrace", 
 
44
            self.nonmatchingBracesButton)
 
45
        self.__initEditorColoursColour("NonmatchingBraceBack", 
 
46
            self.nonmatchingBracesBackButton)
 
47
        self.__initEditorColoursColour("CallTipsBackground", 
 
48
            self.calltipsBackgroundButton)
 
49
        self.__initEditorColoursColour("CaretForeground", 
 
50
            self.caretForegroundButton)
 
51
        self.__initEditorColoursColour("CaretLineBackground", 
 
52
            self.caretlineBackgroundButton)
 
53
        self.__initEditorColoursColour("SelectionForeground", 
 
54
            self.selectionForegroundButton)
 
55
        self.__initEditorColoursColour("SelectionBackground", 
 
56
            self.selectionBackgroundButton)
 
57
        
 
58
    def save(self):
 
59
        """
 
60
        Public slot to save the Editor Colours configuration.
 
61
        """
 
62
        for key in self.editorColours.keys():
 
63
            Preferences.setEditorColour(key, self.editorColours[key])
 
64
        
 
65
    def __initEditorColoursColour(self, colourstr, button):
 
66
        """
 
67
        Private method to initialize the colour buttons.
 
68
        
 
69
        @param colourstr Colour to be set. (string)
 
70
        @param button Reference to a QButton to show the colour on.
 
71
        """
 
72
        colour = QColor(Preferences.getEditorColour(colourstr))
 
73
        self.editorColours[colourstr] = colour
 
74
        size = button.size()
 
75
        pm = QPixmap(size.width()/2, size.height()/2)
 
76
        pm.fill(colour)
 
77
        button.setIconSize(pm.size())
 
78
        button.setIcon(QIcon(pm))
 
79
        
 
80
    def __selectEditorColour(self, colourstr, button):
 
81
        """
 
82
        Private method used by the buttons selecting the marker colours.
 
83
        
 
84
        @param colourstr Colour to be set. (string)
 
85
        @param button Reference to a QButton to show the colour on.
 
86
        """
 
87
        colour = KQColorDialog.getColor(self.editorColours[colourstr])
 
88
        if colour.isValid():
 
89
            self.editorColours[colourstr] = colour
 
90
            size = button.iconSize()
 
91
            pm = QPixmap(size.width(), size.height())
 
92
            pm.fill(colour)
 
93
            button.setIcon(QIcon(pm))
 
94
        
 
95
    @pyqtSignature("")
 
96
    def on_currentLineMarkerButton_clicked(self):
 
97
        """
 
98
        Private slot to set the colour for the highlight of the current line.
 
99
        """
 
100
        self.__selectEditorColour("CurrentMarker", 
 
101
            self.currentLineMarkerButton)
 
102
        
 
103
    @pyqtSignature("")
 
104
    def on_errorMarkerButton_clicked(self):
 
105
        """
 
106
        Private slot to set the colour for the highlight of the error line.
 
107
        """
 
108
        self.__selectEditorColour("ErrorMarker", 
 
109
            self.errorMarkerButton)
 
110
        
 
111
    @pyqtSignature("")
 
112
    def on_matchingBracesButton_clicked(self):
 
113
        """
 
114
        Private slot to set the colour for highlighting matching braces.
 
115
        """
 
116
        self.__selectEditorColour("MatchingBrace", 
 
117
            self.matchingBracesButton)
 
118
        
 
119
    @pyqtSignature("")
 
120
    def on_matchingBracesBackButton_clicked(self):
 
121
        """
 
122
        Private slot to set the background colour for highlighting matching braces.
 
123
        """
 
124
        self.__selectEditorColour("MatchingBraceBack", 
 
125
            self.matchingBracesBackButton)
 
126
        
 
127
    @pyqtSignature("")
 
128
    def on_nonmatchingBracesButton_clicked(self):
 
129
        """
 
130
        Private slot to set the colour for highlighting nonmatching braces.
 
131
        """
 
132
        self.__selectEditorColour("NonmatchingBrace", 
 
133
            self.nonmatchingBracesButton)
 
134
        
 
135
    @pyqtSignature("")
 
136
    def on_nonmatchingBracesBackButton_clicked(self):
 
137
        """
 
138
        Private slot to set the background colour for highlighting nonmatching braces.
 
139
        """
 
140
        self.__selectEditorColour("NonmatchingBraceBack", 
 
141
            self.nonmatchingBracesBackButton)
 
142
        
 
143
    @pyqtSignature("")
 
144
    def on_calltipsBackgroundButton_clicked(self):
 
145
        """
 
146
        Private slot to set the background colour for calltips.
 
147
        """
 
148
        self.__selectEditorColour("CallTipsBackground", 
 
149
            self.calltipsBackgroundButton)
 
150
        
 
151
    @pyqtSignature("")
 
152
    def on_caretForegroundButton_clicked(self):
 
153
        """
 
154
        Private slot to set the foreground colour of the caret.
 
155
        """
 
156
        self.__selectEditorColour("CaretForeground", 
 
157
            self.caretForegroundButton)
 
158
        
 
159
    @pyqtSignature("")
 
160
    def on_caretlineBackgroundButton_clicked(self):
 
161
        """
 
162
        Private slot to set the background colour of the caretline.
 
163
        """
 
164
        self.__selectEditorColour("CaretLineBackground", 
 
165
            self.caretlineBackgroundButton)
 
166
        
 
167
    @pyqtSignature("")
 
168
    def on_selectionForegroundButton_clicked(self):
 
169
        """
 
170
        Private slot to set the foreground colour of the selection.
 
171
        """
 
172
        self.__selectEditorColour("SelectionForeground", 
 
173
            self.selectionForegroundButton)
 
174
        
 
175
    @pyqtSignature("")
 
176
    def on_selectionBackgroundButton_clicked(self):
 
177
        """
 
178
        Private slot to set the background colour of the selection.
 
179
        """
 
180
        self.__selectEditorColour("SelectionBackground", 
 
181
            self.selectionBackgroundButton)
 
182
    
 
183
def create(dlg):
 
184
    """
 
185
    Module function to create the configuration page.
 
186
    
 
187
    @param dlg reference to the configuration dialog
 
188
    """
 
189
    page = EditorColoursPage()
 
190
    return page