Esempio n. 1
0
    def on_edit(self, sender):
        self.check_layer()
        
        (model, pathlist) = self.treeview.get_selection().get_selected_rows()
        if model is None or len(pathlist) == 0:
            return
        project = self.get_data('project')
            
        label = model.get_value( model.get_iter(pathlist[0]), 0)
        new_label = self.edit(label.copy())
        print "new label", new_label, label
        changeset = label.create_changeset(new_label)
        
        ul = UndoList().describe("Update label.")
        changeset['undolist'] = ul
        uwrap.set(label, **changeset)
        uwrap.emit_last(self.backend.layer, 'notify::labels',
                        updateinfo={'edit' : label},
                        undolist=ul)
        
        logger.info("Updateinfo: documentation = %s" % ul.doc)
        project.journal.append(ul)
        logger.info("Journal text: %s" % project.journal.undo_text())

        self.on_update_layer()
Esempio n. 2
0
    def add_datasets_to_plot(self, datasets, plot, undolist=None):
        """
        Adds the given Datasets to Dataset to the Plot object.
        
        >>> add_datasets_to_plot( [ds1,ds2], plot )

        Returns the Plot object.
        """
        if undolist is None:
            undolist = self.journal
        
        # make sure we are talking about an iterable object
        if not isinstance( datasets, (list,tuple) ):
            datasets = [datasets]

        ul = UndoList().describe("Add Datasets to Plot")

        try:
            layer = plot.layers[0]
        except KeyError:
            layer = Layer(type='lineplot2d')
            
        for dataset in datasets:
            dataset = self.get_dataset(dataset)
            line = Line(source=dataset, label = dataset.key)
            ulist.append( layer.lines, line, undolist=ul )

        uwrap.emit_last(self.plot, "changed", undolist=ul)
        undolist.append( ul )
        
        return plot
    def check_out(self):
        ul = UndoList().describe("Set Column Properties")
        for pw in self.pwdict.itervalues():
            pw.check_out(undolist=ul)

        uwrap.emit_last(self.table, 'update-columns', undolist=ul)

        self.app.project.journal.add_undo(ul)
Esempio n. 4
0
    def on_new(self, sender):
        label = objects.TextLabel(text="newlabel")
        self.edit(label)
        project = self.get_data("project")

        ul = UndoList().describe("New label.")
        ulist.append(self.layer.labels, label, undolist=ul)
        uwrap.emit_last(self.layer, "notify::labels", updateinfo={"add": label}, undolist=ul)
        project.journal.append(ul)
Esempio n. 5
0
    def on_remove(self, sender):
        (model, pathlist) = self.treeview.get_selection().get_selected_rows()
        if model is None:
            return
        project = self.get_data("project")
        label = model.get_value(model.get_iter(pathlist[0]), 0)

        ul = UndoList().describe("Remove label.")
        ulist.remove(self.layer.labels, label, undolist=ul)
        uwrap.emit_last(self.layer, "notify::labels", updateinfo={"remove": label}, undolist=ul)
        project.journal.append(ul)
Esempio n. 6
0
 def set_designation(self, d):
     path, column = self.dataview.get_cursor()
     if column is None:
         return
     else:            
         colnr = self.dataview.get_columns().index(column)
     
     info = self.dataset.get_info(colnr)
     ul = UndoList().describe("Change designation")        
     uwrap.set(info, designation=d, undolist=ul)
     uwrap.emit_last(self.dataset, 'update-fields', undolist=ul)
     self.project.journal.append(ul)
 def cb_edit_columns(self, action):
     table = self.dataset.get_data()
     dialog = ModifyTableDialog(table)
     try:
         response = dialog.run()
         if response == gtk.RESPONSE_ACCEPT:
             ul = UndoList().describe("Update Columns")
             dialog.check_out(undolist=ul)
             uwrap.emit_last(table, 'update-columns', undolist=ul)
             self.project.journal.append(ul)
     finally:
         dialog.destroy()
Esempio n. 8
0
 def on_new(self, sender):
     self.check_layer()
     
     label = objects.TextLabel(text='newlabel')
     self.edit(label)
     project = self.get_data('project')
         
     ul = UndoList().describe("New label.")
     ulist.append(self.layer.labels, label, undolist=ul)
     uwrap.emit_last(self.layer, "notify::labels",
                     updateinfo={'add' : label},
                     undolist=ul)
     project.journal.append(ul)
    def cb_column_properties(self, action):
        # column_object = treeview_column
        rownr, colnr, column_object = self.popup_info
        table = self.dataset.get_data()

        dialog = ColumnPropertiesDialog(table.get_column(colnr))
        try:
            response = dialog.run()
            if response == gtk.RESPONSE_ACCEPT:
                ul = UndoList().describe("Update Columns")
                dialog.check_out(undolist=ul)
                uwrap.emit_last(table, 'update-columns', undolist=ul)
                self.project.journal.append(ul)
        finally:
            dialog.destroy()
