Added entry for RGBA color. release_2.1.0

Thu, 12 Feb 2015 19:35:07 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 12 Feb 2015 19:35:07 +0100
changeset 20
ffe2ec016dfb
parent 19
ff19ebcd800d
child 21
daa796cc59dd

Added entry for RGBA color.

ChangeLog file | annotate | diff | comparison | revisions
ColorString/Documentation/source/Plugin_Tools_ColorString.PluginColorString.html file | annotate | diff | comparison | revisions
ColorString/i18n/colorstring_de.qm file | annotate | diff | comparison | revisions
ColorString/i18n/colorstring_de.ts file | annotate | diff | comparison | revisions
ColorString/i18n/colorstring_en.ts file | annotate | diff | comparison | revisions
ColorString/i18n/colorstring_es.ts file | annotate | diff | comparison | revisions
ColorString/i18n/colorstring_ru.ts file | annotate | diff | comparison | revisions
PluginColorString.py file | annotate | diff | comparison | revisions
PluginColorString.zip file | annotate | diff | comparison | revisions
--- a/ChangeLog	Mon Jan 05 20:15:30 2015 +0100
+++ b/ChangeLog	Thu Feb 12 19:35:07 2015 +0100
@@ -1,5 +1,8 @@
 ChangeLog
 ---------
+Version 2.1.0:
+- added entry for RGBA color
+
 Version 2.0.1:
 - bug fixes
 
--- a/ColorString/Documentation/source/Plugin_Tools_ColorString.PluginColorString.html	Mon Jan 05 20:15:30 2015 +0100
+++ b/ColorString/Documentation/source/Plugin_Tools_ColorString.PluginColorString.html	Thu Feb 12 19:35:07 2015 +0100
@@ -78,6 +78,9 @@
 <td><a href="#ColorStringPlugin.__isValidColor">__isValidColor</a></td>
 <td>Private method to check for a valid color name.</td>
 </tr><tr>
+<td><a href="#ColorStringPlugin.__isValidRgbaColor">__isValidRgbaColor</a></td>
+<td>Private method to check for a valid RGBA color.</td>
+</tr><tr>
 <td><a href="#ColorStringPlugin.__loadTranslator">__loadTranslator</a></td>
 <td>Private method to load the translation file.</td>
 </tr><tr>
@@ -90,6 +93,9 @@
 <td><a href="#ColorStringPlugin.__selectHexColor">__selectHexColor</a></td>
 <td>Private slot implementing the hex color string selection.</td>
 </tr><tr>
+<td><a href="#ColorStringPlugin.__selectRgbaColor">__selectRgbaColor</a></td>
+<td>Private slot implementing the RGBA color string selection.</td>
+</tr><tr>
 <td><a href="#ColorStringPlugin.activate">activate</a></td>
 <td>Public method to activate this plugin.</td>
 </tr><tr>
@@ -183,6 +189,22 @@
 <dd>
 flag indicating a valid color name (boolean)
 </dd>
+</dl><a NAME="ColorStringPlugin.__isValidRgbaColor" ID="ColorStringPlugin.__isValidRgbaColor"></a>
+<h4>ColorStringPlugin.__isValidRgbaColor</h4>
+<b>__isValidRgbaColor</b>(<i>color</i>)
+<p>
+        Private method to check for a valid RGBA color.
+</p><dl>
+<dt><i>name</i></dt>
+<dd>
+color string to check (string)
+</dd>
+</dl><dl>
+<dt>Returns:</dt>
+<dd>
+flag indicating a valid RGBA color (boolean) and a list with
+            the RGBA components of the color (three or four integers)
+</dd>
 </dl><a NAME="ColorStringPlugin.__loadTranslator" ID="ColorStringPlugin.__loadTranslator"></a>
 <h4>ColorStringPlugin.__loadTranslator</h4>
 <b>__loadTranslator</b>(<i></i>)
@@ -211,6 +233,11 @@
 <b>__selectHexColor</b>(<i></i>)
 <p>
         Private slot implementing the hex color string selection.
+</p><a NAME="ColorStringPlugin.__selectRgbaColor" ID="ColorStringPlugin.__selectRgbaColor"></a>
+<h4>ColorStringPlugin.__selectRgbaColor</h4>
+<b>__selectRgbaColor</b>(<i></i>)
+<p>
+        Private slot implementing the RGBA color string selection.
 </p><a NAME="ColorStringPlugin.activate" ID="ColorStringPlugin.activate"></a>
 <h4>ColorStringPlugin.activate</h4>
 <b>activate</b>(<i></i>)
Binary file ColorString/i18n/colorstring_de.qm has changed
--- a/ColorString/i18n/colorstring_de.ts	Mon Jan 05 20:15:30 2015 +0100
+++ b/ColorString/i18n/colorstring_de.ts	Thu Feb 12 19:35:07 2015 +0100
@@ -21,19 +21,34 @@
 <context>
     <name>ColorStringPlugin</name>
     <message>
-        <location filename="../../PluginColorString.py" line="269"/>
+        <location filename="../../PluginColorString.py" line="340"/>
         <source>Color String</source>
         <translation>Farbzeichenkette</translation>
     </message>
     <message>
-        <location filename="../../PluginColorString.py" line="220"/>
+        <location filename="../../PluginColorString.py" line="328"/>
         <source>&lt;p&gt;The selected string &lt;b&gt;{0}&lt;/b&gt; is not a valid color string. Aborting!&lt;/p&gt;</source>
         <translation>&lt;p&gt;Die ausgewählte Zeichenkette &lt;b&gt;{0}&lt;/b&gt; ist keine gültige Farbe. Abbruch!&lt;/p&gt;</translation>
     </message>
     <message>
-        <location filename="../../PluginColorString.py" line="269"/>
+        <location filename="../../PluginColorString.py" line="291"/>
         <source>&lt;p&gt;The selected string &lt;b&gt;{0}&lt;/b&gt; is not a valid color name. Aborting!&lt;/p&gt;</source>
         <translation>&lt;p&gt;Die ausgewählte Zeichenkette &lt;b&gt;{0}&lt;/b&gt; ist kein gültiger Farbname. Abbruch!&lt;/p&gt;</translation>
     </message>
+    <message>
+        <location filename="../../PluginColorString.py" line="129"/>
+        <source>Hex Color</source>
+        <translation>Hex Farbe</translation>
+    </message>
+    <message>
+        <location filename="../../PluginColorString.py" line="130"/>
+        <source>Color Name</source>
+        <translation>Farbname</translation>
+    </message>
+    <message>
+        <location filename="../../PluginColorString.py" line="131"/>
+        <source>RGBA Color</source>
+        <translation>RGBA Farbe</translation>
+    </message>
 </context>
 </TS>
--- a/ColorString/i18n/colorstring_en.ts	Mon Jan 05 20:15:30 2015 +0100
+++ b/ColorString/i18n/colorstring_en.ts	Thu Feb 12 19:35:07 2015 +0100
@@ -21,19 +21,34 @@
 <context>
     <name>ColorStringPlugin</name>
     <message>
-        <location filename="../../PluginColorString.py" line="269"/>
+        <location filename="../../PluginColorString.py" line="340"/>
         <source>Color String</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="../../PluginColorString.py" line="220"/>
+        <location filename="../../PluginColorString.py" line="328"/>
         <source>&lt;p&gt;The selected string &lt;b&gt;{0}&lt;/b&gt; is not a valid color string. Aborting!&lt;/p&gt;</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="../../PluginColorString.py" line="269"/>
+        <location filename="../../PluginColorString.py" line="291"/>
         <source>&lt;p&gt;The selected string &lt;b&gt;{0}&lt;/b&gt; is not a valid color name. Aborting!&lt;/p&gt;</source>
         <translation type="unfinished"></translation>
     </message>
