PluginSelectionEncloser.py

changeset 46
c12f1feea96a
parent 45
896b66ba45f0
child 48
767eb5905e08
equal deleted inserted replaced
45:896b66ba45f0 46:c12f1feea96a
5 5
6 """ 6 """
7 Module implementing the Selection Encloser plug-in. 7 Module implementing the Selection Encloser plug-in.
8 """ 8 """
9 9
10 import contextlib
10 import os 11 import os
11 import json 12 import json
12 13
13 from PyQt5.QtCore import QObject, QTranslator, QCoreApplication 14 from PyQt5.QtCore import QObject, QTranslator, QCoreApplication
14 from PyQt5.QtWidgets import QAction, QMenu 15 from PyQt5.QtWidgets import QAction, QMenu
20 # Start-Of-Header 21 # Start-Of-Header
21 name = "Selection Encloser Plug-in" 22 name = "Selection Encloser Plug-in"
22 author = "Detlev Offenbach <detlev@die-offenbachs.de>" 23 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
23 autoactivate = True 24 autoactivate = True
24 deactivateable = True 25 deactivateable = True
25 version = "3.1.0" 26 version = "3.2.0"
26 className = "SelectionEncloserPlugin" 27 className = "SelectionEncloserPlugin"
27 packageName = "SelectionEncloser" 28 packageName = "SelectionEncloser"
28 shortDescription = "Enclose the selection with a string." 29 shortDescription = "Enclose the selection with a string."
29 longDescription = ( 30 longDescription = (
30 """This plug-in implements a tool to enclose the selection of""" 31 """This plug-in implements a tool to enclose the selection of"""
61 @return dictionary containing the relevant data 62 @return dictionary containing the relevant data
62 """ 63 """
63 try: 64 try:
64 usesDarkPalette = e5App().usesDarkPalette() 65 usesDarkPalette = e5App().usesDarkPalette()
65 except AttributeError: 66 except AttributeError:
67 # for eric6 < 20.4
66 from PyQt5.QtGui import QPalette 68 from PyQt5.QtGui import QPalette
67 palette = e5App().palette() 69 palette = e5App().palette()
68 lightness = palette.color(QPalette.Window).lightness() 70 lightness = palette.color(QPalette.Window).lightness()
69 usesDarkPalette = lightness <= 128 71 usesDarkPalette = lightness <= 128
70 if usesDarkPalette: 72 iconSuffix = "dark" if usesDarkPalette else "light"
71 iconSuffix = "dark"
72 else:
73 iconSuffix = "light"
74 73
75 return { 74 return {
76 "selectionEncloserPage": [ 75 "selectionEncloserPage": [
77 QCoreApplication.translate("SelectionEncloserPlugin", 76 QCoreApplication.translate("SelectionEncloserPlugin",
78 "Selection Encloser"), 77 "Selection Encloser"),
99 """ 98 """
100 Constructor 99 Constructor
101 100
102 @param ui reference to the user interface object (UI.UserInterface) 101 @param ui reference to the user interface object (UI.UserInterface)
103 """ 102 """
104 QObject.__init__(self, ui) 103 super.__init__(ui)
105 self.__ui = ui 104 self.__ui = ui
106 105
107 # menu is a list of lists; each list consists of a string for the 106 # menu is a list of lists; each list consists of a string for the
108 # submenu title and a list of submenu entries. Each submenu entry 107 # submenu title and a list of submenu entries. Each submenu entry
109 # consists of another list giving the title and the enclosing string 108 # consists of another list giving the title and the enclosing string
293 """ 292 """
294 Private slot called, when an editor was closed. 293 Private slot called, when an editor was closed.
295 294
296 @param editor reference to the editor (QScintilla.Editor) 295 @param editor reference to the editor (QScintilla.Editor)
297 """ 296 """
298 try: 297 with contextlib.suppress(KeyError):
299 del self.__editors[editor] 298 del self.__editors[editor]
300 if not self.__editors: 299 if not self.__editors:
301 self.__menu.setEnabled(False) 300 self.__menu.setEnabled(False)
302 except KeyError:
303 pass
304 301
305 def __editorShowMenu(self, menuName, menu, editor): 302 def __editorShowMenu(self, menuName, menu, editor):
306 """ 303 """
307 Private slot called, when the the editor context menu or a submenu is 304 Private slot called, when the the editor context menu or a submenu is
308 about to be shown. 305 about to be shown.

eric ide

mercurial