77from maya import mel
88
99from dwpicker .capture import snap
10- from dwpicker .optionvar import (OVERRIDE_PROD_PICKER_DIRECTORY_ENV ,
11- CUSTOM_PROD_PICKER_DIRECTORY ,
12- LAST_IMAGE_DIRECTORY_USED , save_optionvar )
10+
11+ from dwpicker .path import get_filename
1312from dwpicker .pyside import QtWidgets , QtCore , QtGui
1413from dwpicker .pyside import shiboken2
1514from dwpicker .qtutils import icon
@@ -66,10 +65,10 @@ def __init__(self, editor, parent=None):
6665
6766 self .model_panel_name = cmds .modelPanel (picker_model_name , mbv = False )
6867 cmds .modelEditor (self .model_panel_name ,
69- edit = True ,
70- displayAppearance = 'smoothShaded' ,
71- cam = self .camera_name ,
72- gr = True )
68+ edit = True ,
69+ displayAppearance = 'smoothShaded' ,
70+ camera = self .camera_name ,
71+ grid = True )
7372
7473 ptr = omui .MQtUtil .findControl (self .model_panel_name )
7574 self .model_panel_widget = shiboken2 .wrapInstance (long (ptr ),
@@ -144,7 +143,7 @@ def __init__(self, editor, parent=None):
144143 self .snapshot = QtWidgets .QAction (icon ('snapshot.png' ), '' , self )
145144 self .snapshot .setToolTip ("Capture snapshot" )
146145 self .snapshot .triggered .connect (
147- lambda : capture_snapshot (self , camera_combo_box ))
146+ lambda : self . capture_snapshot (camera_combo_box ))
148147
149148 self .toolbar = QtWidgets .QToolBar ()
150149 self .toolbar .setIconSize (QtCore .QSize (14 , 14 ))
@@ -168,12 +167,12 @@ def __init__(self, editor, parent=None):
168167
169168 def showEvent (self , event ):
170169 super (ViewportWidget , self ).showEvent (event )
171- self .model_panel_widget .repaint ()
170+ self .model_panel_widget .update ()
172171
173172 def add_snapshot_image (self , file = None ):
174173 if os .path .exists (file ):
175- self .editor .create_shape (BACKGROUND , before = True , image = True ,
176- filepath = file )
174+ self .editor .create_shape (
175+ BACKGROUND , before = True , image = True , filepath = file )
177176
178177 def update_camera_viewport (self , combo_box , panel ):
179178 """
@@ -183,9 +182,8 @@ def update_camera_viewport(self, combo_box, panel):
183182 cmds .modelPanel (panel , edit = True , camera = active_camera )
184183 self .camera_name = active_camera
185184
186- def update_resolution_settings (self , combobox , image_size ,
187- custom_width = None ,
188- custom_height = None ):
185+ def update_resolution_settings (
186+ self , combobox , image_size , custom_width = None , custom_height = None ):
189187 resolution = combobox .currentText ()
190188
191189 if resolution == "Custom" :
@@ -220,6 +218,29 @@ def update_resolution_settings(self, combobox, image_size,
220218 device_aspect_ratio )
221219 cmds .setAttr ("defaultResolution.pixelAspect" , 1 )
222220
221+ def capture_snapshot (self , combo_box ):
222+ """
223+ snapshot args:
224+ off_screen: boolean (Process in the background when True)
225+ show_ornaments: boolean (Hide Axis and camera names,... when False)
226+ """
227+ active_camera = combo_box .currentText ()
228+
229+ filename = get_filename ()
230+
231+ snap (active_camera ,
232+ off_screen = True ,
233+ filename = filename ,
234+ frame_padding = 0 ,
235+ show_ornaments = False ,
236+ # clipboard=True,
237+ maintain_aspect_ratio = True ,
238+ camera_options = {"displayFieldChart" : False })
239+
240+ # NotificationWidget.show_notification(cls, "Snapshot done!")
241+
242+ self .add_snapshot_image (filename + ".0.png" )
243+
223244
224245class NotificationWidget (QtWidgets .QLabel ):
225246 def __init__ (self , parent = None , message = "Notification" , duration = 2000 ):
@@ -249,7 +270,7 @@ def __init__(self, parent=None, message="Notification", duration=2000):
249270 self .timer .start (duration )
250271
251272 @staticmethod
252- def show_notification (parent , message = "Notification " , duration = 2000 ):
273+ def show_notification (parent , message = "" , duration = 2000 ):
253274 NotificationWidget (parent , message , duration )
254275
255276
@@ -279,91 +300,48 @@ def toggle_camera_view(camera_name):
279300 orthographic = True )
280301 up_dir = cmds .camera (camera_name , query = True , worldUp = True )
281302
282- camera_view = {"o " : True } if is_perspective else {"p " : True }
283- cmds .viewPlace (camera_name , up = ( up_dir [ 0 ], up_dir [ 1 ], up_dir [ 2 ]),
284- ** camera_view )
303+ camera_view = {"ortho " : True } if is_perspective else {"perspective " : True }
304+ cmds .viewPlace (
305+ camera_name , up = ( up_dir [ 0 ], up_dir [ 1 ], up_dir [ 2 ]), ** camera_view )
285306
286307
287308def toggle_camera_settings (panel , camera_name = "persp" , option = "resolution" ):
288309 """
289310 Toggles the camera settings based on the option specified.
290311
291- - 'resolution' toggles the camera resolution (displayResolution and overscan).
292- - 'field_chart' toggles the field chart display.
312+ Args:
313+ panel (str): The panel's name used on the viewport.
314+ camera_name (str): The name of the camera. Defaults to "persp".
315+ option (str): The setting to toggle. Options include:
316+ - 'lock_camera': Locks or unlocks the camera.
317+ - 'resolution': Toggles the camera's resolution settings (displayResolution and overscan).
318+ - 'field_chart': Toggles the display of the field chart.
293319 """
294320
295321 if option == "lock_camera" :
296322 mel .eval ("changeCameraLockStatus" + " %s;" % panel )
297323
298324 if option == "resolution" :
299- display_resolution = cmds .camera (camera_name , query = True ,
300- displayResolution = True )
325+ display_resolution = cmds .camera (
326+ camera_name , query = True , displayResolution = True )
301327 overscan_value = cmds .camera (camera_name , query = True , overscan = True )
302328
303329 if display_resolution and overscan_value == 1.3 :
304- cmds .camera (camera_name , edit = True , displayFilmGate = False ,
305- displayResolution = False , overscan = 1.0 )
330+ cmds .camera (
331+ camera_name , edit = True , displayFilmGate = False ,
332+ displayResolution = False , overscan = 1.0 )
306333 return
307- cmds .camera (camera_name , edit = True , displayFilmGate = False ,
308- displayResolution = True , overscan = 1.3 )
334+ cmds .camera (
335+ camera_name , edit = True , displayFilmGate = False ,
336+ displayResolution = True , overscan = 1.3 )
309337
310338 elif option == "field_chart" :
311- field_chart_display = cmds .camera (camera_name , query = True ,
312- displayFieldChart = True )
339+ field_chart_display = cmds .camera (
340+ camera_name , query = True , displayFieldChart = True )
313341 if field_chart_display :
314342 cmds .camera (camera_name , edit = True , displayFieldChart = False )
315343 return
316344 cmds .camera (camera_name , edit = True , displayFieldChart = True )
317345
318346
319- def get_custom_picker_directory ():
320- dir_env_overridden = cmds .optionVar (
321- query = OVERRIDE_PROD_PICKER_DIRECTORY_ENV )
322- if not dir_env_overridden :
323- return None
324-
325- dir_path = cmds .optionVar (query = CUSTOM_PROD_PICKER_DIRECTORY )
326- if not os .path .isdir (dir_path ):
327- return None
328-
329- return dir_path
330-
331-
332- def get_filename ():
333- folder_path = get_custom_picker_directory ()
334- if not folder_path :
335- folder_path = QtWidgets .QFileDialog .getExistingDirectory (None ,
336- "Select Directory" ,
337- "" )
338- if folder_path :
339- save_optionvar (LAST_IMAGE_DIRECTORY_USED , folder_path )
340- else :
341- folder_path = cmds .optionVar (query = LAST_IMAGE_DIRECTORY_USED )
342-
343- filename = os .path .join (folder_path , "dwpicker-" + str (uuid .uuid4 ()))
344-
345- return filename
346-
347-
348- def capture_snapshot (cls , combo_box ):
349- """
350- snapshot args:
351- off_screen: boolean (Process in the background when True)
352- show_ornaments: boolean (Hide Axis and camera names,... when False)
353- """
354- active_camera = combo_box .currentText ()
355-
356- filename = get_filename ()
357-
358- snap (active_camera ,
359- off_screen = True ,
360- filename = filename ,
361- frame_padding = 0 ,
362- show_ornaments = False ,
363- # clipboard=True,
364- maintain_aspect_ratio = True ,
365- camera_options = {"displayFieldChart" : False })
366-
367- NotificationWidget .show_notification (cls , "Snapshot done!" )
368347
369- cls .add_snapshot_image (filename + ".0.png" )
0 commit comments