def edit(self, id, fail_callback=None): """ Edit the log of the given id """ ids = Record.matchId(id) if not ids: print('%s not found' % id, file=sys.stderr) return elif len(ids) > 1: prompt = 'multiple match, which one? ' junk, id = interact.printAndPick(ids, lineMode=True, prompt=prompt) assert id, 'invalid id: "%s"' % id else: id = ids[0] oldRecord = Record.load(id) elements = dict(oldRecord.elements()) elements = self.preActionOfEdit(elements) newRecord = self.makeLogEntry(**elements) try: newRecord.save(oldRecord=oldRecord) except: if fail_callback: data = '%s\n\n%s' % (newRecord.subject, newRecord.data) fail_callback(data)
def note(self): """ Add notes to the notes database """ noteObj = Noter(self.config.note_path, self.config.book_name) actions = ['add', 'list', 'edit', 'delete'] picked = interact.printAndPick(actions, lineMode=True) func = getattr(noteObj, picked[1]) func()
def menu(self): choices = [['add', self.add], ['list', self.list], ['search', self.search], ['edit', self.edit], ['delete', self.delete]] i, junk = interact.printAndPick([x for x, y in choices], prompt='choice: ', lineMode=True) action = choices[i][-1] action()
def menu(self): choices = [ ['add', self.add], ['list', self.list], ['search', self.search], ['edit', self.edit], ['delete', self.delete] ] i, junk = interact.printAndPick([x for x, y in choices], prompt='choice: ', lineMode=True) action = choices[i][-1] action()
def list(self): cont = self.opendb() notes = sorted(cont.items(), key=lambda x: int(x[0])) text_list = [] for time, note in notes: text = isotime(int(time)) + '\n' + note.content[:80] text_list.append(text) res = interact.printAndPick(text_list) if res: idx = res[0] else: return key = notes[idx][0] note = notes[idx][1] print('-' * 80) print('Book: %s' % note.book) print('Chapter: %s' % note.chapter) print('Subject: %s' % note.subject) print('Content:\n%s' % note.content)
def edit(self, id): """ Edit the log of the given id """ ids = Record.matchId(id) if not ids: print('%s not found' % id, file=sys.stderr) return elif len(ids) > 1: prompt = 'multiple match, which one? ' junk, id = interact.printAndPick(ids, lineMode=True, prompt=prompt) assert id, 'invalid id: "%s"' % id else: id = ids[0] oldRecord = Record.load(id) elements = dict(oldRecord.elements()) elements = self.preActionOfEdit(elements) newRecord = self.makeLogEntry(**elements) newRecord.save(oldRecord=oldRecord)
def edit(self): """ change an existing note """ cont = self.opendb() notes = sorted(cont.items(), key=lambda x: int(x[0])) text_list = [] for time, note in notes: text = isotime(int(time)) + '\n' + note.content[:80] text_list.append(text) idx, junk = interact.printAndPick(text_list) key = notes[idx][0] note = notes[idx][1] prompt = 'Chapter [%s]: ' % note.chapter note.chapter = interact.readint(prompt, default=note.chapter) prompt = 'Subject [%s]: ' % note.subject note.subject = interact.readstr(prompt, default='') or note.subject note.content = self.edit_content(data=note.content) self.save(key, note)
def log(self): """ Complete an temporary log, or manually add a new complete one """ # use the tmp log record if any tmplogs = self.logger.fetch_tmplogs() if tmplogs: ent = interact.printAndPick(tmplogs) if ent: ent.start_time = self.logger.ask_start_time(ent.start_time) ent.end_time = self.logger.ask_end_time(ent.end_time) ent.start_page = self.logger.ask_start_page(ent.start_page) ent.end_page = self.logger.ask_end_page(ent.end_page) ent.complete = True self.logger.save(str(ent.start_time), ent) return start_time = self.logger.ask_start_time() end_time = self.logger.ask_end_time() start_page = self.logger.ask_start_page() end_page = self.logger.ask_end_page() ent = self.logger.make_log(self.config.book_name, start_time, end_time, start_page, end_page, True) self.logger.save(str(ent.start_time), ent)