def loadPiecesFile():
global movesString
global piecesString
global status
filename = filedialog.askopenfilename()
if not filename.endswith('.txt'):
messagebox.showinfo("Visualizer error", "Filetype must be a .txt")
else:
with open(filename, 'r') as infile:
piecesString = infile.read().replace('\n', '')
if piecesString is not None and movesString is not None:
status.set("Pieces: Loaded\nMoves: Loaded")
generateFrames(piecesString,movesString)
elif movesString is None:
status.set("Pieces: Loaded\nMoves: Not Loaded")
python类askopenfilename()的实例源码
def openBox(
self,
title=None,
dirName=None,
fileTypes=None,
asFile=False):
self.topLevel.update_idletasks()
# define options for opening
options = {}
if title is not None:
options['title'] = title
if dirName is not None:
options['initialdir'] = dirName
if fileTypes is not None:
options['filetypes'] = fileTypes
if asFile:
return filedialog.askopenfile(mode="r", **options)
# will return "" if cancelled
else:
return filedialog.askopenfilename(**options)
def loadMovesFile():
global movesString
global piecesString
global status
filename = filedialog.askopenfilename()
if not filename.endswith('.txt'):
messagebox.showinfo("Visualizer error", "Filetype must be a .txt")
else:
with open(filename, 'r') as infile:
movesString = infile.read().replace('\n', '')
if piecesString is not None and movesString is not None:
status.set("Pieces: Loaded\nMoves: Loaded")
generateFrames(piecesString,movesString)
elif piecesString is None:
status.set("Pieces: Not Loaded\nMoves: Loaded")
def loadMovesFile():
global movesString
global piecesString
global status
filename = filedialog.askopenfilename()
if not filename.endswith('.txt'):
messagebox.showinfo("Visualizer error", "Filetype must be a .txt")
else:
with open(filename, 'r') as infile:
movesString = infile.read().replace('\n', '')
if piecesString is not None and movesString is not None:
status.set("Pieces: Loaded\nMoves: Loaded")
generateFrames(piecesString,movesString)
elif piecesString is None:
status.set("Pieces: Not Loaded\nMoves: Loaded")
def loadPiecesFile():
global movesString
global piecesString
global status
filename = filedialog.askopenfilename()
if not filename.endswith('.txt'):
messagebox.showinfo("Visualizer error", "Filetype must be a .txt")
else:
with open(filename, 'r') as infile:
piecesString = infile.read().replace('\n', '')
if piecesString is not None and movesString is not None:
status.set("Pieces: Loaded\nMoves: Loaded")
generateFrames(piecesString,movesString)
elif movesString is None:
status.set("Pieces: Loaded\nMoves: Not Loaded")
def openBox(
self,
title=None,
dirName=None,
fileTypes=None,
asFile=False):
self.topLevel.update_idletasks()
# define options for opening
options = {}
if title is not None:
options['title'] = title
if dirName is not None:
options['initialdir'] = dirName
if fileTypes is not None:
options['filetypes'] = fileTypes
if asFile:
return filedialog.askopenfile(mode="r", **options)
# will return "" if cancelled
else:
return filedialog.askopenfilename(**options)
def fileChooser(self, ftype, tkentry, tkcheck=None, tkbutton=None):
file_opt = FTYPE_MAP[ftype]
file_opt['parent'] = None
file_opt['initialdir'] = self.prefs['lastDir'][ftype]
file_opt['multiple'] = False
inpath = askopenfilename(**file_opt)
if len(inpath):
tkentry.config(state="normal")
tkentry.delete(0, tkinter.constants.END)
tkentry.insert(0, os.path.normpath(inpath))
self.prefs['lastDir'][ftype] = os.path.dirname(inpath)
tkentry.config(state="readonly")
else:
if tkcheck is not None:
tkcheck.deselect()
if tkbutton is not None:
tkbutton.config(state='disabled')
def apply_settings(self, gui, filename, category, keywords):
# TODO: Change to use the above methods for setting the keyfiles.
# TODO: Also needs to evenually allow for LE certs and self-signed.
gui.keyFilename = filedialog.askopenfilename(initialdir="/", title="Select file")
print(gui.filename)
self.filenameInput.insert(0, gui.filename)
response = gui.getClient().upload(filename, category, keywords)
"""
Goes back to the home page.
"""
gui.show_frame(home_gui.HomePage)
# self.filenameInput.delete(0, 'end')
# self.categoryInput.delete(0, 'end')
# self.keywordsInput.delete(0, 'end')
def file_open(self, event=None):
file_to_open = filedialog.askopenfilename()
if file_to_open:
self.open_file = file_to_open
self.main_text.delete(1.0, tk.END)
with open(file_to_open, "r") as file_contents:
file_lines = file_contents.readlines()
if len(file_lines) > 0:
for index, line in enumerate(file_lines):
index = float(index) + 1.0
self.main_text.insert(index, line)
self.title(" - ".join([self.WINDOW_TITLE, self.open_file]))
final_index = self.main_text.index(tk.END)
final_line_number = int(final_index.split(".")[0])
for line_number in range(final_line_number):
line_to_tag = ".".join([str(line_number), "0"])
self.tag_keywords(None, line_to_tag)
def file_open(self, event=None):
file_to_open = filedialog.askopenfilename()
if file_to_open:
self.open_file = file_to_open
self.main_text.delete(1.0, tk.END)
with open(file_to_open, "r") as file_contents:
file_lines = file_contents.readlines()
if len(file_lines) > 0:
for index, line in enumerate(file_lines):
index = float(index) + 1.0
self.main_text.insert(index, line)
self.title(" - ".join([self.WINDOW_TITLE, self.open_file]))
self.tag_all_lines()
def load_chart(self, *args):
"Load a chart from a pickle file"
filename = askopenfilename(filetypes=self.CHART_FILE_TYPES,
defaultextension='.pickle')
if not filename: return
try:
with open(filename, 'rb') as infile:
chart = pickle.load(infile)
self._chart = chart
self._cv.update(chart)
if self._matrix: self._matrix.set_chart(chart)
if self._matrix: self._matrix.deselect_cell()
if self._results: self._results.set_chart(chart)
self._cp.set_chart(chart)
except Exception as e:
raise
tkinter.messagebox.showerror('Error Loading Chart',
'Unable to open file: %r' % filename)
def load_grammar(self, *args):
"Load a grammar from a pickle file"
filename = askopenfilename(filetypes=self.GRAMMAR_FILE_TYPES,
defaultextension='.cfg')
if not filename: return
try:
if filename.endswith('.pickle'):
with open(filename, 'rb') as infile:
grammar = pickle.load(infile)
else:
with open(filename, 'r') as infile:
grammar = CFG.fromstring(infile.read())
self.set_grammar(grammar)
except Exception as e:
tkinter.messagebox.showerror('Error Loading Grammar',
'Unable to open file: %r' % filename)
def on_load_json(self, *args):
"""Triggered when load-button is clicked.
Displays a load dialog, clears the GUI, populates the merge and uppdates the GUI"""
_setup_filename = filedialog.askopenfilename(defaultextension=".json",
filetypes=[('JSON files', '.json'), ('all files', '.*')],
title="Choose file")
if _setup_filename is not None:
self.notify_task('Loading setup..', 0)
try:
self.setup.load_from_file(_setup_filename=_setup_filename)
self.setup_filename.set(_setup_filename)
except Exception as e:
self.notify_messagebox("Error loading data", str(e))
self.setup_to_gui()
self.notify_task('Loading setup..done', 100)
self.resize()
def select_file(self, _default_extension, _file_types):
"""Brings up a selector dialog, prompting the user to select a file,
the relative path if the file is then saved to the filename property.
Also, the base path is set.
"""
if self.is_destination is True:
_filename = filedialog.asksaveasfilename(initialdir=os.path.dirname(self.filename.get()),
defaultextension=_default_extension,
filetypes=_file_types,
title="Choose destination file")
else:
_filename = filedialog.askopenfilename(initialdir=os.path.dirname(self.filename.get()),
defaultextension=_default_extension,
filetypes=_file_types,
title="Choose source file")
if _filename:
self.base_path = os.path.dirname(_filename)
self.filename.set(os.path.relpath(_filename, self.base_path))
def load_TED():
'''Loads a TED file and returns a TrackObject'''
root=tk.Tk()
root.withdraw()
root.attributes("-topmost", True)
file_opt = options = {}
options['defaultextension'] = '.ted'
options['filetypes'] = [('GT6TED', '.ted')]
options['initialdir'] = 'TED'
options['parent'] = root
options['title'] = 'Open file'
path = filedialog.askopenfilename(**file_opt)
filename = basename(path)
root.destroy()
try:
with open(path, mode='rb') as file:
tedfile = file.read()
Track = initFromTedFile(tedfile, filename)
return Track
except FileNotFoundError:
return None
def openBox(
self,
title=None,
dirName=None,
fileTypes=None,
asFile=False):
self.topLevel.update_idletasks()
# define options for opening
options = {}
if title is not None:
options['title'] = title
if dirName is not None:
options['initialdir'] = dirName
if fileTypes is not None:
options['filetypes'] = fileTypes
if asFile:
return filedialog.askopenfile(mode="r", **options)
# will return "" if cancelled
else:
return filedialog.askopenfilename(**options)
chartparser_app.py 文件源码
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda
作者: SignalMedia
项目源码
文件源码
阅读 18
收藏 0
点赞 0
评论 0
def load_chart(self, *args):
"Load a chart from a pickle file"
filename = askopenfilename(filetypes=self.CHART_FILE_TYPES,
defaultextension='.pickle')
if not filename: return
try:
with open(filename, 'rb') as infile:
chart = pickle.load(infile)
self._chart = chart
self._cv.update(chart)
if self._matrix: self._matrix.set_chart(chart)
if self._matrix: self._matrix.deselect_cell()
if self._results: self._results.set_chart(chart)
self._cp.set_chart(chart)
except Exception as e:
raise
tkinter.messagebox.showerror('Error Loading Chart',
'Unable to open file: %r' % filename)
chartparser_app.py 文件源码
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda
作者: SignalMedia
项目源码
文件源码
阅读 27
收藏 0
点赞 0
评论 0
def load_grammar(self, *args):
"Load a grammar from a pickle file"
filename = askopenfilename(filetypes=self.GRAMMAR_FILE_TYPES,
defaultextension='.cfg')
if not filename: return
try:
if filename.endswith('.pickle'):
with open(filename, 'rb') as infile:
grammar = pickle.load(infile)
else:
with open(filename, 'r') as infile:
grammar = CFG.fromstring(infile.read())
self.set_grammar(grammar)
except Exception as e:
tkinter.messagebox.showerror('Error Loading Grammar',
'Unable to open file: %r' % filename)
def main_updateFirmware():
root.update()
FWfileName=askopenfilename(filetypes=(("BennVenn Firmware File","*.BEN"),("All Files","*.*")))
if FWfileName:
FWfile=open(FWfileName,'rb')
FWbuffer=FWfile.read()
FWsize=len(FWbuffer)
if FWsize==33280:
dev.write(0x01,[0x03])
USBbuffer = dev.read(0x81,64)
app.lowerRightLabel.set(("File Size Correct"))
for FWpos in range (512,33279,64):
dev.write(0x01,FWbuffer[FWpos:FWpos+64])
else:
app.lowerRightLabel.set(("File Invalid"))
FWfile.close()
exit()
def main_GBA_Write64kEEPROM():
root.update()
SRAMfileName=askopenfilename(filetypes=(("GBA Save File","*.SAV"),("All Files","*.*")))
if SRAMfileName:
SRAMfile=open(SRAMfileName,'rb')
SRAMbuffer=SRAMfile.read()
SRAMsize=len(SRAMbuffer)
for Address in range(0,1024):
Lo2=Address&0xFF
Me2=(Address&0xFF00) >> 8
Data8Bytes=SRAMbuffer[(Address*8):(Address*8)+8]
Me=Me2.to_bytes(1,'little')
Lo=Lo2.to_bytes(1,'little')
WriteCommand=b'\x37\x00\x00'+Me+Lo
Dataout=WriteCommand+Data8Bytes
dev.write(0x01,Dataout)
RAMbuffer= dev.read(0x81,64)
for WriteDelay in range (0,10):#10 usb write transactions = 10ms
dev.write(0x01,[0x38,0x00,0x00,Me2,Lo2])
SRAMfile.close()
print ('Done!')
def main_GBA_Write4kEEPROM():
root.update()
SRAMfileName=askopenfilename(filetypes=(("GBA Save File","*.SAV"),("All Files","*.*")))
if SRAMfileName:
SRAMfile=open(SRAMfileName,'rb')
SRAMbuffer=SRAMfile.read()
SRAMsize=len(SRAMbuffer)
for Address in range(0,64):
Lo2=Address&0xFF
Me2=(Address&0xFF00) >> 8
Data8Bytes=SRAMbuffer[(Address*8):(Address*8)+8]
Me=Me2.to_bytes(1,'little')
Lo=Lo2.to_bytes(1,'little')
WriteCommand=b'\x3D\x00\x00'+Me+Lo
Dataout=WriteCommand+Data8Bytes
dev.write(0x01,Dataout)
RAMbuffer= dev.read(0x81,64)
for WriteDelay in range (0,10):#10 usb write transactions = 10ms
dev.write(0x01,[0x38,0x00,0x00,Me2,Lo2])
SRAMfile.close()
print ('Done!')
def main_GBA_Write64kFLASHRAM():
root.update()
SRAMfileName=askopenfilename(filetypes=(("GBA Save File","*.SAV"),("All Files","*.*")))
if SRAMfileName:
main_GBA_FlashSaveErase()
SRAMfile=open(SRAMfileName,'rb')
SRAMbuffer=SRAMfile.read()
SRAMsize=len(SRAMbuffer)
dev.write(0x01,[0x39,0x00,0x00,0x00,0x00,0x00])
RAMbuffer= dev.read(0x81,64)
for Address in range(0,SRAMsize,32):
Lo=Address&0xFF
Me=(Address&0xFF00) >> 8
Data32Bytes=SRAMbuffer[Address:Address+32]
Me=Me.to_bytes(1,'little')
Lo=Lo.to_bytes(1,'little')
WriteCommand=b'\x3B\x00\x00'+Me+Lo
Dataout=WriteCommand+Data32Bytes
dev.write(0x01,Dataout)
RAMbuffer= dev.read(0x81,64)
SRAMfile.close()
print ('Done!')
def main_updateFirmware():
root.update()
FWfileName=askopenfilename(filetypes=(("BennVenn Firmware File","*.BEN"),("All Files","*.*")))
if FWfileName:
FWfile=open(FWfileName,'rb')
FWbuffer=FWfile.read()
FWsize=len(FWbuffer)
if FWsize==33280:
dev.write(0x01,[0x03])
USBbuffer = dev.read(0x81,64)
app.lowerRightLabel.set(("File Size Correct"))
for FWpos in range (512,33279,64):
dev.write(0x01,FWbuffer[FWpos:FWpos+64])
else:
app.lowerRightLabel.set(("File Invalid"))
FWfile.close()
exit()
def main_GBA_Write4kEEPROM():
root.update()
SRAMfileName=askopenfilename(filetypes=(("GBA Save File","*.SAV"),("All Files","*.*")))
if SRAMfileName:
SRAMfile=open(SRAMfileName,'rb')
SRAMbuffer=SRAMfile.read()
SRAMsize=len(SRAMbuffer)
for Address in range(0,64):
Lo2=Address&0xFF
Me2=(Address&0xFF00) >> 8
Data8Bytes=SRAMbuffer[(Address*8):(Address*8)+8]
Me=Me2.to_bytes(1,'little')
Lo=Lo2.to_bytes(1,'little')
WriteCommand=b'\x3D\x00\x00'+Me+Lo
Dataout=WriteCommand+Data8Bytes
dev.write(0x01,Dataout)
RAMbuffer= dev.read(0x81,64)
for WriteDelay in range (0,10):#10 usb write transactions = 10ms
dev.write(0x01,[0x38,0x00,0x00,Me2,Lo2])
SRAMfile.close()
print ('Done!')
def main_GBA_Write64kSRAM():
root.update()
SRAMfileName=askopenfilename(filetypes=(("GBA Save File","*.SAV"),("All Files","*.*")))
if SRAMfileName:
SRAMfile=open(SRAMfileName,'rb')
SRAMbuffer=SRAMfile.read()
SRAMsize=len(SRAMbuffer)
for Address in range(0,SRAMsize,32):
Lo=Address&0xFF
Me=(Address&0xFF00) >> 8
Data32Bytes=SRAMbuffer[Address:Address+32]
Me=Me.to_bytes(1,'little')
Lo=Lo.to_bytes(1,'little')
WriteCommand=b'\x36\x00\x00'+Me+Lo
Dataout=WriteCommand+Data32Bytes
dev.write(0x01,Dataout)
RAMbuffer= dev.read(0x81,64)
SRAMfile.close()
print ('Done!')
def main_GBA_Write64kFLASHRAM():
root.update()
SRAMfileName=askopenfilename(filetypes=(("GBA Save File","*.SAV"),("All Files","*.*")))
if SRAMfileName:
main_GBA_FlashSaveErase()
SRAMfile=open(SRAMfileName,'rb')
SRAMbuffer=SRAMfile.read()
SRAMsize=len(SRAMbuffer)
dev.write(0x01,[0x39,0x00,0x00,0x00,0x00,0x00])
RAMbuffer= dev.read(0x81,64)
for Address in range(0,SRAMsize,32):
Lo=Address&0xFF
Me=(Address&0xFF00) >> 8
Data32Bytes=SRAMbuffer[Address:Address+32]
Me=Me.to_bytes(1,'little')
Lo=Lo.to_bytes(1,'little')
WriteCommand=b'\x3B\x00\x00'+Me+Lo
Dataout=WriteCommand+Data32Bytes
dev.write(0x01,Dataout)
RAMbuffer= dev.read(0x81,64)
SRAMfile.close()
print ('Done!')
def open(self):
filename = filedialog.askopenfilename(initialdir="data/")
if filename:
with open(filename, 'r') as f:
o = json.load(f)
self.methodvar.set(o["method"])
self.schemavar.set(o["schema"])
self.urlvar.set(o["url"])
self.datah_text.delete(1.0,END)
self.datah_text.insert(END,o["sheaders"])
self.data_text.delete(1.0,END)
self.data_text.insert(END,o["data"])
self.response_headers.delete(1.0,END)
self.response_headers.insert(END,o["response_headers"])
self.response_data.delete(1.0,END)
self.response_data.insert(END,o["response_data"])
def load_chart(self, *args):
"Load a chart from a pickle file"
filename = askopenfilename(filetypes=self.CHART_FILE_TYPES,
defaultextension='.pickle')
if not filename: return
try:
with open(filename, 'rb') as infile:
chart = pickle.load(infile)
self._chart = chart
self._cv.update(chart)
if self._matrix: self._matrix.set_chart(chart)
if self._matrix: self._matrix.deselect_cell()
if self._results: self._results.set_chart(chart)
self._cp.set_chart(chart)
except Exception as e:
raise
tkinter.messagebox.showerror('Error Loading Chart',
'Unable to open file: %r' % filename)
def load_grammar(self, *args):
"Load a grammar from a pickle file"
filename = askopenfilename(filetypes=self.GRAMMAR_FILE_TYPES,
defaultextension='.cfg')
if not filename: return
try:
if filename.endswith('.pickle'):
with open(filename, 'rb') as infile:
grammar = pickle.load(infile)
else:
with open(filename, 'r') as infile:
grammar = CFG.fromstring(infile.read())
self.set_grammar(grammar)
except Exception as e:
tkinter.messagebox.showerror('Error Loading Grammar',
'Unable to open file: %r' % filename)
def browseFiles(self):
self.filename = filedialog.askopenfilename(
title='Select image source',
filetypes=(('jpeg files', '*.jpg'), ('all files', '*.*'))
)
if self.filename:
self.file_selection_string.set(self.filename.split('/')[-1])
img = Image.open(self.filename)
self.last_frame = np.array(img)
self.img_update = True
self.process_status[0] = 1
self.manager.assignSourceImage(self.last_frame, self.filename)
self.updateVideoHolder()
self.updateInformation()