예제 #1
0
 def setUp(self):
     """Create test data."""
     self.table = 'people'
     self.db_file = create_db(self.table)
     self.datasource = SQLiteDataSource(
         self.db_file,
         table=self.table,
         config=[
             {
                 'column': 'First name',
                 'type': 'str'
             },
             {
                 'column': 'Last name',
                 'type': 'str'
             },
             {
                 'column': 'Age',
                 'type': 'int'
             },
             {
                 'column': 'Start',
                 'type': 'int',
                 'encoding': 'timestamp'
             },
             {
                 'column': 'Image',
                 'type': 'int',
                 'encoding': 'image'
             },
         ],
     )
     self.datasource.MAX_RECS = 2
예제 #2
0
 def setUp(self):  # noqa
     """Create test data."""
     self.table = 'people'
     self.db_file = create_db(self.table)
     self.datasource = SQLiteDataSource(self.db_file, self.table, None, [
         {
             'column': 'First name',
             'type': 'str'
         },
         {
             'column': 'Last name',
             'type': 'str'
         },
         {
             'column': 'Age',
             'type': 'int'
         },
         {
             'column': 'Start',
             'type': 'int',
             'encoding': 'timestamp'
         },
         {
             'column': 'Image',
             'type': 'buffer',
             'encoding': 'image'
         },
     ])
     self.datasource.MAX_RECS = 2  # 2 records per page
     win = mock.MagicMock()
     datagrid_container = DataGridContainer(win)
     self.datagrid_controller = DataGridController(datagrid_container,
                                                   self.datasource)
     self.model = self.datagrid_controller.model
예제 #3
0
 def setUp(self):  # noqa
     """Create test data."""
     self.datagrid_model = DataGridModel(
         data_source=SQLiteDataSource('',
                                      'test',
                                      ensure_selected_column=False),
         get_media_callback=mock.MagicMock(),
         decode_fallback=mock.MagicMock())
예제 #4
0
 def select_table(selection):
     model, iterator = selection.get_selected()
     if iterator:
         table_name, config = model[iterator]
         controller.bind_datasource(
             SQLiteDataSource(db_path,
                              table_name,
                              config=config,
                              ensure_selected_column=False,
                              display_all=True,
                              persist_columns_visibility=False))
예제 #5
0
 def test_explicit_query(self):
     """Test using an explicit query for the data source."""
     # Important to not ensure "selected" column if there is no primary
     # key returned by the query.
     datasource = SQLiteDataSource(
         self.db_file,
         query='SELECT first_name, age FROM people',
         ensure_selected_column=False)
     rows = datasource.load()
     data = {tuple(row.data) for row in rows}
     reference_data = {(record[1], record[3])
                       for record in TEST_DATA[self.table]['data']}
     self.assertEqual(data, reference_data)
예제 #6
0
    DataGridController,
)

logger = logging.getLogger(__name__)

if __name__ == '__main__':
    setup_logging_to_stdout()
    setup_gtk_show_rules_hint()

    logger.info("Starting a datagrid_gtk3 example.")

    path = os.path.join(os.path.dirname(os.path.realpath(__file__)))
    db_path = os.path.join(path, 'selectable.sqlite')

    data_source = SQLiteDataSource(db_path,
                                   'fruits',
                                   ensure_selected_column=True)

    win = Gtk.Window()

    datagrid_container = DataGridContainer(win)
    controller = DataGridController(datagrid_container,
                                    data_source,
                                    has_checkboxes=True)
    datagrid_container.grid_vbox.reparent(win)

    win.set_default_size(600, 400)
    win.connect("delete-event", lambda *args: Gtk.main_quit())
    win.show()

    try: