~ubuntu-branches/ubuntu/karmic/eric/karmic

« back to all changes in this revision

Viewing changes to eric/UI/TemplateMultipleVariablesDialog.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2008-01-28 18:02:25 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080128180225-6nrox6yrworh2c4v
Tags: 4.0.4-1ubuntu1
* Add python-qt3 to build-depends becuase that's where Ubuntu puts 
  pyqtconfig
* Change maintainer to MOTU

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
 
3
 
# Copyright (c) 2005 - 2007 Detlev Offenbach <detlev@die-offenbachs.de>
4
 
#
5
 
 
6
 
"""
7
 
Module implementing a dialog for entering multiple template variables.
8
 
"""
9
 
 
10
 
from qt import *
11
 
 
12
 
class TemplateMultipleVariablesDialog(QDialog):
13
 
    """
14
 
    Class implementing a dialog for entering multiple template variables.
15
 
    """
16
 
    def __init__(self, variables, parent = None):
17
 
        """
18
 
        Constructor
19
 
        
20
 
        @param variables list of template variable names (list of strings)
21
 
        @param parent parent widget of this dialog (QWidget)
22
 
        """
23
 
        QDialog.__init__(self, parent, None, 1)
24
 
 
25
 
        TemplateMultipleVariablesDialogLayout = \
26
 
            QVBoxLayout(self, 6, 6,"TemplateMultipleVariablesDialogLayout")
27
 
 
28
 
        # generate the scrollview
29
 
        self.variablesView = QScrollView(self, "variablesView")
30
 
        self.variablesView.setFrameStyle(QFrame.NoFrame)
31
 
        TemplateMultipleVariablesDialogLayout.addWidget(self.variablesView)
32
 
        
33
 
        self.variablesView.setResizePolicy(QScrollView.AutoOneFit)
34
 
        
35
 
        top = QWidget(self.variablesView.viewport())
36
 
        self.variablesView.addChild(top)
37
 
        grid = QGridLayout(top, len(variables), 2)
38
 
        grid.setMargin(6)
39
 
        grid.setSpacing(6)
40
 
 
41
 
        # populate the scrollview with labels and text edits
42
 
        self.variablesEntries = {}
43
 
        row = 0
44
 
        for var in variables:
45
 
            l = QLabel("%s:" % var, top)
46
 
            grid.addWidget(l, row, 0, Qt.AlignTop)
47
 
            if var.find(":") >= 0:
48
 
                formatStr = var[1:-1].split(":")[1]
49
 
                if formatStr in ["ml"]:
50
 
                    t = QTextEdit(top)
51
 
                    t.setTabChangesFocus(1)
52
 
                else:
53
 
                    t = QLineEdit(top)
54
 
            else:
55
 
                t = QLineEdit(top)
56
 
            grid.addWidget(t, row, 1)
57
 
            self.variablesEntries[var] = t
58
 
            row += 1
59
 
        self.variablesEntries[variables[0]].setFocus()
60
 
 
61
 
        # generate the buttons
62
 
        layout1 = QHBoxLayout(None,0,6,"layout1")
63
 
        spacer1 = QSpacerItem(40,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
64
 
        layout1.addItem(spacer1)
65
 
 
66
 
        self.okButton = QPushButton(self,"okButton")
67
 
        self.okButton.setDefault(1)
68
 
        layout1.addWidget(self.okButton)
69
 
 
70
 
        self.cancelButton = QPushButton(self,"cancelButton")
71
 
        layout1.addWidget(self.cancelButton)
72
 
        spacer2 = QSpacerItem(40,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
73
 
        layout1.addItem(spacer2)
74
 
        TemplateMultipleVariablesDialogLayout.addLayout(layout1)
75
 
 
76
 
        # set the texts of the standard widgets
77
 
        self.setCaption(self.trUtf8("Enter Template Variables"))
78
 
        self.okButton.setText(self.trUtf8("&OK"))
79
 
        self.okButton.setAccel(self.trUtf8("Alt+O"))
80
 
        self.cancelButton.setText(self.trUtf8("&Cancel"))
81
 
        self.cancelButton.setAccel(self.trUtf8("Alt+C"))
82
 
 
83
 
        # polish up the dialog
84
 
        self.resize(QSize(400,480).expandedTo(self.minimumSizeHint()))
85
 
        self.clearWState(Qt.WState_Polished)
86
 
 
87
 
        self.connect(self.okButton,SIGNAL("clicked()"),self.accept)
88
 
        self.connect(self.cancelButton,SIGNAL("clicked()"),self.reject)
89
 
 
90
 
    def getVariables(self):
91
 
        """
92
 
        Public method to get the values for all variables.
93
 
        
94
 
        @return dictionary with the variable as a key and its value (string)
95
 
        """
96
 
        values = {}
97
 
        for var, textEdit in self.variablesEntries.items():
98
 
            values[var] = unicode(textEdit.text())
99
 
        return values