Skip to content

Commit

Permalink
Merge pull request #94 from masqu3rad3/TIK-117-make-the-version-owner…
Browse files Browse the repository at this point in the history
…-visible-in-the-version-layout

Tik 117 make the version owner visible in the version layout
  • Loading branch information
masqu3rad3 authored Apr 14, 2024
2 parents 638193b + c8f24d8 commit 157f94f
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 43 deletions.
4 changes: 2 additions & 2 deletions tik_manager4/objects/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,15 @@ def destroy(self):
self._publish_versions = {}
return 1

def check_delete_version_permissions(self, version_number):
def check_owner_permissions(self, version_number):
"""Shortcut and wrapper for the check_permissions method."""
if self.check_permissions(level=3) == -1:
return False, "Only Admins can delete publishes."
return True, ""

def delete_version(self, version_number):
"""Delete the given publish version."""
state, msg = self.check_delete_version_permissions(version_number)
state, msg = self.check_owner_permissions(version_number)
if not state:
LOG.warning(msg)
return -1
Expand Down
38 changes: 24 additions & 14 deletions tik_manager4/objects/work.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def resolve_preview_names(self, version, camera, label=None):
full_name = nice_name + [self._name, f"v{version:03d}"]
return "_".join(nice_name), "_".join(full_name)

def construct_names(self, file_format, version_number=None):
def construct_names(self, file_format, version_number=None, thumbnail_extension=".jpg"):
"""Construct a name for the work version.
Args:
Expand All @@ -435,7 +435,7 @@ def construct_names(self, file_format, version_number=None):
"""
version_number = version_number or self.get_last_version() + 1
version_name = f"{self._name}_v{version_number:03d}{file_format}"
thumbnail_name = f"{self._name}_v{version_number:03d}_thumbnail.jpg"
thumbnail_name = f"{self._name}_v{version_number:03d}_thumbnail{thumbnail_extension}"
return version_number, version_name, thumbnail_name

def load_version(self, version_number, force=False, **kwargs):
Expand Down Expand Up @@ -596,6 +596,19 @@ def delete_version(self, version_number):
self.apply_settings(force=True)
return 1


def __generate_thumbnail_paths(self, version_obj, override_extension=None):
"""Return the thumbnail paths of the given version."""
# if there is no previous thumbnail, generate a new one
extension = override_extension or Path(version_obj.get("thumbnail", "noThumb.jpg")).suffix
_number, _name, thumbnail_name = self.construct_names(version_obj.get("file_format", ""), version_obj.get("version_number"), thumbnail_extension=extension)
relative_path = Path("thumbnails", thumbnail_name).as_posix()
# version_obj["thumbnail"] = relative_path
abs_path = self.get_abs_database_path(relative_path)
Path(abs_path).parent.mkdir(parents=True, exist_ok=True)
return relative_path, abs_path


def replace_thumbnail(self, version_number, new_thumbnail_path=None):
"""Replace the thumbnail of the given version.
Args:
Expand All @@ -606,22 +619,19 @@ def replace_thumbnail(self, version_number, new_thumbnail_path=None):
state, _msg = self.check_owner_permissions(version_number)
if not state:
return -1

version_obj = self.get_version(version_number)
thumbnail_relative_path = version_obj.get("thumbnail", None)
if not thumbnail_relative_path:
# if there is no previous thumbnail, generate a new one
_number, _name, thumbnail_relative_path = self.construct_names(version_obj.get("file_format", ".jpg"), version_number)
version_obj["thumbnail"] = thumbnail_relative_path
thumbnail_abs_path = self.get_abs_database_path(thumbnail_relative_path)
# make sure the path exists
Path(thumbnail_abs_path).parent.mkdir(parents=True, exist_ok=True)
if new_thumbnail_path:
shutil.copy(new_thumbnail_path, thumbnail_abs_path)
override_suffix = Path(new_thumbnail_path).suffix if new_thumbnail_path else None
target_relative_path, target_absolute_path = self.__generate_thumbnail_paths(version_obj, override_extension=override_suffix)

if not new_thumbnail_path:
self._dcc_handler.generate_thumbnail(target_absolute_path, 220, 124)
version_obj["thumbnail"] = target_relative_path
else:
self._dcc_handler.generate_thumbnail(thumbnail_abs_path, 220, 124)
shutil.copy(new_thumbnail_path, target_absolute_path)
version_obj["thumbnail"] = target_relative_path

self.apply_settings(force=True)
self.apply_settings()

def check_dcc_version_mismatch(self):
"""Check if there is a mismatch with the current and defined dcc versions.
Expand Down
80 changes: 53 additions & 27 deletions tik_manager4/ui/mcv/version_mcv.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ def __init__(self, project_object, *args, **kwargs):
self.show_preview_btn.setEnabled(False)
version_layout.addWidget(self.show_preview_btn)

user_layout = QtWidgets.QHBoxLayout()
self.addLayout(user_layout)
self.version_owner_lbl = QtWidgets.QLabel("Owner: ")
self.version_owner_lbl.setFont(QtGui.QFont("Arial", 10))
user_layout.addStretch()
user_layout.addWidget(self.version_owner_lbl)

element_layout = QtWidgets.QVBoxLayout()
self.addLayout(element_layout)
element_lbl = QtWidgets.QLabel("Element: ")
Expand All @@ -69,28 +76,16 @@ def __init__(self, project_object, *args, **kwargs):
notes_layout.addWidget(self.notes_editor)

