PluginToolGenerateHash.py

changeset 32
287d824b90bd
parent 30
7fa4803a4c92
child 34
37088185a328
equal deleted inserted replaced
31:c4aea61e0230 32:287d824b90bd
21 # Start-Of-Header 21 # Start-Of-Header
22 name = "Generate Hash Tool Plug-in" 22 name = "Generate Hash Tool Plug-in"
23 author = "Detlev Offenbach <detlev@die-offenbachs.de>" 23 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
24 autoactivate = True 24 autoactivate = True
25 deactivateable = True 25 deactivateable = True
26 version = "2.0.2" 26 version = "2.1.0"
27 className = "ToolGenerateHashPlugin" 27 className = "ToolGenerateHashPlugin"
28 packageName = "ToolGenerateHash" 28 packageName = "ToolGenerateHash"
29 shortDescription = "Generate a hash for a selectable file or directory" 29 shortDescription = "Generate a hash for a selectable file or directory"
30 longDescription = \ 30 longDescription = \
31 """Plug-in to generate a hash for a selectable file or directory. The"""\ 31 """Plug-in to generate a hash for a selectable file or directory. The"""\
65 self.__loadTranslator() 65 self.__loadTranslator()
66 66
67 self.__initMenus() 67 self.__initMenus()
68 68
69 self.__editors = {} 69 self.__editors = {}
70 self.__mainActions = []
70 71
71 def activate(self): 72 def activate(self):
72 """ 73 """
73 Public method to activate this plugin. 74 Public method to activate this plugin.
74 75
76 """ 77 """
77 global error 78 global error
78 error = "" # clear previous error 79 error = "" # clear previous error
79 80
80 self.__ui.showMenu.connect(self.__populateMenu) 81 self.__ui.showMenu.connect(self.__populateMenu)
82
83 menu = self.__ui.getMenu("plugin_tools")
84 if menu is not None:
85 if not menu.isEmpty():
86 act = menu.addSeparator()
87 self.__mainActions.append(act)
88 act = menu.addMenu(self.__fileMenu)
89 self.__mainActions.append(act)
90 act = menu.addMenu(self.__dirMenu)
91 self.__mainActions.append(act)
81 92
82 e5App().getObject("ViewManager").editorOpenedEd.connect( 93 e5App().getObject("ViewManager").editorOpenedEd.connect(
83 self.__editorOpened) 94 self.__editorOpened)
84 e5App().getObject("ViewManager").editorClosedEd.connect( 95 e5App().getObject("ViewManager").editorClosedEd.connect(
85 self.__editorClosed) 96 self.__editorClosed)
93 """ 104 """
94 Public method to deactivate this plugin. 105 Public method to deactivate this plugin.
95 """ 106 """
96 self.__ui.showMenu.disconnect(self.__populateMenu) 107 self.__ui.showMenu.disconnect(self.__populateMenu)
97 108
109 menu = self.__ui.getMenu("plugin_tools")
110 if menu is not None:
111 for act in self.__mainActions:
112 menu.removeAction(act)
113 self.__mainActions = []
114
98 e5App().getObject("ViewManager").editorOpenedEd.disconnect( 115 e5App().getObject("ViewManager").editorOpenedEd.disconnect(
99 self.__editorOpened) 116 self.__editorOpened)
100 e5App().getObject("ViewManager").editorClosedEd.disconnect( 117 e5App().getObject("ViewManager").editorClosedEd.disconnect(
101 self.__editorClosed) 118 self.__editorClosed)
102 119
161 Private slot to populate the tools menu with our entries. 178 Private slot to populate the tools menu with our entries.
162 179
163 @param name name of the menu (string) 180 @param name name of the menu (string)
164 @param menu reference to the menu to be populated (QMenu) 181 @param menu reference to the menu to be populated (QMenu)
165 """ 182 """
166 if name != "Tools": 183 if name not in ["Tools", "PluginTools"]:
167 return 184 return
168 185
169 editor = e5App().getObject("ViewManager").activeWindow() 186 editor = e5App().getObject("ViewManager").activeWindow()
170 187
171 if not menu.isEmpty(): 188 if name == "Tools":
172 menu.addSeparator() 189 if not menu.isEmpty():
173 190 menu.addSeparator()
174 act = menu.addMenu(self.__fileMenu) 191
175 act.setEnabled(editor is not None) 192 act = menu.addMenu(self.__fileMenu)
176 act = menu.addMenu(self.__dirMenu) 193 act.setEnabled(editor is not None)
177 act.setEnabled(editor is not None) 194 act = menu.addMenu(self.__dirMenu)
195 act.setEnabled(editor is not None)
196 elif name == "PluginTools" and self.__mainActions:
197 self.__mainActions[-2].setEnabled(editor is not None)
198 self.__mainActions[-1].setEnabled(editor is not None)
178 199
179 def __editorOpened(self, editor): 200 def __editorOpened(self, editor):
180 """ 201 """
181 Private slot called, when a new editor was opened. 202 Private slot called, when a new editor was opened.
182 203

eric ide

mercurial