From 083849161f075878e4175cd03cb7afa83d64e7f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Thu, 6 Jul 2017 22:55:08 +0200 Subject: New upstream version 0.9.0 --- raphodo/messagewidget.py | 108 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 raphodo/messagewidget.py (limited to 'raphodo/messagewidget.py') diff --git a/raphodo/messagewidget.py b/raphodo/messagewidget.py new file mode 100644 index 0000000..b76ab40 --- /dev/null +++ b/raphodo/messagewidget.py @@ -0,0 +1,108 @@ +# Copyright (C) 2017 Damon Lynch + +# This file is part of Rapid Photo Downloader. +# +# Rapid Photo Downloader 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 3 of the License, or +# (at your option) any later version. +# +# Rapid Photo Downloader 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 Rapid Photo Downloader. If not, +# see . + +""" +Display messages to the user in stacked widget +""" + +__author__ = 'Damon Lynch' +__copyright__ = "Copyright 2017, Damon Lynch" + +from typing import Tuple +from gettext import gettext as _ + +from PyQt5.QtCore import (Qt, pyqtSlot, pyqtSignal) +from PyQt5.QtWidgets import (QSizePolicy, QStackedWidget, QPushButton, QLabel) +from PyQt5.QtGui import (QMouseEvent, QFocusEvent) + + +class MessageWidget(QStackedWidget): + """ + Display messages to the user in stacked widget. + + Index 0 always represents a blank state. + + Other indexes represent the position in the + tuple of messages. + + If the message does not start with an html tag or , + the start of the message will be modified to display Hint: + (with closing tags too, naturally). + """ + + def __init__(self, messages: Tuple[str,...], parent=None) -> None: + super().__init__(parent) + + # For some obscure reason, must set the label types for all labels in the stacked + # widget to have the same properties, or else the stacked layout size goes bonkers. + # Must make the empty label contain *something*, too, so make it contain a space. + blank = QLabel(' ') + blank.setWordWrap(True) + blank.setTextFormat(Qt.RichText) + self.addWidget(blank) + + for message in messages: + if message.startswith('') or message.startswith(''): + label = QLabel(message) + else: + # Translators: please do not modify or leave out html formatting tags like and + # . These are used to format the text the users sees + label = QLabel(_("Hint: %(message)s") % dict(message=message)) + label.setWordWrap(True) + label.setTextFormat(Qt.RichText) + label.setAlignment(Qt.AlignTop|Qt.AlignLeft) + self.addWidget(label) + + self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum) + + +class MessageButton(QPushButton): + """ + A simple QPushButton that emits a signal when it is entered / exited. + """ + + isActive = pyqtSignal() + isInactive = pyqtSignal() + + def __init__(self, label: str, parent=None) -> None: + super().__init__(label, parent) + + @pyqtSlot(QMouseEvent) + def enterEvent(self, event: QMouseEvent) -> None: + self.isActive.emit() + super().enterEvent(event) + + @pyqtSlot(QMouseEvent) + def leaveEvent(self, event: QMouseEvent) -> None: + self.isInactive.emit() + super().leaveEvent(event) + + @pyqtSlot(QFocusEvent) + def focusInEvent(self, event: QFocusEvent) -> None: + self.isActive.emit() + super().focusInEvent(event) + + @pyqtSlot(QFocusEvent) + def focusOutEvent(self, event: QFocusEvent) -> None: + self.isInactive.emit() + super().focusOutEvent(event) + + + + + -- cgit v1.2.3