本文整理汇总了Python中enthought.pyface.api.FileDialog.open方法的典型用法代码示例。如果您正苦于以下问题:Python FileDialog.open方法的具体用法?Python FileDialog.open怎么用?Python FileDialog.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类enthought.pyface.api.FileDialog
的用法示例。
在下文中一共展示了FileDialog.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open_menu
# 需要导入模块: from enthought.pyface.api import FileDialog [as 别名]
# 或者: from enthought.pyface.api.FileDialog import open [as 别名]
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()
示例2: _dialog
# 需要导入模块: from enthought.pyface.api import FileDialog [as 别名]
# 或者: from enthought.pyface.api.FileDialog import open [as 别名]
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
示例3: _load_button_fired
# 需要导入模块: from enthought.pyface.api import FileDialog [as 别名]
# 或者: from enthought.pyface.api.FileDialog import open [as 别名]
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
示例4: _save_as_button_fired
# 需要导入模块: from enthought.pyface.api import FileDialog [as 别名]
# 或者: from enthought.pyface.api.FileDialog import open [as 别名]
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()
示例5: _on_open
# 需要导入模块: from enthought.pyface.api import FileDialog [as 别名]
# 或者: from enthought.pyface.api.FileDialog import open [as 别名]
def _on_open(self, info):
""" Menu action to load a script from file. """
file_dialog = FileDialog(action='open',
default_directory=info.object.file_directory,
wildcard='All files (*.*)|*.*')
file_dialog.open()
if file_dialog.path != '':
info.object.load_code_from_file(file_dialog.path)
return
示例6: _load_button_fired
# 需要导入模块: from enthought.pyface.api import FileDialog [as 别名]
# 或者: from enthought.pyface.api.FileDialog import open [as 别名]
def _load_button_fired(self):
dialog = FileDialog(action="open", wildcard=self.file_wildcard)
dialog.open()
if dialog.return_code == OK:
f = open(dialog.path, 'r')
data = f.readline()
if data.endswith('\n'):
data = data[:-1]
self.value = data
self.filedir = dialog.directory
self.filename = dialog.filename
self.saved = True
示例7: _on_save_as
# 需要导入模块: from enthought.pyface.api import FileDialog [as 别名]
# 或者: from enthought.pyface.api.FileDialog import open [as 别名]
def _on_save_as(self, info):
""" Menu action to save script to file of different name """
file_dialog = FileDialog(action='save as',
default_path=info.object.file_directory,
wildcard='All files (*.*)|*.*')
file_dialog.open()
if file_dialog.path != '':
info.object.save_code_to_file(file_dialog.path)
msg = 'Saving script at ', file_dialog.path
logger.debug(msg)
return
示例8: _on_import_data_file
# 需要导入模块: from enthought.pyface.api import FileDialog [as 别名]
# 或者: from enthought.pyface.api.FileDialog import open [as 别名]
def _on_import_data_file(self, info):
""" Loading data files to import data for data contexts.
File formats supported are ASCII, LAS, CSV, pickled files.
ASCII files can be tab- or whitespace- delimited.
If geo cannot be imported, only the pickled files can be
used.
"""
try:
import geo
wildcard = 'All files (*.*)|*.*|' + \
'ASCII files (*.asc)|*.asc|' + \
'Text files (*.txt)|*.txt|' + \
'CSV files (*.csv)|*.csv|' + \
'LAS files (*.las)|*.las|' + \
'Pickled files (*.pickle)|*.pickle|'+ \
'Segy files (*.segy)|*.segy'
except ImportError:
wildcard = 'Pickled files (*.pickle)|*.pickle'
app = info.object
file_dialog = FileDialog(action = 'open',
default_directory = app.data_directory,
wildcard = wildcard,
)
file_dialog.open()
data_context, filename = None, file_dialog.path
if file_dialog.path != '':
filesplit = os.path.splitext(filename)
if filesplit[1] != '':
configurable_import = ConfigurableImportUI(filename = filename,
wildcard = wildcard)
ui = configurable_import.edit_traits(kind='livemodal')
if ui.result and isinstance(configurable_import.context,DataContext):
data_context = configurable_import.context
app.load_context(
data_context, mode=configurable_import.save_choice_)
filename = configurable_import.filename
if isinstance(data_context,DataContext):
logger.debug('Loading data from %s' % filename)
else:
logger.error('Unidentified file format for data import: %s' %
filename)
return
示例9: on_savefig
# 需要导入模块: from enthought.pyface.api import FileDialog [as 别名]
# 或者: from enthought.pyface.api.FileDialog import open [as 别名]
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: on_savedata
# 需要导入模块: from enthought.pyface.api import FileDialog [as 别名]
# 或者: from enthought.pyface.api.FileDialog import open [as 别名]
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
示例11: _load_button_fired
# 需要导入模块: from enthought.pyface.api import FileDialog [as 别名]
# 或者: from enthought.pyface.api.FileDialog import open [as 别名]
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: _save_button_fired
# 需要导入模块: from enthought.pyface.api import FileDialog [as 别名]
# 或者: from enthought.pyface.api.FileDialog import open [as 别名]
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()
示例13: open_file
# 需要导入模块: from enthought.pyface.api import FileDialog [as 别名]
# 或者: from enthought.pyface.api.FileDialog import open [as 别名]
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"
示例14: on_savefig
# 需要导入模块: from enthought.pyface.api import FileDialog [as 别名]
# 或者: from enthought.pyface.api.FileDialog import open [as 别名]
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
示例15: save_as
# 需要导入模块: from enthought.pyface.api import FileDialog [as 别名]
# 或者: from enthought.pyface.api.FileDialog import open [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