objectlist.py :  » IDE » PIDA » pida-0.6beta3 » pida » ui » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » IDE » PIDA 
PIDA » pida 0.6beta3 » pida » ui » objectlist.py
# -*- coding: utf-8 -*-
"""
    :copyright: 2005-2008 by The PIDA Project
    :license: GPL 2 or later (see README/COPYING/LICENSE)
"""

import gtk

from kiwi.ui.objectlist import Column

_ = lambda t: t

class AttrSortCombo(gtk.HBox):

    def __init__(self, objectlist, attributes, default):
        """
        @var objectlist: the objectlist to act on
        @var attributes: a sequence of attribute, title pairs
        @var default: the default attribute to sort by
        """
        gtk.HBox.__init__(self, spacing=3)
        self.set_border_width(3)
        self._objectlist = objectlist
        self._model = gtk.ListStore(str, str)
        self._order_button = gtk.ToggleToolButton(
            stock_id=gtk.STOCK_SORT_DESCENDING)
        self._order_button.connect('toggled', self._on_order_toggled)
        self._order_button.show()
        # Use a real combo to avoid internal dependency
        self._combo = gtk.ComboBox(model=self._model)
        self._combo.set_size_request(1, 1)
        self._combo.connect('changed', self._on_selection_changed)
        cell = gtk.CellRendererText()
        self._combo.pack_start(cell, True)
        self._combo.add_attribute(cell, 'text', 1)
        for name, title in attributes:
            iter = self._model.append((name, title))
            if name == default:
                self._combo.set_active_iter(iter)
        self._combo.show_all()
        self._label = gtk.Label(_('Sort'))
        self._label.show()
        self.pack_start(self._label, expand=False)
        self.pack_start(self._combo)
        self.pack_start(self._order_button, expand=False)

    def _on_selection_changed(self, combo):
        self._sort()

    def _on_order_toggled(self, button):
        self._sort()

    def _sort(self):
        self._objectlist.sort_by_attribute(self._get_attribute(),
                                           self._get_order())

    def _get_order(self):
        if self._order_button.get_active():
            return gtk.SORT_DESCENDING
        else:
            return gtk.SORT_ASCENDING

    def _get_attribute(self):
        return self._model[self._combo.get_active_iter()][0]

def sort_by_attribute(self, attribute, order=gtk.SORT_ASCENDING):
    """Sort by an attribute in the model."""
    def _sort_func(model, iter1, iter2):
        attr1 = getattr(model[iter1][0], attribute, None)
        attr2 = getattr(model[iter2][0], attribute, None)
        return cmp(attr1, attr2)
    unused_sort_col_id = len(self._columns)
    self._model.set_sort_func(unused_sort_col_id, _sort_func)
    self._model.set_sort_column_id(unused_sort_col_id, order)


class PBC(Column):

    pb = None

    def __init__(self, *args, **kw):
        self.pb = None
        Column.__init__(self, use_stock=True, *args, **kw)

    def cell_data_func(self, tree_column, renderer, model, treeiter,
                               (column, renderer_prop)):
        "To render the data of a cell renderer pixbuf"
        row = model[treeiter]
        data = column.get_attribute(row[COL_MODEL],
                                    column.attribute, None)
        if data is not None:
            if self.pb is None:
                self.pb = gtk.gdk.pixbuf_new_from_file(data)
            pixbuf = self.pb
            renderer.set_property(renderer_prop, pixbuf)
            print pixbuf




# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.