From c32ecfac7a61af0abf33ff9189c04bd2d61daad0 Mon Sep 17 00:00:00 2001 From: adeliktas <64136642+adeliktas@users.noreply.github.com> Date: Fri, 12 Nov 2021 13:28:28 +0100 Subject: [PATCH 01/11] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cb33634..16f24bd 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This simple Python script gives you a Windows-like autoscroll feature on Linux. 1. Clone the repository: ``` -git clone https://github.com/TWolczanski/linux-autoscroll.git +git clone https://github.com/adeliktas/linux-autoscroll.git ``` 2. Create a Python virtual environment and activate it: ``` @@ -13,7 +13,8 @@ source .autoscroll/bin/activate ``` 3. Install pynput: ``` -python3 -m pip install pynput +pip3 install --user pynput +(python3 -m pip install pynput) ``` 4. Add the following shebang to the script (substitute `/path/to` with the actual path to your virtual environment): ``` From 5b2ab1fa5f7cbb00964690000bb11c984d06b2a1 Mon Sep 17 00:00:00 2001 From: adeliktas <64136642+adeliktas@users.noreply.github.com> Date: Sat, 13 Nov 2021 11:03:03 +0100 Subject: [PATCH 02/11] Update autoscroll.py --- autoscroll.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/autoscroll.py b/autoscroll.py index bfb0566..cb4b8e1 100644 --- a/autoscroll.py +++ b/autoscroll.py @@ -1,6 +1,6 @@ from pynput.mouse import Button, Controller, Listener from threading import Event -from time import sleep +import time def on_move(x, y): global pos, scroll_mode, direction, interval, DELAY, DEAD_AREA @@ -19,19 +19,30 @@ def on_move(x, y): def on_click(x, y, button, pressed): global pos, scroll_mode, direction, interval, BUTTON_START, BUTTON_STOP + + #Trigger Delay 400ms to avoid instant changes + Triggerdelay = 0.4 + global Timestart, Timeend, Timedelta + if button == BUTTON_START and pressed and not scroll_mode.is_set(): pos = (x, y) direction = 0 interval = 0 scroll_mode.set() - elif button == BUTTON_STOP and pressed and scroll_mode.is_set(): + Timestart = time.time() + elif button == BUTTON_STOP and not pressed and scroll_mode.is_set(): + Timeend = time.time() + Timedelta = Timeend - Timestart + if Timedelta>Triggerdelay: + scroll_mode.clear() + elif (button == BUTTON_STOP or button==Button.left) and pressed and scroll_mode.is_set(): scroll_mode.clear() def autoscroll(): global mouse, scroll_mode, direction, interval while True: scroll_mode.wait() - sleep(interval) + time.sleep(interval) mouse.scroll(0, direction) mouse = Controller() @@ -48,7 +59,8 @@ def autoscroll(): # modify this to change the button used for exiting the scroll mode BUTTON_STOP = Button.middle # modify this to change the size (in px) of the area below and above the starting point where the scrolling is paused -DEAD_AREA = 30 +DEAD_AREA = 10 + listener.start() autoscroll() From 8e7049922a4a1051683b18e937c3b05d6249d91d Mon Sep 17 00:00:00 2001 From: adeliktas <64136642+adeliktas@users.noreply.github.com> Date: Sat, 13 Nov 2021 19:56:50 +0100 Subject: [PATCH 03/11] qt crosshair tracking and improved scroll behaviour --- autoscroll.py | 180 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 125 insertions(+), 55 deletions(-) diff --git a/autoscroll.py b/autoscroll.py index cb4b8e1..2be88df 100644 --- a/autoscroll.py +++ b/autoscroll.py @@ -1,66 +1,136 @@ +import sys +from PyQt5 import QtCore, QtGui, QtWidgets from pynput.mouse import Button, Controller, Listener from threading import Event import time -def on_move(x, y): - global pos, scroll_mode, direction, interval, DELAY, DEAD_AREA - if scroll_mode.is_set(): - delta = pos[1] - y - if abs(delta) <= DEAD_AREA: - direction = 0 - elif delta > 0: - direction = 1 - elif delta < 0: - direction = -1 - if abs(delta) <= DEAD_AREA + DELAY * 2: - interval = 0.5 - else: - interval = DELAY / (abs(delta) - DEAD_AREA) +xpos,ypos = Controller().position +crosssizepx=30 -def on_click(x, y, button, pressed): - global pos, scroll_mode, direction, interval, BUTTON_START, BUTTON_STOP - - #Trigger Delay 400ms to avoid instant changes - Triggerdelay = 0.4 - global Timestart, Timeend, Timedelta +from PyQt5.QtCore import Qt, QObject, pyqtSignal, QTimer + +from tkinter import Tk +import subprocess + +class QMouseListener(QObject): + mouse_moved = pyqtSignal(int, int) + mouse_clicked = pyqtSignal(int, int, Button, bool) + + def __init__(self, parent=None): + super().__init__(parent=parent) + self.listener = Listener(on_move=self.mouse_moved.emit, on_click=self.mouse_clicked.emit) + + def start(self): + self.listener.start() + +class Autoscrollsymbol(QtWidgets.QWidget): - if button == BUTTON_START and pressed and not scroll_mode.is_set(): - pos = (x, y) - direction = 0 - interval = 0 - scroll_mode.set() - Timestart = time.time() - elif button == BUTTON_STOP and not pressed and scroll_mode.is_set(): - Timeend = time.time() - Timedelta = Timeend - Timestart - if Timedelta>Triggerdelay: - scroll_mode.clear() - elif (button == BUTTON_STOP or button==Button.left) and pressed and scroll_mode.is_set(): - scroll_mode.clear() + def __init__(self, parent=None, windowSize=24, penWidth=2): + QtWidgets.QWidget.__init__(self, parent) + self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint | QtCore.Qt.WindowTransparentForInput) + self.setStyleSheet("background:transparent") + self.setAttribute(QtCore.Qt.WA_TranslucentBackground) + self.setGeometry(xpos, ypos, 50, 50) + self.pen = QtGui.QPen(QtGui.QColor(0,255,0,255)) + self.pen.setWidth(penWidth) + + self.mouse_listener = QMouseListener(self) + self.mouse_listener.mouse_moved.connect(self.on_move) + self.mouse_listener.mouse_clicked.connect(self.on_click) + self.mouse_listener.start() + + self.scroll_mode = 0 -def autoscroll(): - global mouse, scroll_mode, direction, interval - while True: - scroll_mode.wait() - time.sleep(interval) - mouse.scroll(0, direction) + self.mouse = Controller() + self.pos = self.mouse.position + self.direction = 0 + self.interval = 0 + + # modify this to adjust the speed of scrolling + self.DELAY = 5 + # modify this to change the button used for using scroll mode + self.BUTTON_Scroll = Button.middle + # modify this to change the size (in px) of the area below and above the starting point where the scrolling is paused + self.DEAD_AREA = 10 + + #Trigger Delay 250ms to avoid instant changes + self.Triggerdelay = 0.25 + self.Timestart = 0 + self.Timeend = 0 + self.Timedelta = 0 + + + self.autoscroll() -mouse = Controller() -listener = Listener(on_move = on_move, on_click = on_click) -scroll_mode = Event() -pos = mouse.position -direction = 0 -interval = 0 + def on_move(self, x, y): + if self.scroll_mode: + delta = self.pos[1] - y + if abs(delta) <= self.DEAD_AREA: + self.direction = 0 + elif delta > 0: + self.direction = 1 + elif delta < 0: + self.direction = -1 + if abs(delta) <= self.DEAD_AREA + self.DELAY * 2: + self.interval = 0.5 + else: + self.interval = self.DELAY / (abs(delta) - self.DEAD_AREA) + if not self.scroll_mode: + self.move(x -int(crosssizepx/2),y -int(crosssizepx/2)) -# modify this to adjust the speed of scrolling -DELAY = 5 -# modify this to change the button used for entering the scroll mode -BUTTON_START = Button.middle -# modify this to change the button used for exiting the scroll mode -BUTTON_STOP = Button.middle -# modify this to change the size (in px) of the area below and above the starting point where the scrolling is paused -DEAD_AREA = 10 + def clearclip(self): + r = Tk() + r.withdraw() + r.clipboard_clear() + r.clipboard_append('') + r.update() + r.destroy() + subprocess.run(["xsel","-c"]) + def on_click(self, x, y, button, pressed): + #if button==Button.middle and pressed: + #print('Button {0} pressed on pos: {1}'.format(button, (x, y))) + + if button == self.BUTTON_Scroll and pressed and not self.scroll_mode: + self.clearclip() + self.pos = (x, y) + self.direction = 0 + self.interval = 0 + self.scroll_mode = 1 + self.Timestart = time.time() + elif button == self.BUTTON_Scroll and not pressed and self.scroll_mode: + self.Timeend = time.time() + self.Timedelta = self.Timeend - self.Timestart + if self.Timedelta>self.Triggerdelay: + self.scroll_mode = 0 + elif (button == self.BUTTON_Scroll or button==Button.left) and pressed and self.scroll_mode: + self.clearclip() + self.scroll_mode = 0 + + def paintEvent(self, event): + painter = QtGui.QPainter(self) + pen = QtGui.QPen(QtCore.Qt.green, 2, QtCore.Qt.SolidLine) + painter.setPen(pen) + #painter.setPen(self.pen) + painter.drawEllipse(0, 0, (crosssizepx), (crosssizepx)) + painter.drawLine(0, int(crosssizepx/2), crosssizepx, int(crosssizepx/2))#- + painter.drawLine(int(crosssizepx/2), 0, int(crosssizepx/2), crosssizepx)#| + + def scrolldown(self): + if self.scroll_mode: + time.sleep(self.interval) + self.mouse.scroll(0, self.direction) + + def autoscroll(self): + self.timer = QTimer(self) + self.timer.timeout.connect(self.scrolldown) + self.timer.start(0) + + def mouselistener(self): + self.listener=Listener(on_move=self.on_move) + self.listener.start() -listener.start() -autoscroll() +app = QtWidgets.QApplication(sys.argv) +widget = Autoscrollsymbol(windowSize=1, penWidth=10) +widget.show() +sys.exit(app.exec_()) From 3aba97ccf0c80b72fb87a3d2b64c031dfcae3c0b Mon Sep 17 00:00:00 2001 From: adeliktas <64136642+adeliktas@users.noreply.github.com> Date: Sat, 13 Nov 2021 20:35:47 +0100 Subject: [PATCH 04/11] hidden autoscroll symbol --- autoscroll.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/autoscroll.py b/autoscroll.py index 2be88df..47e5d15 100644 --- a/autoscroll.py +++ b/autoscroll.py @@ -25,22 +25,19 @@ def start(self): class Autoscrollsymbol(QtWidgets.QWidget): - def __init__(self, parent=None, windowSize=24, penWidth=2): + def __init__(self, parent=None, windowSize=0, penWidth=0): QtWidgets.QWidget.__init__(self, parent) - self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint | QtCore.Qt.WindowTransparentForInput) + self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint | QtCore.Qt.WindowTransparentForInput | QtCore.Qt.Tool) self.setStyleSheet("background:transparent") self.setAttribute(QtCore.Qt.WA_TranslucentBackground) self.setGeometry(xpos, ypos, 50, 50) self.pen = QtGui.QPen(QtGui.QColor(0,255,0,255)) - self.pen.setWidth(penWidth) - + self.pen.setWidth(penWidth) self.mouse_listener = QMouseListener(self) self.mouse_listener.mouse_moved.connect(self.on_move) self.mouse_listener.mouse_clicked.connect(self.on_click) self.mouse_listener.start() - - self.scroll_mode = 0 - + self.scroll_mode = 0 self.mouse = Controller() self.pos = self.mouse.position self.direction = 0 @@ -59,7 +56,6 @@ def __init__(self, parent=None, windowSize=24, penWidth=2): self.Timeend = 0 self.Timedelta = 0 - self.autoscroll() def on_move(self, x, y): @@ -88,11 +84,9 @@ def clearclip(self): subprocess.run(["xsel","-c"]) def on_click(self, x, y, button, pressed): - #if button==Button.middle and pressed: - #print('Button {0} pressed on pos: {1}'.format(button, (x, y))) - if button == self.BUTTON_Scroll and pressed and not self.scroll_mode: self.clearclip() + self.setWindowOpacity(1.0) self.pos = (x, y) self.direction = 0 self.interval = 0 @@ -103,9 +97,11 @@ def on_click(self, x, y, button, pressed): self.Timedelta = self.Timeend - self.Timestart if self.Timedelta>self.Triggerdelay: self.scroll_mode = 0 + self.setWindowOpacity(0.0) elif (button == self.BUTTON_Scroll or button==Button.left) and pressed and self.scroll_mode: self.clearclip() self.scroll_mode = 0 + self.setWindowOpacity(0.0) def paintEvent(self, event): painter = QtGui.QPainter(self) @@ -115,6 +111,7 @@ def paintEvent(self, event): painter.drawEllipse(0, 0, (crosssizepx), (crosssizepx)) painter.drawLine(0, int(crosssizepx/2), crosssizepx, int(crosssizepx/2))#- painter.drawLine(int(crosssizepx/2), 0, int(crosssizepx/2), crosssizepx)#| + self.setWindowOpacity(0.0) def scrolldown(self): if self.scroll_mode: From 4a18f0ba66cd119809cfe75cbbbe56c535c72cbc Mon Sep 17 00:00:00 2001 From: adeliktas <64136642+adeliktas@users.noreply.github.com> Date: Sat, 13 Nov 2021 20:49:26 +0100 Subject: [PATCH 05/11] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 23303f3..7f48a8d 100644 --- a/README.md +++ b/README.md @@ -53,3 +53,6 @@ By default the scrolling begins when the mouse pointer is 30 px below or above t Click the middle mouse button (or the button you assigned to `BUTTON_START`) and move your mouse to start scrolling. The further you move the mouse (vertically) from the point where you have clicked the button, the faster the scrolling becomes. To leave the scroll mode, simply press the middle mouse button again (or press the button you assigned to `BUTTON_STOP`). Note that at slow speed the scrolling is not smooth and (probably) there is no way to make it smooth. However, one can easily get used to it. + +##Todo +-improve scroll smoothness From 90befd38544f966659d16c01ef63667d20e4954f Mon Sep 17 00:00:00 2001 From: adeliktas <64136642+adeliktas@users.noreply.github.com> Date: Sat, 13 Nov 2021 20:49:46 +0100 Subject: [PATCH 06/11] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7f48a8d..80d7bbd 100644 --- a/README.md +++ b/README.md @@ -54,5 +54,6 @@ Click the middle mouse button (or the button you assigned to `BUTTON_START`) and Note that at slow speed the scrolling is not smooth and (probably) there is no way to make it smooth. However, one can easily get used to it. -##Todo +## Todo + -improve scroll smoothness From 7a0a6468ac6776f184f6c2bb57d2f55b43fa614f Mon Sep 17 00:00:00 2001 From: adeliktas <64136642+adeliktas@users.noreply.github.com> Date: Sat, 13 Nov 2021 20:59:29 +0100 Subject: [PATCH 07/11] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 80d7bbd..015a14d 100644 --- a/README.md +++ b/README.md @@ -57,3 +57,4 @@ Note that at slow speed the scrolling is not smooth and (probably) there is no w ## Todo -improve scroll smoothness +-fix losing window title bar control handle From 0dbf5d0d06295eab98352978b18a0054b424eb70 Mon Sep 17 00:00:00 2001 From: adeliktas <64136642+adeliktas@users.noreply.github.com> Date: Fri, 3 Dec 2021 19:52:23 +0100 Subject: [PATCH 08/11] small hotfix cpu usage, clip clear on middle mouse small hotfix cpu usage, clip clear on middle mouse --- autoscroll.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/autoscroll.py b/autoscroll.py index 47e5d15..d199e07 100644 --- a/autoscroll.py +++ b/autoscroll.py @@ -24,7 +24,7 @@ def start(self): self.listener.start() class Autoscrollsymbol(QtWidgets.QWidget): - + def __init__(self, parent=None, windowSize=0, penWidth=0): QtWidgets.QWidget.__init__(self, parent) self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint | QtCore.Qt.WindowTransparentForInput | QtCore.Qt.Tool) @@ -32,17 +32,17 @@ def __init__(self, parent=None, windowSize=0, penWidth=0): self.setAttribute(QtCore.Qt.WA_TranslucentBackground) self.setGeometry(xpos, ypos, 50, 50) self.pen = QtGui.QPen(QtGui.QColor(0,255,0,255)) - self.pen.setWidth(penWidth) + self.pen.setWidth(penWidth) self.mouse_listener = QMouseListener(self) self.mouse_listener.mouse_moved.connect(self.on_move) self.mouse_listener.mouse_clicked.connect(self.on_click) self.mouse_listener.start() - self.scroll_mode = 0 + self.scroll_mode = 0 self.mouse = Controller() self.pos = self.mouse.position self.direction = 0 self.interval = 0 - + # modify this to adjust the speed of scrolling self.DELAY = 5 # modify this to change the button used for using scroll mode @@ -55,7 +55,7 @@ def __init__(self, parent=None, windowSize=0, penWidth=0): self.Timestart = 0 self.Timeend = 0 self.Timedelta = 0 - + self.autoscroll() def on_move(self, x, y): @@ -85,7 +85,6 @@ def clearclip(self): def on_click(self, x, y, button, pressed): if button == self.BUTTON_Scroll and pressed and not self.scroll_mode: - self.clearclip() self.setWindowOpacity(1.0) self.pos = (x, y) self.direction = 0 @@ -99,10 +98,12 @@ def on_click(self, x, y, button, pressed): self.scroll_mode = 0 self.setWindowOpacity(0.0) elif (button == self.BUTTON_Scroll or button==Button.left) and pressed and self.scroll_mode: - self.clearclip() self.scroll_mode = 0 self.setWindowOpacity(0.0) - + + if (button == Button.middle) and pressed: + self.clearclip() + def paintEvent(self, event): painter = QtGui.QPainter(self) pen = QtGui.QPen(QtCore.Qt.green, 2, QtCore.Qt.SolidLine) @@ -112,22 +113,22 @@ def paintEvent(self, event): painter.drawLine(0, int(crosssizepx/2), crosssizepx, int(crosssizepx/2))#- painter.drawLine(int(crosssizepx/2), 0, int(crosssizepx/2), crosssizepx)#| self.setWindowOpacity(0.0) - + def scrolldown(self): if self.scroll_mode: time.sleep(self.interval) self.mouse.scroll(0, self.direction) - + def autoscroll(self): self.timer = QTimer(self) self.timer.timeout.connect(self.scrolldown) - self.timer.start(0) - + self.timer.start(1) + def mouselistener(self): self.listener=Listener(on_move=self.on_move) self.listener.start() -app = QtWidgets.QApplication(sys.argv) +app = QtWidgets.QApplication(sys.argv) widget = Autoscrollsymbol(windowSize=1, penWidth=10) widget.show() sys.exit(app.exec_()) From 07417b44f25293b5b337064fac6de177c755111c Mon Sep 17 00:00:00 2001 From: adeliktas <64136642+adeliktas@users.noreply.github.com> Date: Sat, 4 Dec 2021 16:47:39 +0100 Subject: [PATCH 09/11] time.sleep replaced with QTimer --- autoscroll.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/autoscroll.py b/autoscroll.py index d199e07..2a626b5 100644 --- a/autoscroll.py +++ b/autoscroll.py @@ -24,7 +24,8 @@ def start(self): self.listener.start() class Autoscrollsymbol(QtWidgets.QWidget): - +#create a timer with set interval, connect timeout to scroll function and +#then you can replace scroll_mode = 1 with timer.start() and scroll_mode = 0 with timer.stop() def __init__(self, parent=None, windowSize=0, penWidth=0): QtWidgets.QWidget.__init__(self, parent) self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint | QtCore.Qt.WindowTransparentForInput | QtCore.Qt.Tool) @@ -41,14 +42,13 @@ def __init__(self, parent=None, windowSize=0, penWidth=0): self.mouse = Controller() self.pos = self.mouse.position self.direction = 0 - self.interval = 0 # modify this to adjust the speed of scrolling - self.DELAY = 5 + self.DELAY = 3000 # modify this to change the button used for using scroll mode self.BUTTON_Scroll = Button.middle # modify this to change the size (in px) of the area below and above the starting point where the scrolling is paused - self.DEAD_AREA = 10 + self.DEAD_AREA = 20 #Trigger Delay 250ms to avoid instant changes self.Triggerdelay = 0.25 @@ -67,10 +67,10 @@ def on_move(self, x, y): self.direction = 1 elif delta < 0: self.direction = -1 - if abs(delta) <= self.DEAD_AREA + self.DELAY * 2: - self.interval = 0.5 + if abs(delta) <= self.DEAD_AREA: + self.timer.setInterval(500) else: - self.interval = self.DELAY / (abs(delta) - self.DEAD_AREA) + self.timer.setInterval(int(self.DELAY / (abs(delta) - self.DEAD_AREA))) if not self.scroll_mode: self.move(x -int(crosssizepx/2),y -int(crosssizepx/2)) @@ -88,17 +88,20 @@ def on_click(self, x, y, button, pressed): self.setWindowOpacity(1.0) self.pos = (x, y) self.direction = 0 - self.interval = 0 + self.timer.setInterval(100) self.scroll_mode = 1 + self.timer.start() self.Timestart = time.time() elif button == self.BUTTON_Scroll and not pressed and self.scroll_mode: self.Timeend = time.time() self.Timedelta = self.Timeend - self.Timestart if self.Timedelta>self.Triggerdelay: self.scroll_mode = 0 + self.timer.stop() self.setWindowOpacity(0.0) elif (button == self.BUTTON_Scroll or button==Button.left) and pressed and self.scroll_mode: self.scroll_mode = 0 + self.timer.stop() self.setWindowOpacity(0.0) if (button == Button.middle) and pressed: @@ -113,16 +116,15 @@ def paintEvent(self, event): painter.drawLine(0, int(crosssizepx/2), crosssizepx, int(crosssizepx/2))#- painter.drawLine(int(crosssizepx/2), 0, int(crosssizepx/2), crosssizepx)#| self.setWindowOpacity(0.0) - + def scrolldown(self): - if self.scroll_mode: - time.sleep(self.interval) - self.mouse.scroll(0, self.direction) + self.mouse.scroll(0, self.direction) def autoscroll(self): self.timer = QTimer(self) + self.timer.setInterval(100) self.timer.timeout.connect(self.scrolldown) - self.timer.start(1) + self.timer.start() def mouselistener(self): self.listener=Listener(on_move=self.on_move) From f9a3e81068e74d00efcec348c5fb6a775908db43 Mon Sep 17 00:00:00 2001 From: adeliktas <64136642+adeliktas@users.noreply.github.com> Date: Sat, 4 Dec 2021 16:49:37 +0100 Subject: [PATCH 10/11] Update autoscroll.py --- autoscroll.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/autoscroll.py b/autoscroll.py index 2a626b5..1c92032 100644 --- a/autoscroll.py +++ b/autoscroll.py @@ -24,8 +24,6 @@ def start(self): self.listener.start() class Autoscrollsymbol(QtWidgets.QWidget): -#create a timer with set interval, connect timeout to scroll function and -#then you can replace scroll_mode = 1 with timer.start() and scroll_mode = 0 with timer.stop() def __init__(self, parent=None, windowSize=0, penWidth=0): QtWidgets.QWidget.__init__(self, parent) self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint | QtCore.Qt.WindowTransparentForInput | QtCore.Qt.Tool) From 29257d1997f6b32f50c1f0ad195f2e21145ed050 Mon Sep 17 00:00:00 2001 From: adeliktas Date: Sat, 25 Dec 2021 16:26:44 +0100 Subject: [PATCH 11/11] minor improvement variable abs redundancy --- autoscroll.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/autoscroll.py b/autoscroll.py index 1c92032..41896b2 100644 --- a/autoscroll.py +++ b/autoscroll.py @@ -59,16 +59,17 @@ def __init__(self, parent=None, windowSize=0, penWidth=0): def on_move(self, x, y): if self.scroll_mode: delta = self.pos[1] - y - if abs(delta) <= self.DEAD_AREA: + absdelta = abs(delta) + if absdelta <= self.DEAD_AREA: self.direction = 0 elif delta > 0: self.direction = 1 elif delta < 0: self.direction = -1 - if abs(delta) <= self.DEAD_AREA: + if absdelta <= self.DEAD_AREA: self.timer.setInterval(500) else: - self.timer.setInterval(int(self.DELAY / (abs(delta) - self.DEAD_AREA))) + self.timer.setInterval(int(self.DELAY / (absdelta - self.DEAD_AREA))) if not self.scroll_mode: self.move(x -int(crosssizepx/2),y -int(crosssizepx/2))