def __init__( self, master, is_dir: bool = False, loc: str = '', callback: Callable[[str], None] = None, ) -> None: """Initialise the field. - Set is_dir to true to look for directories, instead of files. - width sets the number of characters to display. - callback is a function to be called with the new path whenever it changes. """ from tooltip import add_tooltip super(FileField, self).__init__(master) self._location = loc self.is_dir = is_dir self._text_var = tk.StringVar(master=self, value='') if is_dir: self.browser = filedialog.Directory( self, initialdir=loc, ) # type: commondialog.Dialog else: self.browser = filedialog.SaveAs( self, initialdir=loc, ) if callback is None: callback = self._nop_callback self.callback = callback self.textbox = ReadOnlyEntry( self, textvariable=self._text_var, font=_file_field_font, cursor=utils.CURSORS['regular'], ) self.textbox.grid(row=0, column=0, sticky='ew') self.columnconfigure(0, weight=1) utils.bind_leftclick(self.textbox, self.browse) # The full location is displayed in a tooltip. add_tooltip(self.textbox, self._location) self.textbox.bind('<Configure>', self._text_configure) self.browse_btn = ttk.Button( self, text="...", width=1.5, command=self.browse, ) self.browse_btn.grid(row=0, column=1) self._text_var.set(self._truncate(loc))
def set_work_dir(self, classmethods): self.viewmethos = classmethods work_dir = dir.Directory() temp_dir = work_dir.show(initialdir='.', title='设置工作目录') if temp_dir != '': self.renew() self.remove_canvas_lable_all() self.work_dir = temp_dir self.get_all_img() if len(self.image_paths) < 1: mb.showinfo("提醒", "当前目录没有图片!") return self.showImage(self.image_paths[self.image_index]) # self.image_index = self.image_index + 1 classmethods.next_image.config(state=tk.ACTIVE) self.create_image_tree(self.viewmethos.image_name_tree, self.work_dir) self.viewmethos.zoomIn_image.config(state=tk.ACTIVE) self.viewmethos.zoomOut_image.config(state=tk.ACTIVE) self.viewmethos.revoke.config(state=tk.ACTIVE) self.viewmethos.label_rect.config(state=tk.ACTIVE) self.viewmethos.label_scat.config(state=tk.ACTIVE) self.viewmethos.save_lable.config(state=tk.ACTIVE) self.viewmethos.show_lable.config(state=tk.ACTIVE) #self.draw_available = True else: mb.showinfo("提醒", "目录选择失败!")
def loadDataFunc(self): dirselect = filedialog.Directory() self.dirsList = [] while True: d = dirselect.show() if not d: break self.dirsList.append(d) self.createOptionMenu()
def browseRow(self, row): # Open a dialog to find a directory new_path = filedialog.Directory(self).show() # Remove "\\steamapps" if the user selected it if new_path.lower().endswith("\\steamapps"): new_path = os.path.split(new_path)[0] # Replace "/" with "\\" to keep things consistent self.entryValues[row].set(new_path.replace("/", "\\"))
def browse_for_all_files(): path = "" folder = filedialog.Directory(initialdir=os.path.dirname(path)) path = folder.show() # Iterate over each item in the directory and check if it's a file for entry in os.scandir(path): if entry.is_file(): # Modify the path name and add it to FILES entry = entry.path.replace("\\", "/") if entry not in FILES: FILES.append(entry)
def get_multi_paths(): dirselect = filedialog.Directory(initialdir=os.path.expanduser('~')) dirs = [] while True: d = dirselect.show() if not d: break dirs.append(d) if len(dirs) == 0: print('No paths selected, exiting...') sys.exit return dirs
def _browse(self): """Display the dialog to _browse for a directory.""" initial_dir = self._variable.get() initial_dir = os.path.abspath(os.path.expanduser(initial_dir)) self.options['initialdir'] = initial_dir dlg = filedialog.Directory(self.master, **self.options) new_dir = dlg.show() if new_dir: new_dir = shorten(new_dir) self.value = new_dir
def select(): # Open a new window to select a file folder_selector = filedialog.Directory( initialdir=self.handler.video.path, title='Select a folder to download') folder_selector.show() # Calling the handler path = folder_selector.__getattribute__('directory') path = self.handler.folder_select_handler(path) # chaging the output path to the new diretory folder['text'] = path
def __init__(self, master=None, **kw): super().__init__(master, **kw) # Configure the progressbar. self.__progress = ttk.Progressbar(self, orient=HORIZONTAL) self.__progress.grid(row=0, column=0, columnspan=4, sticky=EW) # Configure the tree. self.__tree = ttk.Treeview(self, selectmode=BROWSE, columns=('d_size', 'f_size', 'path')) self.__tree.heading('#0', text=' Name', anchor=W) self.__tree.heading('d_size', text=' Total Size', anchor=W) self.__tree.heading('f_size', text=' File Size', anchor=W) self.__tree.heading('path', text=' Path', anchor=W) self.__tree.column('#0', minwidth=80, width=160) self.__tree.column('d_size', minwidth=80, width=160) self.__tree.column('f_size', minwidth=80, width=160) self.__tree.column('path', minwidth=80, width=160) self.__tree.grid(row=1, column=0, columnspan=3, sticky=NSEW) # Configure the scrollbar. self.__scroll = ttk.Scrollbar(self, orient=VERTICAL, command=self.__tree.yview) self.__tree.configure(yscrollcommand=self.__scroll.set) self.__scroll.grid(row=1, column=3, sticky=NS) # Configure the path button. self.__label = ttk.Button(self, text='Path:', command=self.choose) self.__label.bind('<Return>', self.choose) self.__label.grid(row=2, column=0) # Configure the directory dialog. head, tail = os.getcwd(), True while tail: head, tail = os.path.split(head) self.__dialog = filedialog.Directory(self, initialdir=head) # Configure the path entry box. self.__path = ttk.Entry(self, cursor='xterm') self.__path.bind('<Control-Key-a>', self.select_all) self.__path.bind('<Control-Key-/>', lambda event: 'break') self.__path.bind('<Return>', self.search) self.__path.grid(row=2, column=1, sticky=EW) self.__path.focus_set() # Configure the execution button. self.__run = ttk.Button(self, text='Search', command=self.search) self.__run.bind('<Return>', self.search) self.__run.grid(row=2, column=2) # Configure the sizegrip. self.__grip = ttk.Sizegrip(self) self.__grip.grid(row=2, column=3, sticky=SE) # Configure the grid. self.grid_rowconfigure(1, weight=1) self.grid_columnconfigure(1, weight=1) # Configure root item in tree. self.__root = None
def browse_for_folders(coming_from): folder_path = "" # Keep browsing for folders while True: folder = filedialog.Directory(initialdir=os.path.dirname(folder_path)) folder_path = folder.show() # Break if the user doesn't provide directory (presses cancel) if not folder_path: break # If the selected folder isn't in FOLDERS add it to the list if folder_path not in FOLDERS: FOLDERS.append(folder_path) if coming_from == "Page": load_bottomFrame()
def set_work_dir(self): work_dir = dir.Directory() temp_dir = work_dir.show(initialdir='.', title='设置工作目录') if temp_dir != '': self.work_dir = temp_dir self.get_all_img(self.work_dir) if len(self.image_paths) < 1: mb.showinfo("提醒", "当前目录没有图片!") return self.showImage(self.image_paths[self.image_index]) #self.image_index = self.image_index + 1 self.next_image.config(state=tk.ACTIVE) self.create_image_tree(self.image_name_tree, self.work_dir) self.revoke.config(state=tk.ACTIVE) self.label_rect.config(state=tk.ACTIVE) self.label_scat.config(state=tk.ACTIVE) self.save_lable.config(state=tk.ACTIVE) else: mb.showinfo("提醒", "目录选择失败!")
def open_dir(self): d = dir.Directory() self.path = d.show(initialdir=self.path)
def select_path(self): self.path_entry.delete(0, END) path_dialog = filedialog.Directory(self.win) path = path_dialog.show() self.path_entry.insert(0, path)
def __init__( self, master, is_dir: bool = False, loc: str = '', callback: Callable[[str], None] = None, ) -> None: """Initialise the field. - Set is_dir to true to look for directories, instead of files. - width sets the number of characters to display. - callback is a function to be called with the new path whenever it changes. """ from app.tooltip import add_tooltip super(FileField, self).__init__(master) self._location = loc self.is_dir = is_dir self._text_var = tk.StringVar(master=self, value='') if is_dir: self.browser = filedialog.Directory( self, initialdir=loc, ) else: self.browser = filedialog.SaveAs( self, initialdir=loc, ) if callback is None: callback = self._nop_callback self.callback = callback self.textbox = ReadOnlyEntry( self, textvariable=self._text_var, font=_file_field_font, cursor=Cursors.REGULAR, ) self.textbox.grid(row=0, column=0, sticky='ew') self.columnconfigure(0, weight=1) bind_leftclick(self.textbox, self.browse) # The full location is displayed in a tooltip. add_tooltip(self.textbox, self._location) self.textbox.bind('<Configure>', self._text_configure) self.browse_btn = ttk.Button( self, text="...", command=self.browse, ) self.browse_btn.grid(row=0, column=1) # It should be this narrow, but perhaps this doesn't accept floats? try: self.browse_btn['width'] = 1.5 except tk.TclError: self.browse_btn['width'] = 2 self._text_var.set(self._truncate(loc))
def open_dir(self): d = filedialog.Directory() self.path = d.show(initialdir=self.path)
def askdirectory(): path = os.path.normpath(filedialog.Directory().show()) if not os.path.isdir(path): return save(defaultPath := path) setText(pathText, defaultPath)