-
Notifications
You must be signed in to change notification settings - Fork 3
/
auri_lib.py
158 lines (121 loc) · 3.88 KB
/
auri_lib.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import abc
import os
import re
from auri import __version__
from auri.vendor.Qt import QtWidgets
def get_application():
try:
import maya.OpenMayaUI as mui
import maya.cmds as cmds
import pymel.core as pymel
host_application = "maya"
except (ImportError, TypeError):
try:
import hou
host_application = "houdini"
except ImportError:
try:
import nuke
import nukescripts
host_application = "nuke"
except ImportError:
try:
import MaxPlus
host_application = "3dsmax"
except ImportError:
try:
import modo
host_application = "modo"
except ImportError:
host_application = "standalone"
return host_application
def get_auri_version():
return __version__
def get_scripts_directory():
return os.path.join(os.path.dirname(os.path.realpath(__file__)), "scripts")
def get_categories():
categories = [cat for cat in os.listdir(get_scripts_directory()) if os.path.isdir(os.path.join(get_scripts_directory(), cat))]
return categories
def get_subcategories(category=None):
if category is None:
categories = get_categories()
if len(categories) > 0:
category = get_categories()[0]
else:
return []
category = os.path.join(get_scripts_directory(), category)
subcategories = [subcat for subcat in os.listdir(category) if subcat != ".git" and os.path.isdir(os.path.join(category, subcat))]
return subcategories
def get_scripts(category=None, subcategory=None):
if category is None:
return []
if subcategory is None:
return []
scripts = next(os.walk(os.path.join(get_scripts_directory(), category, subcategory)))[2]
excludes = r"(__init__.py)|(.*.pyc)"
includes = r".*.py$"
scripts = [s for s in scripts if re.match(includes, s) and not re.match(excludes, s)]
return scripts
def push_button(text, signal=None):
assert isinstance(text, str)
btn = QtWidgets.QPushButton(text)
if signal is not None:
btn.clicked.connect(signal)
return btn
def grpbox(title, lyt=None):
if lyt is None:
lyt = QtWidgets.QVBoxLayout()
g = QtWidgets.QGroupBox(title=title)
g.setLayout(lyt)
return g
def get_resources_path():
return os.path.join(os.path.dirname(os.path.abspath(__file__)), "resources")
def get_auri_icon(icon_name):
return os.path.join(get_resources_path(), "icons", icon_name)
def is_checked(chkbox_state):
"""
Connect to a checkbox stateChanged
Args:
chkbox_state (int):
"""
switch = {0: False, 2: True}
return switch.get(chkbox_state)
def get_houdini_style():
with open(os.path.join(get_resources_path(), "themes", "houdini_base.qss"), "r") as houdini_style:
style = houdini_style.read()
return style
class AuriScriptView(QtWidgets.QWidget):
def __init__(self, *args, **kwargs):
super(AuriScriptView, self).__init__(*args, **kwargs)
self.ctrl = None
self.model = None
self.set_model()
self.set_controller()
self.setup_ui()
@abc.abstractmethod
def set_model(self):
pass
@abc.abstractmethod
def set_controller(self):
pass
@abc.abstractmethod
def setup_ui(self):
pass
@abc.abstractmethod
def refresh_view(self):
pass
def refresh_fold(self):
self.setVisible(not self.model.folded)
class AuriScriptController:
def __init__(self):
pass
@abc.abstractmethod
def execute(self):
pass
@abc.abstractmethod
def prebuild(self):
pass
class AuriScriptModel:
def __init__(self):
self.module_name = None
self.folded = False