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

« back to all changes in this revision

Viewing changes to eric/UI/TemplatePropertiesDialog.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 the templates properties dialog.
8
 
"""
9
 
 
10
 
from qt import *
11
 
 
12
 
from KdeQt import KQMessageBox
13
 
 
14
 
from TemplatePropertiesForm import TemplatePropertiesForm
15
 
 
16
 
 
17
 
class TemplatePropertiesDialog(TemplatePropertiesForm):
18
 
    """
19
 
    Class implementing the templates properties dialog.
20
 
    """
21
 
    def __init__(self, parent, groupMode = 0, itm = None):
22
 
        """
23
 
        Constructor
24
 
        
25
 
        @param parent the parent widget (QWidget)
26
 
        @param groupMode flag indicating group mode (boolean)
27
 
        @param itm item (TemplateEntry or TemplateGroup) to
28
 
            read the data from
29
 
        """
30
 
        TemplatePropertiesForm.__init__(self, parent, None, 1)
31
 
        
32
 
        self.languages = [
33
 
            ("All", self.trUtf8("All")),
34
 
            ("Bash", self.trUtf8("Bash")),
35
 
            ("Batch", self.trUtf8("Batch")),
36
 
            ("C/C++", self.trUtf8("C++")),
37
 
            ("C#", self.trUtf8("C#")),
38
 
            ("HTML/XML", self.trUtf8("HTML/XML")),
39
 
            ("IDL", self.trUtf8("IDL")),
40
 
            ("Java", self.trUtf8("Java")),
41
 
            ("JavaScript", self.trUtf8("JavaScript")),
42
 
            ("Lua", self.trUtf8("Lua")),
43
 
            ("Makefile", self.trUtf8("Makefile")),
44
 
            ("Perl", self.trUtf8("Perl")),
45
 
            ("Properties", self.trUtf8("Properties")),
46
 
            ("Python", self.trUtf8("Python")),
47
 
            ("Ruby", self.trUtf8("Ruby")),
48
 
            ("SQL", self.trUtf8("SQL")),
49
 
            ("TeX", self.trUtf8("TeX")),
50
 
        ]
51
 
        
52
 
        self.groupMode = groupMode
53
 
        if groupMode:
54
 
            langList = QStringList()
55
 
            for lang, langDisp in self.languages:
56
 
                langList.append(langDisp)
57
 
            
58
 
            self.groupLabel.setText(self.trUtf8("Language:"))
59
 
            self.groupCombo.insertStringList(langList)
60
 
            self.templateLabel.setEnabled(0)
61
 
            self.templateEdit.setEnabled(0)
62
 
            self.templateEdit.setText(self.trUtf8("GROUP"))
63
 
            self.helpButton.setEnabled(0)
64
 
        else:
65
 
            groups = QStringList()
66
 
            for group in parent.getGroupNames():
67
 
                groups.append(group)
68
 
            self.groupCombo.insertStringList(groups)
69
 
        
70
 
        if itm is not None:
71
 
            self.nameEdit.setText(itm.getName())
72
 
            if groupMode:
73
 
                lang = itm.getLanguage()
74
 
                for l, d in self.languages:
75
 
                    if l == lang:
76
 
                        self.groupCombo.setCurrentText(d)
77
 
                        break
78
 
            else:
79
 
                self.groupCombo.setCurrentText(itm.getGroupName())
80
 
                self.templateEdit.setText(itm.getTemplateText())
81
 
 
82
 
    def handleHelp(self):
83
 
        """
84
 
        Public slot to show some help.
85
 
        """
86
 
        KQMessageBox.information(self,
87
 
            self.trUtf8("Template Help"),
88
 
            self.trUtf8("""<p>To use variables in a template, you just have to enclose"""
89
 
                        """ the variablename with $-characters. When you use the template,"""
90
 
                        """ you will then be asked for a value for this variable.</p>"""
91
 
                        """<p>Example template: This is a $VAR$</p>"""
92
 
                        """<p>When you use this template you will be prompted for a value"""
93
 
                        """ for the variable $VAR$. Any occurences of $VAR$ will then be"""
94
 
                        """ replaced with whatever you've entered.</p>"""
95
 
                        """<p>If you need a single $-character in a template, which is not"""
96
 
                        """ used to enclose a variable, type $$(two dollar characters)"""
97
 
                        """ instead. They will automatically be replaced with a single"""
98
 
                        """ $-character when you use the template.</p>"""
99
 
                        """<p>If you want a variables contents to be treated specially,"""
100
 
                        """ the variablename must be followed by a ':' and one formatting"""
101
 
                        """ specifier (e.g. $VAR:ml$). The supported specifiers are:"""
102
 
                        """<table>"""
103
 
                        """<tr><td>ml</td><td>Specifies a multiline formatting."""
104
 
                        """ Each line of the variable contents is prefixed with the string"""
105
 
                        """ occuring before the variable on the same line of the template."""
106
 
                        """</td></tr>"""
107
 
                        """</table></p>"""
108
 
                        """<p>If you want to change the default delimiter to anything"""
109
 
                        """ different, please use the configuration dialog to do so.</p>"""),
110
 
            self.trUtf8("&OK"),
111
 
            QString.null,
112
 
            QString.null,
113
 
            0, -1)
114
 
 
115
 
    def setSelectedGroup(self, name):
116
 
        """
117
 
        Public method to select a group.
118
 
        
119
 
        @param name name of the group to be selected (string or QString)
120
 
        """
121
 
        self.groupCombo.setCurrentText(name)
122
 
 
123
 
    def getData(self):
124
 
        """
125
 
        Public method to get the data entered into the dialog.
126
 
        
127
 
        @return a tuple of two strings (name, language), if the dialog is in group mode,
128
 
            and a tuple of three strings (name, group name, template) otherwise.
129
 
        """
130
 
        if self.groupMode:
131
 
            return (unicode(self.nameEdit.text()),
132
 
                    self.languages[self.groupCombo.currentItem()][0]
133
 
                   )
134
 
        else:
135
 
            return (unicode(self.nameEdit.text()),
136
 
                    unicode(self.groupCombo.currentText()),
137
 
                    unicode(self.templateEdit.text())
138
 
                   )