コード例 #1
0
ファイル: resource_wizard.py プロジェクト: rwl/puddle
    def _finished_fired(self):
        """ This will just create a file at the location specified in the
            wizard pages.  Override this method in a subclass for other
            resource types.
        """
        container_page = self.pages[0]
        resource_page = self.pages[1]

        resource = File(resource_page.abs_path)
        resource.create_file()

        self._open_resource(file)
        # FIXME: Refresh the parent folder not the whole tree
        workspace = self.window.application.get_service(IWorkspace)
        self._refresh_container(workspace)
コード例 #2
0
    def perform(self, event=None):

        from csurface_action import SurfaceParameter
        from scripts import surfscript
        cfile = self.window.application.get_service(
            'cviewer.plugins.cff2.cfile.CFile')

        so = SurfaceParameter(cfile)
        so.edit_traits(kind='livemodal')

        if not so.pointset_da[so.pointset]['name'] == "None":
            # if cancel, not create surface
            # create a temporary file
            import tempfile
            myf = tempfile.mktemp(suffix='.py', prefix='my')
            f = open(myf, 'w')
            if so.labels_da[so.labels].has_key('da_idx'):
                labels = so.labels_da[so.labels]['da_idx']
            else:
                labels = 0
            f.write(surfscript % (so.pointset_da[so.pointset]['name'],
                                  so.pointset_da[so.pointset]['da_idx'],
                                  so.faces_da[so.faces]['name'],
                                  so.faces_da[so.faces]['da_idx'],
                                  so.labels_da[so.labels]['name'], labels))
            f.close()

            self.window.workbench.edit(File(myf),
                                       kind=TextEditor,
                                       use_existing=False)
コード例 #3
0
    def _lookup(self, name):
        """ Looks up a name in this context. """

        if name in self._cache:
            obj = self._cache[name]

        else:
            # Get the full path to the file.
            path = join(self.path, self._name_to_filename_map[name])

            # If the file contains a serialized Python object then load it.
            for serializer in self._get_object_serializers():
                if serializer.can_load(path):
                    try:
                        state = serializer.load(path)

                    # If the load fails then we create a generic file resource
                    # (the idea being that it might be useful to have access to
                    # the file to see what went wrong).
                    except:
                        state = File(path)
                        logger.exception('Error loading resource at %s' % path)

                    break

            # Otherwise, it must just be a file or folder.
            else:
                # Directories are contexts.
                if os.path.isdir(path):
                    state = self._context_factory(name, path)

                # Files are just files!
                elif os.path.isfile(path):
                    state = File(path)

                else:
                    raise ValueError('unrecognized file for %s' % name)

            # Get the actual object from the naming manager.
            obj = naming_manager.get_object_instance(state, name, self)

            # Update the cache.
            self._cache[name] = obj

        return obj
コード例 #4
0
ファイル: folder_wizard.py プロジェクト: rwl/puddle
    def _finished_fired(self):
        """ Performs the folder resource creation if the wizard is
            finished successfully.
        """
        csp = self.pages[0]
        fwp = self.pages[1]

        path = join(csp.directory, fwp.folder_name)
        folder = File(path)
        folder.create_folder()

        # Refresh the workspace tree view
        view = self.window.get_view_by_id(RESOURCE_VIEW)
        if view is not None:
            # FIXME: Refresh the parent folder not the whole tree
            workspace = self.window.application.get_service(IWorkspace)
            workspace.path = path
            wtv = view.tree_viewer.refresh(workspace)
コード例 #5
0
ファイル: new_file_wizard.py プロジェクト: rwl/puddle
    def _finished_fired(self):
        """ Performs the file resource creation if the wizard is
        finished successfully.

        """

        csp = self.pages[0]
        fwp = self.pages[1]

        file = File(fwp.abs_path)
        file.create_file()

        # Refresh the workspace tree view
        view = self.window.get_view_by_id(RESOURCE_VIEW)
        if view is not None:
            # FIXME: Refresh the parent folder, not the whole tree.
            workspace = self.window.application.get_service(IWorkspace)
            wtv = view.tree_viewer.refresh(workspace)
コード例 #6
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)

            
コード例 #7
0
    def get_object_instance(self, state, name, context):
        """ Creates an object using the specified state information. """

        obj = None

        if isinstance(state, Reference):
            if state.class_name == 'File' and  len(state.addresses) > 0:
                obj = File(state.addresses[0].content)

        return obj
コード例 #8
0
    def perform(self, event=None):

        from scripts import corticocortico

        import tempfile
        myf = tempfile.mktemp(suffix='.py', prefix='my')
        f = open(myf, 'w')
        f.write(corticocortico)
        f.close()

        self.window.workbench.edit(File(myf),
                                   kind=TextEditor,
                                   use_existing=False)
