From 90fbf6ee6da0a3b17933fccfccd3e3921533a823 Mon Sep 17 00:00:00 2001 From: "B. Stack" Date: Thu, 21 Nov 2024 11:11:44 -0500 Subject: gtk: drag-and-drop works including from xfe --- example/foo.glade | 40 ----------------- example/foo.py | 132 ------------------------------------------------------ 2 files changed, 172 deletions(-) delete mode 100644 example/foo.glade delete mode 100644 example/foo.py (limited to 'example') diff --git a/example/foo.glade b/example/foo.glade deleted file mode 100644 index b29f92f..0000000 --- a/example/foo.glade +++ /dev/null @@ -1,40 +0,0 @@ - - - -
- Change label - - win.change_label - String 1 - String 1 - - - win.change_label - String 2 - String 2 - - - win.change_label - String 3 - String 3 - -
-
- - win.maximize - Maximize - -
-
- - app.about - _About - - - app.quit - _Quit - <Primary>q - -
-
-
diff --git a/example/foo.py b/example/foo.py deleted file mode 100644 index bfcac79..0000000 --- a/example/foo.py +++ /dev/null @@ -1,132 +0,0 @@ -import sys -import gi -gi.require_version("Gtk", "3.0") -from gi.repository import GLib, Gio, Gtk -# This would typically be its own file -MENU_XML = """ - - - -
- Change label - - win.change_label - String 1 - String 1 - - - win.change_label - String 2 - String 2 - - - win.change_label - String 3 - String 3 - -
-
- - win.maximize - Maximize - -
-
- - app.about - _About - - - app.quit - _Quit - <Primary>q - -
-
-
-""" -class AppWindow(Gtk.ApplicationWindow): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - # This will be in the windows group and have the "win" prefix - max_action = Gio.SimpleAction.new_stateful( - "maximize", None, GLib.Variant.new_boolean(False) - ) - max_action.connect("change-state", self.on_maximize_toggle) - self.add_action(max_action) - # Keep it in sync with the actual state - self.connect( - "notify::is-maximized", - lambda obj, pspec: max_action.set_state( - GLib.Variant.new_boolean(obj.props.is_maximized) - ), - ) - lbl_variant = GLib.Variant.new_string("String 1") - lbl_action = Gio.SimpleAction.new_stateful( - "change_label", lbl_variant.get_type(), lbl_variant - ) - lbl_action.connect("change-state", self.on_change_label_state) - self.add_action(lbl_action) - self.label = Gtk.Label(label=lbl_variant.get_string(), margin=30) - self.add(self.label) - self.label.show() - def on_change_label_state(self, action, value): - action.set_state(value) - self.label.set_text(value.get_string()) - def on_maximize_toggle(self, action, value): - action.set_state(value) - if value.get_boolean(): - self.maximize() - else: - self.unmaximize() -class Application(Gtk.Application): - def __init__(self, *args, **kwargs): - super().__init__( - *args, - application_id="org.example.myapp", - flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE, - **kwargs - ) - self.window = None - self.add_main_option( - "test", - ord("t"), - GLib.OptionFlags.NONE, - GLib.OptionArg.NONE, - "Command line test", - None, - ) - def do_startup(self): - Gtk.Application.do_startup(self) - action = Gio.SimpleAction.new("about", None) - action.connect("activate", self.on_about) - self.add_action(action) - action = Gio.SimpleAction.new("quit", None) - action.connect("activate", self.on_quit) - self.add_action(action) - builder = Gtk.Builder.new_from_string(MENU_XML, -1) - self.set_app_menu(builder.get_object("app-menu")) - def do_activate(self): - # We only allow a single window and raise any existing ones - if not self.window: - # Windows are associated with the application - # when the last one is closed the application shuts down - self.window = AppWindow(application=self, title="Main Window") - self.window.present() - def do_command_line(self, command_line): - options = command_line.get_options_dict() - # convert GVariantDict -> GVariant -> dict - options = options.end().unpack() - if "test" in options: - # This is printed on the main instance - print("Test argument recieved: %s" % options["test"]) - self.activate() - return 0 - def on_about(self, action, param): - about_dialog = Gtk.AboutDialog(transient_for=self.window, modal=True) - about_dialog.present() - def on_quit(self, action, param): - self.quit() -if __name__ == "__main__": - app = Application() - app.run(sys.argv) -- cgit