self.thumbnail = ImageWidget()
self.empty_pixmap = pick.pixmap("empty_thumbnail.png")
# self.empty_pixmap = pick.pixmap("empty_thumbnail.png")
self.thumbnail.setToolTip("Right Click for replace options")
self.thumbnail.setProperty("image", True)
self.thumbnail.setPixmap(self.empty_pixmap)
# self.thumbnail.setProperty("image", True)
# self.thumbnail.setPixmap(self.empty_pixmap)

self.thumbnail.setMinimumSize(QtCore.QSize(221, 124))
self.thumbnail.setFrameShape(QtWidgets.QFrame.Box)
self.thumbnail.setScaledContents(True)
self.thumbnail.setAlignment(QtCore.Qt.AlignCenter)

# self.thumbnail.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
# self.thumbnail.customContextMenuRequested.connect(self.on_thumbnail_menu_request)
# self.popmenu_thumbnail = QtWidgets.QMenu()
# replace_with_view_action = QtWidgets.QAction("Replace with current view", self)
# self.popmenu_thumbnail.addAction(replace_with_view_action)
# replace_with_view_action.triggered.connect(lambda: self.thumbnail_replace(mode="view"))
# replace_with_file_action = QtWidgets.QAction("Replace with external file", self)
# self.popmenu_thumbnail.addAction(replace_with_file_action)
# replace_with_file_action.triggered.connect(lambda: self.thumbnail_replace(mode="file"))



self.addWidget(self.thumbnail)

# # buttons
Expand Down Expand Up @@ -291,12 +286,6 @@ def __load_btn_state(self, base, element_type):

def __import_and_reference_btn_states(self, base, element_type):
"""Resolve the import button state."""

# if element_type == "source" or not element_type:
# self.import_btn.setEnabled(base.dcc == base.guard.dcc)
# self.reference_btn.setEnabled(base.dcc == base.guard.dcc)
# return

# if the ingest combo is empty, disable the import and reference buttons
_ingestor = self.get_selected_ingestor()
if not _ingestor:
Expand Down Expand Up @@ -391,20 +380,24 @@ def version_changed(self):
self.element_combo.addItems(list(self.element_mapping.keys()))
# trigger the element type changed manually
self.element_type_changed(self.element_combo.currentText())
owner = _version.creator
else: # WORK
# disable
self.element_combo.setEnabled(False)
self.ingest_with_combo.setEnabled(False)
# enable the show preview button if there are previews
self.show_preview_btn.setEnabled(bool(_version.get("previews")))
owner = _version.get("user", "")
self.version_owner_lbl.setText(f"Owner: {owner}")
self.notes_editor.clear()
self.thumbnail.clear()
self.notes_editor.setPlainText(_version.get("notes"))
_thumbnail_path = self.base.get_abs_database_path(_version.get("thumbnail", ""))
if Path(_thumbnail_path).is_file():
self.thumbnail.setPixmap(QtGui.QPixmap(_thumbnail_path))
else:
self.thumbnail.setPixmap(self.empty_pixmap)
self.thumbnail.set_media(_thumbnail_path)
# if Path(_thumbnail_path).is_file():
# self.thumbnail.setPixmap(QtGui.QPixmap(_thumbnail_path))
# else:
# self.thumbnail.setPixmap(self.empty_pixmap)
self.element_combo.blockSignals(False)
self.ingest_with_combo.blockSignals(False)

Expand Down Expand Up @@ -543,7 +536,7 @@ def on_replace_thumbnail(self, mode="view"):
file_path = None
else:
# get the project directory
file_path = QtWidgets.QFileDialog.getOpenFileName(self.parent, 'Open file', self.project.get_abs_project_path(), "Image files (*.jpg *.png *.gif)")[0]
file_path = QtWidgets.QFileDialog.getOpenFileName(self.parent, 'Open file', self.project.get_abs_project_path(), "Image files (*.jpg *.png *.gif *.webp)")[0]

self.base.replace_thumbnail(version, new_thumbnail_path=file_path)
self.refresh()
Expand Down Expand Up @@ -608,7 +601,6 @@ def publish_snapshot(self):
text=f"Snapshot published.\nName: {published_object.name}\nPath: {published_object.path}",
critical=False,
)

class ImageWidget(QtWidgets.QLabel):
"""Custom class for thumbnail section. Keeps the aspect ratio when resized."""

Expand All @@ -620,6 +612,40 @@ def __init__(self):
)
size_policy.setHeightForWidth(True)
self.setSizePolicy(size_policy)
self.setProperty("image", True)

self.is_movie = False
self.q_media = None

def set_media(self, media_path):
"""Set the media to the widget."""
if not Path(media_path).exists():
self.q_media = pick.pixmap("empty_thumbnail.png")
self.setPixmap(self.q_media)
self.is_movie = False
return
if Path(media_path).suffix.lower() in [".gif", ".webp"]:
self.q_media = QtGui.QMovie(media_path)
# don't start but show the first frame
self.q_media.jumpToFrame(0)
# self.q_media.start()
self.setAttribute(QtCore.Qt.WA_NoSystemBackground)
self.setMovie(self.q_media)
self.is_movie = True
else:
self.q_media = QtGui.QPixmap(media_path)
self.setPixmap(self.q_media)
self.is_movie = False

# start playing the movie if the mouse is over the widget
def enterEvent(self, _):
if self.is_movie:
self.q_media.start()

# pause playing it the mouse leaves the widget
def leaveEvent(self, _):
if self.is_movie:
self.q_media.setPaused(True)

def resizeEvent(self, _resize_event):
height = self.width()
Expand Down

0 comments on commit 157f94f

Please sign in to comment.