From f42ff06ce89fcdbf35d09a1b2f03f599767c50b7 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Thu, 28 Oct 2021 09:40:40 +0200 Subject: [PATCH] use wheel + ctrl to change font size --- bigtext.py | 9 +++++++-- scribble.py | 53 +++++++++++++++++++++++++++++++++++++++++------------ settings.py | 8 ++++++-- 3 files changed, 54 insertions(+), 16 deletions(-) diff --git a/bigtext.py b/bigtext.py index 8059708..aa41266 100644 --- a/bigtext.py +++ b/bigtext.py @@ -148,8 +148,13 @@ class InnerBigText(QWidget): def wheelEvent(self, event: QWheelEvent): direction = 1 if event.angleDelta().y() < 0 else -1 - # print("wheel event fired :) %s" % (direction)) - self.scroll_by_lines(direction * 3) + if event.modifiers() == Qt.KeyboardModifier.ControlModifier: + font_size = min(max(4, self.model.settings.get_font_size()-direction),30) + self.model.settings.font_size(font_size) + self.update() + else: + # print("wheel event fired :) %s" % (direction)) + self.scroll_by_lines(direction * 3) def scroll_by_lines(self, scroll_lines: int): self.scroll_lines = scroll_lines diff --git a/scribble.py b/scribble.py index 83e219f..5d9e892 100644 --- a/scribble.py +++ b/scribble.py @@ -1,15 +1,44 @@ -import math + +import multiprocessing +import time + +from multiprocessing import Pool + +file = "/tmp/tmp123123" + +from concurrent.futures import ThreadPoolExecutor +from time import sleep + +def writer(): + with open(file, "w+b") as f: + for i in range(0, 10): + f.write(("%s"%(i)).encode("utf8")) + time.sleep(0.5) + print("writing ", time.time()) + +def reader(): + with open(file, "rb") as f: + for i in range(0,10): + + lines = f.readlines() + time.sleep(0.5) + print("read ", time.time()) + +pool = Pool(5) + +with pool as p: + p.apply_async(writer) + p.apply_async(reader) + +pool.join() + + +executor = ThreadPoolExecutor(2) +future1 = executor.submit(writer) +future2 = executor.submit(reader) + +print(future1.result()) +print(future2.result()) -before = []#[0,1,2,3] -after = ["a","b","c","d"] -both = before + after -scroll = -3 -lines = 1 -start = len(before) + scroll -if start+lines < len(both): - result = both[start:start+lines] -else: - result = both[-lines:] -print("%s" % result) diff --git a/settings.py b/settings.py index 6ad8f2e..78ebd9d 100644 --- a/settings.py +++ b/settings.py @@ -1,9 +1,12 @@ +from typing import Callable + from PyQt6.QtGui import QFont class Settings(): - def __init__(self): + def __init__(self, callback_update_ui: Callable[[], None]): + self.callback_update_ui = callback_update_ui self.font_size(12) @staticmethod @@ -18,4 +21,5 @@ class Settings(): def font_size(self, font_size: int): self._font_size = font_size - self._font = QFont("monospace", font_size) \ No newline at end of file + self._font = QFont("monospace", font_size) + self.callback_update_ui() \ No newline at end of file