PluginColorString.py

changeset 11
3b7ec819a55d
parent 8
ba338747008c
child 16
126fc3a16ebf
equal deleted inserted replaced
9:100cd707c50a 11:3b7ec819a55d
9 9
10 from __future__ import unicode_literals 10 from __future__ import unicode_literals
11 11
12 import os 12 import os
13 13
14 from PyQt4.QtCore import QObject, QTranslator 14 from PyQt5.QtCore import QObject, QTranslator
15 from PyQt4.QtGui import QColor, QColorDialog, QMenu, QDialog 15 from PyQt5.QtGui import QColor
16 from PyQt5.QtWidgets import QColorDialog, QMenu, QDialog
16 17
17 from E5Gui.E5Application import e5App 18 from E5Gui.E5Application import e5App
18 from E5Gui import E5MessageBox 19 from E5Gui import E5MessageBox
19 20
20 # Start-Of-Header 21 # Start-Of-Header
21 name = "Color String Plug-in" 22 name = "Color String 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 = "1.0.0" 26 version = "2.0.0"
26 className = "ColorStringPlugin" 27 className = "ColorStringPlugin"
27 packageName = "ColorString" 28 packageName = "ColorString"
28 shortDescription = "Insert color as string" 29 shortDescription = "Insert color as string"
29 longDescription = \ 30 longDescription = \
30 """This plug-in implements a tool to select a color via a""" \ 31 """This plug-in implements a tool to select a color via a""" \
177 @param text text to check (string) 178 @param text text to check (string)
178 @return flag indicating a hex string (boolean) 179 @return flag indicating a hex string (boolean)
179 """ 180 """
180 isHex = True 181 isHex = True
181 for c in text: 182 for c in text:
182 isHex = isHex and c in "0123456789abcdefABCDEF" 183 isHex = isHex and c in "0123456789abcdefABCDEF"
183 return isHex 184 return isHex
184 185
185 def __isValidColor(self, name): 186 def __isValidColor(self, name):
186 """ 187 """
187 Private method to check for a valid color name. 188 Private method to check for a valid color name.
215 if editor.hasSelectedText(): 216 if editor.hasSelectedText():
216 currColor = editor.selectedText() 217 currColor = editor.selectedText()
217 if not self.__isValidColor(currColor): 218 if not self.__isValidColor(currColor):
218 E5MessageBox.critical( 219 E5MessageBox.critical(
219 self.__ui, 220 self.__ui,
220 self.trUtf8("Color String"), 221 self.tr("Color String"),
221 self.trUtf8( 222 self.tr(
222 """<p>The selected string <b>{0}</b> is not a""" \ 223 """<p>The selected string <b>{0}</b> is not a"""
223 """ valid color string. Aborting!</p>""") 224 """ valid color string. Aborting!</p>""")
224 .format(currColor)) 225 .format(currColor))
225 return 226 return
226 227
227 if currColor.startswith("#"): 228 if currColor.startswith("#"):
263 if editor.hasSelectedText(): 264 if editor.hasSelectedText():
264 currColor = editor.selectedText() 265 currColor = editor.selectedText()
265 if currColor not in QColor.colorNames(): 266 if currColor not in QColor.colorNames():
266 E5MessageBox.critical( 267 E5MessageBox.critical(
267 self.__ui, 268 self.__ui,
268 self.trUtf8("Color String"), 269 self.tr("Color String"),
269 self.trUtf8( 270 self.tr(
270 """<p>The selected string <b>{0}</b> is not a""" \ 271 """<p>The selected string <b>{0}</b> is not a"""
271 """ valid color name. Aborting!</p>""") 272 """ valid color name. Aborting!</p>""")
272 .format(currColor)) 273 .format(currColor))
273 return 274 return
274 else: 275 else:
275 currColor = "" 276 currColor = ""

eric ide

mercurial