browser.py
changeset 31 c2e6e24b83d9
parent 2 efee419b7a2d
child 57 ba323bbed6a4
equal deleted inserted replaced
30:a8b7cd92f39f 31:c2e6e24b83d9
       
     1 #!/usr/bin/env python3
       
     2 # -*- coding: utf-8 -*-
       
     3 
       
     4 import locale
       
     5 locale.setlocale(locale.LC_ALL, '')
       
     6 
       
     7 from tuikit import *
       
     8 from pgtoolkit import pgbrowser
       
     9 from pgtoolkit.toolbase import SimpleTool
       
    10 
       
    11 
       
    12 class MyApplication(Application, SimpleTool):
       
    13     def __init__(self):
       
    14         Application.__init__(self)
       
    15         SimpleTool.__init__(self, name='browser', desc='PostgreSQL database browser.')
       
    16         self.init()
       
    17         
       
    18         self.top.connect('keypress', self.globalkeypress)
       
    19 
       
    20         browser = pgbrowser.PgBrowser(self.pgm.get_conn('target'))
       
    21         model = TreeModel()
       
    22         view = TreeView(model)
       
    23         self.top.add(view)
       
    24         
       
    25         # populate schemas
       
    26         schemas = browser.list_schemas()
       
    27         model.add('/',  [schema['name'] for schema in schemas if not schema['system']])
       
    28         # populate tables
       
    29         for schema in schemas:
       
    30             if schema['system']:
       
    31                 continue
       
    32             tables = browser.list_tables(schema=schema['name'])
       
    33             schemanode = '/'+schema['name']
       
    34             model.add(schemanode,  [table['name'] for table in tables])
       
    35             view.collapse(schemanode)        
       
    36         
       
    37         vert = VerticalLayout()
       
    38         self.top.layout(vert)
       
    39         
       
    40         view.setfocus()
       
    41 
       
    42     def globalkeypress(self, keyname, char):
       
    43         if keyname == 'escape':
       
    44             self.terminate()
       
    45 
       
    46 
       
    47 if __name__ == '__main__':
       
    48     app = MyApplication()
       
    49     app.start()
       
    50