Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).

Tue, 11 Feb 2014 19:51:01 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 11 Feb 2014 19:51:01 +0100
changeset 3270
d8532d902e76
parent 3269
866c3a2f5380
child 3271
86df7bf80760

Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).

APIs/Python3/eric5.api file | annotate | diff | comparison | revisions
Documentation/Help/source.qch file | annotate | diff | comparison | revisions
Documentation/Help/source.qhp file | annotate | diff | comparison | revisions
Documentation/Source/eric5.UI.PixmapCache.html file | annotate | diff | comparison | revisions
Plugins/ViewManagerPlugins/Listspace/Listspace.py file | annotate | diff | comparison | revisions
Plugins/ViewManagerPlugins/Tabview/Tabview.py file | annotate | diff | comparison | revisions
UI/PixmapCache.py file | annotate | diff | comparison | revisions
icons/default/empty.png file | annotate | diff | comparison | revisions
icons/default/syntaxError22.png file | annotate | diff | comparison | revisions
icons/default/warning22.png file | annotate | diff | comparison | revisions
--- a/APIs/Python3/eric5.api	Sun Feb 09 16:01:42 2014 +0100
+++ b/APIs/Python3/eric5.api	Tue Feb 11 19:51:01 2014 +0100
@@ -7959,6 +7959,7 @@
 eric5.UI.PixmapCache.PixmapCache.getPixmap?4(key)
 eric5.UI.PixmapCache.PixmapCache?1()
 eric5.UI.PixmapCache.addSearchPath?4(path, cache=pixCache)
+eric5.UI.PixmapCache.getCombinedIcon?4(keys, cache=pixCache)
 eric5.UI.PixmapCache.getIcon?4(key, cache=pixCache)
 eric5.UI.PixmapCache.getPixmap?4(key, cache=pixCache)
 eric5.UI.PixmapCache.getSymlinkIcon?4(key, cache=pixCache)
Binary file Documentation/Help/source.qch has changed
--- a/Documentation/Help/source.qhp	Sun Feb 09 16:01:42 2014 +0100
+++ b/Documentation/Help/source.qhp	Tue Feb 11 19:51:01 2014 +0100
@@ -13056,6 +13056,7 @@
       <keyword name="generateQtToolName" id="generateQtToolName" ref="eric5.Utilities.__init__.html#generateQtToolName" />
       <keyword name="generateVersionInfo" id="generateVersionInfo" ref="eric5.Utilities.__init__.html#generateVersionInfo" />
       <keyword name="getChannelModesDict" id="getChannelModesDict" ref="eric5.Network.IRC.IrcUtilities.html#getChannelModesDict" />
+      <keyword name="getCombinedIcon" id="getCombinedIcon" ref="eric5.UI.PixmapCache.html#getCombinedIcon" />
       <keyword name="getCompleter" id="getCompleter" ref="eric5.QScintilla.TypingCompleters.__init__.html#getCompleter" />
       <keyword name="getConfig" id="getConfig" ref="eric5.eric5config.html#getConfig" />
       <keyword name="getConfigData" id="getConfigData" ref="eric5.Plugins.PluginVcsMercurial.html#getConfigData" />
--- a/Documentation/Source/eric5.UI.PixmapCache.html	Sun Feb 09 16:01:42 2014 +0100
+++ b/Documentation/Source/eric5.UI.PixmapCache.html	Tue Feb 11 19:51:01 2014 +0100
@@ -40,6 +40,9 @@
 <td><a href="#addSearchPath">addSearchPath</a></td>
 <td>Module function to add a path to the search path.</td>
 </tr><tr>
+<td><a href="#getCombinedIcon">getCombinedIcon</a></td>
+<td>Module function to retrieve a symbolic link icon.</td>
+</tr><tr>
 <td><a href="#getIcon">getIcon</a></td>
 <td>Module function to retrieve an icon.</td>
 </tr><tr>
@@ -132,6 +135,27 @@
 </dl>
 <div align="right"><a href="#top">Up</a></div>
 <hr /><hr />
