-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[ui] Status messages interface #2891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import json | ||
| from PySide6.QtCore import QObject | ||
| from datetime import datetime | ||
| from meshroom.common import Signal, Slot, Property | ||
|
|
||
|
|
||
| class Message: | ||
| def __init__(self, msg, status=None): | ||
| self.msg = msg | ||
| self.status = status or "info" | ||
| self.date = datetime.now() | ||
|
|
||
| def dateStr(self, fullDate=False): | ||
| dateFormat = "%H:%M:%S" | ||
| if fullDate: | ||
| dateFormat = "%Y-%m-%d %H:%M:%S.%f" | ||
| return self.date.strftime(dateFormat) | ||
|
|
||
|
|
||
| class MessageController(QObject): | ||
| """ | ||
| Handles messages sent from the Python side to the StatusBar component | ||
| """ | ||
|
|
||
| message = Signal(str, str, int) | ||
| messagesChanged = Signal() # Signal to notify when messages list changes | ||
|
|
||
| def __init__(self, parent): | ||
| super().__init__(parent) | ||
| self._messages = [] | ||
|
|
||
| def sendMessage(self, msg, status, duration): | ||
| """ Sends a message that will be displayed on the status bar """ | ||
| self.message.emit(msg, status, duration) | ||
|
|
||
| @Slot(str, str) | ||
| def storeMessage(self, msg, status): | ||
| """ Adds a new message in the stack """ | ||
| self._messages.append(Message(msg, status or "info")) | ||
| self.messagesChanged.emit() # Notify QML that messages have changed | ||
|
|
||
| def _getMessagesDict(self, fullDate=False): | ||
| """ Get a dict with all stored messages """ | ||
| messages = [] | ||
| for msg in self._messages: | ||
| messages.append({ | ||
| "status": msg.status, | ||
| "date": msg.dateStr(fullDate), | ||
| "text": msg.msg, | ||
| }) | ||
| return messages | ||
|
|
||
| def getMessages(self): | ||
| """ Get the messages with simple date infos. | ||
| Reverse the list to make sure we see the most recent item on top | ||
| """ | ||
| return self._getMessagesDict()[::-1] | ||
|
|
||
| @Slot(result=str) | ||
| def getMessagesAsString(self): | ||
| """ Return messages for clipboard copy | ||
| .. note:: | ||
| Could also do `json.dumps(self._getMessagesDict(fullDate=True), indent=4)` | ||
| """ | ||
| messages = [] | ||
| for msg in self._messages: | ||
| messages.append(f"{msg.dateStr(True)} [{msg.status.upper():<7}] {msg.msg}") | ||
| return "\n".join(messages) | ||
|
|
||
| @Slot() | ||
| def clearMessages(self): | ||
| """ Clear all stored messages """ | ||
| self._messages.clear() | ||
| self.messagesChanged.emit() | ||
|
|
||
| # Property to expose messages to QML | ||
| messages = Property("QVariantList", getMessages, notify=messagesChanged) |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| import QtQuick | ||
| import QtQuick.Controls | ||
| import QtQuick.Layouts | ||
|
|
||
| import MaterialIcons 2.2 | ||
| import Utils 1.0 | ||
|
|
||
| ApplicationWindow { | ||
| id: root | ||
| title: "Messages" | ||
| width: 500 | ||
| height: 400 | ||
| minimumWidth: 350 | ||
| minimumHeight: 250 | ||
|
|
||
| SystemPalette { id: systemPalette } | ||
|
|
||
| function getColor(status) { | ||
| switch (status) { | ||
| case "ok": return Colors.green | ||
| case "warning": return Colors.orange | ||
| case "error": return Colors.red | ||
| default: return systemPalette.text | ||
| } | ||
| } | ||
|
|
||
| function getBackgroundColor(status) { | ||
| var color = getColor(status) | ||
| var alphaValue = status == "info" ? 0.05 : 0.1 | ||
| return Qt.rgba(color.r, color.g, color.b, alphaValue) | ||
| } | ||
|
|
||
| function getBorderColor(status) { | ||
| var color = getColor(status) | ||
| var alphaValue = status == "info" ? 0.2 : 0.3 | ||
| return Qt.rgba(color.r, color.g, color.b, alphaValue) | ||
| } | ||
|
|
||
| function getStatusIcon(status) { | ||
| switch (status) { | ||
| case "ok": return MaterialIcons.check_circle | ||
| case "warning": return MaterialIcons.warning | ||
| case "error": return MaterialIcons.error | ||
| default: return MaterialIcons.info | ||
| } | ||
| } | ||
|
|
||
| header: ToolBar { | ||
|
|
||
| background: Rectangle { | ||
| implicitWidth: root.width | ||
| implicitHeight: 50 | ||
| color: Qt.darker(systemPalette.base, 1.2) | ||
| } | ||
|
|
||
| RowLayout { | ||
| anchors.fill: parent | ||
|
|
||
| Text { | ||
| Layout.fillWidth: true | ||
| text: "Messages (" + messageListView.count + ")" | ||
| font.bold: true | ||
| color: Qt.darker(systemPalette.text, 1.2) | ||
| } | ||
|
|
||
| MaterialToolButton { | ||
| ToolTip.text: "Clear the message list" | ||
| text: MaterialIcons.clear_all | ||
| font.pointSize: 16 | ||
| palette.base: systemPalette.base | ||
| // Text color | ||
| Component.onCompleted: { | ||
| contentItem.color = Qt.darker(systemPalette.text, 1.2) | ||
| } | ||
| onClicked: _messageController.clearMessages() | ||
| } | ||
|
|
||
| MaterialToolButton { | ||
| ToolTip.text: "Copy the messages" | ||
| text: MaterialIcons.content_copy | ||
| font.pointSize: 16 | ||
| palette.base: systemPalette.base | ||
| // Text color | ||
| Component.onCompleted: { | ||
| contentItem.color = Qt.darker(systemPalette.text, 1.2) | ||
| } | ||
| onClicked: { | ||
| var msgDict = _messageController.getMessagesAsString() | ||
| if (msgDict !== '') { | ||
| Clipboard.clear() | ||
| Clipboard.setText(msgDict) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Rectangle { | ||
| anchors.fill: parent | ||
| color: systemPalette.base | ||
|
|
||
| ScrollView { | ||
| anchors.fill: parent | ||
| anchors.margins: 10 | ||
|
|
||
| ListView { | ||
| id: messageListView | ||
| model: _messageController.messages | ||
| verticalLayoutDirection: ListView.TopToBottom | ||
| spacing: 5 | ||
|
|
||
| delegate: Rectangle { | ||
| width: messageListView.width | ||
| height: messageLayout.implicitHeight + 16 | ||
| color: root.getBackgroundColor(modelData.status) | ||
| border.color: root.getBorderColor(modelData.status) | ||
| border.width: 1 | ||
| radius: 4 | ||
|
|
||
| RowLayout { | ||
| id: messageLayout | ||
| anchors.fill: parent | ||
| anchors.margins: 8 | ||
| spacing: 12 | ||
|
|
||
| // Icon | ||
| Text { | ||
| text: root.getStatusIcon(modelData.status) | ||
| font.pointSize: 14 | ||
| color: root.getColor(modelData.status) | ||
| Layout.alignment: Qt.AlignVCenter | ||
| } | ||
|
|
||
| // Text | ||
| RowLayout { | ||
| Layout.fillWidth: true | ||
| spacing: 8 | ||
|
|
||
| Text { | ||
| text: modelData.date | ||
| font.pointSize: 8 | ||
| color: Qt.darker(systemPalette.windowText, 1.5) | ||
| Layout.alignment: Qt.AlignLeft | ||
| } | ||
|
|
||
| Text { | ||
| text: modelData.text | ||
| wrapMode: Text.WordWrap | ||
| Layout.fillWidth: true | ||
| color: systemPalette.windowText | ||
| font.pointSize: 10 | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Empty state | ||
| Text { | ||
| anchors.centerIn: parent | ||
| text: "No message to display" | ||
| color: Qt.darker(systemPalette.windowText, 1.5) | ||
| font.pointSize: 12 | ||
| visible: messageListView.count === 0 | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.