]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/wxPIA_book/Chapter-18/drop_source.py
3 class DragController(wx
.Control
):
5 Just a little control to handle dragging the text from a text
6 control. We use a separate control so as to not interfere with
7 the native drag-select functionality of the native text control.
9 def __init__(self
, parent
, source
, size
=(25,25)):
10 wx
.Control
.__init
__(self
, parent
, -1, size
=size
,
11 style
=wx
.SIMPLE_BORDER
)
14 self
.Bind(wx
.EVT_PAINT
, self
.OnPaint
)
15 self
.Bind(wx
.EVT_LEFT_DOWN
, self
.OnLeftDown
)
17 def OnPaint(self
, evt
):
19 dc
= wx
.BufferedPaintDC(self
)
20 dc
.SetBackground(wx
.Brush(self
.GetBackgroundColour()))
24 dc
.SetPen(wx
.Pen("dark blue", 2))
25 dc
.DrawLine(w
/8, y
, w
-w
/8, y
)
26 dc
.DrawLine(w
-w
/8, y
, w
/2, h
/4)
27 dc
.DrawLine(w
-w
/8, y
, w
/2, 3*h
/4)
29 def OnLeftDown(self
, evt
):
30 text
= self
.source
.GetValue()
31 data
= wx
.TextDataObject(text
)
32 dropSource
= wx
.DropSource(self
)
33 dropSource
.SetData(data
)
34 result
= dropSource
.DoDragDrop(wx
.Drag_AllowMove
)
36 # if the user wants to move the data then we should delete it
38 if result
== wx
.DragMove
:
39 self
.source
.SetValue("")
41 class MyFrame(wx
.Frame
):
43 wx
.Frame
.__init
__(self
, None, title
="Drop Source")
47 label1
= wx
.StaticText(p
, -1, "Put some text in this control:")
48 label2
= wx
.StaticText(p
, -1,
49 "Then drag from the neighboring bitmap and\n"
50 "drop in an application that accepts dropped\n"
51 "text, such as MS Word.")
52 text
= wx
.TextCtrl(p
, -1, "Some text")
53 dragctl
= DragController(p
, text
)
55 # setup the layout with sizers
56 sizer
= wx
.BoxSizer(wx
.VERTICAL
)
57 sizer
.Add(label1
, 0, wx
.ALL
, 5)
58 hrow
= wx
.BoxSizer(wx
.HORIZONTAL
)
59 hrow
.Add(text
, 1, wx
.RIGHT
, 5)
61 sizer
.Add(hrow
, 0, wx
.EXPAND|wx
.ALL
, 5)
62 sizer
.Add(label2
, 0, wx
.ALL
, 5)
67 app
= wx
.PySimpleApp()