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:
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With