SVGHMI: Add file type drag'n'drop to widget picker, for now drops widget's original SVG. svghmi
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Wed, 31 Mar 2021 08:25:18 +0200
branchsvghmi
changeset 3213 afef7011f475
parent 3212 2b5b3f4f26f0
child 3214 bb314cdfc656
SVGHMI: Add file type drag'n'drop to widget picker, for now drops widget's original SVG.
svghmi/ui.py
--- a/svghmi/ui.py	Tue Mar 30 14:56:04 2021 +0200
+++ b/svghmi/ui.py	Wed Mar 31 08:25:18 2021 +0200
@@ -150,6 +150,7 @@
         sizer.Fit(self)
         self.Bind(wx.EVT_BUTTON, self.OnSelectLibDir, self.libbutton)
         self.preview.Bind(wx.EVT_PAINT, self.OnPaint)
+        self.preview.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
 
         self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnWidgetSelection, self.widgetpicker)
 
@@ -272,6 +273,16 @@
         self.ValidateWidget()
         self.Refresh()
 
+    def OnLeftDown(self, evt):
+        if self.selected_SVG is not None:
+            # TODO replace with generated widget file
+            filename = self.selected_SVG
+            data = wx.FileDataObject()
+            data.AddFile(filename)
+            dropSource = wx.DropSource(self)
+            dropSource.SetData(data)
+            dropSource.DoDragDrop(wx.Drag_AllowMove)
+
     def ValidateWidget(self):
         if self.selected_SVG is not None:
             if self.hmitree_node is not None: