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