ModelView wx-way or own-way?

274 views
Skip to first unread message

moo...@posteo.org

unread,
Feb 7, 2015, 1:28:53 PM2/7/15
to wxpytho...@googlegroups.com
I knew the theoretical background of the MVC-Pattern.
I used it with C++ years ago.
So I am quite familiar with it.

About wxPython I read
<http://www.wiki.wxpython.org/ModelViewController/>
This is a python-specific description/tutorial about the MVC-pattern.
But it doesn't use wx-classes (except in the UI-layer).

But I read about the Document/View Framework in wxWidgets
<http://docs.wxwidgets.org/trunk/overview_docview.html>

The questions is, should I use the wx-way for MVC, or should I
implement it myself like the first description in the wxPyWiki
explained?

What do you prefere in your productive daily work?

Werner

unread,
Feb 7, 2015, 4:56:29 PM2/7/15
to wxpytho...@googlegroups.com
There have been a few discussions on this list on that subject in the past.

The one which helped me getting my code better organized was the thread
"Separating GUI code from Logic" a few years ago.

Werner

Mike Driscoll

unread,
Feb 9, 2015, 9:39:56 AM2/9/15
to wxpytho...@googlegroups.com

I believe Werner is referring to this thread: https://groups.google.com/forum/#!searchin/wxpython-users/Separating$20GUI$20code$20from$20Logic/wxpython-users/3FXIJZXw7uw/QYegTgSVTZoJ

You may also find this old tutorial helpful: http://www.blog.pythonlibrary.org/2011/11/10/wxpython-and-sqlalchemy-an-intro-to-mvc-and-crud/

Werner and I ended up spinning that article off into a demo of MVC (sort of) called MediaLocker - http://www.blog.pythonlibrary.org/2011/11/30/improving-medialocker-wxpython-sqlalchemy-and-mvc/

I hope they help in some way.
Mike

moo...@posteo.org

unread,
Feb 9, 2015, 10:36:20 AM2/9/15
to wxpytho...@googlegroups.com
Hi Mike

On 2015-02-09 06:39 Mike Driscoll <kyos...@gmail.com> wrote:
> Werner and I ended up spinning that article off into a demo of MVC
> (sort of) called MediaLocker -
> http://www.blog.pythonlibrary.org/2011/11/30/improving-medialocker-wxpython-sqlalchemy-and-mvc/

Thank you very much. wx & sqlalchemy is exactly what I am using
currently. ;)

There is one line in the blog-article
"an example of a wxPython database-enabled application"

Does this mean there is somewhere an official example in the office
wxPython docs? I couldn't find something like that.

Mike Driscoll

unread,
Feb 9, 2015, 11:37:23 AM2/9/15
to wxpytho...@googlegroups.com, moo...@posteo.org

Yes, that was a reference to the MediaLocker project - https://bitbucket.org/driscollis/medialocker/src

The second article I linked to (http://www.blog.pythonlibrary.org/2011/11/30/improving-medialocker-wxpython-sqlalchemy-and-mvc/) had a bunch of fixes to the original one. Then Werner took the changes in that second article and added a bunch more. It's really interesting to see how it changed.

Mike

Mike Driscoll

unread,
Feb 9, 2015, 11:38:16 AM2/9/15
to wxpytho...@googlegroups.com
My apologies if that last one got copied to your email. Google Groups web interface seems to do that automatically and I don't always notice the checkbox.

Mike

Chris Barker

unread,
Feb 9, 2015, 12:07:28 PM2/9/15
to wxpython-users
You've got some nice pointers, but to answer your  question directly:

About wxPython I read
<http://www.wiki.wxpython.org/ModelViewController/>
This is a python-specific description/tutorial about the MVC-pattern.
But it doesn't use wx-classes (except in the UI-layer).

But I read about the Document/View Framework in wxWidgets
<http://docs.wxwidgets.org/trunk/overview_docview.html>

The questions is, should I use the wx-way for MVC, or should I
implement it myself like the first description in the wxPyWiki
explained?

I would go with using pure-python for everything except the UI layer.

1) It's a good rule of thumb to use the the python-way for thigns that are supported in both C++ wx and python itself.

2) One of the reasons to do MVC is to keep GUI-logic completely independent of the rest of the app, so that you could swap out another GUI, pure text API, Web API, etc. In that case, you don't want to be relying on anything from wx outside of the GUI itself.

3) IMHO, MVC "frameworks" don't really give you much over rolling your own, application-specific structure -- particularly in Python.

-HTH,

-Chris




 
What do you prefere in your productive daily work?

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris....@noaa.gov

Robin Dunn

unread,
Feb 11, 2015, 12:13:18 AM2/11/15
to wxpytho...@googlegroups.com
Chris Barker wrote:
> You've got some nice pointers, but to answer your question directly:
>
> About wxPython I read
> <http://www.wiki.wxpython.org/ModelViewController/>
> This is a python-specific description/tutorial about the MVC-pattern.
> But it doesn't use wx-classes (except in the UI-layer).
>
> But I read about the Document/View Framework in wxWidgets
> <http://docs.wxwidgets.org/trunk/overview_docview.html>
>
> The questions is, should I use the wx-way for MVC, or should I
> implement it myself like the first description in the wxPyWiki
> explained?
>
>
> I would go with using pure-python for everything except the UI layer.
>
> 1) It's a good rule of thumb to use the the python-way for thigns that
> are supported in both C++ wx and python itself.
>
> 2) One of the reasons to do MVC is to keep GUI-logic completely
> independent of the rest of the app, so that you could swap out another
> GUI, pure text API, Web API, etc. In that case, you don't want to be
> relying on anything from wx outside of the GUI itself.
>
> 3) IMHO, MVC "frameworks" don't really give you much over rolling your
> own, application-specific structure -- particularly in Python.
>

And to throw yet another log on the fire, wx's docview framework was
ported to Python code so it is more or less a pure python implementation
of that pattern. See wx.lib.docview and wx.lib.pydocview for a bit of
extra pythonification on top of docview. Personally the pattern has
never gelled with me like some of the others do, but it's there if
anybody wants to use it.


--
Robin Dunn
Software Craftsman
http://wxPython.org
Reply all
Reply to author
Forward
0 new messages