Commits

Craig Swank  committed 4025ea4

finished the changes for the note dialog of the ui

  • Participants
  • Parent commits b359b85

Comments (0)

Files changed (2)

File gadgets/ui/dialogs/notes.py

         timestamp=datetime.datetime.now()
         self._db.save(self._insert, (self._name, method_id, int(timestamp.strftime('%s')), notes))
 
-    def _get_notes(self, win, method_id):
+    def _new_note(self, screen, method_id):
+        win = self._get_subwin(screen)
+        self._add_title(win, self.__doc__)
         curses.echo()
         curses.curs_set(1)
-        notes = ''
+        note = ''
         row = 2
-        while not notes.endswith('\n\n'):
+        while not note.endswith('\n\n'):
             win.move(row ,1)
-            notes += win.getstr() + '\n'
+            note += win.getstr() + '\n'
             row += 1
         curses.noecho()
         curses.curs_set(0)
-        if notes != '':
-            notes = notes.strip()
-            self._save(notes, method_id)
+        if note != '':
+            note = note.strip()
+            self._save(note, method_id)
 
-    def _show_notes(self, win, screen):
+    def _show_note(self, x, notes, screen):
+        try:
+            i = int(chr(x)) - 1
+            note = notes[i]
+        except IndexError:
+            pass
+        except ValueError:
+            pass
+        else:
+            lines = note[3].split('\n')
+            win = self._get_subwin(screen)
+            self._add_title(win, self.__doc__)
+            row = 2
+            for line in lines:
+                win.addstr(row, 2, line)
+                row += 1
+            win.getch()
+
+    def _show_notes(self, screen, win, method_id):
         notes = [note for note in self._db.query(self._notes_query, [self._name])]
         row = 2
         for i, note in enumerate(notes):
             d = datetime.datetime.fromtimestamp(note[2])
             win.addstr(row, 2, '{0}: {1}'.format(i + 1, d))
             row += 1
+        win.addstr(row, 2, 'n: new note')
         x = win.getch()
-        i = int(chr(x)) - 1
-        try:
-            note = notes[i]
-        except IndexError:
-            pass
+        if chr(x) == 'n':
+            self._new_note(screen, method_id)
         else:
-            win = self._get_subwin(screen)
-            win.addstr(2, 2, note[3])
-        win.getch()
+            self._show_note(x, notes, screen)
 
-    def __call__(self, screen, data, method_id=None, command=None, name=None):
+    def __call__(self, screen, data, method_id=None, name=None):
         self._name = name
         self._lock.acquire()
         win = self._get_subwin(screen)
         self._add_title(win, self.__doc__)
-        if command == ord('n'):
-            self._get_notes(win, method_id)
-        elif command == ord('N'):
-            self._show_notes(win, screen)
+        self._show_notes(screen, win, method_id)
         self._lock.release()
         

File gadgets/ui/ui.py

             ord('c'): self.Dialog(self._enter_command_mode, None),
             ord('C'): self.Dialog(Command(self, self._lock), None),
             ord('n'): self.Dialog(Notes(self.sockets, self._lock, self._db), self._get_notes_args),
-            ord('N'): self.Dialog(Notes(self.sockets, self._lock, self._db), self._get_notes_args),
             ord('m'): self.Dialog(Method(self.sockets, self._lock, self._db), None),
             ord('f'): self.Dialog(self._user_confirmed, None),
         }
         self._dialogs[ord(key)] = self.Dialog(DialogClass(self.sockets, self._lock, self._db), dialog_kw)
 
     def _get_notes_args(self, command):
-        return {'name': self._name, 'command': command, 'method_id': self._data.get('method', {}).get('_id')}
+        return {'name': self._name, 'method_id': self._data.get('method', {}).get('_id')}
 
     def set_data(self, data):
         self._data = data