1 #!/usr/bin/env python2.5
2 # -*- coding: utf-8 -*-
5 Copyright (C) 2007 Christoph Würstle
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 2 as
9 published by the Free Software Foundation.
25 _moduleLogger = logging.getLogger("kopfzeile")
28 class Kopfzeile(gtk.HBox):
34 'reload_notes' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
37 def __init__(self, db):
38 self._lastCategory = ""
41 gtk.HBox.__init__(self, homogeneous = False, spacing = 3)
42 _moduleLogger.info("libkopfzeile, init")
44 categoryHBox = gtk.HBox()
45 self.pack_start(categoryHBox, expand = False, fill = True, padding = 0)
47 label = gtk.Label(_("Category: "))
48 categoryHBox.pack_start(label, expand = False, fill = True, padding = 0)
50 self.categoryCombo = gtk.combo_box_entry_new_text()
51 categoryHBox.pack_start(self.categoryCombo, expand = True, fill = True, padding = 0)
52 self.load_categories()
53 self.categoryCombo.connect("changed", self.category_combo_changed, None)
55 searchHBox = gtk.HBox()
56 self.pack_start(searchHBox, expand = True, fill = True, padding = 0)
58 label = gtk.Label(_("Search: "))
59 searchHBox.pack_start(label, expand = False, fill = True, padding = 0)
61 self._searchEntry = gtk.Entry()
62 searchHBox.pack_start(self._searchEntry, expand = True, fill = True, padding = 0)
63 self._searchEntry.connect("changed", self.search_entry_changed, None)
65 def category_combo_changed(self, widget = None, data = None):
66 _moduleLogger.debug("comboCategoryChanged")
67 if self._lastCategory != self.categoryCombo.get_active():
68 sql = "UPDATE categories SET liste = ? WHERE id = 1"
69 self._db.speichereSQL(sql, (self.categoryCombo.get_active(), ))
71 self.emit("reload_notes")
73 def search_entry_changed(self, widget = None, data = None):
74 _moduleLogger.debug("search_entry_changed")
75 self.emit("reload_notes")
77 def get_category(self):
78 entry = self.categoryCombo.get_child()
79 category = entry.get_text()
80 if category == _("all"):
83 category = "undefined"
84 self.categoryCombo.set_active(1)
85 self.categoryCombo.show()
88 def define_this_category(self):
89 category = self.get_category()
91 model = self.categoryCombo.get_model()
92 n = len(self.categoryCombo.get_model())
96 for i, row in enumerate(model):
97 if row[0] == category:
102 if active == -1 and category != "%":
103 self.categoryCombo.append_text(category)
104 sql = "INSERT INTO categories (id, liste) VALUES (0, ?)"
105 self._db.speichereSQL(sql, (category, ))
106 self.categoryCombo.set_active(i)
108 def get_search_pattern(self):
109 return self._searchEntry.get_text()
111 def load_categories(self):
112 sql = "CREATE TABLE categories (id TEXT , liste TEXT)"
113 self._db.speichereSQL(sql)
115 sql = "SELECT id, liste FROM categories WHERE id = 0 ORDER BY liste"
116 rows = self._db.ladeSQL(sql)
118 if rows is not None and 0 < len(rows):
122 sql = "SELECT * FROM categories WHERE id = 1"
123 rows = self._db.ladeSQL(sql)
124 if rows is None or len(rows) == 0:
125 sql = "INSERT INTO categories (id, liste) VALUES (1, 1)"
126 self._db.speichereSQL(sql)
128 #self.categoryCombo.clear()
129 while 0 < len(self.categoryCombo.get_model()):
130 self.categoryCombo.remove_text(0)
132 self.categoryCombo.append_text(_('all'))
133 self.categoryCombo.append_text('undefined')
135 if cats is not None and 0 < len(cats):
137 self.categoryCombo.append_text(cat)
139 sql = "SELECT * FROM categories WHERE id = 1"
140 rows = self._db.ladeSQL(sql)
141 if rows is not None and 0 < len(rows):
142 self.categoryCombo.set_active(int(rows[0][1]))
144 self.categoryCombo.set_active(1)
146 self._lastCategory = self.categoryCombo.get_active()