5 |
5 |
6 """ |
6 """ |
7 Module implementing the 'Color String' tool plug-in. |
7 Module implementing the 'Color String' tool plug-in. |
8 """ |
8 """ |
9 |
9 |
|
10 import contextlib |
10 import os |
11 import os |
11 |
12 |
12 from PyQt5.QtCore import QObject, QTranslator |
13 from PyQt5.QtCore import QObject, QTranslator |
13 from PyQt5.QtGui import QColor |
14 from PyQt5.QtGui import QColor |
14 from PyQt5.QtWidgets import QColorDialog, QMenu, QDialog |
15 from PyQt5.QtWidgets import QColorDialog, QMenu, QDialog |
19 # Start-Of-Header |
20 # Start-Of-Header |
20 name = "Color String Plug-in" |
21 name = "Color String Plug-in" |
21 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
22 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
22 autoactivate = True |
23 autoactivate = True |
23 deactivateable = True |
24 deactivateable = True |
24 version = "3.1.0" |
25 version = "3.2.0" |
25 className = "ColorStringPlugin" |
26 className = "ColorStringPlugin" |
26 packageName = "ColorString" |
27 packageName = "ColorString" |
27 shortDescription = "Insert color as string" |
28 shortDescription = "Insert color as string" |
28 longDescription = ( |
29 longDescription = ( |
29 """This plug-in implements a tool to select a color via a""" |
30 """This plug-in implements a tool to select a color via a""" |
184 """ |
185 """ |
185 Private slot called, when an editor was closed. |
186 Private slot called, when an editor was closed. |
186 |
187 |
187 @param editor reference to the editor (QScintilla.Editor) |
188 @param editor reference to the editor (QScintilla.Editor) |
188 """ |
189 """ |
189 try: |
190 with contextlib.suppress(KeyError): |
190 del self.__editors[editor] |
191 del self.__editors[editor] |
191 if not self.__editors: |
192 if not self.__editors: |
192 self.__menu.setEnabled(False) |
193 self.__menu.setEnabled(False) |
193 except KeyError: |
|
194 pass |
|
195 |
194 |
196 def __editorShowMenu(self, menuName, menu, editor): |
195 def __editorShowMenu(self, menuName, menu, editor): |
197 """ |
196 """ |
198 Private slot called, when the the editor context menu or a submenu is |
197 Private slot called, when the the editor context menu or a submenu is |
199 about to be shown. |
198 about to be shown. |
200 |
199 |
201 @param menuName name of the menu to be shown (string) |
200 @param menuName name of the menu to be shown (string) |
202 @param menu reference to the menu (QMenu) |
201 @param menu reference to the menu (QMenu) |
203 @param editor reference to the editor |
202 @param editor reference to the editor |
204 """ |
203 """ |
205 if menuName == "Tools": |
204 if ( |
206 if self.__menu.menuAction() not in menu.actions(): |
205 menuName == "Tools" and |
207 # Re-add our menu |
206 self.__menu.menuAction() not in menu.actions() |
208 self.__editors[editor] = [] |
207 ): |
209 if not menu.isEmpty(): |
208 # Re-add our menu |
210 act = menu.addSeparator() |
209 self.__editors[editor] = [] |
211 self.__editors[editor].append(act) |
210 if not menu.isEmpty(): |
212 act = menu.addMenu(self.__menu) |
211 act = menu.addSeparator() |
213 self.__editors[editor].append(act) |
212 self.__editors[editor].append(act) |
|
213 act = menu.addMenu(self.__menu) |
|
214 self.__editors[editor].append(act) |
214 |
215 |
215 def __isHexString(self, text): |
216 def __isHexString(self, text): |
216 """ |
217 """ |
217 Private method to check, if a given text is a hex string. |
218 Private method to check, if a given text is a hex string. |
218 |
219 |