Esempio n. 10
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)
    def zoom_autoscale(self, undolist=[]):

        # TODO: We assume that there is a valid layer...
        layer = self.plot.layers[0]

        ul = UndoList()

        xaxis = layer.xaxis
        uwrap.set(xaxis, "start", None, undolist=ul)
        uwrap.set(xaxis, "end", None, undolist=ul)

        yaxis = layer.yaxis
        uwrap.set(yaxis, "start", None, undolist=ul)
        uwrap.set(yaxis, "end", None, undolist=ul)

        uwrap.emit_last(self.plot, "changed", undolist=ul)
        undolist.append(ul)
Esempio n. 12
0
 def on_edit(self, sender):
     (model, pathlist) = self.treeview.get_selection().get_selected_rows()
     if model is None:
         return
     project = self.get_data('project')
         
     label = model.get_value( model.get_iter(pathlist[0]), 0)
     new_label = self.edit(label.copy())
     changeset = create_changeset(label, new_label)
     
     ul = UndoList().describe("Update label.")
     changeset['undolist'] = ul
     uwrap.set(label, **changeset)
     uwrap.emit_last(self.layer, 'notify::labels',
                     updateinfo={'edit' : label},
                     undolist=ul)
     project.journal.append(ul)    
Esempio n. 13
0
    def _edit_column_info(self, colnr):
        info = self.dataset.get_info(colnr)                        
        name = self.dataset.get_name(colnr)            
        names = self.dataset.names

        dlg = ColumnInfoDialog(info, name, names)
        try:
            response = dlg.run()
            if response == gtk.RESPONSE_ACCEPT:
                # check out
                ul = UndoList("edit column info")
                dlg.check_out(undolist=ul)
                self.dataset.rename_column(colnr, dlg.new_name, undolist=ul)
                uwrap.emit_last(self.dataset, 'update-fields', undolist=ul)
                self.project.journal.append(ul)                
        finally:
            dlg.destroy()
    def zoom_autoscale(self, undolist=[]):

        # TODO: We assume that there is a valid layer...
        layer = self.plot.layers[0]

        ul = UndoList()

        xaxis = layer.request_axis('x', undolist=ul)        
        uwrap.set(xaxis,'start', None, undolist=ul)
        uwrap.set(xaxis,'end', None, undolist=ul)

        yaxis = layer.request_axis('y', undolist=ul)        
        uwrap.set(yaxis,'start', None, undolist=ul)
        uwrap.set(yaxis,'end', None, undolist=ul)

        uwrap.emit_last( self.plot, "plot-changed", undolist=ul )            
        undolist.append(ul)    
    def zoom_selection(self, undolist=[]):

        # TODO: We assume that there is a valid layer...
        layer = self.plot.layers[0]

        ul = UndoList()

        #
        # XRANGE
        #
        result = "\n".join(self.backend("show xrange"))
        regexp = re.compile("set xrange \[ (?P<xstart>.*) : (?P<xend>.*) \]")
        cv = regexp.search(result).groupdict()
        new_value = "set xrange [ %(xstart)s : %(xend)s ]" % cv

        xaxis = layer.xaxis
        xstart = cv["xstart"]
        if xstart == "*":
            xstart = None
        xend = cv["xend"]
        if xend == "*":
            xend = None
        uwrap.set(xaxis, "start", xstart, undolist=ul)
        uwrap.set(xaxis, "end", xend, undolist=ul)

        #
        # YRANGE
        #
        result = "\n".join(self.backend("show yrange"))
        regexp = re.compile("set yrange \[ (?P<ystart>.*) : (?P<yend>.*) \]")
        cv = regexp.search(result).groupdict()
        new_value = "set yrange [ %(ystart)s : %(yend)s ]" % cv

        yaxis = layer.yaxis
        ystart = cv["ystart"]
        if ystart == "*":
            ystart = None
        yend = cv["yend"]
        if yend == "*":
            yend = None
        uwrap.set(yaxis, "start", ystart, undolist=ul)
        uwrap.set(yaxis, "end", yend, undolist=ul)

        uwrap.emit_last(self.plot, "changed", undolist=ul)
        undolist.append(ul)
    def zoom_selection(self, undolist=[]):

        # TODO: We assume that there is a valid layer...
        layer = self.plot.layers[0]
        
        ul = UndoList()
        
        #
        # XRANGE
        #
        result = "\n".join(self.backend('show xrange'))
        regexp = re.compile('set xrange \[ (?P<xstart>.*) : (?P<xend>.*) \]')
        cv = regexp.search(result).groupdict()
        new_value = 'set xrange [ %(xstart)s : %(xend)s ]' % cv        

        xaxis = layer.request_axis('x', undolist=ul)
        xstart = cv['xstart']
        if xstart == '*':
            xstart = None
        xend = cv['xend']
        if xend == '*':
            xend = None
        uwrap.set( xaxis, 'start', xstart, undolist=ul )
        uwrap.set( xaxis, 'end', xend, undolist=ul )
        
        #
        # YRANGE
        #
        result = "\n".join(self.backend('show yrange'))
        regexp = re.compile('set yrange \[ (?P<ystart>.*) : (?P<yend>.*) \]')
        cv = regexp.search(result).groupdict()
        new_value = 'set yrange [ %(ystart)s : %(yend)s ]' % cv

        yaxis = layer.request_axis('y', undolist=ul)
        ystart = cv['ystart']
        if ystart == '*':
            ystart = None
        yend = cv['yend']
        if yend == '*':
            yend = None        
        uwrap.set(yaxis, 'start', ystart, undolist=ul)
        uwrap.set(yaxis, 'end', yend, undolist=ul)

        uwrap.emit_last( self.plot, "plot-changed", undolist=ul )
        undolist.append(ul)
