Browse Source

update template

master
Nils 4 years ago
parent
commit
d51c4b127e
  1. 10
      template/qtgui/helper.py
  2. 13
      template/qtgui/mainwindow.py

10
template/qtgui/helper.py

@ -21,9 +21,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging; logger = logging.getLogger(__name__); logger.info("import") import logging; logger = logging.getLogger(__name__); logger.info("import")
from PyQt5 import QtGui, QtWidgets from PyQt5 import QtCore, QtGui, QtWidgets
from hashlib import md5 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): def stringToColor(st):
"""Convert a string to QColor. Same string, same color """Convert a string to QColor. Same string, same color
Is used for group coloring""" Is used for group coloring"""

13
template/qtgui/mainwindow.py

@ -71,6 +71,7 @@ class EventLoop(object):
self.fastLoop = QtCore.QTimer() self.fastLoop = QtCore.QTimer()
self.slowLoop = QtCore.QTimer() self.slowLoop = QtCore.QTimer()
self.verySlowLoop = QtCore.QTimer()
def fastConnect(self, function): def fastConnect(self, function):
self.fastLoop.timeout.connect(function) self.fastLoop.timeout.connect(function)
@ -78,6 +79,9 @@ class EventLoop(object):
def slowConnect(self, function): def slowConnect(self, function):
self.slowLoop.timeout.connect(function) self.slowLoop.timeout.connect(function)
def verySlowConnect(self, function):
self.verySlowLoop.timeout.connect(function)
def fastDisconnect(self, function): def fastDisconnect(self, function):
"""The function must be the exact instance that was registered""" """The function must be the exact instance that was registered"""
self.fastLoop.timeout.disconnect(function) self.fastLoop.timeout.disconnect(function)
@ -86,18 +90,27 @@ class EventLoop(object):
"""The function must be the exact instance that was registered""" """The function must be the exact instance that was registered"""
self.slowLoop.timeout.disconnect(function) 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): def start(self):
"""The event loop MUST be started after the Qt Application instance creation""" """The event loop MUST be started after the Qt Application instance creation"""
logger.info("Starting fast qt event loop") logger.info("Starting fast qt event loop")
self.fastLoop.start(20) self.fastLoop.start(20)
logger.info("Starting slow qt event loop") logger.info("Starting slow qt event loop")
self.slowLoop.start(100) self.slowLoop.start(100)
logger.info("Starting very slow qt event loop")
self.verySlowLoop.start(200)
def stop(self): def stop(self):
logger.info("Stopping fast qt event loop") logger.info("Stopping fast qt event loop")
self.fastLoop.stop() self.fastLoop.stop()
logger.info("Stopping slow qt event loop") logger.info("Stopping slow qt event loop")
self.slowLoop.stop() self.slowLoop.stop()
logger.info("Stopping very slow qt event loop")
self.verySlowLoop.stop()
api.session.eventLoop = EventLoop() api.session.eventLoop = EventLoop()
#QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_DontUseNativeMenuBar) #Force a real menu bar. Qt on wayland will not display it otherwise. #QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_DontUseNativeMenuBar) #Force a real menu bar. Qt on wayland will not display it otherwise.

Loading…
Cancel
Save