UI/UserInterface.py

changeset 6422
1b8bff880c6b
parent 6421
ef33cbc7cc8c
child 6423
a9e6ae68170b
diff -r ef33cbc7cc8c -r 1b8bff880c6b UI/UserInterface.py
--- a/UI/UserInterface.py	Mon Jul 09 19:10:09 2018 +0200
+++ b/UI/UserInterface.py	Tue Jul 10 19:11:06 2018 +0200
@@ -131,7 +131,7 @@
         self.buffer += str(s)
         self.__nWrite(self.__bufferedWrite())
 
-# TODO: make "Cooperation" and "IRC" configurable
+# TODO: make "File-Browser", "Symbols" and "Numbers" configurable
 class UserInterface(E5MainWindow):
     """
     Class implementing the main user interface.
@@ -268,6 +268,8 @@
         splash.showMessage(self.tr("Generating Main User Interface..."))
         
         self.codeDocumentationViewer = None
+        self.cooperation = None
+        self.irc = None
         
         # Create the main window now so that we can connect QActions to it.
         logging.debug("Creating Layout...")
@@ -487,11 +489,10 @@
         self.preferencesChanged.connect(self.pluginManager.preferencesChanged)
         self.preferencesChanged.connect(debugServer.preferencesChanged)
         self.preferencesChanged.connect(self.debugViewer.preferencesChanged)
-        self.preferencesChanged.connect(self.cooperation.preferencesChanged)
         self.preferencesChanged.connect(
             self.backgroundService.preferencesOrProjectChanged)
         
-        if self.codeDocumentationViewer:
+        if self.codeDocumentationViewer is not None:
             self.preferencesChanged.connect(
                 self.codeDocumentationViewer.preferencesChanged)
         
@@ -504,8 +505,6 @@
             self.projectBrowser.handleEditorChanged)
         self.viewmanager.editorLineChanged.connect(
             self.projectBrowser.handleEditorLineChanged)
-        self.viewmanager.checkActions.connect(
-            self.cooperation.checkEditorActions)
         self.viewmanager.editorOpened.connect(self.__writeCrashSession)
         self.viewmanager.editorClosed.connect(self.__writeCrashSession)
         self.viewmanager.editorRenamed.connect(self.__writeCrashSession)
@@ -514,19 +513,32 @@
         self.shell.zoomValueChanged.connect(
             lambda v: self.viewmanager.zoomValueChanged(v, self.shell))
         
-        self.cooperation.shareEditor.connect(self.viewmanager.shareEditor)
-        self.cooperation.startEdit.connect(self.viewmanager.startSharedEdit)
-        self.cooperation.sendEdit.connect(self.viewmanager.sendSharedEdit)
-        self.cooperation.cancelEdit.connect(self.viewmanager.cancelSharedEdit)
-        self.cooperation.connected.connect(self.viewmanager.shareConnected)
-        self.cooperation.editorCommand.connect(self.viewmanager.receive)
-        self.viewmanager.setCooperationClient(self.cooperation.getClient())
+        if self.cooperation is not None:
+            self.viewmanager.checkActions.connect(
+                self.cooperation.checkEditorActions)
+            self.preferencesChanged.connect(
+                self.cooperation.preferencesChanged)
+            self.cooperation.shareEditor.connect(
+                self.viewmanager.shareEditor)
+            self.cooperation.startEdit.connect(
+                self.viewmanager.startSharedEdit)
+            self.cooperation.sendEdit.connect(
+                self.viewmanager.sendSharedEdit)
+            self.cooperation.cancelEdit.connect(
+                self.viewmanager.cancelSharedEdit)
+            self.cooperation.connected.connect(
+                self.viewmanager.shareConnected)
+            self.cooperation.editorCommand.connect(
+                self.viewmanager.receive)
+            self.viewmanager.setCooperationClient(
+                self.cooperation.getClient())
         
         self.symbolsViewer.insertSymbol.connect(self.viewmanager.insertSymbol)
         
         self.numbersViewer.insertNumber.connect(self.viewmanager.insertNumber)
         
-        self.irc.autoConnected.connect(self.__ircAutoConnected)
+        if self.irc is not None:
+            self.irc.autoConnected.connect(self.__ircAutoConnected)
         
         # create the toolbar manager object
         self.toolbarManager = E5ToolBarManager(self, self)
@@ -572,11 +584,13 @@
             e5App().registerObject("DummyHelpViewer", self.dummyHelpViewer)
         e5App().registerObject("PluginManager", self.pluginManager)
         e5App().registerObject("ToolbarManager", self.toolbarManager)
-        e5App().registerObject("Cooperation", self.cooperation)
-        e5App().registerObject("IRC", self.irc)
+        if self.cooperation is not None:
+            e5App().registerObject("Cooperation", self.cooperation)
+        if self.irc is not None:
+            e5App().registerObject("IRC", self.irc)
         e5App().registerObject("Symbols", self.symbolsViewer)
         e5App().registerObject("Numbers", self.numbersViewer)
-        if self.codeDocumentationViewer:
+        if self.codeDocumentationViewer is not None:
             e5App().registerObject("DocuViewer", self.codeDocumentationViewer)
         
         # list of web addresses serving the versions file
@@ -647,7 +661,7 @@
         self.toolbarManager.restoreState(
             Preferences.getUI("ToolbarManagerState"))
         
-        if self.codeDocumentationViewer:
+        if self.codeDocumentationViewer is not None:
             # finalize the initialization of the code documentation viewer
             self.codeDocumentationViewer.finalizeSetup()
         
@@ -815,22 +829,24 @@
         self.rToolbox.addItem(self.debugViewer,
                               UI.PixmapCache.getIcon("debugViewer.png"),
                               self.tr("Debug-Viewer"))
-
-        # Create the chat part of the user interface
-        logging.debug("Creating Chat Widget...")
-        from Cooperation.ChatWidget import ChatWidget
-        self.cooperation = ChatWidget(self)
-        self.rToolbox.addItem(self.cooperation,
-                              UI.PixmapCache.getIcon("cooperation.png"),
-                              self.tr("Cooperation"))
-        
-        # Create the IRC part of the user interface
-        logging.debug("Creating IRC Widget...")
-        from Network.IRC.IrcWidget import IrcWidget
-        self.irc = IrcWidget(self)
-        self.rToolbox.addItem(self.irc,
-                              UI.PixmapCache.getIcon("irc.png"),
-                              self.tr("IRC"))
+        
+        if Preferences.getUI("ShowCooperation"):
+            # Create the chat part of the user interface
+            logging.debug("Creating Chat Widget...")
+            from Cooperation.ChatWidget import ChatWidget
+            self.cooperation = ChatWidget(self)
+            self.rToolbox.addItem(self.cooperation,
+                                  UI.PixmapCache.getIcon("cooperation.png"),
+                                  self.tr("Cooperation"))
+        
+        if Preferences.getUI("ShowIrc"):
+            # Create the IRC part of the user interface
+            logging.debug("Creating IRC Widget...")
+            from Network.IRC.IrcWidget import IrcWidget
+            self.irc = IrcWidget(self)
+            self.rToolbox.addItem(self.irc,
+                                  UI.PixmapCache.getIcon("irc.png"),
+                                  self.tr("IRC"))
         
         # Create the task viewer part of the user interface
         logging.debug("Creating Task Viewer...")
@@ -951,20 +967,23 @@
             self.debugViewer, UI.PixmapCache.getIcon("debugViewer.png"),
             self.tr("Debug-Viewer"))
 
-        # Create the chat part of the user interface
-        logging.debug("Creating Chat Widget...")
-        from Cooperation.ChatWidget import ChatWidget
-        self.cooperation = ChatWidget(self)
-        self.rightSidebar.addTab(
-            self.cooperation, UI.PixmapCache.getIcon("cooperation.png"),
-            self.tr("Cooperation"))
-        
-        # Create the IRC part of the user interface
-        logging.debug("Creating IRC Widget...")
-        from Network.IRC.IrcWidget import IrcWidget
-        self.irc = IrcWidget(self)
-        self.rightSidebar.addTab(
-            self.irc, UI.PixmapCache.getIcon("irc.png"), self.tr("IRC"))
+        if Preferences.getUI("ShowCooperation"):
+            # Create the chat part of the user interface
+            logging.debug("Creating Chat Widget...")
+            from Cooperation.ChatWidget import ChatWidget
+            self.cooperation = ChatWidget(self)
+            self.rightSidebar.addTab(
+                self.cooperation, UI.PixmapCache.getIcon("cooperation.png"),
+                self.tr("Cooperation"))
+        
+        if Preferences.getUI("ShowIrc"):
+            # Create the IRC part of the user interface
+            logging.debug("Creating IRC Widget...")
+            from Network.IRC.IrcWidget import IrcWidget
+            self.irc = IrcWidget(self)
+            self.rightSidebar.addTab(
+                self.irc, UI.PixmapCache.getIcon("irc.png"),
+                self.tr("IRC"))
         
         # Create the task viewer part of the user interface
         logging.debug("Creating Task Viewer...")
@@ -1647,40 +1666,42 @@
         self.bsbAct.triggered.connect(self.__toggleBottomSidebar)
         self.actions.append(self.bsbAct)
         
-        self.cooperationViewerActivateAct = E5Action(
-            self.tr('Cooperation-Viewer'),
-            self.tr('Co&operation-Viewer'),
-            QKeySequence(self.tr("Alt+Shift+O")),
-            0, self,
-            'cooperation_viewer_activate')
-        self.cooperationViewerActivateAct.setStatusTip(self.tr(
-            "Switch the input focus to the Cooperation-Viewer window."))
-        self.cooperationViewerActivateAct.setWhatsThis(self.tr(
-            """<b>Activate Cooperation-Viewer</b>"""
-            """<p>This switches the input focus to the Cooperation-Viewer"""
-            """ window.</p>"""
-        ))
-        self.cooperationViewerActivateAct.triggered.connect(
-            self.activateCooperationViewer)
-        self.actions.append(self.cooperationViewerActivateAct)
-        self.addAction(self.cooperationViewerActivateAct)
-
-        self.ircActivateAct = E5Action(
-            self.tr('IRC'),
-            self.tr('&IRC'),
-            QKeySequence(self.tr("Meta+Shift+I")),
-            0, self,
-            'irc_widget_activate')
-        self.ircActivateAct.setStatusTip(self.tr(
-            "Switch the input focus to the IRC window."))
-        self.ircActivateAct.setWhatsThis(self.tr(
-            """<b>Activate IRC</b>"""
-            """<p>This switches the input focus to the IRC window.</p>"""
-        ))
-        self.ircActivateAct.triggered.connect(
-            self.__activateIRC)
-        self.actions.append(self.ircActivateAct)
-        self.addAction(self.ircActivateAct)
+        if self.cooperation is not None:
+            self.cooperationViewerActivateAct = E5Action(
+                self.tr('Cooperation-Viewer'),
+                self.tr('Co&operation-Viewer'),
+                QKeySequence(self.tr("Alt+Shift+O")),
+                0, self,
+                'cooperation_viewer_activate')
+            self.cooperationViewerActivateAct.setStatusTip(self.tr(
+                "Switch the input focus to the Cooperation-Viewer window."))
+            self.cooperationViewerActivateAct.setWhatsThis(self.tr(
+                """<b>Activate Cooperation-Viewer</b>"""
+                """<p>This switches the input focus to the"""
+                """ Cooperation-Viewer window.</p>"""
+            ))
+            self.cooperationViewerActivateAct.triggered.connect(
+                self.activateCooperationViewer)
+            self.actions.append(self.cooperationViewerActivateAct)
+            self.addAction(self.cooperationViewerActivateAct)
+        
+        if self.irc is not None:
+            self.ircActivateAct = E5Action(
+                self.tr('IRC'),
+                self.tr('&IRC'),
+                QKeySequence(self.tr("Meta+Shift+I")),
+                0, self,
+                'irc_widget_activate')
+            self.ircActivateAct.setStatusTip(self.tr(
+                "Switch the input focus to the IRC window."))
+            self.ircActivateAct.setWhatsThis(self.tr(
+                """<b>Activate IRC</b>"""
+                """<p>This switches the input focus to the IRC window.</p>"""
+            ))
+            self.ircActivateAct.triggered.connect(
+                self.__activateIRC)
+            self.actions.append(self.ircActivateAct)
+            self.addAction(self.ircActivateAct)
 
         self.symbolsViewerActivateAct = E5Action(
             self.tr('Symbols-Viewer'),
@@ -2764,13 +2785,16 @@
             # Qt4
             self.__menus["subwindow"].addSeparator()
         # right side
-        if self.codeDocumentationViewer:
+        if self.codeDocumentationViewer is not None:
             self.__menus["subwindow"].addAction(
                 self.tr("Code Documentation Viewer"),
                 self.activateCodeDocumentationViewer)
         self.__menus["subwindow"].addAction(self.debugViewerActivateAct)
-        self.__menus["subwindow"].addAction(self.cooperationViewerActivateAct)
-        self.__menus["subwindow"].addAction(self.ircActivateAct)
+        if self.cooperation is not None:
+            self.__menus["subwindow"].addAction(
+                self.cooperationViewerActivateAct)
+        if self.irc is not None:
+            self.__menus["subwindow"].addAction(self.ircActivateAct)
         try:
             self.__menus["subwindow"].addSection(self.tr("Plug-ins"))
         except AttributeError:
@@ -3588,7 +3612,7 @@
         """
         if self.__shutdown():
             e5App().closeAllWindows()
-        
+    
     def __restart(self):
         """
         Private method to restart the application.
@@ -4228,29 +4252,31 @@
         """
         Public slot to handle the activation of the cooperation window.
         """
-        if self.layoutType == "Toolboxes":
-            self.rToolboxDock.show()
-            self.rToolbox.setCurrentWidget(self.cooperation)
-        elif self.layoutType == "Sidebars":
-            self.rightSidebar.show()
-            self.rightSidebar.setCurrentWidget(self.cooperation)
-        else:
-            self.cooperation.show()
-        self.cooperation.setFocus(Qt.ActiveWindowFocusReason)
+        if self.cooperation is not None:
+            if self.layoutType == "Toolboxes":
+                self.rToolboxDock.show()
+                self.rToolbox.setCurrentWidget(self.cooperation)
+            elif self.layoutType == "Sidebars":
+                self.rightSidebar.show()
+                self.rightSidebar.setCurrentWidget(self.cooperation)
+            else:
+                self.cooperation.show()
+            self.cooperation.setFocus(Qt.ActiveWindowFocusReason)
         
     def __activateIRC(self):
         """
         Private slot to handle the activation of the IRC window.
         """
-        if self.layoutType == "Toolboxes":
-            self.rToolboxDock.show()
-            self.rToolbox.setCurrentWidget(self.irc)
-        elif self.layoutType == "Sidebars":
-            self.rightSidebar.show()
-            self.rightSidebar.setCurrentWidget(self.irc)
-        else:
-            self.irc.show()
-        self.irc.setFocus(Qt.ActiveWindowFocusReason)
+        if self.irc is not None:
+            if self.layoutType == "Toolboxes":
+                self.rToolboxDock.show()
+                self.rToolbox.setCurrentWidget(self.irc)
+            elif self.layoutType == "Sidebars":
+                self.rightSidebar.show()
+                self.rightSidebar.setCurrentWidget(self.irc)
+            else:
+                self.irc.show()
+            self.irc.setFocus(Qt.ActiveWindowFocusReason)
         
     def __activateSymbolsViewer(self):
         """
@@ -4295,7 +4321,7 @@
         @param switchFocus flag indicating to transfer the input focus
         @type bool
         """
-        if self.codeDocumentationViewer:
+        if self.codeDocumentationViewer is not None:
             if self.layoutType == "Toolboxes":
                 self.rToolboxDock.show()
                 self.rToolbox.setCurrentWidget(self.codeDocumentationViewer)
@@ -6433,8 +6459,9 @@
             if not self.helpWindow.shutdown():
                 return False
         
-        if not self.irc.shutdown():
-            return False
+        if self.irc is not None:
+            if not self.irc.shutdown():
+                return False
         
         sessionCreated = self.__writeSession()
         
@@ -6450,7 +6477,7 @@
         if sessionCreated and not self.__disableCrashSession:
             self.__deleteCrashSession()
         
-        if self.codeDocumentationViewer:
+        if self.codeDocumentationViewer is not None:
             self.codeDocumentationViewer.shutdown()
         
         self.__previewer.shutdown()
@@ -6466,7 +6493,8 @@
         
         self.backgroundService.shutdown()
         
-        self.cooperation.shutdown()
+        if self.cooperation is not None:
+            self.cooperation.shutdown()
         
         self.pluginManager.doShutdown()
         
@@ -6984,7 +7012,8 @@
         """
         Public method to initiate the IRC auto connection.
         """
-        self.irc.autoConnect()
+        if self.irc is not None:
+            self.irc.autoConnect()
     
     def __ircAutoConnected(self):
         """

eric ide

mercurial