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 class Kopfzeile(gtk.HBox):
28 'reload_notes' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
31 def __init__(self, db):
32 self._lastCategory = ""
35 gtk.HBox.__init__(self, homogeneous = False, spacing = 3)
36 logging.info("libkopfzeile, init")
38 categoryHBox = gtk.HBox()
39 self.pack_start(categoryHBox, expand = False, fill = True, padding = 0)
41 label = gtk.Label(_("Category: "))
42 categoryHBox.pack_start(label, expand = False, fill = True, padding = 0)
44 self.categoryCombo = gtk.combo_box_entry_new_text()
45 categoryHBox.pack_start(self.categoryCombo, expand = True, fill = True, padding = 0)
46 self.load_categories()
47 self.categoryCombo.connect("changed", self.category_combo_changed, None)
49 searchHBox = gtk.HBox()
50 self.pack_start(searchHBox, expand = True, fill = True, padding = 0)
52 label = gtk.Label(_("Search: "))
53 searchHBox.pack_start(label, expand = False, fill = True, padding = 0)
55 self._searchEntry = gtk.Entry()
56 searchHBox.pack_start(self._searchEntry, expand = True, fill = True, padding = 0)
57 self._searchEntry.connect("changed", self.search_entry_changed, None)
59 def category_combo_changed(self, widget = None, data = None):
60 logging.debug("comboCategoryChanged")
61 if self._lastCategory != self.categoryCombo.get_active():
62 sql = "UPDATE categories SET liste = ? WHERE id = 1"
63 self._db.speichereSQL(sql, (self.categoryCombo.get_active(), ))
65 self.emit("reload_notes")
67 def search_entry_changed(self, widget = None, data = None):
68 logging.debug("search_entry_changed")
69 self.emit("reload_notes")
71 def get_category(self):
72 entry = self.categoryCombo.get_child()
73 category = entry.get_text()
74 if category == _("all"):
77 category = "undefined"
78 self.categoryCombo.set_active(1)
79 self.categoryCombo.show()
82 def define_this_category(self):
83 category = self.get_category()
85 model = self.categoryCombo.get_model()
86 n = len(self.categoryCombo.get_model())
91 if (model[i][0] == category):
92 #self.categoryCombo.set_active(i)
94 if (model[i][0]!= "%"):
95 cats.append(model[i][0])
98 if (active == -1) and (category!= "%"):
99 self.categoryCombo.append_text(category)
100 sql = "INSERT INTO categories (id, liste) VALUES (0, ?)"
101 self._db.speichereSQL(sql, (category, ))
102 self.categoryCombo.set_active(i)
104 def get_search_pattern(self):
105 return self._searchEntry.get_text()
107 def load_categories(self):
108 sql = "CREATE TABLE categories (id TEXT , liste TEXT)"
109 self._db.speichereSQL(sql)
111 sql = "SELECT id, liste FROM categories WHERE id = 0 ORDER BY liste"
112 rows = self._db.ladeSQL(sql)
114 if rows is not None and 0 < len(rows):
118 sql = "SELECT * FROM categories WHERE id = 1"
119 rows = self._db.ladeSQL(sql)
120 if rows is None or len(rows) == 0:
121 sql = "INSERT INTO categories (id, liste) VALUES (1, 1)"
122 self._db.speichereSQL(sql)
124 #self.categoryCombo.clear()
125 while 0 < len(self.categoryCombo.get_model()):
126 self.categoryCombo.remove_text(0)
128 self.categoryCombo.append_text(_('all'))
129 self.categoryCombo.append_text('undefined')
131 if cats is not None and 0 < len(cats):
133 self.categoryCombo.append_text(cat)
135 sql = "SELECT * FROM categories WHERE id = 1"
136 rows = self._db.ladeSQL(sql)
137 if rows is not None and 0 < len(rows):
138 self.categoryCombo.set_active(int(rows[0][1]))
140 self.categoryCombo.set_active(1)
142 self._lastCategory = self.categoryCombo.get_active()