demo_tableview.py
changeset 99 f3063f08ba81
parent 64 03f591f5fe5c
equal deleted inserted replaced
98:dcfb185ac866 99:f3063f08ba81
     4 import locale
     4 import locale
     5 locale.setlocale(locale.LC_ALL, '')
     5 locale.setlocale(locale.LC_ALL, '')
     6 
     6 
     7 from tuikit import Application
     7 from tuikit import Application
     8 from tuikit.tableview import TableView, TableModel
     8 from tuikit.tableview import TableView, TableModel
       
     9 from tuikit.scrollview import ScrollView
     9 
    10 
    10 
    11 
    11 class MyApplication(Application):
    12 class MyApplication(Application):
    12     def __init__(self):
    13     def __init__(self):
    13         Application.__init__(self)
    14         Application.__init__(self)
    14         self.top.add_handler('keypress', self.on_top_keypress)
    15         self.top.add_handler('keypress', self.on_top_keypress)
    15 
    16 
    16         data = []
    17         model = TableModel()
    17         for y in range(100):
    18         model.set_num_headers(1, 1)
    18             row = [str(y+1)]
    19         for col in range(10):
    19             for x in range(10):
    20             model.insert_column(col)
    20                 row.append('r{}:c{}'.format(y, x))
    21             model.set_column_header(col, 0, 'col'+str(col+1))
    21             data.append(row)
    22         for row in range(100):
    22         model = TableModel(data)
    23             model.insert_row(row)
       
    24             model.set_row_header(row, 0, 'row'+str(row+1))
       
    25             for col in range(10):
       
    26                 model.set_item(row, col, 'r{}:c{}'.format(row+1, col+1))
    23 
    27 
    24         view = TableView(model)
    28         view = TableView(model)
    25         view.addcolumn(header=True, expand=False, sizereq=5)
       
    26         for x in range(10):
       
    27             view.addcolumn(title='head'+str(x))
       
    28 
    29 
    29         self.top.add(view, halign='fill', valign='fill')
    30         scroll = ScrollView()
       
    31         scroll.add(view)
       
    32 
       
    33         self.top.add(scroll, halign='fill', valign='fill')
    30 
    34 
    31     def on_top_keypress(self, ev):
    35     def on_top_keypress(self, ev):
    32         if ev.keyname == 'escape':
    36         if ev.keyname == 'escape':
    33             self.terminate()
    37             self.terminate()
    34             return True
    38             return True