def cycle_viewport_presets(): cache = path.get_config_yaml(VIEWPORT_PRESET_YAML) presets = database._parse_yaml(cache).keys() current_viewport_preset = database.read_cache('current_viewport_preset') logger.info(presets) l = len(presets) i = 0 if current_viewport_preset in presets: for k in range(l): i = k logger.info("presets[%s] %s" % (i, presets[i])) if current_viewport_preset == presets[i]: logger.info("%s is a match" % i) break else: i = 0 i += 1 if i >= l: i = 0 database.save_cache('current_viewport_preset', presets[i], yaml_file=CACHE_YAML) maya_scene.apply_viewport_preset(cache, presets[i])
def refresh_menu_state(): ''' If before_login is the given state, some parts of the menu will be greyed out. If after_login, all parts of the menu will be enabled and accessible. ''' current_user = user.SyncSketchUser() username = current_user.get_name() login_info = 'Currently not logged in' if username: login_info = 'Logged in as: [{}]'.format(username) # Parse the yaml file and get the menu items as a dictionary yaml_path = path.get_config_yaml(yaml_file) data = database._parse_yaml(yaml_path) if not data: return if not isinstance(data, dict): return # Build menus from the parsed data menu_tops = data.keys() for menu_top in menu_tops: menu_top_name = _make_object_name(menu_top) if not cmds.menuItem('logged_in_as', exists=True): cmds.menuItem('logged_in_as', parent=menu_top_name) cmds.menuItem('logged_in_as', edit=True, enable=False, label=login_info)
def rename_preset(self): title = 'Renaming Preset' message = 'Please choose a name for this preset.' old_preset_name = self.ui.ui_formatPreset_comboBox.currentText() new_preset_name, response = QtWidgets.QInputDialog.getText( self, "Rename this preset", "Please enter a new Name:", QtWidgets.QLineEdit.Normal, old_preset_name) if not new_preset_name: logger.info("No new preset name specified") return preset_file = path.get_config_yaml(PRESET_YAML) current_preset_names = database._parse_yaml(preset_file).keys() if new_preset_name in current_preset_names: title = 'Error Renaming' message = 'It appears this name already exists.' WarningDialog(self, title, message) return logger.info("Rename Preset from {} to {}".format( old_preset_name, new_preset_name)) database.rename_key_in_cache(old_preset_name, new_preset_name, preset_file) if database.read_cache("current_preset") == old_preset_name: self._update_current_preset(new_preset_name) self.populate_ui() self.ui.ui_formatPreset_comboBox.set_combobox_index( selection=new_preset_name)
def build_menu(): ''' Build and populate the menus based on the yaml file ''' # Parse the yaml file and get the menu items as a dictionary yaml_path = path.get_config_yaml(yaml_file) data = database._parse_yaml(yaml_path) if not data: _show_error('Invalid YAML data.') return if not isinstance(data, dict): return # Build menus from the parsed data menu_tops = data.keys() # Create the menu tops for menu_top in menu_tops: _add_menu_top(menu_top) # Populate the first menus for menu_top in menu_tops: menu_data = data.get(menu_top) if menu_data: _populate_menus(menu_data, menu_top) # Populate the second menus second_menus = list() for menu_top in menu_tops: menu_data = data.get(menu_top) if not menu_data: continue for second_menu in menu_data: if isinstance(second_menu, dict): second_menus.append(second_menu) for second_menu in second_menus: second_menu_data = second_menu.values()[0] second_menu_parent = second_menu.keys()[0] if isinstance(second_menu_data, list): _populate_menus(second_menu_data, second_menu_parent) # Populate the third menus third_menus = list() for second_menu in second_menus: for third_menu_list in second_menu.values(): for third_menu in third_menu_list: if isinstance(third_menu, dict): third_menus.append(third_menu) for third_menu in third_menus: third_menu_data = third_menu.values()[0] third_menu_parent = third_menu.keys()[0] if isinstance(third_menu_data, list): _populate_menus(third_menu_data, third_menu_parent)
def new_viewport_preset(cache_file, preset_name=None, source_preset=None, panel=None): preset_data = database._parse_yaml(cache_file) if not preset_data: preset_data = {} existing_keys = preset_data.keys() if source_preset and source_preset in existing_keys: options = database.read_cache(source_preset, cache_file) if not preset_name: preset_name = 'Copy of ' + source_preset else: if not panel: panel = get_active_editor() options = capture.parse_view(panel) if not preset_name or preset_name in existing_keys: logger.info('key exists') preset_name = create_unique_name(existing_keys, new_key = preset_name, suffix = 'Preset') logger.info(preset_name) if not options: options = capture.parse_view(panel) else: preset_data[preset_name] = options logger.info("preset_name %s" + preset_name) preset_data[preset_name] = options database.dump_cache(preset_data, cache_file) return preset_name
def save(self): presetFile = path.get_config_yaml(PRESET_YAML) presetData = database._parse_yaml(presetFile) presetName = self.ui.ui_formatPreset_comboBox.currentText() format = self.ui.format_comboBox.currentText() encoding = self.ui.encoding_comboBox.currentText() width = self.ui.width_spinBox.value() height = self.ui.height_spinBox.value() newData = dict() if presetName == DEFAULT_PRESET: newData = {'current_preset': presetName} else: newData = { 'current_preset': presetName, presetName: { 'encoding': encoding, 'format': format, 'height': height, 'width': width } } if presetData: presetData.update(newData) else: presetData = newData with codecs.open(presetFile, 'w', encoding='utf-8') as f_out: yaml.safe_dump(presetData, f_out, default_flow_style=False) self.parent.ui.ui_formatPreset_comboBox.populate_combo_list( PRESET_YAML, presetName) self.close()
def _get_from_yaml_user(key): ''' Get the given key's value from the user's local yaml file ''' yaml_path = path.get_config_yaml(yaml_file) if not os.path.isfile(yaml_path): return user_data = database._parse_yaml(yaml_path) return user_data.get(key)
def load_preset(self, presetName=None): """ Load the user's current preset from yaml """ presetFile = path.get_config_yaml(PRESET_YAML) logger.info("reading YAML: {}".format(presetFile)) presetData = database._parse_yaml(presetFile) if not presetData: return if not presetName: self.ui.ui_formatPreset_comboBox.set_combobox_index( selection=database.read_cache('current_preset')) self.ui.format_comboBox.set_combobox_index(selection='avi') self.ui.encoding_comboBox.set_combobox_index(selection='none') self.ui.width_spinBox.setValue(1280) self.ui.height_spinBox.setValue(720) elif presetName == DEFAULT_PRESET: self.ui.ui_formatPreset_comboBox.set_combobox_index( selection=DEFAULT_PRESET) if sys.platform == 'darwin': format = 'avfoundation' encoding = 'H.264' elif sys.platform == 'linux2': format = 'movie' encoding = 'H.264' elif sys.platform == 'win32': format = 'avi' encoding = 'none' else: preset = presetData.get(presetName) logger.info("presetName: {}, preset: {} presetData: {}".format( presetName, preset, presetData)) if not preset: return logger.info(preset) format = preset.get('format') encoding = preset.get('encoding') width = preset.get('width') height = preset.get('height') self.ui.ui_formatPreset_comboBox.set_combobox_index( selection=presetName) self.ui.format_comboBox.set_combobox_index(selection=format) self.ui.encoding_comboBox.set_combobox_index(selection=encoding) self.ui.width_spinBox.setValue(width) self.ui.height_spinBox.setValue(height)
def populate_combo_list(self, file, defaultValue=None, currentValue='current preset'): combo_file = path.get_config_yaml(file) combo_data = database._parse_yaml(combo_file) if not combo_data: return combo_items = combo_data.keys() if not combo_items: return self.clear() self.addItems(combo_items) current_preset = combo_data.get(currentValue) self.set_combobox_index(selection=current_preset, default=defaultValue)
def delete_preset(self): preset_file = path.get_config_yaml(PRESET_YAML) preset_name = self.ui.ui_formatPreset_comboBox.currentText() database.delete_key_from_cache(preset_name, preset_file) current_preset = database.read_cache("current_preset") if current_preset == preset_name: current_preset_names = database._parse_yaml(preset_file).keys() new_preset_name = current_preset_names[0] self._update_current_preset(new_preset_name) else: self._update_current_preset(current_preset) self.populate_ui() self.ui.ui_formatPreset_comboBox.set_combobox_index(0)
def delete_menu(): ''' Delete the menu tops based on the yaml file ''' # Parse the yaml file and get the menu items as a dictionary yaml_path = path.get_config_yaml(yaml_file) data = database._parse_yaml(yaml_path) if not data: _show_error('Invalid YAML data.') return # Get menus from the parsed data menu_tops = data.keys() # Create the menu tops for menu_top in menu_tops: _delete_menu_top(menu_top)
def _set_to_yaml_user(key, value): ''' Set the given dictionary to the user's local yaml file ''' yaml_path = path.get_config_yaml(yaml_file) if not os.path.isfile(yaml_path): yaml_path = open(yaml_path, 'w') existing_data = dict() user_data = {str(key): str(value)} if os.path.isfile(yaml_path): existing_data = database._parse_yaml(yaml_path) if existing_data: user_data = _merge_dictionaries(existing_data, user_data) with open(yaml_path, 'w') as outfile: new_data = yaml.dump(user_data, default_flow_style=False) outfile.write(new_data)
def new_preset(self): """Create a new preset""" title = 'Creating Preset' message = 'Please choose a name for this preset.' user_input = InputDialog(self, title, message) if not user_input.response: return preset_name = user_input.response_text if not preset_name: logger.info("No new preset name specified") return preset_file = path.get_config_yaml(PRESET_YAML) current_preset_names = database._parse_yaml(preset_file).keys() if preset_name in current_preset_names: title = 'Error Creating' message = 'It appears this name already exists.' WarningDialog(self, title, message) return width, height = maya_scene.get_render_resolution() encoding = maya_scene.get_playblast_encoding() format = maya_scene.get_playblast_format() preset_data = { preset_name: { 'encoding': encoding, 'format': format, 'height': height, 'width': width } } logger.info("Create Format Preset from {}".format(preset_name)) database.dump_cache(preset_data, preset_file) self.populate_ui() self.ui.ui_formatPreset_comboBox.set_combobox_index( selection=preset_name)
def _record(): # filename & path filepath = database.read_cache('ps_directory_lineEdit') filename = database.read_cache('us_filename_lineEdit') clipname = database.read_cache('ps_clipname_lineEdit') if not filepath or not filename: title = 'Playblast Location' message = 'Please specify playblast file name and location.' return qt_widgets.WarningDialog(None, title, message) filepath = os.path.expanduser('~/Desktop/playblasts/') filename = 'playblast' if clipname: filename = filename + clipname filepath = path.sanitize(os.path.join(filepath, filename)) # preset preset_file = path.get_config_yaml(PRESET_YAML) preset_data = database._parse_yaml(preset_file) preset_name = database.read_cache('current_preset') preset = preset_data.get(preset_name) start_frame, end_frame = maya_scene.get_InOutFrames( database.read_cache('current_range_type')) start_frame = database.read_cache('frame_start') end_frame = database.read_cache('frame_end') #setting up args for recording recArgs = { "show_ornaments": False, "start_frame": start_frame, "end_frame": end_frame, "camera": database.read_cache('selected_camera'), "format": preset.get('format'), "viewer": True if database.read_cache('ps_play_after_creation_checkBox') == 'true' else False, "filename": filepath, "width": preset.get('width'), "height": preset.get('height'), "overwrite": True if database.read_cache('ps_force_overwrite_checkBox') == 'true' else False, "compression": preset.get('encoding'), "off_screen": True } logger.info("recArgs: {}".format(recArgs)) # read from database Settings playblast_file = maya_scene.playblast_with_settings( viewport_preset=database.read_cache('current_viewport_preset'), viewport_preset_yaml=VIEWPORT_PRESET_YAML, **recArgs) return playblast_file