1
# -*- coding: utf-8 -*-
3
# Copyright (c) 2002 - 2007 Detlev Offenbach <detlev@die-offenbachs.de>
7
Module implementing a configuration dialog for the tools menu.
14
from PyQt4.QtCore import *
15
from PyQt4.QtGui import *
17
from KdeQt import KQMessageBox
19
from Ui_ToolGroupConfigurationDialog import Ui_ToolGroupConfigurationDialog
22
class ToolGroupConfigurationDialog(QDialog, Ui_ToolGroupConfigurationDialog):
24
Class implementing a configuration dialog for the tool groups.
26
def __init__(self, toolGroups, currentGroup, parent = None):
30
@param toolGroups list of configured tool groups
31
@param currentGroup number of the active group (integer)
32
@param parent parent widget (QWidget)
34
QDialog.__init__(self, parent)
37
self.currentGroup = currentGroup
38
self.toolGroups = copy.deepcopy(toolGroups)
39
for group in toolGroups:
40
self.groupsList.addItem(group[0])
43
self.groupsList.setCurrentRow(0)
44
self.on_groupsList_currentRowChanged(0)
47
def on_newButton_clicked(self):
49
Private slot to clear all entry fields.
54
def on_addButton_clicked(self):
56
Private slot to add a new entry.
58
groupName = self.nameEdit.text()
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."))
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.")\
73
self.groupsList.addItem(unicode(groupName))
74
self.toolGroups.append([unicode(groupName), []])
77
def on_changeButton_clicked(self):
79
Private slot to change an entry.
81
row = self.groupsList.currentRow()
85
groupName = self.nameEdit.text()
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."))
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.")\
100
self.toolGroups[row][0] = unicode(groupName)
101
self.groupsList.currentItem().setText(groupName)
104
def on_deleteButton_clicked(self):
106
Private slot to delete the selected entry.
108
row = self.groupsList.currentRow()
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(\
121
if res != QMessageBox.Yes:
124
if row == self.currentGroup:
125
# set to default group if current group gets deleted
126
self.currentGroup = -1
128
del self.toolGroups[row]
129
itm = self.groupsList.takeItem(row)
131
if row >= len(self.toolGroups):
133
self.groupsList.setCurrentRow(row)
134
self.on_groupsList_currentRowChanged(row)
137
def on_downButton_clicked(self):
139
Private slot to move an entry down in the list.
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)
152
def on_upButton_clicked(self):
154
Private slot to move an entry up in the list.
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)
163
self.upButton.setEnabled(False)
164
self.downButton.setEnabled(True)
166
def on_groupsList_currentRowChanged(self, row):
168
Private slot to set the lineedits depending on the selected entry.
170
@param row the row of the selected entry (integer)
172
if row >= 0 and row < len(self.toolGroups):
173
group = self.toolGroups[row]
174
self.nameEdit.setText(group[0])
176
self.deleteButton.setEnabled(True)
177
self.changeButton.setEnabled(True)
180
self.upButton.setEnabled(True)
182
self.upButton.setEnabled(False)
184
if row+1 != len(self.toolGroups):
185
self.downButton.setEnabled(True)
187
self.downButton.setEnabled(False)
189
self.nameEdit.clear()
190
self.downButton.setEnabled(False)
191
self.upButton.setEnabled(False)
192
self.deleteButton.setEnabled(False)
193
self.changeButton.setEnabled(False)
195
def getToolGroups(self):
197
Public method to retrieve the tool groups.
199
@return a list of lists containing the group name and the
202
return self.toolGroups[:], self.currentGroup
204
def __swap(self, itm1, itm2):
206
Private method used two swap two list entries given by their index.
208
@param itm1 index of first entry (int)
209
@param itm2 index of second entry (int)
211
tmp = self.toolGroups[itm1]
212
self.toolGroups[itm1] = self.toolGroups[itm2]
213
self.toolGroups[itm2] = tmp