SelectionEncloser/ConfigurationPage/SelectionEncloserPage.py

Mon, 21 Apr 2014 15:25:27 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 21 Apr 2014 15:25:27 +0200
changeset 3
b26df0282953
parent 1
a9f6842a18f6
child 7
e6addbe23b18
permissions
-rw-r--r--

Finished implementing the functionality.

1
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
3
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
3 # Copyright (c) 2014 Detlev Offenbach <detlev@die-offenbachs.de>
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
4 #
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
5
1
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing Selection Encloser configuration page.
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from __future__ import unicode_literals # __IGNORE_WARNING__
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 import os
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 from PyQt4.QtCore import pyqtSlot, Qt
3
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
15 from PyQt4.QtGui import QTreeWidgetItem, QInputDialog, QLineEdit, QDialog
1
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 from Preferences.ConfigurationPages.ConfigurationPageBase import \
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 ConfigurationPageBase
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 from .Ui_SelectionEncloserPage import Ui_SelectionEncloserPage
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 import UI.PixmapCache
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 class SelectionEncloserPage(ConfigurationPageBase, Ui_SelectionEncloserPage):
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 Class implementing Selection Encloser configuration page.
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 def __init__(self, plugin):
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 """
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 Constructor
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 @param plugin reference to the plugin object
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 super(SelectionEncloserPage, self).__init__()
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 self.setupUi(self)
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 self.setObjectName("SelectionEncloserPage")
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
3
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
38 self.editButton.setIcon(UI.PixmapCache.getIcon(
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
39 os.path.join("SelectionEncloser", "icons", "edit.png")))
1
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 self.addButton.setIcon(UI.PixmapCache.getIcon("plus.png"))
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 self.deleteButton.setIcon(UI.PixmapCache.getIcon("minus.png"))
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 self.upButton.setIcon(UI.PixmapCache.getIcon("1uparrow.png"))
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 self.downButton.setIcon(UI.PixmapCache.getIcon("1downarrow.png"))
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 self.addMenuButton.setIcon(UI.PixmapCache.getIcon(
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 os.path.join("SelectionEncloser", "icons", "topAdd.png")))
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46
3
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
47 self.editButton.setEnabled(False)
1
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 self.addButton.setEnabled(False)
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 self.deleteButton.setEnabled(False)
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 self.upButton.setEnabled(False)
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 self.downButton.setEnabled(False)
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 self.__plugin = plugin
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 # set initial values
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 hierarchy = self.__plugin.getPreferences("MenuHierarchy")
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 for menuTitle, entries in hierarchy:
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 top = QTreeWidgetItem(self.menuTree, [menuTitle])
3
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
59 for title, encString in entries:
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
60 itm = QTreeWidgetItem(top, [title])
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
61 itm.setData(0, Qt.UserRole, encString)
1
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 top.setExpanded(True)
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 def save(self):
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 """
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 Public slot to save the Selection Encloser configuration.
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 """
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 hierarchy = []
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 for topIndex in range(self.menuTree.topLevelItemCount()):
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 topItem = self.menuTree.topLevelItem(topIndex)
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 topEntry = [topItem.text(0), []]
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 for index in range(topItem.childCount()):
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 itm = topItem.child(index)
3
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
74 topEntry[1].append([itm.text(0), itm.data(0, Qt.UserRole)])
1
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 hierarchy.append(topEntry)
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 self.__plugin.setPreferences("MenuHierarchy", hierarchy)
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 @pyqtSlot()
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 def on_addMenuButton_clicked(self):
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 """
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 Private slot to add a top level menu item.
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 """
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 menuTitle, ok = QInputDialog.getText(
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 self,
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 self.tr("Menu Title"),
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 self.tr("Enter menu title:"),
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 QLineEdit.Normal)
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 if ok and menuTitle:
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 top = QTreeWidgetItem(self.menuTree, [menuTitle])
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 top.setExpanded(True)
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 @pyqtSlot()
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 def on_addButton_clicked(self):
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 """
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 Private slot to add a menu entry.
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 """
3
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
97 from .SelectionEncloserEditDialog import SelectionEncloserEditDialog
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
98 dlg = SelectionEncloserEditDialog(parent=self)
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
99 if dlg.exec_() == QDialog.Accepted:
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
100 title, encString = dlg.getData()
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
101 itm = QTreeWidgetItem(self.menuTree.selectedItems()[0], [title])
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
102 itm.setData(0, Qt.UserRole, encString)
1
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 @pyqtSlot()
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 def on_deleteButton_clicked(self):
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 """
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 Private slot to delete the selected entry.
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 """
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 itm = self.menuTree.selectedItems()[0]
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 parent = itm.parent()
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 if parent is None:
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 index = self.menuTree.indexOfTopLevelItem(itm)
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 self.menuTree.takeTopLevelItem(index)
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 else:
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 index = parent.indexOfChild(itm)
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 parent.takeChild(index)
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 del itm
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 @pyqtSlot()
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 def on_upButton_clicked(self):
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 """
3
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
122 Private slot to move an entry up.
1
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 """
3
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
124 self.__moveSelectedEntry(True)
1
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 @pyqtSlot()
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 def on_downButton_clicked(self):
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 """
3
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
129 Private slot to move an entry down.
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
130 """
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
131 self.__moveSelectedEntry(False)
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
132
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
133 def __moveSelectedEntry(self, moveUp):
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
134 """
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
135 Private method to move the selected entry up or down.
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
136 """
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
137 itm = self.menuTree.selectedItems()[0]
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
138 parent = itm.parent()
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
139 if parent is None:
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
140 # top level item
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
141 index = self.menuTree.indexOfTopLevelItem(itm)
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
142 newIndex = index - 1 if moveUp else index + 1
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
143 self.menuTree.takeTopLevelItem(index)
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
144 self.menuTree.insertTopLevelItem(newIndex, itm)
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
145 itm.setExpanded(True)
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
146 else:
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
147 # sub item
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
148 index = parent.indexOfChild(itm)
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
149 newIndex = index - 1 if moveUp else index + 1
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
150 parent.takeChild(index)
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
151 parent.insertChild(newIndex, itm)
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
152 for sitm in self.menuTree.selectedItems():
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
153 sitm.setSelected(False)
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
154 itm.setSelected(True)
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
155
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
156 @pyqtSlot()
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
157 def on_editButton_clicked(self):
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
158 """
1
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 Slot documentation goes here.
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 """
3
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
161 itm = self.menuTree.selectedItems()[0]
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
162 parent = itm.parent()
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
163 if parent is None:
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
164 menuTitle, ok = QInputDialog.getText(
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
165 self,
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
166 self.tr("Menu Entry"),
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
167 self.tr("Enter menu entry text:"),
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
168 QLineEdit.Normal,
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
169 itm.text(0))
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
170 if ok and menuTitle:
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
171 itm.setText(0, menuTitle)
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
172 else:
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
173 from .SelectionEncloserEditDialog import \
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
174 SelectionEncloserEditDialog
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
175 dlg = SelectionEncloserEditDialog(
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
176 itm.text(0), itm.data(0, Qt.UserRole), self)
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
177 if dlg.exec_() == QDialog.Accepted:
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
178 title, encString = dlg.getData()
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
179 itm.setText(0, title)
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
180 itm.setData(0, Qt.UserRole, encString)
1
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 @pyqtSlot()
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 def on_menuTree_itemSelectionChanged(self):
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 """
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 Private slot handling the selection of an item.
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 """
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 if len(self.menuTree.selectedItems()) == 0:
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 self.addButton.setEnabled(False)
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 self.deleteButton.setEnabled(False)
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 self.upButton.setEnabled(False)
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 self.downButton.setEnabled(False)
3
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
192 self.editButton.setEnabled(False)
1
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 else:
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 addEnable = True
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 upEnable = True
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 downEnable = True
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 itm = self.menuTree.selectedItems()[0]
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 parent = itm.parent()
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 if parent is None:
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 # top level item
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 if self.menuTree.indexOfTopLevelItem(itm) == 0:
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 upEnable = False
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 if self.menuTree.indexOfTopLevelItem(itm) == \
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 self.menuTree.topLevelItemCount() - 1:
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 downEnable = False
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 else:
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 # sub item
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 if parent.indexOfChild(itm) == 0:
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 upEnable = False
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 if parent.indexOfChild(itm) == \
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 parent.childCount() - 1:
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 downEnable = False
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 addEnable = False
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 self.addButton.setEnabled(addEnable)
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 self.deleteButton.setEnabled(True)
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 self.upButton.setEnabled(upEnable)
a9f6842a18f6 Implemented most of the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 self.downButton.setEnabled(downEnable)
3
b26df0282953 Finished implementing the functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
218 self.editButton.setEnabled(True)

eric ide

mercurial