Skip to content
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

Add Task Comments widget #4

Open
BigRoy opened this issue Dec 10, 2019 · 0 comments
Open

Add Task Comments widget #4

BigRoy opened this issue Dec 10, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@BigRoy
Copy link
Member

BigRoy commented Dec 10, 2019

Issue

Getting the comments for a Widget through gazu can be done. However qtazu does not expose any widget that allows to choose a Task and display the available comments.

This would be an amazingly helpful Widget as it would allow for Artists to avoid having to go to Kitsu to read up on the notes on their current scene but instead can have it right next to them in the DCC or pipeline.

Here's a very simple example, but this should be much prettier:

qtazu_task_comments

import datetime

from Qt import QtWidgets, QtCore, QtGui
import gazu

from qtazu.widgets import taskbreadcrumb


class TaskComments(QtWidgets.QWidget):
    def __init__(self, parent=None, task_id=None):
        super(TaskComments, self).__init__(parent)

        self._task = None

        breadcrumb = taskbreadcrumb.TaskBreadcrumb()
        comments = QtWidgets.QTextEdit()
        comments.setReadOnly(True)

        layout = QtWidgets.QVBoxLayout(self)
        layout.addWidget(breadcrumb)
        layout.addWidget(comments)

        self.breadcrumb = breadcrumb
        self.comments = comments

        self.setWindowTitle("CG-Wire Comments")

        self.resize(250, 600)

        if task_id:
            self.set_task(task_id)

    def set_task(self, task_id):

        # todo: Remove force to `str`
        task_id = str(task_id)


        self._task = gazu.task.get_task(task_id)

        self.comments.clear()

        comments = gazu.task.all_comments_for_task(task_id)
        text = ""
        for comment in comments:

            if not comment["text"]:
                # Exclude empty comments for quick readability?
                # todo: do we want to do this by default? we could add a toggle to widget
                continue

            # Include readable date in comment for parsing
            date = datetime.datetime.strptime(comment["created_at"], '%Y-%m-%dT%H:%M:%S')
            date = date.strftime('%Y-%m-%d %I:%M %p')
            comment["date"] = date

            # Ensure new lines in comment text are parsed
            comment["text"] = comment["text"].replace(r"\\n", "<br>")

            html_start = """
            <b>{person[first_name]} {person[last_name]}</b> | {date}<br>
            <br>""".format(**comment)

            html_end = """
            <br><br>
            ----<br>
            <br>
            """

            self.comments.insertHtml(html_start)
            self.comments.insertPlainText(comment["text"])
            self.comments.insertHtml(html_end)

Then to use it:

# Get a specific task by names (purely to aid in trying out the example)
project = gazu.project.get_project_by_name("projectname")
sequence = gazu.shot.get_sequence_by_name(project, "sequencename")
shot = gazu.shot.get_shot_by_name(sequence, "shotname")
task = gazu.task.get_task_by_name(shot, gazu.task.get_task_type_by_name("taskname"))

# Use the example widget
widget = TaskComments(task_id=task["id"])
widget.show()

In the end the goal is to have a similar view as Kitsu presents:

kitsu_task_comments

@BigRoy BigRoy added the enhancement New feature or request label Dec 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant