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

« back to all changes in this revision

Viewing changes to eric/Preferences/ToolGroupConfigurationDialog.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) 2002 - 2007 Detlev Offenbach <detlev@die-offenbachs.de>
 
4
#
 
5
 
 
6
"""
 
7
Module implementing a configuration dialog for the tools menu.
 
8
"""
 
9
 
 
10
import sys
 
11
import os
 
12
import copy
 
13
 
 
14
from PyQt4.QtCore import *
 
15
from PyQt4.QtGui import *
 
16
 
 
17
from KdeQt import KQMessageBox
 
18
 
 
19
from Ui_ToolGroupConfigurationDialog import Ui_ToolGroupConfigurationDialog
 
20
import Utilities
 
21
 
 
22
class ToolGroupConfigurationDialog(QDialog, Ui_ToolGroupConfigurationDialog):
 
23
    """
 
24
    Class implementing a configuration dialog for the tool groups.
 
25
    """
 
26
    def __init__(self, toolGroups, currentGroup, parent = None):
 
27
        """
 
28
        Constructor
 
29
        
 
30
        @param toolGroups list of configured tool groups
 
31
        @param currentGroup number of the active group (integer)
 
32
        @param parent parent widget (QWidget)
 
33
        """
 
34
        QDialog.__init__(self, parent)
 
35
        self.setupUi(self)
 
36
        
 
37
        self.currentGroup = currentGroup
 
38
        self.toolGroups = copy.deepcopy(toolGroups)
 
39
        for group in toolGroups:
 
40
            self.groupsList.addItem(group[0])
 
41
        
 
42
        if len(toolGroups):
 
43
            self.groupsList.setCurrentRow(0)
 
44
            self.on_groupsList_currentRowChanged(0)
 
45
        
 
46
    @pyqtSignature("")
 
47
    def on_newButton_clicked(self):
 
48
        """
 
49
        Private slot to clear all entry fields.
 
50
        """
 
51
        self.nameEdit.clear()
 
52
        
 
53
    @pyqtSignature("")
 
54
    def on_addButton_clicked(self):
 
55
        """
 
56
        Private slot to add a new entry.
 
57
        """
 
58
        groupName = self.nameEdit.text()
 
59
        
 
60
        if groupName.isEmpty():
 
61
            KQMessageBox.critical(self,
 
62
                self.trUtf8("Add tool group entry"),
 
63
                self.trUtf8("You have to give a name for the group to add."))
 
64
            return
 
65
        
 
66
        if len(self.groupsList.findItems(groupName, Qt.MatchFlags(Qt.MatchExactly))):
 
67
            KQMessageBox.critical(self,
 
68
                self.trUtf8("Add tool group entry"),
 
69
                self.trUtf8("An entry for the group name %1 already exists.")\
 
70
                    .arg(groupName))
 
71
            return
 
72
        
 
73
        self.groupsList.addItem(unicode(groupName))
 
74
        self.toolGroups.append([unicode(groupName), []])
 
75
    
 
76
    @pyqtSignature("")
 
77
    def on_changeButton_clicked(self):
 
78
        """
 
79
        Private slot to change an entry.
 
80
        """
 
81
        row = self.groupsList.currentRow()
 
82
        if row < 0:
 
83
            return
 
84
        
 
85
        groupName = self.nameEdit.text()
 
86
        
 
87
        if groupName.isEmpty():
 
88
            KQMessageBox.critical(self,
 
89
                self.trUtf8("Add tool group entry"),
 
90
                self.trUtf8("You have to give a name for the group to add."))
 
91
            return
 
92
        
 
93
        if len(self.groupsList.findItems(groupName, Qt.MatchFlags(Qt.MatchExactly))):
 
94
            KQMessageBox.critical(self,
 
95
                self.trUtf8("Add tool group entry"),
 
96
                self.trUtf8("An entry for the group name %1 already exists.")\
 
97
                    .arg(groupName))
 
98
            return
 
99
            
 
100
        self.toolGroups[row][0] = unicode(groupName)
 
101
        self.groupsList.currentItem().setText(groupName)
 
102
        
 
103
    @pyqtSignature("")
 
104
    def on_deleteButton_clicked(self):
 
105
        """
 
106
        Private slot to delete the selected entry.
 
107
        """
 
108
        row = self.groupsList.currentRow()
 
