special dates support
This commit is contained in:
parent
1bc94bfd0a
commit
83ae35006b
@ -2,7 +2,10 @@ import datetime
|
|||||||
from textual.screen import ModalScreen
|
from textual.screen import ModalScreen
|
||||||
from textual.binding import Binding
|
from textual.binding import Binding
|
||||||
from textual.widgets import Label
|
from textual.widgets import Label
|
||||||
|
from textual.containers import Horizontal, Vertical
|
||||||
|
from textual.reactive import reactive
|
||||||
from ..utils import get_color_enum
|
from ..utils import get_color_enum
|
||||||
|
from ..constants import SPECIAL_DATES_PIECES
|
||||||
|
|
||||||
|
|
||||||
class ConfirmModal(ModalScreen):
|
class ConfirmModal(ModalScreen):
|
||||||
@ -101,16 +104,27 @@ class ChoiceModal(ModalScreen):
|
|||||||
class DateModal(ModalScreen):
|
class DateModal(ModalScreen):
|
||||||
CSS = """
|
CSS = """
|
||||||
DateModal {
|
DateModal {
|
||||||
layout: horizontal;
|
|
||||||
align: center middle;
|
align: center middle;
|
||||||
background: $primary 30%;
|
background: $primary 30%;
|
||||||
}
|
}
|
||||||
|
DateModal Vertical {
|
||||||
|
border: double teal;
|
||||||
|
height: 10;
|
||||||
|
width: 50;
|
||||||
|
}
|
||||||
|
DateModal Horizonal {
|
||||||
|
}
|
||||||
DateModal Label {
|
DateModal Label {
|
||||||
border: solid grey;
|
border: solid white;
|
||||||
|
align: center middle;
|
||||||
}
|
}
|
||||||
DateModal Label.selected-date {
|
DateModal Label.selected-date {
|
||||||
border: solid green;
|
border: solid green;
|
||||||
}
|
}
|
||||||
|
DateModal Label.hints {
|
||||||
|
border: solid grey;
|
||||||
|
height: 4;
|
||||||
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
BINDINGS = [
|
BINDINGS = [
|
||||||
@ -118,24 +132,43 @@ class DateModal(ModalScreen):
|
|||||||
("k", "cursor_up", "Up"),
|
("k", "cursor_up", "Up"),
|
||||||
("h,shift+tab", "cursor_left", "Left"),
|
("h,shift+tab", "cursor_left", "Left"),
|
||||||
("l,tab", "cursor_right", "Right"),
|
("l,tab", "cursor_right", "Right"),
|
||||||
|
("f", "future", "Future"),
|
||||||
|
("t", "today", "Today"),
|
||||||
|
("u", "unclassified", "Unclassified"),
|
||||||
Binding("enter", "select", "Select", priority=True),
|
Binding("enter", "select", "Select", priority=True),
|
||||||
("escape", "cancel", "cancel"),
|
("escape", "cancel", "cancel"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
pieces = reactive([0, 0, 0], recompose=True)
|
||||||
|
|
||||||
def __init__(self, date):
|
def __init__(self, date):
|
||||||
if date:
|
super().__init__()
|
||||||
|
if date in SPECIAL_DATES_PIECES:
|
||||||
|
self.pieces = SPECIAL_DATES_PIECES[date]
|
||||||
|
elif date:
|
||||||
self.pieces = [int(p) for p in date.split("-")]
|
self.pieces = [int(p) for p in date.split("-")]
|
||||||
else:
|
else:
|
||||||
today = datetime.date.today()
|
self.action_today()
|
||||||
self.pieces = [today.year, today.month, today.day]
|
|
||||||
self.selected = 1 # start on month
|
self.selected = 1 # start on month
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
def compose(self):
|
def compose(self):
|
||||||
for idx, piece in enumerate(self.pieces):
|
with Vertical():
|
||||||
yield Label(
|
with Horizontal():
|
||||||
str(piece), classes="selected-date" if idx == self.selected else ""
|
yield Label(f"{self.pieces[0]}")
|
||||||
)
|
yield Label(f"{self.pieces[1]}", classes="selected-date")
|
||||||
|
yield Label(f"{self.pieces[2]}")
|
||||||
|
yield Label("""(h/j/k/l) move (enter) confirm (esc) quit
|
||||||
|
(p)ast (t)oday (f)uture""", classes="hints")
|
||||||
|
|
||||||
|
def action_future(self):
|
||||||
|
self.pieces = SPECIAL_DAYS_PIECES["future"]
|
||||||
|
|
||||||
|
def action_unclassified(self):
|
||||||
|
self.pieces = SPECIAL_DAYS_PIECES["unclassified"]
|
||||||
|
|
||||||
|
def action_today(self):
|
||||||
|
today = datetime.date.today()
|
||||||
|
self.pieces = [today.year, today.month, today.day]
|
||||||
|
|
||||||
def action_cursor_left(self):
|
def action_cursor_left(self):
|
||||||
# cycle Y/M/D
|
# cycle Y/M/D
|
||||||
@ -171,8 +204,7 @@ class DateModal(ModalScreen):
|
|||||||
if cur_value > self.max_for(self.selected):
|
if cur_value > self.max_for(self.selected):
|
||||||
cur_value = 1
|
cur_value = 1
|
||||||
self.pieces[self.selected] = cur_value
|
self.pieces[self.selected] = cur_value
|
||||||
cur_label = self.query("Label")[self.selected]
|
self.mutate_reactive(DateModal.pieces)
|
||||||
cur_label.update(str(cur_value))
|
|
||||||
|
|
||||||
def action_cursor_down(self):
|
def action_cursor_down(self):
|
||||||
self._move_piece(-1)
|
self._move_piece(-1)
|
||||||
|
@ -3,6 +3,7 @@ import os
|
|||||||
import datetime
|
import datetime
|
||||||
import tempfile
|
import tempfile
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from .constants import SPECIAL_DATES_DISPLAY
|
||||||
|
|
||||||
|
|
||||||
def filter_to_string(filters, search_query):
|
def filter_to_string(filters, search_query):
|
||||||
@ -41,6 +42,8 @@ def get_colored_date(date: datetime.date) -> str:
|
|||||||
if not isinstance(date, datetime.date):
|
if not isinstance(date, datetime.date):
|
||||||
return ""
|
return ""
|
||||||
as_str = date.strftime("%Y-%m-%d")
|
as_str = date.strftime("%Y-%m-%d")
|
||||||
|
if as_str in SPECIAL_DATES_DISPLAY:
|
||||||
|
return SPECIAL_DATES_DISPLAY[as_str]
|
||||||
today = datetime.date.today()
|
today = datetime.date.today()
|
||||||
if date.date() < today:
|
if date.date() < today:
|
||||||
return f"[#eeeeee on #dd1111]{as_str}[/]"
|
return f"[#eeeeee on #dd1111]{as_str}[/]"
|
||||||
|
Loading…
Reference in New Issue
Block a user