Ejemplo n.º 1
0
    def insert_row(self, path, data=None, undolist=[]):

        ul = UndoList().describe("Insert row")
        if data is None:
            self.table.insert_n_rows(path[0], 1)
        else:
            self.table.insert_rows(path[0], data)
        ul.append( UndoInfo(self.delete_rows, [path]) )
        self.row_inserted(path, self.get_iter(path))

        undolist.append(UndoInfo(self.delete_rows, [path]))
Ejemplo n.º 2
0
    def delete_rows(self, pathlist, undolist=[]):

        ul = UndoList().describe("Delete rows")
        deleted = 0
        for path in pathlist:
            real_row = path[0]-deleted
            real_path = (real_row,)
            old_data = self.table.delete_n_rows(real_row, 1)
            ul.append( UndoInfo(self.insert_row, real_path, data=old_data) )
            self.row_deleted(real_path)
            deleted += 1
            
        undolist.append(ul)
Ejemplo n.º 3
0
    def apply_changes(self):
        ul = UndoList().describe("Edit Plot Properties")
        for tab in self.tabs:
            ui = UndoList()
            tab.check_out(undolist=ui)
            ul.append(ui.simplify())


        ul = ul.simplify(preserve_list=True)
        
        if len(ul) > 0:
            uwrap.emit_last(self.plot, "plot-changed", undolist=ul)            
        else:
            ul = NullUndo()
            
        self.app.project.journal.add_undo(ul)
Ejemplo n.º 4
0
    def set_region(self, row, col, array, coerce=True, undolist=[]):
        undo_data = self.get_region(row, col, len(array), len(array.dtype.fields[-1]))
        ul = UndoList()
        ul.append(UndoInfo(self.set_region, row, col, undo_data))

        try:
            names = array.dtype.fields[-1]
            i = 0
            for name in self.names[col:col+len(array)]:
                if coerce is True:
                    z = self.get_column_type(col+i)(array[names[i]])
                else:
                    z = array[names[i]]
                self._array[name][row:row+len(array)] = z
                i += 1
        except Exception, msg:
            print "set_region failed: %s.  undoing." % msg
            ul.execute()
Ejemplo n.º 5
0
    def insert_(self, col, table, undolist=[]):
        
        col = self.get_index(col)
       
        # We merge in the description of the new array into the
        # existing array 'self._array'. Unfortunately we must
        # make sure that each new added field has a unique name.
        new_names = self.names[:]
        descriptor = self._array.dtype.descr[:]
        infos = {}
        i = 0
        for name in table.names:
            typecode = table.get_column_type(name)
            new_name = utils.unique_names([name], new_names)[0]
            new_names.insert(i+col, new_name)
            descriptor.insert(i+col, (new_name, typecode))
            
            if table._infos.has_key(name):
                infos[new_name] = table._infos[name].copy()
            i+=1

        new_array = numpy.zeros( (self.nrows,), dtype=numpy.dtype(descriptor))

        # fill new array with data
        # copy data from existing dataset
        for name in self.names:
            new_array[name] = self._array[name]

        # ..and then copy data from table object.
        # Because the names might have changed, we refer
        # to the columns by their index!    
        i = 0
        for name in table.names:
            new_array[new_names[col+i]] = table._array[name]
            i += 1
            
        # undo information
        ul = UndoList()
        self.update_infos(infos, undolist=ul)        
        ul.append(UndoInfo(self.remove_n_columns, col, table.ncols))
        undolist.append(ul)

        self._array = new_array
        self.sig_emit('update-fields')        
Ejemplo n.º 6
0
    def zoom_to_region(self, layer, region, undolist=[]):

        old_region = (layer.xaxis.start,
                      layer.yaxis.start,
                      layer.xaxis.end,
                      layer.yaxis.end)
        
        x0 = min( region[0], region[2] )
        x1 = max( region[0], region[2] )            
        y0 = min( region[1], region[3] )
        y1 = max( region[1], region[3] )

        # Do not zoom if x0 == x1 or if y0 == y1, because
        # otherwise matplotlib will mess up.  Of course, if x0 and
        # x1 are None (or y0 and y1), i.e. if autoscale is turned on,
        # then it is ok to zoom.
        if ((x0 is not None) and (x0 == x1)) or \
           ((y0 is not None) and (y0 == y1)):            
            undolist.append(NullUndo())
            return

        def set_axis(axis, start, end):
            if axis.start is not None and axis.end is not None:
                swap_axes = axis.start > axis.end
            else:
                swap_axes = False

            if swap_axes is True:
                _start, _end = end, start
            else:
                _start, _end = start, end

            print "-------"
            axis.set(start=_start, end=_end)
            print "-------"            

        self.backend.block_redraw()
        set_axis(layer.xaxis, x0, x1)
        set_axis(layer.yaxis, y0, y1)
        self.backend.unblock_redraw()

        ul = UndoList("Zoom Region")        
        ul.append(UndoInfo(self.zoom_to_region, layer, old_region))
        undolist.append(ul)
Ejemplo n.º 7
0
    def zoom_to_region(self, layer, region, undolist=[]):
       
        ul = UndoList()

        x0 = min( region[0], region[2] )
        x1 = max( region[0], region[2] )
            
        y0 = min( region[1], region[3] )
        y1 = max( region[1], region[3] )

        # Do not zoom if x0 == x1 or if y0 == y1, because
        # otherwise matplotlib will mess up.  Of course, if x0 and
        # x1 are None (or y0 and y1), i.e. if autoscale is turned on,
        # then it is ok to zoom.
        if ((x0 is not None) and (x0 == x1)) or \
           ((y0 is not None) and (y0 == y1)):            
            ul.append( NullUndo() )
            return          

        def set_axis(key, start, end):
            axis = layer.request_axis(key, undolist=ul)            
            if axis.start is not None and axis.end is not None:
                swap_axes = axis.start > axis.end
            else:
                swap_axes = False

            if swap_axes is True:
                _start, _end = end, start
            else:
                _start, _end = start, end
                
            uwrap.set(axis, start=_start, end=_end, undolist=ul)

        set_axis('x', x0, x1)
        set_axis('y', y0, y1)
        
        uwrap.emit_last( self.plot, "plot-changed", undolist=ul )
        
        undolist.append(ul)
Ejemplo n.º 8
0
    def apply_changes(self):
        """ Apply all changes in all tabs.

        The method calls 'check_in' of every tab in the dialog's
        notebook. The created undolists are unified into a single
        undolist, which is appended to the project's journal.
        """
        
        ul = UndoList().describe("Edit Plot Properties")

        for tab in self.tabdict.itervalues():
            ui = UndoList()            
            tab.check_out(undolist=ui)
            ul.append(ui.simplify())

        ul = ul.simplify(preserve_list=True)

        if len(ul) > 0:
            uwrap.emit_last(self.plot, "changed", undolist=ul)            
        else:
            ul = NullUndo()
            
        globals.app.project.journal.add_undo(ul)