summaryrefslogtreecommitdiff
path: root/raphodo/messagewidget.py
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2017-07-06 22:55:08 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2017-07-06 22:55:08 +0200
commit083849161f075878e4175cd03cb7afa83d64e7f5 (patch)
tree101feb02f6306f8f8b335faa39d74f1eaafc8d54 /raphodo/messagewidget.py
parentb5287ed17bda10877d84ba86fcf148ee74b93b9b (diff)
New upstream version 0.9.0upstream/0.9.0
Diffstat (limited to 'raphodo/messagewidget.py')
-rw-r--r--raphodo/messagewidget.py108
1 files changed, 108 insertions, 0 deletions
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 <damonlynch@gmail.com>
+
+# 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 <http://www.gnu.org/licenses/>.
+
+"""
+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 <i> or <b>,
+ the start of the message will be modified to display <i><b>Hint:</b>
+ (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('<i>') or message.startswith('<b>'):
+ label = QLabel(message)
+ else:
+ # Translators: please do not modify or leave out html formatting tags like <i> and
+ # <b>. These are used to format the text the users sees
+ label = QLabel(_("<i><b>Hint:</b> %(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)
+
+
+
+
+