def _setupGui(self): self.setWindowTitle('Save Script to Work Area') self.setLayout(QtGui.QVBoxLayout()) self._pickerModel, self._pickerView = any_task( path=os.path.dirname(nuke.root().name()), extra_node_types=[ functools.partial( DirectoryPicker, entity_types=['Task'], template='nuke_scripts_dir', ), ], ) self._pickerView.setFixedSize(600, 250) self._pickerView.setPreviewVisible(False) self._pickerView.nodeChanged.connect(self._pickerNodeChanged) self.layout().addWidget(self._pickerView) # The main widget. self._sceneName = SceneNameWidget(self._kwargs) self.layout().addWidget(self._sceneName) # Save button. self._button = button = QtGui.QPushButton('Save', clicked=self._onSaveClicked) self.layout().addWidget(button) self._pickerNodeChanged(self._pickerView.currentNode())
def _setupGui(self): self.setWindowTitle('Save Script to Work Area') self.setLayout(QtGui.QVBoxLayout()) self._pickerModel, self._pickerView = any_task( path=os.path.dirname(nuke.root().name()), extra_node_types=[functools.partial( DirectoryPicker, entity_types=['Task'], template='nuke_scripts_dir', ), ], ) self._pickerView.setFixedSize(600, 250) self._pickerView.setPreviewVisible(False) self._pickerView.nodeChanged.connect(self._pickerNodeChanged) self.layout().addWidget(self._pickerView) # The main widget. self._sceneName = SceneNameWidget(self._kwargs) self.layout().addWidget(self._sceneName) # Save button. self._button = button = QtGui.QPushButton('Save', clicked=self._onSaveClicked) self.layout().addWidget(button) self._pickerNodeChanged(self._pickerView.currentNode())
def _setup_ui(self): self.setWindowTitle("Copy Publish to Work Area") self.setLayout(Q.VBoxLayout()) self._workspace = workspace = self._path or cmds.workspace( q=True, rootDirectory=True) self._model, self._picker = picker_presets.publishes_from_path( workspace) self._model.register_node_type(ScenePickerNode) self._picker.setMaximumHeight(400) self._picker.nodeChanged.connect(self._on_node_changed) self._picker.setColumnWidths([200] * 10) self.layout().addWidget(self._picker) self._namer = SceneNameWidget(dict(workspace=workspace)) self.layout().addWidget(self._namer) button_layout = Q.HBoxLayout() self.layout().addLayout(button_layout) self._cancel_button = Q.PushButton("Cancel") self._cancel_button.clicked.connect(self._on_cancel_pressed) button_layout.addWidget(self._cancel_button) button_layout.addStretch() self._copy_button = Q.PushButton("Copy") self._copy_button.setEnabled(False) self._copy_button.clicked.connect(self._on_copy_pressed) button_layout.addWidget(self._copy_button) self._open_button = Q.PushButton("Copy and Open") self._open_button.setEnabled(False) self._open_button.clicked.connect(self._on_open_pressed) button_layout.addWidget(self._open_button) self._preview = Preview() self._picker.setPreviewWidget(self._preview) self._picker.updatePreviewWidget.connect(self._on_update_preview)
class Dialog(QtGui.QDialog): def __init__(self, kwargs=None, parent=None): super(Dialog, self).__init__(parent) filename = nuke.root().name() if filename == 'Root': filename = '' self._kwargs = { 'workspace': os.path.dirname(nuke.root().name()), 'filename': filename, 'directory': '', 'warning': nuke.warning, 'error': nuke.error, 'extension': '.nk', } self._kwargs.update(kwargs or {}) self._setupGui() def _setupGui(self): self.setWindowTitle('Save Script to Work Area') self.setLayout(QtGui.QVBoxLayout()) self._pickerModel, self._pickerView = any_task( path=os.path.dirname(nuke.root().name()), extra_node_types=[functools.partial( DirectoryPicker, entity_types=['Task'], template='nuke_scripts_dir', ), ], ) self._pickerView.setFixedSize(600, 250) self._pickerView.setPreviewVisible(False) self._pickerView.nodeChanged.connect(self._pickerNodeChanged) self.layout().addWidget(self._pickerView) # The main widget. self._sceneName = SceneNameWidget(self._kwargs) self.layout().addWidget(self._sceneName) # Save button. self._button = button = QtGui.QPushButton('Save', clicked=self._onSaveClicked) self.layout().addWidget(button) self._pickerNodeChanged(self._pickerView.currentNode()) def show(self): super(Dialog, self).show() self.setMinimumSize(self.size()) self.setMaximumHeight(self.height()) def _pickerNodeChanged(self, node): entity = node.state.get('Shot') or node.state.get('Asset') if entity: self._sceneName.setEntityName(entity.get('code') or entity.get('name')) if 'path' in node.state: self._sceneName.setWorkspace(node.state['workspace']) relpath = os.path.relpath(node.state['path'], node.state['workspace']) self._sceneName.setDirectory(relpath) self._button.setEnabled( 'path' in node.state ) def _onSaveClicked(self, *args): path = os.path.join( self._pickerView.currentNode().state['path'], self._sceneName._namer.get_basename(), ) if not self._checkOverwriteSafety(path): return dir_name = os.path.dirname(path) if not os.path.exists(dir_name): os.makedirs(dir_name) print 'Save to', repr(path) self._save(path) self.close() def _checkOverwriteSafety(self, path): basic = not os.path.exists(path) if basic: return True message = "%s already exists.\nDo you want to replace it?" % os.path.basename(path) return nuke.ask(message) def _save(self, path): nuke.scriptSaveAs(path, 1)
class Dialog(QtGui.QDialog): def __init__(self, kwargs=None, parent=None): super(Dialog, self).__init__(parent) filename = nuke.root().name() if filename == 'Root': filename = '' self._kwargs = { 'workspace': os.path.dirname(nuke.root().name()), 'filename': filename, 'directory': '', 'warning': nuke.warning, 'error': nuke.error, 'extension': '.nk', } self._kwargs.update(kwargs or {}) self._setupGui() def _setupGui(self): self.setWindowTitle('Save Script to Work Area') self.setLayout(QtGui.QVBoxLayout()) self._pickerModel, self._pickerView = any_task( path=os.path.dirname(nuke.root().name()), extra_node_types=[ functools.partial( DirectoryPicker, entity_types=['Task'], template='nuke_scripts_dir', ), ], ) self._pickerView.setFixedSize(600, 250) self._pickerView.setPreviewVisible(False) self._pickerView.nodeChanged.connect(self._pickerNodeChanged) self.layout().addWidget(self._pickerView) # The main widget. self._sceneName = SceneNameWidget(self._kwargs) self.layout().addWidget(self._sceneName) # Save button. self._button = button = QtGui.QPushButton('Save', clicked=self._onSaveClicked) self.layout().addWidget(button) self._pickerNodeChanged(self._pickerView.currentNode()) def show(self): super(Dialog, self).show() self.setMinimumSize(self.size()) self.setMaximumHeight(self.height()) def _pickerNodeChanged(self, node): entity = node.state.get('Shot') or node.state.get('Asset') if entity: self._sceneName.setEntityName( entity.get('code') or entity.get('name')) if 'path' in node.state: self._sceneName.setWorkspace(node.state['workspace']) relpath = os.path.relpath(node.state['path'], node.state['workspace']) self._sceneName.setDirectory(relpath) self._button.setEnabled('path' in node.state) def _onSaveClicked(self, *args): path = os.path.join( self._pickerView.currentNode().state['path'], self._sceneName._namer.get_basename(), ) if not self._checkOverwriteSafety(path): return dir_name = os.path.dirname(path) if not os.path.exists(dir_name): os.makedirs(dir_name) print 'Save to', repr(path) self._save(path) self.close() def _checkOverwriteSafety(self, path): basic = not os.path.exists(path) if basic: return True message = "%s already exists.\nDo you want to replace it?" % os.path.basename( path) return nuke.ask(message) def _save(self, path): nuke.scriptSaveAs(path, 1)
class Dialog(Q.Widgets.Dialog): def __init__(self, path=None): super(Dialog, self).__init__() self._node = None self._path = path self._setup_ui() def _setup_ui(self): self.setWindowTitle("Copy Publish to Work Area") self.setLayout(Q.VBoxLayout()) self._workspace = workspace = self._path or cmds.workspace( q=True, rootDirectory=True) self._model, self._picker = picker_presets.publishes_from_path( workspace) self._model.register_node_type(ScenePickerNode) self._picker.setMaximumHeight(400) self._picker.nodeChanged.connect(self._on_node_changed) self._picker.setColumnWidths([200] * 10) self.layout().addWidget(self._picker) self._namer = SceneNameWidget(dict(workspace=workspace)) self.layout().addWidget(self._namer) button_layout = Q.HBoxLayout() self.layout().addLayout(button_layout) self._cancel_button = Q.PushButton("Cancel") self._cancel_button.clicked.connect(self._on_cancel_pressed) button_layout.addWidget(self._cancel_button) button_layout.addStretch() self._copy_button = Q.PushButton("Copy") self._copy_button.setEnabled(False) self._copy_button.clicked.connect(self._on_copy_pressed) button_layout.addWidget(self._copy_button) self._open_button = Q.PushButton("Copy and Open") self._open_button.setEnabled(False) self._open_button.clicked.connect(self._on_open_pressed) button_layout.addWidget(self._open_button) self._preview = Preview() self._picker.setPreviewWidget(self._preview) self._picker.updatePreviewWidget.connect(self._on_update_preview) def _on_node_changed(self, node): self._node = node self._enable = 'PublishEvent' in node.state # Button only works when there is a publish. self._copy_button.setEnabled(self._enable) self._open_button.setEnabled(self._enable) if self._enable: self._task_path = self._model.sgfs.path_for_entity( node.state['Task']) publish = node.state.get('PublishEvent') # TODO: Strip this with the scene_name(r)'s tools, when they exist. detail = publish['code'] step_name = publish.fetch('link.Task.step.Step.short_name') if detail.lower().startswith(step_name.lower()): detail = detail[len(step_name):].lstrip('_') self._namer._namer.detail = detail self._namer._namer.extension = ext = os.path.splitext( publish['sg_path'])[1] basename = self._namer._namer.get_basename() self._namer._namer.revision = utils.get_next_revision( os.path.join(self._workspace, 'scenes'), os.path.splitext(basename)[0], ext, 1, ) self._namer.namer_updated() self._namer.update_preview() def _on_update_preview(self, index): node = self._model.node_from_index(index) entity = node.state['PublishEvent'] self._preview.update(entity) def _on_cancel_pressed(self): self.hide() def _on_open_pressed(self): self._on_copy_pressed(open_=True) def _on_copy_pressed(self, state=None, open_=False): src_path = self._node.state.get('maya_scene') if not src_path: publish = self._node.state['PublishEvent'] src_path = publish.fetch('sg_path') dst_path = self._namer._namer.get_path() # TODO: Do this with shutil subprocess.check_call(['cp', src_path, dst_path]) subprocess.check_call(['chmod', 'a+w', dst_path]) self.hide() if open_: # Make sure they want to proceed if there are changes to the file. if cmds.file(q=True, modified=True): res = Q.MessageBox.warning( self, "Unsaved Changes", "Would you like to save your changes before opening the copied file?", Q.MessageBox.Save | Q.MessageBox.No | Q.MessageBox.Cancel, Q.MessageBox.Save) if res & Q.MessageBox.Cancel: return if res & Q.MessageBox.Save: cmds.file(save=True) cmds.file(dst_path, open=True, force=True)