Skip to content

Commit

Permalink
Merge pull request #187 from TrevisanGMW/dev
Browse files Browse the repository at this point in the history
release <- dev (3.1.11)
  • Loading branch information
TrevisanGMW committed Sep 8, 2023
2 parents fe7b8f0 + beefeb1 commit ab60ccf
Show file tree
Hide file tree
Showing 17 changed files with 865 additions and 27 deletions.
2 changes: 1 addition & 1 deletion gt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys

# Package Variables
__version_tuple__ = (3, 1, 10)
__version_tuple__ = (3, 1, 11)
__version_suffix__ = ''
__version__ = '.'.join(str(n) for n in __version_tuple__) + __version_suffix__
__authors__ = ['Guilherme Trevisan']
Expand Down
2 changes: 1 addition & 1 deletion gt/tools/curve_library/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
logger.setLevel(logging.INFO)

# Tool Version
__version_tuple__ = (1, 1, 2)
__version_tuple__ = (1, 1, 3)
__version_suffix__ = ''
__version__ = '.'.join(str(n) for n in __version_tuple__) + __version_suffix__

Expand Down
25 changes: 23 additions & 2 deletions gt/tools/curve_library/curve_library_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Curve Library View - The main GUI window class for the Curve Library tool.
"""
from PySide2.QtWidgets import QListWidget, QPushButton, QWidget, QSplitter, QLineEdit, QDesktopWidget, QListWidgetItem
from PySide2.QtGui import QIcon, QPixmap, QColor, QFont
import gt.ui.resource_library as resource_library
from PySide2.QtGui import QIcon, QPixmap, QColor
from gt.ui.squared_widget import SquaredWidget
from gt.ui.qt_utils import MayaWindowMeta
from PySide2 import QtWidgets, QtCore
Expand Down Expand Up @@ -51,6 +51,10 @@ def __init__(self, parent=None, controller=None, version=None):
QtCore.Qt.WindowMaximizeButtonHint |
QtCore.Qt.WindowMinimizeButtonHint)
self.setWindowIcon(QIcon(resource_library.Icon.tool_crv_library))
# from PySide2.QtGui import QScreen
# primary_screen = QScreen.primaryScreen()
# dpi = primary_screen.physicalDotsPerInch()
# print(dpi)

stylesheet = resource_library.Stylesheet.scroll_bar_dark
stylesheet += resource_library.Stylesheet.maya_basic_dialog
Expand All @@ -75,11 +79,15 @@ def update_preview_image(self, new_image_path=None):

def create_widgets(self):
"""Create the widgets for the window."""
font = QFont()
font.setPointSize(10)
self.item_list = QListWidget()
self.item_list.setFont(font)
self.build_button = QPushButton("Build")
self.build_button.setIcon(QIcon(resource_library.Icon.curve_library_build))
self.build_button.setStyleSheet(resource_library.Stylesheet.push_button_bright)
self.search_bar = QLineEdit(self)
self.search_bar.setFont(font)
self.search_bar.setPlaceholderText('Search...')
self.preview_image = SquaredWidget(self, center_y=False)
# Buttons
Expand All @@ -91,7 +99,8 @@ def create_widgets(self):
self.delete_custom_button.setEnabled(False)
self.delete_custom_button.setIcon(QIcon(resource_library.Icon.curve_library_remove))
self.description = QLabel("<description>")
self.description.setMaximumHeight(20)
self.description.setFont(font)

self.description.setAlignment(Qt.AlignCenter)
self.snapshot_button = QPushButton("Create Snapshot")
self.snapshot_button.setEnabled(False)
Expand Down Expand Up @@ -234,6 +243,18 @@ def update_curve_description(self, new_title, new_description):
output_color="white",
overall_alignment="center")

def moveEvent(self, event):
"""
Move Event, called when the window is moved (must use this name "moveEvent")
Updates the maximum size of the description according to the scale factor of the current screen.
On windows Settings > Display > Scale and layout > Change the size of text, apps, and other items > %
"""
desktop = QDesktopWidget()
screen_number = desktop.screenNumber(self)
scale_factor = qt_utils.get_screen_dpi_scale(screen_number)
default_maximum_height_description = 20
self.description.setMaximumHeight(default_maximum_height_description*scale_factor)


if __name__ == "__main__":
with qt_utils.QtApplicationContext():
Expand Down
2 changes: 1 addition & 1 deletion gt/tools/influences_to_python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


# Tool Version
__version_tuple__ = (2, 0, 0)
__version_tuple__ = (2, 0, 1)
__version_suffix__ = ''
__version__ = '.'.join(str(n) for n in __version_tuple__) + __version_suffix__

Expand Down
12 changes: 7 additions & 5 deletions gt/tools/influences_to_python/influences_python_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ def extract_influence_python(self):
"""
include_bound_mesh = self.view.include_mesh_chk.isChecked()
include_existing_filter = self.view.non_existent_chk.isChecked()
_code = "import maya.cmds as cmds\n\n"
_code += selected_get_python_influences_code(include_bound_mesh=include_bound_mesh,
include_existing_filter=include_existing_filter)
self.view.clear_python_output()
self.view.set_python_output_text(text=_code)
_maya_import = "import maya.cmds as cmds\n\n"
_code = selected_get_python_influences_code(include_bound_mesh=include_bound_mesh,
include_existing_filter=include_existing_filter)
if _code:
_code = _maya_import + _code
self.view.clear_python_output()
self.view.set_python_output_text(text=_code)

