Beispiel #1
0
def show_date_list(tag, dates, area_id=None, text_area=None):
    """Show the list of entries for a tag."""
    labels = map(format_date, dates)
    sl = ScrollableList(labels, tag, area_id=area_id)
    sl.draw()
    date = dates[sl.get_current_index()]
    metadata = Metadata.get(date.year, date.month)
    if not text_area:
        text_area = TextArea()
    text_area.set_title()
    text_area.show_text(metadata.text(date.day))
    while 1:
        try:
            kn = curses.keyname(sl.window.getch())
        except KeyboardInterrupt:
            break
        if kn in Config.general_keys['quit']:
            raise WLQuit
        if kn in Config.general_keys['quit_mode']:
            break
        if kn == 'KEY_RESIZE':
            ScreenManager.resize()
        if sl.hidden:
            continue
        if kn in Config.tag_details_keys['edit']:
            date = dates[sl.get_current_index()]
            edit_date(date)
            sl.draw()
            metadata.load_day(date.day)
            text_area.show_text(metadata.text(date.day))
        elif kn in Config.tag_details_keys['edits']:
            date = dates[sl.get_current_index()]
            edits = get_edits(date)
            if edits:
                show_edits(date, edits, text_area.area_id)
                ScreenManager.restore_area(text_area.area_id)
                text_area.show_text(metadata.text(date.day))
        else:
            sl.handle_keypress(kn)
            date = dates[sl.get_current_index()]
            metadata = Metadata.get(date.year, date.month)
            text_area.show_text(metadata.text(date.day))
    Metadata.write_all()
Beispiel #2
0
def show_calendar():
    """Show an interactive calendar.

    Show the calendar on the left side of the screen and some metadata about
    the selected date on the right. Any entry can be edited in external editor.
    """
    today = datetime.date.today()
    year, month = today.year, today.month
    cal = Calendar(year, month, today.day, entry_exists)
    metadata = Metadata.get(year, month)
    text_area = TextArea()
    ScreenManager.draw_all()
    d = cal.get_current_date()
    text_area.show_text(metadata.text(d.day))
    keys = Config.calendar_keys
    while 1:
        try:
            kn = curses.keyname(cal.window.getch())
        except KeyboardInterrupt:
            break
        except ValueError:
            continue
        if kn in Config.general_keys['quit']:
            raise WLQuit
        if kn in Config.general_keys['quit_mode']:
            break
        if kn == 'KEY_RESIZE':
            ScreenManager.resize()
        if cal.hidden:
            continue
        if kn in keys['left']:
            moved = cal.move_left()
            if not moved:
                cal = cal.get_previous_calendar()
                cal.draw()
                metadata = Metadata.get(cal.year, cal.month)
            text_area.show_text(metadata.text(cal.get_current_day()))
        elif kn in keys['right']:
            moved = cal.move_right()
            if not moved:
                cal = cal.get_next_calendar()
                cal.draw()
                metadata = Metadata.get(cal.year, cal.month)
            text_area.show_text(metadata.text(cal.get_current_day()))
        elif kn in keys['down']:
            cal.move_down()
            text_area.show_text(metadata.text(cal.get_current_day()))
        elif kn in keys['up']:
            cal.move_up()
            text_area.show_text(metadata.text(cal.get_current_day()))
        elif kn in keys['edit']:
            date = cal.get_current_date()
            edit_date(date)
            metadata.load_day(date.day)
            cal.set_active(entry_exists(date))
            text_area.show_text(metadata.text(date.day))
        elif kn in keys['tags']:
            show_tags(cal.area_id, text_area)
            ScreenManager.restore_area(cal.area_id)
            cal.reinit()
            text_area.set_title()
            text_area.show_text(metadata.text(cal.get_current_day()))
        elif kn in keys['edits']:
            date = cal.get_current_date()
            edits = get_edits(date)
            if edits:
                show_edits(date, edits, text_area.area_id)
                ScreenManager.restore_area(text_area.area_id)
                text_area.show_text(metadata.text(date.day))
        elif kn in keys['prev_month']:
            cal = cal.get_previous_calendar(cal.get_current_day())
            cal.draw()
            metadata = Metadata.get(cal.year, cal.month)
            text_area.show_text(metadata.text(cal.get_current_day()))
        elif kn in keys['next_month']:
            cal = cal.get_next_calendar(cal.get_current_day())
            cal.draw()
            metadata = Metadata.get(cal.year, cal.month)
            text_area.show_text(metadata.text(cal.get_current_day()))
    Metadata.write_all()
    clean_tmp()