示例#1
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))
示例#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
示例#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
示例#4
0
    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, e:
            errmsg = "The filename must have an extension that matches a graphics"
            errmsg = errmsg + " 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")
示例#5
0
文件: sources.py 项目: sjl421/code-2
    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
示例#6
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
示例#7
0
文件: data.py 项目: pmrup/labtools
 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)
示例#8
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()
示例#9
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()
示例#10
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()
    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.)
                size=(650,400)
                gc = GraphicsContext(size)
                self.plot_container.draw(gc)
                gc.save(path)
            except:
                print "Error saving!"
                raise
            print "Plot saved."
        return
    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
示例#13
0
文件: plotter.py 项目: yggi/smear
 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
示例#14
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()
示例#15
0
    def perform(self, event, cfile=None):
        """ Performs the action. """

        logger.info("Performing save connectome file action")

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

        cfile = self.window.application.get_service("cviewer.plugins.cff2.cfile.CFile")

        wildcard = "Connectome File Format v2.0 (*.cff)|*.cff|" "All files (*.*)|*.*"

        dlg = FileDialog(
            wildcard=wildcard,
            title="Save as Connectome File",
            resizeable=False,
            action="save as",
            default_directory=preference_manager.cviewerui.cffpath,
        )

        if dlg.open() == OK:

            if (dlg.paths[0]).endswith(".cff"):

                cfflib.save_to_cff(cfile.obj, dlg.paths[0])
                logger.info("Saved connectome file to %s" % dlg.paths[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()
 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()
    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
示例#19
0
    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
示例#20
0
    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
示例#21
0
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"
    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:
                vectors = []
                x_values = self.value.xdata
                y_values = self.value.ydata
                #savetxt( path, vstack( (x_values, y_values[:,0], y_values[:,1], y_values[:,2]) ).transpose() )
                
                print 'y_values', y_values
                y_values_tr = y_values.transpose()
                for vector in y_values_tr[:]:
                    vectors.append(vector)

                savetxt( path, vstack( (x_values, vectors) ).transpose() )
                    
            except:
                print "Error saving!"
                raise
            print "Plot saved."
        return
示例#23
0
 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()
示例#24
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)
示例#25
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()
示例#26
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
示例#27
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
示例#28
0
    def _open_file(self):
        """ Open a new file. """

        if self.control:
            dlg = FileDialog(parent=self.control, wildcard=WILDCARD)

            if dlg.open() == OK:
                self._editor.path = dlg.path
示例#29
0
 def perform(self):
     extns = ['*.pickle']
     dlg = FileDialog(parent=self._window.control, action='save as',
             wildcard='|'.join(extns), title="Save As")
     if dlg.open() == OK:
         file = open( dlg.path, 'w' )
         pickle.dump(self._window.scene, file)
         file.close()  
示例#30
0
 def perform(self):
     extns = ['*.pickle']
     dlg = FileDialog(parent=self._window.control, action='open',
             wildcard='|'.join(extns), title="Open")
     if dlg.open() == OK:
         file = open( dlg.path, 'r' )
         self._window.scene = pickle.load(file)
         self. refresh()
         file.close()
示例#31
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)
示例#32
0
文件: tools.py 项目: pmrup/labtools
 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)
示例#33
0
    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)

            
示例#34
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)
示例#35
0
    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))
    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
示例#37
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=WILDCARD)
                if dlg.open() == OK:
                    self._editor.save(dlg.path)
    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
示例#39
0
 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
示例#40
0
文件: ivtk.py 项目: sjl421/code-2
 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)
示例#41
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)
示例#42
0
文件: recorder.py 项目: sjl421/code-2
 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()
示例#43
0
 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))
示例#44
0
文件: recorder.py 项目: fspaolo/code
 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()
示例#45
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
示例#46
0
文件: gui.py 项目: danginsburg/cmp
    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)
示例#47
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)
示例#48
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)
示例#49
0
文件: gui.py 项目: danginsburg/cmp
    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)
示例#50
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)
示例#51
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)
示例#52
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)
示例#53
0
    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
示例#54
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 ''
示例#55
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