def test_moving(self): today = datetime.date.today() day = 1 last = lastday(today) cal = Calendar(today.year, today.month, day) ScreenManager.draw_all() # moving from the first day to the last while day < last: cal.move_right() day += 1 self.assertEquals(cal.get_current_day(), day) # moving from the last day to the 7th while day > 7: cal.move_left() day -= 1 self.assertEquals(cal.get_current_day(), day) # moving up and down cal.move_down() self.assertEquals(cal.get_current_day(), 14) cal.move_up() self.assertEquals(cal.get_current_day(), 7)
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()