From 843b0b72478ba005991f193a281f668f74b49c3f Mon Sep 17 00:00:00 2001 From: Nils <> Date: Sat, 27 Jun 2020 00:45:16 +0200 Subject: [PATCH] update template --- template/qtgui/helper.py | 10 +++++++++- template/qtgui/mainwindow.py | 13 +++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/template/qtgui/helper.py b/template/qtgui/helper.py index f4fc1f9..f04e227 100644 --- a/template/qtgui/helper.py +++ b/template/qtgui/helper.py @@ -21,9 +21,17 @@ along with this program. If not, see . import logging; logger = logging.getLogger(__name__); logger.info("import") -from PyQt5 import QtGui, QtWidgets +from PyQt5 import QtCore, QtGui, QtWidgets + from hashlib import md5 + +def iconFromString(st, size=128): + px = QtGui.QPixmap(size,size) + color = stringToColor(st) + px.fill(color) + return QtGui.QIcon(px) + def stringToColor(st): """Convert a string to QColor. Same string, same color Is used for group coloring""" diff --git a/template/qtgui/mainwindow.py b/template/qtgui/mainwindow.py index 7d24185..da4a37e 100644 --- a/template/qtgui/mainwindow.py +++ b/template/qtgui/mainwindow.py @@ -71,6 +71,7 @@ class EventLoop(object): self.fastLoop = QtCore.QTimer() self.slowLoop = QtCore.QTimer() + self.verySlowLoop = QtCore.QTimer() def fastConnect(self, function): self.fastLoop.timeout.connect(function) @@ -78,6 +79,9 @@ class EventLoop(object): def slowConnect(self, function): self.slowLoop.timeout.connect(function) + def verySlowConnect(self, function): + self.verySlowLoop.timeout.connect(function) + def fastDisconnect(self, function): """The function must be the exact instance that was registered""" self.fastLoop.timeout.disconnect(function) @@ -86,18 +90,27 @@ class EventLoop(object): """The function must be the exact instance that was registered""" self.slowLoop.timeout.disconnect(function) + def verySlowDisconnect(self, function): + """The function must be the exact instance that was registered""" + self.verySlowLoop.timeout.disconnect(function) + + def start(self): """The event loop MUST be started after the Qt Application instance creation""" logger.info("Starting fast qt event loop") self.fastLoop.start(20) logger.info("Starting slow qt event loop") self.slowLoop.start(100) + logger.info("Starting very slow qt event loop") + self.verySlowLoop.start(200) def stop(self): logger.info("Stopping fast qt event loop") self.fastLoop.stop() logger.info("Stopping slow qt event loop") self.slowLoop.stop() + logger.info("Stopping very slow qt event loop") + self.verySlowLoop.stop() api.session.eventLoop = EventLoop() #QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_DontUseNativeMenuBar) #Force a real menu bar. Qt on wayland will not display it otherwise.