109
        if row < 0:
 
110
            return
 
111
        
 
112
        res = KQMessageBox.warning(None,
 
113
            self.trUtf8("Delete tool group entry"),
 
114
            self.trUtf8("""<p>Do you really want to delete the tool group"""
 
115
                        """ <b>"%1"</b>?</p>""")\
 
116
                .arg(self.groupsList.currentItem().text()),
 
117
            QMessageBox.StandardButtons(\
 
118
                QMessageBox.No | \
 
119
                QMessageBox.Yes),
 
120
            QMessageBox.No)
 
121
        if res != QMessageBox.Yes:
 
122
            return
 
123
        
 
124
        if row == self.currentGroup:
 
125
            # set to default group if current group gets deleted
 
126
            self.currentGroup = -1
 
127
        
 
128
        del self.toolGroups[row]
 
129
        itm = self.groupsList.takeItem(row)
 
130
        del itm
 
131
        if row >= len(self.toolGroups):
 
132
            row -= 1
 
133
        self.groupsList.setCurrentRow(row)
 
134
        self.on_groupsList_currentRowChanged(row)
 
135
        
 
136
    @pyqtSignature("")
 
137
    def on_downButton_clicked(self):
 
138
        """
 
139
        Private slot to move an entry down in the list.
 
140
        """
 
141
        curr = self.groupsList.currentRow()
 
142
        self.__swap(curr, curr+1)
 
143
        self.groupsList.clear()
 
144
        for group in self.toolGroups:
 
145
            self.groupsList.addItem(group[0])
 
146
        self.groupsList.setCurrentRow(curr + 1)
 
147
        if curr + 1 == len(self.toolGroups):
 
148
            self.downButton.setEnabled(False)
 
149
        self.upButton.setEnabled(True)
 
150
        
 
151
    @pyqtSignature("")
 
152
    def on_upButton_clicked(self):
 
153
        """
 
154
        Private slot to move an entry up in the list.
 
155
        """
 
156
        curr = self.groupsList.currentRow()
 
157
        self.__swap(curr-1, curr)
 
158
        self.groupsList.clear()
 
159
        for group in self.toolGroups:
 
160
            self.groupsList.addItem(group[0])
 
161
        self.groupsList.setCurrentRow(curr - 1)
 
162
        if curr - 1 == 0:
 
163
            self.upButton.setEnabled(False)
 
164
        self.downButton.setEnabled(True)
 
165
        
 
166
    def on_groupsList_currentRowChanged(self, row):
 
167
        """
 
168
        Private slot to set the lineedits depending on the selected entry.
 
169
        
 
170
        @param row the row of the selected entry (integer)
 
171
        """
 
172
        if row >= 0 and row < len(self.toolGroups):
 
173
            group = self.toolGroups[row]
 
174
            self.nameEdit.setText(group[0])
 
175
            
 
176
            self.deleteButton.setEnabled(True)
 
177
            self.changeButton.setEnabled(True)
 
178
            
 
179
            if row != 0:
 
180
                self.upButton.setEnabled(True)
 
181
            else:
 
182
                self.upButton.setEnabled(False)
 
183
            
 
184
            if row+1 != len(self.toolGroups):
 
185
                self.downButton.setEnabled(True)
 
186
            else:
 
187
                self.downButton.setEnabled(False)
 
188
        else:
 
189
            self.nameEdit.clear()
 
190
            self.downButton.setEnabled(False)
 
191
            self.upButton.setEnabled(False)
 
192
            self.deleteButton.setEnabled(False)
 
193
            self.changeButton.setEnabled(False)
 
194
        
 
195
    def getToolGroups(self):
 
196
        """
 
197
        Public method to retrieve the tool groups. 
 
198
        
 
199
        @return a list of lists containing the group name and the
 
200
            tool group entries
 
201
        """
 
202
        return self.toolGroups[:], self.currentGroup
 
203
        
 
204
    def __swap(self, itm1, itm2):
 
205
        """
 
206
        Private method used two swap two list entries given by their index.
 
207
        
 
208
        @param itm1 index of first entry (int)
 
209
        @param itm2 index of second entry (int)
 
210
        """
 
211
        tmp = self.toolGroups[itm1]
 
212
        self.toolGroups[itm1] = self.toolGroups[itm2]
 
213
        self.toolGroups[itm2] = tmp