From e747064bced213416fda192d7bfea5157c931db5 Mon Sep 17 00:00:00 2001 From: epage Date: Sat, 9 Jan 2010 02:37:13 +0000 Subject: [PATCH] Not the prettiest (yet) but now on the touch selector entry git-svn-id: file:///svnroot/quicknote/trunk@100 bb7704e3-badb-4cfa-9ab3-9374dc87eaa2 --- src/kopfzeile.py | 76 +++++++++++++++----------------------------------- src/quicknote_gtk.py | 2 +- support/builddeb.py | 1 + 3 files changed, 25 insertions(+), 54 deletions(-) diff --git a/src/kopfzeile.py b/src/kopfzeile.py index a1d00c4..7eb7c35 100644 --- a/src/kopfzeile.py +++ b/src/kopfzeile.py @@ -40,8 +40,8 @@ class Kopfzeile(gtk.HBox): UNDEFINED_CATEGORY = "undefined" def __init__(self, db): - self._lastCategory = "" self._db = db + self._lastCategory = 1 _moduleLogger.info("libkopfzeile, init") gtk.HBox.__init__(self, homogeneous = False, spacing = 3) @@ -49,18 +49,12 @@ class Kopfzeile(gtk.HBox): categoryHBox = gtk.HBox() self.pack_start(categoryHBox, expand = False, fill = True, padding = 0) - label = gtk.Label(_("Category: ")) - categoryHBox.pack_start(label, expand = False, fill = True, padding = 0) - self._categories = [self.ALL_CATEGORIES, self.UNDEFINED_CATEGORY] self._categorySelectorButton = gtk.Button(self.UNDEFINED_CATEGORY) self._categorySelectorButton.connect("clicked", self._on_category_selector) - #categoryHBox.pack_start(self._categorySelectorButton) + categoryHBox.pack_start(self._categorySelectorButton) - self.categoryCombo = gtk.combo_box_entry_new_text() - categoryHBox.pack_start(self.categoryCombo, expand = True, fill = True, padding = 0) self.load_categories() - self.categoryCombo.connect("changed", self.category_combo_changed, None) searchHBox = gtk.HBox() self.pack_start(searchHBox, expand = True, fill = True, padding = 0) @@ -73,17 +67,21 @@ class Kopfzeile(gtk.HBox): self._searchEntry.connect("changed", self.search_entry_changed, None) def get_category(self): - entry = self.categoryCombo.get_child() - category = entry.get_text() + category = self._categorySelectorButton.get_label() if category == self.ALL_CATEGORIES: category = "%" if category == "": category = self.UNDEFINED_CATEGORY self._categorySelectorButton.set_label(category) - self.categoryCombo.set_active(1) - self.categoryCombo.show() return category + def _get_category_index(self): + categoryName = self._categorySelectorButton.get_label() + try: + return self._categories.index(categoryName) + except ValueError: + return -1 + @gtk_toolbox.log_exception(_moduleLogger) def _on_category_selector(self, *args): window = gtk_toolbox.find_parent_window(self) @@ -93,20 +91,13 @@ class Kopfzeile(gtk.HBox): self._categories, self._categorySelectorButton.get_label(), ) - if userSelection == self._categorySelectorButton.get_label(): - return - - sql = "UPDATE categories SET liste = ? WHERE id = 1" - self._db.speichereSQL(sql, (self.categoryCombo.get_active(), )) - - self.emit("category_changed") + self.set_category(userSelection) - def category_combo_changed(self, widget = None, data = None): - _moduleLogger.debug("comboCategoryChanged") - if self._lastCategory != self.categoryCombo.get_active(): + def set_category(self, categoryName = None): + if categoryName is not None and categoryName != self._categorySelectorButton.get_label(): + self._categorySelectorButton.set_label(categoryName) sql = "UPDATE categories SET liste = ? WHERE id = 1" - self._db.speichereSQL(sql, (self.categoryCombo.get_active(), )) - + self._db.speichereSQL(sql, (self._get_category_index(), )) self.emit("category_changed") def search_entry_changed(self, widget = None, data = None): @@ -115,24 +106,13 @@ class Kopfzeile(gtk.HBox): def define_this_category(self): category = self.get_category() + catIndex = self._get_category_index() + cats = self._categories[1:] # Skip ALL_CATEGORIES - model = self.categoryCombo.get_model() - n = len(self.categoryCombo.get_model()) - i = 0 - active = -1 - cats = [] - for i, row in enumerate(model): - if row[0] == category: - active = i - if row[0] != "%": - cats.append(row[0]) - - if active == -1 and category != "%": - self.categoryCombo.append_text(category) + if catIndex == -1 and category != "%": self._categories.append(category) sql = "INSERT INTO categories (id, liste) VALUES (0, ?)" self._db.speichereSQL(sql, (category, )) - self.categoryCombo.set_active(i) self._categorySelectorButton.set_label(category) def delete_this_category(self): @@ -142,11 +122,10 @@ class Kopfzeile(gtk.HBox): self._db.speichereSQL(sql, (self.UNDEFINED_CATEGORY, category)) sql = "DELETE FROM categories WHERE liste = ?" self._db.speichereSQL(sql, (category, )) - model = self.categoryCombo.get_model() - pos = self.categoryCombo.get_active() + + pos = self._get_category_index() if 1 < pos: - self.categoryCombo.remove_text(pos) - self.categoryCombo.set_active(0) + del self._categories[pos] self._categorySelectorButton.set_label(self.ALL_CATEGORIES) def get_search_pattern(self): @@ -169,27 +148,18 @@ class Kopfzeile(gtk.HBox): sql = "INSERT INTO categories (id, liste) VALUES (1, 1)" self._db.speichereSQL(sql) - #self.categoryCombo.clear() - while 0 < len(self.categoryCombo.get_model()): - self.categoryCombo.remove_text(0) - del self._categories[2:] - - self.categoryCombo.append_text(self.ALL_CATEGORIES) - self.categoryCombo.append_text(self.UNDEFINED_CATEGORY) + del self._categories[2:] # Leave ALL_CATEGORIES and UNDEFINED_CATEGORY in if cats is not None: for cat in cats: - self.categoryCombo.append_text(cat) self._categories.append(cat) sql = "SELECT * FROM categories WHERE id = 1" rows = self._db.ladeSQL(sql) if rows is not None and 0 < len(rows): index = int(rows[0][1]) - self.categoryCombo.set_active(index) self._categorySelectorButton.set_label(self._categories[index]) else: - self.categoryCombo.set_active(1) self._categorySelectorButton.set_label(self.UNDEFINED_CATEGORY) - self._lastCategory = self.categoryCombo.get_active() + self._lastCategory = self._get_category_index() diff --git a/src/quicknote_gtk.py b/src/quicknote_gtk.py index 162782b..e8aa54c 100644 --- a/src/quicknote_gtk.py +++ b/src/quicknote_gtk.py @@ -405,7 +405,7 @@ class QuicknoteProgram(hildonize.get_app_class()): noteid, pcdatum, category, note = self._db.loadNote(self._notizen.noteId) self._db.saveNote(noteid, note, cat_id, pcdatum = None) - self._topBox.category_combo_changed() + self._topBox.set_category() # force it to update else: mbox = gtk.MessageDialog(self._window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("No note selected.")) response = mbox.run() diff --git a/support/builddeb.py b/support/builddeb.py index d71587d..5f35c7b 100755 --- a/support/builddeb.py +++ b/support/builddeb.py @@ -23,6 +23,7 @@ __build__ = constants.__build__ __changelog__ = """ 0.7.10 * Moved history to the menu/appmenu + * Switched category selection over to a touch selector entry, making it prettier and easier * Ctrl+w/q to quit 0.7.9 -- 1.7.9.5