Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC for standalone application using python, sqlite3 and gtk

I am developing a pygtk application for which I have adopted MVC structure. But I don't think I'm following the standard MVC pattern in the implementation.

Please suggest how I must use MVC for the following problem statement.

I am using python, gtk, sqlite3 in my application

Problem statement for the Application:
The data is present in a logfile. It should be extracted and shown in a GUI. The GUI can have multiple views(like browser tabs) which show the data extracted from the logfile(User can create multiple views from the same database table). Users can filter/search the data through GUI views. The filter condition can vary from one view to another.

Current Implementation using MVC structure:
Currently, in the GUI, a button "Create View" is present, which upon clicking, creates a view to display the extracted data. The data is extracted(Controller extracts the data) from the logfile and added to the sqlite database(Model). Data from the sqlite database table is fetched and added to the gtk.Treemodel which displays it in the gtk.Treeview(View). Each time the user clicks "Create View", the Controller instantiates the View class and creates a new tab in the GUI.

I have created three classes Model, View, and Controller to achieve this. the Controller instantiates Model and View. The application, while running, instantiates Controller that keeps waiting for GUI events(click on "Create View" etc.. using gtk main loop)

Here I Need some help!
I have read that, in MVC, if the model (database) gets changed the views also get changed or vice versa. Is it possible to achieve the same using sqlite3 and gtk.Treeview.

In short, my questions are:

  1. How can I update my application GUI while extracting the data from the database? In MVC examples there are Observer classes which call callback functions when the model changes. How can I write the same for above problem statement?
  2. Is there anyway I can set sqlite3 database as treemodel for gtk.Treeview so that if any row is inserted to the database table it gets updated in the treeview?
  3. Is there any example which uses MVC architecture and is built using python, gtk, sqlite?
like image 406
user2109788 Avatar asked Jul 23 '15 14:07

user2109788


Video Answer


1 Answers

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

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

When user clicks on 'Click View' the sqlite view gets created and connected to gtk.GenericTreeModel in order to display the data in gtk.Treeview(GUI).

And if data is added to the database after the sqlite view is created, in order to update the gtk.Treeview, we need to emit the signal "row-inserted."

The project conduit from github has an example to connect sqlite to gtk generic treemodel.

Hope this helps!

like image 152
user2109788 Avatar answered Oct 24 '22 07:10

user2109788