~ubuntu-branches/ubuntu/utopic/python-traitsui/utopic

« back to all changes in this revision

Viewing changes to traitsui/qt4/table_model.py

  • Committer: Package Import Robot
  • Author(s): Varun Hiremath
  • Date: 2012-04-23 16:05:43 UTC
  • mfrom: (3.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20120423160543-bgafgw04y68arfjn
Tags: 4.1.0-1
* New upstream release
* Bump Standards-Version to 3.9.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
# MIME type for internal table drag/drop operations
42
42
mime_type = 'traits-ui-table-editor'
43
43
 
 
44
def as_qcolor(color):
 
45
    """ Convert a color specification (maybe a tuple) into a QColor.
 
46
    """
 
47
    if isinstance(color, SequenceTypes):
 
48
        return QtGui.QColor(*color)
 
49
    else:
 
50
        return QtGui.QColor(color)
 
51
 
44
52
#-------------------------------------------------------------------------------
45
53
#  'TableModel' class:
46
54
#-------------------------------------------------------------------------------
99
107
 
100
108
        elif role == QtCore.Qt.BackgroundRole:
101
109
            color = column.get_cell_color(obj)
102
 
            if color is not None:
103
 
                if isinstance(color, SequenceTypes):
104
 
                    q_color = QtGui.QColor(*color)
105
 
                else:
106
 
                    q_color = QtGui.QColor(color)
 
110
            if color is None:
 
111
                # FIXME: Yes, this is weird. It should work fine to fall through
 
112
                # to the catch-all None at the end, but it doesn't.
 
113
                return None
 
114
            else:
 
115
                q_color = as_qcolor(color)
107
116
                return QtGui.QBrush(q_color)
108
117
 
109
118
        elif role == QtCore.Qt.ForegroundRole:
110
119
            color = column.get_text_color(obj)
111
120
            if color is not None:
112
 
                if isinstance(color, SequenceTypes):
113
 
                    q_color = QtGui.QColor(*color)
114
 
                else:
115
 
                    q_color = QtGui.QColor(color)
 
121
                q_color = as_qcolor(color)
116
122
                return QtGui.QBrush(q_color)
117
123
 
118
124
        elif role == QtCore.Qt.UserRole:
119
125
            return obj
120
126
 
 
127
        elif role == QtCore.Qt.CheckStateRole:
 
128
            if column.get_type(obj) == "bool" and column.show_checkbox:
 
129
                if column.get_raw_value(obj):
 
130
                    return QtCore.Qt.Checked
 
131
                else:
 
132
                    return QtCore.Qt.Unchecked
 
133
 
121
134
        return None
122
135
 
123
136
    def flags(self, mi):
138
151
        if editor.factory.reorderable:
139
152
            flags |= QtCore.Qt.ItemIsDragEnabled | QtCore.Qt.ItemIsDropEnabled
140
153
 
 
154
        if column.get_type(obj) == "bool" and column.show_checkbox:
 
155
            flags |= QtCore.Qt.ItemIsUserCheckable
 
156
 
141
157
        return flags
142
158
 
143
159
    def headerData(self, section, orientation, role):