eric6/Preferences/ToolGroupConfigurationDialog.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7229
53054eb5b15a
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2002 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a configuration dialog for the tools menu.
8 """
9
10 from __future__ import unicode_literals
11
12 import copy
13
14 from PyQt5.QtCore import Qt, pyqtSlot
15 from PyQt5.QtWidgets import QDialog
16
17 from E5Gui import E5MessageBox
18
19 from .Ui_ToolGroupConfigurationDialog import Ui_ToolGroupConfigurationDialog
20
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 super(ToolGroupConfigurationDialog, self).__init__(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 @pyqtSlot()
47 def on_newButton_clicked(self):
48 """
49 Private slot to clear all entry fields.
50 """
51 self.nameEdit.clear()
52
53 @pyqtSlot()
54 def on_addButton_clicked(self):
55 """
56 Private slot to add a new entry.
57 """
58 groupName = self.nameEdit.text()
59
60 if not groupName:
61 E5MessageBox.critical(
62 self,
63 self.tr("Add tool group entry"),
64 self.tr("You have to give a name for the group to add."))
65 return
66
67 if len(self.groupsList.findItems(
68 groupName, Qt.MatchFlags(Qt.MatchExactly))):
69 E5MessageBox.critical(
70 self,
71 self.tr("Add tool group entry"),
72 self.tr("An entry for the group name {0} already exists.")
73 .format(groupName))
74 return
75
76 self.groupsList.addItem(groupName)
77 self.toolGroups.append([groupName, []])
78
79 @pyqtSlot()
80 def on_changeButton_clicked(self):
81 """
82 Private slot to change an entry.
83 """
84 row = self.groupsList.currentRow()
85 if row < 0:
86 return
87
88 groupName = self.nameEdit.text()
89
90 if not groupName:
91 E5MessageBox.critical(
92 self,
93 self.tr("Add tool group entry"),
94 self.tr("You have to give a name for the group to add."))
95 return
96
97 if len(self.groupsList.findItems(
98 groupName, Qt.MatchFlags(Qt.MatchExactly))):
99 E5MessageBox.critical(
100 self,
101 self.tr("Add tool group entry"),
102 self.tr("An entry for the group name {0} already exists.")
103 .format(groupName))
104 return
105
106 self.toolGroups[row][0] = groupName
107 self.groupsList.currentItem().setText(groupName)
108
109 @pyqtSlot()
110 def on_deleteButton_clicked(self):
111 """
112 Private slot to delete the selected entry.
113 """
114 row = self.groupsList.currentRow()
115 if row < 0:
116 return
117
118 res = E5MessageBox.yesNo(
119 self,
120 self.tr("Delete tool group entry"),
121 self.tr("""<p>Do you really want to delete the tool group"""
122 """ <b>"{0}"</b>?</p>""")
123 .format(self.groupsList.currentItem().text()),
124 icon=E5MessageBox.Warning)
125 if not res:
126 return
127
128 if row == self.currentGroup:
129 # set to default group if current group gets deleted
130 self.currentGroup = -1
131
132 del self.toolGroups[row]
133 itm = self.groupsList.takeItem(row)
134 del itm
135 if row >= len(self.toolGroups):
136 row -= 1
137 self.groupsList.setCurrentRow(row)
138 self.on_groupsList_currentRowChanged(row)
139
140 @pyqtSlot()
141 def on_downButton_clicked(self):
142 """
143 Private slot to move an entry down in the list.
144 """
145 curr = self.groupsList.currentRow()
146 self.__swap(curr, curr + 1)
147 self.groupsList.clear()
148 for group in self.toolGroups:
149 self.groupsList.addItem(group[0])
150 self.groupsList.setCurrentRow(curr + 1)
151 if curr + 1 == len(self.toolGroups):
152 self.downButton.setEnabled(False)
153 self.upButton.setEnabled(True)
154
155 @pyqtSlot()
156 def on_upButton_clicked(self):
157 """
158 Private slot to move an entry up in the list.
159 """
160 curr = self.groupsList.currentRow()
161 self.__swap(curr - 1, curr)
162 self.groupsList.clear()
163 for group in self.toolGroups:
164 self.groupsList.addItem(group[0])
165 self.groupsList.setCurrentRow(curr - 1)
166 if curr - 1 == 0:
167 self.upButton.setEnabled(False)
168 self.downButton.setEnabled(True)
169
170 def on_groupsList_currentRowChanged(self, row):
171 """
172 Private slot to set the lineedits depending on the selected entry.
173
174 @param row the row of the selected entry (integer)
175 """
176 if row >= 0 and row < len(self.toolGroups):
177 group = self.toolGroups[row]
178 self.nameEdit.setText(group[0])
179
180 self.deleteButton.setEnabled(True)
181 self.changeButton.setEnabled(True)
182
183 if row != 0:
184 self.upButton.setEnabled(True)
185 else:
186 self.upButton.setEnabled(False)
187
188 if row + 1 != len(self.toolGroups):
189 self.downButton.setEnabled(True)
190 else:
191 self.downButton.setEnabled(False)
192 else:
193 self.nameEdit.clear()
194 self.downButton.setEnabled(False)
195 self.upButton.setEnabled(False)
196 self.deleteButton.setEnabled(False)
197 self.changeButton.setEnabled(False)
198
199 def getToolGroups(self):
200 """
201 Public method to retrieve the tool groups.
202
203 @return a list of lists containing the group name and the
204 tool group entries
205 """
206 return self.toolGroups[:], self.currentGroup
207
208 def __swap(self, itm1, itm2):
209 """
210 Private method used two swap two list entries given by their index.
211
212 @param itm1 index of first entry (int)
213 @param itm2 index of second entry (int)
214 """
215 tmp = self.toolGroups[itm1]
216 self.toolGroups[itm1] = self.toolGroups[itm2]
217 self.toolGroups[itm2] = tmp

eric ide

mercurial