2 # -*- coding: utf-8 -*-
5 This file is part of Multilist.
7 Multilist is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 Multilist is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Multilist. If not, see <http://www.gnu.org/licenses/>.
20 Copyright (C) 2008 Christoph Würstle
37 _moduleLogger = logging.getLogger(__name__)
40 class Selection(gtk.HBox):
43 'changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING, gobject.TYPE_STRING)),
44 #'changedCategory': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING, gobject.TYPE_STRING))
47 def __init__(self, db, isHildon):
48 gtk.HBox.__init__(self, homogeneous = False, spacing = 3)
51 self.isHildon = isHildon
53 _moduleLogger.info("libSelection, init")
55 label = gtk.Label(_("List:"))
56 self.pack_start(label, expand = False, fill = True, padding = 0)
58 self.comboList = gtk.combo_box_entry_new_text()
59 self.comboList.set_size_request(180, -1)
60 self.pack_start(self.comboList, expand = False, fill = True, padding = 0)
62 label = gtk.Label(_(" Category:"))
63 self.pack_start(label, expand = False, fill = True, padding = 0)
65 self.comboCategory = gtk.combo_box_entry_new_text()
66 self.comboCategory.set_size_request(180, -1)
67 self.pack_start(self.comboCategory, expand = False, fill = True, padding = 0)
69 self.comboList.connect("changed", self.comboList_changed, None)
70 self.comboCategory.connect("changed", self.comboCategory_changed, None)
72 label = gtk.Label(_(" View:"))
73 self.pack_start(label, expand = False, fill = True, padding = 0)
75 self.radio_all = gtk.RadioButton(group = None, label = _("All"), use_underline = True)
76 self.pack_start(self.radio_all, expand = False, fill = True, padding = 0)
77 self.radio_active = gtk.RadioButton(group = self.radio_all, label = _("Active"), use_underline = True)
78 self.pack_start(self.radio_active, expand = False, fill = True, padding = 0)
79 self.radio_all.connect("toggled", self.radioActive_changed, None)
82 model = self.comboList.get_model()
84 #self.comboList.remove(0)
86 sql = "SELECT DISTINCT list FROM items ORDER BY list"
87 rows = self.db.ladeSQL(sql)
88 if ((rows is not None)and(len(rows)>0)):
90 self.comboList.append_text(row[0])
92 self.comboList.append_text("default")
94 s = self.db.ladeDirekt("comboListText")
96 self.comboList.get_child().set_text(s)
98 self.comboList.set_active(0)
100 @gtk_toolbox.log_exception(_moduleLogger)
101 def comboList_changed(self, widget = None, data = None):
102 #self.comboCategory.set_model(None)
103 #print "reload categories"
104 while len(self.comboCategory.get_model())>0:
105 self.comboCategory.remove_text(0)
107 sql = "SELECT DISTINCT category FROM items WHERE list = ? ORDER BY category"
108 rows = self.db.ladeSQL(sql, (self.get_list(), ))
110 self.comboCategory.append_text(_("all"))
111 if ((rows is not None)and(len(rows)>0)):
113 if (row[0] != _("all")):
114 self.comboCategory.append_text(row[0])
116 s = self.db.ladeDirekt("comboCategoryText"+self.comboList.get_child().get_text())
118 self.comboCategory.get_child().set_text(s)
120 self.comboCategory.set_active(0)
122 self.emit("changed", "list", "")
123 self.db.speichereDirekt("comboListText", self.comboList.get_child().get_text())
125 @gtk_toolbox.log_exception(_moduleLogger)
126 def comboCategory_changed(self, widget = None, data = None):
127 #_moduleLogger.info("Klasse geaendert zu ")
128 #self.hauptRegister.set_current_page(0)
129 self.emit("changed", "category", "")
130 if self.comboCategory.get_active()>-1:
131 self.db.speichereDirekt("comboCategoryText"+self.comboList.get_child().get_text(), self.comboCategory.get_child().get_text())
133 @gtk_toolbox.log_exception(_moduleLogger)
134 def radioActive_changed(self, widget, data = None):
135 self.emit("changed", "radio", "")
137 def comboLists_check_for_update(self):
138 if self.comboCategory.get_active() == -1:
139 model = self.comboCategory.get_model()
141 cat = self.get_category()
146 self.comboCategory.append_text(self.get_category())
147 self.comboCategory.set_active(len(self.comboCategory.get_model())-1)
148 if self.comboList.get_active() == -1:
149 model = self.comboList.get_model()
151 list = self.get_list()
156 self.comboList.append_text(self.get_list())
157 self.comboList.set_active(len(self.comboList.get_model())-1)
160 _moduleLogger.warning("Laden der aktuellen position noch nicht implementiert")
163 _moduleLogger.warning("Speichern der aktuellen position noch nicht implementiert")
165 def getIsHildon(self):
168 def get_category(self, select = False):
169 s = self.comboCategory.get_child().get_text()
171 if (select == False):
177 def set_category(self, category):
178 self.comboCategory.get_child().set_text(category)
180 def set_list(self, listname):
181 self.comboList.get_child().set_text(listname)
184 return self.comboList.get_child().get_text()
186 def get_status(self):
187 #return self.comboCategory.get_child().get_text()
188 if self.radio_all.get_active() == True: