def build_application(self, rebuild=False, reinsert=False, examples=False): """Work on window recursion and tree""" screen = self.screen height, width = screen.getmaxyx() self.controller = PersonController(PersonConnection(rebuild=rebuild), reinsert=reinsert) if rebuild: self.data = [self.controller.request_persons()] else: self.data = [Person.random() for _ in range(10)] # main window self.window.title = 'Application Example 1' # display window display = DisplayWindow(screen.subwin(11, utils.partition(width, 5, 3), 1, utils.partition(width, 5, 2)), title="Profile") # self.on_data_changed.append(display.on_data_changed) # scroll window scroller = ScrollableWindow( screen.subwin(height - 2, utils.partition(width, 5, 2), 1, 0), title="Directory", data=[str(n.name) for n in self.data], focused=True, # data_changed_handlers=(self.on_data_changed,) ) # secondary display -- currently unused # adding sub windows to parent window unused = Window(screen.subwin(height - 13, utils.partition(width, 5, 3), 12, utils.partition(width, 5, 2)), title='verylongtitlescree') # prompt screen # prompt = PromptWindow(screen.subwin(3, width, height - 4, 0)) self.window.add_windows( scroller, display, unused, # prompt )
def build_application(self, rebuild=False, reinsert=False, examples=False): """Work on window recursion and tree""" screen = self.screen height, width = screen.getmaxyx() # main window self.window = Window(screen, title='Application Example 1') # first window half screen vertical sub1 = DisplayWindow(screen.subwin(height - 1, utils.partition(width, 2, 1), 0, 0), title="Sub-win 1", focused=True) # second window quarter screen top right sub2 = DisplayWindow(screen.subwin( utils.partition(height - 1, 2, 1, math.ceil), utils.partition(width, 2, 1), 0, utils.partition(width, 2, 1), ), title="Sub-win 2") sub3 = DisplayWindow(screen.subwin( utils.partition(height - 2, 2, 1), utils.partition(width, 2, 1), utils.partition(height - 1, 2, 1, math.ceil), utils.partition(width, 2, 1), ), title="Sub-win 3") # win 1 handlers sub1.add_handler(27, self.keypress_escape) sub1.add_handlers(9, sub1.unfocus, sub2.focus, self.on_focus_changed) sub1.add_handlers(351, sub1.unfocus, sub3.focus, self.on_focus_changed) # window 2 handlers sub2.add_handler(27, self.keypress_escape) sub2.add_handlers(351, sub2.unfocus, sub1.focus, self.on_focus_changed) sub2.add_handlers(9, sub2.unfocus, sub3.focus, self.on_focus_changed) # window 3 handlers sub3.add_handler(27, self.keypress_escape) sub3.add_handlers(351, sub3.unfocus, sub2.focus, self.on_focus_changed) sub3.add_handlers(9, sub3.unfocus, sub1.focus, self.on_focus_changed) self.window.add_windows(sub1, sub2, sub3) self.on_focus_changed(self)
def build_receipt_viewer(self, rebuild=False): screen = self.screen height, width = screen.getmaxyx() self.controller = ReceiptController(ReceiptConnection(rebuild=rebuild)) self.data = list(self.controller.request_receipts()) receipt_explorer = ScrollableWindow( screen.subwin(height - 2, utils.partition(width, 3, 1), 1, 0), title="receipt", title_centered=True, focused=True, data=[n.store for n in self.data], data_changed_handlers=(self.on_data_changed, )) receipt_explorer.keypress_up_event = on_keypress_up receipt_explorer.keypress_down_event = on_keypress_down self.window.add_window(receipt_explorer) self.events[curses.KEY_DOWN].append(receipt_explorer.handle_key) self.events[curses.KEY_UP].append(receipt_explorer.handle_key) self.focused = self.window.currently_focused if not self.focused: self.focused = self.window
def build_application(self, rebuild=False, reinsert=False, examples=False): """ Builds an application to view all quizzes """ screen = self.screen height, width = screen.getmaxyx() if not examples: self.controller = QuizController( connection=QuizConnection(rebuild=rebuild), reinsert=reinsert) self.data = list(self.controller.request_questions()) else: self.data = [Question.random() for i in range(100)] print(self.data) self.window.title = 'Quiz Viewer Example' quiz_display = QuizDisplayWindow( screen.subwin(height - 2, utils.partition(width, 3, 2), 1, utils.partition(width, 3, 1)), title="Quiz viewer", dataobj=self.data[0] if self.data else None) quiz_explorer = QuizScrollableWindow( screen.subwin(height - 2, utils.partition(width, 3, 1), 1, 0), title="Quizs", title_centered=True, focused=True, data=[q.question for q in self.data], data_changed_handlers=(self.data_changed, )) help_window = QuizHelpWindow(screen.subwin( height // 3, utils.partition(width, 4, 2), utils.partition(height, 3, 1), utils.partition(width, 4, 1)), title="Help Window", dataobj=Text.random()) # application change event # self.on_data_changed.append(quiz_display.data_changed) # main window key press handlers self.window.changes.on('focused', self.focus_changed) self.window.keypresses.on(27, self.keypress_escape) self.window.keypresses.on(curses.KEY_F1, help_window.keypress_f1) # scroll window key press handlers quiz_explorer.changes.on('focused', self.focus_changed) quiz_explorer.keypresses.on(27, self.keypress_escape) quiz_explorer.keypresses.on(9, quiz_display.keypress_tab) quiz_explorer.keypresses.on(curses.KEY_F1, help_window.keypress_f1) quiz_explorer.keypresses.on(curses.KEY_DOWN, quiz_explorer.keypress_down) quiz_explorer.keypresses.on(curses.KEY_UP, quiz_explorer.keypress_up) # display window key press handlers self.on_data_changed.append(quiz_display.data_changed) quiz_display.changes.on('focused', self.focus_changed) quiz_display.keypresses.on(27, self.keypress_escape) quiz_display.keypresses.on(351, quiz_explorer.keypress_btab) quiz_display.keypresses.on(curses.KEY_F1, help_window.keypress_f1) # help window key press handlers help_window.changes.on('focused', self.focus_changed) help_window.keypresses.on(27, help_window.keypress_f1) help_window.keypresses.on(curses.KEY_F1, help_window.keypress_f1) self.window.add_windows(quiz_explorer, quiz_display, help_window) self.focused = self.window.currently_focused
def build_application(self, rebuild=False, examples=False, demo=None): """Build window objects and handlers for a todo task list app""" screen = self.screen height, width = screen.getmaxyx() self.data = [ Task(f"task {i}", random.randint(0, 3), datetime.datetime.today()) for i in range(50) ] self.window.title = "Tasks To Do" task_win = DisplayWindow( screen.subwin( utils.partition(height-2, 2, 1), width, utils.partition(height, 2, 1), 0 ) ) self.on_data_changed.append(task_win.on_data_changed) none_win = ScrollableWindow( screen.subwin( (height // 2) - 1, utils.partition(width, 4, 1), 1, 0 ), title="No Status", title_centered=True, data=[task.title for task in self.data if task.status_id == 0], data_changed_handlers=(self.on_data_changed,) ) todo_win = ScrollableWindow( screen.subwin( (height // 2) - 1, utils.partition(width, 4, 1), 1, utils.partition(width, 4, 1) ), title="Todo", title_centered=True, focused=True, data=[task.title for task in self.data if task.status_id == 1], data_changed_handlers=(self.on_data_changed,), eventmap=EventMap.fromkeys(( 9, # ord('\t'), 351, # curses.KEY_BTAB, 258, # curses.KEY_DOWN, 259 # curses.KEY_UP, )) ) work_win = ScrollableWindow( screen.subwin( (height // 2) - 1, utils.partition(width, 4, 1), 1, utils.partition(width, 4, 2) ), title="In-progress", title_centered=True, data=[task.title for task in self.data if task.status_id == 2], data_changed_handlers=(self.on_data_changed,) ) done_win = ScrollableWindow( screen.subwin( (height // 2) - 1, utils.partition(width, 4, 1), 1, utils.partition(width, 4, 3) ), title="Finished", title_centered=True, data=[task.title for task in self.data if task.status_id == 3], data_changed_handlers=(self.on_data_changed,) ) # tasks without statuses none_win.add_handler(258, on_keypress_down) none_win.add_handler(259, on_keypress_up) none_win.add_handler(27, self.on_keypress_escape) none_win.add_handlers( 9, none_win.unfocus, todo_win.focus, self.on_focus_changed ) # tasks in todo list todo_win.add_handler(258, on_keypress_down) todo_win.add_handler(259, on_keypress_up) todo_win.add_handler(27, self.on_keypress_escape) todo_win.add_handlers( 351, todo_win.unfocus, none_win.focus, self.on_focus_changed ) todo_win.add_handlers( 9, todo_win.unfocus, work_win.focus, self.on_focus_changed ) # in work tasks work_win.add_handler(258, on_keypress_down) work_win.add_handler(259, on_keypress_up) work_win.add_handler(27, self.on_keypress_escape) work_win.add_handlers( 351, work_win.unfocus, todo_win.focus, self.on_focus_changed ) work_win.add_handlers( 9, work_win.unfocus, done_win.focus, self.on_focus_changed ) # finished tasks done_win.add_handler(258, on_keypress_down) done_win.add_handler(259, on_keypress_up) done_win.add_handler(27, self.on_keypress_escape) done_win.add_handlers( 351, done_win.unfocus, work_win.focus, self.on_focus_changed ) self.window.add_windows( none_win, todo_win, work_win, done_win, task_win ) self.focused = self.window.currently_focused
def build_application(self, rebuild=False, reinsert=False, examples=False): """Builds an application to view all notes""" screen = self.screen height, width = screen.getmaxyx() if not examples: self.controller = NotesController(NoteConnection(rebuild=rebuild), reinsert=reinsert) self.data = self.controller.request_notes() else: self.data = [Note.random() for i in range(10)] # print(self.data) self.window.title = 'Note Viewer Example' note_display = NoteDisplayWindow( screen.subwin(height - 2, utils.partition(width, 3, 2), 1, utils.partition(width, 3, 1)), title="Note viewer", dataobj=self.data[0] if self.data else None) note_explorer = NoteScrollableWindow( screen.subwin(height - 2, utils.partition(width, 3, 1), 1, 0), title="Notes", title_centered=True, focused=True, data=[n.title for n in self.data], data_changed_handlers=(self.data_changed, )) print("error here?") help_window = NoteHelpWindow(screen.subwin( height // 3, utils.partition(width, 4, 2), utils.partition(height, 3, 1), utils.partition(width, 4, 1)), title="Help Window", dataobj=Text(HELP_STRING)) print(help_window.width) delete_window = NoteHelpWindow(screen.subwin( height // 3, utils.partition(width, 4, 2), utils.partition(height, 3, 1), utils.partition(width, 4, 1)), title="Delete Note", dataobj=Text.random()) create_window = NewNoteWindow( screen.subwin(height // 3, utils.partition(width, 4, 2), utils.partition(height, 3, 1), utils.partition(width, 4, 1)), screen.subwin((height // 3) - 7, utils.partition(width, 4, 2) - 2, utils.partition(height, 3, 1) + 3, utils.partition(width, 4, 1) + 1), screen.subwin((height // 3) - 4, utils.partition(width, 4, 2) - 2, utils.partition(height, 3, 1) + 3, utils.partition(width, 4, 1) + 1), title="Add Note Window", showing=False) create_window.note_created.append(self.data_added) # application change event # self.on_data_changed.append(note_display.data_changed) # main window key press handlers self.window.changes.on(('focused', self.focus_changed)) self.window.keypresses.on((27, self.keypress_escape), (curses.KEY_F1, help_window.keypress_f1)) # scroll window key press handlers note_explorer.changes.on(('focused', self.focus_changed)) note_explorer.keypresses.on( (27, self.keypress_escape), (9, note_display.keypress_tab), (curses.KEY_F1, help_window.keypress_f1), (curses.KEY_DOWN, note_explorer.keypress_down), (curses.KEY_UP, note_explorer.keypress_up), (ord('a'), create_window.keypress_a), (ord('d'), self.data_deleted)) self.on_data_added.append(note_explorer.data_added) self.on_data_changed.append(note_explorer.data_removed) # display window key press handlers self.on_data_changed.append(note_display.data_changed) note_display.changes.on(('focused', self.focus_changed), (27, self.keypress_escape), (351, note_explorer.keypress_btab), (curses.KEY_F1, help_window.keypress_f1)) # help window key press handlers help_window.changes.on(('focused', self.focus_changed)) help_window.keypresses.on((27, help_window.keypress_f1), (curses.KEY_F1, help_window.keypress_f1)) print("finish adding handlers") self.window.add_windows(note_explorer, note_display, help_window, create_window) print('add windows') self.focused = self.window.currently_focused print('finish init')