本文整理汇总了Python中pyface.api.FileDialog类的典型用法代码示例。如果您正苦于以下问题:Python FileDialog类的具体用法?Python FileDialog怎么用?Python FileDialog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileDialog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: perform
def perform(self,event):
"""Perform the Save Phantom Action """
wildcard = 'MagicalPhantom files (*.mp)|*.mp|' + FileDialog.WILDCARD_ALL
parent = self.window.control
dialog = FileDialog(parent=parent,
title = 'Open MagicalPhantom file',
action = 'open',wildcard = wildcard)
if dialog.open()==OK:
if not isfile(dialog.path):
error("File '%s' does not exist"%dialog.path,parent)
return
run_manager = self.window.application.get_service('mphantom.api.RunManager')
phantom = run_manager.model
print dialog.path
phantom.clear_phantom()
phantom.load_phantom(dialog.path)
self.window.active_perspective = self.window.perspectives[1]
示例2: _file_dialog_
def _file_dialog_(self, action, **kw):
'''
'''
# print 'file_dialog', kw
dlg = FileDialog(action=action, **kw)
if dlg.open() == OK:
return dlg.path
示例3: save_config_file
def save_config_file(self, ui_info):
dialog = FileDialog(action="save as", default_filename="config.ini")
dialog.open()
if dialog.return_code == OK:
save_config(self.pipeline, ui_info.ui.context["object"].project_info.config_file)
if dialog.path != ui_info.ui.context["object"].project_info.config_file:
shutil.copy(ui_info.ui.context["object"].project_info.config_file, dialog.path)
示例4: 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 as e:
errmsg = ("The filename must have an extension that matches "
"a graphics 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")
# Restore the toolbar.
plot_component.add_toolbar()
示例5: _save_
def _save_(self, type_='pic', path=None):
"""
"""
if path is None:
dlg = FileDialog(action='save as')
if dlg.open() == OK:
path = dlg.path
self.status_text = 'Image Saved: %s' % path
if path is not None:
if type_ == 'pdf':
self._render_to_pdf(filename=path)
else:
# auto add an extension to the filename if not present
# extension is necessary for PIL compression
# set default save type_ DEFAULT_IMAGE_EXT='.png'
# see http://infohost.nmt.edu/tcc/help/pubs/pil/formats.html
saved = False
for ei in IMAGE_EXTENSIONS:
if path.endswith(ei):
self._render_to_pic(path)
saved = True
break
if not saved:
self._render_to_pic(path + DEFAULT_IMAGE_EXT)
示例6: save_file
def save_file():
wildcard='*.txt'
dialog = FileDialog(title='Select the file to save as...',
action='save as', wildcard=wildcard)
if dialog.open() == Pyface_OK:
return dialog.path
return ''
示例7: OpenFileDialog
def OpenFileDialog(action, wildcard, self):
from pyface.api import FileDialog, OK
doaction = action
if action == "new":
doaction = "save as"
dialog = FileDialog(action=doaction, wildcard=wildcard)
dialog.open()
if dialog.return_code == OK:
self.filedir = dialog.directory
self.filename = dialog.filename
self.Configuration_File = os.path.join(dialog.directory, dialog.filename)
if action == "open":
self._config = load_config(dialog.path, self.config_class)
self._config.configure_traits(view=self.config_view())
self.saved = False
self.config_changed = True
if action == "new":
self._config = self.config_class()
self._config.configure_traits(view=self.config_view())
self._save_to_file()
self.saved = False
self.config_changed = True
if action == "save as":
self._save_to_file()
self.saved = True
self.config_changed = False
示例8: perform
def perform(self, event):
""" Performs the action. """
mv = get_imayavi(self.window)
s = get_scene(mv)
if s is None:
return
wildcard = 'All files (*.*)|*.*'
for src in registry.sources:
if len(src.extensions) > 0:
if wildcard.endswith('|') or \
src.wildcard.startswith('|'):
wildcard += src.wildcard
else:
wildcard += '|' + src.wildcard
parent = self.window.control
dialog = FileDialog(parent=parent,
title='Open supported data file',
action='open', wildcard=wildcard
)
if dialog.open() == OK:
if not isfile(dialog.path):
error("File '%s' does not exist!"%dialog.path, parent)
return
# FIXME: Ask for user input if a filetype is unknown and
# choose appropriate reader.
src = mv.open(dialog.path)
if src is not None:
mv.engine.current_selection = src
示例9: parse_autoupdate
def parse_autoupdate(self):
'''
'''
f = FileDialog(action='open',
# default_directory=paths.modeling_data_dir
default_directory=self.data_directory
)
if f.open() == OK:
self.info('loading autoupdate file {}'.format(f.path))
# open a autoupdate config dialog
from clovera_configs import AutoUpdateParseConfig
adlg = AutoUpdateParseConfig('', '')
info = adlg.edit_traits()
if info.result:
self.info('tempoffset = {} (C), timeoffset = {} (min)'.format(adlg.tempoffset, adlg.timeoffset))
rids = self.data_loader.load_autoupdate(f.path, adlg.tempoffset, adlg.timeoffset)
auto_files = True
if auto_files:
for rid in rids:
root = f.path + '_data'
with open(os.path.join(root, rid, 'samples.lst'), 'w') as s:
s.write('{}'.format(rid))
self.execute_files(rid=rid, root=root,
block=True)
示例10: _save_fired
def _save_fired(self):
import pickle
import os.path
# support the new traits api
try:
import apptools.sweet_pickle as sp
except ImportError:
import enthought.sweet_pickle as sp
# support the new traits api
try:
from pyface.api import FileDialog, OK
except ImportError:
from enthought.pyface.api import FileDialog, OK
wildcard = "CMP Configuration State (*.pkl)|*.pkl|" \
"All files (*.*)|*.*"
dlg = FileDialog(wildcard=wildcard,title="Filename to store configuration state",\
resizeable=False, action = 'save as', \
default_directory=self.subject_workingdir,)
if dlg.open() == OK:
if not dlg.path.endswith('.pkl'):
dlg.path = dlg.path + '.pkl'
self.save_state(dlg.path)
示例11: export_chaco_python
def export_chaco_python(self, info):
"""Implements the "File / Export / Chaco python code" menu item."""
dialog = FileDialog(
parent=info.ui.control,
default_filename=info.object.name + ".py",
action="save as",
title="Chaco python file",
)
if dialog.open() == OK:
# The data is attached to the function as an attribute. This
# will allow a program to import a module, look for functions in
# the module that have the _colormap_data attribute and recover
# the data without having to call the function.
f = open(dialog.path, "w")
f.write("\n")
f.write("from enthought.chaco.api import ColorMapper\n\n")
f.write("def %s(range, **traits):\n" % info.object.name)
f.write(' """Generator for the colormap "%s"."""\n' % info.object.name)
f.write(
(" return ColorMapper.from_segment_map(" "%s._colormap_data, range=range, **traits)\n\n")
% info.object.name
)
f.write("%s._colormap_data = " % info.object.name)
segment_map = info.object.colormap_editor._segment_map()
seg_code = "%r" % segment_map
seg_code = seg_code.replace("'red'", "\n 'red'")
seg_code = seg_code.replace("'green'", "\n 'green'")
seg_code = seg_code.replace("'blue'", "\n 'blue'")
seg_code = seg_code.replace("}", "\n }")
f.write(seg_code)
f.close()
示例12: open_outputdbs
def open_outputdbs():
"""Open file"""
wildcard = "Output files (*.dbx;*.exo)|*.dbx;*.exo|"
dialog = FileDialog(action="open files", wildcard=wildcard)
if dialog.open() != pyOK:
return []
return dialog.paths
示例13: save
def save(self, ui_info):
print self.view.save_image_file
fd = FileDialog(action='save as', default_path=self.view.save_image_file)
if fd.open() == OK:
print 'Saving figure to ', fd.path
self.view.save_image(fd.path)
self.view.save_image_file = fd.path
示例14: get_transformed_filename
def get_transformed_filename(filename):
dialog = FileDialog(default_path=filename, action="save as", title="Save as", wildcard=xye_wildcard)
if dialog.open() == OK:
filename = dialog.path
if filename:
return filename
return None
示例15: open
def open(self):
""" Shows a dialog to open a file.
"""
logger.debug('PythonShellTask: opening file')
dialog = FileDialog(parent=self.window.control, wildcard='*.py')
if dialog.open() == OK:
self._open_file(dialog.path)