Initial version.
This commit is contained in:
commit
0ed83a8306
74
main.py
Normal file
74
main.py
Normal file
@ -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()
|
Loading…
Reference in New Issue
Block a user