added file chooser UI, changed the gtk.TargetEntry on D&D to uri-list and put all UI init in one function..
This commit is contained in:
parent
3d655490b8
commit
9bac67b52b
@ -2,6 +2,42 @@
|
|||||||
<!-- Generated with glade 3.36.0 -->
|
<!-- Generated with glade 3.36.0 -->
|
||||||
<interface>
|
<interface>
|
||||||
<requires lib="gtk+" version="3.20"/>
|
<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">
|
<object class="GtkApplicationWindow" id="mainWindow">
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="resizable">False</property>
|
<property name="resizable">False</property>
|
||||||
@ -12,11 +48,12 @@
|
|||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkEventBox">
|
<object class="GtkEventBox" id="dropBox">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
|
<signal name="button-press-event" handler="add_files" swapped="no"/>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox" id="dropBox">
|
<object class="GtkBox">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="margin_left">16</property>
|
<property name="margin_left">16</property>
|
||||||
|
50
dropship.py
50
dropship.py
@ -50,8 +50,7 @@ class DropShip:
|
|||||||
|
|
||||||
self.init_glade()
|
self.init_glade()
|
||||||
self.init_css()
|
self.init_css()
|
||||||
self.init_drop_box()
|
self.init_ui_elements()
|
||||||
self.init_recv_box()
|
|
||||||
self.init_window()
|
self.init_window()
|
||||||
|
|
||||||
def init_glade(self):
|
def init_glade(self):
|
||||||
@ -70,39 +69,42 @@ class DropShip:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def init_window(self):
|
def init_window(self):
|
||||||
"""Initialise the GUI window."""
|
"""Initialise the Main GUI window."""
|
||||||
self.main_window_id = "mainWindow"
|
self.main_window_id = "mainWindow"
|
||||||
self.window = self.builder.get_object(self.main_window_id)
|
self.window = self.builder.get_object(self.main_window_id)
|
||||||
self.window.connect("delete-event", self.on_quit)
|
self.window.connect("delete-event", self.on_quit)
|
||||||
self.window.show()
|
self.window.show()
|
||||||
|
|
||||||
def init_drop_box(self):
|
def init_ui_elements(self):
|
||||||
"""Initialise the drag & drop box."""
|
"""Initialize the UI elements."""
|
||||||
|
|
||||||
|
# Send UI
|
||||||
|
# Drag & Drop Box
|
||||||
self.files_to_send = ""
|
self.files_to_send = ""
|
||||||
|
self.enforce_target = gtk.TargetEntry.new("text/uri-list", gtk.TargetFlags(4), 129)
|
||||||
|
|
||||||
# TODO(rra): check the target flags
|
self.drop_box = self.builder.get_object('dropBox')
|
||||||
# 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)
|
|
||||||
|
|
||||||
self.drop_box_id = "dropBox"
|
|
||||||
self.drop_box_label = "dropLabel"
|
|
||||||
|
|
||||||
self.drop_box = self.builder.get_object(self.drop_box_id)
|
|
||||||
self.drop_box.drag_dest_set(
|
self.drop_box.drag_dest_set(
|
||||||
gtk.DestDefaults.ALL, [self.enforce_target], gdk.DragAction.COPY
|
gtk.DestDefaults.ALL, [self.enforce_target], gdk.DragAction.COPY
|
||||||
)
|
)
|
||||||
self.drop_box.connect("drag-data-received", self.on_drop)
|
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):
|
# File chooser
|
||||||
"""Initialise the receive code box."""
|
self.file_chooser = self.builder.get_object('filePicker')
|
||||||
self.recv_box_id = "receiveBoxCodeEntry"
|
self.file_chooser.add_buttons(
|
||||||
self.recv_box = self.builder.get_object(self.recv_box_id)
|
'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)
|
self.recv_box.connect("activate", self.on_recv)
|
||||||
|
|
||||||
|
|
||||||
def on_drop(self, widget, drag_context, x, y, data, info, time):
|
def on_drop(self, widget, drag_context, x, y, data, info, time):
|
||||||
"""Handler for file dropping."""
|
"""Handler for file dropping."""
|
||||||
files = data.get_text().split()
|
files = data.get_uris()
|
||||||
self.files_to_send = files
|
self.files_to_send = files
|
||||||
if len(files) == 1:
|
if len(files) == 1:
|
||||||
fpath = Path(files[0].replace("file://", ""))
|
fpath = Path(files[0].replace("file://", ""))
|
||||||
@ -111,6 +113,16 @@ class DropShip:
|
|||||||
else:
|
else:
|
||||||
log.info("Multiple file sending coming soon ™")
|
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):
|
def on_recv(self, entry):
|
||||||
"""Handler for receiving transfers."""
|
"""Handler for receiving transfers."""
|
||||||
code = entry.get_text()
|
code = entry.get_text()
|
||||||
|
Loading…
Reference in New Issue
Block a user