~chromano/kiwi/ideale

« back to all changes in this revision

Viewing changes to kiwi/ui/objectlist.py

  • Committer: romaia
  • Date: 2009-07-01 18:31:29 UTC
  • Revision ID: vcs-imports@canonical.com-20090701183129-so7qf21lkdlbzcan
Enable custom sort functions for objectlists

Show diffs side-by-side

added added

removed removed

Lines of Context:
138
138
      - B{column}: str None
139
139
        - A string referencing to another column. If this is set a new column
140
140
          will not be created and the column will be packed into the other.
 
141
      - B{sort_func}: object I{None}
 
142
        -  a callable which will be used to sort the contents of the column.
 
143
           The function will take two values (x and y) from the column and
 
144
           should return negative if x<y, zero if x==y, positive if x>y.
141
145
    """
142
146
    __gtype_name__ = 'Column'
143
147
    gproperty('attribute', str, flags=(gobject.PARAM_READWRITE | gobject.PARAM_CONSTRUCT_ONLY))
164
168
    gproperty('ellipsize', pango.EllipsizeMode, default=pango.ELLIPSIZE_NONE)
165
169
    gproperty('font-desc', str)
166
170
    gproperty('column', str)
 
171
    gproperty('sort_func', object, default=None)
167
172
    #gproperty('title_pixmap', str)
168
173
 
169
174
    # This can be set in subclasses, to be able to allow custom
242
247
                raise TypeError(
243
248
                    "spin_adjustment must be a gtk.Adjustment instance")
244
249
 
 
250
        if 'sort_func' in kwargs:
 
251
            if not callable(format_func):
 
252
                raise TypeError("sort_func must be callable")
 
253
            self.compare = kwargs['sort_func']
 
254
 
245
255
        PropertyObject.__init__(self, **kwargs)
246
256
        gobject.GObject.__init__(self, attribute=attribute)
247
257
 
252
262
    def prop_set_data_type(self, data):
253
263
        if data is not None:
254
264
            conv = converter.get_converter(data)
255
 
            self.compare = conv.get_compare_function()
 
265
            self.compare = self.compare or conv.get_compare_function()
256
266
            self.from_string = conv.from_string
257
267
        return data
258
268