MCPcopy Create free account
hub / github.com/dedsec1121fk/DedSec / curses_date_picker

Function curses_date_picker

Scripts/Developer Base/Smart Notes.py:502–580  ·  view source on GitHub ↗
(stdscr, initial_dt=None)

Source from the content-addressed store, hash-verified

500
501# Date/time picker
502def curses_date_picker(stdscr, initial_dt=None):
503 try:
504 curses.curs_set(0)
505 now = datetime.now()
506 year = initial_dt.year if initial_dt else now.year
507 month = initial_dt.month if initial_dt else now.month
508 day = initial_dt.day if initial_dt else now.day
509 hour = initial_dt.hour if initial_dt else now.hour
510 minute = initial_dt.minute if initial_dt else 0
511 fields = ['year','month','day','hour','minute','confirm']
512 idx = 0
513 while True:
514 stdscr.erase()
515 h,w = stdscr.getmaxyx()
516 centered_addstr(stdscr, 1, ' Select date & time for reminder ')
517 centered_addstr(stdscr, 3, f' Year: {year} ', curses.A_REVERSE if fields[idx]=='year' else 0)
518 centered_addstr(stdscr, 5, f' Month: {month} ', curses.A_REVERSE if fields[idx]=='month' else 0)
519 centered_addstr(stdscr, 7, f' Day: {day} ', curses.A_REVERSE if fields[idx]=='day' else 0)
520 centered_addstr(stdscr, 9, f' Hour: {hour:02d} ', curses.A_REVERSE if fields[idx]=='hour' else 0)
521 centered_addstr(stdscr, 11, f' Minute: {minute:02d} ', curses.A_REVERSE if fields[idx]=='minute' else 0)
522 centered_addstr(stdscr, 13, f' [ Confirm ] ', curses.A_REVERSE if fields[idx]=='confirm' else 0)
523 centered_addstr(stdscr, h-2, 'Left/Right field, Up/Down value, Enter confirm, ESC cancel')
524 stdscr.refresh()
525 ch = stdscr.getch()
526 if ch == curses.KEY_LEFT:
527 idx = (idx - 1) % len(fields)
528 elif ch == curses.KEY_RIGHT:
529 idx = (idx + 1) % len(fields)
530 elif ch == curses.KEY_UP:
531 if fields[idx] == 'year':
532 year += 1
533 elif fields[idx] == 'month':
534 month = 12 if month == 12 else month + 1
535 _, mdays = calendar.monthrange(year, month)
536 if day > mdays:
537 day = mdays
538 elif fields[idx] == 'day':
539 _, mdays = calendar.monthrange(year, month)
540 day = 1 if day >= mdays else day + 1
541 elif fields[idx] == 'hour':
542 hour = (hour + 1) % 24
543 elif fields[idx] == 'minute':
544 minute = (minute + 1) % 60
545 elif ch == curses.KEY_DOWN:
546 if fields[idx] == 'year':
547 year = max(now.year, year - 1)
548 elif fields[idx] == 'month':
549 month = 1 if month == 1 else month - 1
550 _, mdays = calendar.monthrange(year, month)
551 if day > mdays:
552 day = mdays
553 elif fields[idx] == 'day':
554 _, mdays = calendar.monthrange(year, month)
555 day = mdays if day <= 1 else day - 1
556 elif fields[idx] == 'hour':
557 hour = (hour - 1) % 24
558 elif fields[idx] == 'minute':
559 minute = (minute - 1) % 60

Callers 1

curses_reminders_menuFunction · 0.70

Calls 2

centered_addstrFunction · 0.70
log_exceptionFunction · 0.70

Tested by

no test coverage detected