def onBrowse(self): """Present the File Open dialog. Parameters: self: This object. Return value: String containing the path to the selected file, or None if no file was selected. Description: Display the File/Open dialog box and return the path to the selected file. """ # Present the file/open dialog. path = Open().show() # If no file was selected, return. if path == '': return # Save the current path in the file entry field. self._fileEntryField.setvalue(path)
def askopenfilenames(**options): """Ask for multiple filenames to open. Returns a list of filenames or empty list if cancel button selected """ options["multiple"] = 1 return Open(**options).show()
def lueosallistujatshelve(self): self.openDialog = Open(initialdir=self.startfiledir, filetypes=self.ftypes2) file = self.openDialog.show() if not file: print("plaa") return if not os.path.isfile(file): self.writeToLog( 'Ajanotto by Juha Viitanen Tiedostoa ei voitu avata ' + file) try: print("tuliko" + os.path.splitext(file)[0]) self.dbase = shelve.open(os.path.splitext(file)[0]) #print(list(self.dbase.keys())) for key in list(self.dbase.keys()): #print(self.dbase[key].bibnumber) self.competitors.append(self.dbase[key]) self.__kilpailijoita = self.__kilpailijoita + 1 for luokka in self.luokat: if luokka == self.dbase[key].kilpasarja: self.luokkafound = 1 break if self.luokkafound == 0: self.luokat.append(self.dbase[key].kilpasarja) else: self.luokkafound = 0 print(list(self.luokat)) self.writeToLog("Ladattiin " + str(self.__kilpailijoita) + " kilpailijaa järjestelmään") except: print("Jotain meni pieleen")
def cll_abrir_arquivo(self): #b 0: abrindo arquivo arquivos = [( Gui.JSON["open_save_file"]["format_description"], Gui.JSON["open_save_file"]["allowed_extension"], )] caminho_arquivo = Open( filetypes=arquivos, defaultextension=arquivos, ) #e 0: obtemos uma string com o caminho completo do arquivo #b 1: se a abertura do arquivo for cancelada (string vazia) if len(caminho_arquivo) == 0: return None #e 1: encerramos a função sem fazer mais nada #b 2: pegando nome do arquivo para colocar no label self.nome_arquivo = caminho_arquivo.split("/")[-1] f = open(caminho_arquivo, "r") self.url_list = list(map( lambda l: l.strip(), f.readlines(), )) self.links_as_texto = "\n".join(self.url_list) f.close() #e 2: os links estão em self.url_list #b 3: chama a interface de novo arquivo self.cll_novo_arquivo() self.l_nome_arquivo["text"] = self.nome_arquivo self.t_text_area.insert(0.0, self.links_as_texto)
def onOpen(self): ftypes = {('All files', '*'), ('Text files', '*.txt'), ('jpg file', '*.jpg'), ('gif file', '*.gif')} dlg = Open(self, filetypes=ftypes) fl = dlg.show() if fl != '': images = fl if images.endswith("png") \ or images.endswith("jpg") \ or images.endswith("jpeg") \ or images.endswith("gif") \ or images.endswith("tiff") \ or images.endswith("bmp") \ or images.endswith("PNG") \ or images.endswith("JPG") \ or images.endswith("JPEG") \ or images.endswith("GIF") \ or images.endswith("TIFF") \ or images.endswith("BMP"): window = tk.Toplevel() str = fl.split('/', 100) number_last = len(fl.split('/', 100)) - 1 window.title(str[number_last]) self.mg = Image.open(fl) w, h = Image.open(fl).size window.geometry(("%dx%d + 300 + 300") % (w, h)) window.configure(background='grey') path = fl self.img = Image.open(path) img = ImageTk.PhotoImage(Image.open(path)) panel = tk.Label(window, image=img) panel.pack(side="bottom", fill="both", expand=True) window.mainloop() else: mbox.showerror("Error", "Could not open file")
def ask_file(title, message, filetypes, directory, mult): dlg = Open(title=title, filetypes=filetypes, initialdir=directory, multiple=mult) out = dlg.show() return out
def askopenfile(mode="r", **options): "Ask for a filename to open, and returned the opened file" filename = Open(**options).show() if filename: return open(filename, mode) return None
def callback_excl(): ftypes = [('Excl files', '*.excl'), ('All files', '*')] dlg = Open(self, filetypes=ftypes) fl = dlg.show() self.label_exclfile['text'] = fl # save used paths to file self.write_input_hist(self.label_exclfile['text'], self.label_ddir['text'])
def choose(): if (PDF_Path != ""): PDF_Path.set( Open(title="Choose File", initialdir="C:/", filetypes=(("PDF File", "*.pdf"), ("All Files", "*.*")))) else: PDF_Path.set("Please Choose PDF File Again...:(")
def _getPicture(self): self.bgcolor = None ftypes = [('Image files', '*.gif *.png *.jpeg'), ('All files', '*')] dlg = Open(self._master, filetypes = ftypes) fl = dlg.show() if fl != '': img = Image.open(fl) img = img.resize((670,520), Image.ANTIALIAS) self.bgpic = 'Image/'+fl.split('/')[-1] img.save(self.bgpic) self._demo_turtle_screen.bgpic(self.bgpic)
def _onFileOpen(self): if debug: print ('File/Open...') # If the current document has changed, prompt to save it. self._saveIfChanged() # Fetch the path to the new file. If found, load the document and # save the path. path = Open().show() if path == (): return self._open(path)
def onOpen(self): self.image = None self.rects_img = None ftypes = [('Image files', '*.jpg *.png *.jpeg *.JPG'), ('All files', '*')] dlg = Open(self, filetypes=ftypes) self.img_dir = dlg.show() if self.img_dir != '': self.image = self.openImage(self.img_dir) label = Label(self, image=self.image) label.grid(row=0, column=0) self.text_frame.delete(1.0, 'end')
def lueosallistujat(self): self.openDialog = Open(initialdir=self.startfiledir, filetypes=self.ftypes) file = self.openDialog.show() self.vaihelaskuri[0] = 0 self.vaihelaskuri[1] = 0 self.vaihelaskuri[2] = 0 self.vaihelaskuri[3] = 0 if not file: return if not os.path.isfile(file): self.writeToLog( 'Ajanotto by Juha Viitanen 2016 Tiedostoa ei voitu avata ' + file) try: self.dbase = shelve.open('backlog/backlog' + time.strftime( "%d_%m_%y_%H_%M_%S", time.localtime(time.time())) + 'shv') with open(file, newline='') as csvfile: spamreader = csv.reader(csvfile, delimiter=';', quotechar='|') """print(spamreader)""" for row in spamreader: self.competitors.append( kilpailija(row[2], row[1], '+358........', row[3], row[4], row[0])) self.__kilpailijoita = self.__kilpailijoita + 1 for luokka in self.luokat: if luokka == row[4]: self.luokkafound = 1 break if self.luokkafound == 0: self.luokat.append(row[4]) else: self.luokkafound = 0 #self.writeToLog(', '.join(row)) #self.writeToLog(self.luokat) self.writeToLog("Ladattiin " + str(self.__kilpailijoita) + " kilpailijaa järjestelmään") for obj in self.competitors: self.dbase[obj.bibnumber] = obj self.dbase.close() """self.writeToLog(('%s'%self.__kilpailijoita))""" except: self.writeToLog( "CSV-tiedostoa ei löytynyt tai sitä ei voi avatata.")
def onOpen(): global ftypes ftypes = [('Images', '*.jpg *.tif *.bmp *.gif *.png')] dlg = Open(filetypes = ftypes) fl = dlg.show() if fl != '': global imgin global imgincv imgin = skimage.io.imread(fl) #imgin = cv2.imread(fl,cv2.IMREAD_COLOR); cv2.namedWindow("ImageIn", cv2.WINDOW_AUTOSIZE) imgincv = cv2.cvtColor(imgin, cv2.COLOR_BGR2RGB) cv2.imshow("ImageIn", imgincv) cv2.waitKey(1000) cv2.destroyAllWindows()
def importSudoku(self): # List lưu các định dạng file khác nhau để đọc ftypes = [('All files','*')] # Hiển thị hộp thoại chọn đường dẫn file dialog = Open(self,filetypes = ftypes) path = dialog.show() # Đọc file intput_ = "" with open(path,"r") as ins: for line in ins: intput_ += line self.input = intput_ self.createSquares(9) self.setNumbers(9,intput_)
def callback_dis(): ftypes = [('Disco files', '*.dst'), ('All files', '*')] dlg = Open(self, filetypes=ftypes) fl = dlg.show() self.label_discofile['text'] = fl # load stations to the listbox discos_dates = velocities.load_discofile(fl) all_stations = sorted(list(discos_dates)) self.lb.configure(state=NORMAL) self.lb.delete(0, END) for st in all_stations: self.lb.insert(END, st) # disable listbox again if multistation mode if self.solution_mode.get() == 0: self.lb.configure(state='disabled')
def openfile(): ftypes = [('Python files', '*.*'), ('All files', '*')] #Loại file dlg = Open(filetypes=ftypes) fl = dlg.show() global f, frame, labelsize if fl != '': im = readFile(fl) f = fl show(im) im = cv2.imread(f) #Lấy kích thước labelsize = Label(frame, text="", font="Times 18 bold italic") labelsize.place(x=560, y=195) height, width, channels = im.shape stringsize = "-Kích thước ảnh: " + str(height) + "x" + str(width) labelsize.config(text=stringsize) print(stringsize)
def onOpen(self): """ Event handler for clicking the Open button Args: None Returns: None """ ftypes = [('all files', '.*'), ('text files', '.txt'), ('ann files', '.ann')] dlg = Open(self, filetypes=ftypes) fl = dlg.show() if fl != '': self.text.delete("1.0", END) text = self.readFile(fl) self.text.insert(END, text) self.lbl.config(text="File: " + fl) self.autoLoadNewFile(self.fileName, "1.0") self.text.mark_set(INSERT, "1.0")
def inputImage(self): ftypes = [('Image files', '*.gif *.png *.jpeg'), ('All files', '*')] dlg = Open(self._master, filetypes=ftypes) fl = dlg.show() if fl != '': photo = Image.open(fl) if self._is_int(self._subframe.shape_width.get()) == True: photo = photo.resize( (int(self._subframe.shape_width.get()), photo.height), Image.ANTIALIAS) if self._is_int(self._subframe.shape_height.get()) == True: photo = photo.resize( (photo.width, int(self._subframe.shape_height.get())), Image.ANTIALIAS) photo = ImageTk.PhotoImage(photo) self._shape_image = photo self._subframe.shape_image.configure(image=photo) self._subframe.shape_image.photo = photo self._subframe.shape_image.place(x=500, y=250)
def onOpen(self): if self.a != 0: self.lable2.destroy() ftypes = [('Python files', '*.jpg'), ('All files', '*')] dlg = Open(self, filetypes=ftypes) fl = dlg.show() if fl != '': self.liv = Image.open(fl) lbl5 = Label(self, text="%f MB" % (os.path.getsize(fl) / 1048576.0), width=10) lbl5.place(x=80, y=300) self.liv.thumbnail((200, 200), Image.ANTIALIAS) liverpool = ImageTk.PhotoImage(self.liv) self.lable2 = Label(self, image=liverpool) self.lable2.image = liverpool self.lable2.place(x=20, y=80) self.a = 1
def loadImage(self): """Load an image into ds9 Parameters: - self - This DS9Connector object Return value: - ra - the ROI center RA coordinate - dec - the ROI center Dec coordinate Description: After checking for a connection to ds9, if connected the method launches and Open File dialog to allow the user to select an image file to display. Once selected it attempts to display the file in ds9. If the file type is unsupported, the user is warned of such. If the file is supported, the program attempts to load and extract the images ROI data and passes it back to the calling method. """ noROIData = (-1, 0, 0) self._checkConnection() if (self._isConnected()): # open file dialog to get name path = Open().show() if path == (): return noROIData # open the file in window try: self.ds9.set("fits " + path) file = FitsFile(path) if file.hasROIData(): return file.getROIData() else: return noROIData except: showwarning("File Type Error!", "The specified file is not a valid FITS image") return noROIData
def importGrid(self): #List lưu các định dạng file khác nhau để đọc file ftypes = [('All files', '*')] #Hiển thị file dialog chúng ta cần gọi hàm Open(). Hàm này trả về đường dẫn file dlg = Open(self, filetypes=ftypes) fl = dlg.show() with open(fl) as textFile: lines = [line.split() for line in textFile] self.gridWidth = len(lines) self.gridHeight = len(lines[0]) results = [] for i in range(self.gridWidth): results.append([]) for j in range(self.gridHeight): if lines[i][j] == "1": results[i].append(1) else: results[i].append(0) self.MAP = results # Đưa grid lên form self.updateUI()
def onOpen(self): if self.a == 0: self.liv = Image.open("1.png") self.liv.thumbnail((200, 200), Image.ANTIALIAS) liverpool = ImageTk.PhotoImage(self.liv) self.lable2 = Label(self, image=liverpool) self.lable2.image = liverpool self.lable2.place(x=20, y=80) self.lable2.destroy() else: self.lable2.destroy() ftypes = [('Python files', '*.jpg'), ('All files', '*')] dlg = Open(self, filetypes=ftypes) fl = dlg.show() if fl != '': self.liv = Image.open(fl) self.liv.thumbnail((200, 200), Image.ANTIALIAS) liverpool = ImageTk.PhotoImage(self.liv) self.lable2 = Label(self, image=liverpool) self.lable2.image = liverpool self.lable2.place(x=20, y=80) self.a = 1
def my_askopenfilename(self): # objects remember last result dir/file if not self.openDialog: self.openDialog = Open(initialdir=self.startfiledir, filetypes=self.ftypes) return self.openDialog.show()
def my_askopenfilename(self): self.openDialog = Open(initialdir=self.startfiledir, filetypes=self.ftypes) return self.openDialog.show()
def __init__(self, master, cid_path=None, data_path=None, config=dict(), **keywords): """ Set up a frame with widgets to validate ``id_path`` and ``data_path``. :param master: Tk master or root in which the frame should show up :param cid_path: optional preset for :guilabel:`CID` widget :type cid_path: str or None :param data_path: optional preset for :guilabel:`Data` widget :type data_path: str or None :param config: Tk configuration :param keywords: Tk keywords """ assert has_tk assert master is not None if six.PY2: # In Python 2, Frame is an old style class. Frame.__init__(self, master, config, **keywords) else: super().__init__(master, config, **keywords) self._master = master # Define basic layout. self.grid(padx=_PADDING, pady=_PADDING) # self.grid_columnconfigure(1, weight=1) self.grid_rowconfigure(_VALIDATION_REPORT_ROW, weight=1) # Choose CID. self._cid_label = Label(self, text='CID:') self._cid_label.grid(row=_CID_ROW, column=0, sticky=E) self._cid_path_entry = Entry(self, width=55) self._cid_path_entry.grid(row=_CID_ROW, column=1, sticky=E + W) self._choose_cid_button = Button(self, command=self.choose_cid, text='Choose...') self._choose_cid_button.grid(row=_CID_ROW, column=2) self.cid_path = cid_path # Choose data. self._data_label = Label(self, text='Data:') self._data_label.grid(row=_DATA_ROW, column=0, sticky=E) self._data_path_entry = Entry(self, width=55) self._data_path_entry.grid(row=_DATA_ROW, column=1, sticky=E + W) self._choose_data_button = Button(self, command=self.choose_data, text='Choose...') self._choose_data_button.grid(row=_DATA_ROW, column=2) self.data_path = data_path # Validate. self._validate_button = Button(self, command=self.validate, text='Validate') self._validate_button.grid(row=_VALIDATE_BUTTON_ROW, column=0, padx=_PADDING, pady=_PADDING) # Validation status text. self._validation_status_text = StringVar() validation_status_label = Label( self, textvariable=self._validation_status_text) validation_status_label.grid(row=_VALIDATE_BUTTON_ROW, column=1) # Validation result. validation_report_frame = LabelFrame(self, text='Validation report') validation_report_frame.grid(row=_VALIDATION_REPORT_ROW, columnspan=3, sticky=E + N + S + W) validation_report_frame.grid_columnconfigure(0, weight=1) validation_report_frame.grid_rowconfigure(0, weight=1) self._validation_report_text = Text(validation_report_frame) self._validation_report_text.grid(column=0, row=0, sticky=E + N + S) _validation_report_scrollbar = Scrollbar(validation_report_frame) _validation_report_scrollbar.grid(column=1, row=0, sticky=N + S + W) _validation_report_scrollbar.config( command=self._validation_report_text.yview) self._validation_report_text.config( yscrollcommand=_validation_report_scrollbar.set) # Set up file dialogs. self._choose_cid_dialog = Open( initialfile=self.cid_path, title='Choose CID', ) self._choose_data_dialog = Open( initialfile=self.data_path, title='Choose data', ) self._save_log_as_dialog = SaveAs( defaultextension='.log', initialfile='cutplace.log', title='Save validation result', ) menubar = Menu(master) master.config(menu=menubar) self._file_menu = Menu(menubar, tearoff=False) self._file_menu.add_command(command=self.choose_cid, label='Choose CID...') self._file_menu.add_command(command=self.choose_data, label='Choose data...') self._file_menu.add_command(command=self.save_validation_report_as, label='Save validation report as...') self._file_menu.add_command(command=self.quit, label='Quit') menubar.add_cascade(label='File', menu=self._file_menu) help_menu = Menu(menubar, tearoff=False) help_menu.add_command(command=self.show_about, label='About') menubar.add_cascade(label='Help', menu=help_menu) self._enable_usable_widgets()
def my_askopenfilename(self): # 对象记住最后结果目录/文件 if not self.openDialog: self.openDialog = Open(initialdir=self.startfiledir, filetypes=self.ftypes) return self.openDialog.show()
def load_Bern_file(self): dlg = Open(self) bfile = dlg.show() self.label_Bernfile['text'] = bfile self.convert_but.config(state='normal')
def askopenfilename(**options): "Ask for a filename to open." return Open(**options).show()
def on_import(self): """Обработчик кнопки Импорт""" filename = Open(initialdir='../you-can/source/', filetypes=(('Текст', '*.txt'),)).show() text_ls = do_import(filename) self.do_open(text_ls)