Skip to content

Commit

Permalink
Merge pull request #16 from quadproduction/release/4.0.9
Browse files Browse the repository at this point in the history
Release/4.0.9
  • Loading branch information
BenSouchet authored Dec 5, 2024
2 parents 755980d + 9c7c580 commit 5267378
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/quadpype/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
get_user_settings,
save_user_settings,
get_user_profile,
get_all_user_profiles,
get_user_workstation_info
)

Expand Down Expand Up @@ -271,6 +272,7 @@
"get_user_settings",
"save_user_settings",
"get_user_profile",
"get_all_user_profiles",
"get_user_workstation_info",

"ApplicationLaunchFailed",
Expand Down
8 changes: 8 additions & 0 deletions src/quadpype/lib/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ def get_user_profile(self):

return user_profile

def get_all_user_profiles(self):
return self.collection.find({})

def update_user_profile_on_startup(self):
"""Update user profile on startup"""
user_profile = self.get_user_profile()
Expand Down Expand Up @@ -218,6 +221,11 @@ def get_user_profile():
return _USER_HANDLER.get_user_profile()


@require_user_handler
def get_all_user_profiles():
return _USER_HANDLER.get_all_user_profiles()


@require_user_handler
def update_user_profile_on_startup():
return _USER_HANDLER.update_user_profile_on_startup()
Expand Down
4 changes: 2 additions & 2 deletions src/quadpype/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from quadpype.lib.version_utils import is_running_staging, is_running_locally
from quadpype.lib.version_utils import is_staging_enabled, is_running_locally

RESOURCES_DIR = os.path.dirname(os.path.abspath(__file__))

Expand Down Expand Up @@ -42,7 +42,7 @@ def get_liberation_font_path(bold=False, italic=False):
def _get_app_image_variation_name():
if is_running_locally():
return "dev"
elif is_running_staging():
elif is_staging_enabled():
return "staging"

return "default"
Expand Down
73 changes: 56 additions & 17 deletions src/quadpype/tools/settings/settings/categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
import contextlib
from abc import abstractmethod
from enum import Enum
from datetime import datetime

from qtpy import QtWidgets, QtCore
import qtawesome

from quadpype.lib import get_quadpype_version
from quadpype.lib import (
get_quadpype_version,
get_all_user_profiles
)
from quadpype.tools.utils import set_style_property
from quadpype.settings.entities import (
GlobalSettingsEntity,
Expand Down Expand Up @@ -1238,13 +1243,14 @@ def on_saved(self, saved_tab_widget):


class UserManagerWidget(BaseControlPanelWidget):
table_column_labels = [
"Username",
"ID",
"Role",
"Last Connection",
"Last Workstation Name"
]
_ws_profile_prefix = "last_workstation_profile/"
table_column_data = {
_ws_profile_prefix + "username": "Username",
"user_id": "ID",
"role": "Role",
"last_connection_timestamp": "Last Connection",
_ws_profile_prefix + "workstation_name": "Last Workstation Name"
}

def __init__(self, controller, parent=None):
super().__init__(controller, parent)
Expand Down Expand Up @@ -1276,7 +1282,7 @@ def update_column_widths(self):
self.table_widget.setColumnWidth(column_index, columns_size[column_index] + additional_width_column)

if additional_width_column:
# This means without adding width the sum of column wouldn't take the full width
# This means, without adding width, the sum of column wouldn't take the full width
# Stretching the last column to ensure the row will be fully filled
last_column_index = columns_count-1
self.table_widget.horizontalHeader().setSectionResizeMode(last_column_index, QtWidgets.QHeaderView.Stretch)
Expand All @@ -1290,14 +1296,47 @@ def add_user_row(self, user_data):
item.setTextAlignment(QtCore.Qt.AlignCenter)
self.table_widget.setItem(row_index, column_index, item)

def _update_user_list(self):
# Remove all the rows (if any)
self.table_widget.setRowCount(0)

# Get the user profiles
user_profiles = get_all_user_profiles()

# Populate the table
for user_profile in user_profiles:
user_data = []

# Aggregate the user data
last_workstation_profile = \
user_profile["workstation_profiles"][user_profile["last_workstation_profile_index"]]
for user_profile_key in self.table_column_data:
if user_profile_key.startswith(self._ws_profile_prefix):
user_profile_key = user_profile_key.removeprefix(self._ws_profile_prefix)
cell_value = last_workstation_profile[user_profile_key]
else:
cell_value = user_profile[user_profile_key]

if isinstance(cell_value, datetime):
# Convert datetime to string (close to the ISO 8601 standard)
cell_value = cell_value.strftime("%Y-%m-%d, %H:%M:%S")

user_data.append(cell_value)

self.add_user_row(user_data)

if user_profiles.retrieved == 0:
# No profile found, this should be impossible unless the
# collection has been cleared while QuadPype was running

# Inserting an empty row to avoid issues:
user_data = [""] * len(self.table_column_data)
self.add_user_row(user_data)

def resizeEvent(self, event):
super().resizeEvent(event)
self.update_column_widths()

def on_cell_clicked(self, row, column):
cell_value = self.table_widget.item(row, column).text() if self.table_widget.item(row, column) else ""
print(f"Cell clicked at row {row}, column {column}: {cell_value}")

def on_selection_changed(self):
selected_items = self.table_widget.selectedItems()
if not selected_items:
Expand All @@ -1312,8 +1351,8 @@ def create_ui(self):
self.table_widget = QtWidgets.QTableWidget(self.content_widget)

self.table_widget.verticalHeader().hide()
self.table_widget.setColumnCount(len(self.table_column_labels))
self.table_widget.setHorizontalHeaderLabels(self.table_column_labels)
self.table_widget.setColumnCount(len(self.table_column_data))
self.table_widget.setHorizontalHeaderLabels(self.table_column_data.values())

# Set selection mode to only allow single row selection
self.table_widget.setSelectionMode(QtWidgets.QTableWidget.SingleSelection)
Expand All @@ -1323,7 +1362,7 @@ def create_ui(self):

self.table_widget.setSortingEnabled(True)

self.add_user_row(["placeholder", "wealthy-warm-kestrel", "administrator", "2024-12-03 13:52", "computer"])
self._update_user_list()

# Initially sort by the "Username" column (index 0)
self.table_widget.sortItems(0)
Expand Down Expand Up @@ -1357,7 +1396,7 @@ def _on_path_edited(self, path):
pass

def _on_refresh_button_pressed(self):
pass
self._update_user_list()

def _on_footer_button_pressed(self):
pass
2 changes: 1 addition & 1 deletion src/quadpype/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-
"""File declaring QuadPype version."""
__version__ = "4.0.8"
__version__ = "4.0.9"

0 comments on commit 5267378

Please sign in to comment.