コード例 #9
0
    def __attributes_default(self):
        """ Initializes the '_attributes' trait. """

        attributes_file = File(join(self.path, self.ATTRIBUTES_FILE))
        if attributes_file.is_file:
            f = file(attributes_file.path, 'rb')
            attributes = cPickle.load(f)
            f.close()

        else:
            attributes = {}

        return attributes
コード例 #10
0
    def _unbind(self, name):
        """ Unbinds a name from this context. """

        # Get the full path to the file.
        path = join(self.path, self._name_to_filename_map[name])

        # Remove it!
        f = File(path)
        f.delete()

        # Update the name to filename map.
        del self._name_to_filename_map[name]

        # Update the cache.
        if name in self._cache:
            del self._cache[name]

        # Remove any attributes.
        if name in self._attributes:
            del self._attributes[name]
            self._save_attributes()

        return
コード例 #11
0
ファイル: pyfs_context.py プロジェクト: fspaolo/code
    def _unbind(self, name):
        """ Unbinds a name from this context. """

        # Get the full path to the file.
        path = join(self.path, self._name_to_filename_map[name])

        # Remove it!
        f = File(path)
        f.delete()

        # Update the name to filename map.
        del self._name_to_filename_map[name]

        # Update the cache.
        if name in self._cache:
            del self._cache[name]

        # Remove any attributes.
        if name in self._attributes:
            del self._attributes[name]
            self._save_attributes()

        return
コード例 #12
0
    def perform(self, event=None):

        #        from cnetwork_nbs_action import NBSNetworkParameter, NBSMoreParameter
        from scripts import nbsscript
        #        cfile = self.window.application.get_service('cviewer.plugins.cff2.cfile.CFile')
        #
        #        no = NBSNetworkParameter(cfile)
        #        no.edit_traits(kind='livemodal')
        #
        #        if (len(no.selected1) == 0 or len(no.selected2) == 0):
        #            return
        #
        #        mo = NBSMoreParameter(cfile, no.selected1[0], no.selected2[0])
        #        mo.edit_traits(kind='livemodal')
        #
        #        import datetime as dt
        #        a=dt.datetime.now()
        #        ostr = '%s%s%s' % (a.hour, a.minute, a.second)

        #        if not (len(no.selected1) == 0 or len(no.selected2) == 0):
        #            # if cancel, not create surface
        #            # create a temporary file
        #            import tempfile
        #            myf = tempfile.mktemp(suffix='.py', prefix='my')
        #            f=open(myf, 'w')
        #            f.write(nbsscript % (str(no.selected1),
        #                                 mo.first_edge_value,
        #                                 str(no.selected2),
        #                                 mo.second_edge_value,
        #                                 mo.THRES,
        #                                 mo.K,
        #                                 mo.TAIL,
        #                                 ostr))
        #            f.close()
        #
        #            self.window.workbench.edit(File(myf), kind=TextEditor,use_existing=False)

        import tempfile
        myf = tempfile.mktemp(suffix='.py', prefix='my')
        f = open(myf, 'w')
        f.write(nbsscript)
        f.close()

        self.window.workbench.edit(File(myf),
                                   kind=TextEditor,
                                   use_existing=False)
コード例 #13
0
    def perform(self, event=None):

        from cnetwork_action import MatrixNetworkParameter
        from scripts import conmatrix
        cfile = self.window.application.get_service(
            'cviewer.plugins.cff2.cfile.CFile')

        no = MatrixNetworkParameter(cfile)
        no.edit_traits(kind='livemodal')

        if not no.netw[no.graph]['name'] == "None":
            # if cancel, not create surface
            # create a temporary file
            import tempfile
            myf = tempfile.mktemp(suffix='.py', prefix='my')
            f = open(myf, 'w')
            f.write(conmatrix % (no.netw[no.graph]['name'], no.node_label))
            f.close()

            self.window.workbench.edit(File(myf),
                                       kind=TextEditor,
                                       use_existing=False)
コード例 #14
0
    def perform(self, event=None):

        from cvolume_action import VolumeParameter
        from scripts import volslice
        cfile = self.window.application.get_service(
            'cviewer.plugins.cff2.cfile.CFile')

        so = VolumeParameter(cfile)
        so.edit_traits(kind='livemodal')

        if True:  #not so.pointset_da[so.pointset]['name'] == "None":
            # if cancel, not create surface
            # create a temporary file
            import tempfile
            myf = tempfile.mktemp(suffix='.py', prefix='my')
            f = open(myf, 'w')
            f.write(volslice % so.volumes[so.myvolume]['name'])
            f.close()

            self.window.workbench.edit(File(myf),
                                       kind=TextEditor,
                                       use_existing=False)
