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
@@ -64,12 +63,13 @@ def __init__(self, editor, parent=None):
6463 camera_ = cmds .camera (n = self .camera_name )[0 ]
6564 cmds .rename (camera_ , self .camera_name )
6665
67- self .model_panel_name = cmds .modelPanel (picker_model_name , mbv = False )
66+ self .model_panel_name = cmds .modelPanel (
67+ picker_model_name , menuBarVisible = False )
6868 cmds .modelEditor (self .model_panel_name ,
69- edit = True ,
70- displayAppearance = 'smoothShaded' ,
71- cam = self .camera_name ,
72- gr = True )
69+ edit = True ,
70+ displayAppearance = 'smoothShaded' ,
71+ camera = self .camera_name ,
72+ grid = True )
7373
7474 ptr = omui .MQtUtil .findControl (self .model_panel_name )
7575 self .model_panel_widget = shiboken2 .wrapInstance (long (ptr ),
@@ -144,7 +144,7 @@ def __init__(self, editor, parent=None):
144144 self .snapshot = QtWidgets .QAction (icon ('snapshot.png' ), '' , self )
145145 self .snapshot .setToolTip ("Capture snapshot" )
146146 self .snapshot .triggered .connect (
147- lambda : capture_snapshot (self , camera_combo_box ))
147+ lambda : self . capture_snapshot (camera_combo_box ))
148148
149149 self .toolbar = QtWidgets .QToolBar ()
150150 self .toolbar .setIconSize (QtCore .QSize (14 , 14 ))
@@ -168,12 +168,12 @@ def __init__(self, editor, parent=None):
168168
169169 def showEvent (self , event ):
170170 super (ViewportWidget , self ).showEvent (event )
171- self .model_panel_widget .repaint ()
171+ self .model_panel_widget .update ()
172172
173173 def add_snapshot_image (self , file = None ):
174174 if os .path .exists (file ):
175- self .editor .create_shape (BACKGROUND , before = True , image = True ,
176- filepath = file )
175+ self .editor .create_shape (
176+ BACKGROUND , before = True , image = True , filepath = file )
177177
178178 def update_camera_viewport (self , combo_box , panel ):
179179 """
@@ -183,9 +183,8 @@ def update_camera_viewport(self, combo_box, panel):
183183 cmds .modelPanel (panel , edit = True , camera = active_camera )
184184 self .camera_name = active_camera
185185
186- def update_resolution_settings (self , combobox , image_size ,
187- custom_width = None ,
188- custom_height = None ):
186+ def update_resolution_settings (
187+ self , combobox , image_size , custom_width = None , custom_height = None ):
189188 resolution = combobox .currentText ()
190189
191190 if resolution == "Custom" :
@@ -220,6 +219,29 @@ def update_resolution_settings(self, combobox, image_size,
220219 device_aspect_ratio )
221220 cmds .setAttr ("defaultResolution.pixelAspect" , 1 )
222221
222+ def capture_snapshot (self , combo_box ):
223+ """
224+ snapshot args:
225+ off_screen: boolean (Process in the background when True)
226+ show_ornaments: boolean (Hide Axis and camera names,... when False)
227+ """
228+ active_camera = combo_box .currentText ()
229+
230+ filename = get_filename ()
231+
232+ snap (active_camera ,
233+ off_screen = True ,
234+ filename = filename ,
235+ frame_padding = 0 ,
236+ show_ornaments = False ,
237+ # clipboard=True,
238+ maintain_aspect_ratio = True ,
239+ camera_options = {"displayFieldChart" : False })
240+
241+ # NotificationWidget.show_notification(cls, "Snapshot done!")
242+
243+ self .add_snapshot_image (filename + ".0.png" )
244+
223245
224246class NotificationWidget (QtWidgets .QLabel ):
225247 def __init__ (self , parent = None , message = "Notification" , duration = 2000 ):
@@ -249,7 +271,7 @@ def __init__(self, parent=None, message="Notification", duration=2000):
249271 self .timer .start (duration )
250272
251273 @staticmethod
252- def show_notification (parent , message = "Notification " , duration = 2000 ):
274+ def show_notification (parent , message = "" , duration = 2000 ):
253275 NotificationWidget (parent , message , duration )
254276
255277
@@ -279,91 +301,48 @@ def toggle_camera_view(camera_name):
279301 orthographic = True )
280302 up_dir = cmds .camera (camera_name , query = True , worldUp = True )
281303
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 )
304+ camera_view = {"ortho " : True } if is_perspective else {"perspective " : True }
305+ cmds .viewPlace (
306+ camera_name , up = ( up_dir [ 0 ], up_dir [ 1 ], up_dir [ 2 ]), ** camera_view )
285307
286308
287309def toggle_camera_settings (panel , camera_name = "persp" , option = "resolution" ):
288310 """
289311 Toggles the camera settings based on the option specified.
290312
291- - 'resolution' toggles the camera resolution (displayResolution and overscan).
292- - 'field_chart' toggles the field chart display.
313+ Args:
314+ panel (str): The panel's name used on the viewport.
315+ camera_name (str): The name of the camera. Defaults to "persp".
316+ option (str): The setting to toggle. Options include:
317+ - 'lock_camera': Locks or unlocks the camera.
318+ - 'resolution': Toggles the camera's resolution settings (displayResolution and overscan).
319+ - 'field_chart': Toggles the display of the field chart.
293320 """
294321
295322 if option == "lock_camera" :
296323 mel .eval ("changeCameraLockStatus" + " %s;" % panel )
297324
298325 if option == "resolution" :
299- display_resolution = cmds .camera (camera_name , query = True ,
300- displayResolution = True )
326+ display_resolution = cmds .camera (
327+ camera_name , query = True , displayResolution = True )
301328 overscan_value = cmds .camera (camera_name , query = True , overscan = True )
302329
303330 if display_resolution and overscan_value == 1.3 :
304- cmds .camera (camera_name , edit = True , displayFilmGate = False ,
305- displayResolution = False , overscan = 1.0 )
331+ cmds .camera (
332+ camera_name , edit = True , displayFilmGate = False ,
333+ displayResolution = False , overscan = 1.0 )
306334 return
307- cmds .camera (camera_name , edit = True , displayFilmGate = False ,
308- displayResolution = True , overscan = 1.3 )
335+ cmds .camera (
336+ camera_name , edit = True , displayFilmGate = False ,
337+ displayResolution = True , overscan = 1.3 )
309338
310339 elif option == "field_chart" :
311- field_chart_display = cmds .camera (camera_name , query = True ,
312- displayFieldChart = True )
340+ field_chart_display = cmds .camera (
341+ camera_name , query = True , displayFieldChart = True )
313342 if field_chart_display :
314343 cmds .camera (camera_name , edit = True , displayFieldChart = False )
315344 return
316345 cmds .camera (camera_name , edit = True , displayFieldChart = True )
317346
318347
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!" )
368348
369- cls .add_snapshot_image (filename + ".0.png" )
0 commit comments