Ejemplo n.º 1
0
    def onDrop(self, event):
        dt = event.dataTransfer
        text = dt.getData('text')
        package = json.decode(text)
        x = DOM.eventGetClientX(event)
        y = DOM.eventGetClientY(event)
        scrollY = Window.getScrollTop()
        scrollX = Window.getScrollLeft()
        offsetX = int(package['offsetX'])
        offsetY = int(package['offsetY'])
        at = self.getAbsoluteTop()
        al = self.getAbsoluteLeft()
        posX, posY = x - (al - scrollX), y - (at - scrollY)
        w = DragWidget6(package['text'])
        self.add(w)
        makeDraggable(w)
        # firefox seems to be off-by-one in x.
        # firefox-specific code?
        #w.setStyleAttribute('left', posX - offsetX -1)
        w.setStyleAttribute('left', posX - offsetX)
        w.setStyleAttribute('top', posY - offsetY)
        w.removeStyleName('invisible')
        self.addMessage(
            "top:%s, left:%s, cy:%s cx:%s, sy:%s sx:%s dropy:%s dropx:%s" % (
            at, al, y, x, scrollY, scrollX, posY, posX))

        DOM.eventPreventDefault(event)
Ejemplo n.º 2
0
 def action(self,element,event):
     x = DOM.eventGetClientX(event) - self.ox
     y = DOM.eventGetClientY(event) - self.oy
     DOM.eventCancelBubble(event,True)
     DOM.eventPreventDefault(event)
     #alert('clic %s %s'%(x,y))
     self._action(x,y)
Ejemplo n.º 3
0
 def onCanvasContextmenu(self, sender, event):
     x = DOM.eventGetClientX(event) - DOM.getAbsoluteLeft(
         self.canvas.getElement())
     y = DOM.eventGetClientY(event) - DOM.getAbsoluteTop(
         self.canvas.getElement())
     self.set_status('Contextmenue on Canvas at ' + str(x) + ', ' + str(y))
     DOM.eventPreventDefault(event)
Ejemplo n.º 4
0
def fireMouseEvent(listeners, sender, event):
    x = DOM.eventGetClientX(event) - DOM.getAbsoluteLeft(sender.getElement())
    y = DOM.eventGetClientY(event) - DOM.getAbsoluteTop(sender.getElement())

    etype = DOM.eventGetType(event)
    if etype == "mousedown":
        for listener in listeners:
            listener.onMouseDown(sender, x, y)
        return True
    elif etype == "mouseup":
        for listener in listeners:
            listener.onMouseUp(sender, x, y)
        return True
    elif etype == "mousemove":
        for listener in listeners:
            listener.onMouseMove(sender, x, y)
        return True
    elif etype == "mouseover":
        from_element = DOM.eventGetFromElement(event)
        if not DOM.isOrHasChild(sender.getElement(), from_element):
            for listener in listeners:
                listener.onMouseEnter(sender)
        return True
    elif etype == "mouseout":
        to_element = DOM.eventGetToElement(event)
        if not DOM.isOrHasChild(sender.getElement(), to_element):
            for listener in listeners:
                listener.onMouseLeave(sender)
        return True
    return False
Ejemplo n.º 5
0
    def onDrop(self, event):
        dt = event.dataTransfer
        text = dt.getData('text')
        package = json.decode(text)
        x = DOM.eventGetClientX(event)
        y = DOM.eventGetClientY(event)
        scrollY = Window.getScrollTop()
        scrollX = Window.getScrollLeft()
        offsetX = int(package['offsetX'])
        offsetY = int(package['offsetY'])
        at = self.getAbsoluteTop()
        al = self.getAbsoluteLeft()
        posX, posY = x - (al - scrollX), y - (at - scrollY)
        w = DragWidget6(package['text'])
        self.add(w)
        makeDraggable(w)
        # firefox seems to be off-by-one in x.
        # firefox-specific code?
        #w.setStyleAttribute('left', posX - offsetX -1)
        w.setStyleAttribute('left', posX - offsetX)
        w.setStyleAttribute('top', posY - offsetY)
        w.removeStyleName('invisible')
        self.addMessage(
            "top:%s, left:%s, cy:%s cx:%s, sy:%s sx:%s dropy:%s dropx:%s" %
            (at, al, y, x, scrollY, scrollX, posY, posX))

        DOM.eventPreventDefault(event)
Ejemplo n.º 6
0
 def onElementContextmenu(self, sender,event):
     x = DOM.eventGetClientX(event) - DOM.getAbsoluteLeft(self.canvas.getElement())
     y = DOM.eventGetClientY(event) - DOM.getAbsoluteTop(self.canvas.getElement())
     s = self.desc[self.elements.index(sender)]
     self.set_status('Contextmenue on Element '+s+' at '+str(x)+', '+str(y))
     DOM.eventCancelBubble(event,True)
     DOM.eventPreventDefault(event)
Ejemplo n.º 7
0
def fireMouseEvent(listeners, sender, event):
    x = DOM.eventGetClientX(event) - DOM.getAbsoluteLeft(sender.getElement())
    y = DOM.eventGetClientY(event) - DOM.getAbsoluteTop(sender.getElement())

    etype = DOM.eventGetType(event)
    if etype == "mousedown":
        for listener in listeners:
            listener.onMouseDown(sender, x, y)
        return True
    elif etype == "mouseup":
        for listener in listeners:
            listener.onMouseUp(sender, x, y)
        return True
    elif etype == "mousemove":
        for listener in listeners:
            listener.onMouseMove(sender, x, y)
        return True
    elif etype == "mouseover":
        from_element = DOM.eventGetFromElement(event)
        if not DOM.isOrHasChild(sender.getElement(), from_element):
            for listener in listeners:
                listener.onMouseEnter(sender)
        return True
    elif etype == "mouseout":
        to_element = DOM.eventGetToElement(event)
        if not DOM.isOrHasChild(sender.getElement(), to_element):
            for listener in listeners:
                listener.onMouseLeave(sender)
        return True
    return False
 def onClick(self, sender=None):
     self.setFocus(True)
     # work out the relative position of cursor
     event = DOM.eventGetCurrentEvent()
     mouse_x = DOM.eventGetClientX(event) + Window.getScrollLeft()
     mouse_y = DOM.eventGetClientY(event) + Window.getScrollTop()
     self.moveControl(mouse_x - self.getAbsoluteLeft(),
                      mouse_y - self.getAbsoluteTop(), True)
Ejemplo n.º 9
0
 def onClick(self, sender=None):
     self.setFocus(True);
     # work out the relative position of cursor
     event = DOM.eventGetCurrentEvent()
     mouse_x = DOM.eventGetClientX(event) + Window.getScrollLeft()
     mouse_y = DOM.eventGetClientY(event) + Window.getScrollTop()
     self.moveControl(mouse_x - self.getAbsoluteLeft(),
                      mouse_y - self.getAbsoluteTop())
Ejemplo n.º 10
0
 def onElementDblClick(self, sender, event):
     x = DOM.eventGetClientX(event) - DOM.getAbsoluteLeft(
         self.canvas.getElement())
     y = DOM.eventGetClientY(event) - DOM.getAbsoluteTop(
         self.canvas.getElement())
     s = self.desc[self.elements.index(sender)]
     self.set_status('Doubleclick on Element ' + s + ' at ' + str(x) +
                     ', ' + str(y))
     DOM.eventCancelBubble(event, True)
Ejemplo n.º 11
0
 def onElementContextmenu(self, sender, event):
     x = DOM.eventGetClientX(event) - DOM.getAbsoluteLeft(
         self.canvas.getElement())
     y = DOM.eventGetClientY(event) - DOM.getAbsoluteTop(
         self.canvas.getElement())
     s = self.desc[self.elements.index(sender)]
     self.set_status('Contextmenue on Element ' + s + ' at ' + str(x) +
                     ', ' + str(y))
     DOM.eventCancelBubble(event, True)
     DOM.eventPreventDefault(event)
