Exemple #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))
Exemple #2
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 #3
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 #4
0
 def perform(self, event):
     mv = get_imayavi(self.window)
     s = get_scene(mv)
     if s is None:
         return
     callable = self.metadata.get_callable()
     obj = callable()
     mv.add_source(obj)
     mv.engine.current_selection = obj
Exemple #5
0
 def perform(self, event):
     mv = get_imayavi(self.window)
     s = get_scene(mv)
     if s is None:
         return
     callable = self.metadata.get_callable()
     obj = callable()
     mv.add_source(obj)
     mv.engine.current_selection = obj
Exemple #6
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)
    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 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 #9
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 #10
0
 def _mayavi_default(self):
     return get_imayavi(self.window)