How to implement observer in wxPython

Dear Pythoners,

I’ve got two questions for you since I need help to improve my GUI application.

I’ve just finished writing a basic GUI interface for my former python application and it works!
However, my old application writes info and outputs into logs (text files).

Can you suggest me a way (steps?) to restructure my application so that I can send relevant information to a wx window (for example, a frame with some auto-updating counters and a nice progress bar)?

Basically, I have the following:

a frame with a control list of files (added via a File chooser) and a start button.

—> The start button triggers the execution of a method that call some methods of my older class. These methods write information in a log file.

How can I grab updated infos from older class’ methods during their execution?

Question 2 is:

I would like to abort the process. How can I stop the execution of a method so that the control comes back to the main window?

Thanks a lot in any case!

Dear Pythoners,

I've got two questions for you since I need help to improve my GUI
application.

I've just finished writing a basic GUI interface for my former python
application and it works!
However, my old application writes info and outputs into logs (text files).

Can you suggest me a way (steps?) to restructure my application so that I
can send relevant information to a wx window (for example, a frame with some
auto-updating counters and a nice progress bar)?

Basically, I have the following:

a frame with a control list of files (added via a File chooser) and a start
button.

---> The start button triggers the execution of a method that call some
methods of my older class. These methods write information in a log file.

How can I grab updated infos from older class' methods during their
execution?

Check out pubsub. It allows you to pass messages back and forth
between the GUI and the engine pretty effortlessly.

http://wiki.wxpython.org/PubSub

Question 2 is:

I would like to abort the process. How can I stop the execution of a method
so that the control comes back to the main window?

Also from the Wiki, see Long Running Tasks:

http://wiki.wxpython.org/LongRunningTasks

···

On Mon, May 25, 2009 at 7:57 AM, Domenico Nappo <domenico.nappo@gmail.com> wrote:

Hi all,

I'm in Boa Constructor.

I press the help button and I get C++ code.... I don't understand C++ code.

How can I find out how to use the Splitterwindow?

I've looked at the wxpython examples and they down't work within boa
constructor...

How do I use these things? I have a very simple app...

(un)Help as follows:

wxSplitterWindow overview
Classes: wxSplitterWindow
The following screenshot shows the appearance of a splitter window with a
horizontal split.

The style wxSP_3D has been used to show a 3D border and 3D sash.
Example

Example
The following fragment shows how to create a splitter window, creating two
subwindows and hiding one of them.

  splitter = new wxSplitterWindow(this, -1, wxPoint(0, 0), wxSize(400,
400), wxSP_3D);
  leftWindow = new MyWindow(splitter);
  leftWindow->SetScrollbars(20, 20, 50, 50);
  rightWindow = new MyWindow(splitter);
  rightWindow->SetScrollbars(20, 20, 50, 50);
  rightWindow->Show(false);
  splitter->Initialize(leftWindow);
  // Set this to prevent unsplitting
// splitter->SetMinimumPaneSize(20);

The next fragment shows how the splitter window can be manipulated after
creation.

  void MyFrame::OnSplitVertical(wxCommandEvent& event)
  {
        if ( splitter->IsSplit() )
            splitter->Unsplit();
        leftWindow->Show(true);
        rightWindow->Show(true);
        splitter->SplitVertically( leftWindow, rightWindow );
  }
  void MyFrame::OnSplitHorizontal(wxCommandEvent& event)
  {
        if ( splitter->IsSplit() )
            splitter->Unsplit();
        leftWindow->Show(true);
        rightWindow->Show(true);
        splitter->SplitHorizontally( leftWindow, rightWindow );
  }
  void MyFrame::OnUnsplit(wxCommandEvent& event)
  {
        if ( splitter->IsSplit() )
            splitter->Unsplit();
  }

Domenico Nappo wrote:

Dear Pythoners,

I've got two questions for you since I need help to improve my GUI application.

I've just finished writing a basic GUI interface for my former python application and it works!
However, my old application writes info and outputs into logs (text files).

Can you suggest me a way (steps?) to restructure my application so that I can send relevant information to a wx window (for example, a frame with some auto-updating counters and a nice progress bar)?

Basically, I have the following:

a frame with a control list of files (added via a File chooser) and a start button.

---> The start button triggers the execution of a method that call some methods of my older class. These methods write information in a log file.

How can I grab updated infos from older class' methods during their execution?

Question 2 is:

I would like to abort the process. How can I stop the execution of a method so that the control comes back to the main window?

Thanks a lot in any case!

In addition to what Anthony suggested, I recommend checking out the demo. There is a couple of widgets in there that you could use for the progress bar and some examples of threading as well.

···

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4101 (20090525) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

David Lyon wrote:

Hi all,

I'm in Boa Constructor.

I press the help button and I get C++ code.... I don't understand C++ code.

How can I find out how to use the Splitterwindow?

http://wiki.wxpython.org/C%2B%2BGuideForwxPythoneers

···

--
Robin Dunn
Software Craftsman

David,

Robin Dunn wrote:

David Lyon wrote:

Hi all,

I'm in Boa Constructor.
I press the help button and I get C++ code.... I don't understand C++ code.

How can I find out how to use the Splitterwindow?

C++GuideForwxPythoneers - wxPyWiki

Boa includes both the C++ doc and the new wxPython doc.

If you do ctrl-h and then enter splitterwindow and press ok you will see both. The entries starting with "wxSplitter" are the C++ doc and the ones on the top e.g. "SplitterWindow" are from the new doc.

Werner

In addition to what Anthony suggested, I recommend checking out the demo. There is a couple of widgets in there that you could use for the progress bar and some examples of threading as well.

Thanks guys!

Really useful!! I’ll let you know :slight_smile:

PbuY

···


DN

This is all less than helpful...

The presumption placed upon the read is that they already know wxwidgets,
already know what all the controls do, that they know how to program it all
in C++... and they just want to do the same thing in wxpython.

Quoting wrappers in C++ is like being read back text from a Latin lawbook..

What an application developer wants to know is what are the components..
What is the relationship between them.... and how are they used together to
make an application window that sizes nicely.

None of these questions are covered in the documentation...

Here's an analogy of how this documentation was written..

Somebody makes a road. Somebody else wants to use it to drive a car down to
the shops....

The road maker writes down all the fun things like the chemical composition
of the bitumen and chucks in for "free" the timecards of all of the various
steamroller driver as a reference...

what more could any driver need....? right?

It's the same with this documentation. No python programmer can use the
wrappers. They make no sense. And are transient and irrelevant.

But... just like a chemical composition of a road... it's being held in the
highest esteem... for all pedestrians and motorists alike....

I'm sorry - I'm just trying to explain very clearly what the problem with
the existing documentation is.

But if nobody cares... it doesn't matter...

David

···

On Tue, 26 May 2009 09:15:00 +0200, "Werner F. Bruhin" <werner.bruhin@free.fr> wrote:

How can I find out how to use the Splitterwindow?

C++GuideForwxPythoneers - wxPyWiki

Boa includes both the C++ doc and the new wxPython doc.

If you do ctrl-h and then enter splitterwindow and press ok you will see
both. The entries starting with "wxSplitter" are the C++ doc and the
ones on the top e.g. "SplitterWindow" are from the new doc.

David Lyon wrote:

[snip snip snip]

What an application developer wants to know is what are the components..
What is the relationship between them.... and how are they used together to
make an application window that sizes nicely.

None of these questions are covered in the documentation...
  David

Hi David,
Have you looked at the wxpython demo? It shows you how to use the splitterctrl there

(unrelated to the topic...)
Also is it me or is Google Groups being weird, for example this very thread, here http://groups.google.com/group/wxPython-users/browse_thread/thread/e19fd7788995165e somehow inserts Domenico's post halfway through the thread, when in fact it is a new message.

Hi David,

David Lyon wrote:

How can I find out how to use the Splitterwindow?
        

C++GuideForwxPythoneers - wxPyWiki
      

Boa includes both the C++ doc and the new wxPython doc.

If you do ctrl-h and then enter splitterwindow and press ok you will see both. The entries starting with "wxSplitter" are the C++ doc and the ones on the top e.g. "SplitterWindow" are from the new doc.
    
This is all less than helpful...

