def check_out(self, undolist=[]):

        ul = UndoList()
        
        def check_out_row(owner, iter, undolist=[]):
            n = 0
            adict = {}
            for key in self.keys:
                adict[key]=model.get_value(iter, n)
                n += 1
            adict['undolist'] = ul
            uwrap.smart_set(owner, **adict)

        new_list = []
        model = self.treeview.get_model()
        iter = model.get_iter_first()
        while iter is not None:
            owner = model.get_value(iter, len(self.keys))
            check_out_row(owner, iter, undolist=ul)
            new_list.append(owner)
            iter = model.iter_next(iter)

        if self.old_list != new_list:        
            uwrap.set(self.listowner, self.listkey, new_list, undolist=ul)
            self.old_list = new_list

        undolist.append(ul)
Example #2
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()
 def check_out(self, undolist=[]):
     if self.widget.get_inconsistent() is True:
         val = None
     else:
         val = self.widget.get_active()
     if val != self.old_value:
         uwrap.set( self.container, self.key, val, undolist=undolist)
         self.old_value = val
    def check_out(self, undolist=[]):           
        val = self.widget.get_text()
        if len(val) == 0:
            val = None
        else:
            val = self.prop.check_type(val)

        if val != self.old_value:
            uwrap.set(self.container, self.key, val, undolist=undolist)
            #self.container.set(self.key, val, undolist=undolist)
            self.old_value = val
    def check_out(self, undolist=[]):
        # create changeset
        new_values = self.obj._values
        old_values = self.original_obj._values

        changeset = {}
        for key, value in new_values.iteritems():
            if value != old_values[key]:
                changeset[key] = value

        changeset['undolist'] = undolist
        uwrap.set(self.original_obj, **changeset)
    def rename_plot(self, xn_plot, new_key, undolist=None):
        " Analogon to `rename_dataset`. "
        if undolist is None:
            undolist = self.journal

        plotlist = [plot for plot in self.plots]
        plot = self.get_plot(xn_plot)
        plotlist.remove(plot)
        new_key = pdict.unique_key(plotlist, new_key)
        
        uwrap.set(plot, 'key', new_key, undolist=undolist)
        return plot
 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 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
                
            uwrap.set(axis, start=_start, end=_end, undolist=ul)
 def check_out(self, undolist=[]):        
     model = self.get_model()
     iter = model.get_iter_first()
     n = 0
     while iter:
         column = model.get_value(iter, 0)
         # copy all properties except for the actual data
         kwargs = column.get_key_value_dict()
         kwargs.pop('data')
         uwrap.set(self.table.get_column(n), **kwargs)             # ADD Undo
         iter = model.iter_next(iter)
         n += 1
 def check_out(self, undolist=[]):        
     model = self.get_model()
     iter = model.get_iter_first()
     n = 0
     while iter:
         column = model.get_value(iter, 0)
         # copy all properties except for the actual data
         kwargs = column.get_values(exclude=['data'])
         print "CHECK_ ", kwargs
         uwrap.set(self.table.get_column(n), **kwargs)             # ADD Undo
         iter = model.iter_next(iter)
         n += 1
Example #11
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)    
Example #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 = 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())
    def rename_dataset(self, xn_dataset, new_key, undolist=None):
        """
        Rename a Dataset and make sure that its key is unique.
        The name might be modified so if the key is important to you,
        you might want to check it afterwards.
        Returns the Dataset.
        """
        if undolist is None:
            undolist = self.journal

        dataset = self.get_dataset(xn_dataset)

        dslist = [ds for ds in self.datasets]
        dslist.remove(dataset)
        new_key = pdict.unique_key(dslist, new_key)
        
        uwrap.set(dataset, 'key', new_key, undolist=undolist)
        return dataset
    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()
    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)

        undolist.append(ul)

        cli_logger.info("Added %d plot(s)." % len(plots) )
    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))
    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)        
    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_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)
    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)
    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)
    def edit(self, obj):

        # create new widget (unless we don't have a SPObject, e.g. a List)
        if self.edit_cache.has_key(obj.__class__) is False:
            # create factory
            factory = checkwidgets.DisplayFactory(obj)
            try:
                #keys = KLASS_KEYS[obj.__class__]
                keys = KLASS_DESCR[obj.__class__]['attrs']
            except KeyError:
                keys = [key for key, check in obj._checks.iteritems() if not isinstance(check, (List,Dict))]                
            factory.add_keys(keys)

            # create widget and add it to the edit area
            tbl = factory.create_table()
            widget = uihelper.add_scrollbars(tbl, viewport=True)
            self.paned.pack2(widget)

            # set up undo hooks (needs to be after creation of table, because
            # otherwise there are no displays!)
            undo_hook = lambda obj, key, value: uwrap.set(obj, key, value, undolist=globals.app.project.journal)
            for display in factory.displays.itervalues():
                display.set_value = undo_hook

            self.add_to_cache(obj, widget, factory)           

        # show widget
        widget, factory = self.edit_cache[obj.__class__]
        if factory is not None:
            factory.connect(obj)
        child = self.paned.get_child2()
        if child is not None and child is not widget:
            self.paned.remove(child)
            self.paned.pack2(widget)
        widget.show_all()

        self.obj = obj        
    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)