+    <message>
+        <location filename="../../PluginColorString.py" line="129"/>
+        <source>Hex Color</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../../PluginColorString.py" line="130"/>
+        <source>Color Name</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../../PluginColorString.py" line="131"/>
+        <source>RGBA Color</source>
+        <translation type="unfinished"></translation>
+    </message>
 </context>
 </TS>
--- a/ColorString/i18n/colorstring_es.ts	Mon Jan 05 20:15:30 2015 +0100
+++ b/ColorString/i18n/colorstring_es.ts	Thu Feb 12 19:35:07 2015 +0100
@@ -21,19 +21,34 @@
 <context>
     <name>ColorStringPlugin</name>
     <message>
-        <location filename="../../PluginColorString.py" line="269"/>
+        <location filename="../../PluginColorString.py" line="340"/>
         <source>Color String</source>
         <translation>Cadena de Color</translation>
     </message>
     <message>
-        <location filename="../../PluginColorString.py" line="220"/>
+        <location filename="../../PluginColorString.py" line="328"/>
         <source>&lt;p&gt;The selected string &lt;b&gt;{0}&lt;/b&gt; is not a valid color string. Aborting!&lt;/p&gt;</source>
         <translation>&lt;p&gt;La cadena seleccionada&lt;b&gt;{0}&lt;/b&gt; no es una cadena de color válida. ¡Abortando!&lt;/p&gt;</translation>
     </message>
     <message>
-        <location filename="../../PluginColorString.py" line="269"/>
+        <location filename="../../PluginColorString.py" line="291"/>
         <source>&lt;p&gt;The selected string &lt;b&gt;{0}&lt;/b&gt; is not a valid color name. Aborting!&lt;/p&gt;</source>
         <translation>&lt;p&gt;La cadena seleccionada&lt;b&gt;{0}&lt;/b&gt; no es un nombre de color válido. ¡Abortando!&lt;/p&gt;</translation>
     </message>
+    <message>
+        <location filename="../../PluginColorString.py" line="129"/>
+        <source>Hex Color</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../../PluginColorString.py" line="130"/>
+        <source>Color Name</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../../PluginColorString.py" line="131"/>
+        <source>RGBA Color</source>
+        <translation type="unfinished"></translation>
+    </message>
 </context>
 </TS>
--- a/ColorString/i18n/colorstring_ru.ts	Mon Jan 05 20:15:30 2015 +0100
+++ b/ColorString/i18n/colorstring_ru.ts	Thu Feb 12 19:35:07 2015 +0100
@@ -21,19 +21,34 @@
 <context>
     <name>ColorStringPlugin</name>
     <message>
-        <location filename="../../PluginColorString.py" line="269"/>
+        <location filename="../../PluginColorString.py" line="340"/>
         <source>Color String</source>
         <translation>Цвет</translation>
     </message>
     <message>
-        <location filename="../../PluginColorString.py" line="220"/>
+        <location filename="../../PluginColorString.py" line="328"/>
         <source>&lt;p&gt;The selected string &lt;b&gt;{0}&lt;/b&gt; is not a valid color string. Aborting!&lt;/p&gt;</source>
         <translation>&lt;p&gt;Выбранная строка &lt;b&gt;{0}&lt;/b&gt; не является правильной для определения цвета. Авост!&lt;/p&gt;</translation>
     </message>
     <message>
-        <location filename="../../PluginColorString.py" line="269"/>
+        <location filename="../../PluginColorString.py" line="291"/>
         <source>&lt;p&gt;The selected string &lt;b&gt;{0}&lt;/b&gt; is not a valid color name. Aborting!&lt;/p&gt;</source>
         <translation>&lt;p&gt;Выбранная строка &lt;b&gt;{0}&lt;/b&gt; не является правильным разванием цвета. Авост!&lt;/p&gt;</translation>
     </message>
+    <message>
+        <location filename="../../PluginColorString.py" line="129"/>
+        <source>Hex Color</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../../PluginColorString.py" line="130"/>
+        <source>Color Name</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../../PluginColorString.py" line="131"/>
+        <source>RGBA Color</source>
+        <translation type="unfinished"></translation>
+    </message>
 </context>
 </TS>
--- a/PluginColorString.py	Mon Jan 05 20:15:30 2015 +0100
+++ b/PluginColorString.py	Thu Feb 12 19:35:07 2015 +0100
@@ -23,7 +23,7 @@
 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
 autoactivate = True
 deactivateable = True
-version = "2.0.1"
+version = "2.1.0"
 className = "ColorStringPlugin"
 packageName = "ColorString"
 shortDescription = "Insert color as string"
@@ -124,9 +124,10 @@
         """
         Private method to initialize the menu.
         """
-        self.__menu = QMenu("Color String")
-        self.__menu.addAction("Hex Color", self.__selectHexColor)
-        self.__menu.addAction("Color Name", self.__selectColorName)
+        self.__menu = QMenu(self.tr("Color String"))
+        self.__menu.addAction(self.tr("Hex Color"), self.__selectHexColor)
+        self.__menu.addAction(self.tr("Color Name"), self.__selectColorName)
+        self.__menu.addAction(self.tr("RGBA Color"), self.__selectRgbaColor)
         self.__menu.setEnabled(False)
     
     def __populateMenu(self, name, menu):
@@ -308,3 +309,72 @@
                 editor.insert(colorStr)
                 editor.setCursorPosition(line, index + len(colorStr))
             editor.endUndoAction()
+    
+    def __selectRgbaColor(self):
+        """
+        Private slot implementing the RGBA color string selection.
+        """
+        editor = e5App().getObject("ViewManager").activeWindow()
+        if editor is None:
+            return
+        
+        if editor.hasSelectedText():
+            currColor = editor.selectedText()
+            valid, rgba = self.__isValidRgbaColor(currColor)
+            if not valid:
+                E5MessageBox.critical(
+                    self.__ui,
+                    self.tr("Color String"),
+                    self.tr(
+                        """<p>The selected string <b>{0}</b> is not a"""
+                        """ valid color string. Aborting!</p>""")
+                    .format(currColor))
+                return
+            initColor = QColor(*rgba)
+        else:
+            initColor = QColor()
+        
+        color = QColorDialog.getColor(
+            initColor, self.__ui, self.tr("Color String"),
+            QColorDialog.ShowAlphaChannel)
+        if color.isValid():
+            rgba = color.getRgb()
+            if rgba[-1] == 255:
+                colorStr = "{0}, {1}, {2}".format(*rgba[:-1])
+            else:
+                colorStr = "{0}, {1}, {2}, {3}".format(*rgba)
+            editor.beginUndoAction()
+            if editor.hasSelectedText():
+                editor.replaceSelectedText(colorStr)
+            else:
+                line, index = editor.getCursorPosition()
+                editor.insert(colorStr)
+                editor.setCursorPosition(line, index + len(colorStr))
+            editor.endUndoAction()
+    
+    def __isValidRgbaColor(self, color):
+        """
+        Private method to check for a valid RGBA color.
+        
+        @param name color string to check (string)
+        @return flag indicating a valid RGBA color (boolean) and a list with
+            the RGBA components of the color (three or four integers)
+        """
+        rgba = []
+        
+        parts = color.split(",")
+        if len(parts) not in [3, 4]:
+            return False, []
+        
+        for part in parts:
+            try:
+                c = int(part)
+            except ValueError:
+                return False, []
+            
+            if c < 0 or c > 255:
+                return False, []
+            
+            rgba.append(c)
+        
+        return True, rgba
Binary file PluginColorString.zip has changed

eric ide

mercurial