Merge branch 'pendingUI' into main

This commit is contained in:
Luke Murphy 2020-10-11 11:42:06 +02:00
commit 206c7f2455
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
5 changed files with 333 additions and 172 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<!-- Generated with glade 3.36.0 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkApplicationWindow" id="mainWindow">
@ -7,21 +7,6 @@
<property name="resizable">False</property>
<property name="default_width">250</property>
<property name="default_height">250</property>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="show_close_button">True</property>
<child>
<object class="GtkStackSwitcher">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">10</property>
<property name="stack">sendReceiveStack</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkStack" id="sendReceiveStack">
<property name="visible">True</property>
@ -111,17 +96,28 @@
</packing>
</child>
<child>
<object class="GtkBox">
<object class="GtkBox" id="pendingBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">16</property>
<property name="margin_right">16</property>
<property name="margin_start">16</property>
<property name="margin_end">16</property>
<property name="margin_top">16</property>
<property name="margin_bottom">16</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>
<object class="GtkListBox" id="pendingTransfersList">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<style>
<class name=".pendingArea"/>
</style>
</object>
<packing>
<property name="name">Pending</property>
@ -131,6 +127,21 @@
</child>
</object>
</child>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="show_close_button">True</property>
<child>
<object class="GtkStackSwitcher">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">10</property>
<property name="stack">sendReceiveStack</property>
</object>
</child>
</object>
</child>
</object>
<object class="GtkFileChooserDialog" id="filePicker">
<property name="can_focus">False</property>
@ -139,9 +150,6 @@
<property name="transient_for">mainWindow</property>
<property name="has_resize_grip">True</property>
<property name="select_multiple">True</property>
<child type="titlebar">
<placeholder/>
</child>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can_focus">False</property>
@ -169,5 +177,8 @@
</child>
</object>
</child>
<child type="titlebar">
<placeholder/>
</child>
</object>
</interface>

View File