コード例 #15
0
ファイル: pyfs_context.py プロジェクト: fspaolo/code
    def _rename(self, old_name, new_name):
        """ Renames an object in this context. """

        # Get the old filename.
        old_filename = self._name_to_filename_map[old_name]
        old_file = File(join(self.path, old_filename))

        # Lookup the object bound to the old name.  This has the side effect
        # of adding the object to the cache under the name 'old_name'.
        obj = self._lookup(old_name)

        # We are renaming a LOCAL context (ie. a folder)...
        if old_file.is_folder:
            # Create the new filename.
            new_filename = new_name
            new_file = File(join(self.path, new_filename))

            # Move the folder.
            old_file.move(new_file)

            # Update the 'Context' object.
            obj.path = new_file.path

            # Update the cache.
            self._cache[new_name] = obj
            del self._cache[old_name]

            # Refreshing the context makes sure that all of its contents
            # reflect the new name (i.e., sub-folders and files have the
            # correct path).
            #
            # fixme: This currently results in new copies of serialized
            # Python objects!  We need to be a bit more judicious in the
            # refresh.
            obj.refresh()

        # We are renaming a file...
        elif isinstance(obj, File):
            # Create the new filename.
            new_filename = new_name
            new_file = File(join(self.path, new_filename))

            # Move the file.
            old_file.move(new_file)

            # Update the 'File' object.
            obj.path = new_file.path

            # Update the cache.
            self._cache[new_name] = obj
            del self._cache[old_name]

        # We are renaming a serialized Python object...
        else:
            # Create the new filename.
            new_filename = new_name + old_file.ext
            new_file = File(join(self.path, new_filename))

            old_file.delete()

            # Update the cache.
            if old_name in self._cache:
                self._cache[new_name] = self._cache[old_name]
                del self._cache[old_name]

            # Force the creation of the new file.
            #
            # fixme: I'm not sure that this is really the place for this.  We
            # do it because often the 'name' of the object is actually an
            # attribute of the object itself, and hence we want the serialized
            # state to reflect the new name... Hmmm...
            self._rebind(new_name, obj)

        # Update the name to filename map.
        del self._name_to_filename_map[old_name]
        self._name_to_filename_map[new_name] = new_filename

        # Move any attributes over to the new name.
        if old_name in self._attributes:
            self._attributes[new_name] = self._attributes[old_name]
            del self._attributes[old_name]
            self._save_attributes()

        return
コード例 #16
0
 def _get_root ( self ):
     return File( path = self.root_path )
コード例 #17
0
    def _rename(self, old_name, new_name):
        """ Renames an object in this context. """

        # Get the old filename.
        old_filename = self._name_to_filename_map[old_name]
        old_file = File(join(self.path, old_filename))

        # Lookup the object bound to the old name.  This has the side effect
        # of adding the object to the cache under the name 'old_name'.
        obj = self._lookup(old_name)

        # We are renaming a LOCAL context (ie. a folder)...
        if old_file.is_folder:
            # Create the new filename.
            new_filename = new_name
            new_file = File(join(self.path, new_filename))

            # Move the folder.
            old_file.move(new_file)

            # Update the 'Context' object.
            obj.path = new_file.path

            # Update the cache.
            self._cache[new_name] = obj
            del self._cache[old_name]

            # Refreshing the context makes sure that all of its contents
            # reflect the new name (i.e., sub-folders and files have the
            # correct path).
            #
            # fixme: This currently results in new copies of serialized
            # Python objects!  We need to be a bit more judicious in the
            # refresh.
            obj.refresh()

        # We are renaming a file...
        elif isinstance(obj, File):
            # Create the new filename.
            new_filename = new_name
            new_file = File(join(self.path, new_filename))

            # Move the file.
            old_file.move(new_file)

            # Update the 'File' object.
            obj.path = new_file.path

            # Update the cache.
            self._cache[new_name] = obj
            del self._cache[old_name]

        # We are renaming a serialized Python object...
        else:
            # Create the new filename.
            new_filename = new_name + old_file.ext
            new_file = File(join(self.path, new_filename))

            old_file.delete()

            # Update the cache.
            if old_name in self._cache:
                self._cache[new_name] = self._cache[old_name]
                del self._cache[old_name]

            # Force the creation of the new file.
            #
            # fixme: I'm not sure that this is really the place for this.  We
            # do it because often the 'name' of the object is actually an
            # attribute of the object itself, and hence we want the serialized
            # state to reflect the new name... Hmmm...
            self._rebind(new_name, obj)

        # Update the name to filename map.
        del self._name_to_filename_map[old_name]
        self._name_to_filename_map[new_name] = new_filename

        # Move any attributes over to the new name.
        if old_name in self._attributes:
            self._attributes[new_name] = self._attributes[old_name]
            del self._attributes[old_name]
            self._save_attributes()

        return
コード例 #18
0
 def perform(self, event=None):
     logger.info('NewFileAction.perform()')
     self.window.workbench.edit(File(''), kind=TextEditor,
         use_existing=False)