Compare commits

..

1 Commits

Author SHA1 Message Date
Sergio Martínez Portela
ef4d268225 Make default size larger, and closer to PinePhone form factor. 2022-03-27 23:34:01 +02:00
4 changed files with 34 additions and 95 deletions

View File

@ -1,8 +0,0 @@
import subprocess
def navigate_emacs_to_id(item_id):
item_id = item_id.replace('"', '\\"')
return subprocess.check_call([
'emacsclient', '-e', '(org-id-goto "{}")'.format(item_id)],
stdout=subprocess.DEVNULL,
)

61
main.py
View File

@ -6,9 +6,8 @@ import logging
import threading import threading
import task_manager import task_manager
import emacs_client
APP_TITLE = "Org-Convergence" APP_TITLE = "Org-mob"
DOCS_PATH = os.environ["ORG_PATH"] DOCS_PATH = os.environ["ORG_PATH"]
STYLE_FILE_PATH = os.path.join( STYLE_FILE_PATH = os.path.join(
os.path.dirname(os.path.abspath(__file__)), os.path.dirname(os.path.abspath(__file__)),
@ -25,9 +24,6 @@ gi.require_version(namespace='Adw', version='1')
from gi.repository import Gtk, Polkit, GObject, Gio, Adw, Gdk from gi.repository import Gtk, Polkit, GObject, Gio, Adw, Gdk
class MainWindow(Gtk.Window): class MainWindow(Gtk.Window):
__gsignals__ = {
"open-in-emacs": (GObject.SignalFlags.RUN_FIRST, GObject.TYPE_NONE, (object, )),
}
## Setup ## Setup
def __init__(self, *, title, application, task_manager, with_titlebar=True): def __init__(self, *, title, application, task_manager, with_titlebar=True):
@ -54,7 +50,6 @@ class MainWindow(Gtk.Window):
self.task_list = Gtk.ListBox(name='task-list') self.task_list = Gtk.ListBox(name='task-list')
self.scrollview.set_child(self.task_list) self.scrollview.set_child(self.task_list)
self.item_rows = []
# self.main_box.props.valign = Gtk.Align.CENTER # self.main_box.props.valign = Gtk.Align.CENTER
# self.main_box.props.halign = Gtk.Align.CENTER # self.main_box.props.halign = Gtk.Align.CENTER
@ -63,23 +58,7 @@ class MainWindow(Gtk.Window):
self.set_child(self.scrollview) self.set_child(self.scrollview)
self.loading += 1 self.loading += 1
self.task_manager.get_task_list( self.task_manager.get_task_list(self.on_task_list_ready)
self.on_task_list_update,
self.on_task_list_ready,
)
## Keyboard shortcuts
def open_in_emacs(self, *args):
row = self.task_list.get_selected_row()
if row is None:
return
item = self.item_rows[row.get_index()]
item_id = item.id
if item_id is None:
logging.warning("No ID found for item: {}".format(item))
return
emacs_client.navigate_emacs_to_id(item_id)
## Rendering ## Rendering
def build_agenda_task_row(self, task): def build_agenda_task_row(self, task):
@ -104,7 +83,7 @@ class MainWindow(Gtk.Window):
row.set_child(hbox) row.set_child(hbox)
return row return row
def on_ready(self): def on_ready(self):
self.loading -= 1 self.loading -= 1
@ -115,16 +94,21 @@ class MainWindow(Gtk.Window):
self.progress_spinner.stop() self.progress_spinner.stop()
## Callbacks ## Callbacks
def on_task_list_update(self, new_rows): def on_task_list_ready(self, agenda):
for item in new_rows.with_hour: # TODO: Avoid reconstructing the whole list every time
self.task_list.append(self.build_agenda_task_row(item)) i = 0
self.item_rows.append(item) child = self.task_list.get_first_child()
while child is not None:
was = child
child = child.get_next_sibling()
i += 1
self.task_list.remove(was)
for item in new_rows.no_hour: for item in agenda.with_hour:
self.task_list.append(self.build_agenda_task_row(item)) self.task_list.append(self.build_agenda_task_row(item))
self.item_rows.append(item)
def on_task_list_ready(self, success): for item in agenda.no_hour:
self.task_list.append(self.build_agenda_task_row(item))
self.on_ready() self.on_ready()
## Reactions ## Reactions
@ -139,7 +123,7 @@ class Application(Gtk.Application):
""" Main Aplication class """ """ Main Aplication class """
def __init__(self): def __init__(self):
super().__init__(application_id='com.codigoparallevar.org-convergence', super().__init__(application_id='com.codigoparallevar.gtk4-organizer',
flags=Gio.ApplicationFlags.FLAGS_NONE) flags=Gio.ApplicationFlags.FLAGS_NONE)
self.task_manager = task_manager.TaskManager(DOCS_PATH) self.task_manager = task_manager.TaskManager(DOCS_PATH)
@ -156,18 +140,7 @@ class Application(Gtk.Application):
application=self, application=self,
task_manager=self.task_manager, task_manager=self.task_manager,
) )
win.set_default_size(720, 1024) # PinePhone screen is 720x1440
# PinePhone screen is 720x1440 (portrait) but, has 2x pixel density
win.set_default_size(360, 720)
## Load shortcuts
# Open in emacs
action = Gio.SimpleAction.new("open-in-emacs", None)
action.connect("activate", win.open_in_emacs)
self.add_action(action)
self.set_accels_for_action('app.open-in-emacs', ["<Ctrl>e"])
win.present() win.present()

