Skip to content

Instantly share code, notes, and snippets.

@jwiggins
Created October 5, 2012 15:39
Show Gist options
  • Save jwiggins/3840576 to your computer and use it in GitHub Desktop.
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.
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