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
29 import libliststorehandler
38 _moduleLogger = logging.getLogger(__name__)
41 class TripleToggleCellRenderer(gtk.CellRendererToggle):
44 "status": (gobject.TYPE_STRING, "Status",
45 "Status", "", gobject.PARAM_READWRITE),
49 'status_changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_INT, gobject.TYPE_STRING)),
53 gtk.CellRendererToggle.__init__(self)
54 self.set_property("activatable", True)
55 self.connect('toggled', self._on_toggled)
56 self.status = libliststorehandler.Liststorehandler.SHOW_NEW
58 @gtk_toolbox.log_exception(_moduleLogger)
59 def do_set_property(self, property, value):
60 if getattr(self, property.name) == value or value is None:
63 setattr(self, property.name, value)
65 if property.name == "status":
66 active, inconsistent = {
67 libliststorehandler.Liststorehandler.SHOW_NEW: (False, False),
68 libliststorehandler.Liststorehandler.SHOW_ACTIVE: (False, True),
69 libliststorehandler.Liststorehandler.SHOW_COMPLETE: (True, False),
71 self.set_property("active", active)
72 self.set_property("inconsistent", inconsistent)
74 @gtk_toolbox.log_exception(_moduleLogger)
75 def do_get_property(self, property):
76 return getattr(self, property.name)
78 @gtk_toolbox.log_exception(_moduleLogger)
79 def _on_toggled(self, widget, path):
80 self.emit("status_changed", int(path), "-1")
83 gobject.type_register(TripleToggleCellRenderer)
88 def __init__(self, db, liststorehandler, parent_window):
90 self.parent_window = parent_window
91 self.liststorehandler = liststorehandler
93 gtk.VBox.__init__(self, homogeneous = False, spacing = 0)
95 logging.info("libview, init")
97 self.scrolled_window = None
101 ls = self.liststorehandler.get_liststore()
102 self.treeview.set_model(ls)
104 def del_active_row(self):
105 path, col = self.treeview.get_cursor()
108 row_iter = self.treeview.get_model().get_iter(path)
109 self.liststorehandler.del_row(irow, row_iter)
111 def reload_view(self):
112 # create the TreeView using liststore
113 self.modelsort = gtk.TreeModelSort(self.liststorehandler.get_liststore())
114 self.modelsort.set_sort_column_id(2, gtk.SORT_ASCENDING)
116 self.treeview = gtk.TreeView(self.modelsort)
117 self.treeview.set_headers_visible(True)
118 self.treeview.set_reorderable(False)
120 self.cell = range(self.liststorehandler.get_colcount())
121 self.tvcolumn = range(self.liststorehandler.get_colcount())
123 m = self.liststorehandler.get_unitsstore()
125 for i in range(self.liststorehandler.get_colcount()):
130 if self.db.ladeDirekt("showcol_"+str(self.liststorehandler.get_colname(i)), default) == "1":
132 self.cell[i] = TripleToggleCellRenderer()
133 self.tvcolumn[i] = gtk.TreeViewColumn("", self.cell[i])
134 self.cell[i].connect( 'status_changed', self._on_col_toggled)
135 self.tvcolumn[i].set_attributes( self.cell[i], status = i)
137 self.cell[i] = gtk.CellRendererCombo()
138 self.tvcolumn[i] = gtk.TreeViewColumn(self.liststorehandler.get_colname(i), self.cell[i])
139 self.cell[i].set_property("model", m)
140 self.cell[i].set_property('text-column', i)
141 self.cell[i].set_property('editable', True)
142 self.cell[i].connect("edited", self._on_col_edited, i)
143 self.tvcolumn[i].set_attributes( self.cell[i], text = i)
145 self.cell[i] = gtk.CellRendererText()
146 self.tvcolumn[i] = gtk.TreeViewColumn(self.liststorehandler.get_colname(i), self.cell[i])
147 self.cell[i].set_property('editable', True)
148 self.cell[i].set_property('editable-set', True)
149 self.cell[i].connect("edited", self._on_col_edited, i)
150 self.tvcolumn[i].set_attributes(self.cell[i], text = i)
152 self.tvcolumn[i].set_sort_column_id(i)
153 self.tvcolumn[i].set_resizable(True)
154 self.treeview.append_column(self.tvcolumn[i])
156 if self.scrolled_window is not None:
157 self.scrolled_window.destroy()
159 self.scrolled_window = gtk.ScrolledWindow()
160 self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
162 self.scrolled_window.add(self.treeview)
163 self.pack_start(self.scrolled_window, expand = True, fill = True, padding = 0)
168 @gtk_toolbox.log_exception(_moduleLogger)
169 def _on_col_edited(self, cell, irow, new_text, icol = None):
171 self.liststorehandler.update_row(irow, icol, new_text)
173 print cell, irow, new_text, icol
175 @gtk_toolbox.log_exception(_moduleLogger)
176 def _on_col_toggled(self, widget, irow, status):
177 ls = self.treeview.get_model()
179 if self.liststorehandler.get_filter() == self.liststorehandler.SHOW_ACTIVE:
180 if ls[irow][1] == "0":
181 self.liststorehandler.update_row(irow, 1, "1")
183 self.liststorehandler.update_row(irow, 1, "0")
185 if ls[irow][1] == "1":
186 self.liststorehandler.update_row(irow, 1, "-1")
187 elif ls[irow][1] == "0":
188 self.liststorehandler.update_row(irow, 1, "1")
190 self.liststorehandler.update_row(irow, 1, "0")