本文整理汇总了Python中pyface.api.FileDialog.create_wildcard方法的典型用法代码示例。如果您正苦于以下问题:Python FileDialog.create_wildcard方法的具体用法?Python FileDialog.create_wildcard怎么用?Python FileDialog.create_wildcard使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyface.api.FileDialog
的用法示例。
在下文中一共展示了FileDialog.create_wildcard方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save
# 需要导入模块: from pyface.api import FileDialog [as 别名]
# 或者: from pyface.api.FileDialog import create_wildcard [as 别名]
def save(self):
extensions = [ '*.bmp', '*.gif', '*.jpg', '*.pdf',
'*.png', '*.svg', '*.tif', '*.xbm' ]
wildcard = FileDialog.create_wildcard('From file name', extensions)
dialog = FileDialog(action = 'save as',
default_directory = self.default_directory,
parent = self.window.control,
wildcard = wildcard)
if dialog.open() == OK:
filename = dialog.path
extension = os.path.splitext(filename)[1]
if not extension:
extension = '.png'
filename += extension
try:
# FIXME: Expose size and background color?
self.editor_area.active_editor.save(filename, bgcolor='white')
except Exception as exc:
msg = 'Failed to save image in %s format' % extension.upper()
dialog = MessageDialog(title = 'Error saving',
message = msg,
detail = str(exc),
parent = self.window.control,
severity = 'error')
dialog.open()
示例2: resize_and_save_matplotlib_figure
# 需要导入模块: from pyface.api import FileDialog [as 别名]
# 或者: from pyface.api.FileDialog import create_wildcard [as 别名]
def resize_and_save_matplotlib_figure(figure):
''' To save a matplotlib figure with custom width and height in pixels
requires changing the bounding box while is being rendered! '''
# get figure size
figure_size = MatplotlibFigureSize(figure=figure)
old_dpi = figure_size.dpi
old_width_inches = figure_size.width_inches
old_height_inches = figure_size.height_inches
ui = figure_size.edit_traits(kind='modal')
widget = ui.control
# maybe change figure size
if ui.result:
figure.dpi = figure_size.dpi # set new dpi
figure.bbox_inches.p1 = figure_size.width_inches, figure_size.height_inches # set new width and height in inches
else:
return
# get file name with (correct choice of formats)
fd = FileDialog(
action='save as',
wildcard=FileDialog.create_wildcard('All available formats', ['*.eps', '*.png', '*.pdf', '*.ps', '*.svg']),
)
if fd.open() != OK:
return
file_name = fd.path
# save it
figure.savefig(file_name)
# restore original figure size
figure.dpi = old_dpi # restore old dpi
figure.bbox_inches.p1 = old_width_inches, old_height_inches # restore old width and height in inches
示例3: _savePlot_fired
# 需要导入模块: from pyface.api import FileDialog [as 别名]
# 或者: from pyface.api.FileDialog import create_wildcard [as 别名]
def _savePlot_fired(self):
dialog = FileDialog(title='Save plot as...', action='save as',
wildcard = FileDialog.create_wildcard('Portable Network Graphics', '*.png'))
if not dialog.open():
self.add_line("ERROR opening save file.")
return
self.plotRU(save=True,filename=dialog.path)
示例4: open
# 需要导入模块: from pyface.api import FileDialog [as 别名]
# 或者: from pyface.api.FileDialog import create_wildcard [as 别名]
def open(self):
wildcard = FileDialog.create_wildcard('JSON files', '*.json')
dialog = FileDialog(action = 'open',
default_directory = self.default_directory,
parent = self.window.control,
wildcard = wildcard)
if dialog.open() == OK:
runner = load(dialog.path)
runner.outfile = dialog.path
self.editor_area.edit(runner)
示例5: _saveLog_fired
# 需要导入模块: from pyface.api import FileDialog [as 别名]
# 或者: from pyface.api.FileDialog import create_wildcard [as 别名]
def _saveLog_fired(self):
dialog = FileDialog(title='Save plot as...', action='save as',
wildcard = FileDialog.create_wildcard('Text file', '*.txt'))
if not dialog.open():
self.add_line("ERROR opening save file.")
return
try:
out = open(dialog.path,'w')
out.write(self.results)
out.close()
except IOError:
self.add_line("I failed to open "+str(dialog.path))
return
示例6: perform
# 需要导入模块: from pyface.api import FileDialog [as 别名]
# 或者: from pyface.api.FileDialog import create_wildcard [as 别名]
def perform(self, event=None):
fd = FileDialog(
wildcard=FileDialog.create_wildcard('PModelChecker results files', ['*.psm', '*.mc2']),
title='Select a PModelChecker results file',
)
if fd.open() != OK:
return
commons.edit_pmodelchecker_results_file(
file=fd.path,
# application=self.application,
# application=self.window.application,
application=self.window.workbench.application,
)
示例7: save_as
# 需要导入模块: from pyface.api import FileDialog [as 别名]
# 或者: from pyface.api.FileDialog import create_wildcard [as 别名]
def save_as(self):
''' Saves the file to disk after prompting for the file name. '''
dialog = FileDialog(
parent=self.window.control,
action='save as',
default_filename=self.name,
wildcard='\n'.join([FileDialog.create_wildcard(wildcard[0], ', '.join(wildcard[1])) for wildcard in self.wildcards]) if len(self.wildcards) > 0 else FileDialog.create_wildcard('All files', '*')
)
if dialog.open() != CANCEL:
# update this editor
self.id = dialog.path
self.name = os.path.basename(dialog.path)
self.obj.path = dialog.path # update obj (an apptools.io.api.File)
self.save() # save it now it has a path
示例8: click
# 需要导入模块: from pyface.api import FileDialog [as 别名]
# 或者: from pyface.api.FileDialog import create_wildcard [as 别名]
def click ( self ):
""" Handles the user left clicking on the feature image.
"""
# Create the file dialog:
fd = FileDialog()
# Set up the default path based on the current value (if any):
default_path = getattr( self.dock_control.object, self.name, None )
if default_path is not None:
fd.default_path = default_path
# Set up the appropriate extension filters (if any):
if len( self.extensions ) > 0:
fd.wildcard = '\n'.join([ FileDialog.create_wildcard('', '*' + ext)
for ext in self.extensions ])
# Display the file dialog, and if successful, set the new file name:
if fd.open() == OK:
self.drop( fd.path )