Skip to content

Commit

Permalink
Merge pull request #370 from davidlatwe/instance_comment
Browse files Browse the repository at this point in the history
Instance comment
  • Loading branch information
davidlatwe authored Nov 16, 2021
2 parents 507bb41 + 1f870bb commit 103fef8
Show file tree
Hide file tree
Showing 15 changed files with 229 additions and 49 deletions.
71 changes: 48 additions & 23 deletions pyblish_qml/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class Controller(QtCore.QObject):
saved = QtCore.Signal()
finished = QtCore.Signal()
initialised = QtCore.Signal()
commented = QtCore.Signal()
commenting = QtCore.Signal(str, arguments=["comment"])
commented = QtCore.Signal(str, arguments=["name"])
commenting = QtCore.Signal(str, str, arguments=["comment", "name"])

state_changed = QtCore.Signal(str, arguments=["state"])

Expand Down Expand Up @@ -75,6 +75,7 @@ def __init__(self, host, parent=None, targets=None):
"result": models.ResultModel(),
},
"comment": "",
"instancesComment": dict(),
"firstRun": True,
}

Expand Down Expand Up @@ -293,19 +294,18 @@ def setup_statemachine(self):
machine.start()
return machine

@QtCore.Slot(result=str)
def comment(self):
@QtCore.Slot(str, result=str)
def comment(self, name):
"""Return first line of comment"""
return self.data["comment"]
if name == "Context":
return self.data["comment"]
else:
return self.data["instancesComment"].get(name, "")

@QtCore.Property(str, notify=state_changed)
def state(self):
return self.data["state"]["current"]

@QtCore.Property(bool, notify=commented)
def hasComment(self):
return True if self.data["comment"] else False

@QtCore.Property(bool, constant=True)
def commentEnabled(self):
return "comment" in self.host.cached_context.data
Expand Down Expand Up @@ -665,10 +665,17 @@ def echo(self, data):
"""Append `data` to result model"""
self.data["models"]["result"].add_item(data)

def comment_sync(self, comment):
def comment_sync(self, comment, item):
"""Update comments to host and notify subscribers"""
self.host.update(key="comment", value=comment)
self.host.emit("commented", comment=comment)
name = item.name
model_item = self.data["models"]["item"].instances[item.id]
model_item.hasComment = bool(comment)

self.host.update(key="comment", value=comment, name=name)
if name == "Context":
self.host.emit("commented", comment=comment)
else:
self.host.emit("instanceCommented", comment=comment, name=name)

def is_ready(self):
count = self.data["state"]["readyCount"]
Expand All @@ -677,18 +684,26 @@ def is_ready(self):

# Event handlers

def on_commenting(self, comment):
def on_commenting(self, comment, name):
"""The user is entering a comment"""

def update():
context = self.host.cached_context
context.data["comment"] = comment
self.data["comment"] = comment

# Notify subscribers of the comment
self.comment_sync(comment)
if name == "Context":
context.data["comment"] = comment
self.data["comment"] = comment
item = context

self.commented.emit()
else:
instance = next(it for it in context if name == it.name)
instance.data["comment"] = comment
self.data["instancesComment"][name] = comment
item = instance

# Notify subscribers of the comment
self.comment_sync(comment, item)
self.commented.emit(name)

# Update local cache a little later
util.schedule(update, 100, channel="commenting")
Expand Down Expand Up @@ -815,17 +830,27 @@ def on_finished(plugins, context):
self.data["models"]["item"].update_compatibility()

# Remember comment across resets
#
comment = self.data["comment"]
if comment:
instances_com = self.data["instancesComment"]
ch_context = self.host.cached_context

if comment or instances_com:
print("Installing local comment..")
self.host.cached_context.data["comment"] = comment
ch_context.data["comment"] = comment
for ch_it in ch_context:
ch_it.data["comment"] = instances_com.get(ch_it.name, "")
else:
print("No local comment, reading from context..")
comment = self.host.cached_context.data.get("comment", "")
self.data["comment"] = comment
self.data["comment"] = ch_context.data.get("comment", "")
for ch_it in ch_context:
instances_com[ch_it.name] = ch_it.data.get("comment", "")

# Notify subscribers of the comment
self.comment_sync(comment)
self.comment_sync(comment, ch_context)
for ch_it in ch_context:
ch_it_com = instances_com.get(ch_it.name, "")
self.comment_sync(ch_it_com, ch_it)

