@bind_to_key("enter") def show_columns_list(self): self.call(TableColumnsListViewerWidget(self.database_connection, self.get_current_item())) class TableColumnsListViewerWidget(FullColumnWidget): def __init__(self, database_connection, table_name): self.database_connection = database_connection self.table_name = table_name FullColumnWidget.__init__(self, self.get_table_columns_list()) def get_table_columns_list(self): return self.database_connection.execute("pragma table_info(%s)" % self.table_name).fetchall() def get_title(self): return "Columns of table: %s" % self.table_name def get_footer(self): return '"j", "k", "up", "down", "h", "left", "l", "right" to move, "q" to return to table listing' if __name__ == "__main__": if len(sys.argv) == 1: print >>sys.stderr, "give the path to the database as first argument" sys.exit(1) if not exists(sys.argv[1]): print >>sys.stderr, "file doesn't exist, stop" run(TableListViewerWidget(sqlite3.connect(sys.argv[1])))
@bind_to_key("a") def test_append_section(self): self.append_section("pouet") @bind_to_key("z") def test_append_item(self): self.append_item("qsd") class TestMenuWidget(FullListWidget): widgets_to_test = ( ("FullListWidget", (TestFullListWidget, "ceci est une liste de test".split())), ("FullColumnWidget", (FullColumnWidget, ["a b c d".split(), "1 2 3 4".split(), "a z e r t y".split()])), ("FullSectionListWidget", (TestFullSectionListWidget, (("pouet", ("a", "b", "c")), ("hophop", ("1", "2", "3")), ("empty", [])))), ) def __init__(self): FullListWidget.__init__(self, zip(*self.widgets_to_test)[0]) @bind_to_key("enter") def test_widget(self): data = dict(self.widgets_to_test)[self.get_current_item()] class_to_spawn = data[0] self.call(class_to_spawn(data[1])) if __name__ == "__main__": logging.debug("[main] start") run(TestMenuWidget()) logging.debug("[main] end\n------------------------------\n\n\n") logging.debug("\n" * 200)
class TableColumnsListViewerWidget(FullListWidget): def __init__(self, database_connection, table_name): self.database_connection = database_connection self.table_name = table_name FullListWidget.__init__(self, self.get_table_columns_list()) def get_table_columns_list(self): return [ x[1] for x in self.database_connection.execute( "pragma table_info(%s)" % self.table_name).fetchall() ] def get_title(self): return "Columns of table: %s" % self.table_name def get_footer(self): return '"j", "k", "up", "down" to move, "q" to return to table listing' if __name__ == "__main__": if len(sys.argv) == 1: print >> sys.stderr, "give the path to the database as first argument" sys.exit(1) if not exists(sys.argv[1]): print >> sys.stderr, "file doesn't exist, stop" run(TableListViewerWidget(sqlite3.connect(sys.argv[1])))
class TestMenuWidget(FullListWidget): widgets_to_test = ( ("FullListWidget", (TestFullListWidget, "ceci est une liste de test".split())), ("FullColumnWidget", (FullColumnWidget, ["a b c d".split(), "1 2 3 4".split(), "a z e r t y".split()])), ("FullSectionListWidget", (TestFullSectionListWidget, (("pouet", ("a", "b", "c")), ("hophop", ("1", "2", "3")), ("empty", [])))), ) def __init__(self): FullListWidget.__init__(self, zip(*self.widgets_to_test)[0]) @bind_to_key("enter") def test_widget(self): data = dict(self.widgets_to_test)[self.get_current_item()] class_to_spawn = data[0] self.call(class_to_spawn(data[1])) if __name__ == "__main__": logging.debug("[main] start") run(TestMenuWidget()) logging.debug("[main] end\n------------------------------\n\n\n") logging.debug("\n" * 200)