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)
73 model = self.comboList.get_model()
75 #self.comboList.remove(0)
77 sql = "SELECT DISTINCT list FROM items ORDER BY list"
78 rows = self.db.ladeSQL(sql)
79 if ((rows is not None)and(len(rows)>0)):
81 self.comboList.append_text(row[0])
83 self.comboList.append_text("default")
85 s = self.db.ladeDirekt("comboListText")
87 self.comboList.get_child().set_text(s)
89 self.comboList.set_active(0)
91 @gtk_toolbox.log_exception(_moduleLogger)
92 def comboList_changed(self, widget = None, data = None):
93 #self.comboCategory.set_model(None)
94 #print "reload categories"
95 while len(self.comboCategory.get_model())>0:
96 self.comboCategory.remove_text(0)
98 sql = "SELECT DISTINCT category FROM items WHERE list = ? ORDER BY category"
99 rows = self.db.ladeSQL(sql, (self.get_list(), ))
101 self.comboCategory.append_text(_("all"))
102 if ((rows is not None)and(len(rows)>0)):
104 if (row[0] != _("all")):
105 self.comboCategory.append_text(row[0])
107 s = self.db.ladeDirekt("comboCategoryText"+self.comboList.get_child().get_text())
109 self.comboCategory.get_child().set_text(s)
111 self.comboCategory.set_active(0)
113 self.emit("changed", "list", "")
114 self.db.speichereDirekt("comboListText", self.comboList.get_child().get_text())
116 @gtk_toolbox.log_exception(_moduleLogger)
117 def comboCategory_changed(self, widget = None, data = None):
118 #_moduleLogger.info("Klasse geaendert zu ")
119 #self.hauptRegister.set_current_page(0)
120 self.emit("changed", "category", "")
121 if self.comboCategory.get_active()>-1:
122 self.db.speichereDirekt("comboCategoryText"+self.comboList.get_child().get_text(), self.comboCategory.get_child().get_text())
124 def comboLists_check_for_update(self):
125 if self.comboCategory.get_active() == -1:
126 model = self.comboCategory.get_model()
128 cat = self.get_category()
133 self.comboCategory.append_text(self.get_category())
134 self.comboCategory.set_active(len(self.comboCategory.get_model())-1)
135 if self.comboList.get_active() == -1:
136 model = self.comboList.get_model()
138 list = self.get_list()
143 self.comboList.append_text(self.get_list())
144 self.comboList.set_active(len(self.comboList.get_model())-1)
147 _moduleLogger.warning("Laden der aktuellen position noch nicht implementiert")
150 _moduleLogger.warning("Speichern der aktuellen position noch nicht implementiert")
152 def getIsHildon(self):
155 def get_category(self, select = False):
156 s = self.comboCategory.get_child().get_text()
165 def set_category(self, category):
166 self.comboCategory.get_child().set_text(category)
168 def set_list(self, listname):
169 self.comboList.get_child().set_text(listname)
172 return self.comboList.get_child().get_text()