browser.py
changeset 72 539c2dd47f3b
parent 57 ba323bbed6a4
child 104 d8ff52a0390f
equal deleted inserted replaced
71:4251068a251a 72:539c2dd47f3b
     8 from pgtoolkit import pgbrowser
     8 from pgtoolkit import pgbrowser
     9 from pgtoolkit.toolbase import SimpleTool
     9 from pgtoolkit.toolbase import SimpleTool
    10 
    10 
    11 
    11 
    12 class MyApplication(Application, SimpleTool):
    12 class MyApplication(Application, SimpleTool):
       
    13 
    13     PLACEHOLDER = '__placeholder__'
    14     PLACEHOLDER = '__placeholder__'
       
    15 
    14     def __init__(self):
    16     def __init__(self):
    15         Application.__init__(self)
    17         Application.__init__(self)
    16         SimpleTool.__init__(self, name='browser', desc='PostgreSQL database browser.')
    18         SimpleTool.__init__(self, name='browser', desc='PostgreSQL database browser.')
    17         self.init()
    19         self.init()
    18 
    20 
    19         self.top.connect('keypress', self.on_top_keypress)
    21         self.top.add_handler('keypress', self.on_top_keypress)
    20 
    22 
    21         self.browser = pgbrowser.PgBrowser(self.pgm.get_conn('target'))
    23         self.browser = pgbrowser.PgBrowser(self.pgm.get_conn('target'))
    22         self.model = TreeModel()
    24         self.model = TreeModel()
    23         self.view = TreeView(self.model)
    25         self.view = TreeView(self.model)
    24         self.view.connect('expand', self.on_view_expand)
    26         self.view.add_handler('expand', self.on_view_expand)
    25         self.top.add(self.view)
       
    26 
    27 
    27         vert = VerticalLayout()
    28         scroll = ScrollView()
    28         self.top.layout(vert)
    29         scroll.add(self.view)
       
    30         self.top.add(scroll, halign='fill', valign='fill')
    29 
    31 
    30         self.populate_schemas()
    32         self.populate_schemas()
    31 
    33 
    32     def populate_schemas(self):
    34     def populate_schemas(self):
    33         schemas = self.browser.list_schemas()
    35         schemas = self.browser.list_schemas()
    51         node.name = 'tables'
    53         node.name = 'tables'
    52         node.title = 'Tables (%d)' % len(table_list)
    54         node.title = 'Tables (%d)' % len(table_list)
    53         for table_name in table_list:
    55         for table_name in table_list:
    54             node.add(TreeNode(table_name))
    56             node.add(TreeNode(table_name))
    55 
    57 
    56     def on_view_expand(self, node):
    58     def on_view_expand(self, ev):
    57         if node.parent.name == 'schemas' and node.children[0].name == self.PLACEHOLDER:
    59         if ev.node.parent.name == 'schemas' and ev.node.children[0].name == self.PLACEHOLDER:
    58             schema_name = node.name
    60             schema_name = ev.node.name
    59             self.populate_tables(node.children[0], schema_name)
    61             self.populate_tables(ev.node.children[0], schema_name)
    60 
    62 
    61     def on_top_keypress(self, keyname, char):
    63     def on_top_keypress(self, ev):
    62         if keyname == 'escape':
    64         if ev.keyname == 'escape':
    63             self.terminate()
    65             self.terminate()
    64 
    66 
    65 
    67 
    66 if __name__ == '__main__':
    68 if __name__ == '__main__':
    67     app = MyApplication()
    69     app = MyApplication()