def change_struct_dir(): global restructZip, chosen_struct_dir init_dir = restructZip.get_dir_path() dir = filedialog.askdirectory(title="Select a directory", initialdir=init_dir if init_dir != "None" else "/") restructZip.set_dir_path(dir) chosen_struct_dir.set('Chosen Directory: ' + restructZip.get_dir_path()) sys.stdout.flush()
def setMusescoreScoresDefaultFldr(self): fldrPath = tkfd.askdirectory() self._convConfigHandler.writeMusescoreScoresDefaultFldr(fldrPath) self.entMCXMLSrcFldr.configure(state=NORMAL) self.entMCXMLSrcFldr.delete(0, END) self.entMCXMLSrcFldr.insert(0, fldrPath) self.entMCXMLSrcFldr.configure(state="readonly")
def setDefaultDestScoreDir(self): fldrPath = tkfd.askdirectory() self._convConfigHandler.writePlaneShiftScoresDefaultFldr(fldrPath) self.entPSSheetDestFldr.configure(state=NORMAL) self.entPSSheetDestFldr.delete(0, END) self.entPSSheetDestFldr.insert(0, fldrPath) self.entPSSheetDestFldr.configure(state="readonly")
def OnOpen(self): if os.path.isfile("sch.txt"): pass print("found sch.txt") print("playing from this file instead") else: print("sch.txt not found") fullname = askdirectory(initialdir="/", title="Select Directory") if os.path.isdir(fullname): video_frmt = [ '.mp4', '.m4a', '.m4v', '.f4v', '.f4a', '.m4b', '.m4r', '.f4b', '.mov', '.wmv', '.wma', '.asf', '.webm', '.flv', '.avi', '.wav', '.mkv' ] mastr = [] hold = [] mastrw = [] for dir in os.listdir(fullname): dirpath = os.path.join(fullname, dir).replace("\\", "/") for path, directories, files in os.walk(dirpath): for filename in files: name, ext = os.path.splitext(filename) if ext in video_frmt: hold.append( os.path.join(path, filename).replace("\\", "/")) else: pass if len(hold): mastr.append(hold) else: pass hold = [] while mastr: randitem = choice(mastr) if len(randitem): mastrw.append(randitem.pop(0)) else: mastr.remove(randitem) with open('sch.txt', 'w') as f: for fullpath in mastrw: f.write(fullpath + '\n') print("created sch.txt") with open("sch.txt") as flplpay: sch_list = flplpay.read().split('\n') for path_line in sch_list: self.media = vlc.Media(path_line) self.media_list.add_media(self.media) self.media_list_player = vlc.MediaListPlayer() self.media_list_player.set_media_list(self.media_list) print("Created MediaListPlayer") if platform.system() == 'Windows': self.media_list_player.get_media_player().set_hwnd( self.GetHandle()) else: self.media_list_player.get_media_player().set_xwindow( self.GetHandle()) self.OnPlay() self.volslider.set( self.media_list_player.get_media_player().audio_get_volume())
def change_dir(): global imageCombiner global chosen_directory init_dir = imageCombiner.get_dir_path() dir = filedialog.askdirectory(title="Select a directory", initialdir=init_dir if init_dir != "None" else "/") imageCombiner.set_dir_path(dir) chosen_directory.set('Chosen Directory: ' + imageCombiner.get_dir_path()) sys.stdout.flush()
def display(self): # ask for file if not loaded yet if self.df is None: self.load() # display if loaded if self.df is not None: self.folder_selected = filedialog.askdirectory()
def change_label_dir(): global autoLabel, chosen_label_dir init_dir = autoLabel.get_dir_path() dir = filedialog.askdirectory(title="Select a directory", initialdir=init_dir if init_dir != "None" else "/") autoLabel.set_dir_path(dir) chosen_label_dir.set('Chosen Directory: ' + autoLabel.get_dir_path()) sys.stdout.flush()
def OnChooseDir(self): target = fdog.askdirectory(title='Set Working Directory') if target == () or target == '': return self.WidgetsChooser.Data['directory'].set(target) logdir = os.path.join(target, 'output') if os.path.isdir(logdir): self.WidgetsChooser.Data['logdir'].set(logdir) self.DirectoryChanged()
def export(self): if self.data.content: if self.mode.get(): # file mode, export to directory final_loc = dialog.askdirectory() else: final_loc = dialog.asksaveasfile(mode='w', defaultextension=".txt") if self.active['location'] != final_loc and final_loc: if self.mode.get(): self.contacts_lib.dic.export(final_loc) else: self.contacts_lib.dic.merge(final_loc)
def getFolderName(title='Abrir Carpeta', init_dir=os.getcwd(), encima=True): if encima == True: root.wm_attributes('-topmost', True) else: root.wm_attributes('-topmost', False) d_path = filedialog.askdirectory(title=title, initialdir=init_dir) if not d_path == '': return d_path
def browse_dir(self): backup = self.curr_loc if self.mode.get(): self.curr_loc = dialog.askopenfilename() really = False else: self.curr_loc = dialog.askdirectory() really = True if self.curr_loc: self.contacts_lib = ContactList(self.curr_loc, is_dir=really) self.await_load = True else: self.curr_loc = backup # reverting to previous value
def export(self): if self.contacts_lib: if self.mode.get(): # file mode, export to directory final_loc = dialog.askdirectory() else: final_loc = dialog.asksaveasfile(mode='w', defaultextension=".txt") self.contacts_lib.find_duplicates( ) # for sure report them, later do different if self.curr_loc != final_loc and final_loc: if self.mode.get(): self.contacts_lib.export(final_loc) else: self.contacts_lib.merge(final_loc)
def sm(self): backup = self.active['location'] self.active['location'] = dialog.askdirectory() if self.active['location']: _, _, filenames = next(walk(self.active['location'])) for file in filenames: if 'json' in file: # print(self.active['location'] + '/' + file) self.list['values'][file] = self.active['location'] + '/' + file self.list['box'].insert('end', file) self.active['index'] = '' self.await_load = True else: if backup: self.active['location'] = backup # reverting to previous value self.refresh()
def install_examples(): """ Pops up windows to allow the user to choose a directory for installation of sfc_models examples. Uses tkinter, which is installed in base Python (modern versions). :return: """ if not mbox.askokcancel(title='sfc_models Example Installation', message=validate_str): return target = fdog.askdirectory( title='Choose directory to for sfc_models examples installation') if target == () or target == '': return install_example_scripts.install(target)
def browseModDirectory(): rimsheets_support.directory_workshop.set(filedialog.askdirectory())
def select_root_dir(self): # Prompt for new root directory root_dir = fd.askdirectory(mustexist=True) if root_dir is not None and root_dir != self.root_dir: self.set_root_dir(root_dir)
def start(): changelabel("Awaiting File Selection.") source_directory = filedialog.askdirectory( title='Please select a source directory.') mirror_directory = filedialog.askdirectory( title='Please select a mirror directory.') source_files_array = [ os.path.join(r, file) for r, d, f in os.walk(source_directory) for file in f ] mirror_files_array = [ os.path.join(r, file) for r, d, f in os.walk(mirror_directory) for file in f ] update_file_count( sum([len(files) for r, d, files in os.walk(source_directory)])) changelabel(str(total_file_count) + " Total Files Selected. Proceed?") try: # Python2 confirm_result = tkMessageBox.askyesno("Confirm", "Proceed with copy operation?") except: # Python3 confirm_result = messagebox.askyesno("Confirm", "Proceed with copy operation?") if not confirm_result == True: exit() for source_file_path in source_files_array: file_name = os.path.basename(source_file_path) current_source_file_directory = os.path.split(source_file_path)[0] mirror_file_path = source_file_path.replace(source_directory, mirror_directory) current_mirror_file_directory = os.path.split(mirror_file_path)[0] # Checking if directory exists if not os.path.exists(current_mirror_file_directory): print("Directory '" + os.path.basename(current_mirror_file_directory).replace( '/', '\\') + "' doesn't exist, creating.") os.makedirs(current_mirror_file_directory) print("Created directory '" + os.path.dirname(mirror_file_path).replace('/', '\\') + "'.") # Try to copy if not os.path.exists(mirror_file_path): try: copy(source_file_path, mirror_file_path) except Exception as e: print("Failed to copy '" + file_name + "'. Exception: '" + str(e) + "'.") inc_file_counter(2) changelabel("Copying Files.\nProgress: " + str(filescopied + fileshashed + filesfailed) + " of " + str(total_file_count) + ".") else: # Hash file if already exists if hashtype == "MD5": srchash = sha512sum(source_file_path) mirrorhash = sha512sum(mirror_file_path) elif hashtype == "SHA512": srchash = sha512sum(source_file_path) mirrorhash = sha512sum(mirror_file_path) if srchash == mirrorhash: print("File '" + file_name + "'" + " exists. Matching " + hashtype + "SUM!") inc_file_counter(0) changelabel("Copying Files.\nProgress: " + str(filescopied + fileshashed + filesfailed) + " of " + str(total_file_count) + ".") else: # Hash different print("File '" + file_name + "'" + " exists, hash didn't match. Overwriting to '" + os.path.dirname(mirror_file_path).replace('/', '\\') + "'.") try: copy(source_file_path, mirror_file_path) except Exception as e: print("Failed to copy '" + file_name + "'. Exception: '" + str(e) + "'.") inc_file_counter(2) changelabel("Copying Files.\nProgress: " + str(filescopied + fileshashed + filesfailed) + " of " + str(total_file_count) + ".")
def chooseDir(): window.sourceFolder = filedialog.askdirectory( parent=window, initialdir="/", title='Please select a directory')
def OnChooseLogDir(self): target = fdog.askdirectory(title='Set Working Directory') if target == () or target == '': return self.WidgetsChooser.Data['logdir'].set(target) self.Parameters.LogDir = target
def browseDirectory(): rimsheets_support.directory_core.set(filedialog.askdirectory())