View File

@ -1,4 +1,7 @@
#task-list { #task-list {
border: 1px solid #cdc7c2;
padding: 1ex;
margin: 1ex;
} }
#task-list .state-button, #task-list .state-button,
@ -7,7 +10,11 @@
} }
window { window {
background-color: #d6d5d4;
} }
#task-list .task-name { #task-list .task-name {
} border: none;
border-bottom: 1px solid #ccc;
border-radius: 0;
}

View File

@ -91,19 +91,22 @@ class TaskManager:
self.docs = docs self.docs = docs
def get_task_list(self, progress_callback, complete_callback): def get_task_list(self, callback):
def aux(): def aux():
if self.docs is None: if self.docs is None:
last_result = None last_result = None
# No docs read yet, load them iteratively
for doc in self.load(): for doc in self.load():
result = self.get_agenda_from_doc(doc) result = self.get_agenda()
GObject.idle_add(progress_callback, result) if ((last_result is None)
or (len(result.with_hour) != len(last_result.with_hour))
or (len(result.no_hour) != len(last_result.no_hour))):
print("Loaded:", doc._path)
GObject.idle_add(callback, result)
print("Load completed")
else: else:
result = self.get_agenda() result = self.get_agenda()
print("Result", result) print("Result", result)
GObject.idle_add(progress_callback, result) GObject.idle_add(callback, result)
GObject.idle_add(complete_callback, True)
thread = threading.Thread(target=aux) thread = threading.Thread(target=aux)
thread.start() thread.start()
@ -150,39 +153,3 @@ class TaskManager:
with_hour=sorted(items_with_hour, key=lambda x: x.scheduled.time), with_hour=sorted(items_with_hour, key=lambda x: x.scheduled.time),
no_hour=other_items, no_hour=other_items,
) )
def get_agenda_from_doc(self, doc: OrgDoc) -> Agenda:
headline_count = 0
items_in_agenda = []
now = datetime.now()
for hl in doc.getAllHeadlines():
headline_count += 1
if (
hl.scheduled
and isinstance(hl.scheduled, OrgTime)
and hl.scheduled.time.active
):
if is_today(hl.scheduled):
items_in_agenda.append(hl)
elif (hl.scheduled.time.to_datetime() < now) and hl.is_todo:
items_in_agenda.append(hl)
items_with_hour = [
item
for item in items_in_agenda
if item.scheduled and is_today(item.scheduled) and item.scheduled.time.hour
]
other_items = [
item
for item in items_in_agenda
if not (
item.scheduled and is_today(item.scheduled) and item.scheduled.time.hour
)
]
return Agenda(
with_hour=sorted(items_with_hour, key=lambda x: x.scheduled.time),
no_hour=other_items,
)