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 self.__listLabel = gtk.Label(_("List:"))
57 self.pack_start(self.__listLabel, 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 self.__catLabel = gtk.Label(_(" Category:"))
65 self.pack_start(self.__catLabel, 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)
72 def set_orientation(self, orientation):
73 if orientation == gtk.ORIENTATION_HORIZONTAL:
74 self.__listLabel.show()
75 self.__catLabel.show()
76 elif orientation == gtk.ORIENTATION_VERTICAL:
77 self.__listLabel.hide()
78 self.__catLabel.hide()
80 raise NotImplementedError(orientation)
85 sql = "SELECT DISTINCT list FROM items ORDER BY list"
86 rows = self.db.ladeSQL(sql)
89 self.__lists.append(row[0])
91 self.__lists.append("default")
93 s = self.db.ladeDirekt("comboListText")
95 self.__listButton.set_label(s)
97 self.__listButton.set_label(self.__lists[0])
99 self.update_categories()
101 @gtk_toolbox.log_exception(_moduleLogger)
102 def _on_category_selector(self, *args):
103 window = gtk_toolbox.find_parent_window(self)
104 userSelection = hildonize.touch_selector_entry(
108 self.__categoryButton.get_label(),
110 self.set_category(userSelection)
111 self.emit("changed", "category", "")
112 self.db.speichereDirekt("comboCategoryText"+self.__listButton.get_label(), self.__categoryButton.get_label())
113 self.update_categories()
115 @gtk_toolbox.log_exception(_moduleLogger)
116 def _on_list_selector(self, *args):
117 window = gtk_toolbox.find_parent_window(self)
118 userSelection = hildonize.touch_selector_entry(
122 self.__listButton.get_label(),
124 self.set_list(userSelection)
126 self.update_categories()
128 self.emit("changed", "list", "")
129 self.db.speichereDirekt("comboListText", self.__listButton.get_label())
131 def update_categories(self):
132 del self.__categories[:]
134 sql = "SELECT DISTINCT category FROM items WHERE list = ? ORDER BY category"
135 rows = self.db.ladeSQL(sql, (self.get_list(), ))
137 self.__categories.append(_("all"))
140 if (row[0] != _("all")):
141 self.__categories.append(row[0])
143 s = self.db.ladeDirekt("comboCategoryText"+self.__listButton.get_label())
145 self.__categoryButton.set_label(s)
147 self.__categoryButton.set_label(self.__categories[0])
149 def comboLists_check_for_update(self):
150 categoryName = self.__categoryButton.get_label()
151 if categoryName not in self.__categories:
152 self.__categories.append(categoryName)
154 listName = self.__listButton.get_label()
155 if listName not in self.__lists:
156 self.__lists.append(listName)
159 _moduleLogger.warning("Laden der aktuellen position noch nicht implementiert")
162 _moduleLogger.warning("Speichern der aktuellen position noch nicht implementiert")
164 def getIsHildon(self):
167 def get_category(self, select = False):
168 s = self.__categoryButton.get_label()
177 def set_category(self, category):
178 # @bug the old code might have relied on this firing a combo change event
179 self.__categoryButton.set_label(category)
181 def set_list(self, listname):
182 # @bug the old code might have relied on this firing a combo change event
183 self.__listButton.set_label(listname)
186 return self.__listButton.get_label()