browser.py
changeset 31 c2e6e24b83d9
parent 2 efee419b7a2d
child 57 ba323bbed6a4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/browser.py	Mon Mar 05 18:36:46 2012 +0100
@@ -0,0 +1,50 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+import locale
+locale.setlocale(locale.LC_ALL, '')
+
+from tuikit import *
+from pgtoolkit import pgbrowser
+from pgtoolkit.toolbase import SimpleTool
+
+
+class MyApplication(Application, SimpleTool):
+    def __init__(self):
+        Application.__init__(self)
+        SimpleTool.__init__(self, name='browser', desc='PostgreSQL database browser.')
+        self.init()
+        
+        self.top.connect('keypress', self.globalkeypress)
+
+        browser = pgbrowser.PgBrowser(self.pgm.get_conn('target'))
+        model = TreeModel()
+        view = TreeView(model)
+        self.top.add(view)
+        
+        # populate schemas
+        schemas = browser.list_schemas()
+        model.add('/',  [schema['name'] for schema in schemas if not schema['system']])
+        # populate tables
+        for schema in schemas:
+            if schema['system']:
+                continue
+            tables = browser.list_tables(schema=schema['name'])
+            schemanode = '/'+schema['name']
+            model.add(schemanode,  [table['name'] for table in tables])
+            view.collapse(schemanode)        
+        
+        vert = VerticalLayout()
+        self.top.layout(vert)
+        
+        view.setfocus()
+
+    def globalkeypress(self, keyname, char):
+        if keyname == 'escape':
+            self.terminate()
+
+
+if __name__ == '__main__':
+    app = MyApplication()
+    app.start()
+