From e2a4d9be8979a581e0bb943136153e88dbd652f2 Mon Sep 17 00:00:00 2001 From: Alex Hughes Date: Wed, 13 Jan 2021 16:10:12 -0800 Subject: [PATCH 1/2] Update docstrings on usage.py --- usage.py | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/usage.py b/usage.py index c074540..5d90c52 100644 --- a/usage.py +++ b/usage.py @@ -122,6 +122,10 @@ def getValue(self, data): def live_version_data(): + """ + live_version_data is an example of how you might prepare data for your + sept application. + """ # Setting up input data from shotgun_api3 import Shotgun sg = Shotgun("https://mysite.shotgunstudio.com", login="mylogin", password="mypassword") @@ -166,6 +170,12 @@ def live_version_data(): def get_version_data(): + """ + get_version_data loads previously live data from disk for examples with + your sept application. + + Plus, not like I'm going to hard code my credentials or anything + """ with open(os.path.join(os.path.dirname(__file__), "usage_data.json"), "r") as fh: version_data = json.loads(fh.read()) return version_data @@ -204,32 +214,9 @@ def _build_ui(self): self.layout().addWidget(self.splitter) - - if __name__ == "__main__": app = QtGui.QApplication([]) - QtGui.QApplication.setStyle("plastique") - # QtGui.QApplication.setStyle("fusion") - # - # palette_file = r"D:\Users\Alex\Downloads\dark_palette.qpalette" - # fh = QtCore.QFile(palette_file) - # fh.open(QtCore.QIODevice.ReadOnly) - # file_in = QtCore.QDataStream(fh) - # - # # deserialize the palette - # # (store it for GC purposes) - # _dark_palette = QtGui.QPalette() - # file_in.__rshift__(_dark_palette) - # fh.close() - # QtGui.QApplication.setPalette(_dark_palette) - # - # css_file = r"D:\Users\Alex\Downloads\dark_palette.css" - # f = open(css_file) - # css_data = f.read() - # f.close() - # app.setStyleSheet(css_data) - dialog = Dialog() dialog.show() From 01ad94985012c083fcfe7a6756e2174686781db2 Mon Sep 17 00:00:00 2001 From: Black Code Formatter Date: Thu, 14 Jan 2021 00:12:09 +0000 Subject: [PATCH 2/2] Black Automatically Formatted Code --- sept_qt/documentation_widget.py | 1 + sept_qt/input_widget.py | 26 ++++++++---- sept_qt/preview_widget.py | 1 + usage.py | 72 +++++++++++++++++++++++++++------ 4 files changed, 79 insertions(+), 21 deletions(-) diff --git a/sept_qt/documentation_widget.py b/sept_qt/documentation_widget.py index c55e6af..0ef833e 100644 --- a/sept_qt/documentation_widget.py +++ b/sept_qt/documentation_widget.py @@ -11,6 +11,7 @@ class DocumentationWidget(QtGui.QTabWidget): This is a known security risk if you are loading Tokens or Operators from an untrusted source. """ + def __init__(self, parser, parent=None): """ DocumentationWidget only requires a `sept.PathTemplateParser` object diff --git a/sept_qt/input_widget.py b/sept_qt/input_widget.py index 9a427b2..9476e4f 100644 --- a/sept_qt/input_widget.py +++ b/sept_qt/input_widget.py @@ -27,6 +27,7 @@ class TemplateInputWidget(QtGui.QWidget): error class has "location" and "length" attributes on it that can be used to display the highlighting. """ + ERROR_BG_COLOUR = QtGui.QColor(255, 192, 192) template_changed = QtCore.Signal(object) _TIMER_TIMEOUT = 1250 @@ -134,28 +135,35 @@ def _display_error_factory(self, error): :return: A python function with the `error` wrapped. :rtype: callable """ + def __display_error(): text = self._line_widget.toPlainText() cursor = self._line_widget.textCursor() position = cursor.position() start = 0 - if isinstance(error, errors.LocationAwareSeptError) or hasattr(error, "location"): + if isinstance(error, errors.LocationAwareSeptError) or hasattr( + error, "location" + ): start = error.location length = len(text) - start - if isinstance(error, errors.LocationAwareSeptError) or hasattr(error, "length"): + if isinstance(error, errors.LocationAwareSeptError) or hasattr( + error, "length" + ): length = error.length + 1 before, target, after = ( text[:start], - text[start:start + length - 1], - text[start + length - 1:], + text[start : start + length - 1], + text[start + length - 1 :], ) - colour_start = ''.format( - red=self.error_colour.red(), - green=self.error_colour.green(), - blue=self.error_colour.blue(), + colour_start = ( + ''.format( + red=self.error_colour.red(), + green=self.error_colour.green(), + blue=self.error_colour.blue(), + ) ) resulting_string = before + colour_start + target + "" + after self._line_widget.textChanged.disconnect(self._handle_text_edited) @@ -168,6 +176,7 @@ def __display_error(): self._error_widget.setText(str(error)) self._error_widget.show() self._stop_error_timer() + return __display_error @QtCore.Slot(object) @@ -214,6 +223,7 @@ def _handle_text_edited(self): except Exception as err: print("Error: {}".format(str(err))) import traceback + traceback.print_exc() return else: diff --git a/sept_qt/preview_widget.py b/sept_qt/preview_widget.py index 2f517b5..0f4e51d 100644 --- a/sept_qt/preview_widget.py +++ b/sept_qt/preview_widget.py @@ -16,6 +16,7 @@ class TemplatePreviewWidget(QtGui.QPlainTextEdit): Assuming all of the example cases resolve correctly, the QPlainTextEdit will update the preview text. """ + resolve_error = QtCore.Signal(object) def __init__(self, data_list, text=None, parent=None): diff --git a/usage.py b/usage.py index 5d90c52..ec10a21 100644 --- a/usage.py +++ b/usage.py @@ -11,71 +11,98 @@ def get_tokens(): """ Setting up Tokens you want to expose to the user. """ + class StatusToken(Token): """ The status Token will return the "sg_status_list" value from the the Shotgun Version. """ + name = "status" + def getValue(self, data): return data.get("sg_status_list") + class LastNameToken(Token): """ The lastname Token will return the "lastname" value of the Artist for the Version. """ + name = "lastname" + def getValue(self, data): return data.get("user.HumanUser.lastname", "") + class FirstNameToken(Token): """ The firstname Token will return the "firstname" value of the Artist for the Version. """ + name = "firstname" + def getValue(self, data): return data.get("user.HumanUser.firstname", "") + class UserToken(Token): """ The user Token will return the "name" value of the Artist for the Version. """ + name = "user" + def getValue(self, data): return data.get("user.HumanUser.name", "") + class ShotToken(Token): """ The shot Token will return the "code" value of the Shot linked to the Version. """ + name = "shot" + def getValue(self, data): return data.get("entity.Shot.code", "") + class SequenceToken(Token): """ The shot Token will return the "code" value of the Sequence linked to the Version. """ + name = "sequence" + def getValue(self, data): value = data.get("entity.Sequence.code", "") if value: return value return data.get("entity.Shot.sg_sequence.Sequence.code", "") + class ProjectToken(Token): """ The project Token will return the "tank_name" value or the "code" value of the Project linked to the Version. """ + name = "project" + def getValue(self, data): value = data.get("project.Project.tank_name", "") return value or data.get("project.Project.code", "") or "" + class NameToken(Token): """ The name Token will return the "code" value of the Version. """ + name = "name" + def getValue(self, data): return data.get("code", "") + class VersionToken(Token): """ The version Token will return the "version_number" value of the PublishedFile linked to the Version. """ + name = "version" + def getValue(self, data): published_files = data.get("published_files", []) version_number = None @@ -86,11 +113,14 @@ def getValue(self, data): if version_number is None: return version_number return str(version_number) + class ExtensionToken(Token): """ The extension Token will return the path extension value of the PublishedFile linked to the Version. """ + name = "extension" + def getValue(self, data): published_files = data.get("published_files", []) extension = None @@ -98,15 +128,18 @@ def getValue(self, data): if published_file.get("path"): path = published_file.get("path") if path.get("link_type") == "local": - local_path = path.get("local_path") or path.get("local_path_linux") + local_path = path.get("local_path") or path.get( + "local_path_linux" + ) elif path.get("link_type") == "web": - local_path = path.get("url")[len("file://"):] + local_path = path.get("url")[len("file://") :] else: return None base, ext = os.path.splitext(local_path) extension = ext.lstrip(".") break return extension + return [ StatusToken, FirstNameToken, @@ -128,22 +161,29 @@ def live_version_data(): """ # Setting up input data from shotgun_api3 import Shotgun - sg = Shotgun("https://mysite.shotgunstudio.com", login="mylogin", password="mypassword") + + sg = Shotgun( + "https://mysite.shotgunstudio.com", login="mylogin", password="mypassword" + ) fields = [ - "code", "description", - "user.HumanUser.firstname", "user.HumanUser.lastname", - "user.HumanUser.name", "sg_status_list", "project.Project.tank_name", + "code", + "description", + "user.HumanUser.firstname", + "user.HumanUser.lastname", + "user.HumanUser.name", + "sg_status_list", + "project.Project.tank_name", "project.Project.code", - "entity.Shot.code", "entity.Shot.sg_sequence.Sequence.code", + "entity.Shot.code", + "entity.Shot.sg_sequence.Sequence.code", "entity.Sequence.code", "published_files", - ] versions = sg.find( entity_type="Version", filters=[["project.Project.id", "is", 128]], fields=fields, - limit=5 + limit=5, ) # Fill out published file data @@ -151,13 +191,15 @@ def live_version_data(): for version in versions: published_files = version.get("published_files") for published_file in published_files: - if not published_file.get("version_number") or not published_file.get("path"): + if not published_file.get("version_number") or not published_file.get( + "path" + ): published_files_ids.append(published_file.get("id")) if published_files_ids: results = sg.find( entity_type="PublishedFile", filters=[["id", "in", published_files_ids]], - fields=["version_number", "path"] + fields=["version_number", "path"], ) for result in results: for version in versions: @@ -200,8 +242,12 @@ def _build_ui(self): self.template_input_widget = TemplateInputWidget(self.parser) self.template_preview_widget = TemplatePreviewWidget(self.version_data) - self.template_input_widget.template_changed.connect(self.template_preview_widget.preview_template) - self.template_preview_widget.resolve_error.connect(self.template_input_widget.recieve_error) + self.template_input_widget.template_changed.connect( + self.template_preview_widget.preview_template + ) + self.template_preview_widget.resolve_error.connect( + self.template_input_widget.recieve_error + ) self.main_page.layout().addWidget(self.template_input_widget) self.main_page.layout().addWidget(self.template_preview_widget)