eric6/ViewManager/ViewManager.py

branch
maintenance
changeset 8273
698ae46f40a4
parent 8176
31965986ecd1
parent 8260
2161475d9639
child 8400
b3eefd7e58d1
diff -r fb0ef164f536 -r 698ae46f40a4 eric6/ViewManager/ViewManager.py
--- a/eric6/ViewManager/ViewManager.py	Fri Apr 02 11:59:41 2021 +0200
+++ b/eric6/ViewManager/ViewManager.py	Sat May 01 14:27:20 2021 +0200
@@ -9,6 +9,7 @@
 
 import re
 import os
+import contextlib
 
 from PyQt5.QtCore import (
     pyqtSignal, pyqtSlot, Qt, QSignalMapper, QTimer, QFileInfo, QPoint,
@@ -111,7 +112,7 @@
         """
         Constructor
         """
-        super(ViewManager, self).__init__()
+        super().__init__()
         
         # initialize the instance variables
         self.editors = []
@@ -4399,11 +4400,7 @@
         @return flag indicating successful reset of all dirty flags
         @rtype bool
         """
-        for editor in self.editors:
-            if not self.checkDirty(editor):
-                return False
-        
-        return True
+        return all(self.checkDirty(editor) for editor in self.editors)
         
     def checkFileDirty(self, fn):
         """
@@ -5166,19 +5163,14 @@
         
         self.recentMenu.clear()
         
-        idx = 1
-        for rs in self.recent:
-            if idx < 10:
-                formatStr = '&{0:d}. {1}'
-            else:
-                formatStr = '{0:d}. {1}'
+        for idx, rs in enumerate(self.recent, start=1):
+            formatStr = '&{0:d}. {1}' if idx < 10 else '{0:d}. {1}'
             act = self.recentMenu.addAction(
                 formatStr.format(
                     idx,
                     Utilities.compactPath(rs, self.ui.maxMenuFilePathLen)))
             act.setData(rs)
             act.setEnabled(QFileInfo(rs).exists())
-            idx += 1
         
         self.recentMenu.addSeparator()
         self.recentMenu.addAction(
@@ -5725,10 +5717,11 @@
         """
         Private method to handle the zoom action.
         """
-        if QApplication.focusWidget() == e5App().getObject("Shell"):
-            aw = e5App().getObject("Shell")
-        else:
-            aw = self.activeWindow()
+        aw = (
+            e5App().getObject("Shell")
+            if QApplication.focusWidget() == e5App().getObject("Shell") else
+            self.activeWindow()
+        )
         if aw:
             from QScintilla.ZoomDialog import ZoomDialog
             dlg = ZoomDialog(aw.getZoom(), self.ui, None, True)
@@ -5742,10 +5735,11 @@
         
         @param value zoom value to be set (integer)
         """
-        if QApplication.focusWidget() == e5App().getObject("Shell"):
-            aw = e5App().getObject("Shell")
-        else:
-            aw = self.activeWindow()
+        aw = (
+            e5App().getObject("Shell")
+            if QApplication.focusWidget() == e5App().getObject("Shell") else
+            self.activeWindow()
+        )
         if aw:
             aw.zoomTo(value)
             self.sbZoom.setValue(aw.getZoom())
@@ -5759,10 +5753,11 @@
         @param zoomingWidget reference to the widget triggering the slot
         @type Editor or Shell
         """
-        if QApplication.focusWidget() == e5App().getObject("Shell"):
-            aw = e5App().getObject("Shell")
-        else:
-            aw = self.activeWindow()
+        aw = (
+            e5App().getObject("Shell")
+            if QApplication.focusWidget() == e5App().getObject("Shell") else
+            self.activeWindow()
+        )
         if aw and aw == zoomingWidget:
             self.sbZoom.setValue(value)
     
@@ -6294,10 +6289,8 @@
         
         @return flag indicating success (boolean)
         """
-        try:
+        with contextlib.suppress(TypeError):
             e5App().focusChanged.disconnect(self.appFocusChanged)
-        except TypeError:
-            pass
         
         self.closeAllWindows()
         self.currentEditor = None
@@ -6309,10 +6302,7 @@
         Preferences.Prefs.settings.setValue(
             'Bookmarked/Sources', self.bookmarked)
         
-        if len(self.editors):
-            res = False
-        else:
-            res = True
+        res = len(self.editors) == 0
         
         if not res:
             e5App().focusChanged.connect(self.appFocusChanged)
@@ -7003,7 +6993,6 @@
                 txt = aw.selectedText()
         else:
             aw = self.activeWindow()
-            if aw is not None:
-                if aw.hasSelectedText():
-                    txt = aw.selectedText()
+            if aw is not None and aw.hasSelectedText():
+                txt = aw.selectedText()
         return txt

eric ide

mercurial