The presumption placed upon the read is that they already know wxwidgets,
already know what all the controls do, that they know how to program it all
in C++... and they just want to do the same thing in wxpython.
  

Both these docs are reference doc, they are not how to docs.

In Boa there is a little tutorial to get going with Boa/wxPython - if you have some suggestions on how that could be enhanced to make it easier, you can either write it and I will incorporate it or you can just make some suggestions and I will add it to my todo list.

There are also some ShowMeDo videos for wxPython.
ShowMeDo Video Tutorials | showmedo.com - 5 videos
ShowMeDo Video Tutorials | showmedo.com - 9 videos on Boa

- Then one of the best tools to get going is the wxPython demo (a separate download with the docs).
- Then there is the wiki

http://wiki.wxpython.org/How%20to%20Learn%20wxPython\\
http://wiki.wxpython.org/ObstacleCourse
and many more

Quoting wrappers in C++ is like being read back text from a Latin lawbook..
  

Frankly I was and I am still getting very confused when I look at the C++ doc, in the rare cases when I can not find an answer in the other docs.

But there are good reasons why it is that way and Robin and others have only so much time in a day, i.e. 24 also I wonder sometimes if Robin figured out how to get 48 out of day.

Here some help/information on this:
http://wiki.wxpython.org/C%2B%2BGuideForwxPythoneers
http://wiki.wxpython.org/C%2B%2B%20%26%20Python%20Sandwich
http://wiki.wxpython.org/C%2B%2BExtensions

And last but not least this is the wxpython-users list, a lot of extremely nice and helpful bunch of people hang out here and they are always very helpful when one asks nicely.

Werner

···

On Tue, 26 May 2009 09:15:00 +0200, "Werner F. Bruhin" > <werner.bruhin@free.fr> wrote:

On Tue, 26 May 2009 11:36:48 +0200, "Werner F. Bruhin"

Both these docs are reference doc, they are not how to docs.

Not really. They don't provide any "reference" points...

There's nothing that a python programmer needs in the
current documentation...

Sadly... it doesn't work very well as reference material.

In Boa there is a little tutorial to get going with Boa/wxPython - if
you have some suggestions on how that could be enhanced to make it
easier, you can either write it and I will incorporate it or you can
just make some suggestions and I will add it to my todo list.

The wxpython documentation needs revising. It just needs a fresh
rework from an application developers perspective.

That means... what wxpython has.... what it gives you...

and some proper pythonic examples and references...

- Then one of the best tools to get going is the wxPython demo (a
separate download with the docs).

Yes - but the example python code needs to be where the C++ code
currently sits. Right where you need it. Not in some seperate
system that needs a seperate download. That's not how good
documentation works.

But there are good reasons why it is that way and Robin and others have
only so much time in a day, i.e. 24 also I wonder sometimes if Robin
figured out how to get 48 out of day.

Well I understand that completely...

But likewise, the burden of all the documentation shouldn't lie on
Robin alone.

Here some help/information on this:
C++GuideForwxPythoneers - wxPyWiki
C++ & Python Sandwich - wxPyWiki
C++Extensions - wxPyWiki

Man... (sigh)

That's a lot of documentation to have to read to find out an
answer to how to set up splitter components on a wxpython app...

I already found the spot in the reference material where it
was supposed to be but their was nothing written.

If you're somehow suggesting that I read through all the
documentation and somehow colate it into something useful
I probably would be a bit more positive....

To mind.. the existing documentation structure is pretty good. It
just needs revising. Adding better descriptions of what the classes
do... Listing the key properties and methods.. and providing
an in-situ example that a developer can cut and paste directly.

That's basically what I am suggesting needs doing.

And last but not least this is the wxpython-users list, a lot of
extremely nice and helpful bunch of people hang out here and they are
always very helpful when one asks nicely.

Yes - I don't doubt that.

But application developers too have only so many hours in the day.

I don't blame any application developer for being annoyed when they
have to work 4 hours extra hunting through useless documentation
and google till 3am to answer a question on how to do something that
should have been a two minute task....

You may say you are helpful, but I never got an answer on what
I need to do to put the splitter components together into something
working. Like I said... I gave up... moved onto something else...

