Tagging the pre-epage code
[quicknote] / src / quicknoteclasses / libkopfzeile.py
1 #!/usr/bin/env python2.5
2 # -*- coding: utf-8 -*-
3  
4 """
5  *
6  *  Copyright (C) 2007 Christoph Würstle
7  *
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.
11  *
12  *
13 """
14  
15 import gobject
16 import time
17 import random
18 import logging
19
20 import gtk
21
22 import libspeichern
23 import string
24
25
26 class Kopfzeile(gtk.HBox):
27         
28         __gsignals__ = {
29                 'reload_notes' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,()),
30         }
31
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(),))
37                         
38                 self.emit("reload_notes")
39         
40         def searchEntryChanged(self, widget=None, data=None):
41                 logging.debug("searchEntryChanged")
42                 self.emit("reload_notes")
43                 
44
45         def getCategory(self):
46                 entry = self.comboCategory.get_child()
47                 category=entry.get_text()
48                 if (category==_("all")):
49                         category="%"
50                 if (category==""):
51                         category="undefined"
52                         self.comboCategory.set_active(1)
53                         self.comboCategory.show()
54                 return category
55         
56         def defineThisCategory(self):
57                 category=self.getCategory()
58                 
59                 model = self.comboCategory.get_model()
60                 n=len(self.comboCategory.get_model())
61                 i=0
62                 active=-1
63                 cats=[]
64                 while i<n:
65                         
66                         if (model[i][0]==category): 
67                                 #self.comboCategory.set_active(i)
68                                 active=i
69                         if (model[i][0]!="%"):
70                                 cats.append(model[i][0])
71                         i+=1
72                 
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)
78                         
79         def getSearchPattern(self):
80                 return self.searchEntry.get_text()
81
82
83         def loadCategories(self):
84                 sql="CREATE TABLE categories (id TEXT , liste TEXT)"
85                 self.db.speichereSQL(sql)
86                 
87                 sql="SELECT id,liste FROM categories WHERE id=0 ORDER BY liste"
88                 rows=self.db.ladeSQL(sql)
89                 self.cats=[]
90                 if (rows!=None)and(len(rows)>0):
91                         for row in rows:
92                                 self.cats.append(row[1])
93                                 
94                         
95                 sql="SELECT * FROM categories WHERE id=1"
96                 rows=self.db.ladeSQL(sql)
97                 cats=None
98                 if (rows==None)or(len(rows)==0):
99                         sql="INSERT INTO categories (id, liste) VALUES (1,1)"
100                         self.db.speichereSQL(sql)
101                         
102                 #self.comboCategory.clear()
103                 while len(self.comboCategory.get_model())>0:
104                         self.comboCategory.remove_text(0)
105                         
106                 self.comboCategory.append_text(_('all'))
107                 self.comboCategory.append_text('undefined')
108                 
109                 if (self.cats!=None)and(len(self.cats)>0):
110                         for cat in self.cats:
111                                 #print cat
112                                 self.comboCategory.append_text(cat)
113                                 
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]))
118                 else:   
119                         self.comboCategory.set_active(1)
120                         
121                 self.lastCategory=self.comboCategory.get_active()
122
123
124         def __init__(self,db):
125                 
126                 self.db=db
127
128                 gtk.HBox.__init__(self,homogeneous=False, spacing=3)
129                 logging.info("libkopfzeile, init")
130                 
131                 label=gtk.Label(_("Search:  "))
132                 self.pack_start(label, expand=False, fill=True, padding=0)
133                 
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)
137                 
138                 label=gtk.Label("   ")
139                 self.pack_start(label, expand=True, fill=True, padding=0)
140                 
141                 label=gtk.Label(_("Category:  "))
142                 self.pack_start(label, expand=False, fill=True, padding=0)
143                 
144                 self.comboCategory = gtk.combo_box_entry_new_text()
145
146                 self.pack_start(self.comboCategory, expand=True, fill=True, padding=0)
147                 
148                 self.loadCategories()
149                 
150                 self.comboCategory.connect("changed", self.comboCategoryChanged, None)
151                 
152                 
153
154
155