22# Reference Importer v1.1, made by Jaime Florian
33# Video Demonstration: https://www.youtube.com/watch?v=ObX9NU2BmZo
44
5- import os
65import sys
7- libs = os .path .abspath (os .path .dirname (__file__ ))
8- libs = os .path .join (libs ,'lib' )
9- sys .path .append (libs )
10- from PySide2 import QtCore ,QtGui ,QtWidgets
11- import maya .cmds as cmds
12- import maya .OpenMaya as om
13- import maya .OpenMayaUI as omui
14- from shiboken2 import wrapInstance
15- from reference_importer import ImageSequencer , Ui
6+ from pathlib import Path
7+
8+ VENDOR_PATH = Path (__file__ ).parent .resolve () / "vendor"
9+ sys .path .insert (0 , str (VENDOR_PATH ))
10+
11+ import os
12+ import re
13+ from Qt import QtCore ,QtWidgets
14+ from Qt .QtCompat import wrapInstance
15+
16+ try :
17+ import maya .cmds as cmds
18+ import maya .OpenMaya as om
19+ import maya .OpenMayaUI as omui
20+ IN_MAYA = True
21+ except ImportError :
22+ IN_MAYA = False
23+
24+ from .reference_importer import ImageSequencer , Ui
1625
1726
1827
1928def maya_main_window ():
2029 """
2130 Return the Maya main window widget as a Python object
2231 """
32+ if not IN_MAYA :
33+ return None
34+
2335 main_window_ptr = omui .MQtUtil .mainWindow ()
2436 return wrapInstance (int (main_window_ptr ), QtWidgets .QWidget )
2537class ReferenceImporterDialog (QtWidgets .QDialog ):
2638
2739 dlg_instance = None
40+ qapp_instance = None
2841
2942 @classmethod
3043 def run (cls ):
31- if not cls .dlg_instance :
32- cls .dlg_instance = ReferenceImporterDialog ()
44+ if IN_MAYA :
45+ if not cls .dlg_instance :
46+ cls .dlg_instance = ReferenceImporterDialog ()
3347
34- if cls .dlg_instance .isHidden ():
35- cls .dlg_instance .show ()
36- else :
37- cls .dlg_instance .raise_ ()
38- cls .dlg_instance .activateWindow ()
48+ if cls .dlg_instance .isHidden ():
49+ cls .dlg_instance .show ()
50+ else :
51+ cls .dlg_instance .raise_ ()
52+ cls .dlg_instance .activateWindow ()
53+ return
54+
55+ if not cls .qapp_instance :
56+ cls .qapp_instance = QtWidgets .QApplication (sys .argv )
57+
58+ dialog = ReferenceImporterDialog ()
59+ dialog .show ()
60+ cls .qapp_instance .exec_ ()
3961
40- def __init__ (self ,parent = maya_main_window ()):
62+ def __init__ (self , parent = maya_main_window ()):
4163 super (ReferenceImporterDialog ,self ).__init__ (parent )
4264 self .setWindowFlags (self .windowFlags () ^ QtCore .Qt .WindowContextHelpButtonHint )
4365 self .imageSequencer = ImageSequencer ()
4466 self .ui = Ui (self )
4567 self .CreateConnections ()
4668 self .ui .pushButton_create_image_sequence .setDisabled (True )
69+ if not IN_MAYA :
70+ self .ui .checkBox_imagePlane .setDisabled (True )
4771
4872 def CreateConnections (self ):
4973 self .ui .pushButton_fileExplorer_input .clicked .connect (self .SetInput )
@@ -107,14 +131,13 @@ def CheckText(self):
107131 except Exception as e :
108132 raise e
109133
110- def ValidateTimecode (self , text , ):
111- timecode_rx = QtCore .QRegExp ('([0-9]{2}[:]){1,2}[0-9]{2}[.]?[0-9]{0,2}' )
112- timecode_validator = QtGui .QRegExpValidator (timecode_rx , self )
113- state = timecode_validator .validate (text ,0 )
114- if state [0 ] == QtGui .QRegExpValidator .Acceptable :
115- return True
116134
117- else :
135+ def ValidateTimecode (self , text ):
136+ timecode_rx = r'([0-9]{2}[:]){1,2}[0-9]{2}[.]?[0-9]{0,2}'
137+ state = re .fullmatch (timecode_rx , text )
138+ if state :
139+ return True
140+ else :
118141 return False
119142
120143 def CreateImageSequence (self ):
@@ -136,12 +159,12 @@ def CreateImageSequence(self):
136159 trim_start ,trim_end ,
137160 output_file )
138161
139- if self .ui .checkBox_imagePlane .isChecked ():
162+ if self .ui .checkBox_imagePlane .isChecked () and IN_MAYA :
140163 output_file = output_file .replace ('%03d' , '001' )
141164 image_plane = cmds .imagePlane (fn = output_file )
142165 cmds .setAttr ("%s.useFrameExtension" % image_plane [0 ],True )
143166 except Exception as e :
144167 raise e
145168
146- if 'name' == "__main__" :
147- pass
169+ if __name__ == "__main__" :
170+ ReferenceImporterDialog . run ()
0 commit comments