RefactoringRope/GetterSetterDialog.py

Fri, 01 Jan 2016 12:19:02 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 01 Jan 2016 12:19:02 +0100
changeset 144
bfc6a3b38330
parent 94
03d6a17c66ac
child 147
3f8a995f6e49
permissions
-rw-r--r--

Updated copyright for 2016.

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

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

"""
Module implementing a dialog to create getter and setter method names.
"""

from __future__ import unicode_literals

from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QDialog

from Ui_GetterSetterDialog import Ui_GetterSetterDialog


class GetterSetterDialog(QDialog, Ui_GetterSetterDialog):
    """
    Class implementing a dialog to create getter and setter method names.
    """
    def __init__(self, fieldName, parent=None):
        """
        Constructor
        
        @param fieldName name of the field to create getter and setter
            method names (string)
        @param parent parent widget of the dialog (QWidget)
        """
        QDialog.__init__(self, parent)
        self.setupUi(self)
        
        self.__fieldName = fieldName
        
        self.on_typeCheckBox_toggled(False)
        
        msh = self.minimumSizeHint()
        self.resize(max(self.width(), msh.width()), msh.height())
    
    @pyqtSlot(bool)
    def on_typeCheckBox_toggled(self, checked):
        """
        Private slot to react to changes of the type checkbox.
        
        @param checked state of the checkbox (boolean)
        """
        if checked:
            self.getterEdit.setText("get_{0}".format(self.__fieldName))
            self.setterEdit.setText("set_{0}".format(self.__fieldName))
        else:
            self.getterEdit.setText(
                "get{0}{1}".format(self.__fieldName[0].upper(),
                                   self.__fieldName[1:]))
            self.setterEdit.setText(
                "set{0}{1}".format(self.__fieldName[0].upper(),
                                   self.__fieldName[1:]))
    
    def getData(self):
        """
        Public method to return the getter and setter method names.
        
        @return tuple of two strings with getter and setter method names
        """
        return (self.getterEdit.text(), self.setterEdit.text())

eric ide

mercurial