MVC for standalone application using python, sqlite3 and gtk

I am developing a pygtk application for which I have adopted the MVC framework. But I do not think that I am following the standard MVC pattern in the implementation.

Please suggest how I should use MVC for the next statement of the problem.

I am using Python, GTK, sqlite3 in my application

The problem statement for the Application:
Data is present in the log file. It should be retrieved and displayed in the graphical interface. A graphical interface can have several views (for example, browser tabs) that show data extracted from a log file (a user can create several views from a single database table). Users can filter / search data through GUI views. The condition of the filter can vary from one type to another.

Current implementation using MVC structure:
Currently, there is a Create View button in the graphical interface that, when clicked, creates a view to display the extracted data. Data is extracted (the controller extracts data) from the log file and added to the sqlite database (model). Data from the sqlite database table is extracted and added to gtk.Treemodel, which displays it in gtk.Treeview (View). Each time the user clicks "Create View", the controller creates an instance of the view class and creates a new tab in the GUI.

I created three classes Model, View and Controller to achieve this. The controller instantiates Model and View. During operation, the application creates an instance of the controller that continues to wait for GUI events (click "Create View", etc. Using the main gtk loop)

I need help here!
I read that in MVC, if the model (database) changes, the views also change and vice versa. Is it possible to achieve the same using sqlite3 and gtk.Treeview.

In short, my questions are:

  1. How can I update the application GUI by retrieving data from a database? MVC examples have Observer classes that call callback functions when the model changes. How can I write the same for the above statement of the problem?
  2. In any case, can I install the sqlite3 database as a treemodel for gtk.Treeview, so that when I insert any row into the database table, it is updated in the form of a tree?
  3. Is there an example that uses the MVC architecture and is built using Python, GTK, SQLite?
+7
source share
2 answers

This is what I finally implemented in my application! Please let me know if there is a better way to do this.

I used gtk.GenericTreeModel to show data from sqlite database in gtk.Treeview.

When the user clicks "Click View", the sqlite view is created and connected to gtk.GenericTreeModel to display the data in gtk.Treeview (GUI).

And if the data is added to the database after creating the sqlite view, to update gtk.Treeview, we need to give the signal "row inserted".

The github project channel has an example of connecting sqlite to the gtk generic treemodel.

Hope this helps!

+1
source

I do not know if any existing examples exist; what you describe sounds very specific to your problem.

However, you can use the Gda library to get a connection to your sqlite database as Gtk.TreeModel .

0
source

All Articles