Created
October 5, 2012 15:39
-
-
Save jwiggins/3840576 to your computer and use it in GitHub Desktop.
This is a list model that I'm using for my Enaml ListView. For some reason, the column indices that I'm getting don't compare correctly with integer constants. WTF.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class XFileItemModel(AbstractListModel): | |
""" An AbstractListModel implementation which handles X files. | |
""" | |
columns = [ | |
'#', | |
'X File', | |
'Start Time (UTC)', | |
'Duration', | |
'Rate', | |
'Channels', | |
'Flag', | |
] | |
def __init__(self, items): | |
super(XFileItemModel, self).__init__() | |
self.items = items | |
def index(self, row, column, parent=None): | |
if self.has_index(row, column, parent): | |
context = self.items[row] | |
return self.create_index(row, column, context) | |
def row_count(self, idx): | |
return len(self.items) | |
def column_count(self, idx): | |
return len(self.columns) | |
def data(self, idx): | |
col = int(idx.column) | |
node = idx.context | |
# This next part only every prints 0, 1, and 6 | |
if col == 0: | |
print col | |
elif col == 1: | |
print col | |
elif col == 2: | |
print col | |
elif col == 3: | |
print col | |
elif col == 4: | |
print col | |
elif col == 5: | |
print col | |
elif col == 6: | |
print col | |
# FORMATTERS is a list of function pointers | |
# This gets around the comparison failure above | |
if col < len(FORMATTERS): | |
return FORMATTERS[col](node) | |
return "" | |
def horizontal_header_data(self, section): | |
return self.columns[section] | |
def alignment(self, index): | |
if index.column == 0: | |
return ALIGN_LEFT | |
return super(XFileItemModel, self).alignment(index) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment