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
38 _moduleLogger = logging.getLogger(__name__)
41 class Selection(gtk.HBox):
44 'changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING, gobject.TYPE_STRING)),
45 #'changedCategory': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING, gobject.TYPE_STRING))
48 def __init__(self, db, isHildon):
49 gtk.HBox.__init__(self, homogeneous = False, spacing = 3)
52 self.isHildon = isHildon
54 _moduleLogger.info("libSelection, init")
56 label = gtk.Label(_("List:"))
57 self.pack_start(label, expand = False, fill = True, padding = 0)
60 self.__listButton = gtk.Button("")
61 self.__listButton.connect("clicked", self._on_list_selector)
62 self.pack_start(self.__listButton, expand = True, fill = True, padding = 0)
64 label = gtk.Label(_(" Category:"))
65 self.pack_start(label, expand = False, fill = True, padding = 0)
67 self.__categories = []
68 self.__categoryButton = gtk.Button("")
69 self.__categoryButton.connect("clicked", self._on_category_selector)
70 self.pack_start(self.__categoryButton, expand = True, fill = True, padding = 0)
75 sql = "SELECT DISTINCT list FROM items ORDER BY list"
76 rows = self.db.ladeSQL(sql)
79 self.__lists.append(row[0])
81 self.__lists.append("default")
83 s = self.db.ladeDirekt("comboListText")
85 self.__listButton.set_label(s)
87 self.__listButton.set_label(self.__lists[0])
89 self.update_categories()
91 @gtk_toolbox.log_exception(_moduleLogger)
92 def _on_category_selector(self, *args):
93 window = gtk_toolbox.find_parent_window(self)
94 userSelection = hildonize.touch_selector_entry(
98 self.__categoryButton.get_label(),
100 self.set_category(userSelection)
101 self.emit("changed", "category", "")
102 self.db.speichereDirekt("comboCategoryText"+self.__listButton.get_label(), self.__categoryButton.get_label())
103 self.update_categories()
105 @gtk_toolbox.log_exception(_moduleLogger)
106 def _on_list_selector(self, *args):
107 window = gtk_toolbox.find_parent_window(self)
108 userSelection = hildonize.touch_selector_entry(
112 self.__listButton.get_label(),
114 self.set_list(userSelection)
116 self.update_categories()
118 self.emit("changed", "list", "")
119 self.db.speichereDirekt("comboListText", self.__listButton.get_label())
121 def update_categories(self):
122 del self.__categories[:]
124 sql = "SELECT DISTINCT category FROM items WHERE list = ? ORDER BY category"
125 rows = self.db.ladeSQL(sql, (self.get_list(), ))
127 self.__categories.append(_("all"))
130 if (row[0] != _("all")):
131 self.__categories.append(row[0])
133 s = self.db.ladeDirekt("comboCategoryText"+self.__listButton.get_label())
135 self.__categoryButton.set_label(s)
137 self.__categoryButton.set_label(self.__categories[0])
139 def comboLists_check_for_update(self):
140 categoryName = self.__categoryButton.get_label()
141 if categoryName not in self.__categories:
142 self.__categories.append(categoryName)
144 listName = self.__listButton.get_label()
145 if listName not in self.__lists:
146 self.__lists.append(listName)
149 _moduleLogger.warning("Laden der aktuellen position noch nicht implementiert")
152 _moduleLogger.warning("Speichern der aktuellen position noch nicht implementiert")
154 def getIsHildon(self):
157 def get_category(self, select = False):
158 s = self.__categoryButton.get_label()
167 def set_category(self, category):
168 # @bug the old code might have relied on this firing a combo change event
169 self.__categoryButton.set_label(category)
171 def set_list(self, listname):
172 # @bug the old code might have relied on this firing a combo change event
173 self.__listButton.set_label(listname)
176 return self.__listButton.get_label()