1 #!/usr/bin/env python2.5
2 # -*- coding: utf-8 -*-
6 * Copyright (C) 2007 Christoph Würstle
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
26 class Kopfzeile(gtk.HBox):
29 'reload_notes' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,()),
32 def comboCategoryChanged(self, widget=None, data=None):
33 logging.debug("comboCategoryChanged")
34 if (self.lastCategory!=self.comboCategory.get_active()):
35 sql="UPDATE categories SET liste=? WHERE id=1"
36 self.db.speichereSQL(sql,(self.comboCategory.get_active(),))
38 self.emit("reload_notes")
40 def searchEntryChanged(self, widget=None, data=None):
41 logging.debug("searchEntryChanged")
42 self.emit("reload_notes")
45 def getCategory(self):
46 entry = self.comboCategory.get_child()
47 category=entry.get_text()
48 if (category==_("all")):
52 self.comboCategory.set_active(1)
53 self.comboCategory.show()
56 def defineThisCategory(self):
57 category=self.getCategory()
59 model = self.comboCategory.get_model()
60 n=len(self.comboCategory.get_model())
66 if (model[i][0]==category):
67 #self.comboCategory.set_active(i)
69 if (model[i][0]!="%"):
70 cats.append(model[i][0])
73 if (active==-1)and(category!="%"):
74 self.comboCategory.append_text(category)
75 sql="INSERT INTO categories (id,liste) VALUES (0,?)"
76 self.db.speichereSQL(sql,(category,))
77 self.comboCategory.set_active(i)
79 def getSearchPattern(self):
80 return self.searchEntry.get_text()
83 def loadCategories(self):
84 sql="CREATE TABLE categories (id TEXT , liste TEXT)"
85 self.db.speichereSQL(sql)
87 sql="SELECT id,liste FROM categories WHERE id=0 ORDER BY liste"
88 rows=self.db.ladeSQL(sql)
90 if (rows!=None)and(len(rows)>0):
92 self.cats.append(row[1])
95 sql="SELECT * FROM categories WHERE id=1"
96 rows=self.db.ladeSQL(sql)
98 if (rows==None)or(len(rows)==0):
99 sql="INSERT INTO categories (id, liste) VALUES (1,1)"
100 self.db.speichereSQL(sql)
102 #self.comboCategory.clear()
103 while len(self.comboCategory.get_model())>0:
104 self.comboCategory.remove_text(0)
106 self.comboCategory.append_text(_('all'))
107 self.comboCategory.append_text('undefined')
109 if (self.cats!=None)and(len(self.cats)>0):
110 for cat in self.cats:
112 self.comboCategory.append_text(cat)
114 sql="SELECT * FROM categories WHERE id=1"
115 rows=self.db.ladeSQL(sql)
116 if (rows!=None)and(len(rows)>0):
117 self.comboCategory.set_active(int(rows[0][1]))
119 self.comboCategory.set_active(1)
121 self.lastCategory=self.comboCategory.get_active()
124 def __init__(self,db):
128 gtk.HBox.__init__(self,homogeneous=False, spacing=3)
129 logging.info("libkopfzeile, init")
131 label=gtk.Label(_("Search: "))
132 self.pack_start(label, expand=False, fill=True, padding=0)
134 self.searchEntry=gtk.Entry()
135 self.pack_start(self.searchEntry, expand=True, fill=True, padding=0)
136 self.searchEntry.connect("changed", self.searchEntryChanged, None)
139 self.pack_start(label, expand=True, fill=True, padding=0)
141 label=gtk.Label(_("Category: "))
142 self.pack_start(label, expand=False, fill=True, padding=0)
144 self.comboCategory = gtk.combo_box_entry_new_text()
146 self.pack_start(self.comboCategory, expand=True, fill=True, padding=0)
148 self.loadCategories()
150 self.comboCategory.connect("changed", self.comboCategoryChanged, None)