Commits

Craig Swank  committed 27b6e05

working on displaying notes

  • Participants
  • Parent commits 74172f9

Comments (0)

Files changed (3)

File gadgets/ui/database.py

         self.connection.execute(insert, args)
         self.connection.commit()
 
+    def query(self, query, args):
+        return self.connection.execute(query, args)
         
 class Mongo(object):
 

File gadgets/ui/dialogs/notes.py

 from gadgets.ui.window import Window
 
 class Notes(Window):
-    """take some notes"""
+    """notes"""
 
     _table = '''CREATE TABLE if not exists notes
              (host text, method_id integer, timestamp integer, notes text)'''
     _notes_query = '''SELECT * FROM notes WHERE host = ? ORDER BY timestamp DESC LIMIT 10'''
 
     def __init__(self, socket, lock, db):
-        self.name = None
+        self._name = None
         self._socket = socket
         self._lock = lock
         db.ensure_table(self._table)
         timestamp=datetime.datetime.now()
         self._db.save(self._insert, (self._name, method_id, int(timestamp.strftime('%s')), notes))
 
-    def _get_notes(self, win):
+    def _get_notes(self, win, method_id):
         curses.echo()
         curses.curs_set(1)
         notes = ''
         if notes != '':
             self._save(notes, method_id)
 
-    def _show_notes(self, win):
-        notes = [note for note in self._db.execute(self._notes_query, self._name)]
+    def _show_notes(self, win, screen):
+        notes = [note for note in self._db.query(self._notes_query, [self._name])]
         row = 2
-        for note in notes:
-            win.addstr(row, 2, str(note[0]))
+        for i, note in enumerate(notes):
+            d = datetime.datetime.fromtimestamp(note[2])
+            win.addstr(row, 2, '{0}: {1}'.format(i + 1, d))
             row += 1
+        x = win.getch()
+        i = int(chr(x)) - 1
+        try:
+            note = notes[i]
+        except IndexError:
+            pass
+        else:
+            win = self._get_subwin(screen)
+            win.addstr(2, 2, note[3])
+        win.getch()
 
-    def __call__(self, screen, data, method_id=None, command=None):
+    def __call__(self, screen, data, method_id=None, command=None, name=None):
+        self._name = name
         self._lock.acquire()
         win = self._get_subwin(screen)
         self._add_title(win, self.__doc__)
-        if command = 'n':
-            self._get_notes(win)
-        elif command = 'N':
-            self._show_notes(win)
+        if command == ord('n'):
+            self._get_notes(win, method_id)
+        elif command == ord('N'):
+            self._show_notes(win, screen)
         self._lock.release()
         

File gadgets/ui/ui.py

         )
         self.sockets = Sockets(addresses)
         self._lock = threading.RLock()
-        self._name = name
+        self._name = None
         self._title_bar_string = 'help: h  quit: q'
         self._location_names = locations
         self._stop = False
         self._dialogs[ord(key)] = self.Dialog(DialogClass(self.sockets, self._lock, self._db), dialog_kw)
 
     def _get_notes_args(self, command):
-        return {'command': command, 'method_id': self._data.get('method', {}).get('_id')}
+        return {'name': self._name, 'command': command, 'method_id': self._data.get('method', {}).get('_id')}
 
     def set_data(self, data):
         self._data = data
         if self._location_names == []:
             self._location_names = self._getter.locations
         self._name = self._getter.name
-        notes = self._dialogs['n']
-        notes.name = self._name
         self._row, self._col = self._get_center(screen)
         self._lock.release()
         self._draw()