Ejemplo n.º 12
0
    def test(self,elm,event,msg='foi'):
        location = None
        JS('''
           location = window.location.hostname;

           ''')
        if 'localhost' == location: location +=':8004'
        return location
        x = DOM.eventGetClientX(event)
        y = DOM.eventGetClientY(event)
        alert ('%s %s %s'%(msg,x,y))
Ejemplo n.º 13
0
  def onContextMenu(self, sender):
    event = DOM.eventGetCurrentEvent()
    subMenu = MenuBar(True)
    subMenu.addItem("<code>Code</code>", True, self)
    subMenu.addItem("<strike>Strikethrough</strike>", True, self)
    subMenu.addItem("<u>Underlined</u>", True, self)

    x = DOM.eventGetClientX(event) + 2
    y = DOM.eventGetClientY(event) + 2

    popup = ContextMenuPopupPanel(subMenu)
    popup.showAt(x, y)
Ejemplo n.º 14
0
 def onBrowserEvent(self, event):
    kind = DOM.eventGetType(event)
    x = DOM.eventGetClientX(event) - DOM.getAbsoluteLeft(self.getElement())
    y = DOM.eventGetClientY(event) - DOM.getAbsoluteTop(self.getElement())
    y = HEIGHT - y
    if kind == "mousedown":
       self.onMouseDown(x,y)
       self._dragging = True
    elif kind == "mousemove" and self._dragging:
       self.onMouseDrag(x,y)
    elif (kind == "mouseup" or kind == "mouseout") and self._dragging:
       self._dragging = False
       self.onMouseUp(x,y)
Ejemplo n.º 15
0
    def onBrowserEvent(self, event):
        typ = DOM.eventGetType(event)

        if typ == "mousedown":
            target = DOM.eventGetTarget(event)
            if DOM.isOrHasChild(self.splitElem, target):
                self.startResizingFrom(
                    DOM.eventGetClientX(event) - self.getAbsoluteLeft(),
                    DOM.eventGetClientY(event) - self.getAbsoluteTop())
                DOM.setCapture(self.getElement())
                DOM.eventPreventDefault(event)

        elif typ == "mouseup":
            DOM.releaseCapture(self.getElement())
            self.stopResizing()

        elif typ == 'mousemove':
            if self.isResizing:
                #assert DOM.getCaptureElement() is not None
                self.onSplitterResize(
                    DOM.eventGetClientX(event) - self.getAbsoluteLeft(),
                    DOM.eventGetClientY(event) - self.getAbsoluteTop())
                DOM.eventPreventDefault(event)
Ejemplo n.º 16
0
def getDropPosition(target, event):
    dt = event.dataTransfer
    text = dt.getData('text')
    package = json.loads(text)
    x, y = DOM.eventGetClientX(event), DOM.eventGetClientY(event)
    scrollX, scrollY = Window.getScrollLeft(), Window.getScrollTop()
    if package == False:
        offsetX, offsetY = 0, 0
    else:
        offsetX, offsetY = int(package['offsetX']), int(
            package['offsetY'])  #BUG no chromium
    at, al = target.getAbsoluteTop(), target.getAbsoluteLeft()
    posX, posY = x - (al - scrollX), y - (at - scrollY)
    return max(posX - offsetX, 0), max(posY - offsetY, 0)
Ejemplo n.º 17
0
 def onBrowserEvent(self, event):
    print "Event happened"
    kind = DOM.eventGetType(event)
    x = DOM.eventGetClientX(event) - DOM.getAbsoluteLeft(self.canvas.getElement())
    y = DOM.eventGetClientY(event) - DOM.getAbsoluteTop(self.canvas.getElement())
    print "Type of event: %s" % (kind)
    if kind == "mousedown":
       self._dragging = True
       self.onMouseDown(x,y)
    elif kind == "mousemove" and self._dragging:
       self.onMouseDrag(x,y)
    elif (kind == "mouseup" or kind == "mouseout") and self._dragging:
       self._dragging = False
       self.onMouseUp(x,y)
Ejemplo n.º 18
0
    def onBrowserEvent(self, event):
        typ = DOM.eventGetType(event)

        if typ == "mousedown":
            target = DOM.eventGetTarget(event)
            if DOM.isOrHasChild(self.splitElem, target):
                self.startResizingFrom(DOM.eventGetClientX(event) -
                                       self.getAbsoluteLeft(),
                          DOM.eventGetClientY(event) - self.getAbsoluteTop())
                DOM.setCapture(self.getElement())
                DOM.eventPreventDefault(event)

        elif typ == "mouseup":
            DOM.releaseCapture(self.getElement())
            self.stopResizing()

        elif typ == 'mousemove':
            if self.isResizing:
                #assert DOM.getCaptureElement() is not None
                self.onSplitterResize(DOM.eventGetClientX(event) -
                                      self.getAbsoluteLeft(),
                          DOM.eventGetClientY(event) - self.getAbsoluteTop())
                DOM.eventPreventDefault(event)
Ejemplo n.º 19
0
 def onClick(self, sender, evt):
     x = DOM.eventGetClientX(evt) - DOM.getAbsoluteLeft(self.getElement())
     y = DOM.eventGetClientY(evt) - DOM.getAbsoluteTop(self.getElement())
     xth = int(x / uwidth)
     yth = int(y / uheight)
     box = self.map[yth][xth]
     if not box:
         return
     box.toggleSelect()
     if not box.selected:
         self.selected_box = None
     elif self.selected_box == None:
         self.selected_box = box
     elif box.img != self.selected_box.img:
         # change selection
         self.selected_box.unSelect()
         self.selected_box = box
     else:
         sbox = self.selected_box
         print 'check'
         result = False
         if box.xth < sbox.xth:
             print(box.yth, box.xth), (sbox.yth, sbox.xth)
             result = checkllk(self.map, (box.yth, box.xth),
                               (sbox.yth, sbox.xth))
         else:
             print(sbox.yth, sbox.xth), (box.yth, box.xth)
             result = checkllk(self.map, (sbox.yth, sbox.xth),
                               (box.yth, box.xth))
         if result:
             print 'path:', result
             sbox.dead()
             self.map[sbox.yth][sbox.xth] = 0
             box.dead()
             self.map[box.yth][box.xth] = 0
             self.selected_box = None
         else:
             print 'fail'
             self.selected_box.unSelect()
             self.selected_box = box
Ejemplo n.º 20
0
 def onClick(self, sender, evt):
     x = DOM.eventGetClientX(evt)-DOM.getAbsoluteLeft(self.getElement())
     y = DOM.eventGetClientY(evt)-DOM.getAbsoluteTop(self.getElement())
     xth = int(x/uwidth)
     yth = int(y/uheight)
     box = self.map[yth][xth]
     if not box:
         return
     box.toggleSelect()
     if not box.selected:
         self.selected_box = None
     elif self.selected_box==None:
         self.selected_box = box
     elif box.img != self.selected_box.img:
         # change selection
         self.selected_box.unSelect()
         self.selected_box = box
     else:
         sbox = self.selected_box
         print 'check'
         result = False
         if box.xth<sbox.xth:
             print (box.yth,box.xth), (sbox.yth,sbox.xth)
             result = checkllk(self.map, (box.yth,box.xth), (sbox.yth,sbox.xth))
         else:
             print (sbox.yth,sbox.xth), (box.yth,box.xth)
             result = checkllk(self.map, (sbox.yth,sbox.xth), (box.yth,box.xth))
         if result:
             print 'path:', result
             sbox.dead()
             self.map[sbox.yth][sbox.xth] = 0
             box.dead()
             self.map[box.yth][box.xth] = 0
             self.selected_box = None
         else:
             print 'fail'
             self.selected_box.unSelect()
             self.selected_box = box
