org-editor/main.py

88 lines
2.3 KiB
Python
Raw Normal View History

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