Example #1
0
 def __init__(self, scene, deleteItem):
     super(CommandDelete, self).__init__()
     self.scene = scene
     self.deleteItem = deleteItem
     self.setText("Delete")
     # the delete animation object
     self.do = DeleteObject(self.deleteItem.shape())
Example #2
0
class CommandDelete(QUndoCommand):
    # Deletes the graphicsitem. Have to be careful when it is
    # a rubric-item - need to refresh score in parent-scene
    # and be careful that is done once the item is actually deleted.
    def __init__(self, scene, deleteItem):
        super(CommandDelete, self).__init__()
        self.scene = scene
        self.deleteItem = deleteItem
        self.setText("Delete")
        # the delete animation object
        self.do = DeleteObject(self.deleteItem.shape())

    def redo(self):
        # remove the object
        self.scene.removeItem(self.deleteItem)
        if isinstance(self.deleteItem, GroupDeltaTextItem):
            self.scene.refreshStateAndScore()
        ## flash an animated box around the deleted object
        self.scene.addItem(self.do.item)
        self.do.flash_undo(
        )  # note - is undo animation since object being removed
        QTimer.singleShot(200, lambda: self.scene.removeItem(self.do.item))

    def undo(self):
        ## flash an animated box around the un-deleted object
        self.scene.addItem(self.do.item)
        self.do.flash_redo(
        )  # is redo animation since object being brought back
        QTimer.singleShot(200, lambda: self.scene.removeItem(self.do.item))
        # put the object back
        self.scene.addItem(self.deleteItem)
        # If the object is a GroupTextDeltaItem then refresh the state and score
        if isinstance(self.deleteItem, GroupDeltaTextItem):
            self.scene.refreshStateAndScore()
Example #3
0
 def __init__(self, scene, pt, text):
     super().__init__(scene)
     self.blurb = TextItem(pt,
                           text,
                           scene,
                           fontsize=scene.fontSize,
                           color=scene.style["annot_color"])
     self.do = DeleteObject(self.blurb.shape(), fill=True)
     self.setText("Text")
Example #4
0
class CommandGroupDeltaText(CommandTool):
    """A group of delta and text.

    Command to do a delta and a textitem together (a "rubric" or
    "saved comment").

    Note: must change mark
    """
    def __init__(self, scene, pt, rid, kind, delta, text):
        super().__init__(scene)
        self.gdt = GroupDeltaTextItem(
            pt,
            delta,
            text,
            rid,
            kind,
            scene=scene,
            style=scene.style,
            fontsize=scene.fontSize,
        )
        self.do = DeleteObject(self.gdt.shape(), fill=True)
        self.setText("GroupDeltaText")

    @classmethod
    def from_pickle(cls, X, *, scene):
        """Construct a CommandGroupDeltaText from a serialized GroupDeltaTextItem.

        TODO: could this comandFoo.__init__() take a FooItem?
        """
        assert X[0] == "GroupDeltaText"
        X = X[1:]
        if len(X) != 6:
            raise ValueError("wrong length of pickle data")
        # knows to latex it if needed.
        return cls(scene, QPointF(X[0], X[1]), X[2], X[3], X[4], X[5])

    def redo(self):
        self.scene.addItem(self.gdt)
        # animate
        self.scene.addItem(self.do.item)
        self.do.flash_redo()
        QTimer.singleShot(200, lambda: self.scene.removeItem(self.do.item))
        #
        self.scene.refreshStateAndScore()

    def undo(self):
        self.scene.removeItem(self.gdt)
        # animate
        self.scene.addItem(self.do.item)
        self.do.flash_undo()
        QTimer.singleShot(200, lambda: self.scene.removeItem(self.do.item))
        #
        self.scene.refreshStateAndScore()
Example #5
0
 def __init__(self, scene, pt, rid, kind, delta, text):
     super().__init__(scene)
     self.gdt = GroupDeltaTextItem(
         pt,
         delta,
         text,
         rid,
         kind,
         scene=scene,
         style=scene.style,
         fontsize=scene.fontSize,
     )
     self.do = DeleteObject(self.gdt.shape(), fill=True)
     self.setText("GroupDeltaText")
Example #6
0
 def __init__(self, scene, pti, ptf):
     super().__init__(scene)
     self.scene = scene
     # A line from pti(nitial) to ptf(inal)
     self.obj = LineItem(pti, ptf, scene.style)
     self.do = DeleteObject(self.obj.shape())
     self.setText("Line")
Example #7
0
class CommandText(CommandTool):
    def __init__(self, scene, pt, text):
        super().__init__(scene)
        self.blurb = TextItem(pt,
                              text,
                              scene,
                              fontsize=scene.fontSize,
                              color=scene.style["annot_color"])
        self.do = DeleteObject(self.blurb.shape(), fill=True)
        self.setText("Text")

    @classmethod
    def from_pickle(cls, X, *, scene):
        """Construct a CommandText from a serialized form."""
        assert X[0] == "Text"
        X = X[1:]
        if len(X) != 3:
            raise ValueError("wrong length of pickle data")
        # knows to latex it if needed.
        return cls(scene, QPointF(X[1], X[2]), X[0])

    def redo(self):
        self.scene.addItem(self.blurb)
        # update the deleteobject since the text may have been updated
        # use getshape - takes offset into account
        self.do.item.setPath(self.blurb.getShape())
        # animate
        self.scene.addItem(self.do.item)
        self.do.flash_redo()
        QTimer.singleShot(200, lambda: self.scene.removeItem(self.do.item))

    def undo(self):
        self.scene.removeItem(self.blurb)
        # update the deleteobject since the text may have been updated
        # use getshape - takes offset into account
        self.do.item.setPath(self.blurb.getShape())
        # animate
        self.scene.addItem(self.do.item)
        self.do.flash_undo()
        QTimer.singleShot(200, lambda: self.scene.removeItem(self.do.item))
Example #8
0
    def __init__(self, scene, pt, image, scale=1, border=True, data=None):
        """
        Initialize a new Image command.

        Args:
            scene (PageScene): the scene the image is being inserted into.
            pt (QPoint): the point of the top left corner of the image.
            image (QImage): the image being added to the scene.
            scale (float): the scaling value, <1 decreases size, >1 increases.
            border (bool): True if the image has a border, false otherwise.
            data (str): Base64 data held in a string if the image had
                previously been json serialized.
        """
        super().__init__(scene)
        self.width = image.width()
        if data is None:
            toMidpoint = QPoint(-image.width() / 2, -image.height() / 2)
            self.midPt = pt + toMidpoint
        else:
            self.midPt = pt
        self.image = image
        self.obj = ImageItem(self.midPt, self.image, scale, border, data)
        self.do = DeleteObject(self.obj.shape())
        self.setText("Image")
Example #9
0
 def __init__(self, scene, pt):
     super().__init__(scene)
     self.obj = QMarkItem(pt, scene.style)
     self.do = DeleteObject(self.obj.shape())
     self.setText("QMark")
Example #10
0
 def __init__(self, scene, rect):
     super().__init__(scene)
     self.obj = BoxItem(rect, scene.style)
     self.do = DeleteObject(self.obj.shape(), fill=True)
     self.setText("Box")
Example #11
0
 def __init__(self, scene, path):
     super().__init__(scene)
     self.obj = PenItem(path, scene.style)
     self.do = DeleteObject(self.obj.shape())
     self.setText("Pen")
Example #12
0
 def __init__(self, scene, path):
     super().__init__(scene, path)
     self.obj = HighlightItem(path, scene.style)
     self.do = DeleteObject(self.obj.path)
     self.setText("Highlight")