Preferences/ConfigurationPages/ConfigurationPageBase.py

Mon, 26 Dec 2011 19:31:22 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 26 Dec 2011 19:31:22 +0100
changeset 1509
c0b5e693b0eb
parent 1131
7781e396c903
child 2228
5c59b9393306
child 2303
0ed4ed026c16
permissions
-rw-r--r--

Updated copyright for 2012.

# -*- coding: utf-8 -*-

# Copyright (c) 2006 - 2012 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing the base class for all configuration pages.
"""

from PyQt4.QtGui import QWidget, QIcon, QPixmap, QColor, QColorDialog, QFontDialog


class ConfigurationPageBase(QWidget):
    """
    Class implementing the base class for all configuration pages.
    """
    def __init__(self):
        """
        Constructor
        """
        super().__init__()
        
    def polishPage(self):
        """
        Public slot to perform some polishing actions.
        """
        return
        
    def saveState(self):
        """
        Public method to save the current state of the widget.
        """
        return None
        
    def setState(self, state):
        """
        Public method to set the state of the widget.
        
        @param state state data generated by saveState
        """
        return
        
    def initColour(self, colourstr, button, prefMethod):
        """
        Public method to initialize a colour selection button.
        
        @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
        @return reference to the created colour (QColor)
        """
        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))
        return colour
        
    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, "",
                QColorDialog.ShowAlphaChannel)
        else:
            colour = QColorDialog.getColor(colourVar)
        if colour.isValid():
            size = button.iconSize()
            pm = QPixmap(size.width(), size.height())
            pm.fill(colour)
            button.setIcon(QIcon(pm))
        else:
            colour = colourVar
        return colour
        
    def selectFont(self, fontSample, fontVar, showFontInfo=False):
        """
        Public method used by the font selection buttons.
        
        @param fontSample reference to the font sample widget (QLineEdit)
        @param fontVar reference to the variable containing the font (QFont)
        @param showFontInfo flag indicating to show some font info
            as the sample (boolean)
        @return selected font (QFont)
        """
        font, ok = QFontDialog.getFont(fontVar)
        if ok:
            fontSample.setFont(font)
            if showFontInfo:
                fontSample.setText(
                    "{0} {1}".format(font.family(), font.pointSize()))
        else:
            font = fontVar
        return font

eric ide

mercurial