Browse Source

added some drag and drop functionality

unifiedWindowUI
rra 4 years ago
parent
commit
608b06889b
  1. 6
      dropship.glade
  2. 36
      dropship.py

6
dropship.glade

@ -16,13 +16,13 @@
<object class="GtkStackSwitcher"> <object class="GtkStackSwitcher">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="stack">mainStack</property> <property name="stack">sendReceiveStack</property>
</object> </object>
</child> </child>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkStack" id="mainStack"> <object class="GtkStack" id="sendReceiveStack">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child> <child>
@ -40,7 +40,7 @@
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="homogeneous">True</property> <property name="homogeneous">True</property>
<child> <child>
<object class="GtkLabel"> <object class="GtkLabel" id="dropLabel">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="label" translatable="yes">Drag a file to send</property> <property name="label" translatable="yes">Drag a file to send</property>

36
dropship.py

@ -6,10 +6,7 @@ from gi.repository import Gtk, GLib, Gdk
class Main: class Main:
def __init__(self): def __init__(self):
self.timer = None
self.event = None
self.timer_running = False
# Connect to the Glade file # Connect to the Glade file
self.builder = Gtk.Builder() self.builder = Gtk.Builder()
self.builder.add_from_file('dropship.glade') self.builder.add_from_file('dropship.glade')
@ -25,7 +22,36 @@ class Main:
window.connect('delete-event', Gtk.main_quit) window.connect('delete-event', Gtk.main_quit)
window.show() 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__': if __name__ == '__main__':
main = Main() main = Main()

Loading…
Cancel
Save