Created
October 5, 2012 17:01
-
-
Save jwiggins/3841012 to your computer and use it in GitHub Desktop.
Kaboom!
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
from enaml.core.item_model import AbstractListModel, ALIGN_LEFT | |
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 = idx.column | |
node = idx.context | |
if col == 0: | |
res = "0" | |
elif col == 1: | |
res = "1" | |
elif col == 2: | |
res = "2" | |
elif col == 3: | |
res = "3" | |
elif col == 4: | |
res = "4" | |
elif col == 5: | |
res = "5" | |
elif col == 6: | |
res = "6" | |
else: | |
res = "Fail" | |
return res | |
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) | |
enamldef BrokenListView(Container): | |
id: file_view | |
attr model | |
constraints = [ | |
vbox( | |
file_table, | |
), | |
] | |
TableView: | |
id: file_table | |
item_model << XFileItemModel(file_view.model.sensor_files) | |
activated :: | |
matches = [] | |
item = None | |
for sensor_file in file_view.model.sensor_files: | |
if sensor_file == item: | |
matches.append(sensor_file) | |
file_view.model.selected = matches | |
enamldef Main(Window): | |
id: main_window | |
attr model | |
BrokenListView: | |
model << main_window.model |
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
import enaml | |
from traits.api import HasTraits, List | |
class MainModel(HasTraits): | |
sensor_files = List | |
if __name__ == "__main__": | |
with enaml.imports(): | |
from enaml_parser_bug import Main | |
model = MainModel(sensor_files=range(10)) | |
view = Main(model=model) | |
view.show() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment