/usr/share/pyshared/libavg/draggable.py is in python-libavg 1.7.1-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
# libavg - Media Playback Engine.
# Copyright (C) 2003-2011 Ulrich von Zadow
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Current versions can be found at www.libavg.de
#
g_Player = None
from libavg import avg
class Draggable:
def __init__(self, node, onDragStart=None, onDragEnd=None, onDragMove=None):
global g_Player
g_Player = avg.Player.get()
self.__node = node
self.__onDragStart = onDragStart
self.__onDragEnd = onDragEnd
self.__onDragMove = onDragMove
self.__isDragging = False
def enable(self):
self.__node.setEventHandler(avg.CURSORDOWN, avg.MOUSE | avg.TOUCH, self.__onStart)
def disable(self):
if self.__isDragging:
self.__stop()
self.__node.setEventHandler(avg.CURSORDOWN, avg.MOUSE | avg.TOUCH, None)
self.__node.setEventHandler(avg.CURSORMOTION, avg.MOUSE | avg.TOUCH, None)
self.__node.setEventHandler(avg.CURSORUP, avg.MOUSE | avg.TOUCH, None)
def startDrag(self, event):
self.__onStart(event)
def isDragging(self):
return self.__isDragging
def __onStart(self, event):
self.__cursorID = event.cursorid
self.__isDragging = True
self.__lastDownPos = event.pos
groupsNode = self.__node.getParent()
groupsNode.reorderChild(groupsNode.indexOf(self.__node),
groupsNode.getNumChildren()-1)
self.__node.setEventCapture(event.cursorid)
self.__node.setEventHandler(avg.CURSORDOWN, avg.MOUSE | avg.TOUCH, None)
self.__node.setEventHandler(avg.CURSORMOTION, avg.MOUSE | avg.TOUCH,
self.__onMove)
self.__node.setEventHandler(avg.CURSORUP, avg.MOUSE | avg.TOUCH, self.__onStop)
stopBubble = False
if self.__onDragStart:
stopBubble = self.__onDragStart(event)
if stopBubble == None:
stopBubble = False
self.__startDragPos = self.__node.pos
return stopBubble
def __onMove(self, event):
if event.cursorid == self.__cursorID:
self.__node.pos = (self.__startDragPos[0]+event.x-self.__lastDownPos[0],
self.__startDragPos[1]+event.y-self.__lastDownPos[1])
stopBubble = False
if self.__onDragMove:
stopBubble = self.__onDragMove(event)
if stopBubble == None:
stopBubble = False
return stopBubble
def __onStop(self, event):
if event.cursorid == self.__cursorID:
self.__onMove(event)
self.__stop()
stopBubble = False
if self.__onDragEnd:
stopBubble = self.__onDragEnd(event)
if stopBubble == None:
stopBubble = False
return stopBubble
def __stop(self):
self.__isDragging = False
self.__node.setEventHandler(avg.CURSORDOWN, avg.MOUSE | avg.TOUCH, self.__onStart)
self.__node.setEventHandler(avg.CURSORMOTION, avg.MOUSE | avg.TOUCH, None)
self.__node.setEventHandler(avg.CURSORUP, avg.MOUSE | avg.TOUCH, None)
self.__node.releaseEventCapture(self.__cursorID)
def init(g_avg):
global avg
avg = g_avg
|