def create_custom_shortcuts_xml(name): shortcuts = etree.parse( _get_shortcut_file_fullpath(editorpersistance.prefs.shortcuts)) # Get numbered custom shortuts file path lowest_ver_number = 0 custom_files = os.listdir(userfolders.get_data_dir() + "/" + appconsts.USER_SHORTCUTS_DIR) for f in custom_files: dot_pos = f.find(".") num_str = f[len(CUSTOM_SHORTCUTS_FILE_NAME_START):dot_pos] if int(num_str) > lowest_ver_number: lowest_ver_number = int(num_str) new_custom_file_name = CUSTOM_SHORTCUTS_FILE_NAME_START + str( lowest_ver_number + 1) + ".xml" new_shortcuts_file_path = userfolders.get_data_dir( ) + "/" + appconsts.USER_SHORTCUTS_DIR + new_custom_file_name # Verify if the file has the right format root = shortcuts.getroot() root.set('name', name) root.set('editable', 'True') shortcuts.write(new_shortcuts_file_path) return new_custom_file_name
def _get_disk_dir_panels(): panels = [] panels.append( DiskFolderManagementPanel(userfolders.get_cache_dir(), appconsts.AUDIO_LEVELS_DIR, _("Audio Levels Data"), RECREATE_WARNING)) panels.append( DiskFolderManagementPanel(userfolders.get_cache_dir(), appconsts.GMIC_DIR, _("G'Mic Tool Session Data"), NO_WARNING)) panels.append( DiskFolderManagementPanel(userfolders.get_data_dir(), appconsts.RENDERED_CLIPS_DIR, _("Rendered Files"), PROJECT_DATA_WARNING)) panels.append( DiskFolderManagementPanel(userfolders.get_cache_dir(), appconsts.THUMBNAILS_DIR, _("Thumbnails"), RECREATE_WARNING)) panels.append( DiskFolderManagementPanel(userfolders.get_data_dir(), appconsts.USER_PROFILES_DIR_NO_SLASH, _("User Created Custom Profiles"), PROJECT_DATA_WARNING)) return panels
def _fluxity_unredered_media_creation_complete(created_unrendered_clip_path, container_clip_data): # This called from inside Gdk.threads_enter(), entering second time here crashes. # Now that unrendered media has been created we have full container data info. data_object = container_clip_data.data_slots["fluxity_plugin_edit_data"] container_clip_data.editable = True container_clip_data.unrendered_length = data_object["length"] container_clip_data.unrendered_media = created_unrendered_clip_path container_clip_data.unrendered_type = appconsts.VIDEO # Copy created unred rand_id_str = str(os.urandom(16)) clip_id_str = hashlib.md5(rand_id_str.encode('utf-8')).hexdigest() unrendered_clip_path = userfolders.get_data_dir( ) + appconsts.CONTAINER_CLIPS_UNRENDERED + "/" + clip_id_str + ".mp4" os.replace(created_unrendered_clip_path, unrendered_clip_path) container_clip_data.unrendered_media = unrendered_clip_path container_clip_data.unrendered_type = appconsts.VIDEO container_clip = ContainerClipMediaItem(PROJECT().next_media_file_id, data_object["name"], container_clip_data) PROJECT().add_container_clip_media_object(container_clip) _update_gui_for_media_object_add()
def run(self): # Launch render process and wait for it to end FLOG = open(userfolders.get_data_dir() + "log_audio_levels_render", 'w') # Sep-2018 - SvdB - Added self. to be able to access the thread through 'process' self.process = subprocess.Popen([sys.executable, respaths.LAUNCH_DIR + "flowbladeaudiorender", \ self.rendered_media, self.profile_desc, respaths.ROOT_PATH], \ stdin=FLOG, stdout=FLOG, stderr=FLOG) self.process.wait() Gdk.threads_enter() updater.repaint_tline() Gdk.threads_leave()
def load_profile_list(): """ Creates a list of MLT profile objects. Called at app start. """ global _profile_list,_factory_profiles, _hidden_factory_profiles, \ _user_profiles, _proxy_profiles, _categorized_profiles user_profiles_dir = userfolders.get_data_dir() + USER_PROFILES_DIR _user_profiles = _load_profiles_list(user_profiles_dir) _load_factory_profiles() _profile_list = _factory_profiles + _user_profiles _profile_list.sort(key=_sort_profiles) _factory_profiles.sort(key=_sort_profiles) _hidden_factory_profiles.sort(key=_sort_profiles) _user_profiles.sort(key=_sort_profiles) # Build categorized representation of available profiles. HD_profiles = [] HD720_profiles = [] UHD_profiles = [] SD_profiles = [] OTHER_profiles = [] for prof in _profile_list: desc, mlt_profile = prof if desc.startswith("HD") and not desc.startswith( "HDV") and not desc.startswith("HD 720p"): HD_profiles.append(desc) elif desc.startswith("HD 720p"): HD720_profiles.append(desc) elif desc.startswith("4K UHD"): UHD_profiles.append(desc) elif desc.startswith("DV/DVD"): SD_profiles.append(desc) else: OTHER_profiles.append(desc) if len(HD_profiles) > 0: _categorized_profiles.append(("HD", HD_profiles)) if len(HD720_profiles) > 0: _categorized_profiles.append(("HD 720p", HD720_profiles)) if len(UHD_profiles) > 0: _categorized_profiles.append(("4K UHD", UHD_profiles)) if len(SD_profiles) > 0: _categorized_profiles.append(("SD", SD_profiles)) if len(OTHER_profiles) > 0: _categorized_profiles.append(("Other", OTHER_profiles)) if len(_user_profiles) > 0: _categorized_profiles.append(("User Custom", _user_profiles))
def _blender_unredered_media_creation_complete(created_unrendered_clip_path, container_clip_data): rand_id_str = str(os.urandom(16)) clip_id_str = hashlib.md5(rand_id_str.encode('utf-8')).hexdigest() unrendered_clip_path = userfolders.get_data_dir() + appconsts.CONTAINER_CLIPS_UNRENDERED +"/"+ clip_id_str + ".mp4" os.replace(created_unrendered_clip_path, unrendered_clip_path) # Now that unrendere media has been created we have full container data info. container_clip_data.unrendered_media = unrendered_clip_path container_clip_data.unrendered_type = appconsts.VIDEO container_clip = ContainerClipMediaItem(PROJECT().next_media_file_id, container_clip_data.get_program_name(), container_clip_data) PROJECT().add_container_clip_media_object(container_clip) _update_gui_for_media_object_add()
def load_shortcut_files(): global shortcut_files, shortcut_files_display_names default_shortcuts_file_found = False loadable_shortcuts_files = os.listdir( respaths.SHORTCUTS_PATH) + os.listdir(userfolders.get_data_dir() + "/" + appconsts.USER_SHORTCUTS_DIR) for f in loadable_shortcuts_files: format_error = True if f[-4:] == '.xml': # Get full path for either presets file on user custom shortcuts file. full_path = _get_shortcut_file_fullpath(f) # We have a valid file name. Now inspect the file for a valid format before loading it shortcuts = etree.parse(full_path) # Verify if the file has the right format root = shortcuts.getroot() # Check the 'tag' is flowblade if root.tag == appconsts.SHORTCUTS_ROOT_TAG: # Check if this is a shortcuts file if root.get('file') == appconsts.SHORTCUTS_TAG: # Get name and comments file_len = len(f) - 4 # Default file is added last to always be at index 0 if f != DEFAULT_SHORTCUTS_FILE: shortcut_files.append(f) shortcut_files_display_names.append(root.get('name')) format_error = False else: # This is added below to index 0 default_shortcuts_file_found = True format_error = False else: format_error = False print("Shortcuts file " + f + " found, but ignored.") if format_error: print("Shortcuts file " + f + " found, but has incorrect format.") # Default shortcuts file always goes to index 0 if default_shortcuts_file_found == True: # this is a bit unnecessery, it is there unless someone destroys it manually shortcut_files.insert(0, DEFAULT_SHORTCUTS_FILE) shortcut_files_display_names.insert(0, "Flowblade Default") print("Valid shortcut files found: " + str(shortcut_files))
def load_profile_list(): """ Creates a list of MLT profile objects. Called at app start. """ global _profile_list, _factory_profiles, _hidden_factory_profiles, _user_profiles, _proxy_profiles user_profiles_dir = userfolders.get_data_dir() + USER_PROFILES_DIR _user_profiles = _load_profiles_list(user_profiles_dir) _load_factory_profiles() _profile_list = _factory_profiles + _user_profiles _profile_list.sort(key=_sort_profiles) _factory_profiles.sort(key=_sort_profiles) _hidden_factory_profiles.sort(key=_sort_profiles) _user_profiles.sort(key=_sort_profiles)
def _add_fluxity_rendered_help_media_complete(created_unrendered_clip_path, container_data): rand_id_str = str(os.urandom(16)) clip_id_str = hashlib.md5(rand_id_str.encode('utf-8')).hexdigest() unrendered_clip_path = userfolders.get_data_dir( ) + appconsts.CONTAINER_CLIPS_UNRENDERED + "/" + clip_id_str + ".mp4" os.replace(created_unrendered_clip_path, unrendered_clip_path) container_data.unrendered_media = unrendered_clip_path container_data.unrendered_type = appconsts.VIDEO throw_away_clip = current_sequence().create_file_producer_clip( unrendered_clip_path, "dummy", False, None) throw_away_clip.container_data = container_data throw_away_clip.container_data.generate_clip_id() action_object = containeractions.get_action_object(container_data) action_object.plugin_create_render_complete_callback = _plugin_create_render_complete_callback action_object.render_full_media(throw_away_clip)
def _profiles_delete_confirm_callback(dialog, response_id, data): if response_id != Gtk.ResponseType.ACCEPT: dialog.destroy() return user_profiles_view, delete_indexes = data for i in delete_indexes: pname, profile = mltprofiles.get_user_profiles()[i] profile_file_name = pname.lower().replace(os.sep, "_").replace(" ","_") profile_path = userfolders.get_data_dir() + mltprofiles.USER_PROFILES_DIR + profile_file_name print profile_path try: os.remove(profile_path) except: # This really should not happen print "removed user profile already gone ???" mltprofiles.load_profile_list() user_profiles_view.fill_data_model(mltprofiles.get_user_profiles()) dialog.destroy()
def _profiles_delete_confirm_callback(dialog, response_id, data): if response_id != Gtk.ResponseType.ACCEPT: dialog.destroy() return user_profiles_view, delete_indexes = data for i in delete_indexes: pname, profile = mltprofiles.get_user_profiles()[i] profile_file_name = pname.lower().replace(os.sep, "_").replace(" ","_") profile_path = userfolders.get_data_dir() + mltprofiles.USER_PROFILES_DIR + profile_file_name try: os.remove(profile_path) except: # This really should not happen print("removed user profile already gone ???") mltprofiles.load_profile_list() user_profiles_view.fill_data_model(mltprofiles.get_user_profiles()) dialog.destroy()
def _save_profile_clicked(widgets, user_profiles_view): load_profile_combo, description, f_rate_num, f_rate_dem, width, height, \ s_rate_num, s_rate_dem, d_rate_num, d_rate_dem, progressive = widgets profile_file_name = description.get_text().lower().replace(os.sep, "_").replace( " ", "_") file_contents = "description=" + description.get_text() + "\n" file_contents += "frame_rate_num=" + f_rate_num.get_text() + "\n" file_contents += "frame_rate_den=" + f_rate_dem.get_text() + "\n" file_contents += "width=" + width.get_text() + "\n" file_contents += "height=" + height.get_text() + "\n" if progressive.get_active() == True: prog_val = "1" else: prog_val = "0" file_contents += "progressive=" + prog_val + "\n" file_contents += "sample_aspect_num=" + s_rate_num.get_text() + "\n" file_contents += "sample_aspect_den=" + s_rate_dem.get_text() + "\n" file_contents += "display_aspect_num=" + d_rate_num.get_text() + "\n" file_contents += "display_aspect_den=" + d_rate_dem.get_text() + "\n" profile_path = userfolders.get_data_dir( ) + mltprofiles.USER_PROFILES_DIR + profile_file_name if os.path.exists(profile_path): dialogutils.warning_message(_("Profile '") + description.get_text() + _("' already exists!"), \ _("Delete profile and save again."), gui.editor_window.window) return profile_file = open(profile_path, "w") profile_file.write(file_contents) profile_file.close() dialogutils.info_message(_("Profile '") + description.get_text() + _("' saved."), \ _("You can now create a new project using the new profile."), gui.editor_window.window) mltprofiles.load_profile_list() render.reload_profiles() user_profiles_view.fill_data_model(mltprofiles.get_user_profiles())
def update_custom_shortcuts(xml_file): # If new shortcuts have been added and user is using custom shortcuts when updating, we need to update customn shortcuts. custom_files = os.listdir(userfolders.get_data_dir() + "/" + appconsts.USER_SHORTCUTS_DIR) if not (xml_file in custom_files): return test_root = get_shortcuts_xml_root_node(xml_file) def_root = get_shortcuts_xml_root_node(DEFAULT_SHORTCUTS_FILE) for code, action_name in _keyboard_action_names.items(): key_name_test, action_name = get_shortcut_info(test_root, code) key_name_def, action_name = get_shortcut_info(def_root, code) if key_name_test != key_name_def: events = def_root.iter('event') for event in events: if event.get('code') == code: key_val_name = event.text mods_list = event.get('modifiers') change_custom_shortcut(code, key_val_name, [mods_list], True)
def _save_profile_clicked(widgets, user_profiles_view): load_profile_combo, description, f_rate_num, f_rate_dem, width, height, \ s_rate_num, s_rate_dem, d_rate_num, d_rate_dem, progressive = widgets profile_file_name = description.get_text().lower().replace(os.sep, "_").replace(" ","_") file_contents = "description=" + description.get_text() + "\n" file_contents += "frame_rate_num=" + f_rate_num.get_text() + "\n" file_contents += "frame_rate_den=" + f_rate_dem.get_text() + "\n" file_contents += "width=" + width.get_text() + "\n" file_contents += "height=" + height.get_text() + "\n" if progressive.get_active() == True: prog_val = "1" else: prog_val = "0" file_contents += "progressive=" + prog_val + "\n" file_contents += "sample_aspect_num=" + s_rate_num.get_text() + "\n" file_contents += "sample_aspect_den=" + s_rate_dem.get_text() + "\n" file_contents += "display_aspect_num=" + d_rate_num.get_text() + "\n" file_contents += "display_aspect_den=" + d_rate_dem.get_text() + "\n" profile_path = userfolders.get_data_dir() + mltprofiles.USER_PROFILES_DIR + profile_file_name if os.path.exists(profile_path): dialogutils.warning_message(_("Profile '") + description.get_text() + _("' already exists!"), \ _("Delete profile and save again."), gui.editor_window.window) return profile_file = open(profile_path, "w") profile_file.write(file_contents) profile_file.close() dialogutils.info_message(_("Profile '") + description.get_text() + _("' saved."), \ _("You can now create a new project using the new profile."), gui.editor_window.window) mltprofiles.load_profile_list() render.reload_profiles() user_profiles_view.fill_data_model(mltprofiles.get_user_profiles())
def get_container_clips_dir(self): return userfolders.get_data_dir() + appconsts.CONTAINER_CLIPS_DIR
def main(root_path, session_id, script, clip_path, range_in, range_out, profile_desc): os.nice(10) prints_to_log_file("/home/janne/gmicheadless") print(session_id, script, clip_path, range_in, range_out, profile_desc) try: editorstate.mlt_version = mlt.LIBMLT_VERSION except: editorstate.mlt_version = "0.0.99" # magic string for "not found" # Set paths. respaths.set_paths(root_path) # Check G'MIC version global _gmic_version _gmic_version = get_gmic_version() if _gmic_version == 2: respaths.set_gmic2(root_path) userfolders.init() editorpersistance.load() global _session_folder, _clip_frames_folder _session_folder = userfolders.get_data_dir( ) + appconsts.CONTAINER_CLIPS_DIR + "/" + session_id _clip_frames_folder = _session_folder + "/clip_frames" # Init gmic session dirs if not os.path.exists(_session_folder): os.mkdir(_session_folder) if not os.path.exists(_clip_frames_folder): os.mkdir(_clip_frames_folder) # Init translations module with translations data translations.init_languages() translations.load_filters_translations() mlttransitions.init_module() repo = mlt.Factory().init() processutils.prepare_mlt_repo(repo) # Set numeric locale to use "." as radix, MLT initilizes this to OS locale and this causes bugs locale.setlocale(locale.LC_NUMERIC, 'C') # Check for codecs and formats on the system mltenv.check_available_features(repo) renderconsumer.load_render_profiles() # Load filter and compositor descriptions from xml files. mltfilters.load_filters_xml(mltenv.services) mlttransitions.load_compositors_xml(mltenv.transitions) # Create list of available mlt profiles mltprofiles.load_profile_list() # Launch server DBusGMainLoop(set_as_default=True) loop = GLib.MainLoop() global _dbus_service _dbus_service = GMicHeadlessDBUSService(loop, session_id, script, clip_path, range_in, range_out, profile_desc) print("tline render service running") loop.run()
def _get_shortcut_file_fullpath(f): full_path = respaths.SHORTCUTS_PATH + f if os.path.isfile(full_path) == False: full_path = userfolders.get_data_dir( ) + "/" + appconsts.USER_SHORTCUTS_DIR + f return full_path
def _get_tline_render_dir(): return userfolders.get_data_dir() + appconsts.TLINE_RENDERS_DIR
def _get_session_folder(session_id): return userfolders.get_data_dir() + appconsts.CONTAINER_CLIPS_DIR + "/" + session_id