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)
59 self.comboList = gtk.combo_box_entry_new_text()
60 self.comboList.set_size_request(180, -1)
61 self.pack_start(self.comboList, expand = False, fill = True, padding = 0)
63 label = gtk.Label(_(" Category:"))
64 self.pack_start(label, expand = False, fill = True, padding = 0)
66 self.__categories = []
67 self.__categoryButton = gtk.Button("")
68 self.__categoryButton.connect("clicked", self._on_category_selector)
69 self.pack_start(self.__categoryButton, expand = False, fill = True, padding = 0)
71 self.comboList.connect("changed", self.comboList_changed, None)
74 model = self.comboList.get_model()
76 #self.comboList.remove(0)
78 sql = "SELECT DISTINCT list FROM items ORDER BY list"
79 rows = self.db.ladeSQL(sql)
80 if ((rows is not None)and(len(rows)>0)):
82 self.comboList.append_text(row[0])
84 self.comboList.append_text("default")
86 s = self.db.ladeDirekt("comboListText")
88 self.comboList.get_child().set_text(s)
90 self.comboList.set_active(0)
92 @gtk_toolbox.log_exception(_moduleLogger)
93 def _on_category_selector(self, *args):
94 window = gtk_toolbox.find_parent_window(self)
95 userSelection = hildonize.touch_selector_entry(
101 self.set_category(userSelection)
102 self.emit("changed", "category", "")
103 self.db.speichereDirekt("comboCategoryText"+self.comboList.get_child().get_text(), self.__categoryButton.get_label())
104 self._update_categories()
106 @gtk_toolbox.log_exception(_moduleLogger)
107 def comboList_changed(self, widget = None, data = None):
108 self._update_categories()
110 s = self.db.ladeDirekt("comboCategoryText"+self.comboList.get_child().get_text())
112 self.__categoryButton.set_label(s)
114 self.__categoryButton.set_label(self.__categories[0])
116 self.emit("changed", "list", "")
117 self.db.speichereDirekt("comboListText", self.comboList.get_child().get_text())
119 def _update_categories(self):
120 del self.__categories[:]
122 sql = "SELECT DISTINCT category FROM items WHERE list = ? ORDER BY category"
123 rows = self.db.ladeSQL(sql, (self.get_list(), ))
125 self.__categories.append(_("all"))
126 if ((rows is not None)and(len(rows)>0)):
128 if (row[0] != _("all")):
129 self.__categories.append(row[0])
131 def comboLists_check_for_update(self):
132 if self.comboList.get_active() == -1:
133 model = self.comboList.get_model()
135 list = self.get_list()
140 self.comboList.append_text(self.get_list())
141 self.comboList.set_active(len(self.comboList.get_model())-1)
144 _moduleLogger.warning("Laden der aktuellen position noch nicht implementiert")
147 _moduleLogger.warning("Speichern der aktuellen position noch nicht implementiert")
149 def getIsHildon(self):
152 def get_category(self, select = False):
153 s = self.__categoryButton.get_label()
162 def set_category(self, category):
163 self.__categoryButton.set_label(category)
165 def set_list(self, listname):
166 self.comboList.get_child().set_text(listname)
169 return self.comboList.get_child().get_text()