Skip to content

Commit

Permalink
Merge pull request #1 from Ahuge/dev
Browse files Browse the repository at this point in the history
Prepare for Release v0.1.0
  • Loading branch information
Ahuge authored Jan 14, 2021
2 parents 92e98d7 + 01ad949 commit 94fba69
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 44 deletions.
1 change: 1 addition & 0 deletions sept_qt/documentation_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 18 additions & 8 deletions sept_qt/input_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = '<b style="background-color:rgb({red},{green},{blue});">'.format(
red=self.error_colour.red(),
green=self.error_colour.green(),
blue=self.error_colour.blue(),
colour_start = (
'<b style="background-color:rgb({red},{green},{blue});">'.format(
red=self.error_colour.red(),
green=self.error_colour.green(),
blue=self.error_colour.blue(),
)
)
resulting_string = before + colour_start + target + "</b>" + after
self._line_widget.textChanged.disconnect(self._handle_text_edited)
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions sept_qt/preview_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
105 changes: 69 additions & 36 deletions usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,71 +11,98 @@ def get_tokens():
"""
Setting up Tokens you want to expose to the user.
"""

class StatusToken(Token):
"""
The <code>status</code> 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 <code>lastname</code> 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 <code>firstname</code> 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 <code>user</code> 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 <code>shot</code> 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 <code>shot</code> 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 <code>project</code> 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 <code>name</code> Token will return the "code" value of the Version.
"""

name = "name"

def getValue(self, data):
return data.get("code", "")

class VersionToken(Token):
"""
The <code>version</code> 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
Expand All @@ -86,27 +113,33 @@ def getValue(self, data):
if version_number is None:
return version_number
return str(version_number)

class ExtensionToken(Token):
"""
The <code>extension</code> 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
for published_file in published_files:
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,
Expand All @@ -122,38 +155,51 @@ 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")

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
published_files_ids = []
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:
Expand All @@ -166,6 +212,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
Expand All @@ -190,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)
Expand All @@ -204,32 +260,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()

Expand Down

0 comments on commit 94fba69

Please sign in to comment.