:slight_smile:

David

(ps: I have a client who uses dBase IV. I dream for documentation
that good. Would anybody be interested to see scans of their
documentation? It takes only 2 mins to get an answer on literally
anything from their reference manual. And that is a paper book! )

While all of your complaints seem to be valid in some abstract sense,
many of us have simply made do with the documentation there is,
because we find the usefulness of the toolkit so great that we are
happy to make the trade off. If you do not feel this way, you should
simply use another toolkit which better fits your needs, or write the
documentation you desire. That's how it works in the free software
world.

···

On Tue, May 26, 2009 at 10:04 AM, David Lyon <david.lyon@preisshare.net> wrote:

And last but not least this is the wxpython-users list, a lot of
extremely nice and helpful bunch of people hang out here and they are
always very helpful when one asks nicely.

Yes - I don't doubt that.

But application developers too have only so many hours in the day.

I don't blame any application developer for being annoyed when they
have to work 4 hours extra hunting through useless documentation
and google till 3am to answer a question on how to do something that
should have been a two minute task....

You may say you are helpful, but I never got an answer on what
I need to do to put the splitter components together into something
working. Like I said... I gave up... moved onto something else...

:slight_smile:

David

(ps: I have a client who uses dBase IV. I dream for documentation
that good. Would anybody be interested to see scans of their
documentation? It takes only 2 mins to get an answer on literally
anything from their reference manual. And that is a paper book! )

--
Best Regards,
Michael Moriarity

Last time I offered to help with the documentation I was told
there was no spare capacity for me to do that.

So rather than do anything constructive to sort out the problem...

(... which might actually be a quicker option... )

I'll just continue to provide feedback on what whatever issue I
come across and report it back every day - haha

Like I said before.. I'm just trying to do a python package manager
using wxwidgets. I'm from a Delphi/VB background. If I stumble upon
any problem... I'll check the documentation.... and if I find
nothing then I'll ask on the list....

That's what I've been told on numerous occasions to do.

So really, you just have to put up with people that are
following the instructions given out to them....

And since I'm not allowed to contribute to the documentation
(like I would in a normal open-source project) these
questions/suggestions of mine are going to be going on
for a very long time.... because I'm many years away
from retirement just yet...

( ..and so the world moves ever so slowly forward.. )

David

···

On Tue, 26 May 2009 11:17:22 -0400, Michael Moriarity <datasmith@gmail.com> wrote:

If you do not feel this way, you should
simply use another toolkit which better fits your needs, or write the
documentation you desire. That's how it works in the free software
world.

Werner F. Bruhin wrote:

Hi David,

David Lyon wrote:

How can I find out how to use the Splitterwindow?
        

C++GuideForwxPythoneers - wxPyWiki
      

Boa includes both the C++ doc and the new wxPython doc.

If you do ctrl-h and then enter splitterwindow and press ok you will see both. The entries starting with "wxSplitter" are the C++ doc and the ones on the top e.g. "SplitterWindow" are from the new doc.
    
This is all less than helpful...

The presumption placed upon the read is that they already know wxwidgets,
already know what all the controls do, that they know how to program it all
in C++... and they just want to do the same thing in wxpython.
  

Both these docs are reference doc, they are not how to docs.

In Boa there is a little tutorial to get going with Boa/wxPython - if you have some suggestions on how that could be enhanced to make it easier, you can either write it and I will incorporate it or you can just make some suggestions and I will add it to my todo list.

There are also some ShowMeDo videos for wxPython.
ShowMeDo Video Tutorials | showmedo.com - 5 videos
ShowMeDo Video Tutorials | showmedo.com - 9 videos on Boa

- Then one of the best tools to get going is the wxPython demo (a separate download with the docs).
- Then there is the wiki

http://wiki.wxpython.org/How%20to%20Learn%20wxPython\\
ObstacleCourse - wxPyWiki
and many more

Don't forget the wxPIA: wxPythonInAction - wxPyWiki

···

On Tue, 26 May 2009 09:15:00 +0200, "Werner F. Bruhin" >> <werner.bruhin@free.fr> wrote:

--
Robin Dunn
Software Craftsman

Steven Sproat wrote:

(unrelated to the topic...)
Also is it me or is Google Groups being weird, for example this very thread, here http://groups.google.com/group/wxPython-users/browse_thread/thread/e19fd7788995165e somehow inserts Domenico's post halfway through the thread, when in fact it is a new message.

The script I wrote to transfer the archives does so by emailing each message to the group's archive address. It looks like if the messages arrive out of order then that is how the get put into the discussions, instead of using the date or the In-Reply-To header to define the order. This is why Mike's reply to Dominic is shown before Dominic's message.

There is another issue in the thread you linked. Notice the boxes with "Discussion subject changed to..." in them. This happens when somebody replies to an existing message and changes the subject instead of creating a new message with the new subject. This is why Dominic's message about the observer pattern shows up in the discussion about splitter docs.

···

--
Robin Dunn
Software Craftsman

David Lyon wrote:

You may say you are helpful, but I never got an answer on what
I need to do to put the splitter components together into something
working. Like I said... I gave up... moved onto something else...

Well, maybe I missed it but I never saw an actual question about splitter windows. Just a rant.

BTW, documentation is something always on my mind and I've been putting some thought into how to automate most of it so it doesn't require having 48 hour days to keep it maintained. The "new" wxPython docs was one attempt that didn't work out so well. I'm gearing up for the next attempt in the not too distant future.

···

--
Robin Dunn
Software Craftsman

I really don't mind pitching in to help out.

Whilst it is a considerable task, it's not an enormous one.

I propose something like this:

- re-categorise all the controls similar to the order
   shown on the boa constructor (or some other ide) tool.

   ie (panels, buttons, lists, dialogs etc)

- We write/find an abstract for every wxwidget.

   (Not as bad as it sounds - might take 3 weeks)

- We find an example for every widget.

   (might take 2 months)

- We identify and document the properties/methods/events
   for every widget.

   (might take a little while...)

I strongly suggest moving the documentation into Sphinx
format.

Whilst I'm only learning sphinx, I can see it's advantages.

One writes in plain text... then compiles it to html..

The results that I have seen look pretty good.

It is a native python tool..

I do have some spare time... that I can allocate...

Regards

David

···

On Tue, 26 May 2009 09:11:33 -0700, Robin Dunn <robin@alldunn.com> wrote:

BTW, documentation is something always on my mind and I've been putting
some thought into how to automate most of it so it doesn't require
having 48 hour days to keep it maintained.

Robin,

Robin Dunn wrote:
...

http://wiki.wxpython.org/How%20to%20Learn%20wxPython\\
ObstacleCourse - wxPyWiki
and many more

Don't forget the wxPIA: wxPythonInAction - wxPyWiki

It was included in the many more :slight_smile: .

Werner

David,

Hi all,

I'm in Boa Constructor.

I press the help button and I get C++ code.... I don't understand C++ code.

How can I find out how to use the Splitterwindow?

I've looked at the wxpython examples and they down't work within boa
constructor...

How do I use these things? I have a very simple app...
  
I don't use Boa, but I went ahead and created a very simple example of how to create a splitter. The demo gives the same info, but it's probably more in depth. I see you decided to go do something else, but hopefully the attached file will help you out in the future...

I ran this under Windows XP, wxPython 2.8.9.2, Python 2.5

- Mike

splitter-example.py (1.9 KB)

Mike Driscoll wrote:

David,

Hi all,

I'm in Boa Constructor.
I press the help button and I get C++ code.... I don't understand C++ code.

How can I find out how to use the Splitterwindow?

I've looked at the wxpython examples and they down't work within boa
constructor...

How do I use these things? I have a very simple app...
  
I don't use Boa, but I went ahead and created a very simple example of how to create a splitter. The demo gives the same info, but it's probably more in depth. I see you decided to go do something else, but hopefully the attached file will help you out in the future...

I ran this under Windows XP, wxPython 2.8.9.2, Python 2.5

- Mike

Oh yeah...I forgot to plug Andrea's docs, which I use as an alternative to the official docs:

http://xoomer.virgilio.it/infinity77/wxPython/Widgets/wx.SplitterWindow.html?highlight=splitterwindow

- Mike