demo_tableview.py
changeset 100 3b2df86d8f94
parent 64 03f591f5fe5c
--- a/demo_tableview.py	Fri Mar 28 19:58:59 2014 +0100
+++ b/demo_tableview.py	Wed Aug 20 14:48:16 2014 +0200
@@ -6,6 +6,7 @@
 
 from tuikit import Application
 from tuikit.tableview import TableView, TableModel
+from tuikit.scrollview import ScrollView
 
 
 class MyApplication(Application):
@@ -13,20 +14,23 @@
         Application.__init__(self)
         self.top.add_handler('keypress', self.on_top_keypress)
 
-        data = []
-        for y in range(100):
-            row = [str(y+1)]
-            for x in range(10):
-                row.append('r{}:c{}'.format(y, x))
-            data.append(row)
-        model = TableModel(data)
+        model = TableModel()
+        model.set_num_headers(1, 1)
+        for col in range(10):
+            model.insert_column(col)
+            model.set_column_header(col, 0, 'col'+str(col+1))
+        for row in range(100):
+            model.insert_row(row)
+            model.set_row_header(row, 0, 'row'+str(row+1))
+            for col in range(10):
+                model.set_item(row, col, 'r{}:c{}'.format(row+1, col+1))
 
         view = TableView(model)
-        view.addcolumn(header=True, expand=False, sizereq=5)
-        for x in range(10):
-            view.addcolumn(title='head'+str(x))
 
-        self.top.add(view, halign='fill', valign='fill')
+        scroll = ScrollView()
+        scroll.add(view)
+
+        self.top.add(scroll, halign='fill', valign='fill')
 
     def on_top_keypress(self, ev):
         if ev.keyname == 'escape':