Esempio n. 17
0
    def toggle_logscale_y(self, plot, layer, undolist=None):
        project = self.app.project
        if undolist is None:
            undolist = project.journal
            
        ul = UndoList().describe("Toggle logarithmic scale")

        axis = layer.request_axis("y", undolist=ul)
        if axis.scale != 'log':
            uwrap.set(axis, scale='log', undolist=ul)
            start = uwrap.get(axis, 'start')
            if start is not None and start < 0:
                uwrap.set(axis, start=None, undolist=ul)
        else:
            uwrap.set(axis, scale='linear', undolist=ul)

        uwrap.emit_last( plot, "plot-changed", undolist=ul )
        undolist.append(ul)
Esempio n. 18
0
    def on_edit(self, sender):
        (model, pathlist) = self.treeview.get_selection().get_selected_rows()
        if model is None:
            return
        project = self.get_data("project")

        label = model.get_value(model.get_iter(pathlist[0]), 0)
        new_label = self.edit(label.copy())
        changeset = label.create_changeset(new_label)

        ul = UndoList().describe("Update label.")
        changeset["undolist"] = ul
        uwrap.set(label, **changeset)
        uwrap.emit_last(self.backend.layer, "notify::labels", updateinfo={"edit": label}, undolist=ul)

        logger.info("Updateinfo: documentation = %s" % ul.doc)
        project.journal.append(ul)
        logger.info("Journal text: %s" % project.journal.undo_text())
Esempio n. 19
0
    def cb_column_properties(self, action):
        # column_object = treeview_column
        rownr, colnr, column_object = self.popup_info
        table = self.dataset.get_data()

        column = table.get_column(colnr)
        dialog = OptionsDialog(column.copy())
        try:
            response = dialog.run()
            if response == gtk.RESPONSE_ACCEPT:
                new_column = dialog.check_out()
                changeset = column.create_changeset(new_column)

                ul = UndoList().describe("Update Columns")
                uwrap.set(column, **changeset)
                uwrap.emit_last(table, "update-columns", undolist=ul)
                self.project.journal.append(ul)
        finally:
            dialog.destroy()
Esempio n. 20
0
    def add_datasets(self, datasets, undolist=None):
        if undolist is None:
            undolist = self.journal

        if len(datasets) == 0:
            undolist.append(NullUndo())

        ul = UndoList()
        ul.describe("Append Dataset to Project")

        for dataset in datasets:
            new_key = pdict.unique_key(self.datasets, dataset.key)
            if new_key != dataset.key:
                uwrap.set(dataset, "key", new_key, undolist=ul)
            ulist.append(self.datasets, dataset, undolist=ul)

        uwrap.emit_last(self.datasets, "changed", undolist=ul)
        undolist.append(ul)

        cli_logger.info("Added %d dataset(s)." % len(datasets))
