Changed code to get rid of multiple inheritance in the viewmanager subclasses.

Mon, 28 Mar 2016 13:31:23 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 28 Mar 2016 13:31:23 +0200
changeset 4896
5ace700023de
parent 4892
64fc1deaeadb
child 4897
b45e93648187

Changed code to get rid of multiple inheritance in the viewmanager subclasses.

Plugins/ViewManagerPlugins/Listspace/Listspace.py file | annotate | diff | comparison | revisions
Plugins/ViewManagerPlugins/Tabview/Tabview.py file | annotate | diff | comparison | revisions
UI/UserInterface.py file | annotate | diff | comparison | revisions
ViewManager/ViewManager.py file | annotate | diff | comparison | revisions
--- a/Plugins/ViewManagerPlugins/Listspace/Listspace.py	Mon Mar 28 11:52:38 2016 +0200
+++ b/Plugins/ViewManagerPlugins/Listspace/Listspace.py	Mon Mar 28 13:31:23 2016 +0200
@@ -136,7 +136,7 @@
         return len(self.editors) and self.editors[0] or None
 
 
-class Listspace(QSplitter, ViewManager):
+class Listspace(ViewManager):
     """
     Class implementing the listspace viewmanager class.
     
@@ -199,22 +199,22 @@
         """
         self.stacks = []
         
-        QSplitter.__init__(self, parent)
+        self.__splitter = QSplitter(parent)
         ViewManager.__init__(self)
-        self.setChildrenCollapsible(False)
+        self.__splitter.setChildrenCollapsible(False)
         
         self.viewlist = QListWidget(self)
         policy = self.viewlist.sizePolicy()
         policy.setHorizontalPolicy(QSizePolicy.Ignored)
         self.viewlist.setSizePolicy(policy)
-        self.addWidget(self.viewlist)
+        self.__splitter.addWidget(self.viewlist)
         self.viewlist.setContextMenuPolicy(Qt.CustomContextMenu)
         self.viewlist.currentRowChanged.connect(self.__showSelectedView)
         self.viewlist.customContextMenuRequested.connect(self.__showMenu)
         
         self.stackArea = QSplitter(self)
         self.stackArea.setChildrenCollapsible(False)
-        self.addWidget(self.stackArea)
+        self.__splitter.addWidget(self.stackArea)
         self.stackArea.setOrientation(Qt.Vertical)
         stack = StackedWidget(self.stackArea)
         self.stackArea.addWidget(stack)
@@ -222,7 +222,8 @@
         self.currentStack = stack
         stack.currentChanged.connect(self.__currentChanged)
         stack.installEventFilter(self)
-        self.setSizes([int(self.width() * 0.2), int(self.width() * 0.8)])
+        self.__splitter.setSizes(
+            [int(self.width() * 0.2), int(self.width() * 0.8)])
         # 20% for viewlist, 80% for the editors
         self.__inRemoveView = False
         
@@ -296,6 +297,16 @@
                         self.viewlist.count() > 1)
                     
                     self.__menu.popup(self.viewlist.mapToGlobal(point))
+    
+    def mainWidget(self):
+        """
+        Public method to return a reference to the main Widget of a
+        specific view manager subclass.
+        
+        @return reference to the main widget
+        @rtype QWidget
+        """
+        return self.__splitter
         
     def canCascade(self):
         """
@@ -654,8 +665,10 @@
             if aw:
                 aw.setFocus()
         
-        index = self.editors.index(self.currentStack.currentWidget())
-        self.viewlist.setCurrentRow(index)
+        cw = self.currentStack.currentWidget()
+        if cw:
+            index = self.editors.index(cw)
+            self.viewlist.setCurrentRow(index)
         
     def prevSplit(self):
         """
@@ -672,8 +685,11 @@
             aw = self.activeWindow()
             if aw:
                 aw.setFocus()
-        index = self.editors.index(self.currentStack.currentWidget())
-        self.viewlist.setCurrentRow(index)
+        
+        cw = self.currentStack.currentWidget()
+        if cw:
+            index = self.editors.index(cw)
+            self.viewlist.setCurrentRow(index)
         
     def __contextMenuClose(self):
         """
--- a/Plugins/ViewManagerPlugins/Tabview/Tabview.py	Mon Mar 28 11:52:38 2016 +0200
+++ b/Plugins/ViewManagerPlugins/Tabview/Tabview.py	Mon Mar 28 13:31:23 2016 +0200
@@ -699,7 +699,7 @@
         self.vm.newEditor()
 
 
-class Tabview(QSplitter, ViewManager):
+class Tabview(ViewManager):
     """
     Class implementing a tabbed viewmanager class embedded in a splitter.
     
@@ -762,24 +762,34 @@
         """
         self.tabWidgets = []
         
-        QSplitter.__init__(self, parent)
+        self.__splitter = QSplitter(parent)
         ViewManager.__init__(self)
-        self.setChildrenCollapsible(False)
+        self.__splitter.setChildrenCollapsible(False)
         
         tw = TabWidget(self)
-        self.addWidget(tw)
+        self.__splitter.addWidget(tw)
         self.tabWidgets.append(tw)
         self.currentTabWidget = tw
         self.currentTabWidget.showIndicator(True)
         tw.currentChanged.connect(self.__currentChanged)
         tw.installEventFilter(self)
         tw.tabBar().installEventFilter(self)
-        self.setOrientation(Qt.Vertical)
+        self.__splitter.setOrientation(Qt.Vertical)
         self.__inRemoveView = False
         
         self.maxFileNameChars = Preferences.getUI(
             "TabViewManagerFilenameLength")
         self.filenameOnly = Preferences.getUI("TabViewManagerFilenameOnly")
+    
+    def mainWidget(self):
+        """
+        Public method to return a reference to the main Widget of a
+        specific view manager subclass.
+        
+        @return reference to the main widget
+        @rtype QWidget
+        """
+        return self.__splitter
         
     def canCascade(self):
         """
@@ -1067,7 +1077,7 @@
         """
         tw = TabWidget(self)
         tw.show()
-        self.addWidget(tw)
+        self.__splitter.addWidget(tw)
         self.tabWidgets.append(tw)
         self.currentTabWidget.showIndicator(False)
         self.currentTabWidget = self.tabWidgets[-1]
@@ -1075,11 +1085,11 @@
         tw.currentChanged.connect(self.__currentChanged)
         tw.installEventFilter(self)
         tw.tabBar().installEventFilter(self)
-        if self.orientation() == Qt.Horizontal:
+        if self.__splitter.orientation() == Qt.Horizontal:
             size = self.width()
         else:
             size = self.height()
-        self.setSizes(
+        self.__splitter.setSizes(
             [int(size / len(self.tabWidgets))] * len(self.tabWidgets))
         self.splitRemoveAct.setEnabled(True)
         self.nextSplitAct.setEnabled(True)
@@ -1129,7 +1139,7 @@
         
         @return orientation of the split (Qt.Horizontal or Qt.Vertical)
         """
-        return self.orientation()
+        return self.__splitter.orientation()
         
     def setSplitOrientation(self, orientation):
         """
@@ -1138,7 +1148,7 @@
         @param orientation orientation of the split
                 (Qt.Horizontal or Qt.Vertical)
         """
-        self.setOrientation(orientation)
+        self.__splitter.setOrientation(orientation)
         
     def nextSplit(self):
         """
--- a/UI/UserInterface.py	Mon Mar 28 11:52:38 2016 +0200
+++ b/UI/UserInterface.py	Mon Mar 28 13:31:23 2016 +0200
@@ -611,10 +611,10 @@
         layout = QVBoxLayout()
         layout.setContentsMargins(1, 1, 1, 1)
         layout.setSpacing(1)
-        layout.addWidget(self.viewmanager)
+        layout.addWidget(self.viewmanager.mainWidget())
         layout.addWidget(self.viewmanager.searchWidget())
         layout.addWidget(self.viewmanager.replaceWidget())
-        self.viewmanager.setSizePolicy(
+        self.viewmanager.mainWidget().setSizePolicy(
             QSizePolicy.Preferred, QSizePolicy.Expanding)
         leftWidget.setLayout(layout)
         self.viewmanager.searchWidget().hide()
--- a/ViewManager/ViewManager.py	Mon Mar 28 11:52:38 2016 +0200
+++ b/ViewManager/ViewManager.py	Mon Mar 28 13:31:23 2016 +0200
@@ -12,10 +12,10 @@
 import os
 
 from PyQt5.QtCore import pyqtSignal, pyqtSlot, QSignalMapper, QTimer, \
-    QFileInfo, QRegExp, QObject, Qt, QCoreApplication
+    QFileInfo, QRegExp, Qt, QCoreApplication
 from PyQt5.QtGui import QColor, QKeySequence, QPalette, QPixmap
 from PyQt5.QtWidgets import QLineEdit, QToolBar, QWidgetAction, QDialog, \
-    QApplication, QMenu, QComboBox
+    QApplication, QMenu, QComboBox, QWidget
 from PyQt5.Qsci import QsciScintilla
 
 from E5Gui.E5Application import e5App
@@ -85,7 +85,7 @@
         super(QuickSearchLineEdit, self).focusInEvent(evt)   # pass it on
 
 
-class ViewManager(QObject):
+class ViewManager(QWidget):##QObject):
     """
     Base class inherited by all specific viewmanager classes.
     
@@ -445,6 +445,17 @@
         """
         raise RuntimeError('Not implemented')
     
+    def mainWidget(self):
+        """
+        Public method to return a reference to the main Widget of a
+        specific view manager subclass.
+        
+        @return reference to the main widget
+        @rtype QWidget
+        @exception RuntimeError Not implemented
+        """
+        raise RuntimeError('Not implemented')
+    
     #####################################################################
     ## methods above need to be implemented by a subclass
     #####################################################################

eric ide

mercurial