first_run = self.data["firstRun"]
if first_run:
Expand Down
4 changes: 2 additions & 2 deletions pyblish_qml/ipc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def discover(self):
def emit(self, signal, **kwargs):
self._dispatch("emit", args=[signal, kwargs])

def update(self, key, value):
self._dispatch("update", args=[key, value])
def update(self, key, value, name):
self._dispatch("update", args=[key, value, name])

def _self_destruct(self):
"""Auto quit exec if parent process failed
Expand Down
9 changes: 7 additions & 2 deletions pyblish_qml/ipc/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,14 @@ def emit(self, signal, kwargs):

pyblish.api.emit(signal, **kwargs)

def update(self, key, value):
def update(self, key, value, name):
"""Write data to context from GUI"""
self._context.data[key] = value
context = self._context
if name == "Context":
context.data[key] = value
else:
instance = next(it for it in context if name == it.name)
instance.data[key] = value


class MockService(Service):
Expand Down
1 change: 1 addition & 0 deletions pyblish_qml/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"category": None,
"niceName": "default",
"compatiblePlugins": list(),
"hasComment": False,
},
"result": {
"type": "default",
Expand Down
3 changes: 2 additions & 1 deletion pyblish_qml/qml/Footer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ View {
// 0 = Default; 1 = Publishing; 2 = Finished
property int mode: 0
property bool paused: false
property bool hasComment: false

signal publish
signal validate
Expand Down Expand Up @@ -47,7 +48,7 @@ View {

tooltip: visible ? "Comment.." : ""

name: app.hasComment ? "comment" : "comment-o"
name: hasComment ? "comment" : "comment-o"
onClicked: footer.comment()
visible: mode == 0 ? true : false
}
Expand Down
8 changes: 8 additions & 0 deletions pyblish_qml/qml/List.qml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ ListView {
: Theme.dark.successColor
},

Action {
name: "comment"
iconName: object.hasComment ? "comment" : "comment-o"
iconSize: 12
enabled: object.itemType == "instance" ? true : false
onTriggered: actionTriggered(this, index)
},

Action {
name: "enter"
iconName: "angle-right"
Expand Down
22 changes: 19 additions & 3 deletions pyblish_qml/qml/Overview.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Item {

property bool validated: false

signal commentEntered(int index)
signal instanceEntered(int index)
signal pluginEntered(int index)

Expand Down Expand Up @@ -45,6 +46,11 @@ Item {
footer.message.animation.start()
}

function setComment(text) {
app.commenting(text, "Context")
footer.hasComment = text ? true : false
}

TabBar {
id: tabBar

Expand Down Expand Up @@ -106,6 +112,8 @@ Item {
app.repairInstance(index)
else if (action.name == "enter")
overview.instanceEntered(index)
else if (action.name == "comment")
overview.commentEntered(index)
}

onItemToggled: app.toggleInstance(index)
Expand Down Expand Up @@ -197,10 +205,12 @@ Item {
bottom: footer.top
left: parent.left
right: parent.right
top: (isMaximised && height == parent.height - footer.height) ? tabBar.top : undefined
top: undefined
}

height: isMaximised ? parent.height - footer.height : isUp ? 150 : 0
height: isUp ? 150 : 0

onCommentChanged: setComment(text)
}

Footer {
Expand Down Expand Up @@ -229,7 +239,13 @@ Item {

onFirstRun: {
app.commentEnabled ? commentBox.up() : null
commentBox.text = app.comment()
commentBox.text = app.comment("Context")
}

onCommented: {
if (name == "Context") {
commentBox.text = app.comment(name)
}
}

onStateChanged: {
Expand Down
49 changes: 49 additions & 0 deletions pyblish_qml/qml/Perspective/Footer.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import QtQuick 2.3
import Pyblish 0.1


View {
id: footer

property alias message: __message

// 0 = Default; 1 = Publishing; 2 = Finished
property int mode: 0
property bool hasComment: false

signal comment

width: 200
height: 40

Message {
id: __message
anchors.verticalCenter: parent.verticalCenter
}

Row {
id: row

anchors {
right: parent.right
top: parent.top
bottom: parent.bottom
margins: 5
}

spacing: 3

AwesomeButton {
elevation: 1

size: 25
iconSize: 14

tooltip: visible ? "Comment.." : ""

name: hasComment ? "comment" : "comment-o"
onClicked: footer.comment()
visible: mode == 0 ? true : false
}
}
}
Loading

0 comments on commit 103fef8

Please sign in to comment.