Plugins/WizardPlugins/InputDialogWizard/InputDialogWizardDialog.py

changeset 0
de9c2efb9d02
child 12
1d8dd9706f46
diff -r 000000000000 -r de9c2efb9d02 Plugins/WizardPlugins/InputDialogWizard/InputDialogWizardDialog.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/WizardPlugins/InputDialogWizard/InputDialogWizardDialog.py	Mon Dec 28 16:03:33 2009 +0000
@@ -0,0 +1,197 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2003 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing the input dialog wizard dialog.
+"""
+
+import os
+
+from PyQt4.QtCore import *
+from PyQt4.QtGui import *
+
+from E4Gui.E4Application import e4App
+
+from Ui_InputDialogWizardDialog import Ui_InputDialogWizardDialog
+
+class InputDialogWizardDialog(QDialog, Ui_InputDialogWizardDialog):
+    """
+    Class implementing the input dialog wizard dialog.
+    
+    It displays a dialog for entering the parameters
+    for the QInputDialog code generator.
+    """
+    def __init__(self, parent=None):
+        """
+        Constructor
+        
+        @param parent parent widget (QWidget)
+        """
+        QDialog.__init__(self, parent)
+        self.setupUi(self)
+        
+        # set the validators for the double line edots
+        self.eDoubleDefault.setValidator(\
+            QDoubleValidator(-2147483647, 2147483647, 99, self.eDoubleDefault))
+        self.eDoubleFrom.setValidator(\
+            QDoubleValidator(-2147483647, 2147483647, 99, self.eDoubleFrom))
+        self.eDoubleTo.setValidator(\
+            QDoubleValidator(-2147483647, 2147483647, 99, self.eDoubleTo))
+        
+        self.bTest = \
+            self.buttonBox.addButton(self.trUtf8("Test"), QDialogButtonBox.ActionRole)
+        
+    @pyqtSlot(bool)
+    def on_rItem_toggled(self, checked):
+        """
+        Private slot to perform actions dependant on the item type selection.
+        
+        @param checked flag indicating the checked state (boolean)
+        """
+        self.bTest.setEnabled(not checked)
+        
+    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.rText.isChecked():
+            if self.rEchoNormal.isChecked():
+                echomode = QLineEdit.Normal
+            elif self.rEchoNoEcho.isChecked():
+                echomode = QLineEdit.NoEcho
+            else:
+                echomode = QLineEdit.Password
+            QInputDialog.getText(\
+                None,
+                self.eCaption.text(),
+                self.eLabel.text(),
+                echomode,
+                self.eTextDefault.text())
+        elif self.rInteger.isChecked():
+            QInputDialog.getInteger(\
+                None,
+                self.eCaption.text(),
+                self.eLabel.text(),
+                self.sIntDefault.value(),
+                self.sIntFrom.value(),
+                self.sIntTo.value(),
+                self.sIntStep.value())
+        elif self.rDouble.isChecked():
+            try:
+                doubleDefault = float(self.eDoubleDefault.text())
+            except ValueError:
+                doubleDefault = 0
+            try:
+                doubleFrom = float(self.eDoubleFrom.text())
+            except ValueError:
+                doubleFrom = -2147483647
+            try:
+                doubleTo = float(self.eDoubleTo.text())
+            except ValueError:
+                doubleTo = 2147483647
+            QInputDialog.getDouble(\
+                None,
+                self.eCaption.text(),
+                self.eLabel.text(),
+                doubleDefault,
+                doubleFrom,
+                doubleTo,
+                self.sDoubleDecimals.value())
+        
+    def __getCode4(self, indLevel, indString):
+        """
+        Private method to get the source code for Qt4.
+        
+        @param indLevel indentation level (int)
+        @param indString string used for indentation (space or tab) (string)
+        @return generated code (string)
+        """
+        # calculate our indentation level and the indentation string
+        il = indLevel + 1
+        istring = il * indString
+        
+        # now generate the code
+        code = 'QInputDialog.'
+        if self.rText.isChecked():
+            code += 'getText(\\%s%s' % (os.linesep, istring)
+            code += 'None,%s%s' % (os.linesep, istring)
+            code += 'self.trUtf8("%s"),%s%s' % \
+                (self.eCaption.text(), os.linesep, istring)
+            code += 'self.trUtf8("%s"),%s%s' % \
+                (self.eLabel.text(), os.linesep, istring)
+            if self.rEchoNormal.isChecked():
+                code += 'QLineEdit.Normal'
+            elif self.rEchoNoEcho.isChecked():
+                code += 'QLineEdit.NoEcho'
+            else:
+                code += 'QLineEdit.Password'
+            if self.eTextDefault.text():
+                code += ',%s%sself.trUtf8("%s")' % \
+                    (os.linesep, istring, self.eTextDefault.text())
+            code += ')%s' % os.linesep
+        elif self.rInteger.isChecked():
+            code += 'getInteger(\\%s%s' % (os.linesep, istring)
+            code += 'None,%s%s' % (os.linesep, istring)
+            code += 'self.trUtf8("%s"),%s%s' % \
+                (self.eCaption.text(), os.linesep, istring)
+            code += 'self.trUtf8("%s"),%s%s' % \
+                (self.eLabel.text(), os.linesep, istring)
+            code += '%d, %d, %d, %d)%s' % \
+                (self.sIntDefault.value(), self.sIntFrom.value(),
+                self.sIntTo.value(), self.sIntStep.value(), os.linesep)
+        elif self.rDouble.isChecked():
+            try:
+                doubleDefault = float(self.eDoubleDefault.text())
+            except ValueError:
+                doubleDefault = 0
+            try:
+                doubleFrom = float(self.eDoubleFrom.text())
+            except ValueError:
+                doubleFrom = -2147483647
+            try:
+                doubleTo = float(self.eDoubleTo.text())
+            except ValueError:
+                doubleTo = 2147483647
+            code += 'getDouble(\\%s%s' % (os.linesep, istring)
+            code += 'None,%s%s' % (os.linesep, istring)
+            code += 'self.trUtf8("%s"),%s%s' % \
+                (self.eCaption.text(), os.linesep, istring)
+            code += 'self.trUtf8("%s"),%s%s' % \
+                (self.eLabel.text(), os.linesep, istring)
+            code += '%s, %s, %s, %d)%s' % \
+                (doubleDefault, doubleFrom, doubleTo, 
+                self.sDoubleDecimals.value(), os.linesep)
+        elif self.rItem.isChecked():
+            code += 'getItem(\\%s%s' % (os.linesep, istring)
+            code += 'None,%s%s' % (os.linesep, istring)
+            code += 'self.trUtf8("%s"),%s%s' % \
+                (self.eCaption.text(), os.linesep, istring)
+            code += 'self.trUtf8("%s"),%s%s' % \
+                (self.eLabel.text(), os.linesep, istring)
+            code += '%s,%s%s' % (self.eVariable.text(), os.linesep, istring)
+            code += '%d, %s)%s' % \
+                (self.sCurrentItem.value(), self.cEditable.isChecked(), os.linesep)
+            
+        return code
+        
+    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)
+        """
+        return self.__getCode4(indLevel, indString)

eric ide

mercurial