@ -12,9 +12,11 @@ import trio_gtk
gi.require_version("Gtk", "3.0")
gi.require_version("Gdk", "3.0")
from gi.repository import Gdk as gdk
from gi.repository import GLib as glib
from gi.repository import Gtk as gtk
from gi.repository import Gdk
from gi.repository import GLib
from gi.repository import Gtk
from ui_templates import pendingTransferRow
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
@ -30,7 +32,7 @@ class DropShip:
self.CSS_FILE = "dropship.css"
self.DOWNLOAD_DIR = os.path.expanduser("~")
self.clipboard = gtk.Clipboard.get(gdk.SELECTION_CLIPBOARD)
self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
self.nursery = nursery
self.init_glade()
@ -40,42 +42,39 @@ class DropShip:
def init_glade(self):
"""Initialise the GUI from Glade file."""
self.builder = gtk.Builder()
self.builder = Gtk.Builder()
self.builder.add_from_file(self.GLADE_FILE)
self.builder.connect_signals(self)
def init_css(self):
"""Initialise CSS injection."""
self.screen = gdk.Screen.get_default()
self.provider = gtk.CssProvider()
self.screen = Gdk.Screen.get_default()
self.provider = Gtk.CssProvider()
self.provider.load_from_path(self.CSS_FILE)
gtk.StyleContext.add_provider_for_screen(
self.screen, self.provider, gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
Gtk.StyleContext.add_provider_for_screen(
self.screen, self.provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
)
def init_window(self):
"""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", gtk.main_quit)
self.window.connect("delete-event", Gtk.main_quit)
self.window.show()
def init_ui_elements(self):
"""Initialize the UI elements."""
# TODO (rra) find out how to use composite templates
# https://github.com/sebp/PyGObject-Tutorial/issues/149
# Send UI
# Drag & Drop Box
self.files_to_send = ""
self.enforce_target = gtk.TargetEntry.new(
"text/uri-list", gtk.TargetFlags(4), 129
self.enforce_target = Gtk.TargetEntry.new(
"text/uri-list", Gtk.TargetFlags(4), 129
)
self.drop_box = self.builder.get_object("dropBox")
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_label = self.builder.get_object("dropLabel")
@ -84,7 +83,7 @@ class DropShip:
# File chooser
self.file_chooser = self.builder.get_object("filePicker")
self.file_chooser.add_buttons(
"Cancel", gtk.ResponseType.CANCEL, "Add", gtk.ResponseType.OK
"Cancel", Gtk.ResponseType.CANCEL, "Add", Gtk.ResponseType.OK
)
# Receive UI
@ -92,13 +91,25 @@ class DropShip:
self.recv_box = self.builder.get_object("receiveBoxCodeEntry")
self.recv_box.connect("activate", self.on_recv)
# Pending Transfers UI
self.pending_transfers_list = self.builder.get_object("pendingTransfersList")
self.transfer_code = ''
def on_drop(self, widget, drag_context, x, y, data, info, time):
"""Handler for file dropping."""
files = data.get_uris()
self.files_to_send = files
if len(files) == 1:
fpath = files[0].replace("file://", "")
# TODO Luke can u make a callback that spawns pendingTransmissions after we got a code?
self.nursery.start_soon(self.wormhole_send, fpath)
# TODO Roel/Luke, move this somewhere logical in its own function?
status = pendingTransferRow(self, fpath.split('/')[-1], self.transfer_code)
# TODO Roel, find out how to add to a listbox
self.pending_transfers_list.insert(status,-1) #-1 is add at bottom
else:
log.info("Multiple file sending coming soon ™")
@ -109,7 +120,7 @@ class DropShip:
def add_files(self, widget, event):
"""Handler for adding files with system interface"""
response = self.file_chooser.run()
if response == gtk.ResponseType.OK:
if response == Gtk.ResponseType.OK:
fpath = self.file_chooser.get_filenames()[0]
self.nursery.start_soon(self.wormhole_send, fpath)
self.file_chooser.hide()
@ -129,6 +140,9 @@ class DropShip:
output = await process.stderr.receive_some()
code = output.decode().split()[-1]
self.clipboard.set_text(code, -1)
self.transfer_code = code
self.drop_label.set_text(code)
self.drop_label.set_visible(True)
self.drop_label.set_selectable(True)
@ -144,7 +158,6 @@ class DropShip:
command = ["wormhole", "receive", "--accept-file", code]
await trio.run_process(command, stderr=PIPE)
async def main():
"""Trio main entrypoint."""
async with trio.open_nursery() as nursery:

227
pendingTransferRow.ui Normal file
View File

@ -0,0 +1,227 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.36.0 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-no</property>
<property name="icon_size">3</property>
</object>
<object class="GtkListBoxRow" id="pendingTransferRow">
<property name="width_request">100</property>
<property name="height_request">80</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="activatable">False</property>
<property name="selectable">False</property>
<child>
<object class="GtkBox">
<property name="name">pendingTransmission</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">start</property>
<property name="hexpand">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_bottom">2</property>
<property name="hexpand">True</property>
<child>
<object class="GtkStack" id="transferStatusStack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">6</property>
<property name="margin_right">12</property>
<property name="margin_start">6</property>
<property name="margin_end">12</property>
<child>
<object class="GtkImage">
<property name="width_request">30</property>
<property name="height_request">30</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">network-transmit</property>
<property name="icon_size">5</property>
</object>
<packing>
<property name="name">page0</property>
<property name="title" translatable="yes">page0</property>
</packing>
</child>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">dialog-ok</property>
<property name="icon_size">5</property>
</object>
<packing>
<property name="name">page1</property>
<property name="title" translatable="yes">page1</property>
<property name="position">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">6</property>
<property name="margin_bottom">6</property>
<property name="hexpand">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="fileNameLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">screenshot_lkashdflasjdjasödjlkasjdlaskdlkashd01-292.jpg</property>
<property name="ellipsize">middle</property>
<property name="max_width_chars">20</property>
<property name="track_visited_links">False</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="fileNameMetadata">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">336 KB</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="transferCodeButton">
<property name="label" translatable="yes">5-courier-happening</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">center</property>
<property name="margin_top">6</property>
<signal name="clicked" handler="copy_transfer_code" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkStack" id="statusButtonsStack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">12</property>
<property name="margin_right">6</property>
<property name="margin_start">12</property>
<property name="margin_end">6</property>
<property name="hhomogeneous">False</property>
<property name="transition_type">crossfade</property>
<child>
<object class="GtkButton" id="cancelTransfer">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="margin_top">16</property>
<property name="margin_bottom">16</property>
<property name="image">image1</property>
<signal name="clicked" handler="cancel_transfer" swapped="no"/>
<style>
<class name="circular"/>
</style>
</object>
<packing>
<property name="name">page0</property>
<property name="title" translatable="yes">page0</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">button</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="margin_top">16</property>
<property name="margin_bottom">16</property>
</object>
<packing>
<property name="name">page1</property>
<property name="title" translatable="yes">page1</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSeparator">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

View File

@ -1,130 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<template class="PendingTransmission" parent="GtkBox">
<property name="name">pendingTransmission</property>
<property name="can_focus">False</property>
<property name="decorated">False</property>
<child type="titlebar">
<placeholder/>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkImage">
<property name="width_request">50</property>
<property name="height_request">50</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-network</property>
<property name="icon_size">6</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">6</property>
<property name="margin_bottom">6</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="fileNameLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">screenshot_01-292.jpg</property>
<property name="ellipsize">end</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="1.2"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="fileNameMetadata">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">336 KB</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="transmissionCodeButton">
<property name="label" translatable="yes">5-courier-happening</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">center</property>
<property name="margin_top">6</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="cancelTransmission">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="margin_top">16</property>
<property name="margin_bottom">16</property>
<property name="image">image1</property>
<style>
<class name="circular"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</template>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-no</property>
<property name="icon_size">3</property>
</object>
</interface>

40
ui_templates.py Normal file
View File

@ -0,0 +1,40 @@
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GLib, Gdk
@Gtk.Template.from_file('pendingTransferRow.ui')
class pendingTransferRow(Gtk.ListBoxRow):
__gtype_name__ = 'PendingTransferRow'
fileNameLabel = Gtk.Template.Child()
fileNameMetadata = Gtk.Template.Child()
transferCodeButton = Gtk.Template.Child()
cancelTransfer = Gtk.Template.Child()
def __init__(self, parent, fileName, transferCode):
super(Gtk.ListBoxRow, self).__init__()
self.init_template()
self.fileNameLabel.set_text(fileName)
self.transferCodeButton.set_label(transferCode)
@Gtk.Template.Callback()
def copy_transfer_code(self,widget):
'''
what to do when we press the button:
copy the code again to clipboard
'''
print('click')
code = widget.get_label()
clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
clipboard.set_text(code, -1) #-1 is auto-size
@Gtk.Template.Callback()
def cancel_transfer(self,widget):
'''
cancel the transfer
destroy thread
remove the object from the list
'''
print('poof!')