Browse Source

added file chooser UI, changed the gtk.TargetEntry on D&D to uri-list and put all UI init in one function..

unifiedWindowUI
rra 4 years ago
parent
commit
9bac67b52b
  1. 41
      dropship.glade
  2. 50
      dropship.py

41
dropship.glade

@ -2,6 +2,42 @@
<!-- Generated with glade 3.36.0 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkFileChooserDialog" id="filePicker">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Choose files to ship</property>
<property name="type_hint">dialog</property>
<property name="select_multiple">True</property>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
<child type="titlebar">
<placeholder/>
</child>
</object>
<object class="GtkApplicationWindow" id="mainWindow">
<property name="can_focus">False</property>
<property name="resizable">False</property>
@ -12,11 +48,12 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkEventBox">
<object class="GtkEventBox" id="dropBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="button-press-event" handler="add_files" swapped="no"/>
<child>
<object class="GtkBox" id="dropBox">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">16</property>

50
dropship.py

@ -50,8 +50,7 @@ class DropShip:
self.init_glade()
self.init_css()
self.init_drop_box()
self.init_recv_box()
self.init_ui_elements()
self.init_window()
def init_glade(self):
@ -70,39 +69,42 @@ class DropShip:
)
def init_window(self):
"""Initialise the GUI window."""
"""Initialise the Main GUI window."""
self.main_window_id = "mainWindow"
self.window = self.builder.get_object(self.main_window_id)
self.window.connect("delete-event", self.on_quit)
self.window.show()
def init_drop_box(self):
"""Initialise the drag & drop box."""
self.files_to_send = ""
# TODO(rra): check the target flags
# https://lazka.github.io/pgi-docs/Gtk-3.0/flags.html#Gtk.TargetFlags
self.enforce_target = gtk.TargetEntry.new("text/plain", gtk.TargetFlags(4), 129)
def init_ui_elements(self):
"""Initialize the UI elements."""
self.drop_box_id = "dropBox"
self.drop_box_label = "dropLabel"
# Send UI
# Drag & Drop Box
self.files_to_send = ""
self.enforce_target = gtk.TargetEntry.new("text/uri-list", gtk.TargetFlags(4), 129)
self.drop_box = self.builder.get_object(self.drop_box_id)
self.drop_box = self.builder.get_object('dropBox')
self.drop_box.drag_dest_set(
gtk.DestDefaults.ALL, [self.enforce_target], gdk.DragAction.COPY
)
self.drop_box.connect("drag-data-received", self.on_drop)
self.drop_label = self.builder.get_object(self.drop_box_label)
self.drop_label = self.builder.get_object('dropLabel')
def init_recv_box(self):
"""Initialise the receive code box."""
self.recv_box_id = "receiveBoxCodeEntry"
self.recv_box = self.builder.get_object(self.recv_box_id)
# File chooser
self.file_chooser = self.builder.get_object('filePicker')
self.file_chooser.add_buttons(
'Cancel', gtk.ResponseType.CANCEL, "Add", gtk.ResponseType.OK
)
# Receive UI
# Code entry box
self.recv_box = self.builder.get_object('receiveBoxCodeEntry')
self.recv_box.connect("activate", self.on_recv)
def on_drop(self, widget, drag_context, x, y, data, info, time):
"""Handler for file dropping."""
files = data.get_text().split()
files = data.get_uris()
self.files_to_send = files
if len(files) == 1:
fpath = Path(files[0].replace("file://", ""))
@ -111,6 +113,16 @@ class DropShip:
else:
log.info("Multiple file sending coming soon ™")
def add_files(self,widget, event):
"""Handler for adding files with system interface"""
response = self.file_chooser.run()
if response == gtk.ResponseType.OK:
self.schedule(self.wormhole_send(self, self.file_chooser.get_filenames()[0]))
elif response == gtk.ResponseType.CANCEL:
#TODO(roel) something isn't right here.. maybe we need to initialize it every time we run it.
print("Cancel clicked")
self.file_chooser.destroy()
def on_recv(self, entry):
"""Handler for receiving transfers."""
code = entry.get_text()

Loading…
Cancel
Save