Ejemplo n.º 21
0
 def onCanvasMouseup(self,obj,event):
     x = DOM.eventGetClientX(event) - DOM.getAbsoluteLeft(self.canvas.getElement())
     y = DOM.eventGetClientY(event) - DOM.getAbsoluteTop(self.canvas.getElement())
     self.set_status('Mousemove on Canvas at '+str(x)+', '+str(y))
Ejemplo n.º 22
0
    def onClick(self, sender, event):

        # work out the relative position of cursor
        mouse_y = DOM.eventGetClientY(event) - \
                   DOM.getAbsoluteTop(sender.getElement())
        self.moveSlider(mouse_y)
Ejemplo n.º 23
0
 def onElementDblClick(self,sender,event):
     x = DOM.eventGetClientX(event) - DOM.getAbsoluteLeft(self.canvas.getElement())
     y = DOM.eventGetClientY(event) - DOM.getAbsoluteTop(self.canvas.getElement())
     s = self.desc[self.elements.index(sender)]
     self.set_status('Doubleclick on Element '+s+' at '+str(x)+', '+str(y))
     DOM.eventCancelBubble(event,True)
Ejemplo n.º 24
0
 def onCanvasContextmenu(self, sender,event):
     x = DOM.eventGetClientX(event) - DOM.getAbsoluteLeft(self.canvas.getElement())
     y = DOM.eventGetClientY(event) - DOM.getAbsoluteTop(self.canvas.getElement())
     self.set_status('Contextmenue on Canvas at '+str(x)+', '+str(y))
     DOM.eventPreventDefault(event)
Ejemplo n.º 25
0
 def onCanvasDblClick(self,sender,event):
     x = DOM.eventGetClientX(event) - DOM.getAbsoluteLeft(self.canvas.getElement())
     y = DOM.eventGetClientY(event) - DOM.getAbsoluteTop(self.canvas.getElement())
     self.set_status('Doubleclick on Canvas at '+str(x)+', '+str(y))
Ejemplo n.º 26
0
 def onElementMousemove(self, sender, event):
     x = DOM.eventGetClientX(event) - DOM.getAbsoluteLeft(self.canvas.getElement())
     y = DOM.eventGetClientY(event) - DOM.getAbsoluteTop(self.canvas.getElement())
     s = self.desc[self.elements.index(sender)]
     self.set_status("Mousemove on Element " + s + " at " + str(x) + ", " + str(y))
     DOM.eventCancelBubble(event, True)
Ejemplo n.º 27
0
 def onCanvasMousedown(self, sender, event):
     x = DOM.eventGetClientX(event) - DOM.getAbsoluteLeft(self.canvas.getElement())
     y = DOM.eventGetClientY(event) - DOM.getAbsoluteTop(self.canvas.getElement())
     self.set_status("Mousedown on Canvas at " + str(x) + ", " + str(y))
Ejemplo n.º 28
0
 def onCanvasDblClick(self, sender, event):
     x = DOM.eventGetClientX(event) - DOM.getAbsoluteLeft(
         self.canvas.getElement())
     y = DOM.eventGetClientY(event) - DOM.getAbsoluteTop(
         self.canvas.getElement())
     self.set_status('Doubleclick on Canvas at ' + str(x) + ', ' + str(y))
Ejemplo n.º 29
0
 def onCanvasMousedown(self, sender, event):
     x = DOM.eventGetClientX(event) - DOM.getAbsoluteLeft(
         self.canvas.getElement())
     y = DOM.eventGetClientY(event) - DOM.getAbsoluteTop(
         self.canvas.getElement())
     self.set_status('Mousedown on Canvas at ' + str(x) + ', ' + str(y))