added some drag and drop functionality
This commit is contained in:
parent
9854f12f43
commit
608b06889b
@ -16,13 +16,13 @@
|
||||
<object class="GtkStackSwitcher">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="stack">mainStack</property>
|
||||
<property name="stack">sendReceiveStack</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkStack" id="mainStack">
|
||||
<object class="GtkStack" id="sendReceiveStack">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
@ -40,7 +40,7 @@
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="homogeneous">True</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<object class="GtkLabel" id="dropLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Drag a file to send</property>
|
||||
|
36
dropship.py
36
dropship.py
@ -6,10 +6,7 @@ from gi.repository import Gtk, GLib, Gdk
|
||||
|
||||
class Main:
|
||||
def __init__(self):
|
||||
self.timer = None
|
||||
self.event = None
|
||||
self.timer_running = False
|
||||
|
||||
|
||||
# Connect to the Glade file
|
||||
self.builder = Gtk.Builder()
|
||||
self.builder.add_from_file('dropship.glade')
|
||||
@ -25,7 +22,36 @@ class Main:
|
||||
window.connect('delete-event', Gtk.main_quit)
|
||||
window.show()
|
||||
|
||||
#self.stack = self.builder.get_object("mainStack")
|
||||
#self.stack = self.builder.get_object("sendReceiveStack")
|
||||
|
||||
# Initiate the drag and drop area
|
||||
# https://python-gtk-3-tutorial.readthedocs.io/en/latest/drag_and_drop.html
|
||||
self.files_to_send = ''
|
||||
|
||||
# todo check the target flags, https://lazka.github.io/pgi-docs/Gtk-3.0/flags.html#Gtk.TargetFlags
|
||||
enforce_target = Gtk.TargetEntry.new('text/plain', Gtk.TargetFlags(4), 129)
|
||||
|
||||
self.dropBox = self.builder.get_object('dropBox')
|
||||
self.dropBox.drag_dest_set(Gtk.DestDefaults.ALL, [enforce_target], Gdk.DragAction.COPY)
|
||||
self.dropBox.connect('drag-data-received', self.onDrop)
|
||||
self.dropLabel = self.builder.get_object('dropLabel')
|
||||
|
||||
def onDrop(self,widget, drag_context, x, y, data, info, time):
|
||||
print(drag_context, x,y,data,info,time)
|
||||
files = data.get_text().split()
|
||||
|
||||
if len(files) == 1:
|
||||
print(files)
|
||||
self.dropLabel.set_text('Sending..')
|
||||
elif len(files) > 1:
|
||||
print('multiple files!')
|
||||
print(files)
|
||||
self.dropLabel.set_text('\n'.join(files))
|
||||
|
||||
self.files_to_send = files
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main = Main()
|
||||
|
Loading…
Reference in New Issue
Block a user