Very tough time learning wxPython. Need some kick-starting please!

Hi everyone,

Hi David. Welcome the the world of wxPython.

I have been using Python for years and I love it. I’m trying to use wxPython for the past few days and I’m absolutely smashing my head into a brick wall! How in the world do you learn this library? I’ve done every tutorial and looked at many of the included demos. I’ve bought the “wxPython in Action” book and would gladly pay GOOD MONEY to learn what I need to know. I want to master this thing. But I’m at my wits end!

It would help if you would explain to the list what exactly is the issue. You attempt some of that below (see next) but it’s still a bit too vague, it seems to me. I’m not sure what you’re stuck on. As Robin often very rightly states here, it’s a super idea to include a “small, runnable sample”. See:

http://wiki.wxpython.org/MakingSampleApps

And 7 times out of 10, in making this sample you figure out what the issue is!

Where I am struggling is filling those panels with text/tree widgets

What about that are you struggling with? If you want any widget on any panel, you declare that widget and give that panel as its parent. E.g (oversimplified version):

my_upper_left_panel = wx.Panel(parent=my_frame)
my_text_widget = wx.TextCtrl(parent=my_upper_left_panel)

There, now you have filled the panel with one text widget. For a tree, it would be the same idea, just using the wx.TreeCtrl instead of wx.TextCtrl. Then the tree would need its nodes, etc.

Now, that is assuming you are not using wxSizer yet, which you should. But to just get used to things, you can ignore Sizers for a few minutes.

and figuring out how the heck to tie everything together with my model.

That’s not a wxPython issue, I don’t think, but a code organization issue. If you use MVC as a pattern, it has its rules for how to shuttle info around from the Model to the View via the Controller, and there must a be a lot out there online for how to do that properly. (I tried to “MVC” a biggish application once and it was too tough to re-write it that way, so I left it as ravioli cod–on a good day). That said, there are a few good points to keep in mind for communicating to widgets:

pubsub is a module built into wxPython that allows you to send information around your app using a “broadcast” and “listen” model, and that allows some nice dis-connection of parts, which is great for MVC or just good coding practices generally.

You also want to think in terms of keeping references to instances of various frames and panels around your app. So, let’s say you are in the “main frame” and there are three panels on it. You want to use the dot notation to make reference to them all:

self.first_panel = wx.Panel(parent=mainFrame)
self.2nd_panel = wx.Panel(parent=mainFrame)
self.3rd_panel = wx.Panel(parent=mainFrame)

Now, a widget that lives on self.first_panel could be identified by

self.first_panel.my_text_widget

Though with three levels some may feel this is pushing the “Law of Demeter” too hard, understandably. The Controller part might be able to more suitably refer to this textWidget by keeping a dictionary of them or something like that.

I feel like I could inherit PyOnDemandOutput() but I can’t figure out how to do it.

I don’t know what PyOnDemandOutput is and when I Googled that string your post is the only thing on the internet that has it (well, now this one does, too).

What do you think? How can I learn this library to accomplish this task?

  • Take it one part at a time.

  • Base it on runnable/working examples you find in the Demo or online.

  • Ask the list if you get stuck

  • Use a GUI builder to write the code for you and then see what it did and learn from it (I used Boa Constructor for this).

  • Don’t expect to learn it too quickly

  • Don’t try when you’re tired :smiley: (this is the one I ought to keep in mind more)

Che

···

On Fri, Feb 1, 2013 at 10:49 PM, David Lynch d.lynch@yahoo.com wrote: