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 dump_cache(data, yaml_file=CACHE_YAML): ''' Dump a dictionary data into the yaml_file ''' cache_file = path.get_config_yaml(yaml_file) parsed_data = dict() if os.path.isfile(cache_file): parsed_data = _parse_yaml(cache_file) if not (isinstance(data, dict) or data == 'clear'): return if data == 'clear': print 'should clear' with codecs.open(cache_file, 'w', encoding='utf-8') as f_out: yaml.safe_dump(dict(), f_out, default_flow_style=False) return if parsed_data: parsed_data.update(data) data = parsed_data with codecs.open(cache_file, 'w', encoding='utf-8') as f_out: yaml.safe_dump(data, f_out, default_flow_style=False)
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 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 install(): ''' Dynamically create and load the shelf in maya ''' yaml_shelf_file = path.get_config_yaml(yaml_shelf) icon_path = path.get_image_folder() load(yaml_shelf_file, shelf_name)
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 read_cache(key, yaml_file=CACHE_YAML): ''' Get the value of a key from the yaml_file ''' cache_file = path.get_config_yaml(yaml_file) if os.path.isfile(cache_file): parsed_data = _parse_yaml(cache_file) else: raise RuntimeError( 'Could not read or find %s\nPlease provide valid yaml file.' % cache_file) if isinstance(parsed_data, dict): return parsed_data.get(key)
def playblast_with_settings(viewport_preset=None, viewport_preset_yaml=None, **recArgs): ''' Playblast with the user-defined settings recArgs are the arguments needed for the capture command ''' # get default viewport preset config if viewport_preset and viewport_preset_yaml: cache_file = path.get_config_yaml(viewport_preset_yaml) viewportArgs = database.read_cache(viewport_preset, cache_file) else: viewportArgs = {} # process filenames filepath = recArgs["filename"] if not filepath: filepath = path.get_default_playblast_folder() filepath = path.sanitize(filepath) filepath_with_ext = add_extension(filepath, recArgs) if is_file_on_disk( filepath_with_ext) and not recArgs.get("force_overwrite"): filename = os.path.split(filepath_with_ext)[-1] message = '[{}] already exists.\nDo you want to replace it?'.format( filename) if not confirm_overwrite_dialogue(message) == 'yes': return recArgs["show_ornaments"] = False recArgs["viewer"] = False # merge with viewport args viewport_options = viewportArgs.copy() viewport_options.update(recArgs) logger.info("viewport_options: {}".format(viewport_options)) playblast_file = capture.capture(**viewport_options) if playblast_file: playblast_file = add_extension(playblast_file, recArgs) recArgs["filename"] = playblast_file database.save_last_recorded(recArgs) database.dump_cache({"last_recorded_selection": playblast_file}) logger.info('Find your recorded file here: {}'.format(playblast_file)) return playblast_file else: logger.info("playblast_with_settings failed")
def get_playground_email(): ''' Get the email address for the playground notification ''' cache_file = path.get_config_yaml(CACHE_YAML) if os.path.isfile(cache_file): parsed_data = _parse_yaml(cache_file) if isinstance(parsed_data, dict): playground_email = parsed_data.get('playground_email') if isinstance(playground_email, str): return playground_email
def delete_key_from_cache(key, yaml_file=CACHE_YAML): ''' Delete the key value pair from the yaml_file ''' cache_file = path.get_config_yaml(yaml_file) if os.path.isfile(cache_file): parsed_data = _parse_yaml(cache_file) else: raise RuntimeError('Please provide valid yaml file.') if key in parsed_data: del parsed_data[key] dump_cache('clear', yaml_file) dump_cache(parsed_data, yaml_file) print "Deleted preset %s from %s" % (key, CACHE_YAML)
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 save_cache(key, value, yaml_file=CACHE_YAML): ''' Set the value of a key from the yaml_file ''' data = {key: value} cache_file = path.get_config_yaml(yaml_file) parsed_data = dict() if os.path.isfile(cache_file): parsed_data = _parse_yaml(cache_file) if not isinstance(data, dict) or data == 'clear': return if parsed_data: parsed_data.update(data) data = parsed_data with codecs.open(cache_file, 'w', encoding='utf-8') as f_out: yaml.safe_dump(data, f_out, default_flow_style=False)
def save_playground_email(email_address): ''' Set the playground_email key and value ''' data = {'playground_email': email_address} cache_file = path.get_config_yaml(CACHE_YAML) parsed_data = dict() if os.path.isfile(cache_file): parsed_data = _parse_yaml(cache_file) if not isinstance(data, dict) or data == 'clear': return if parsed_data: parsed_data.update(data) data = parsed_data with codecs.open(cache_file, 'w', encoding='utf-8') as f_out: yaml.safe_dump(data, f_out, default_flow_style=False)
def rename_key_in_cache(old_key, new_key, yaml_file=CACHE_YAML): ''' Delete the key value pair from the yaml_file ''' cache_file = path.get_config_yaml(yaml_file) if os.path.isfile(cache_file): parsed_data = _parse_yaml(cache_file) else: raise RuntimeError('Please provide valid yaml file.') if not parsed_data: return if new_key in parsed_data.keys(): return # raise RuntimeError('Key %s already exists in cache'%new_key) parsed_data[new_key] = parsed_data.pop(old_key) dump_cache('clear', yaml_file) dump_cache(parsed_data, yaml_file) return new_key
def apply_viewport_preset(preset_name): cache = path.get_config_yaml(VIEWPORT_PRESET_YAML) maya_scene.apply_viewport_preset(cache, preset_name)
def new_viewport_preset(preset_name=None, source_preset=None): cache = path.get_config_yaml(VIEWPORT_PRESET_YAML) maya_scene.new_viewport_preset(cache, preset_name=None, source_preset="1", panel=None)
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