src/eric7/WebBrowser/QtHelp/HelpTocWidget.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9473
3f23dbf37dbe
--- a/src/eric7/WebBrowser/QtHelp/HelpTocWidget.py	Wed Jul 13 11:16:20 2022 +0200
+++ b/src/eric7/WebBrowser/QtHelp/HelpTocWidget.py	Wed Jul 13 14:55:47 2022 +0200
@@ -15,7 +15,7 @@
 class HelpTocWidget(QWidget):
     """
     Class implementing a window for showing the QtHelp TOC.
-    
+
     @signal escapePressed() emitted when the ESC key was pressed
     @signal openUrl(QUrl, str) emitted to open an entry in the current tab
     @signal newTab(QUrl, str) emitted to open an entry in a new tab
@@ -23,16 +23,17 @@
         new background tab
     @signal newWindow(QUrl, str) emitted to open an entry in a new window
     """
+
     escapePressed = pyqtSignal()
     openUrl = pyqtSignal(QUrl)
     newTab = pyqtSignal(QUrl)
     newBackgroundTab = pyqtSignal(QUrl)
     newWindow = pyqtSignal(QUrl)
-    
+
     def __init__(self, engine, internal=False, parent=None):
         """
         Constructor
-        
+
         @param engine reference to the help engine
         @type QHelpEngine
         @param internal flag indicating the internal help viewer
@@ -41,72 +42,68 @@
         @type QWidget
         """
         super().__init__(parent)
-        
+
         self.__engine = engine
         self.__expandDepth = -2
-        
+
         self.__internal = internal
-        
+
         self.__tocWidget = self.__engine.contentWidget()
-        self.__tocWidget.setContextMenuPolicy(
-            Qt.ContextMenuPolicy.CustomContextMenu)
+        self.__tocWidget.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
         self.__tocWidget.setSortingEnabled(True)
-        
+
         self.__layout = QVBoxLayout(self)
         if internal:
             # no margins for the internal variant
             self.__layout.setContentsMargins(0, 0, 0, 0)
         self.__layout.addWidget(self.__tocWidget)
-        
-        self.__tocWidget.customContextMenuRequested.connect(
-            self.__showContextMenu)
+
+        self.__tocWidget.customContextMenuRequested.connect(self.__showContextMenu)
         self.__tocWidget.linkActivated.connect(self.__linkActivated)
-        
+
         model = self.__tocWidget.model()
         model.contentsCreated.connect(self.__contentsCreated)
-    
+
     @pyqtSlot(QUrl)
     def __linkActivated(self, url):
         """
         Private slot handling the activation of an entry.
-        
+
         @param url URL of the activated entry
         @type QUrl
         """
         if not url.isEmpty() and url.isValid():
             buttons = QApplication.mouseButtons()
             modifiers = QApplication.keyboardModifiers()
-            
+
             if buttons & Qt.MouseButton.MiddleButton:
                 self.newTab.emit(url)
             else:
-                if (
-                    modifiers & (
-                        Qt.KeyboardModifier.ControlModifier |
-                        Qt.KeyboardModifier.ShiftModifier
-                    ) == (
-                        Qt.KeyboardModifier.ControlModifier |
-                        Qt.KeyboardModifier.ShiftModifier
-                    )
+                if modifiers & (
+                    Qt.KeyboardModifier.ControlModifier
+                    | Qt.KeyboardModifier.ShiftModifier
+                ) == (
+                    Qt.KeyboardModifier.ControlModifier
+                    | Qt.KeyboardModifier.ShiftModifier
                 ):
                     self.newBackgroundTab.emit(url)
                 elif modifiers & Qt.KeyboardModifier.ControlModifier:
                     self.newTab.emit(url)
                 elif (
-                    modifiers & Qt.KeyboardModifier.ShiftModifier and
-                    not self.__internal
+                    modifiers & Qt.KeyboardModifier.ShiftModifier
+                    and not self.__internal
                 ):
                     self.newWindow.emit(url)
                 else:
                     self.openUrl.emit(url)
-    
+
     def __contentsCreated(self):
         """
         Private slot to be run after the contents was generated.
         """
         self.__tocWidget.sortByColumn(0, Qt.SortOrder.AscendingOrder)
         self.__expandTOC()
-    
+
     def __expandTOC(self):
         """
         Private slot to expand the table of contents.
@@ -114,11 +111,11 @@
         if self.__expandDepth > -2:
             self.expandToDepth(self.__expandDepth)
             self.__expandDepth = -2
-    
+
     def expandToDepth(self, depth):
         """
         Public slot to expand the table of contents to a specific depth.
-        
+
         @param depth depth to expand to (integer)
         """
         self.__expandDepth = depth
@@ -126,29 +123,29 @@
             self.__tocWidget.expandAll()
         else:
             self.__tocWidget.expandToDepth(depth)
-    
+
     def focusInEvent(self, evt):
         """
         Protected method handling focus in events.
-        
+
         @param evt reference to the focus event object (QFocusEvent)
         """
         if evt.reason() != Qt.FocusReason.MouseFocusReason:
             self.__tocWidget.setFocus()
-    
+
     def keyPressEvent(self, evt):
         """
         Protected method handling key press events.
-        
+
         @param evt reference to the key press event (QKeyEvent)
         """
         if evt.key() == Qt.Key.Key_Escape:
             self.escapePressed.emit()
-    
+
     def syncToContent(self, url):
         """
         Public method to sync the TOC to the displayed page.
-        
+
         @param url URL of the displayed page (QUrl)
         @return flag indicating a successful synchronization (boolean)
         """
@@ -157,37 +154,35 @@
             return False
         self.__tocWidget.setCurrentIndex(idx)
         return True
-    
+
     def __showContextMenu(self, pos):
         """
         Private slot showing the context menu.
-        
+
         @param pos position to show the menu at (QPoint)
         """
         if not self.__tocWidget.indexAt(pos).isValid():
             return
-        
+
         model = self.__tocWidget.model()
         itm = model.contentItemAt(self.__tocWidget.currentIndex())
         link = itm.url()
         if link.isEmpty() or not link.isValid():
             return
-        
+
         menu = QMenu()
         curTab = menu.addAction(self.tr("Open Link"))
         if self.__internal:
             newTab = menu.addAction(self.tr("Open Link in New Page"))
-            newBackgroundTab = menu.addAction(
-                self.tr("Open Link in Background Page"))
+            newBackgroundTab = menu.addAction(self.tr("Open Link in Background Page"))
         else:
             newTab = menu.addAction(self.tr("Open Link in New Tab"))
-            newBackgroundTab = menu.addAction(
-                self.tr("Open Link in Background Tab"))
+            newBackgroundTab = menu.addAction(self.tr("Open Link in Background Tab"))
             newWindow = menu.addAction(self.tr("Open Link in New Window"))
         menu.addSeparator()
         copyLink = menu.addAction(self.tr("Copy URL to Clipboard"))
         menu.move(self.__tocWidget.mapToGlobal(pos))
-        
+
         act = menu.exec()
         if act == curTab:
             self.openUrl.emit(link)
@@ -200,6 +195,8 @@
         elif act == copyLink:
             # copy the URL to both clipboard areas
             QGuiApplication.clipboard().setText(
-                link.toString(), QClipboard.Mode.Clipboard)
+                link.toString(), QClipboard.Mode.Clipboard
+            )
             QGuiApplication.clipboard().setText(
-                link.toString(), QClipboard.Mode.Selection)
+                link.toString(), QClipboard.Mode.Selection
+            )

eric ide

mercurial