def MoveObjectsUp(self, infolist):
        sliced = list_to_tree_sliced(infolist)
        sliced.reverse()
        undo = [self.begin_change_children()]
        selection = []
        permutation = range(len(self.objects))
        objects = self.objects
        max = len(objects)
        try:
            for start, end in sliced:
                if type(end) == IntType:
                    if end < max:
                        temp = permutation[start:end]
                        del permutation[start:end]
                        permutation[start + 1:start + 1] = temp
                        selection = selection + select_range(
                            start + 1, objects[start:end])
                    else:
                        selection = selection + select_range(
                            start, objects[start:end])

                elif type(end) == ListType:
                    sel, undo_info = objects[start].MoveObjectsUp(end)
                    if undo_info is not NullUndo:
                        undo.append(undo_info)
                    selection = selection + prepend_idx(start, sel)
                else:
                    if start < max - 1:
                        del permutation[start]
                        permutation.insert(start + 1, start)
                        selection.append(build_info(start + 1, objects[start]))
                    else:
                        selection.append(build_info(start, objects[start]))

            undo_info = self.permute_objects(permutation)
            if undo_info is not NullUndo:
                undo.append(undo_info)
            undo.append(self.end_change_children())
            if len(undo) <= 2:
                undo = NullUndo
                selection = infolist
            else:
                undo = CreateListUndo(undo)
            return (selection, undo)
        except:
            Undo(CreateListUndo(undo))
            raise
Beispiel #2
0
    def MoveObjectsUp(self, infolist):
	sliced = list_to_tree_sliced(infolist)
	sliced.reverse()
	undo = [self.begin_change_children()]
	selection = []
	permutation = range(len(self.objects))
	objects = self.objects
	max = len(objects)
	try:
	    for start, end in sliced:
		if type(end) == IntType:
		    if end < max:
			temp = permutation[start:end]
			del permutation[start:end]
			permutation[start + 1:start + 1] = temp
			selection = selection + select_range(start + 1,
							   objects[start:end])
		    else:
			selection = selection + select_range(start,
							   objects[start:end])

		elif type(end) == ListType:
		    sel, undo_info = objects[start].MoveObjectsUp(end)
		    if undo_info is not NullUndo:
			undo.append(undo_info)
		    selection = selection + prepend_idx(start, sel)
		else:
		    if start < max - 1:
			del permutation[start]
			permutation.insert(start + 1, start)
			selection.append(build_info(start + 1, objects[start]))
		    else:
			selection.append(build_info(start, objects[start]))

	    undo_info = self.permute_objects(permutation)
	    if undo_info is not NullUndo:
		undo.append(undo_info)
	    undo.append(self.end_change_children())
	    if len(undo) <= 2:
		undo = NullUndo
		selection = infolist
	    else:
		undo = CreateListUndo(undo)
	    return (selection, undo)
	except:
	    Undo(CreateListUndo(undo))
	    raise
 def Insert(self, obj, at):
     # Insert OBJ into the object hierarchy at the position described
     # by AT. AT should be either an integer or a tuple of integers.
     # OBJ can be a graphics object of a list of such objects.
     #
     # If AT is a tuple of 2 or more ints, self's child at AT[0] has
     # to be a compound object and its Insert method is called with
     # OBJ and AT[1:] as arguments.
     #
     # If AT is an int or a singleton of one int, insert OBJ at that
     # position in self's children. If OBJ is a graphics object, this
     # works just like a list objects insert method (insert(AT,
     # OBJ)). If its a list of graphics objects this method
     # effectively assigns that list to the slice AT:AT.
     #
     # As a side effect, this method calls the following methods of
     # the inserted objects:
     #
     #	    obj.SetDocument(self.document)
     #	    obj.SetParent(self)
     #	    obj.Connect()
     #
     # Return a tuple (SELINFO, UNDO), where SELINFO is selection
     # info for the inserted objects at their new positions, and UNDO
     # is the appropriate undo info.
     #
     # If self is modified directly, issue a CHANGED message.
     undo_info = None
     try:
         if type(at) == TupleType and at:
             if len(at) == 1:
                 at = at[0]
             else:
                 child = at[0]
                 at = at[1:]
                 sel_info, undo_info = self.objects[child].Insert(obj, at)
                 sel_info = prepend_idx(child, sel_info)
                 return (sel_info, undo_info)
         if type(at) != IntType or at > len(self.objects):
             at = len(self.objects)
         if type(obj) == InstanceType:
             self.objects.insert(at, obj)
             obj.SetDocument(self.document)
             obj.SetParent(self)
             obj.Connect()
             sel_info = build_info(at, obj)
             undo_info = (self.Remove, obj, at)
         else:
             self.objects[at:at] = obj
             for o in obj:
                 # XXX: should we have undo info for these:
                 o.SetDocument(self.document)
                 o.SetParent(self)
                 o.Connect()
             sel_info = select_range(at, obj)
             undo_info = (self.RemoveSlice, at, at + len(obj))
         self._changed()
         return (sel_info, undo_info)
     except:
         if undo_info is not None:
             Undo(undo_info)
         raise
