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.comboCategory = gtk.combo_box_entry_new_text()
45 categoryHBox.pack_start(self.comboCategory, expand = True, fill = True, padding = 0)
47 self.comboCategory.connect("changed", self.comboCategoryChanged, 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.searchEntryChanged, None)
59 def comboCategoryChanged(self, widget = None, data = None):
60 logging.debug("comboCategoryChanged")
61 if self.lastCategory != self.comboCategory.get_active():
62 sql = "UPDATE categories SET liste = ? WHERE id = 1"
63 self.db.speichereSQL(sql, (self.comboCategory.get_active(), ))
65 self.emit("reload_notes")
67 def searchEntryChanged(self, widget = None, data = None):
68 logging.debug("searchEntryChanged")
69 self.emit("reload_notes")
71 def getCategory(self):
72 entry = self.comboCategory.get_child()
73 category = entry.get_text()
74 if category == _("all"):
77 category = "undefined"
78 self.comboCategory.set_active(1)
79 self.comboCategory.show()
82 def defineThisCategory(self):
83 category = self.getCategory()
85 model = self.comboCategory.get_model()
86 n = len(self.comboCategory.get_model())
91 if (model[i][0] == category):
92 #self.comboCategory.set_active(i)
94 if (model[i][0]!= "%"):
95 cats.append(model[i][0])
98 if (active == -1) and (category!= "%"):
99 self.comboCategory.append_text(category)
100 sql = "INSERT INTO categories (id, liste) VALUES (0, ?)"
101 self.db.speichereSQL(sql, (category, ))
102 self.comboCategory.set_active(i)
104 def getSearchPattern(self):
105 return self.searchEntry.get_text()
107 def loadCategories(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.comboCategory.clear()
125 while 0 < len(self.comboCategory.get_model()):
126 self.comboCategory.remove_text(0)
128 self.comboCategory.append_text(_('all'))
129 self.comboCategory.append_text('undefined')
131 if cats is not None and 0 < len(cats):
133 self.comboCategory.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.comboCategory.set_active(int(rows[0][1]))
140 self.comboCategory.set_active(1)
142 self.lastCategory = self.comboCategory.get_active()