Skip to content

Instantly share code, notes, and snippets.

@batok
Created June 2, 2009 16:00
Show Gist options
  • Save batok/122325 to your computer and use it in GitHub Desktop.
Save batok/122325 to your computer and use it in GitHub Desktop.
import wx
class GixDragController(wx.Control):
def __init__(self, parent, source, size=(25,25)):
wx.Control.__init__(self,parent, -1, size=size, style=wx.SIMPLE_BORDER)
self.source = source
self.SetMinSize(size)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
def OnPaint( self, evt):
dc = wx.BufferedPaintDC( self )
dc.SetBackground( wx.Brush(self.GetBackgroundColour()))
dc.Clear()
w, h = dc.GetSize()
y = h/2
dc.SetPen(wx.Pen("blue",3))
dc.DrawLine(w/8, y, w-w/8, y)
dc.DrawLine(w-w/8, y, w/2, h/4)
dc.DrawLine(w-w/8, y, w/2, 3*h/4)
def OnLeftDown( self, evt):
#text = self.source.GetValue()
text = self.GetData()
data = wx.TextDataObject(text)
dropSource = wx.DropSource(self)
dropSource.SetData(data)
result = dropSource.DoDragDrop(wx.Drag_AllowMove)
class PolizasDragController(GixDragController):
def __init__(self, parent, source, size=(25,25)):
GixDragController.__init__(self, parent, source, size)
def GetData( self ):
#extraer del arbol el valor de la cuenta
#por lo pronto lo hare con el textctrl del ejemplo
return self.source.GetValue()
class GixDropTarget(wx.DropTarget):
def __init__(self, window):
wx.DropTarget.__init__(self)
self.window = window
self.data = wx.TextDataObject()
self.SetDataObject(self.data)
def OnData(self, x,y, default):
self.GetData()
actual_data = self.data.GetText()
self.window.AppendText(actual_data)
return default
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title= "Drop Source")
p = wx.Panel(self)
label1 = wx.StaticText(p, -1, "Put some text in this control:")
label2 = wx.StaticText(p, -1 ,
"Then drag from the neighboring bitmap and \n"
"drop in an application that accepts dropped\n"
"text, such as MS Word.")
text = wx.TextCtrl(p, -1, "Some Text")
text.SetBackgroundColour(wx.Colour(155,255,153))
self.text = text
dragctl = PolizasDragController(p, text)
self.drag = dragctl
receiver = wx.TextCtrl(p, -1, " ", style=wx.TE_MULTILINE)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add( label1, 0, wx.ALL, 5)
hrow = wx.BoxSizer(wx.HORIZONTAL)
hrow.Add( text, 1, wx.RIGHT, 5)
hrow.Add( dragctl, 0)
sizer.Add(hrow , 0 , wx.EXPAND | wx.ALL, 5)
sizer.Add(label2, 0, wx.ALL, 5)
sizer.Add(receiver, 0, wx.ALL, 5)
#las siguientes dos se requieren para establecer la conexion de control de recepcion y clase heredera de wx.DropTarget
target = GixDropTarget(receiver)
receiver.SetDropTarget(target)
self.Bind(wx.EVT_TEXT, self.OnText, text)
p.SetSizer(sizer)
sizer.Fit(self)
def OnText(self,evt):
if self.text.GetValue().strip() != "":
self.drag.Enable(True)
else:
self.drag.Enable(False)
app = wx.PySimpleApp()
MyFrame().Show()
app.MainLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment