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)
python类askopenfilename()的实例源码
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 loadGame(tkRoot):
print("loadGame")
#so we need to open a file select menu, filtering for .wwr
#then we just parse the string to our dict.
loadFileName = filedialog.askopenfilename(title = "Select file",filetypes = (("warpWar files","*.wwr"),("all files","*.*")))
print (loadFileName)
loadFile = open(loadFileName, 'r')
gameString = loadFile.read()
loadFile.close()
gameDict = json.loads(gameString)
#send the game to the server.
sendJson = warpWarCmds().restoreGame(tkRoot.cfg.Profile.plid, gameDict)
print (sendJson)
tkRoot.hCon.sendCmd(sendJson)
# I don't like these. They don't seem very objecty
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 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 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 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 _load_run_results(self):
filename = filedialog.askopenfilename()
if not filename:
return
self.runresultsvar.set(filename)
valid_parsers = importer.get_parsers(filename, self.cfg)
if not valid_parsers:
messagebox.showerror(
'Unknown Format', 'Unable to parse this file. '
'View log for details.')
self.choose_parser['values'] = ['']
self.choose_parser.current(0)
self.choose_parser.event_generate('<<ComboboxSelected>>')
return
self.valid_parsers = {p.__name__: p for p in valid_parsers}
self.choose_parser['values'] = list(self.valid_parsers.keys())
if len(valid_parsers) > 1:
self.choose_parser.config(state='enabled')
self.choose_parser.current(0)
self.choose_parser.event_generate('<<ComboboxSelected>>')
def restore_clustering(self):
# A window pops up asking the user to specify the path of a *.ANobj (Analysis Object) file
# and attempts to restore it using the Analysis.restore classmethod. Then opens a ClusteringWindow
# which gives the user the option to plot clusters, save the object, or close the window.
fname = askopenfilename(initialdir=IRIS_CSCRATCH_DIR,
filetypes=(("Analysis File Object", "*.ANobj"), ("All Files", "*.*")))
if fname == "" or fname == (): return None
try:
self.AN = analysis.Analysis.restore(fname)
self._restore_settings_from_loaded_object()
self.root.event_generate("<<clustering_restored>>", when="tail")
self.using_analysis_var.set("Using analysis object from\n{}".format(jt.break_path(fname, 24)))
self.using_analysis_label.config(fg="dark green")
except:
ErrorWindow(self.root, "Incorrect file format.")
return None
def upfile(self):
url = "http://" + HOST + ":" + PORT + "/upfile"
# ???????
filename = filedialog.askopenfilename()
self.lfc_field_1_t.delete('0.0', 'end')
self.lfc_field_1_t.insert('0.0', "??????......")
try:
files = {'file': open(str(filename), 'rb')}
req = requests.post(url, files=files)
if req.status_code == 200:
messagebox.showinfo("??", "????")
else:
messagebox.showinfo("??", "????????")
except:
messagebox.showinfo("??", "????????")
finally:
self.lfc_field_1_t.delete('0.0', 'end')
# ????
def open_file(self):
global once
once = True
img_file = filedialog.askopenfilename()
# this makes sure you select a file
# otherwise program crashes if not
if img_file != '':
self.img_path = img_file
# this just makes sure the image shows up after opening it
self.low_hue.set(self.low_hue.get()+1)
self.low_hue.set(self.low_hue.get()-1)
else:
print('picked nothing')
return 0
def __init__(self, response=str, text="", title=None, accept=0, **options):
if response is bool:
self.dialog = [askyesno, askokcancel, askretrycancel][accept]
else: self.dialog = {None:showinfo, str:askstring, int:askinteger, float:askfloat,
0:askopenfilename, 1:asksaveasfilename, 2:askdirectory}[response]
self.options = options.copy()
if "initialdir" in options:
self.options["initialdir"] = abspath(options["initialdir"])
if type(response) is int:
self.args = tuple()
if title: self.options["title"] = title
else:
if title is None:
title = "Info" if response is None else "Confirm" if response is bool else "Input"
self.args = title, text
def drawhistorigram(self, master):
try:
self.Lb1.delete(0, END)
except:
self.Lb1 = Listbox(master, selectmode=MULTIPLE)
self.filename = askopenfilename()
mostpixels = historigram(self.filename)
for i in range(len(mostpixels)):
self.Lb1.insert(i+1, "Pixels: " + str(mostpixels[i][1]) + ', ' + "Value: " +str(mostpixels[i][0]))
self.Lb1.pack()
def open_file(self):
filename = filedialog.askopenfilename()
if filename and (
not self.bodies or messagebox.askokcancel("Discard Changes", "Are you sure you want to discard changes?")):
self.filename = filename
self.name.set(os.path.split(filename)[-1])
for window in self.properties_windows:
window.destroy()
self.properties_windows = []
with open(filename) as file:
self.bodies[:] = generate_bodies(load_save(self, file))
def select_json():
selection = filedialog.askopenfilename(initialdir=getcwd(),
title='Select project json file')
_jsonVar.set(selection)
print('Selected json file: {}'.format(_jsonVar.get()))
def select_seed():
selection = filedialog.askopenfilename(initialdir=getcwd(),
title='Select IVS seed file')
_seedVar.set(selection)
print('Selected seed file: {}'.format(_seedVar.get()))