browser.py
author Radek Brich <radek.brich@devl.cz>
Wed, 26 Sep 2012 16:21:59 +0200
changeset 43 a921669e913a
parent 31 c2e6e24b83d9
child 57 ba323bbed6a4
permissions -rwxr-xr-x
PgManager: rewrite RowDict class.

#!/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()