def saveFile(): global filename if photonfile == None: print("No photon file loaded!!") infoMessageBox("No photon file loaded!", "There is no .photon file loaded to save.") return saveHeader2PhotonFile() savePreview2PhotonFile() saveLayer2PhotonFile() dialog = FileDialog(screen, (40, 40), ext=".photon", title="Save Photon File", defFilename="newfile.photon", parentRedraw=redrawMainWindow) retfilename = dialog.newFile() if not retfilename == None: filename = retfilename photonfile.writeFile(filename) barefilename = (os.path.basename(filename)) pygame.display.set_caption("Photon File Editor - " + barefilename) ''' print ("Returned: ",filename) try: photonfile.writeFile(filename) except Exception as err: errMessageBox(str(err)) ''' else: print("User Canceled") return
def batch_convert(self): """ 批量转换文件为json,自动获取选择文件夹下的xls文件,转为json """ fd = FileDialog(self) dir = fd.go() if dir: filenames = self.get_files(dir, '.xls') # print(filenames) # 获取开启的线程数 threadnum = self.get_thread_num(len(filenames)) # 根据线程数对原有 filenames列表进行拆分,分配给不同线程 threadlist = self.split_list(filenames, threadnum) for list in threadlist: try: t1 = threading.Thread(target=ExcelToJson.do_convert, args=(self, list)) t1.start() t1.join() except: print("Error: unable create thread") tkMessageBox.showinfo("Excel To Json", "转换成功")
def replaceBitmap(): global filename global dispimg global layerimg dialog = FileDialog(screen, (40, 40), ext=".png", title="Load Image File", parentRedraw=redrawMainWindow) retfilename = dialog.getFile() if not retfilename == None: filename = retfilename print("Returned: ", filename) popup = PopupDialog( screen, pos=(140, 140), title="Please wait...", message="Photon File Editor is importing your images.") popup.show() photonfile.replaceBitmap(layerNr, filename) refreshLayerControls() layerimg = photonfile.getBitmap(layerNr, layerForecolor, layerBackcolor) dispimg = layerimg ''' try: openPhotonFile(filename) except Exception as err: errMessageBox(str(err)) ''' else: print("User Canceled") return
def browse(self): if self.must_exist: file = FileDialog.LoadFileDialog(self).go(pattern=self.pattern) else: file = FileDialog.SaveFileDialog(self).go(pattern=self.pattern) if file: self.filename.set(file)
def filesavecallback(self): "The dialog box etc. for the save menu item" fd=FileDialog(self.root) file=fd.go(".","*.pf") if (file != None): f=open(file,"w") pickle.dump(self.fractal,f) f.close() logger("File "+file+" saved",SPL) self.activatebuttons() else: self.mesg("Invalid file") logger("Invalid file name",ERROR)
def setPatientView(self): self.patientModel.clear() dialog = FileDialog() self.filepath = dialog.openFileNameDialog(title="Open DICOMDIR", typeFile=CS_DICOMDIR) if self.filepath: self.base_dir = dirname(self.filepath) self.dicom_dir = read_dicomdir(self.filepath) for patient in range(len(self.dicom_dir.patient_records)): ID = self.dicom_dir.patient_records[patient].PatientID NAME = str(self.dicom_dir.patient_records[patient].PatientName ).replace('^', ' ') it = QtGui.QStandardItem("%s\t%s" % (ID, NAME)) self.patientModel.appendRow(it)
def open(self): app = FileDialog.App() app.show() if app.path: with open(app.path, encoding='utf-8') as f: text = f.read() self.textEdit.setPlainText("".join(str(x) for x in text))
def __init__(self, f_name="", qt=False, port=12345, parent=None): super(MainWindow, self).__init__(parent) self.setupUi(self) self.should_stop = False self.s = None self.contours_name = [] self.pink = 0 self.last_command = "" self.first_window = 0 self.set_up_gui() self.change_contour_limits = False self.tableVertex.enabledChange(False) self.f_name = f_name #self.last_command = "mesh" self.plotTitle.setText("Mesh " + self.f_name) self.control = controller.Controller(self.f_name, self.graphicsView.winId(), qt) self.thread = threading.Thread(target=self.gnuplot_click) self.port = port self.f_dialog = FileDialog.FileDialog() self.operator = OperatorDialog.OperatorDialog() self.color_dialog = ColorDialog.ColorDialog() self.movie_dialog = MovieDialog.MovieDialog() self.bg_dialog = BackgroundDialog.BackgroundDialog() self.count_cell_mass_dialog = CountCellMassDialog.CountCellMassDialog() self.list_vertices = {} self.list_vertices["i"] = [] self.list_vertices["j"] = [] self.list_vertices["x"] = [] self.list_vertices["y"] = [] self.list_vertices_flag = False self.display_callback()
def open_text(self): app = FileDialog.App() app.show() if app.path: with open(app.path, encoding='utf-8') as f: text = f.read() return text
def exportContour(self): file_dialog = FileDialog.Dialog() file_dialog.setFilter('Airfoil contour files (*.dat *.txt)') filename, _ = file_dialog.saveFilename(self.parent.airfoil.name) if not filename: logger.info('No file selected. Nothing saved.') return # get coordinates of modified contour x, y = self.parent.airfoil.spline_data[0] airfoil_name = self.parent.airfoil.name try: # export modified contour with open(filename, 'w') as f: f.write('#\n') f.write('# File created with ' + PyAero.__appname__ + '\n') f.write('# Version: ' + PyAero.__version__ + '\n') f.write('# Author: ' + PyAero.__author__ + '\n') f.write('#\n') f.write('# Derived from: %s\n' % (str(airfoil_name).strip())) f.write('# Number of points: %s\n' % (len(x))) f.write('#\n') for i, _ in enumerate(x): f.write('{:10.6f} {:10.6f}\n'.format(x[i], y[i])) except IOError as error: logger.info('IO error: {}'.format(error)) # log to message window logger.info('Contour saved as {}'.format(filename))
def callback(): global i, left, top, bottom, orangutan_img fd = FileDialog.LoadFileDialog(root) photo = fd.go() im = Image.open(photo) new_img = im.resize((300, 300), Image.ANTIALIAS) neworangu_img = orangutan_img.resize((300, 250), Image.ANTIALIAS) newora_tkimg = ImageTk.PhotoImage(neworangu_img) tkimg = ImageTk.PhotoImage(new_img) tkimgchange = change(photo) tkimgchange = tkimgchange.resize((300, 250), Image.ANTIALIAS) tkimg_change = ImageTk.PhotoImage(tkimgchange) if i == 0: m1 = PanedWindow() m1.pack(fill=BOTH, expand=1) left = Label(m1, text='animal picture', image=tkimg) left.pack() m1.add(left) m2 = PanedWindow(m1, orient=VERTICAL) m1.add(m2) top = Label(m2, text='original picture', image=newora_tkimg) top.pack() m2.add(top) bottom = Label(m2, text='changed picture', image=tkimg_change) bottom.pack() m2.add(bottom) i = 1 mainloop() else: left.config(image=tkimg) top.config(image=newora_tkimg) bottom.config(image=tkimg_change) mainloop()
def open_file_command(self, event=None): import FileDialog dialog = FileDialog.LoadFileDialog(self.master) filename = dialog.go(key="load") if filename: import urllib self.context.load('file:' + urllib.pathname2url(filename))
def save_document(self, *relurls): """Save document to a file. Returns true if the x-fer was initiated; allows histification. """ # File/Save As... url = apply(self.get_baseurl, relurls) if url == self.get_url() and self.busycheck(): return 0 import FileDialog, os fd = FileDialog.SaveFileDialog(self.root) # give it a default filename on which save within the # current directory import urllib if urllib.splittype(url)[0] == "data": default = "" else: urlasfile = string.splitfields(url, '/') default = urlasfile[-1] # strip trailing query i = string.find(default, '?') if i > 0: default = default[:i] # strip trailing fragment i = string.rfind(default, '#') if i > 0: default = default[:i] # maybe bogus assumption? if not default: default = 'index.html' file = fd.go(default=default, key="save") if not file: return 0 # SavingReader(self, url, 'GET', {}, 0, 0, filename=file) self.message_clear() return 1
def file_save_game_clicked(self): self.fdlg = FileDialog.SaveFileDialog(self.root, title="Save A PDN File") if self.file_name == "": self.file_name = "test.pdn" self.file_name = self.fdlg.go(dir_or_file='/home/feike/BoomstraDam/pdn files', \ default = self.file_name, key = None) self.file_open_flag = True try: self.f = open(self.file_name, 'w') except: print "File not created" self.entire_file = '' for game in self.main.Games: self.entire_file = self.entire_file + self.game_to_string(game) print self.entire_file try: self.f.write(self.entire_file) except: print "File not written" try: self.f.close() except: print "File not closed" return
def exportMesh(self): file_dialog = FileDialog.Dialog() file_dialog.setFilter('Mesh files (*.flma *.su2 *.msh)') filename, extension = os.path.splitext(self.parent.airfoil.name) filename, _ = file_dialog.saveFilename(filename) if not filename: logger.info('No file selected. Nothing saved.') return # clean extension again (because added by file_dialog return) filename, extension = os.path.splitext(filename) # add boundary definition attributes to mesh object self.wind_tunnel.lineedit_airfoil = self.lineedit_airfoil.text() self.wind_tunnel.lineedit_inlet = self.lineedit_inlet.text() self.wind_tunnel.lineedit_outlet = self.lineedit_outlet.text() self.wind_tunnel.lineedit_symmetry = self.lineedit_symmetry.text() if self.check_FIRE.isChecked(): name = filename + '.flma' Meshing.BlockMesh.writeFLMA(self.wind_tunnel, name=name) if self.check_SU2.isChecked(): name = filename + '.su2' Meshing.BlockMesh.writeSU2(self.wind_tunnel, name=name) if self.check_GMSH.isChecked(): name = filename + '.msh' Meshing.BlockMesh.writeGMSH(self.wind_tunnel, name=name)
def load_file(self, file_name=None, start_dir=None): """Load a rosbag (*.bag) file. """ start = time.clock() if not file_name: if not start_dir: start_dir = '.' self.file_dialog = FileDialog(None, "Load rosbag ..", start_dir, "rosbag (*.bag)") # file_dialog.setAcceptMode(QtGui.QFileDialog.AcceptSave) self.file_dialog.show() self.file_dialog.fileSelected.connect(self.load_file) return file_name = unicode(file_name) self.file_name = file_name self.label1.setText(str(file_name)) self.file_info(file_name) end = time.clock() print("load file cost %s s" % (end - start))
def dbMenuOpenFile(): fd = FileDialog.LoadFileDialog(root) filePath = fd.go() if filePath!=None: dotIndex = filePath.rfind('.') if dotIndex!=-1: ext = filePath.rsplit('.',1) if ext[1]=='db': loadTable(filePath) else: SimpleDialog.SimpleDialog(root,text='请选择sqlite数据库(*.db)文件,\n选择的文件无效.',buttons=['确定']).go()
def loadFile(): global filename dialog = FileDialog(screen, (40, 40), ext=".photon", title="Load Photon File", parentRedraw=redrawMainWindow) retfilename = dialog.getFile() if not retfilename == None: filename = retfilename print("Returned: ", filename) openPhotonFile(filename) barefilename = (os.path.basename(filename)) pygame.display.set_caption("Photon File Editor - " + barefilename) ''' try: openPhotonFile(filename) except Exception as err: errMessageBox(str(err)) ''' else: print("User Canceled") return
def vOpenIHXCB(self, event=None): oFD = FileDialog.LoadFileDialog(self.oAppSprog.master, title='Load IHX File') filename = oFD.go(dir_or_file='.', key='track', pattern='*.ihx') if filename == None: return if self.bOpenIhxFile(filename) == False: tkMessageBox.showerror('File Error !!', 'It is not a correct IHX file...') return self.vDisplayHexFile(filename) self.filename = filename return
def callback_save(self, event=0): """ call FileDialog, to get the filename, then we save the content in the Text object (text_editor) to file""" outStr = self.text_editor.get(1.0, END) try: dialog = FileDialog.FileDialog(self.main_window) filename = dialog.go() writeOut = open(filename, 'w') writeOut.write(outStr) writeOut.close() except: pass
def batchConvert(self): """ 批量转换文件为json,自动获取选择文件夹下的xls文件,转为json """ fd = FileDialog(self) dir = fd.go() filenames = self.getFilesFromDir(dir, '.xls') # print(filenames) # 获取开启的线程数 threadnum = self.getThreadNum(len(filenames)) # 根据线程数对原有 filenames列表进行拆分,分配给不同线程 threadlist = self.splitList(filenames, threadnum) for list in threadlist: try: t1 = threading.Thread(target=ExcelToJson.doConvert, args=(self, list)) t1.start() t1.join() #threads.append(t1) except: print("Error: unable create thread") tkMessageBox.showinfo("Excel To Json", "转换成功")
def fileloadcallback(self): "The dialog box etc. for the load menu item" fd=FileDialog(self.root) file=fd.go(".","*.pf") # print " ***************** To load fractal file:", file,":" # DEBUG if(file != None): try: f=open(file,"r") except IOError: self.mesg("No such file") logger("No such file :"+file,ERROR) self.activatebuttons() return self.fractal=pickle.load(f) f.close() logger("Loaded fractal file "+file,SPL) self.autocomplete() self.cangle=self.fractal['sangle'] fractl.redraw() self.activatebuttons() else: self.mesg("Invalid file") logger("Invalid file name :"+file,ERROR)
def open_pdn_file(self): self.fdlg = FileDialog.LoadFileDialog(self.root, title="Choose A PDN File") self.fname = self.fdlg.go(pattern="*.pdn", dir_or_file=os.curdir + '\\pdn files') # opt args: dir_or_file=os.curdir, pattern="*", default="", key=None) print self.fname self.chr_pnt=0 self.entire_file=None self.file_open_flag = True try: self.f=open(self.fname, 'rb') self.entire_file=self.f.read() except: self.file_open_flag = False return self.file_open_flag
def importBitmaps(): global photonfile global layerNr global dispimg global layerimg if photonfile == None: print("No template loaded!!") infoMessageBox( "No photon file loaded!", "A .photon file is needed as template to load the bitmaps in.") return dialog = FileDialog(screen, (40, 40), ext=".png", title="Select directory with png files", parentRedraw=redrawMainWindow) directory = dialog.getDirectory() if not directory == None: print("Returned: ", directory) #try: popup = PopupDialog( screen, pos=(140, 140), title="Please wait...", message="Photon File Editor is importing your images.") popup.show() photonfile.replaceBitmaps(directory) layerNr = 0 refreshLayerControls() layerimg = photonfile.getBitmap(layerNr, layerForecolor, layerBackcolor) dispimg = layerimg #except Exception as err: # errMessageBox(str(err)) else: print("User Canceled") return
def callback_open(self, event=0): """ call FileDialog, to get the filename, then we load the file into the Text object (text_editor)""" try: dialog = FileDialog.FileDialog(self.main_window) filename = dialog.go() readIn = open(filename, 'r') lines = readIn.readlines() self.text_editor.delete("1.0", END) for line in lines: self.text_editor.insert(CURRENT, line) readIn.close() except: pass
def get_stand_file(self): self.s = '' # the string with the input to analyse self.cp = 0 # current position pointer in this string self.fdlg = FileDialog.LoadFileDialog(self.root, title="Choose A Stand File") self.fname = self.fdlg.go( pattern="*.stand", dir_or_file='/home/feike/BoomstraDam/stand files') self.file_open_flag = True try: self.f = open(self.fname, 'r') except: self.file_open_flag = False if self.file_open_flag == True: self.StandFileName = self.fname self.f.close() self.display_stand_line(0) return
def get_stand_file(self): self.s = '' # the string with the input to analyse self.cp = 0 # current position pointer in this string self.fdlg = FileDialog.LoadFileDialog(self.root, title="Choose A Stand File") self.fname = self.fdlg.go(pattern="*.stand", dir_or_file='/home/feike/Horizon/Stand') self.file_open_flag = True try: self.f = open(self.fname, 'r') except: self.file_open_flag = False if self.file_open_flag == True: # reset the Games environment self.main.Games = [] game = GameRecord(self.main, self.main.panel, self.main.panel) self.main.Games.append(game) self.main.ActiveGameNumber = 0 self.main.ActiveGame = self.main.Games[0] self.main.ActiveTag = '' # now enter a new game for each line in the stand file MoveNr = 0 for line in self.f: if len(line) > 60: WhiteRating = int(line[5:9]) BlackRating = int(line[10:14]) MoveNr = int(line[15:17]) WhiteResult = line[18:19] BlackResult = line[20:21] Result = WhiteResult + '-' + BlackResult pos = line[22:73] self.enter_pos(game, pos, WhiteRating, BlackRating, MoveNr, Result) else: pos = line[0:52] if len(pos) >= 51: MoveNr += 1 if MoveNr % 1000 == 0: print MoveNr self.enter_pos(game, pos, 0, 0, MoveNr, '0-0') # is entered, make room for a new position game = GameRecord(self.main, self.main.panel, self.main.panel) self.main.Games.append(game) self.main.ActiveGameNumber += 1 self.main.ActiveGameNumber = 0 self.main.ActiveGame = self.main.Games[0] self.main.ActiveGame.refresh_display() return
def save_figure(self, *args): fs = FileDialog.SaveFileDialog(master=self.window, title='Save the figure') try: self.lastDir except AttributeError: self.lastDir = os.curdir fname = fs.go(dir_or_file=self.lastDir) # , pattern="*.png") if fname is None: # Cancel return self.lastDir = os.path.dirname(fname) try: self.canvas.print_figure(fname) except IOError as msg: err = '\n'.join(map(str, msg)) msg = 'Failed to save %s: Error msg was\n\n%s' % (fname, err) error_msg_tkpaint(msg)
def onOpen(self): """Summary Returns: TYPE: Description """ file_dialog = FileDialog.Dialog() file_dialog.setFilter(DIALOGFILTER) filename, _ = file_dialog.openFilename(directory=AIRFOILDATA) if not filename: logger.info('No file selected. Nothing saved.') return if 'su2' in filename: self.loadSU2(filename) return self.loadAirfoil(filename)
def get_pdn_file(self, test, filename = '/home/feike/BoomstraDam/pdn files/thijssen.pdn' ): self.s = '' # the string with the input to analyse self.cp = 0 # current position pointer in this string self.current_color = dc.WHITE_ON_MOVE # used to analyse begin position self.current_king = False # used to analyse begin position self.current_number = 0 # used in get digit self.Games = [] self.lastchrpnt = 0 if test == True: self.fname = filename else: self.fdlg = FileDialog.LoadFileDialog(self.root, title="Choose A PDN File") self.fname = self.fdlg.go(pattern="*.pdn", dir_or_file='/home/feike/Horizon/pdn-files') # opt args: dir_or_file=os.curdir, pattern="*", default="", key=None) self.file_open_flag = True try: self.f = open(self.fname, 'rb') self.s = self.f.read() self.s = self.s + '\0' except: self.file_open_flag = False if self.file_open_flag == True: self.f.close() self.main.Games = self.GetGames() if self.main.Games == None: self.main.ActiveGame = None else: self.main.ActiveGame = self.main.Games[0] self.main.ActiveGameNumber = 0 if self.main.ActiveGame <> None: self.main.ActiveGame.refresh_display() self.main.ActiveGame.write_moves() self.main.panel.current_color_on_move.set(self.main.ActiveGame.BeginPosition.ColorOnMove) self.main.re_play.click(self.main.re_play.compose_tag([0, 0])) else: self.main.panel.notation.insert(END, "No valid PDN in File") return
def save_doc_file(self, doc_file_name=None): # this format can be read by TRUUS if doc_file_name == None: self.fdlg = FileDialog.SaveFileDialog(self.root, title="Save A DOC File") if self.file_name == "": self.file_name = "truus2009.doc" #self.file_name = self.fdlg.go(dir_or_file='/home/feike/BoomstraDam/doc files', \ self.file_name = self.fdlg.go(dir_or_file='/home/feike/workspace', \ default = self.file_name, key = None) else: self.file_name = doc_file_name self.file_open_flag = True try: self.f = open(self.file_name, 'w') except: print "File not created" return s = '' for game in self.main.Games: if game.is_standard_begin_position(): s = s + '\015\012' wp = game.WhitePlayer if wp == '': wp = "white player" bp = game.BlackPlayer if bp == '': bp = "black player" s = s + str(wp).ljust(24) + ' - ' + str(bp).ljust( 24) + ' 00.00 / 00.00' + '\015\012' for move in game.Moves: s = s + str(move.Ply_nr).zfill(2) + '.' + \ str(move.WhiteMove.Start).zfill(2) + self.doc_op(move.WhiteMove) + str(move.WhiteMove.Stop).zfill(2) if move.BlackMove: s = s + ' ' + str( move.BlackMove.Start).zfill(2) + self.doc_op( move.BlackMove) + str( move.BlackMove.Stop).zfill(2) s = s + '\015\012' s = s + '\015\012' + '\015\012' self.f.write(s) self.f.close() return
def get_game_from_pdn_file(self, filename = None): self.s = '' # the string with the input to analyse self.cp = 0 # current position pointer in this string self.current_color = dc.WHITE_ON_MOVE # used to analyse begin position self.current_king = False # used to analyse begin position self.current_number = 0 # used in get digit self.Games = [] self.lastchrpnt = 0 if filename: self.fname = filename else: self.fdlg = FileDialog.LoadFileDialog(self.root, title="Choose A PDN File") self.fname = self.fdlg.go(pattern="*.pdn", dir_or_file='/home/feike/Horizon/pdn-files') self.file_open_flag = True try: self.f = open(self.fname, 'rb') self.s = self.f.read() self.s = self.s + '\0' except: self.file_open_flag = False if self.file_open_flag == True: self.f.close() game = GameRecord(self.main, self.main.panel, self.main.panel) cp = self.GetGame(0, game) if cp == 0: print "Error in PDN, last char tried = ", self.lastchrpnt print self.s[cp-10:cp], self.s[self.lastchrpnt-70:self.lastchrpnt] return None else: # print "got pdn from file:", filename # print "half_ply_length = ", game.half_ply_length() pass return game
def get_stand_file(self): self.s = '' # the string with the input to analyse self.cp = 0 # current position pointer in this string self.fdlg = FileDialog.LoadFileDialog(self.root, title="Choose A Stand File") self.fname = self.fdlg.go( pattern="*.stand", dir_or_file='/home/feike/BoomstraDam/stand files') self.file_open_flag = True try: self.f = open(self.fname, 'r') except: self.file_open_flag = False if self.file_open_flag == True: # reset the Games environment self.main.Games = [] game = GameRecord(self.main, self.main.panel, self.main.panel) self.main.Games.append(game) self.main.ActiveGameNumber = 0 self.main.ActiveGame = self.main.Games[0] self.main.ActiveTag = '' # now enter a new game for each line in the stand file MoveNr = 0 for line in self.f: pos = line[0:52] if len(pos) >= 51: MoveNr += 1 if MoveNr % 1000 == 0: print MoveNr self.enter_pos(game, pos, 0, 0, MoveNr, '0-0') # is entered, make room for a new position game = GameRecord(self.main, self.main.panel, self.main.panel) self.main.Games.append(game) self.main.ActiveGameNumber += 1 self.main.ActiveGameNumber = 0 self.main.ActiveGame = self.main.Games[0] self.main.ActiveGame.refresh_display() return