Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def perform(self, event=None):
logger.info("OpenFileAction.perform()")
dialog = FileDialog(parent=self.window.control, title="Open File")
if dialog.open() == OK:
self.window.workbench.edit(File(dialog.path), kind=TextEditor)
def save_as(self):
""" Saves the text to disk after prompting for the file name. """
dialog = FileDialog(
parent=self.window.control,
action="save as",
default_filename=self.name,
wildcard=FileDialog.WILDCARD_PY,
)
if dialog.open() != CANCEL:
# Update the editor.
self.id = dialog.path
self.name = basename(dialog.path)
# Update the resource.
self.obj.path = dialog.path
# Save it!
self.save()
return
def do_load_data(self, info):
"""Read in the pickled data.'"""
the_pybert = info.object
dlg = FileDialog(action="open", wildcard="*.pybert_data", default_path=the_pybert.data_file)
if dlg.open() == OK:
try:
with open(dlg.path, "rb") as the_file:
the_plotdata = pickle.load(the_file)
if not isinstance(the_plotdata, PyBertData):
raise Exception("The data structure read in is NOT of type: ArrayPlotData!")
for prop, value in the_plotdata.the_data.arrays.items():
the_pybert.plotdata.set_data(prop + "_ref", value)
the_pybert.data_file = dlg.path
# Add reference plots, if necessary.
# - time domain
for (container, suffix, has_both) in [
(the_pybert.plots_h.component_grid.flat, "h", False),
(the_pybert.plots_s.component_grid.flat, "s", True),
(the_pybert.plots_p.component_grid.flat, "p", False),
def _save_snapshot(self):
"""Invoked by the toolbar menu to save a snapshot of the scene
to an image. Note that the extension of the filename
determines what image type is saved. The default is PNG.
"""
if self._panel is not None:
wildcard = "PNG images (*.png)|*.png|Determine by extension (*.*)|*.*"
dialog = FileDialog(
parent = self._panel,
title = 'Save scene to image',
action = 'save as',
default_filename = "snapshot.png",
wildcard = wildcard
)
if dialog.open() == OK:
# The extension of the path will determine the actual
# image type saved.
self.save(dialog.path)
def on_save_file(self):
""" Save the file. """
if self.control:
try:
self._editor.save()
except IOError:
# If you are trying to save to a file that doesn't exist,
# open up a FileDialog with a 'save as' action.
dlg = FileDialog(
parent=self.control, action="save as", wildcard="*.py"
)
if dlg.open() == OK:
self._editor.save(dlg.path)
wi = new_workflow[0]
assert(wi.operation.id == "edu.mit.synbio.cytoflow.operations.import")
missing_tubes = 0
for tube in wi.operation.tubes:
file = pathlib.Path(tube.file)
if not file.exists():
missing_tubes += 1
if missing_tubes == len(wi.operation.tubes):
warning(self.window.control,
"Cytoflow couldn't find any of the FCS files from that "
"workflow. If they've been moved, please open one FCS "
"file to show Cytoflow where they've been moved to.")
dialog = FileDialog(parent = self.window.control,
action = 'open',
wildcard = (FileDialog.create_wildcard("FCS files", "*.fcs *.lmd"))) # @UndefinedVariable
if dialog.open() == OK:
# find the "best" file match -- ie, the one with the longest
# tail match
fcs_path = pathlib.Path(dialog.path).parts
best_path_len = -1
for tube in wi.operation.tubes:
tube_path = pathlib.Path(tube.file).parts
for i in range(len(fcs_path)):
if list(reversed(fcs_path))[:i] == list(reversed(tube_path))[:i] and i > best_path_len:
best_path_len = i
def _show_open_dialog(self, parent):
"""
Show the dialog to open a project.
"""
# Determine the starting point for browsing. It is likely most
# projects will be stored in the default path used when creating new
# projects.
default_path = self.model_service.get_default_path()
project_class = self.model_service.factory.PROJECT_CLASS
if self.model_service.are_projects_files():
dialog = FileDialog(
parent=parent,
default_directory=default_path,
title="Open Project",
)
if dialog.open() == OK:
path = dialog.path
else:
path = None
else:
dialog = DirectoryDialog(
parent=parent,
default_path=default_path,
message="Open Project",
)
if dialog.open() == OK:
path = project_class.get_pickle_filename(dialog.path)
def open(self, info):
selected = info.object.selected_view
if selected and selected.model.filepath:
default_directory = os.path.dirname(selected.model.filepath)
elif os.path.isdir(info.object.selected_file):
default_directory = info.object.selected_file
else:
default_directory = os.path.dirname(info.object.selected_file)
dialog = FileDialog(action='open', title='Open ReST File',
wildcard=self.wildcard,
default_directory=default_directory)
result = dialog.open()
if result == OK and os.path.exists(dialog.path):
info.object.open(dialog.path)
def save_as(self):
if self.net is None:
display_error("Network neither created nor loaded!")
return
wildcard = 'Network file (*.net)|*.net|Any file (*.*)|*.*'
dialog = pyface.FileDialog(parent=None,
title='Save as',
action='save as',
wildcard=wildcard,
default_path=self.filename
)
if dialog.open() == pyface.OK: # path is given
path = dialog.path
if not os.path.basename(path).endswith('.net'):
path += '.net'
savenet(self.net, path)
self.filename = path
self.app.logs.logger.info('Network saved as: %s' %self.filename)
def export(self):
if self.net is None:
display_error("Network neither created nor loaded!")
return
wildcard = 'Fortran file (*.f)|*.f|Any file (*.*)|*.*'
outfile = os.path.splitext(self.filename)[0] + '.f'
dialog = pyface.FileDialog(parent=None,
title='Export as',
action='save as',
wildcard=wildcard,
default_path=outfile
)
if dialog.open() == pyface.OK: # path is given
path = dialog.path
if not os.path.basename(path).endswith('.f'):
path += '.f'
exportnet(self.net, path)
self.app.logs.logger.info('Network exported as: %s' %path)