Beispiel #4
0
    def Insert(self, obj, at):
	# Insert OBJ into the object hierarchy at the position described
	# by AT. AT should be either an integer or a tuple of integers.
	# OBJ can be a graphics object of a list of such objects.
	#
	# If AT is a tuple of 2 or more ints, self's child at AT[0] has
	# to be a compound object and its Insert method is called with
	# OBJ and AT[1:] as arguments.
	#
	# If AT is an int or a singleton of one int, insert OBJ at that
	# position in self's children. If OBJ is a graphics object, this
	# works just like a list objects insert method (insert(AT,
	# OBJ)). If its a list of graphics objects this method
	# effectively assigns that list to the slice AT:AT.
	#
	# As a side effect, this method calls the following methods of
	# the inserted objects:
	#
	#	    obj.SetDocument(self.document)
	#	    obj.SetParent(self)
	#	    obj.Connect()
	#
	# Return a tuple (SELINFO, UNDO), where SELINFO is selection
	# info for the inserted objects at their new positions, and UNDO
	# is the appropriate undo info.
	#
	# If self is modified directly, issue a CHANGED message.
	undo_info = None
	try:
	    if type(at) == TupleType and at:
		if len(at) == 1:
		    at = at[0]
		else:
		    child = at[0]
		    at = at[1:]
		    sel_info, undo_info = self.objects[child].Insert(obj, at)
		    sel_info = prepend_idx(child, sel_info)
		    return (sel_info, undo_info)
	    if type(at) != IntType or at > len(self.objects):
		at = len(self.objects)
	    if type(obj) == InstanceType:
		self.objects.insert(at, obj)
		obj.SetDocument(self.document)
		obj.SetParent(self)
		obj.Connect()
		sel_info = build_info(at, obj)
		undo_info = (self.Remove, obj, at)
	    else:
		self.objects[at:at] = obj
		for o in obj:
		    # XXX: should we have undo info for these:
		    o.SetDocument(self.document)
		    o.SetParent(self)
		    o.Connect()
		sel_info = select_range(at, obj)
		undo_info = (self.RemoveSlice, at, at + len(obj))
	    self._changed()
	    return (sel_info, undo_info)
	except:
	    if undo_info is not None:
		Undo(undo_info)
	    raise
Beispiel #5
0
 def SelectionInfo(self, child, cache=None):
     info = selinfo.build_info(_sketch.IdIndex(self.objects, child), child)
     return selinfo.prepend_idx(self.document.LayerIndex(self), info)
Beispiel #6
0
 def SelectionInfo(self, child, cache=None):
     info = selinfo.build_info(_sketch.IdIndex(self.objects, child), child)
     return selinfo.prepend_idx(self.document.LayerIndex(self), info)