src/eric7/WebBrowser/AutoScroll/AutoScroller.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
--- a/src/eric7/WebBrowser/AutoScroll/AutoScroller.py	Wed Jul 13 11:16:20 2022 +0200
+++ b/src/eric7/WebBrowser/AutoScroll/AutoScroller.py	Wed Jul 13 14:55:47 2022 +0200
@@ -25,41 +25,41 @@
     """
     Class implementing the automatic scroller.
     """
+
     def __init__(self, parent=None):
         """
         Constructor
-        
+
         @param parent reference to the parent object
         @type QObject
         """
         super().__init__(parent)
-        
+
         self.__view = None
-        
+
         self.__indicator = QLabel()
         self.__indicator.resize(32, 32)
         self.__indicator.setContentsMargins(0, 0, 0, 0)
         self.__indicator.installEventFilter(self)
-        
+
         self.__scroller = FrameScroller(self)
-        self.__scroller.setScrollDivider(
-            Preferences.getWebBrowser("AutoScrollDivider"))
-        
+        self.__scroller.setScrollDivider(Preferences.getWebBrowser("AutoScrollDivider"))
+
         self.__enabled = Preferences.getWebBrowser("AutoScrollEnabled")
-    
+
     def isEnabled(self):
         """
         Public method to get the enabled state.
-        
+
         @return enabled state
         @rtype bool
         """
         return self.__enabled
-    
+
     def mouseMove(self, evt):
         """
         Public method to handle mouse move events.
-        
+
         @param evt reference to the mouse move event
         @type QMouseEvent
         @return flag indicating, that the event was handled
@@ -70,25 +70,25 @@
             xlen = 0
             ylen = 0
             egp = evt.globalPosition().toPoint()
-            
+
             if rect.left() > egp.x():
                 xlen = egp.x() - rect.left()
             elif rect.right() < egp.x():
                 xlen = egp.x() - rect.right()
-            
+
             if rect.top() > egp.y():
                 ylen = egp.y() - rect.top()
             elif rect.bottom() < egp.y():
                 ylen = egp.y() - rect.bottom()
-            
+
             self.__scroller.startScrolling(xlen, ylen)
-        
+
         return False
-    
+
     def mousePress(self, view, evt):
         """
         Public method to handle mouse button presses.
-        
+
         @param view reference to the web view the button was pressed on
         @type WebBrowserView
         @param evt reference to the mouse button press event
@@ -98,26 +98,25 @@
         """
         if self.__enabled:
             middleButton = evt.buttons() == Qt.MouseButton.MiddleButton
-            
+
             if view:
                 # test for start
-                if (
-                    middleButton and
-                    (self.__view != view or not self.__indicator.isVisible())
+                if middleButton and (
+                    self.__view != view or not self.__indicator.isVisible()
                 ):
                     return self.__showIndicator(view, evt.position().toPoint())
-                
+
                 # test for stop
                 if self.__indicator.isVisible():
                     self.__stopScrolling()
                     return True
-        
+
         return False
-    
+
     def mouseRelease(self, evt):
         """
         Public method to handle mouse button releases.
-        
+
         @param evt reference to the mouse button release event
         @type QMouseEvent
         @return flag indicating, that the event was handled
@@ -125,25 +124,26 @@
         """
         if self.__enabled and self.__indicator.isVisible():
             if not self.__indicatorGlobalRect().contains(
-                    evt.globalPosition().toPoint()):
+                evt.globalPosition().toPoint()
+            ):
                 self.__stopScrolling()
             return True
-        
+
         return False
-    
+
     def wheel(self):
         """
         Public method to handle a mouse wheel event.
-        
+
         @return flag indicating, that the event was handled
         @rtype bool
         """
         if self.__enabled and self.__indicator.isVisible():
             self.__stopScrolling()
             return True
-        
+
         return False
-    
+
     def preferencesChanged(self):
         """
         Public method to handle a change of the settings.
@@ -153,14 +153,13 @@
             if self.__indicator.isVisible():
                 self.__stopScrolling()
             self.__enabled = enabled
