def importer(root,pathClearMap,runButtonMain,textVar): """ The importer function copies the parameter, process and settings files to the work_dir directory. It starts looking in the exports folder but if any files were copied it is also possible to point it to another directory :return: If a file is part of a tif stack where the sequence is labeled by a Z followed by a 4 digit number this is found using regex and the code is adjusted to fit these images. """ try: scriptsFolder = askopendirname(parent=root, title="Select scripts", initialdir=pathClearMap + "ClearMap/Scripts/exports/") nameFolder = scriptsFolder.replace(pathClearMap + "ClearMap/Scripts/exports/", "") shutil.copy(scriptsFolder + "/parameter_file.py", pathClearMap + "ClearMap/Scripts/work_dir/") shutil.copy(scriptsFolder + "/process_template.py", pathClearMap + "ClearMap/Scripts/work_dir/") shutil.copy(scriptsFolder + "/savedSettings.txt", pathClearMap + "ClearMap/Scripts/work_dir/") runButtonMain['state'] = 'normal' textVar.set("Imported folder " + nameFolder) with open(pathClearMap + "ClearMap/Scripts/work_dir/savedSettings.txt", "r") as outputFile: data = json.load(outputFile) data['fromImport'] = True with open(pathClearMap + "ClearMap/Scripts/work_dir/savedSettings.txt", "w+") as outputFile: json.dump(data, outputFile) except FileNotFoundError: pass
def cb_open_dir(): ret=askopendirname(parent=root,initialdir=Config["path"]+"/recipe.d",initialfile="") dir=re.sub(r".*/recipe.d","",ret) if dir != "": msg=String() msg.data=dir.replace("/","") cb_load(msg)
def save_location(): path = tkfilebrowser.askopendirname(title='Select the file', filetypes=[('*', '*'), ('PNG', '*.png'), ('JPG', '*.jpg')]) print(f"Path is {path}") return path
def askdirectory(initialdir, title="Ouvrir", **options): """ folder browser: initialdir: directory where the filebrowser is opened """ if tkfb: return tkfb.askopendirname(title=title, initialdir=initialdir, **options) elif ZENITY: try: args = [ "zenity", "--file-selection", "--filename", initialdir, "--directory", "--title", title ] folder = check_output(args).decode("utf-8").strip() return folder except CalledProcessError: return "" except Exception: return filedialog.askdirectory(title=title, initialdir=initialdir, **options) else: return filedialog.askdirectory(title=title, initialdir=initialdir, **options)
def opendir(): global dir_path dir_path = askopendirname(title="Select path", initialdir="C:/") print(dir_path) if len(dir_path) > 0: dir_path = str(dir_path + '\\') path.insert(0, str(dir_path))
def askDir(title): root = tkinter.Tk() root.withdraw() directory = tkfilebrowser.askopendirname(title=title, foldercreation=True) if(directory == ""): tkinter.messagebox.showerror("Error", "No directory selected for saving data. Exiting program.") sys.exit(1) return(directory)
def call_file(root, pathClearMap): """ This is the last function that is called, it runs the process_template file which starts clearmap. It also checks if it should kill the program before it begins by looking at the kill parameter in the saved settings file. :return: """ with open(pathClearMap + "ClearMap/Scripts/work_dir/savedSettings.txt") as json_file: dataLoaded = json.load(json_file) if not dataLoaded['kill']: if dataLoaded['cellDetectionBox']: if "Import" in dataLoaded['cellDetection']: import_cell(root, pathClearMap) if dataLoaded['alignmentBox']: if "Manual" in dataLoaded['alignmentOperation']: manual(root, pathClearMap) with open(pathClearMap + "ClearMap/Scripts/work_dir/savedSettings.txt") as json_file: dataLoaded = json.load(json_file) if not dataLoaded['kill']: exec( open(pathClearMap + "ClearMap/Scripts/work_dir/process_template.py").read()) if dataLoaded[ 'baseDir'] == pathClearMap + "ClearMap/clearmap_preset_folder/output": try: if messagebox.askyesno( "Finished", "Succesfully ran clearmap with the selected settings," "would you like to save the output?"): saveLocation = askopendirname( parent=root, title="Select a folder to save the output") if saveLocation == "": raise FileNotFoundError else: saveLocation = str(saveLocation) + "/results" print(saveLocation) copy_tree( pathClearMap + "ClearMap/clearmap_preset_folder/output", saveLocation) messagebox.showinfo( "Finished", "Everything has been saved succesfully") except FileNotFoundError: pass else: messagebox.askyesno( "Finished", "Succesfully ran clearmap with the selected settings")
def select_dir(self, entry): initialdir, initialfile = os.path.split(entry.get()) file = askopendirname(self, 'Select directory', initialdir=initialdir, initialfile=initialfile) if file: entry.delete(0, 'end') entry.insert(0, file)
def searchIlastik(): """ This function opens a dir chooser which asks the user to select the folder where Ilastik is installed :return: """ ilastikPath = askopendirname(parent=rootFirstSetup, title="Select the ilastik folder") settingsFileRead = open(maindir + "ClearMap/Settings.py").read() settingsFileRead = re.sub('("mark")\nIlastik.*', '"mark"\nIlastikPath = "' + ilastikPath + '";', settingsFileRead) settingsFileWrite = open(maindir + "ClearMap/Settings.py", "w") settingsFileWrite.write(settingsFileRead)
def cb_open_dir(): global msgBox, msgBoxWait if msgBoxWait is not None: return msgBox = tk.Tk() msgBox.title("Load Recipe") msgBoxWait = msgBox.after(Config["autoclose"] * 1000, cb_autoclose) ret = askopendirname(parent=msgBox, initialdir=dirpath, initialfile="") if msgBoxWait is None: return #returned by autoclose msgBox.after_cancel(msgBoxWait) msgBoxWait = None msgBox.destroy() dir = re.sub(r".*" + Config["recipe"]["dir"], "", ret) if dir != "": msg = String() msg.data = dir.replace("/", "") cb_load(msg)
def searchElastix(): """ This function opens a dir chooser which asks the user to select the folder where elastix is installed :return: """ elastixPath = askopendirname(parent=rootFirstSetup, title="Select the elastix folder") settingsFileRead = open(maindir + "ClearMap/Settings.py").read() if os.path.isdir( re.search(r'(?<=saveSettings = ")([^"]+)', settingsFileRead).group(0)) and elastixPath != "": quitButton['state'] = 'normal' settingsFileRead = re.sub('("mark")\nElastix.*', '"mark"\nElastixPath = "' + elastixPath + '";', settingsFileRead) settingsFileWrite = open(maindir + "ClearMap/Settings.py", "w") settingsFileWrite.write(settingsFileRead)
def cb_open_dir(): global msgBox, msgBoxWait if wRecipe is None: return if msgBoxWait is not None: return msgBox = tk.Toplevel() msgBox.title("Load Recipe") msgBox.withdraw() msgBoxWait = msgBox.after(1000, cb_wait_nop) ret = askopendirname(parent=root, initialdir=dirpath, initialfile="") msgBox.after_cancel(msgBoxWait) msgBoxWait = None msgBox.destroy() dir = re.sub(r".*" + Config["recipe"]["dir"], "", ret) if dir != "": msg = String() msg.data = dir.replace("/", "") cb_load(msg)
def saveLocation(): """ This function asks for a location where all the local files will be saved. :return: """ savePath = askopendirname(parent=rootFirstSetup, title="Select the save location folder") settingsFileRead = open(maindir + "ClearMap/Settings.py").read() if os.path.isdir( re.search(r'(?<=ElastixPath = ")([^"]+)', settingsFileRead).group(0)) and savePath != "": quitButton['state'] = 'normal' settingsFileRead = re.sub('saveSettings.*', 'saveSettings = "' + savePath + '";', settingsFileRead) settingsFileWrite = open(maindir + "ClearMap/Settings.py", "w") settingsFileWrite.write(settingsFileRead)
def text_swipe(): directory = askopendirname(title='Choose a directory') for text_par in document.paragraphs: text_par.text = text_par.text.replace("NUMB", numb.get()) text_par.text = text_par.text.replace("day", day.get()) text_par.text = text_par.text.replace("month", month.get()) text_par.text = text_par.text.replace("year", year.get()) text_par.text = text_par.text.replace("Prods", prods.get()) text_par.text = text_par.text.replace("DIR", direct.get()) text_par.text = text_par.text.replace("FIOF", fio_f.get()) text_par.text = text_par.text.replace("default", default.get()) for table in document.tables: for row in table.rows: for cell in row.cells: for table_par in cell.paragraphs: table_par.text = table_par.text.replace( "DIR", direct.get()) table_par.text = table_par.text.replace( "Prods", prods.get()) table_par.text = table_par.text.replace( "citycomp", city_comp.get()) table_par.text = table_par.text.replace( "UNP", UNP.get()) table_par.text = table_par.text.replace( "unn", n_unp.get()) table_par.text = table_par.text.replace("RS", rs.get()) table_par.text = table_par.text.replace( "bankname", bank_name.get()) table_par.text = table_par.text.replace( "citybank", city_bank.get()) table_par.text = table_par.text.replace( "BIC", BIC.get()) table_par.text = table_par.text.replace( "tel", tel.get()) table_par.text = table_par.text.replace( "email", email.get()) table_par.text = table_par.text.replace( "IOF", iof.get()) document.save(directory + "\\" + str(file_name.get()) + ".docx") os.startfile(directory + "\\" + str(file_name.get()) + ".docx") window.event_add(exit())
def cb_open_dir(n): global massage func_ret = False name = buttons[n]["name"] ret = askopendirname(parent=root, title=name, initialdir=dirpath, initialfile='', okbuttontext=name) if ret: abs_path = os.path.abspath(Config["dump_prefix"]) if ret.startswith(abs_path): dir = re.sub(r'.*' + Config["dump_prefix"], '', ret) recipe = dir.split('/') if (len(recipe) == 2) and (not recipe[0]): func_ret = set_recipe(recipe[1], n) if name == 'CopySelect': cb_copy_from() else: massage = name + ' Wrong selection folder' else: massage = name + ' Wrong selection folder' return func_ret
def browse_folder_output(self): if found_tkinter: tk.Tk().withdraw() self.output_directory = tkfilebrowser.askopendirname(title="Select output folder")
def fgetDir(self): dirname = askopendirname(parent=self.master, initialdir='/', initialfile='tmp', font_size=font_size) self.dir_ent_var.set(dirname)
def c_open_dir(): rep = askopendirname(parent=root, initialdir='/', initialfile='tmp') print(rep)
def selectOutputDirectory(self, event=None): """Select output directory""" dirInit = self.tape.dirOut self.tape.dirOut = askopendirname(initialdir=dirInit) if self.tape.dirOut != '': self.outDirLabel['text'] = self.tape.dirOut
def text_swipe_spec(): directory = askopendirname(title='Choose a directory') for text_par_spec in document.paragraphs: text_par_spec.text = text_par_spec.text.replace( 'num', num_spec_ent.get()) text_par_spec.text = text_par_spec.text.replace( 'days', days_spec_ent.get()) text_par_spec.text = text_par_spec.text.replace( 'months', months_spec_ent.get()) text_par_spec.text = text_par_spec.text.replace( 'years', years_spec_ent.get()) text_par_spec.text = text_par_spec.text.replace( 'dogn', dognum_spec_ent.get()) text_par_spec.text = text_par_spec.text.replace( 'dd', dd_spec_ent.get()) text_par_spec.text = text_par_spec.text.replace( 'dm', dm_spec_ent.get()) text_par_spec.text = text_par_spec.text.replace( 'dy', dy_spec_ent.get()) text_par_spec.text = text_par_spec.text.replace( 'gost', gost_spec_ent.get()) text_par_spec.text = text_par_spec.text.replace( 'dost', dost_spec_ent.get()) text_par_spec.text = text_par_spec.text.replace( 'posts', posts_spec_ent.get()) # text_par_spec.text = text_par_spec.text.replace('propissummnds', propissummnds.get()) # text_par_spec.text = text_par_spec.text.replace('cop', cop.get()) # text_par_spec.text = text_par_spec.text.replace('porpissnds', propisnds.get()) # text_par_spec.text = text_par_spec.text.replace('copnds', copnds.get()) for tables in document.tables: for rows in tables.rows: for cells in rows.cells: for table_par_spec in cells.paragraphs: price = float(price_spec_ent.get()) pcs = float(pcs_spec_ent.get()) summ = price * pcs sunds = summ * ((float(pnds_spec_ent.get()) / 100) + 1) snds = sunds - summ table_par_spec.text = table_par_spec.text.replace( 'Cult', cult_spec_ent.get()) table_par_spec.text = table_par_spec.text.replace( 'Pcs', pcs_spec_ent.get()) table_par_spec.text = table_par_spec.text.replace( 'price', price_spec_ent.get()) table_par_spec.text = table_par_spec.text.replace( 'summ', str(truncate(summ, 2))) table_par_spec.text = table_par_spec.text.replace( 'pnds', pnds_spec_ent.get()) table_par_spec.text = table_par_spec.text.replace( 'sunds', str(truncate(sunds, 2))) table_par_spec.text = table_par_spec.text.replace( 'snds', str(truncate(snds, 2))) table_par_spec.text = table_par_spec.text.replace( 'scomp', prods.get()) table_par_spec.text = table_par_spec.text.replace( 'sadres', city_comp.get()) table_par_spec.text = table_par_spec.text.replace( 'sunp', UNP.get()) table_par_spec.text = table_par_spec.text.replace( 'sn_unp', n_unp.get()) table_par_spec.text = table_par_spec.text.replace( 'srs', rs.get()) table_par_spec.text = table_par_spec.text.replace( 'sbankname', bank_name.get()) table_par_spec.text = table_par_spec.text.replace( 'sbic', BIC.get()) table_par_spec.text = table_par_spec.text.replace( 'stel', tel.get()) table_par_spec.text = table_par_spec.text.replace( 'se-mail', email.get()) table_par_spec.text = table_par_spec.text.replace( 'sDir', direct.get()) table_par_spec.text = table_par_spec.text.replace( 'sIOF', iof.get()) document.save(directory + "\\" + str(file_name_spec.get()) + ".docx") os.startfile(directory + "\\" + str(file_name_spec.get()) + ".docx") window_s.event_add(exit())
def askdirectory(fd=None, **argv): if fd == None: fd = mode if fd: return _fd2.askopendirname(**argv) else: return _fd1.askdirectory(**argv)