Esempio n. 1
0
 def RemoveObjects(self, infolist):
     if not infolist:
         return NullUndo
     sliced = selinfo.list_to_tree_sliced(infolist)
     sliced.reverse()
     undo = [self.begin_change_children()]
     try:
         for start, end in sliced:
             if type(end) == IntType:
                 # > 1 adjacent children of self. XXX implement this
                 raise SketchInternalError('Deletion of multiple objects'
                                           ' of BlendGroups not yet'
                                           ' implemented')
             elif type(end) == ListType:
                 # remove grandchildren (children of child of self)
                 if start % 2 == 0:
                     # control object changes. This should result in
                     # a recompute() automatically.
                     undo.append(self.objects[start].RemoveObjects(end))
                 else:
                     pass
             else:
                 # a single child. If it's one of our control
                 # objects, remove self
                 undo.append(self.do_remove_child(start))
         undo.append(self.end_change_children())
         return CreateListUndo(undo)
     except:
         Undo(CreateListUndo(undo))
         raise
Esempio n. 2
0
 def do_remove_child(self, idx):
     undo = []
     try:
         if idx % 2 == 0:
             # a control object
             if self.document is not None:
                 undo.append(self.document.AddClearRect(self.bounding_rect))
             if len(self.objects) > 3:
                 if idx == 0:
                     undo.append(self.remove(1))
                     undo.append(self.remove(0))
                 elif idx == len(self.objects) - 1:
                     undo.append(self.remove(idx))
                     undo.append(self.remove(idx - 1))
                 else:
                     steps = self.objects[idx + 1].Steps() \
                           + self.objects[idx - 1].Steps()
                     u = (UndoAfter,
                          CreateMultiUndo(self.remove(idx + 1),
                                          self.remove(idx)),
                          self.objects[idx - 1].SetParameters(steps))
                     undo.append(u)
             else:
                 # remove one of only two control objects -> Remove self
                 undo.append(self.parent.Remove(self))
             return CreateListUndo(undo)
         else:
             # XXX implement this case
             raise ValueError, 'BlendGroup: cannot remove non control child'
     except:
         Undo(CreateListUndo(undo))
         raise
Esempio n. 3
0
 def ForAllUndo(self, func):
     # XXX: should we just change start and end and recompute?
     self.begin_change_children()
     undo = map(func, self.objects)
     self.end_change_children(ignore_child_changes=1)
     idx = range(0, len(self.objects), 2)
     undo = map(operator.getitem, [undo] * len(idx), idx)
     return CreateListUndo(undo)
Esempio n. 4
0
 def ForAllUndo(self, func):
     undoinfo = self.for_all(func)
     self.del_lazy_attrs()
     if len(undoinfo) == 1:
         undoinfo = undoinfo[0]
     if type(undoinfo) == ListType:
         return CreateListUndo(undoinfo)
     return undoinfo
Esempio n. 5
0
 def Transform(self, trafo):
     undo = [self.begin_change_children()]
     try:
         undo.append(PluginCompound.Transform(self, trafo))
         undo.append(self.set_transformation(trafo(self.trafo)))
         undo.append(self.end_change_children())
     except:
         undo.reverse()
         map(Undo, undo)
         raise
     return CreateListUndo(undo)
Esempio n. 6
0
 def ForAllUndo2(self, method, *args):
     t = time.clock()
     methods = map(getattr, self.GetObjects(), [method] * len(self.objects))
     #print time.clock() - t,
     #undoinfo = self.for_all(func)
     undoinfo = map(apply, methods, [args] * len(methods))
     #print time.clock() - t
     self.del_lazy_attrs()
     if len(undoinfo) == 1:
         undoinfo = undoinfo[0]
     if type(undoinfo) == ListType:
         return CreateListUndo(undoinfo)
     return undoinfo
Esempio n. 7
0
 def undo_changes(self):
     Undo(CreateListUndo(self.undo))