Preferences/ConfigurationPages/ConfigurationPageBase.py

changeset 0
de9c2efb9d02
child 13
1af94a91f439
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2006 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the base class for all configuration pages.
8 """
9
10 from PyQt4.QtGui import QWidget, QIcon, QPixmap, QColor, QColorDialog, QFontDialog
11
12 class ConfigurationPageBase(QWidget):
13 """
14 Class implementing the base class for all configuration pages.
15 """
16 def __init__(self):
17 """
18 Constructor
19 """
20 QWidget.__init__(self)
21
22 def polishPage(self):
23 """
24 Public slot to perform some polishing actions.
25 """
26 return
27
28 def saveState(self):
29 """
30 Public method to save the current state of the widget.
31 """
32 return None
33
34 def setState(self, state):
35 """
36 Public method to set the state of the widget.
37
38 @param state state data generated by saveState
39 """
40 return
41
42 def initColour(self, colourstr, button, prefMethod):
43 """
44 Public method to initialize a colour selection button.
45
46 @param colourstr colour to be set (string)
47 @param button reference to a button to show the colour on (QPushButton)
48 @param prefMethod preferences method to get the colour
49 @return reference to the created colour (QColor)
50 """
51 colour = QColor(prefMethod(colourstr))
52 size = button.size()
53 pm = QPixmap(size.width()/2, size.height()/2)
54 pm.fill(colour)
55 button.setIconSize(pm.size())
56 button.setIcon(QIcon(pm))
57 return colour
58
59 def selectColour(self, button, colourVar):
60 """
61 Public method used by the colour selection buttons.
62
63 @param button reference to a button to show the colour on (QPushButton)
64 @param colourVar reference to the variable containing the colour (QColor)
65 @return selected colour (QColor)
66 """
67 colour = QColorDialog.getColor(colourVar)
68 if colour.isValid():
69 size = button.iconSize()
70 pm = QPixmap(size.width(), size.height())
71 pm.fill(colour)
72 button.setIcon(QIcon(pm))
73 else:
74 colour = colourVar
75 return colour
76
77 def selectFont(self, fontSample, fontVar, showFontInfo = False):
78 """
79 Public method used by the font selection buttons.
80
81 @param fontSample reference to the font sample widget (QLineEdit)
82 @param fontVar reference to the variable containing the font (QFont)
83 @param showFontInfo flag indicating to show some font info
84 as the sample (boolean)
85 @return selected font (QFont)
86 """
87 font, ok = QFontDialog.getFont(fontVar)
88 if ok:
89 fontSample.setFont(font)
90 if showFontInfo:
91 fontSample.setText(
92 "{0} {1}".format(font.family(), font.pointSize()))
93 else:
94 font = fontVar
95 return font

eric ide

mercurial