Browse Source

implement ui template, change librarynames gtk to Gtk etc

unifiedWindowUI
rra 4 years ago
parent
commit
ce89f0f463
  1. 66
      dropship.py

66
dropship.py

@ -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 pendingTransmissions
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
@ -96,16 +95,20 @@ class DropShip:
self.pending_box = self.builder.get_object("pendingBox")
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://", "")
status = pendingTransmissions(fpath, self.transfer_code)
self.pending_box.add(status, True, True, 0)
# 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 = pendingTransmissions(self, fpath.split('/')[-1], self.transfer_code)
self.pending_box.add(status)
else:
log.info("Multiple file sending coming soon ™")
@ -116,7 +119,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()
@ -134,9 +137,10 @@ class DropShip:
self.drop_spinner.start()
output = await process.stderr.receive_some()
self.transfer_code = output.decode().split()[-1]
code = output.decode().split()[-1]
self.transfer_code = code
self.drop_label.set_text(self.transfer_code)
self.drop_label.set_text(code)
self.drop_label.set_visible(True)
self.drop_label.set_selectable(True)
@ -151,24 +155,6 @@ class DropShip:
command = ["wormhole", "receive", "--accept-file", code]
await trio.run_process(command, stderr=PIPE)
@gtk.Template.from_file('pendingTransmissions.ui')
class pendingTransmissions(gtk.Box):
__gtype_name__ = 'PendingTransmission'
fileNameLabel = gtk.Template.Child('fileNameLabel')
fileNameMetadata = gtk.Template.Child('fileNameMetadata')
transmissionCodeButton = gtk.Template.Child('transmissionCodeButton')
cancelTransmission = gtk.Template.Child('cancelTransmission')
def __init__(self, widget, fileName, transferCode):
super(Gtk.Box, self).__init__()
self.init_template()
self.fileNameLabel.set_text(fileName)
self.transmissionCodeButton.set_label(transferCode)
async def main():
"""Trio main entrypoint."""
async with trio.open_nursery() as nursery:

Loading…
Cancel
Save