X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fnotizen.py;h=be85c49399d2fcb02977d5ad8da1fc177a9b5691;hb=b62dbd9583ad1ef0edde77a2ae4e114e59b99b68;hp=ccac21a699f3881c16307263011a22ebddc815bc;hpb=bef6345b9d91e1b43a0ca599cecaa25789fde9cc;p=quicknote diff --git a/src/notizen.py b/src/notizen.py index ccac21a..be85c49 100644 --- a/src/notizen.py +++ b/src/notizen.py @@ -7,6 +7,9 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. + +@todo It would be nice to move the category selector to the category list's column and search below everything. +@todo Search would be activated by menu or CTRL+F rather than zoom """ import time @@ -21,6 +24,7 @@ except ImportError: gtkspell = None import hildonize +import gtk_toolbox import simple_list @@ -35,9 +39,10 @@ _moduleLogger = logging.getLogger("notizen") class Notizen(gtk.HBox): - def __init__(self, db, topBox): + def __init__(self, db, category, search): self._db = db - self._topBox = topBox + self._category = category + self._search = search self.noteId = -1 self._pos = -1 self._noteBody = None #Last notetext @@ -51,9 +56,6 @@ class Notizen(gtk.HBox): self._noteslist.set_eventfunction_cursor_changed(self._update_noteslist) self._noteslist.widget.set_size_request(250, -1) - frame = gtk.Frame(_("Titles")) - frame.add(self._noteslist.widget) - buttonHBox = gtk.HBox() button = gtk.Button(stock = gtk.STOCK_ADD) @@ -65,7 +67,8 @@ class Notizen(gtk.HBox): buttonHBox.pack_start(button, expand = True, fill = True, padding = 3) listVbox = gtk.VBox(homogeneous = False, spacing = 0) - listVbox.pack_start(frame, expand = True, fill = True, padding = 3) + listVbox.pack_start(self._category, expand = False, fill = True, padding = 3) + listVbox.pack_start(self._noteslist.widget, expand = True, fill = True, padding = 3) listVbox.pack_start(buttonHBox, expand = False, fill = True, padding = 3) self.pack_start(listVbox, expand = False, fill = True, padding = 3) @@ -85,28 +88,14 @@ class Notizen(gtk.HBox): self._noteScrollWindow.add(self._noteBodyView) hildonize.hildonize_scrollwindow_with_viewport(self._noteScrollWindow) - frame = gtk.Frame(_("Note")) - frame.add(self._noteScrollWindow) - - # History - self._historyBox = gtk.HBox(homogeneous = False, spacing = 0) - - self._historyStatusLabel = gtk.Label(_("No History")) - self._historyStatusLabel.set_alignment(0.0, 0.5) - self._historyBox.pack_start(self._historyStatusLabel, expand = True, fill = True, padding = 3) - - button = gtk.Button(_("History")) - button.connect("clicked", self._on_show_history, None) - self._historyBox.pack_start(button, expand = True, fill = True, padding = 3) - # Note and history stuff in same column noteVbox = gtk.VBox(homogeneous = False, spacing = 0) - noteVbox.pack_start(frame, expand = True, fill = True, padding = 3) - noteVbox.pack_start(self._historyBox, expand = False, fill = True, padding = 3) + noteVbox.pack_start(self._noteScrollWindow, expand = True, fill = True, padding = 3) self.pack_start(noteVbox, expand = True, fill = True, padding = 3) self.load_notes() - self._topBox.connect("reload_notes", self.load_notes) + self._category.connect("category_changed", self.load_notes) + self._search.connect("search_changed", self.load_notes) def set_wordwrap(self, enableWordWrap): if enableWordWrap: @@ -116,19 +105,12 @@ class Notizen(gtk.HBox): self._noteScrollWindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self._noteBodyView.set_wrap_mode(gtk.WRAP_NONE) - def show_history_area(self, visible): - if visible: - self._historyBox.show() - else: - self._historyBox.hide() - def load_notes(self, data = None): _moduleLogger.info("load_notes params: pos:"+str(self._pos)+" noteid:"+str(self.noteId)) self._noteslist.clear_items() - self._noteslist.append_item(_("New Note..."), "new") - self._categoryName = self._topBox.get_category() - search = self._topBox.get_search_pattern() + self._categoryName = self._category.get_category() + search = self._search.get_search_pattern() notes = self._db.searchNotes(search, self._categoryName) if notes is not None: @@ -151,17 +133,52 @@ class Notizen(gtk.HBox): if buf == self._noteBody: return - _moduleLogger.info("Saving note: "+buf) + title = self._get_title(buf) + _moduleLogger.info("Saving note: " + title) if self._pos == -1 or self.noteId == -1: self._pos = -1 self.noteId = str(uuid.uuid4()) self._db.saveNote(self.noteId, buf, self._categoryName) - self._noteslist.append_item(self._get_title(buf), self.noteId) + self._noteslist.append_item(title, self.noteId) self._pos = self._noteslist.select_last_item() else: self._db.saveNote(self.noteId, buf, self._categoryName) - self._topBox.define_this_category() + self._category.define_this_category() + + def show_history(self, *args): + if self.noteId == -1: + mbox = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, _("No note selected.")) + response = mbox.run() + mbox.hide() + mbox.destroy() + return + + rows = self._db.getNoteHistory(self.noteId) + + import history + dialog = history.Dialog() + + lastNoteStr = "" + for row in rows: + daten = row[4][1] + if daten != "" and lastNoteStr != daten: + lastNoteStr = daten + dialog.noteHistory.append([row[0], row[1], row[2], row[3], daten+"\n"]) + + dialog.vbox.show_all() + dialog.set_size_request(600, 380) + + if dialog.run() == gtk.RESPONSE_ACCEPT: + print "saving" + self.save_note() + data = dialog.get_selected_row() + if data is not None: + self._db.speichereSQL(data[2], data[3].split(" <> "), rowid = self.noteId) + _moduleLogger.info("loading History") + self._update_noteslist() + + dialog.destroy() def _get_title(self, buf): """ @@ -177,13 +194,18 @@ class Notizen(gtk.HBox): self._noteBodyView.grab_focus() return False - def _update_noteslist(self, data = None, data2 = None): + def _update_noteslist(self, *args): if self._pos != -1: self.save_note() + if args: + data = args[0] + else: + data = None + try: (pos, key, value) = self._noteslist.get_selection_data() - if (pos == -1): + if pos == -1: return except StandardError: if data != "new": @@ -201,12 +223,12 @@ class Notizen(gtk.HBox): else: self._pos = pos self.noteId, pcdatum, self._categoryName, self._noteBody = self._db.loadNote(key) - self._historyStatusLabel.set_text(time.strftime(_("Last change: %d.%m.%y %H:%M"), time.localtime(pcdatum))) buf = self._noteBodyView.get_buffer() buf.set_text(self._noteBody) gobject.timeout_add(200, self._set_focus) + @gtk_toolbox.log_exception(_moduleLogger) def _on_note_changed(self, widget = None, data = None): if self._pos == -1 or self.noteId == -1: return @@ -219,9 +241,11 @@ class Notizen(gtk.HBox): if value != title: self._noteslist.change_item(self._pos, title, self.noteId) + @gtk_toolbox.log_exception(_moduleLogger) def _on_add_note(self, widget = None, data = None): self._update_noteslist("new") + @gtk_toolbox.log_exception(_moduleLogger) def _on_delete_note(self, widget = None, data = None): if (self.noteId == -1): return @@ -235,37 +259,3 @@ class Notizen(gtk.HBox): self._noteslist.remove_item(self._pos) self._pos = -1 self._noteBodyView.get_buffer().set_text("") - - def _on_show_history(self, widget = None, data = None, label = None): - if self.noteId == -1: - mbox = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, _("No note selected.")) - response = mbox.run() - mbox.hide() - mbox.destroy() - return - - rows = self._db.getNoteHistory(self.noteId) - - import history - dialog = history.Dialog() - - lastNoteStr = "" - for row in rows: - daten = row[4][1] - if daten != "" and lastNoteStr != daten: - lastNoteStr = daten - dialog.noteHistory.append([row[0], row[1], row[2], row[3], daten+"\n"]) - - dialog.vbox.show_all() - dialog.set_size_request(600, 380) - - if dialog.run() == gtk.RESPONSE_ACCEPT: - print "saving" - self.save_note() - data = dialog.get_selected_row() - if data is not None: - self._db.speichereSQL(data[2], data[3].split(" <> "), rowid = self.noteId) - _moduleLogger.info("loading History") - self._update_noteslist() - - dialog.destroy()