Пример #1
0
def show_edits(date, edits, area_id):
    """Show all edits of an entry as a scrollable list."""
    from writelightly.screen import ScreenManager
    from writelightly.utils import format_time, format_size
    from writelightly.scrollable_list import ScrollableList
    import curses
    formatted = ['%s, created' % format_time(edits[0][0], full=True)]
    formatted += ['%s, %s' % (format_time(ts, full=True),
        format_size(size)) for ts, size in edits[1:]]
    sl = ScrollableList(formatted, area_id=area_id)
    sl.draw()
    while 1:
        kn = curses.keyname(sl.window.getch())
        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
        elif kn in Config.edits_keys['open']:
            index = sl.get_current_index()
            fn = save_tmp_version(date, edits, index)
            edit_file(fn)
            sl.draw()
        else:
            sl.handle_keypress(kn)
Пример #2
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()