def perform(self, event):
        """ Performs the action. """
        wildcard = 'Python files (*.py)|*.py'
        parent = self.window.control

        # path from preference manager
        pref_script_path = preference_manager.cviewerui.scriptpath

        if pref_script_path == '':
            # store executed script path in preferences
            dialog = FileDialog(
                parent=parent,
                title='Open Python file',
                action='open',
                wildcard=wildcard,
            )
        else:
            dialog = FileDialog(
                parent=parent,
                title='Open Python file',
                action='open',
                wildcard=wildcard,
                default_directory=pref_script_path,
            )

        if dialog.open() == OK:
            if not isfile(dialog.path):
                error("File '%s' does not exist" % dialog.path, parent)
                return

            # Get the globals.
            # The following code is taken from scripts/mayavi2.py.
            g = sys.modules['__main__'].__dict__
            if 'mayavi' not in g:
                mv = get_imayavi(self.window)
                g['mayavi'] = mv
                g['engine'] = mv.engine

            if 'cfile' not in g:
                # load cfile reference into gloabl name space
                cfile = self.window.application.get_service(
                    'cviewer.plugins.cff2.cfile.CFile')
                g['cfile'] = cfile

            # always store last executed path in preferences
            # but this only gets definitely stored when one open the preference manager
            preference_manager.cviewerui.scriptpath = dirname(dialog.path)

            # Do execfile
            try:
                # If we don't pass globals twice we get NameErrors and nope,
                # using exec open(script_name).read() does not fix it.
                execfile(dialog.path, g, g)
            except Exception, msg:
                exception(str(msg))
Exemple #2
0
    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
Exemple #3
0
    def _dialog(self, message="Select Folder", new_directory=True, mode='r'):
        """Creates a file dialog box for working with

        Args:
            message (string): Message to display in dialog
            new_file (bool): True if allowed to create new directory

        Returns:
            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 = "zip file (*.zip)|All files|*"

        if mode == "r":
            mode2 = "open"
        elif mode == "w":
            mode2 = "save as"

        dlg = FileDialog(action=mode2, wildcard=file_wildcard)
        dlg.open()
        if dlg.return_code == OK:
            self.directory = dlg.path
            self.File = zf.ZipFile(self.directory, mode)
            self.File.close()
            return self.directory
        else:
            return None
Exemple #4
0
    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
Exemple #5
0
 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()
Exemple #6
0
 def _save_btn_fired(self):
     f = FileDialog(action='save as',
                    default_path=self.bad_name,
                    wildcard='*.txt')
     if f.open() == OK:
         self.bad_name = f.path
         self.save_bad_data(self.bad_name)
Exemple #7
0
 def perform(self, event):
     """ Performs the action. """
     wildcard = 'Python files (*.py)|*.py'
     parent = self.window.control
     dialog = FileDialog(parent=parent,
                         title='Open Python file',
                         action='open', wildcard=wildcard
                         )
     if dialog.open() == OK:
         if not isfile(dialog.path):
             error("File '%s' does not exist"%dialog.path, parent)
             return
         
         # Get the globals.
         # The following code is taken from scripts/mayavi2.py.
         g = sys.modules['__main__'].__dict__
         if 'mayavi' not in g:
             mv = get_imayavi(self.window)
             g['mayavi'] = mv
             g['engine'] = mv.engine
         # Do execfile
         try:
             # If we don't pass globals twice we get NameErrors and nope,
             # using exec open(script_name).read() does not fix it.
             execfile(dialog.path, g, g)
         except Exception, msg:
             exception(str(msg))
Exemple #8
0
 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()
Exemple #9
0
 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()
Exemple #10
0
    def _open_file(self):
        """ Open a new file. """

        if self.control:
            dlg = FileDialog(parent=self.control, wildcard="*.py")

            if dlg.open() == OK:
                self._editor.path = dlg.path
Exemple #11
0
 def get_save_filename(self):
     """Get a filename from the user via a FileDialog. Returns the filename."""
     dialog = FileDialog(action="save as",
                         default_filename="spline_00",
                         wildcard="*.png")
     dialog.open()
     if dialog.return_code == OK:
         return dialog.path
Exemple #12
0
 def _save_fired(self):
     f = FileDialog(action='save as',
                    title='Save points',
                    default_path=self.filename,
                    wildcard='*.points')
     if f.open() == OK:
         self.filename = f.path
         self.to_file()
Exemple #13
0
 def _load_fired(self):
     f = FileDialog(action = 'open', 
                    title = 'Load points',
                    default_path = self.filename, 
                    wildcard = '*.points')
     if f.open() == OK:
         self.filename = f.path
         self.from_file(f.path)
Exemple #14
0
 def perform(self, event):
     """ Performs the action. """
     wildcard = 'MayaVi2 files (*.mv2)|*.mv2|' + FileDialog.WILDCARD_ALL
     dialog = FileDialog(parent=self.window.control,
                         title='Save MayaVi2 file',
                         action='save as', wildcard=wildcard
                         )
     if dialog.open() == OK:
         mv = get_imayavi(self.window)
         mv.save_visualization(dialog.path)
Exemple #15
0
 def _save_fired(self):
     f = FileDialog(action='save as',
                    default_path=self.filename,
                    wildcard='*.jpg;*.tiff;*.bmp;*.png')
     if f.open() == OK:
         try:
             self.save_image(f.path)
             self.error = ''
         except Exception as e:
             self.error = error_to_str(e)
    def perform(self, event=None):
        logger.info('OpenFileAction.perform()')
        pref_script_path = preference_manager.cviewerui.scriptpath
        dialog = FileDialog(parent=self.window.control,
            title='Open File',
            default_directory=pref_script_path)
        if dialog.open() == OK:
            self.window.workbench.edit(File(dialog.path), kind=TextEditor)

            
Exemple #17
0
 def perform(self):
     """Pops up a dialog used to save the scene to an image."""
     extns = [
         '*.png', '*.jpg', '*.jpeg', '*.tiff', '*.bmp', '*.ps', '*.eps',
         '*.tex', '*.rib', '*.wrl', '*.oogl', '*.pdf', '*.vrml', '*.obj',
         '*.iv'
     ]
     dlg = FileDialog(parent=self._window.control,
                      action='save as',
                      wildcard='|'.join(extns),
                      title="Save scene to image")
     if dlg.open() == OK:
         self._window.scene.save(dlg.path)
Exemple #18
0
 def ui_save(self):
     """Save recording to file, pop up a UI dialog to find out where
     and close the file when done.
     """
     from enthought.pyface.api import FileDialog, OK
     wildcard = 'Python files (*.py)|*.py|' + FileDialog.WILDCARD_ALL
     dialog = FileDialog(title='Save Script',
                         action='save as',
                         wildcard=wildcard)
     if dialog.open() == OK:
         fname = dialog.path
         f = open(fname, 'w')
         self.save(f)
         f.close()
Exemple #19
0
    def perform(self, event):
        """ Perform the action. """

        dialog = FileDialog(parent=self.window.control,
                            title='Save scene to %s' % self.name,
                            action='save as',
                            wildcard=self.wildcard)
        if dialog.open() == OK:
            scene = self.scene_manager.current_scene
            if scene is not None:
                method = getattr(scene, self.save_method)
                method(dialog.path)

        return
Exemple #20
0
    def _save_file(self):
        """ Save the file. """

        if self.control:
            try:
                self._editor.save()
            except IOError, e:
                # 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)
Exemple #21
0
 def perform(self, event):
     """ Performs the action. """
     wildcard = 'MayaVi2 files (*.mv2)|*.mv2|' + FileDialog.WILDCARD_ALL
     parent = self.window.control
     dialog = FileDialog(parent=parent,
                         title='Open MayaVi2 file',
                         action='open', wildcard=wildcard
                         )
     if dialog.open() == OK:
         if not isfile(dialog.path):
             error("File '%s' does not exist"%dialog.path, parent)
             return
         
         mv = get_imayavi(self.window)
         mv.load_visualization(dialog.path)
Exemple #22
0
    def _load_fired(self):
        import enthought.sweet_pickle as sp
        from enthought.pyface.api import FileDialog, OK

        wildcard = "CMP Configuration State (*.pkl)|*.pkl|" \
                        "All files (*.*)|*.*"
        dlg = FileDialog(wildcard=wildcard,title="Select a configuration state to load",\
                         resizeable=False, \
                         default_directory=self.project_dir,)

        if dlg.open() == OK:
            if not os.path.isfile(dlg.path):
                return
            else:
                self.load_state(dlg.path)
Exemple #23
0
    def _save_fired(self):
        import pickle
        import enthought.sweet_pickle as sp
        import os.path
        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)
Exemple #24
0
 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)
Exemple #25
0
    def perform(self, event, cfile=None):
        """ Performs the action. """

        logger.info('Performing open connectome file action')

        # helper variable to use this function not only in the menubar
        exec_as_funct = True

        if cfile is None:
            # get the instance of the current CFile
            # with the help of the Service Registry
            cfile = self.window.application.get_service(
                'cviewer.plugins.cff2.cfile.CFile')
            exec_as_funct = False

        wildcard = "Connectome Markup File v2.0 (meta.cml)|meta.cml|" \
                    "Connectome File Format v2.0 (*.cff)|*.cff|" \
                    "All files (*.*)|*.*"
        dlg = FileDialog(wildcard=wildcard,title="Choose a Connectome File",\
                         resizeable=False, \
                         default_directory=preference_manager.cviewerui.cffpath,)

        if dlg.open() == OK:

            if not os.path.isfile(dlg.path):
                logger.error("File '%s' does not exist!" % dlg.path)
                return

            # if file exists and has .cff ending
            if os.path.exists(
                    dlg.paths[0]) and (dlg.paths[0]).endswith('.cff'):

                # close the cfile if one is currently loaded
                cfile.close_cfile()

                # load cfile data
                cfile.load_cfile(dlg.paths[0])

                self.window.status_bar_manager.message = ''
            elif os.path.exists(
                    dlg.paths[0]) and (dlg.paths[0]).endswith('meta.cml'):
                cfile.close_cfile()
                cfile.load_cfile(dlg.paths[0], ismetacml=True)
            else:
                logger.info('Could not load file: ' + dlg.paths)
Exemple #26
0
 def _load(self):
     print "Load from EventTable"
     extension = "evt"
     wildcard = "EventTable|*.evt|VA MarkerFile|*.vmrk"
     fileDialog = FileDialog(action='open',
                             title='Load EventTable',
                             wildcard=wildcard)
     fileDialog.open()
     if fileDialog.path == '' or fileDialog.return_code == CANCEL:
         return False
     else:
         print "Opening", fileDialog.path
         #et = eegpy.load(str(fileDialog.path))
         et = eegpy.EventTable(str(fileDialog.path))
         for k in et.keys():
             for t in et[k]:
                 #print k,t
                 self.append(t, k, False, False)
         self.markers.sort(cmp=self.cmp_markers)
Exemple #27
0
 def _save_output_action(self):
     """Pops up a dialog box for the action to ask for a file."""
     # FIXME: in a refactor this should all go in a separate view
     # related object.
     from enthought.pyface.api import FileDialog, OK
     wildcard = 'All files (*.*)|*.*|'\
                'VTK XML files (*.xml)|*.xml|'\
                'Image Data (*.vti)|*.vti|'\
                'Poly Data (*.vtp)|*.vtp|'\
                'Rectilinear Grid (*.vtr)|*.vtr|'\
                'Structured Grid (*.vts)|*.vts|'\
                'Unstructured Grid (*.vtu)|*.vtu|'\
                'Old-style VTK files (*.vtk)|*.vtk'
                
     dialog = FileDialog(title='Save output to file',
                         action='save as', wildcard=wildcard
                         )
     if dialog.open() == OK:
         self.save_output(dialog.path)
    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
Exemple #29
0
def popup_save(parent=None):
    """Popup a dialog asking for an image name to save the scene to.
    This is used mainly to save a scene in full screen mode. Returns a
    filename, returns empty string if action was cancelled. `parent` is
    the parent widget over which the dialog will be popped up.
    """
    extns = ['*.png', '*.jpg', '*.jpeg', '*.tiff', '*.bmp', '*.ps', '*.eps',
             '*.tex', '*.rib', '*.wrl', '*.oogl', '*.pdf', '*.vrml', '*.obj',
             '*.iv']
    wildcard='|'.join(extns)

    dialog = FileDialog(
        parent = parent, title='Save scene to image',
        action='save as', wildcard=wildcard
    )
    if dialog.open() == OK:
        return dialog.path
    else:
        return ''
Exemple #30
0
    def perform(self, event):
        """ Performs the action. """

        extensions = [
            '*.png', '*.jpg', '*.jpeg', '*.tiff', '*.bmp', '*.ps', '*.eps',
            '*.tex', '*.rib', '*.wrl', '*.oogl', '*.pdf', '*.vrml', '*.obj',
            '*.iv'
        ]

        wildcard = '|'.join(extensions)

        dialog = FileDialog(parent=self.window.control,
                            title='Save scene to image',
                            action='save as',
                            wildcard=wildcard)
        if dialog.open() == OK:
            scene = self.scene_manager.current_scene
            if scene is not None:
                scene.save(dialog.path)

        return