def remove_objects(self, objects, confirm=True, undolist=None): """ Remove the given objects (datasets or plots) from the current Project. Returns nothing. """ if undolist is None: undolist = self.journal # if you add an option confirm, make sure that it is False # when GtkApplication calls it. ul = UndoList() datasets = list() plots = list() for obj in objects: if isinstance(obj, Dataset): datasets.append(obj) elif isinstance(obj, Plot): plots.append(obj) if len(datasets) > 0: self.remove_datasets(datasets, undolist=ul) if len(plots) > 0: self.remove_plots(plots, undolist=ul) if len(ul) > 2: ul.describe("Remove objects") undolist.append(ul) return None
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]))
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)
def do_quit(udata, clist): print "Values before:" print recipe.get_values() print print "Values after:" ul = UndoList() for c in clist: c.check_out(undolist=ul) print recipe.get_values() print "Undoing: " ul.execute() print recipe.get_values() gtk.main_quit()
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()
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')
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)
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 apply_changes(self): ul = UndoList().describe("Edit Plot Properties") for tab in self.tabs: ui = UndoList() tab.check_out(undolist=ui) print "ui from tab ", type(tab) print ui.dump(detailed=True) print "simplified: ", ui.simplify().dump() print 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 add_datasets(self, datasets, undolist=None): if undolist is None: undolist = self.journal if len(datasets) == 0: undolist.append(NullUndo()) return 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 ) undolist.append(ul) cli_logger.info("Added %d dataset(s)." % len(datasets) )
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)
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, "changed", undolist=ul) else: ul = NullUndo() self.app.project.journal.add_undo(ul)
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)
continue except error.UserCancel: app.error_msg("Import aborted by user") continue root, ext = os.path.splitext(os.path.basename(filename)) ds.key = utils.encode_as_key(root) new_datasets.append(ds) n+=1 app.progress(n/N) app.progress(1.0) if len(new_datasets) > 0: ul = UndoList() if len(new_datasets) == 1: ul.describe("Import Dataset") else: ul.describe("Import %d Datasets" % len(new_datasets) ) project.add_datasets(new_datasets, undolist=ul) undolist.append(ul) #msg = "Import of %d datasets finished." % len(new_datasets) else: undolist.append(NullUndo()) #msg = "Nothing imported." app.progress(-1) #app.status_message(msg)