-        
-        self.__scroller.setScrollDivider(
-            Preferences.getWebBrowser("AutoScrollDivider"))
-    
+
+        self.__scroller.setScrollDivider(Preferences.getWebBrowser("AutoScrollDivider"))
+
     def eventFilter(self, obj, evt):
         """
         Public method to handle event for an object.
-        
+
         @param obj refernce to the object sending the event
         @type QObject
         @param evt reference to the event to be handled
@@ -171,16 +170,19 @@
         if obj == self.__indicator:
             if evt.type() == QEvent.Type.Enter:
                 self.__scroller.stopScrolling()
-            elif evt.type() in [QEvent.Type.Wheel, QEvent.Type.Hide,
-                                QEvent.Type.MouseButtonPress]:
+            elif evt.type() in [
+                QEvent.Type.Wheel,
+                QEvent.Type.Hide,
+                QEvent.Type.MouseButtonPress,
+            ]:
                 self.__stopScrolling()
-        
+
         return False
-    
+
     def __showIndicator(self, view, pos):
         """
         Private method to show the auto scroll indicator.
-        
+
         @param view reference to the view to show the indicator on
         @type WebBrowserView
         @param pos position to show the indicator at
@@ -189,10 +191,10 @@
         @rtype bool
         """
         hit = view.page().hitTestContent(pos)
-        
+
         if hit.isContentEditable() or not hit.linkUrl().isEmpty():
             return False
-        
+
         jsSource = """
             var out = {
              vertical:
@@ -201,62 +203,61 @@
                 window.innerHeight > document.documentElement.clientHeight
             };
             out;"""
-        
+
         res = view.page().execJavaScript(jsSource)
         if res is None:
             return False
-        
+
         vertical = res["vertical"]
         horizontal = res["horizontal"]
         if not vertical and not horizontal:
             return False
-        
+
         if vertical and horizontal:
-            self.__indicator.setPixmap(
-                UI.PixmapCache.getPixmap("scrollAll"))
+            self.__indicator.setPixmap(UI.PixmapCache.getPixmap("scrollAll"))
         elif vertical:
-            self.__indicator.setPixmap(
-                UI.PixmapCache.getPixmap("scrollVertical"))
+            self.__indicator.setPixmap(UI.PixmapCache.getPixmap("scrollVertical"))
         else:
-            self.__indicator.setPixmap(
-                UI.PixmapCache.getPixmap("scrollHorizontal"))
-        
+            self.__indicator.setPixmap(UI.PixmapCache.getPixmap("scrollHorizontal"))
+
         self.__view = view
         p = QPoint(
             pos.x() - self.__indicator.pixmap().width() // 2,
-            pos.y() - self.__indicator.pixmap().height() // 2
+            pos.y() - self.__indicator.pixmap().height() // 2,
         )
-        
+
         self.__indicator.setParent(self.__view)
         self.__indicator.move(p)
         self.__indicator.show()
-        
+
         self.__scroller.setPage(view.page())
-        
+
         self.__view.inputWidget().grabMouse()
         QApplication.setOverrideCursor(Qt.CursorShape.ArrowCursor)
-        
+
         return True
-    
+
     def __stopScrolling(self):
         """
         Private method to stop scrolling.
         """
         self.__view.inputWidget().releaseMouse()
         QApplication.restoreOverrideCursor()
-        
+
         self.__indicator.hide()
         self.__indicator.setParent(None)
         self.__scroller.stopScrolling()
-    
+
     def __indicatorGlobalRect(self):
         """
         Private method to calculate the global indicator parameters.
-        
+
         @return global indicator parameters
         @rtype QRect
         """
         pos = self.__indicator.parentWidget().mapToGlobal(
-            self.__indicator.geometry().topLeft())
-        return QRect(pos.x(), pos.y(),
-                     self.__indicator.width(), self.__indicator.height())
+            self.__indicator.geometry().topLeft()
+        )
+        return QRect(
+            pos.x(), pos.y(), self.__indicator.width(), self.__indicator.height()
+        )

eric ide

mercurial