+<a NAME="getCombinedIcon" ID="getCombinedIcon"></a>
+<h2>getCombinedIcon</h2>
+<b>getCombinedIcon</b>(<i>keys, cache=pixCache</i>)
+<p>
+    Module function to retrieve a symbolic link icon.
+</p><dl>
+<dt><i>keys</i></dt>
+<dd>
+list of names of icons (string)
+</dd><dt><i>cache</i></dt>
+<dd>
+reference to the pixmap cache object (PixmapCache)
+</dd>
+</dl><dl>
+<dt>Returns:</dt>
+<dd>
+the requested icon (QIcon)
+</dd>
+</dl>
+<div align="right"><a href="#top">Up</a></div>
+<hr /><hr />
 <a NAME="getIcon" ID="getIcon"></a>
 <h2>getIcon</h2>
 <b>getIcon</b>(<i>key, cache=pixCache</i>)
--- a/Plugins/ViewManagerPlugins/Listspace/Listspace.py	Sun Feb 09 16:01:42 2014 +0100
+++ b/Plugins/ViewManagerPlugins/Listspace/Listspace.py	Tue Feb 11 19:51:01 2014 +0100
@@ -520,18 +520,17 @@
         """
         currentRow = self.viewlist.currentRow()
         index = self.editors.index(editor)
+        keys = []
         if m:
-            self.viewlist.item(index).setIcon(
-                UI.PixmapCache.getIcon("fileModified.png"))
-        elif editor.hasSyntaxErrors():
-            self.viewlist.item(index).setIcon(
-                UI.PixmapCache.getIcon("syntaxError.png"))
+            keys.append("fileModified.png")
+        if editor.hasSyntaxErrors():
+            keys.append("syntaxError22.png")
         elif editor.hasWarnings():
-            self.viewlist.item(index).setIcon(
-                UI.PixmapCache.getIcon("warning.png"))
-        else:
-            self.viewlist.item(index).setIcon(
-                UI.PixmapCache.getIcon("empty.png"))
+            keys.append("warning22.png")
+        if not keys:
+            keys.append("empty.png")
+        self.viewlist.item(index).setIcon(
+            UI.PixmapCache.getCombinedIcon(keys))
         self.viewlist.setCurrentRow(currentRow)
         self._checkActions(editor)
         
@@ -543,18 +542,17 @@
         """
         currentRow = self.viewlist.currentRow()
         index = self.editors.index(editor)
+        keys = []
+        if editor.isModified():
+            keys.append("fileModified.png")
         if editor.hasSyntaxErrors():
-            self.viewlist.item(index).setIcon(
-                UI.PixmapCache.getIcon("syntaxError.png"))
+            keys.append("syntaxError22.png")
         elif editor.hasWarnings():
-            self.viewlist.item(index).setIcon(
-                UI.PixmapCache.getIcon("warning.png"))
-        elif editor.isModified():
-            self.viewlist.item(index).setIcon(
-                UI.PixmapCache.getIcon("fileModified.png"))
-        else:
-            self.viewlist.item(index).setIcon(
-                UI.PixmapCache.getIcon("empty.png"))
+            keys.append("warning22.png")
+        if not keys:
+            keys.append("empty.png")
+        self.viewlist.item(index).setIcon(
+            UI.PixmapCache.getCombinedIcon(keys))
         self.viewlist.setCurrentRow(currentRow)
         
         ViewManager._syntaxErrorToggled(self, editor)
--- a/Plugins/ViewManagerPlugins/Tabview/Tabview.py	Sun Feb 09 16:01:42 2014 +0100
+++ b/Plugins/ViewManagerPlugins/Tabview/Tabview.py	Tue Feb 11 19:51:01 2014 +0100
@@ -10,7 +10,7 @@
 import os
 
 from PyQt4.QtCore import QPoint, QFileInfo, pyqtSignal, QEvent, QByteArray, \
-    QMimeData, Qt
+    QMimeData, Qt, QSize
 from PyQt4.QtGui import QWidget, QColor, QHBoxLayout, QDrag, QPixmap, \
     QSplitter, QTabBar, QApplication, QToolButton, QMenu, QLabel
 
