#!/usr/bin/env python3 import sys import os import logging import threading import task_manager APP_TITLE = "Org-mob" DOCS_PATH = os.environ["ORG_PATH"] import gi gi.require_version("Gtk", "4.0") gi.require_version('Polkit', '1.0') gi.require_version(namespace='Adw', version='1') from gi.repository import Gtk, Polkit, GObject, Gio, Adw class MainWindow(Gtk.Window): def __init__(self, *, title, application, task_manager): super().__init__(title=title, application=application) self.application = application self.task_manager = task_manager self.task_manager.get_task_list(self.on_task_list_ready) self.task_list = Gtk.ListBox() self.set_child(self.task_list) def on_button_clicked(self, button): print('{} was clicked'.format(button)) def build_agenda_task_row(self, task): row = Gtk.ListBoxRow() hbox = Gtk.Box(spacing=6) state_button = Gtk.Button.new_with_label(task.state or '') state_button.connect("clicked", self.on_button_clicked) hbox.append(state_button) task_name_label = Gtk.Entry(text=task.title) hbox.append(task_name_label) row.set_child(hbox) return row def on_task_list_ready(self, agenda): for item in agenda.with_hour: self.task_list.append(self.build_agenda_task_row(item)) for item in agenda.no_hour: self.task_list.append(self.build_agenda_task_row(item)) class Application(Gtk.Application): """ Main Aplication class """ def __init__(self): super().__init__(application_id='com.codigoparallevar.gtk4-organizer', flags=Gio.ApplicationFlags.FLAGS_NONE) self.task_manager = task_manager.TaskManager(DOCS_PATH) def do_activate(self): win = self.props.active_window if not win: win = MainWindow( title=APP_TITLE, application=self, task_manager=self.task_manager, ) win.present() def main(): """ Run the main application""" GObject.threads_init() logging.basicConfig(level=logging.INFO, format="%(levelname)-8s %(message)s") app = Application() return app.run(sys.argv) if __name__ == '__main__': main()