Source code for mesycontrol.gui_tutorial
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# mesycontrol - Remote control for mesytec devices.
# Copyright (C) 2015-2016 mesytec GmbH & Co. KG <info@mesytec.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
__author__ = 'Florian Lüke'
__email__ = 'f.lueke@mesytec.com'
from qt import pyqtSignal
from qt import QtCore
from qt import QtGui
import weakref
[docs]class UIFlasher(QtCore.QObject):
def __init__(self, widget, flashcount=10, interval_ms=500, autostart=False, parent=None):
super(UIFlasher, self).__init__(parent)
self.flashcount = flashcount
self.interval = interval_ms
self.timer = QtCore.QTimer(self, timeout=self._do_flash)
self.flash_on = False
self.widget = None
self.set_widget(widget, autostart)
[docs] def start(self):
self._current_flashcount = self.flashcount
self.timer.start(self.interval)
self._do_flash()
[docs] def stop(self):
self.timer.stop()
if self.flash_on and self.widget and self.widget():
self.widget().setStyleSheet('')
def _do_flash(self):
if self._current_flashcount <= 0 or not self.widget or not self.widget():
return
style = '' if self.flash_on else 'background: yellow;'
self.widget().setStyleSheet(style)
if self.flash_on:
self._current_flashcount -= 1
self.flash_on = not self.flash_on
if self._current_flashcount <= 0:
self.stop()
[docs]class TutorialTextBrowser(QtGui.QTextBrowser):
href_hover = pyqtSignal(str)
def __init__(self, parent=None, **kwargs):
super(TutorialTextBrowser, self).__init__(parent=parent, **kwargs)
self.setMouseTracking(True)
[docs] def mouseMoveEvent(self, event):
pos = event.pos()
cursor = self.cursorForPosition(pos)
cursor.select(QtGui.QTextCursor.WordUnderCursor)
fmt = cursor.charFormat()
self.href_hover.emit(str(fmt.anchorHref()) if fmt.isAnchor() else str())
super(TutorialTextBrowser, self).mouseMoveEvent(event)