--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/blogic/categories.py Wed Jan 03 10:46:07 2007 -0300
@@ -0,0 +1,141 @@
+#!/usr/bin/env python
+#
+# blogic - Tool for blog's messages publishing
+# Copyright (C) 2006 German Poo-Caaman~o <gpoo@ubiobio.cl>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+import pygtk
+pygtk.require('2.0')
+
+import gtk
+import gobject
+import gtkspell
+from gettext import bindtextdomain, textdomain
+from gettext import gettext as _
+
+(
+ COLUMN_ID,
+ COLUMN_PRIMARY,
+ COLUMN_SECONDARY,
+ COLUMN_NAME,
+) = range(4)
+
+data = (
+ (0, False, False, 'Trivia'),
+ (1, False, False, 'Normal'),
+ (2, False, False, 'Critical'),
+ (3, False, False, 'Urgent')
+)
+
+class CategoryView(gtk.TreeView):
+ def __init__(self, *args):
+ gtk.TreeView.__init__(self, *args)
+ self.set_model(self._create_model())
+ self._add_columns()
+ self.primary_path = None
+
+ def _create_model(self):
+ # Store
+ store = gtk.ListStore(str, bool, bool, str)
+ for item in data:
+ iter = store.append()
+ store.set(iter,
+ COLUMN_ID, item[COLUMN_ID],
+ COLUMN_PRIMARY, item[COLUMN_PRIMARY],
+ COLUMN_SECONDARY, item[COLUMN_SECONDARY],
+ COLUMN_NAME, item[COLUMN_NAME])
+ return store
+
+ def _add_columns(self):
+ model = self.get_model()
+
+ cell = gtk.CellRendererToggle()
+ cell.connect('toggled', self._primary_toggled, model)
+ column = gtk.TreeViewColumn("Main", cell, active=COLUMN_PRIMARY)
+ self.append_column(column)
+
+ cell = gtk.CellRendererToggle()
+ cell.connect('toggled', self._secondary_toggled, model)
+ column = gtk.TreeViewColumn("Use", cell, active=COLUMN_SECONDARY)
+ column.set_sort_column_id(COLUMN_SECONDARY)
+ self.append_column(column)
+
+ cell = gtk.CellRendererText()
+ column = gtk.TreeViewColumn("Category", cell, text=COLUMN_NAME)
+ column.set_sort_column_id(COLUMN_NAME)
+ self.append_column(column)
+
+ def _primary_toggled(self, cell, path, model):
+ iter = model.get_iter(path)
+ primary = not model.get_value(iter, COLUMN_PRIMARY)
+ model.set(iter, COLUMN_PRIMARY, primary)
+
+ if self.primary_path is not None and self.primary_path != path:
+ iter_old = model.get_iter(self.primary_path)
+ model.set(iter_old, COLUMN_PRIMARY, False)
+
+ if primary:
+ model.set(iter, COLUMN_SECONDARY, True)
+
+ self.primary_path = path
+
+ def _secondary_toggled(self, cell, path, model):
+ iter = model.get_iter(path)
+ secondary = not model.get_value(iter, COLUMN_SECONDARY)
+ model.set(iter, COLUMN_SECONDARY, secondary)
+
+ if not secondary and model.get_value(iter, COLUMN_PRIMARY):
+ model.set(iter, COLUMN_PRIMARY, False)
+ self.primary_path = None
+
+class CategoryWindow(gtk.Window):
+ def __init__(self, *args):
+ gtk.Window.__init__(self, *args)
+
+ self.set_border_width(8)
+ self.set_title('Choose categories')
+
+ scroll = gtk.ScrolledWindow()
+ scroll.set_shadow_type(gtk.SHADOW_ETCHED_IN)
+ scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
+
+ treeview = CategoryView()
+ treeview.set_rules_hint(True)
+
+ scroll.add(treeview)
+
+ vbox = gtk.VBox(False, 8)
+ vbox.pack_start(scroll)
+
+ bbox = gtk.HButtonBox()
+ bbox.set_layout(gtk.BUTTONBOX_END)
+ bbox.set_spacing(8)
+ #bbox.set_border_width(12)
+ bbox.add(gtk.Button(stock='gtk-cancel'))
+ bbox.add(gtk.Button(stock='gtk-ok'))
+
+ vbox.pack_start(bbox, False, False)
+
+ self.add(vbox)
+
+if __name__ == "__main__":
+ window = CategoryWindow(gtk.WINDOW_TOPLEVEL)
+ #window = create_window()
+ window.set_default_size(300,250)
+ window.connect('delete-event', gtk.main_quit, None)
+ window.show_all()
+
+ gtk.main()