Plugins/WizardPlugins/FontDialogWizard/FontDialogWizardDialog.py

Wed, 01 Jan 2014 14:40:41 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 01 Jan 2014 14:40:41 +0100
branch
5_3_x
changeset 3163
9f50365a0870
parent 2302
f29e9405c851
permissions
-rw-r--r--

Updated copyright for 2014.

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

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

"""
Module implementing the font dialog wizard dialog.
"""

import os

from PyQt4.QtCore import pyqtSlot
from PyQt4.QtGui import QDialog, QDialogButtonBox, QFontDialog

from .Ui_FontDialogWizardDialog import Ui_FontDialogWizardDialog


class FontDialogWizardDialog(QDialog, Ui_FontDialogWizardDialog):
    """
    Class implementing the font dialog wizard dialog.
    
    It displays a dialog for entering the parameters
    for the QFontDialog code generator.
    """
    def __init__(self, parent=None):
        """
        Constructor
        
        @param parent parent widget (QWidget)
        """
        super().__init__(parent)
        self.setupUi(self)
        
        self.bTest = \
            self.buttonBox.addButton(self.trUtf8("Test"), QDialogButtonBox.ActionRole)
        
        self.font = None
        
    def on_buttonBox_clicked(self, button):
        """
        Private slot called by a button of the button box clicked.
        
        @param button button that was clicked (QAbstractButton)
        """
        if button == self.bTest:
            self.on_bTest_clicked()
    
    @pyqtSlot()
    def on_bTest_clicked(self):
        """
        Private method to test the selected options.
        """
        if self.font is None:
            QFontDialog.getFont()
        else:
            QFontDialog.getFont(self.font)
        
    def on_eVariable_textChanged(self, text):
        """
        Private slot to handle the textChanged signal of eVariable.
        
        @param text the new text (string)
        """
        if not text:
            self.bTest.setEnabled(True)
        else:
            self.bTest.setEnabled(False)
        
    @pyqtSlot()
    def on_fontButton_clicked(self):
        """
        Private slot to handle the button press to select a font via a font selection
        dialog.
        """
        if self.font is None:
            font, ok = QFontDialog.getFont()
        else:
            font, ok = QFontDialog.getFont(self.font)
        if ok:
            self.font = font
        else:
            self.font = None
        
    def getCode(self, indLevel, indString):
        """
        Public method to get the source code.
        
        @param indLevel indentation level (int)
        @param indString string used for indentation (space or tab) (string)
        @return generated code (string)
        """
        estring = os.linesep + indLevel * indString
        
        # generate the code
        code = 'QFontDialog.getFont('
        if not self.eVariable.text():
            if self.font is not None:
                code += 'QFont("{0}", {1:d}, {2:d}, {3:d})'.format(
                    self.font.family(), self.font.pointSize(),
                    self.font.weight(), self.font.italic())
        else:
            code += self.eVariable.text()
        code += '){0}'.format(estring)
            
        return code

eric ide

mercurial