Skip to content

Commit

Permalink
Merge pull request #3 from nfa-vfxim/dev
Browse files Browse the repository at this point in the history
Complete rewrite
  • Loading branch information
mervinvb authored Mar 21, 2024
2 parents 7e60ba8 + d3378a7 commit 5be3004
Show file tree
Hide file tree
Showing 15 changed files with 955 additions and 833 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Netherlands Film Academy
Copyright (c) 2024 Netherlands Film Academy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
This app will get all shots with the "Ready for Delivery" status, and copy the publishes to the delivery folder with the correct naming convention. Currently used at the Netherlands Film Academy.

## User interface
![tk-desktop-deliveries](./resources/tk-desktop-deliveries.png)
![delivery_export](https://github.com/nfa-vfxim/tk-desktop-deliveries/assets/63094424/46c7fbab-84c8-401e-8627-eb25b315b313)


## Requirements
* This app will need a sg_projectcode field on the project in ShotGrid
Expand Down
13 changes: 3 additions & 10 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,10 @@ class tkShotGridDeliveries(Application):
"""

def init_app(self):
"""
Called as the application is being initialized
"""

# Register command
"""Called as the application is being initialized"""
self.engine.register_command("Deliveries", self.deliveries)

def deliveries(self):
"""This function will run the application"""
# Import application
"""This function will open the application"""
app_payload = self.import_module("app")

# Run application
app_payload.dialog.show_dialog(self)
app_payload.controller.open_delivery_app(self)
50 changes: 50 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[tool.black]
line-length = 79

[tool.pytest.ini_options]
addopts = "--capture=tee-sys"

[tool.isort]
profile = "black"

[tool.ruff]
select = [
"A",
"B",
"BLE",
"C4",
"EM",
"ERA",
"F",
"FA",
"FIX",
"G",
"I",
"ICN",
"INP",
"ISC",
"N",
"NPY",
"PERF",
"PGH",
"PIE",
"PL",
"PT",
"PTH",
"PYI",
"Q",
"RET",
"RSE",
"RUF",
"SIM",
"SLF",
"SLOT",
"T20",
"TCH",
"TD",
"TID",
"UP",
"W",
"YTT",
]
show-fixes = true
2 changes: 1 addition & 1 deletion python/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
# SOFTWARE.


from . import dialog
from . import controller
156 changes: 156 additions & 0 deletions python/app/controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# MIT License

# Copyright (c) 2024 Netherlands Film Academy

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

"""Controller for delivery tool, written by Mervin van Brakel 2024"""

import sgtk
from sgtk.platform.qt5 import QtWidgets

from . import model, view

logger = sgtk.platform.get_logger(__name__)


def open_delivery_app(app_instance):
"""
Opens up the app. Is called when user clicks on the delivery button.
"""

app_instance.engine.show_dialog(
"Deliveries", app_instance, DeliveryController
)


class DeliveryController(QtWidgets.QWidget):
"""
The controller for the delivery application.
"""

def __init__(self):
"""
Initializes the controller.
"""
self.view = view.DeliveryView()
self.view.create_user_interface(self)
self.model = model.DeliveryModel(
sgtk.platform.current_bundle(), logger
)
self.connect_buttons()
self.load_shots()

def connect_buttons(self):
"""Connects the buttons from our view to our controller function."""
self.view.reload_button.clicked.connect(self.load_shots)
self.view.export_shots_button.clicked.connect(self.export_shots)
self.view.open_delivery_folder_button.clicked.connect(
self.open_delivery_folder
)

def load_shots(self):
"""Clear the olds shots, then fetches the shots on the model."""
self.view.final_validation_label.hide()

for shot in self.view.shot_widget_references:
self.view.shot_widget_references[shot]["widget"].hide()
self.view.shots_list_widget_layout.removeWidget(
self.view.shot_widget_references[shot]["widget"]
)

self.view.loading_widget.show()
self.model.load_shots(
self.loading_shots_successful,
self.loading_shots_failed,
)

def loading_shots_successful(self, shots_to_deliver):
"""Runs when shots have finished loading.
Args:
shots_to_deliver: List of shots to deliver
"""
self.view.loading_widget.hide()

for shot in shots_to_deliver:
shot_widget = self.view.get_shot_widget(shot)
self.view.shots_list_widget_layout.addWidget(shot_widget)

def loading_shots_failed(self, error: str):
"""Runs when loading shots fails.
Args:
error: Error message from model
"""
logger.error(f"Error while loading shots: {error}")
self.view.loading_widget.hide()
self.view.shots_list_widget_layout.addWidget(
QtWidgets.QLabel("Error while loading shots. Please check logs!")
)

def open_delivery_folder(self):
"""Opens the delivery folder."""
self.model.open_delivery_folder()

def export_shots(self):
"""Runs the export function on the model."""
self.view.final_validation_label.hide()
self.model.export_shots(
self.show_validation_error,
self.update_progress_bar,
self.show_validation_message,
)

def show_validation_error(self, shot: dict) -> None:
"""Sets the validation error text on the shot widget.
Args:
shot: Shot information to show validation error on
"""
self.view.shot_widget_references[shot["id"]][
"validation_label"
].setText(shot["validation_error"])
self.view.shot_widget_references[shot["id"]][
"validation_label"
].setStyleSheet("color: '#FF3E3E'; font: bold; font-size: 12px")
self.view.final_validation_label.show()

def show_validation_message(self, shot) -> None:
"""Sets the validation message on the shot widget.
Args:
shot: Shot to show validation message on
"""
self.view.shot_widget_references[shot["id"]][
"validation_label"
].setText(shot["validation_message"])
self.view.shot_widget_references[shot["id"]][
"validation_label"
].setStyleSheet("color: '#8BFF3E'; font: normal; font-size: 10px")

def update_progress_bar(self, shot: dict) -> None:
"""Updates the progress bar on a shot.
Args:
shot: Shot to change progress bar on
"""
self.view.shot_widget_references[shot["id"]][
"shot_progress_bar"
].setValue(shot["frames_delivered"])
Loading

0 comments on commit 5be3004

Please sign in to comment.