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())
90 for i, row in enumerate(model):
91 if row[0] == category:
96 if active == -1 and category != "%":
97 self.categoryCombo.append_text(category)
98 sql = "INSERT INTO categories (id, liste) VALUES (0, ?)"
99 self._db.speichereSQL(sql, (category, ))
100 self.categoryCombo.set_active(i)
102 def get_search_pattern(self):
103 return self._searchEntry.get_text()
105 def load_categories(self):
106 sql = "CREATE TABLE categories (id TEXT , liste TEXT)"
107 self._db.speichereSQL(sql)
109 sql = "SELECT id, liste FROM categories WHERE id = 0 ORDER BY liste"
110 rows = self._db.ladeSQL(sql)
112 if rows is not None and 0 < len(rows):
116 sql = "SELECT * FROM categories WHERE id = 1"
117 rows = self._db.ladeSQL(sql)
118 if rows is None or len(rows) == 0:
119 sql = "INSERT INTO categories (id, liste) VALUES (1, 1)"
120 self._db.speichereSQL(sql)
122 #self.categoryCombo.clear()
123 while 0 < len(self.categoryCombo.get_model()):
124 self.categoryCombo.remove_text(0)
126 self.categoryCombo.append_text(_('all'))
127 self.categoryCombo.append_text('undefined')
129 if cats is not None and 0 < len(cats):
131 self.categoryCombo.append_text(cat)
133 sql = "SELECT * FROM categories WHERE id = 1"
134 rows = self._db.ladeSQL(sql)
135 if rows is not None and 0 < len(rows):
136 self.categoryCombo.set_active(int(rows[0][1]))
138 self.categoryCombo.set_active(1)
140 self._lastCategory = self.categoryCombo.get_active()