commit 0ed83a8306b91d1f8c5225859c26c2f3bc8e7cef Author: Sergio Martínez Portela Date: Wed Dec 22 22:44:34 2021 +0100 Initial version. diff --git a/main.py b/main.py new file mode 100644 index 0000000..d8d7a8e --- /dev/null +++ b/main.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 + +import sys +import gi + +gi.require_version("Gtk", "4.0") +gi.require_version('Polkit', '1.0') + +from gi.repository import Gtk, Polkit, GObject, Gio + +class MainWindow(Gtk.Window): + def __init__(self, title, width, height, application=None): + super().__init__(title=title, application=application) + + task_list = Gtk.ListBox() + self.set_child(task_list) + + row = Gtk.ListBoxRow() + hbox = Gtk.Box(spacing=6) + button = Gtk.Button.new_with_label("Click Me") + button.connect("clicked", self.on_click_me_clicked) + hbox.append(button) + row.set_child(hbox) + task_list.append(row) + + row = Gtk.ListBoxRow() + hbox = Gtk.Box(spacing=6) + button = Gtk.Button.new_with_mnemonic("_Open") + button.connect("clicked", self.on_open_clicked) + hbox.append(button) + row.set_child(hbox) + task_list.append(row) + + row = Gtk.ListBoxRow() + hbox = Gtk.Box(spacing=6) + button = Gtk.Button.new_with_mnemonic("_Close") + button.connect("clicked", self.on_close_clicked) + hbox.append(button) + row.set_child(hbox) + task_list.append(row) + + def on_click_me_clicked(self, button): + print('"Click me" button was clicked') + + def on_open_clicked(self, button): + print('"Open" button was clicked') + + def on_close_clicked(self, button): + print("Closing application") + self.close() + + +class Application(Gtk.Application): + """ Main Aplication class """ + + def __init__(self): + super().__init__(application_id='com.codigoparallevar.gtk4-organizer', + flags=Gio.ApplicationFlags.FLAGS_NONE) + + def do_activate(self): + win = self.props.active_window + if not win: + win = MainWindow("My Gtk4 Application", 800, 800, application=self) + win.present() + + +def main(): + """ Run the main application""" + app = Application() + return app.run(sys.argv) + + +if __name__ == '__main__': + main()