import gobject
import gtk
+import gtk_toolbox
+import hildonize
try:
_
"""
__gsignals__ = {
- 'reload_notes' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
+ 'category_changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
}
+ ALL_CATEGORIES = _("all")
+ UNDEFINED_CATEGORY = "undefined"
+
def __init__(self, db):
- self._lastCategory = ""
self._db = db
+ self._lastCategory = 1
- gtk.HBox.__init__(self, homogeneous = False, spacing = 3)
_moduleLogger.info("libkopfzeile, init")
+ gtk.HBox.__init__(self, homogeneous = False, spacing = 3)
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)
- 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)
searchHBox.pack_start(self._searchEntry, expand = True, fill = True, padding = 0)
self._searchEntry.connect("changed", self.search_entry_changed, None)
- def category_combo_changed(self, widget = None, data = None):
- _moduleLogger.debug("comboCategoryChanged")
- if self._lastCategory != self.categoryCombo.get_active():
- sql = "UPDATE categories SET liste = ? WHERE id = 1"
- self._db.speichereSQL(sql, (self.categoryCombo.get_active(), ))
-
- self.emit("reload_notes")
-
- def search_entry_changed(self, widget = None, data = None):
- _moduleLogger.debug("search_entry_changed")
- self.emit("reload_notes")
-
def get_category(self):
- entry = self.categoryCombo.get_child()
- category = entry.get_text()
- if category == _("all"):
+ category = self._categorySelectorButton.get_label()
+ if category == self.ALL_CATEGORIES:
category = "%"
if category == "":
- category = "undefined"
- self.categoryCombo.set_active(1)
- self.categoryCombo.show()
+ category = self.UNDEFINED_CATEGORY
+ self._categorySelectorButton.set_label(category)
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)
+ userSelection = hildonize.touch_selector_entry(
+ window,
+ "Categories",
+ self._categories,
+ self._categorySelectorButton.get_label(),
+ )
+ self.set_category(userSelection)
+
+ 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._get_category_index(), ))
+ self.emit("category_changed")
+
+ def search_entry_changed(self, widget = None, data = None):
+ _moduleLogger.debug("search_entry_changed")
+ self.emit("category_changed")
+
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):
+ category = self.get_category()
+
+ sql = "UPDATE notes SET category = ? WHERE category = ?"
+ self._db.speichereSQL(sql, (self.UNDEFINED_CATEGORY, category))
+ sql = "DELETE FROM categories WHERE liste = ?"
+ self._db.speichereSQL(sql, (category, ))
+
+ pos = self._get_category_index()
+ if 1 < pos:
+ del self._categories[pos]
+ self._categorySelectorButton.set_label(self.ALL_CATEGORIES)
def get_search_pattern(self):
return self._searchEntry.get_text()
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)
-
- self.categoryCombo.append_text(_('all'))
- self.categoryCombo.append_text('undefined')
+ del self._categories[2:] # Leave ALL_CATEGORIES and UNDEFINED_CATEGORY in
- if cats is not None and 0 < len(cats):
+ 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):
- self.categoryCombo.set_active(int(rows[0][1]))
+ index = int(rows[0][1])
+ 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()