Update
This commit is contained in:
151
2023/scripts/dev_tools/mayaiconview.py
Normal file
151
2023/scripts/dev_tools/mayaiconview.py
Normal file
@@ -0,0 +1,151 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Maya Icon Viewer
|
||||
A utility tool to browse, search, and manage Maya icons.
|
||||
Compatible with Maya 2017+ and Python 2.7/3.x
|
||||
"""
|
||||
|
||||
from __future__ import print_function, division, absolute_import
|
||||
import os
|
||||
import sys
|
||||
import maya.cmds as cmds
|
||||
|
||||
# Global variables
|
||||
favorites = [] # Store favorite icons
|
||||
MAX_FAVORITES = 15 # Maximum capacity of favorites
|
||||
ICON_SIZE = 50 # Icon size in pixels
|
||||
COLUMNS = 15 # Number of columns in icon grid
|
||||
ROWS = 10 # Number of visible rows in icon grid
|
||||
WINDOW_NAME = "mayaIconViewer" # Window name
|
||||
|
||||
def create_icon_viewer():
|
||||
"""Create and display the icon viewer window"""
|
||||
window_width = COLUMNS * ICON_SIZE
|
||||
|
||||
# Delete window if it already exists
|
||||
if cmds.window(WINDOW_NAME, exists=True):
|
||||
cmds.deleteUI(WINDOW_NAME)
|
||||
|
||||
# Create main window
|
||||
cmds.window(WINDOW_NAME, title="Maya Icon Viewer", width=window_width)
|
||||
main_layout = cmds.columnLayout(adjustableColumn=True)
|
||||
|
||||
# Add UI elements
|
||||
create_ui_elements(window_width)
|
||||
update_icons()
|
||||
cmds.showWindow(WINDOW_NAME)
|
||||
|
||||
def create_ui_elements(width):
|
||||
"""Create UI elements including search field and icon areas"""
|
||||
cmds.text(label="Click icon to copy name and add to favorites - Note: Search may be slow, please be patient",
|
||||
align="center", font="boldLabelFont", width=width)
|
||||
cmds.textFieldGrp("searchField", label="Search:",
|
||||
columnWidth=[(1, 50), (2, width-70)],
|
||||
changeCommand=update_icons)
|
||||
create_favorites_area()
|
||||
create_icon_grid()
|
||||
|
||||
def create_favorites_area():
|
||||
"""Create favorites area for quick access to frequently used icons"""
|
||||
cmds.separator(height=10, style='none') # Add spacing
|
||||
cmds.text(label="Favorites", align='left', font="boldLabelFont")
|
||||
cmds.separator(height=5, style='none') # Add more spacing
|
||||
|
||||
global favorites_layout
|
||||
favorites_layout = cmds.rowLayout(numberOfColumns=MAX_FAVORITES+1,
|
||||
columnWidth1=45,
|
||||
adjustableColumn=2,
|
||||
columnAttach=[(1, 'left', 0), (2, 'left', 0)],
|
||||
height=50,
|
||||
backgroundColor=[0.2, 0.2, 0.2])
|
||||
|
||||
# Add star icon (non-clickable)
|
||||
cmds.symbolButton(image="SE_FavoriteStar.png", width=45, height=45,
|
||||
enable=False, annotation="Favorites: Click icon to quickly copy name")
|
||||
|
||||
# Create favorite icon slots
|
||||
for _ in range(MAX_FAVORITES):
|
||||
cmds.symbolButton(parent=favorites_layout, width=45, height=45, visible=False)
|
||||
|
||||
cmds.setParent('..')
|
||||
cmds.separator(height=10, style='none') # Add bottom spacing
|
||||
|
||||
def create_icon_grid():
|
||||
"""Create icon grid with scroll layout"""
|
||||
global scroll_layout, grid_layout
|
||||
scroll_layout = cmds.scrollLayout(horizontalScrollBarThickness=16,
|
||||
verticalScrollBarThickness=16)
|
||||
grid_layout = cmds.gridLayout(numberOfColumns=COLUMNS,
|
||||
cellWidthHeight=(ICON_SIZE, ICON_SIZE))
|
||||
|
||||
def update_icons(*args):
|
||||
"""Update icon display based on search term"""
|
||||
search_term = cmds.textFieldGrp("searchField", query=True, text=True).lower()
|
||||
|
||||
# Clear existing icons
|
||||
for child in cmds.gridLayout(grid_layout, query=True, childArray=True) or []:
|
||||
cmds.deleteUI(child)
|
||||
|
||||
# Add matching icons
|
||||
for icon in cmds.resourceManager(nameFilter="*.png"):
|
||||
if search_term in icon.lower():
|
||||
cmds.symbolButton(parent=grid_layout, image=icon, width=45, height=45,
|
||||
command=lambda x, i=icon: handle_click(i), annotation=icon)
|
||||
|
||||
adjust_layout()
|
||||
|
||||
def adjust_layout():
|
||||
"""Adjust layout size based on number of visible icons"""
|
||||
visible_icons = len(cmds.gridLayout(grid_layout, query=True, childArray=True) or [])
|
||||
total_rows = -(-visible_icons // COLUMNS) # Ceiling division
|
||||
scroll_height = min(total_rows, ROWS) * ICON_SIZE
|
||||
cmds.scrollLayout(scroll_layout, edit=True, height=scroll_height)
|
||||
cmds.window(WINDOW_NAME, edit=True, height=scroll_height + 180)
|
||||
|
||||
def handle_click(icon):
|
||||
"""Handle icon click event"""
|
||||
copy_to_clipboard(icon)
|
||||
add_to_favorites(icon)
|
||||
|
||||
def copy_to_clipboard(icon):
|
||||
"""Copy icon name to clipboard (cross-platform compatible)"""
|
||||
try:
|
||||
if sys.platform == 'win32':
|
||||
# Windows
|
||||
os.system('echo {}| clip'.format(icon.replace('|', '^|')))
|
||||
elif sys.platform == 'darwin':
|
||||
# macOS
|
||||
os.system('echo "{}" | pbcopy'.format(icon))
|
||||
else:
|
||||
# Linux
|
||||
try:
|
||||
os.system('echo "{}" | xclip -selection clipboard'.format(icon))
|
||||
except:
|
||||
# Fallback if xclip is not available
|
||||
os.system('echo "{}" | xsel --clipboard --input'.format(icon))
|
||||
print("Copied to clipboard: {}".format(icon))
|
||||
except Exception as e:
|
||||
cmds.warning("Failed to copy to clipboard: {}".format(str(e)))
|
||||
|
||||
def add_to_favorites(icon):
|
||||
"""Add icon to favorites"""
|
||||
global favorites
|
||||
if icon not in favorites:
|
||||
if len(favorites) >= MAX_FAVORITES:
|
||||
favorites.pop(0) # Remove oldest icon if favorites is full
|
||||
favorites.append(icon)
|
||||
update_favorites()
|
||||
|
||||
def update_favorites():
|
||||
"""Update favorites display"""
|
||||
children = cmds.layout(favorites_layout, query=True, childArray=True)
|
||||
for i, child in enumerate(children[1:], 1): # Skip first child (star icon)
|
||||
if i <= len(favorites):
|
||||
cmds.symbolButton(child, edit=True, image=favorites[i-1], visible=True,
|
||||
command=lambda x, icon=favorites[i-1]: copy_to_clipboard(icon))
|
||||
else:
|
||||
cmds.symbolButton(child, edit=True, visible=False)
|
||||
|
||||
if __name__ == "__main__":
|
||||
create_icon_viewer()
|
||||
Reference in New Issue
Block a user