Exemplo n.º 1
0
def dragDrop(gr, ev):
    "Drag a Graphic, possibly into a different canvas"
    gr.hoverable = False
    pos = sigma(gr.pos, ev.rel)
    drop = False
    try:
        cv = [gr for gr in gr.sketch.objectAt(ev.pos).path if getattr(gr, "allowDrop", False)][0]
        if cv is not gr.canvas:
            pos = sigma(pos, delta(gr.canvas.rect.topleft, cv.rect.topleft))
            drop = True
            gr.setCanvas(cv)
    except: pass
    gr.config(pos=pos, hoverable=True)
    if drop: gr.bubble("ondrop", ev)
Exemplo n.º 2
0
 def draw(self, srf):
     c = self.canvas.rect.topleft
     pos = [round(x) for x in sigma(c, self.pos)]
     r = round(self.radius)
     wt = self.weight
     f = self._fill
     s = self._stroke
     rect = None
     if f: rect = pygame.draw.circle(srf, f, pos, r)
     if s and wt: rect = pygame.draw.circle(srf, s, pos, r, wt).inflate(wt, wt)
     return pygame.Rect((0, 0), (0, 0)) if rect is None else rect
Exemplo n.º 3
0
def _knobDrag(knob, ev):
    "Handle drag events on the slider's 'knob' object"
    slider = knob.canvas
    if knob._dragRel is None:
        knob._dragRel = delta(knob.rect.center, ev.pos)
    if slider._lastButton in slider.allowButton:
        x = pygame.event.Event(pygame.USEREVENT, pos=sigma(ev.pos, knob._dragRel))
        v = slider._val
        slider.val = slider._eventValue(x)
        x = slider.val
        setattr(ev, "target", slider)
        if x != v:
            setattr(ev, "method", DRAG)
            slider.bubble("onchange", ev)
Exemplo n.º 4
0
    def scroll(self, pix=None, rel=True):
        # Calculate scroll when not specified
        a = self.angle
        if pix is None: pix = self.focussed and a in (0, 90)
        if pix is False: pix, rel = 0, False
        elif pix is True: pix, rel = self._scrollCalc(a)

        # Set scrolling attributes
        if pix or not rel:
            if rel: self._scrollX += pix
            else:
                tmp = pix
                pix -= self._scrollX
                self._scrollX = tmp
            if pix:
                if a == 90: self.pos = self.pos[0], self.pos[1] + pix
                else: self.pos = sigma(self.pos, vec2d(pix, a))
        return self
Exemplo n.º 5
0
def ondrag(gr, ev):
    "Move a Graphic instance while dragging"
    gr.pos = sigma(gr.pos, ev.rel)
Exemplo n.º 6
0
 def cs(self, *pt):
     return self._cs(sigma(pt, self._scroll))