Preferences/ToolGroupConfigurationDialog.py

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

eric ide

mercurial