[POS-commit] CVS: Kiwi/Kiwi Delegates.py,1.84,1.85 List.py,1.58,1.59
Christian Reis
kiko at async.com.br
Sun Feb 2 13:44:27 BRDT 2003
Update of /cvs/Kiwi/Kiwi
In directory anthem:/tmp/cvs-serv27751/Kiwi
Modified Files:
Delegates.py List.py
Log Message:
Implement a type framework for CListDelegate's Column specification.
This will allow us to determine the type manually (avoiding the
autodetection we do today; the autodetection is nice, but it misfires
when we have the wrong sort of data in a column). This was specifically
implemented to support the addition of None as a possible value for
columns (renders as an empty cell), and perhaps DateTime support.
Index: Delegates.py
===================================================================
RCS file: /cvs/Kiwi/Kiwi/Delegates.py,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -d -r1.84 -r1.85
--- Delegates.py 30 Jan 2003 20:49:59 -0000 1.84
+++ Delegates.py 2 Feb 2003 14:44:24 -0000 1.85
@@ -28,7 +28,8 @@
from List import CList, SortedCList
from Views import SlaveView, GladeView, BaseView, gladepath, find_in_gladepath
from FrameWork import BaseController
-from types import IntType, FloatType, ListType, DictType, TupleType, StringType
+from types import IntType, FloatType, ListType, DictType, TupleType, \
+ StringType, NoneType
from gtk import TRUE, FALSE
def _warn(msg):
@@ -75,6 +76,7 @@
def __init__(self,
attribute,
title = None,
+ type = None,
visible = TRUE,
justify = None,
format = None,
@@ -91,6 +93,8 @@
column represents
- title: the title of the column, defaulting to the capitalized form
of the attribute
+ - type: the type of the attribute that will be inserted into the
+ column
- visible: a boolean specifying if it is initially hidden or shown
- justify: one of gtk.JUSTIFY_LEFT, gtk.JUSTIFY_RIGHT or
gtk.JUSTIFY_CENTER or None. If None, the justification will be
@@ -113,6 +117,7 @@
a tooltip is not set.
"""
self.attribute = attribute
+ self.type = type
self.visible = visible
self.justify = justify
self.format = format
@@ -131,6 +136,12 @@
# Tip: when adding items here, remember to update
# CListDelegate.dump_column_code()
+ def __repr__(self):
+ dict = self.__dict__.copy()
+ attr = dict['attribute']
+ del dict['attribute']
+ return "<Column %s: %s>" % (attr, dict)
+
# CListView, the abject-poor-man's JTable :-)
class CListDelegate(SlaveDelegate):
@@ -139,8 +150,8 @@
an easy way to save and restore the column status (hidden/sorted/width)
to allow persisting user settings.
-CList delegate defines one public attribute: clist, which is the CList
-widget it holds.
+The CList delegate defines one public attribute: clist, which is the
+CList widget it holds.
"""
def __init__(self, columns, instance_list=None, handler=None,
mode=gtk.SELECTION_BROWSE):
@@ -153,7 +164,8 @@
If no Column has the `sorted' attribute set, we assume a normal,
unsorted CList is to be built; otherwise, a SortedCList is
created. This has impact over the add_instance() method - for
- normal CLists, append() is called; for SortedCList, insert_sorted.
+ normal CLists, append() is called; for SortedCList,
+ insert_sorted().
- list offers a list of instances to be inserted into the clist. If
no list is provided, the CList will be initialized empty, and the
columns won't be autosized or aligned by type; the first
@@ -339,6 +351,7 @@
if c.pixmap_spec:
name = "pixmap_spec_%s" % ret.index(c)
cdict["pixmap_spec"] = ", pixmap_spec=%s" % name
+ # Isn't printing text lovely?
text = text + """
\tColumn(attribute=%(attribute)s, title=%(title)s, visible=%(visible)s, \
justify=%(justify)s,
@@ -348,6 +361,7 @@
def get_clist(self):
"""Returns the clist object the CListDelegate holds"""
+ _warn("get_clist() is deprecated, use the `clist' attribute")
return self.clist
def dump_list(self):
@@ -485,6 +499,9 @@
clist = self.clist
columns = self._columns
clist.freeze()
+ # typelist *may* be uncreated at this point: we do lazy creation
+ # since we might not have a sample instance at instantiation
+ # time.
if not self._typelist:
self._typelist = self._get_types(list[0], columns)
clist.set_typelist(self._typelist)
@@ -511,11 +528,22 @@
return c
return None
+ # Iterates through columns, using the type attribute when found or
+ # the type of the associated attribute from the sample instance
+ # provided.
def _get_types(self, instance, columns):
tl = []
for c in columns:
- attr = c.attribute
- tl.append(type(self._get_attribute(instance, attr)))
+ if c.type is not None:
+ tp = c.type
+ else:
+ attr = c.attribute
+ tp = type(self._get_attribute(instance, attr))
+ if tp is NoneType:
+ raise TypeError, \
+"""Detected invalid type None for column `%s'; please specify
+type in Column constructor.""" % c.attribute
+ tl.append(tp)
return tl
def _get_justify_by_type(self, tp):
Index: List.py
===================================================================
RCS file: /cvs/Kiwi/Kiwi/List.py,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- List.py 8 Jan 2003 21:33:29 -0000 1.58
+++ List.py 2 Feb 2003 14:44:24 -0000 1.59
@@ -28,7 +28,7 @@
import gtk, Menu, UserList, sys, _gtk, GDK, GTK
from gtk import TRUE, FALSE, SORT_ASCENDING, SORT_DESCENDING
from types import StringType, IntType, FloatType, TupleType, ListType, \
- MethodType, FunctionType, TypeType
+ MethodType, FunctionType, TypeType, NoneType
def _warn(msg):
sys.stderr.write("Kiwi warning: "+msg+"\n")
@@ -1014,7 +1014,11 @@
# sort_with_type.
if typelist:
for t in typelist:
+ if type(t) is NoneType:
+ raise TypeError, "Types in list may *not* be of NoneType"
if type(t) is not StringType:
+ # The first non-string occurence indicates we need
+ # kiwi's special sorting.
self.typelist = typelist
break
More information about the POS-commit
mailing list