Skip to content

Commit

Permalink
Adding Qt Resources for Tree View icons.
Browse files Browse the repository at this point in the history
CMake build system compiles Qt .rcc files to be loaded at runtime for icons.
Issue #29 and #30.
  • Loading branch information
david-cattermole committed Jan 28, 2020
1 parent 1ddb3ee commit ed553c6
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 2 deletions.
16 changes: 14 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -483,16 +483,24 @@ endif ()

# Install Icons.
if (BUILD_ICONS)
install(DIRECTORY "icons/"
DESTINATION "${MODULE_FULL_NAME}/resources"
FILES_MATCHING PATTERN "*.rcc"
PATTERN "icons/edit" EXCLUDE
PATTERN "icons/library" EXCLUDE
PATTERN "icons/ui" EXCLUDE)
install(DIRECTORY "icons/"
DESTINATION "${MODULE_FULL_NAME}/icons"
FILES_MATCHING PATTERN "*.png"
PATTERN "icons/edit" EXCLUDE
PATTERN "icons/library" EXCLUDE)
PATTERN "icons/library" EXCLUDE
PATTERN "icons/ui" EXCLUDE)
install(DIRECTORY "icons/"
DESTINATION "${MODULE_FULL_NAME}/icons"
FILES_MATCHING PATTERN "*.svg"
PATTERN "icons/edit" EXCLUDE
PATTERN "icons/library" EXCLUDE)
PATTERN "icons/library" EXCLUDE
PATTERN "icons/ui" EXCLUDE)
endif ()


Expand Down Expand Up @@ -550,6 +558,10 @@ if (BUILD_DOCS)
add_subdirectory(docs)
endif ()

if (BUILD_ICONS)
add_subdirectory(icons)
endif ()

if (BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
Expand Down
33 changes: 33 additions & 0 deletions icons/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (C) 2020 David Cattermole.
#
# This file is part of mmSolver.
#
# mmSolver is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# mmSolver is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with mmSolver. If not, see <https://www.gnu.org/licenses/>.
# ---------------------------------------------------------------------
#
# Build Icons (using Qt Resource Compiler)

set(input_file ${CMAKE_SOURCE_DIR}/icons/resources.qrc)
set(output_file ${CMAKE_SOURCE_DIR}/icons/resources.rcc)
add_custom_command(
OUTPUT ${output_file}
COMMAND rcc -binary resources.qrc -o resources.rcc
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/icons
DEPENDS ${input_file}
)
add_custom_target(
build_icons ALL
DEPENDS ${output_file}
COMMENT "Building Icons (with Qt Resource Compiler) (${input_file})..."
)
12 changes: 12 additions & 0 deletions icons/resources.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<RCC>
<qresource>
<file alias="mmSolver_attr.png">ui/mmSolver_attr.png</file>
<file alias="mmSolver_node.png">ui/mmSolver_node.png</file>
<file alias="mmSolver_plug.png">ui/mmSolver_plug.png</file>
<file alias="mmSolver_bundle.png">ui/mmSolver_bundle.png</file>
<file alias="mmSolver_marker.png">ui/mmSolver_marker.png</file>
<file alias="mmSolver_object.png">ui/mmSolver_object.png</file>
<file alias="mmSolver_camera.png">ui/mmSolver_camera.png</file>
<file alias="mmSolver_solverStep.png">ui/mmSolver_solverStep.png</file>
</qresource>
</RCC>
Binary file added icons/ui/mmSolver_attr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ui/mmSolver_bundle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ui/mmSolver_camera.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ui/mmSolver_marker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ui/mmSolver_node.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ui/mmSolver_object.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ui/mmSolver_plug.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ui/mmSolver_solverStep.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions modules/mayaMatchMoveSolver_windows.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
MMSOLVER_LOCATION :=
MMSOLVER_CONFIG_PATH +:= config
MMSOLVER_CONFIG_PATH += ${APPDATA}/mmSolver
MMSOLVER_RESOURCE_PATH := resources
MMSOLVER_LOAD_AT_STARTUP = 1
MMSOLVER_CREATE_MENU = 1
MMSOLVER_CREATE_SHELF = 1
Expand Down
24 changes: 24 additions & 0 deletions python/mmSolver/tools/solver/ui/solver_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
The main window for the 'Solver' tool.
"""

import os
import datetime
import uuid
from functools import partial
Expand Down Expand Up @@ -629,6 +630,28 @@ def help(self):
return


def loadAllResources():
base_install_location = os.environ.get('MMSOLVER_LOCATION', None)
assert base_install_location is not None
fallback = os.path.join(base_install_location, 'resources')
resource_paths = os.environ.get('MMSOLVER_RESOURCE_PATH', fallback)
assert isinstance(resource_paths, basestring)
resource_paths = resource_paths.split(os.pathsep)
for directory_path in resource_paths:
if not os.path.isdir(directory_path):
continue
file_names = os.listdir(directory_path)
for file_name in file_names:
file_path = os.path.join(directory_path, file_name)
if os.path.isfile(file_path):
is_registered = QtCore.QResource.registerResource(file_path)
if is_registered:
LOG.info("Resource registered: %r", file_path)
else:
LOG.warn("Resource failed to register: %r", file_path)
return


def main(show=True, auto_raise=True, delete=False):
"""
Open the Solver UI window.
Expand All @@ -650,6 +673,7 @@ def main(show=True, auto_raise=True, delete=False):
# Force the Plug-in to load. If the plug-in cannot load, the UI
# will not open and an error will be given.
lib_maya_utils.ensure_plugin_loaded()
loadAllResources()

win = SolverWindow.open_window(
show=show,
Expand Down

0 comments on commit ed553c6

Please sign in to comment.