Hi Che and Werner,
Although I am only an amateur and consequently an eternel newbie,
I'll try explain what I understood from the MVP, which is quite
similar to MVC.
Python and wxPython Gurus, please correct me if I am misunderstanding
something.
In the MVP, you have several components: the model, the view and the
interactor, and the Presenter.
According to ModelViewPresenter - wxPyWiki, "the
difference between MVC and MVP is that in MVP the presenter does not
handles the GUI events directly as the controller does in MVC but
through delegation via the interactor".
Thus, in the MVC, the bindings are done in the Controller while they
are kept seperated in the interactor in the MVP.
The model:
- manages all data coming in / from the database,
- defines methods to get data from the db (queries,...)
The View:
- is a gui with a frame, panels, buttons, fields,...
- is modified through:
- the presenter which has methods calling, for instance,
view.TextCtrl_1.ChangeValue()
- the interactor which binds all widgets of the view to methods
that
send back to methods defined in the presenter
The Interactor:
- binds all the View widgets to methods
- these methods call Presenter's methods that update the view
The Presenter:
- takes care of the logic of the application
- has methods that :
- update the View (send data to the View)
- get data from the View through the Interactor
- get data from the model
- send data to the model
Everything goes through the Presenter
For instance, if a button is pressed:
- the button is defined in the View
- the button is bound in the Interactor, with a method that calls
a Presenter's method such as:
def OnButtonPressed(self, evt):
# This is in the Interactor
self.presenter.UpdateView()
- the Presenter's method is called:
def UpdateView(self):
# This is in the Presenter
self.view.SetTextCtrl_1(value= self.view.GetTextCtrl_2())
self.model.UpdateDb()
which:
- updates the View (the value of the TC_1 is set to the value of
the TC_2)
- calls the updateDb method of the Model class, which updates the
db, doing
this or that
As a consequence, the Presenter manages the logic of the app, since
when the user acts on the gui elements, it goes to the interactor and
then to the Presenter where the action in response to the user actions
is defined:
gui action --> interactor (bindings) --> Calls Presenter's method -->
action managed by the Presenter (on the View, database,...).
To my understanding, the Presenter (or Controller) makes it easier to
modify the gui without putting the mess in the app.
You just modify your gui and the bindings in the interactor.
Since the logic of the app is in the presenter, you keep it clean.
To me, if the app becomes a little bit complex, it is certainly
worthwhile to use the MVP or MVC.
In the MVC pattern, what's the point of the Controller?
I found this way of thinking about MVC:
Input --> Processing --> Output
Controller --> Model --> View
...but why shouldn't one thing take care of input and output,
since both are handled by GUI code (e.g. .SetValue and
.GetValue). To add to my confusion, in the wxPython
doc about MVC, often the two words are combined into
one, as in View/Controller or ViewController.
One source I found said that for desktop GUI apps,
the distinction between View and Controller is not
important, but that it is important for web apps.
A good answer about the point of the Controller
would take the form: "Unless you have a Controller,
you will not be able to do x." (or it will harder to do x).
I am trying to do something like MVC now, and also
trying to create "ravioli code", and wondering if it is
worth my time to create a separate Controller. To
start, I am just trying to separate any GUI aspect
(display and user selection) from logic like database
queries and other processes. I will have some
wxTimers involved, too, and realize these can only
run in the main loop, so I'll need to think about how
that factors in here as well.
Regarding your wxTimer point, I don't really understand.
The app is defined in the __init__ method of the View:
wx.InitAllImageHandlers()# if necessary
self.app = wx.App(0)
Then, the mainloop is launched FROM the presenter (Controller) calling
for instance view.Start(), method defined in the View:
self.Show()
self.app.MainLoop()
Consequently, once the app is launched, you can put your timers
wherever you want:
- in the presenter,
- in the view,
and interacts with them without problems in the interactor.
If you need a small very simple app, let us know.
I hope this can help you.
Dominique
···
On Jul 20, 11:25 pm, C M <cmpyt...@gmail.com> wrote: