本文整理汇总了Python中enthought.pyface.api.FileDialog类的典型用法代码示例。如果您正苦于以下问题:Python FileDialog类的具体用法?Python FileDialog怎么用?Python FileDialog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileDialog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_savefig
def on_savefig ( self ):
""" Handles the user requesting that the image of the function is to be saved.
"""
import os
dlg = FileDialog(parent = self.control,
title = 'Save as image',
default_directory=os.getcwd(),
default_filename="", wildcard=WILDCARD,
action='save as')
if dlg.open() == OK:
path = dlg.path
print "Saving plot to", path, "..."
try:
# Now we create a canvas of the appropriate size and ask it to render
# our component. (If we wanted to display this plot in a window, we
# would not need to create the graphics context ourselves; it would be
# created for us by the window.)
self._plot.bounds = [500,300]
self._plot.padding = 50
plot_gc = PlotGraphicsContext(self._plot.outer_bounds)
print self._plot.outer_bounds
plot_gc.render_component(self._plot)
# Finally, we tell the graphics context to save itself to disk as an image.
plot_gc.save(path)
except:
print "Error saving!"
raise
print "Plot saved."
return
示例2: perform
def perform(self, event):
plot_component = self.container.component
filter = 'PNG file (*.png)|*.png|\nTIFF file (*.tiff)|*.tiff|'
dialog = FileDialog(action='save as', wildcard=filter)
if dialog.open() != OK:
return
# Remove the toolbar before saving the plot, so the output doesn't
# include the toolbar.
plot_component.remove_toolbar()
filename = dialog.path
width, height = plot_component.outer_bounds
gc = PlotGraphicsContext((width, height), dpi=72)
gc.render_component(plot_component)
try:
gc.save(filename)
except KeyError, e:
errmsg = "The filename must have an extension that matches a graphics"
errmsg = errmsg + " format, such as '.png' or '.tiff'."
if str(e.message) != '':
errmsg = ("Unknown filename extension: '%s'\n" % str(e.message)) + errmsg
error(None, errmsg, title="Invalid Filename Extension")
示例3: open_menu
def open_menu(self):
dlg = FileDialog()
dlg.open()
if dlg.return_code == OK:
self.img.load_image(dlg.path)
self.update_affine()
self.update_slice_index()
示例4: on_savedata
def on_savedata ( self ):
""" Handles the user requesting that the data of the function is to be saved.
"""
import os
dlg = FileDialog(parent = self.control,
title = 'Export function data',
default_directory=os.getcwd(),
default_filename="", wildcard='*.csv',
action='save as')
if dlg.open() == OK:
path = dlg.path
print "Saving data to", path, "..."
try:
# factory = self.factory
# plotitem = factory.plotitem
# x_values = getattr(self.object, plotitem.index)
# y_values = getattr(self.object, plotitem.value)
x_values = self.value.xdata
y_values = self.value.ydata
savetxt( path, vstack( (x_values,y_values) ).transpose() )
except:
print "Error saving!"
raise
print "Plot saved."
return
示例5: on_savedata
def on_savedata ( self ):
""" Handles the user requesting that the data of the function is to be saved.
"""
import os
dlg = FileDialog(parent = self.control,
title = 'Export function data',
default_directory=os.getcwd(),
default_filename="", wildcard='*.csv',
action='save as')
if dlg.open() == OK:
path = dlg.path
print "Saving data to", path, "..."
try:
vectors = []
x_values = self.value.xdata
y_values = self.value.ydata
#savetxt( path, vstack( (x_values, y_values[:,0], y_values[:,1], y_values[:,2]) ).transpose() )
print 'y_values', y_values
y_values_tr = y_values.transpose()
for vector in y_values_tr[:]:
vectors.append(vector)
savetxt( path, vstack( (x_values, vectors) ).transpose() )
except:
print "Error saving!"
raise
print "Plot saved."
return
示例6: on_savefig
def on_savefig ( self ):
""" Handles the user requesting that the image of the function is to be saved.
"""
import os
dlg = FileDialog(parent = self.control,
title = 'Save as image',
default_directory=os.getcwd(),
default_filename="", wildcard=WILDCARD,
action='save as')
if dlg.open() == OK:
path = dlg.path
print "Saving plot to", path, "..."
try:
# Now we create a canvas of the appropriate size and ask it to render
# our component. (If we wanted to display this plot in a window, we
# would not need to create the graphics context ourselves; it would be
# created for us by the window.)
size=(650,400)
gc = GraphicsContext(size)
self.plot_container.draw(gc)
gc.save(path)
except:
print "Error saving!"
raise
print "Plot saved."
return
示例7: _save_as_button_fired
def _save_as_button_fired(self):
dialog = FileDialog(action="save as", wildcard=self.file_wildcard)
dialog.open()
if dialog.return_code == OK:
self.filedir = dialog.directory
self.filename = dialog.filename
self._save_to_file()
示例8: perform
def perform(self, event, cfile=None):
""" Performs the action. """
logger.info("Performing save connectome file action")
# helper variable to use this function not only in the menubar
exec_as_funct = True
cfile = self.window.application.get_service("cviewer.plugins.cff2.cfile.CFile")
wildcard = "Connectome File Format v2.0 (*.cff)|*.cff|" "All files (*.*)|*.*"
dlg = FileDialog(
wildcard=wildcard,
title="Save as Connectome File",
resizeable=False,
action="save as",
default_directory=preference_manager.cviewerui.cffpath,
)
if dlg.open() == OK:
if (dlg.paths[0]).endswith(".cff"):
cfflib.save_to_cff(cfile.obj, dlg.paths[0])
logger.info("Saved connectome file to %s" % dlg.paths[0])
示例9: on_savefig
def on_savefig ( self ):
""" Handles the user requesting that the image of the function is to be saved.
"""
import os
dlg = FileDialog(parent = self.control,
title = 'Save as image',
default_directory=os.getcwd(),
default_filename="", wildcard=WILDCARD,
action='save as')
if dlg.open() == OK:
path = dlg.path
print "Saving plot to", path, "..."
try:
# Now we create a canvas of the appropriate size and ask it to render
# our component. (If we wanted to display this plot in a window, we
# would not need to create the graphics context ourselves; it would be
# created for us by the window.)
# plot_gc = PlotGraphicsContext(self._plot.outer_bounds)
# plot_gc.render_component(self._plot)
#self._plot_container.outer_bounds = list((800,600))
# plot_gc = PlotGraphicsContext((400,300), dpi=72.0)
# plot_gc.render_component(self._plot_container)
# self.line_plot.bounds = [500,300]
# self.line_plot.padding = 50
#
# win_size = self.line_plot.outer_bounds
# # win_size = self.component.outer_bounds
# plot_gc = PlotGraphicsContext(win_size)
#
#
# # Have the plot component into it
# plot_gc.render_component(self.line_plot)
#
# # Finally, we tell the graphics context to save itself to disk as an image.
# plot_gc.save(path)
DPI = 70.0
size=(550,450)
# self.plot_container = create_plot()
self.plot_container.bounds = list(size)
self.plot_container.do_layout(force=True)
gc = PlotGraphicsContext(size, dpi=DPI)
#gc = GraphicsContext((size[0]+1, size[1]+1))
gc.render_component(self.plot_container)
gc.save(path)
except:
print "Error saving!"
raise
print "Plot saved."
return
示例10: save_as
def save_as(self, info):
""" Handles saving the current model to file.
"""
if not info.initialized:
return
# retval = self.edit_traits(parent=info.ui.control, view="file_view")
dlg = FileDialog( action = "save as",
wildcard = "Graphviz Files (*.dot, *.xdot, *.txt)|" \
"*.dot;*.xdot;*.txt|Dot Files (*.dot)|*.dot|" \
"All Files (*.*)|*.*|")
if dlg.open() == OK:
fd = None
try:
fd = open(dlg.path, "wb")
dot_code = str(self.model)
fd.write(dot_code)
self.save_file = dlg.path
except:
error(parent=info.ui.control, title="Save Error",
message="An error was encountered when saving\nto %s"
% self.file)
finally:
if fd is not None:
fd.close()
del dlg
示例11: _load_button_fired
def _load_button_fired(self):
dialog = FileDialog(action="open", wildcard='EQ files (*.eq)|*.eq')
result = dialog.open()
if result == OK:
f = file(dialog.path, "rb")
self.equalizers = pickle.load(f)
f.close()
示例12: _load_button_fired
def _load_button_fired(self):
dialog = FileDialog(action = "open", wildcard=self.file_wildcard)
dialog.open()
if dialog.return_code == OK:
self.init(smear.RawData(dialog.path))
#self.raw = smear.RawData(dialog.path, 'r')
self.filename = dialog.filename
示例13: _save_button_fired
def _save_button_fired(self):
dialog = FileDialog(action="save as", wildcard='EQ files (*.eq)|*.eq')
result = dialog.open()
if result == OK:
f = file(dialog.path, "wb")
pickle.dump( self.equalizers , f)
f.close()
示例14: _dialog
def _dialog(self, message="Select Folder", new_directory=True,mode='r'):
"""Creates a file dialog box for working with
@param message Message to display in dialog
@param new_file True if allowed to create new directory
@return A directory to be used for the file operation."""
try:
from enthought.pyface.api import FileDialog, OK
except ImportError:
from pyface.api import FileDialog, OK
# Wildcard pattern to be used in file dialogs.
file_wildcard = "hdf file (*.hdf5)|*.hdf5|Data file (*.dat)|\
*.dat|All files|*"
if mode == "r":
mode2 = "open"
elif mode == "w":
mode2 = "save as"
if self.directory is not None:
filename = path.basename(path.realpath(self.directory))
dirname = path.dirname(path.realpath(self.directory))
else:
filename = ""
dirname = ""
dlg = FileDialog(action=mode2, wildcard=file_wildcard)
dlg.open()
if dlg.return_code == OK:
self.directory = dlg.path
self.File=h5py.File(self.directory,mode)
self.File.close()
return self.directory
else:
return None
示例15: open_file
def open_file(window, path=None):
if path==None:
wildcard="|".join([
"All files (*)", "*",
"Hermes2D mesh files (*.mesh)", "*.mesh",
"Agros2D problem files (*.a2d)", "*.a2d",
])
dialog = FileDialog(parent=None, title='Open supported data file',
action='open', wildcard=wildcard,
# use this to have Hermes2D by default:
#wildcard_index=1,
wildcard_index=0,
default_directory=get_data_dir(),
#default_filename="lshape.mesh",
)
if dialog.open() == OK:
path = dialog.path
else:
return
ext = os.path.splitext(path)[1]
if ext == ".a2d":
scene = window.get_view_by_id("Problem")
p, g = read_a2d(path)
scene.problem = p
scene.geometry = g
else:
scene = window.get_view_by_id("Scene")
mesh = read_mesh(path)
scene.mesh = mesh
scene.mode = "mesh"