@staticmethod
def extract_influence_set():
Expand Down
2 changes: 1 addition & 1 deletion gt/tools/resource_library/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
logger.setLevel(logging.INFO)

# Tool Version
__version_tuple__ = (1, 0, 0)
__version_tuple__ = (1, 0, 1)
__version_suffix__ = ''
__version__ = '.'.join(str(n) for n in __version_tuple__) + __version_suffix__

Expand Down
33 changes: 26 additions & 7 deletions gt/tools/resource_library/resource_library_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"""
from PySide2.QtWidgets import QListWidget, QPushButton, QWidget, QSplitter, QLineEdit, QDesktopWidget, QListWidgetItem
from gt.ui.syntax_highlighter import PythonSyntaxHighlighter
from PySide2.QtGui import QIcon, QPixmap, QColor, QFont
from PySide2.QtWidgets import QTextEdit, QComboBox
import gt.ui.resource_library as resource_library
from PySide2.QtGui import QIcon, QPixmap, QColor
from gt.ui.squared_widget import SquaredWidget
from gt.ui.qt_utils import MayaWindowMeta
from PySide2 import QtWidgets, QtCore
Expand Down Expand Up @@ -78,26 +78,30 @@ def update_preview_image(self, new_image=None):

def create_widgets(self):
"""Create the widgets for the window."""
font = QFont()
font.setPointSize(10)
self.item_list = QListWidget()
self.item_list.setFont(font)
self.save_btn = QPushButton("Export Resource")
self.save_btn.setIcon(QIcon(resource_library.Icon.curve_library_build))
self.save_btn.setStyleSheet(resource_library.Stylesheet.push_button_bright)
self.search_bar = QLineEdit(self)
self.search_bar.setFont(font)
self.search_bar.setPlaceholderText('Search...')
self.preview_image = SquaredWidget(self, center_y=False)
self.resource_path = QTextEdit()
PythonSyntaxHighlighter(self.resource_path.document())
self.resource_path.setMaximumHeight(60)
self.resource_path.setFontPointSize(10)

self.source_combo_box = QComboBox()
self.source_combo_box.setFont(font)
self.source_combo_box.addItem("All")
self.source_combo_box.addItem("Package Resources")
self.source_combo_box.addItem("Package Icons Only")
self.source_combo_box.addItem("Package Colors Only")
self.source_combo_box.addItem("Maya Resources")

self.description = QLabel("<description>")
self.description.setMaximumHeight(20)
self.description.setFont(font)
self.description.setAlignment(Qt.AlignCenter)
# Initial Image Update
self.update_preview_image()
Expand Down Expand Up @@ -206,13 +210,28 @@ def update_item_description(self, new_title, new_description):
output_color="white",
overall_alignment="center")

def moveEvent(self, event):
"""
Move Event, called when the window is moved (must use this name "moveEvent")
Updates the maximum size of the description/resource_path according to the scale factor of the current screen.
On windows Settings > Display > Scale and layout > Change the size of text, apps, and other items > %
"""
desktop = QDesktopWidget()
screen_number = desktop.screenNumber(self)
scale_factor = qt_utils.get_screen_dpi_scale(screen_number)
default_maximum_height_description = 20
self.description.setMaximumHeight(default_maximum_height_description*scale_factor)
default_maximum_height_resource = 50
self.resource_path.setMaximumHeight(default_maximum_height_resource*scale_factor)


if __name__ == "__main__":
with qt_utils.QtApplicationContext():
window = ResourceLibraryView()
mocked_icon = QIcon(resource_library.Icon.curve_library_base_curve)
window.add_item_view_library("item_one", icon=QIcon(resource_library.Icon.curve_library_user_curve))
window.add_item_view_library("item_two", icon=QIcon(resource_library.Icon.curve_library_control))
window.add_item_view_library(item_name="item_one", icon=QIcon(resource_library.Icon.curve_library_user_curve))
window.add_item_view_library(item_name="item_two", icon=QIcon(resource_library.Icon.curve_library_control))
for index in range(1, 101):
window.add_item_view_library(f"item_with_a_very_long_name_for_testing_ui_{index}", icon=mocked_icon)
window.add_item_view_library(item_name=f"item_with_a_very_long_name_for_testing_ui_{index}",
icon=mocked_icon)
window.show()
3 changes: 2 additions & 1 deletion gt/ui/progress_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def __init__(self, parent=None, output_text=True, has_second_button=False):
# Window
self.setGeometry(0, 0, _min_width, _min_height) # Args X, Y, W, H
self.setMinimumWidth(_min_width*.8) # 80% of the maximum width
qt_utils.resize_to_screen(window=self, height_percentage=20, width_percentage=25,
dpi_scale=True, dpi_percentage=20)
qt_utils.center_window(self)
# Window Details
self.setWindowTitle("Progress Bar")
Expand Down Expand Up @@ -296,4 +298,3 @@ def close_parent_window(self):
out = window.get_output_box_plain_text()
print(out)
sys.exit(app.exec_())

80 changes: 73 additions & 7 deletions gt/ui/qt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,25 @@ def get_qt_color(color):
logger.error(f'Unable to create QColor. Unrecognized object type received: "{type(color)}"')


def resize_to_screen(window, percentage=20, width_percentage=None, height_percentage=None):
def resize_to_screen(window, percentage=20,
width_percentage=None, height_percentage=None,
dpi_scale=False, dpi_percentage=20, dpi_ignore_below_one=True):
"""
Resizes the window to match a percentage of the screen size.
Args:
window (QDialog, any): Window to be resized.
percentage (int, optional): The percentage of the screen size that the window should inherit.
Must be a value between 0 and 100. Default is 20.
width_percentage (int, optional): If provided, it will overwrite general set percentage when setting width
height_percentage (int, optional): If provided, it will overwrite general set percentage when setting height
width_percentage (int, optional): If provided, it will overwrite general set percentage when setting width.
height_percentage (int, optional): If provided, it will overwrite general set percentage when setting height.
dpi_scale (bool, optional): When active, it will multiply the size of the window by the DPI scale factor.
It will limit it to the size of the window.
dpi_percentage (float, int, optional): If using dpi scale, this number determines the percentage of the scale
influences the window.
For example: if "dpi_scale" is 10 and "dpi_percentage" is 50,
the used value for "dpi_scale" will become 5 (50% of 10)
dpi_ignore_below_one (bool, optional): When active, it ignores DPI calculations when the scale is 1 (100%)
Raises:
ValueError: If the percentage is not within the range [0, 100].
Expand All @@ -318,6 +327,21 @@ def resize_to_screen(window, percentage=20, width_percentage=None, height_percen
height = screen_geometry.height() * height_percentage / 100
if width_percentage:
width = screen_geometry.height() * width_percentage / 100
if dpi_scale:
dpi_scale = get_screen_dpi_scale(get_window_screen_number(window=window))
dpi_scale = dpi_scale * (dpi_percentage / 100)
if dpi_ignore_below_one and dpi_scale < 1.0:
dpi_scale = 1.0
scaled_height = height*dpi_scale
if scaled_height <= screen_geometry.height():
height = scaled_height
else:
height = screen_geometry.height()
scaled_width = width*dpi_scale
if scaled_width <= screen_geometry.width():
width = scaled_width
else:
width = screen_geometry.width()
window.setGeometry(0, 0, width, height)


Expand All @@ -336,6 +360,19 @@ def get_main_window_screen_number():
return screen_number


def get_window_screen_number(window):
"""
Determines the screen number where the provided Qt windows is located.
Args:
window (QWidget): Qt Window used to determine screen number
Returns:
int: Screen number where the window is located.
"""
desktop = QDesktopWidget()
screen_number = desktop.screenNumber(window)
return screen_number


def center_window(window):
"""
Moves the given window to the center of the screen.
Expand Down Expand Up @@ -412,14 +449,14 @@ def update_formatted_label(target_label,
target_label.setText(_html)


def load_and_scale_pixmap(image_path, scale_percentage, exact_height=None, exact_width=None):
def load_and_scale_pixmap(image_path, scale_percentage=100, exact_height=None, exact_width=None):
"""
Load an image from the given path, and scale it by the specified percentage,
then return the scaled QPixmap.
Args:
image_path (str): Path to the image file.
scale_percentage (float): Percentage to scale the image by.
scale_percentage (float): Percentage to scale the image by. (Default is 100%, which is the original resolution)
100 = Same resolution. 50 = half the resolution. 200 = double the resolution.
exact_height (int, optional): If provided, it will overwrite scale percentage and use this height instead.
exact_width (int, optional): If provided, it will overwrite scale percentage and use this width instead.
Expand All @@ -437,7 +474,7 @@ def load_and_scale_pixmap(image_path, scale_percentage, exact_height=None, exact
if exact_height and isinstance(exact_height, int):
scaled_height = exact_height
if exact_width and isinstance(exact_width, int):
scaled_height = exact_width
scaled_width = exact_width

scaled_pixmap = pixmap.scaled(scaled_width, scaled_height, mode=QtCore.Qt.SmoothTransformation)
return scaled_pixmap
Expand Down Expand Up @@ -489,7 +526,11 @@ def __enter__(self):
self.parent = get_maya_main_window()
else:
logger.debug('Running Qt outside Maya. Initializing QApplication.')
self.app = QtWidgets.QApplication(sys.argv)
_app_instance = QApplication.instance()
if not _app_instance:
self.app = QApplication(sys.argv)
else:
self.app = _app_instance
return self

def __exit__(self, exc_type, exc_value, traceback):
Expand Down Expand Up @@ -562,6 +603,31 @@ def create_color_icon(color, width=24, height=24):
return icon


def get_screen_dpi_scale(screen_number):
"""
Calculate the scale factor of the DPI for a given screen number.
Args:
screen_number (int): The index of the screen for which to calculate DPI percentage.
Returns:
float: The scale factor of DPI for the specified screen.
Raises:
ValueError: If the screen number is out of range.
"""
app = QApplication.instance()
screen_list = app.screens()

if 0 <= screen_number < len(screen_list):
target_screen = screen_list[screen_number]
standard_dpi = 96.0
dpi_scale_factor = target_screen.logicalDotsPerInch() / standard_dpi
return dpi_scale_factor
else:
raise ValueError("Invalid screen number. Please provide a valid screen number.")


if __name__ == "__main__":
with QtApplicationContext() as context:
print(context)
Expand Down
11 changes: 10 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,19 @@

# Modules to Test
modules_to_test = [
# Ui
test_ui.test_input_window_text,
test_ui.test_line_text_widget,
test_ui.test_maya_menu,
test_ui.test_progress_bar,
test_ui.test_python_output_view,
test_ui.test_qt_utils,
test_ui.test_resource_library,
# Tools
test_curve_library.test_curve_library_model,
test_package_updater.test_package_updater_model,
test_sample_tool.test_sample_tool_model,
test_ui.test_resource_library,
# Utils
test_utils.test_alembic_utils,
test_utils.test_anim_utils,
test_utils.test_attr_utils,
Expand Down
6 changes: 6 additions & 0 deletions tests/test_ui/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
from . import test_input_window_text
from . import test_line_text_widget
from . import test_maya_menu
from . import test_progress_bar
from . import test_python_output_view
from . import test_qt_utils
from . import test_resource_library
Loading

0 comments on commit ab60ccf

Please sign in to comment.