Esempio n. 21
0
    def add_plots(self, plots, undolist=None):
        if undolist is None:
            undolist = self.journal

        if len(plots) == 0:
            undolist.append(NullUndo())

        ul = UndoList()
        ul.describe("Append Plots to Project")

        for plot in plots:
            new_key = pdict.unique_key(self.plots, plot.key)
            if new_key != plot.key:
                uwrap.set(plot, 'key', new_key, undolist=ul)
            ulist.append(self.plots, plot, undolist=ul)

        uwrap.emit_last(self, "notify::plots", undolist=ul)
        undolist.append(ul)

        cli_logger.info("Added %d plot(s)." % len(plots) )
    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)
Esempio n. 23
0
    def cb_edited_key(self, cell, path, new_text):
        """
        When an object key is edited, we need to check whether
        the key is valid. If so, the key is changed.
        """        
        model = self.get_model()
        object = model[path][self.COL_OBJECT]

        ul = UndoList()
        if isinstance(object , Dataset):
            if new_text not in [dataset.key for dataset in self.project.datasets]:
                ul.describe("Edit Dataset key")
                uwrap.set(object, key=new_text, undolist=ul)
                uwrap.emit_last(self.project.plots, "changed", undolist=ul)
        elif isinstance(object, Plot):
            if new_text not in [plot.key for plot in self.project.plots]:
                ul.describe("Edit Plot key")
                uwrap.set(object, key=new_text, undolist=ul)
                uwrap.emit_last(self.project.datasets, "changed", undolist=ul)

        if len(ul) > 0:
            self.project.journal.append(ul)        
Esempio n. 24
0
    def toggle_logscale_y(self, plot, layer, undolist=None):
        project = self.app.project
        if undolist is None:
            undolist = project.journal
            
        ul = UndoList().describe("Toggle logarithmic scale")

        axis = layer.yaxis
        if axis.scale != 'log':
            uwrap.set(axis, scale='log', undolist=ul)
            updateinfo.update['scale'] = 'log'
            
            start = uwrap.get(axis, 'start')
            if start is not None and start < 0:
                uwrap.set(axis, start=None, undolist=ul)
                updateinfo.update['start'] = None
        else:
            uwrap.set(axis, scale='linear', undolist=ul)

        # TODO: replace by something like
        #uwrap.emit_last(layer, "notify::axes", updateinfo=updateinfo, undolist=ul)
        uwrap.emit_last( plot, "plot-changed", undolist=ul )
        undolist.append(ul)
Esempio n. 25
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)
Esempio n. 26
0
    def add_experimental_plot(self, project, undolist=None):

        if undolist is None:
            undolist = project.journal

        ul = UndoList().describe("Experimental Plot")

        ds = Dataset()
        ds.key = pdict.unique_key(project.datasets, "exp_ds")
        ds.data = Table(colcount=2, rowcount=5)
        ds.data[0] = [1,2,3,4,5]
        ds.data[1] = [1,4,9,16,25]

        ds2 = Dataset()
        ds2.key = pdict.unique_key(project.datasets, "exp_ds2")
        ds2.data = Table(colcount=2, rowcount=4)
        ds2.data[0] = [10,17,3,8]
        ds2.data[1] = [1,89,48,1]

        ulist.append( project.datasets, ds, undolist=ul )
        ulist.append( project.datasets, ds2, undolist=ul )                

        plot = Plot()
        plot.key = pdict.unique_key(project.plots, "exp_plot")
        layer1 = Layer(type="line2d",
                       lines=[Line(source=ds,cx=0,cy=1), Line(source=ds2)],
                       x=0.0, y=0.0, width=1.0, height=0.5)
        layer2 = Layer(type="line2d",
                       lines=[Line(source=ds2,cx=0,cy=1)],
                       x=0.0, y=0.5, width=1.0, height=0.5)
        plot.layers = [layer1, layer2]
#        plot.layers.arrange(rowcount=1, colcount=2)
        
        ulist.append( project.plots, plot, undolist=ul )

        uwrap.emit_last(project.datasets, "changed")
        undolist.append(ul)
        finally:
            dialog.destroy()
        self.cview.queue_draw()


    def check_out(self, undolist=[]):
        self.cview.check_out(undolist=undolist)
        
    def run(self):
        self.cview.check_in()
        return gtk.Dialog.run(self)
            
        

###############################################################################
if __name__ == "__main__":

    table = setup_test_table()
    print table

    dlg = ModifyTableDialog(table)
    response = dlg.run()
    if response == gtk.RESPONSE_ACCEPT:
        ul = UndoList().describe("Update Columns")
        dialog.check_out(undolist=ul)
        uwrap.emit_last(table, 'update-columns', undolist=ul)
        #self.project.journal.append(ul)

    print table