Python Forum
[WxPython] Responsibility in MVP Pattern
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[WxPython] Responsibility in MVP Pattern
#1
I'm new to the concept of enforcing some kind of design pattern in the application (using wxPython) I'm trying to write according to MVP (model-view-presenter) principles. I'm having some difficulty identifying who should do what.

In the case of my dialog box, I think I've identified and isolated the code needed to setup the view (create and style controls, create and populate sizers, display buttons, etc.). I have a wx.ComboBox that is used to select which widget is displayed in the dialog for data entry. With the idea in mind that I want to keep logic out of the view, I send a command to the presenter with the value selected in the combo box. The presenter then makes a decision, and sends a widget back that should be displayed to match the combo box selection.

Should the presenter handle the code associated with switching the displayed widget and repopulating the sizer? Or is that "dumb enough" for the view to handle?
Reply
#2
you must be running the old wxpython.

I highly recommend the vastly improved phoenix version (needs python 3.6 or newer)

with it comes a most remarkable demo program which covers just about every widget (preview some of the available widgets here: https://wxpython.org/Phoenix/docs/html/gallery.html) each has example code, a working demo and full documentation arranged on a tabbed notebook window.

I have windows tutorial here: https://python-forum.io/Thread-wxPython-...ep-by-step
Reply
#3
(Nov-08-2018, 02:08 AM)Larz60+ Wrote: you must be running the old wxpython.

What about my post suggests I'm running old wxpython? I thought I was on the Phoenix code base, but I'll check tomorrow (I'm python 3.7)
Reply
#4
Quote: I thought I was on the Phoenix code base, but I'll check tomorrow (I'm python 3.7)
you may be, if you installed with pip using:
pip install wxpython
you probably do.

if so, you can run the demo to get some ideas. I have instructions for demo here: https://python-forum.io/Thread-Generate-...0#pid56190
Reply
#5
wxPython Phoenix is available on PyPI

https://pypi.org/project/wxPython/

So using
pip install wxPython should work on Windows and MacOS

for some linux distroes, there are wheels as extra files - https://extras.wxpython.org/wxPython4/extras/linux/

For detailed information
https://wxpython.org/pages/downloads/
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#6
(Nov-08-2018, 03:56 AM)Larz60+ Wrote:
Quote: I thought I was on the Phoenix code base, but I'll check tomorrow (I'm python 3.7)
you may be, if you installed with pip using:
pip install wxpython
you probably do.

if so, you can run the demo to get some ideas. I have instructions for demo here: https://python-forum.io/Thread-Generate-...0#pid56190

Yes, I installed wxpython through pip, and I do recall seeing 4.0.3 as the installed version.

Perhaps this is ignorance on my part, but how do the wxPython demos fit into the MVP part of my question? I know HOW to manipulate the things I mentioned, but I'm not sure where in my code (view or presenter) it makes the most sense. This is sort of an opinion type question, but I'm looking for multiple opinions upon which to base my own development practices.
Reply
#7
Quote:how do the wxPython demos fit into the MVP part of my question

It doesn't, my confusion with Advanced User Interface (AUI) ( https://wxpython.org/Phoenix/docs/html/w...index.html ). Sorry,
you may still be interested in the demo. One of the best.
Reply
#8
(Nov-08-2018, 03:18 PM)Larz60+ Wrote: It doesn't, my confusion with Advanced User Interface (AUI) ( https://wxpython.org/Phoenix/docs/html/w...index.html ). Sorry,
you may still be interested in the demo. One of the best.

Lol, okay I'm not crazy :D Yes, I have run the demo numerous times to look for particular functions, they did a great service to the community with that.
Reply
#9
Maybe I can narrow down my question to make it a little more general.

After studying a few concrete examples, I think I noticed a pattern to the patterns. Rather than one object (model, view, or presenter) directly manipulating the attributes of another object, it seems that the right thing to do is to communicate through commands between objects. This abstracts the specific functionality of the object to a higher level protocol which is not dependent on the specific implementation of the attributes of the object.

Does this make sense?
Reply
#10
I've worked 'under the covers' all my programming life (since 1968), always avoiding the middle man, so probably not one to contribute here. Hope I haven't messed up your thread too much!. Best wishes.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020