Add loopquery tool. Log notices to console from all tools (toolbase).
#!/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()