Run formatter and specify Gdk version

This commit is contained in:
Luke Murphy 2020-07-22 16:03:55 +02:00
parent 7b0d0fd416
commit 93c88a5a2c
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC

View File

@ -1,58 +1,62 @@
import gi import gi
gi.require_version("Gtk", "3.0") gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, GLib, Gdk gi.require_version("Gdk", "3.0")
from gi.repository import Gdk, GLib, Gtk
class Main: class Main:
def __init__(self): def __init__(self):
# 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")
self.builder.connect_signals(self) self.builder.connect_signals(self)
# Connect to the Stylesheet # Connect to the Stylesheet
screen = Gdk.Screen.get_default() screen = Gdk.Screen.get_default()
provider = Gtk.CssProvider() provider = Gtk.CssProvider()
provider.load_from_path("./dropship.css") provider.load_from_path("./dropship.css")
Gtk.StyleContext.add_provider_for_screen(screen, provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) Gtk.StyleContext.add_provider_for_screen(
screen, provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
)
window = self.builder.get_object("mainWindow") window = self.builder.get_object("mainWindow")
window.connect('delete-event', Gtk.main_quit) window.connect("delete-event", Gtk.main_quit)
window.show() window.show()
#self.stack = self.builder.get_object("sendReceiveStack") # self.stack = self.builder.get_object("sendReceiveStack")
# Initiate the drag and drop area # Initiate the drag and drop area
# https://python-gtk-3-tutorial.readthedocs.io/en/latest/drag_and_drop.html # https://python-gtk-3-tutorial.readthedocs.io/en/latest/drag_and_drop.html
self.files_to_send = '' self.files_to_send = ""
# todo check the target flags, https://lazka.github.io/pgi-docs/Gtk-3.0/flags.html#Gtk.TargetFlags # 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) enforce_target = Gtk.TargetEntry.new("text/plain", Gtk.TargetFlags(4), 129)
self.dropBox = self.builder.get_object('dropBox') self.dropBox = self.builder.get_object("dropBox")
self.dropBox.drag_dest_set(Gtk.DestDefaults.ALL, [enforce_target], Gdk.DragAction.COPY) self.dropBox.drag_dest_set(
self.dropBox.connect('drag-data-received', self.onDrop) Gtk.DestDefaults.ALL, [enforce_target], Gdk.DragAction.COPY
self.dropLabel = self.builder.get_object('dropLabel') )
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): def onDrop(self, widget, drag_context, x, y, data, info, time):
print(drag_context, x,y,data,info,time) print(drag_context, x, y, data, info, time)
files = data.get_text().split() files = data.get_text().split()
if len(files) == 1: if len(files) == 1:
print(files) print(files)
self.dropLabel.set_text('Sending..') self.dropLabel.set_text("Sending..")
elif len(files) > 1: elif len(files) > 1:
print('multiple files!') print("multiple files!")
print(files) print(files)
self.dropLabel.set_text('\n'.join(files)) self.dropLabel.set_text("\n".join(files))
self.files_to_send = files self.files_to_send = files
if __name__ == "__main__":
if __name__ == '__main__':
main = Main() main = Main()
Gtk.main() Gtk.main()