@@ -159,6 +159,9 @@
         
         self.__tabBar = TabBar(self)
         self.setTabBar(self.__tabBar)
+        iconSize = self.__tabBar.iconSize()
+        self.__tabBar.setIconSize(
+            QSize(2 * iconSize.width(), iconSize.height()))
         
         self.setUsesScrollButtons(True)
         self.setElideMode(Qt.ElideNone)
@@ -997,14 +1000,16 @@
             if tw.hasEditor(editor):
                 break
         index = tw.indexOf(editor)
+        keys = []
         if m:
-            tw.setTabIcon(index, UI.PixmapCache.getIcon("fileModified.png"))
-        elif editor.hasSyntaxErrors():
-            tw.setTabIcon(index, UI.PixmapCache.getIcon("syntaxError.png"))
+            keys.append("fileModified.png")
+        if editor.hasSyntaxErrors():
+            keys.append("syntaxError22.png")
         elif editor.hasWarnings():
-            tw.setTabIcon(index, UI.PixmapCache.getIcon("warning.png"))
-        else:
-            tw.setTabIcon(index, UI.PixmapCache.getIcon("empty.png"))
+            keys.append("warning22.png")
+        if not keys:
+            keys.append("empty.png")
+        tw.setTabIcon(index, UI.PixmapCache.getCombinedIcon(keys))
         self._checkActions(editor)
         
     def _syntaxErrorToggled(self, editor):
@@ -1017,14 +1022,16 @@
             if tw.hasEditor(editor):
                 break
         index = tw.indexOf(editor)
+        keys = []
+        if editor.isModified():
+            keys.append("fileModified.png")
         if editor.hasSyntaxErrors():
-            tw.setTabIcon(index, UI.PixmapCache.getIcon("syntaxError.png"))
+            keys.append("syntaxError22.png")
         elif editor.hasWarnings():
-            tw.setTabIcon(index, UI.PixmapCache.getIcon("warning.png"))
-        elif editor.isModified():
-            tw.setTabIcon(index, UI.PixmapCache.getIcon("fileModified.png"))
-        else:
-            tw.setTabIcon(index, UI.PixmapCache.getIcon("empty.png"))
+            keys.append("warning22.png")
+        if not keys:
+            keys.append("empty.png")
+        tw.setTabIcon(index, UI.PixmapCache.getCombinedIcon(keys))
         
         ViewManager._syntaxErrorToggled(self, editor)
         
--- a/UI/PixmapCache.py	Sun Feb 09 16:01:42 2014 +0100
+++ b/UI/PixmapCache.py	Tue Feb 11 19:51:01 2014 +0100
@@ -9,6 +9,7 @@
 
 import os
 
+from PyQt4.QtCore import Qt, QSize
 from PyQt4.QtGui import QPixmap, QIcon, QPainter
 
 
@@ -97,6 +98,37 @@
     return QIcon(pix1)
 
 
+def getCombinedIcon(keys, cache=pixCache):
+    """
+    Module function to retrieve a symbolic link icon.
+
+    @param keys list of names of icons (string)
+    @param cache reference to the pixmap cache object (PixmapCache)
+    @return the requested icon (QIcon)
+    """
+    height = width = 0
+    pixmaps = []
+    for key in keys:
+        pix = cache.getPixmap(key)
+        if not pix.isNull():
+            height = max(height, pix.height())
+            width = max(width, pix.width())
+            pixmaps.append(pix)
+    if pixmaps:
+        pix = QPixmap(len(pixmaps) * width, height)
+        pix.fill(Qt.transparent)
+        painter = QPainter(pix)
+        x = 0
+        for pixmap in pixmaps:
+            painter.drawPixmap(x, 0, pixmap.scaled(QSize(width, height)))
+            x += width
+        painter.end()
+        icon = QIcon(pix)
+    else:
+        icon = QIcon()
+    return icon
+
+
 def addSearchPath(path, cache=pixCache):
     """
     Module function to add a path to the search path.
Binary file icons/default/empty.png has changed
Binary file icons/default/syntaxError22.png has changed
Binary file icons/default/warning22.png has changed

eric ide

mercurial