File: trDragDrop.py

package info (click to toggle)
pythoncard 0.8.2-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 8,452 kB
  • sloc: python: 56,787; makefile: 56; sh: 22
file content (51 lines) | stat: -rw-r--r-- 1,303 bytes parent folder | download | duplicates (4)
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
import wx

class trURLDropTarget(wx.PyDropTarget):
    def __init__(self, trWindow):
        wx.PyDropTarget.__init__(self)
        self.trWin = trWindow

        self.data = wx.URLDataObject();
        self.SetDataObject(self.data)

    def OnDragOver(self, x, y, d):
        return wx.DragLink

    def OnData(self, x, y, d):
        if not self.GetData():
            return wx.DragNone

        text  = self.data.GetURL()
        
        if text.count("\n") == 0 and text.find("://") != -1:
            text = "<a href=\"" + text + "\"></a>"
        
        self.trWin.updateTextBox(text, "insert")

        return d


class trTextDropTarget(wx.PyDropTarget):
    def __init__(self, trWindow):
        wx.PyDropTarget.__init__(self)
        self.do = wx.TextDataObject()
        self.SetDataObject(self.do)
        self.trWin = trWindow

    def OnEnter(self, x, y, d):
        #print "OnEnter: %d, %d, %d" % (x, y, d)
        return wx.DragCopy

    #def OnLeave(self):
        #print "OnLeave"

    def OnDrop(self, x, y):
        #print "OnDrop: %d %d" % (x, y)
        return true

    def OnData(self, x, y, d):
        #print "OnData: %d, %d, %d" % (x, y, d)
        self.GetData()
        #print "%s" % self.do.GetText()
        self.trWin.updateTextBox(self.do.GetText())
        return d