我有一个图像注释工具,它采用当前在 GIMP 中活动的选择并将其保存到一个新层,充当实例分割的掩码。我还有一个具有 TreeView 的外部 GUI(在 PyGTK2 中),其中包含所有注释的列表。我希望能够撤消所做的注释,GIMP 可以撤消掩码的创建,但它可以更新外部 GUI 的状态,并且能够更新更改。我不完全确定撤消堆栈通常如何工作/与 GIMP 一起工作,因此将不胜感激。
def save_mask_on_click(self, widget):
pdb.gimp_image_undo_group_start(self.img)
# make sure a selection exists
if pdb.gimp_selection_is_empty(self.img):
pdb.gimp_message('No selection - Select an area first')
return
if self.label_combo.get_active_text() is None:
pdb.gimp_message('No label selected - add and select a label first')
return
self.region_id = int(self.sb_adj.get_value())
rgb = id2rgb(self.region_id)
pdb.gimp_context_set_foreground(rgb)
pdb.gimp_drawable_edit_fill(self.annot_layer, 0)
path = pdb.plug_in_sel2path(self.img, None)
self.path_db[self.region_id] = pdb.gimp_vectors_export_to_string(self.img, path)
pdb.gimp_selection_none(self.img)
label = self.label_combo.get_active_text()
self.region_db[self.region_id] = label
text = '(' + str(self.region_id) + ') ' + str(label)
self.mask_store.append([text])
self.region_id += 1
if self.region_id > self.max_id:
self.max_id = self.region_id
self.sb_adj.set_upper(self.max_id)
self.sb_adj.set_value(self.max_id)
pdb.gimp_image_undo_group_end(self.img)