Subclassing wxGlade best practise/tips/experience wanted!

I used to created with wxglade then refactor the generated code to make it all nice and efficient (looped menu/button creation à la Robin’s book etc etc) but that was a thankless task as I needed to make some alterations to the wxglade file and obviously had to regenerate everything. I then read that subclassing the glade file was common (best practise?) and then just handling and doing other stuff in the subclassed file. I have been doing that (being able to regenerate the code and not lose my changes is important to me) but am having to tweak things in the glade code that will obviously be lost again when i regenerate. I have attached some code samples below with inline comments describing what I want/wish for it to do but am not sure how. If anyone has any tips or experiences to share that would be great!

MainWindow - http://bpaste.net/show/25547/
PersonalDetails - http://bpaste.net/show/25548/

I don't use wxGlade so I won't have an authoritative answer here, and I think you're going to need to provide more explanation. What errors are you getting with CreateStatusBar? What are you trying to do with self.LIST_PLACEHOLDER and what do you want to replace it with? What version of wxPython are you using?

If you give your toolbar items IDs in wxGlade then you (or wxGlade) should be able to use those IDs when doing the event bindings.

As far as subclassing goes you should be able to do things like override the methods that wxGlade generates, call the base class version and then do your customizations and tweaks after it gets back to the method in the subclass. Or IIRC you can put your code outside of the #begin wxGlade...#end wxGlade blocks and it should preserve those code segments when it is regenerating the source module.

···

On 3/20/12 9:44 AM, johnharris85 wrote:

I used to created with wxglade then refactor the generated code to make
it all nice and efficient (looped menu/button creation � la Robin's book
etc etc) but that was a thankless task as I needed to make some
alterations to the wxglade file and obviously had to regenerate
everything. I then read that subclassing the glade file was common (best
practise?) and then just handling and doing other stuff in the
subclassed file. I have been doing that (being able to regenerate the
code and not lose my changes is important to me) but am having to tweak
things in the glade code that will obviously be lost again when i
regenerate. I have attached some code samples below with inline comments
describing what I want/wish for it to do but am not sure how. If anyone
has any tips or experiences to share that would be great!

MainWindow - http://bpaste.net/show/25547/
PersonalDetails - http://bpaste.net/show/25548/

--
Robin Dunn
Software Craftsman

Hey Robin, thanks for answering. Sorry I wrote my question in a rush and I’ll admit it wasn’t very good :stuck_out_tongue:

The error was to do with status bar fields. Apparently wxglade lets you have none, which is an exception in python. Easily fixed.

The listplaceholder is just a listctrl to block out my gui, I’m going to replace it with a hand-coded ObjectListView.

Using python 2.7 and wxpython 2.8.

The ID problem is actually to do with the way wxglade creates toolbars. I can specify a numeric ID, which is fine, however I don’t want to do this and instead want to use wx.ID_ANY to take care of this for me. The only trouble is that wxglade creates toolbar items like so:

self.toolbar.AddLabelTool(wx.NewId(), …)

Instead I want it to create like so:

self.toolitem = self.toolbar.AddLabelTool(wx.ID_ANY…)

Guessed there wasn’t much I could do about this so instead I have modified wxglade’s codegen files to produce the desired output, taking the value the user specifies as the ID and inserting into the statement generated like this:

self.{user-specified-ID-in-glade} = self.toolbar.AddLabelTool(wx.ID_ANY…)

I’ve also modified the event handler generation so that it generates properly.

Lastly, I’ve toyed with the idea of placing code outside of the wxglade tags and just using the generated files however I really want to try and keep it all separate so I’m going to play around more with the subclassing idea and see how much mileage I get from it. I think a lot of my hangups come from the fact that I don’t like the way wxglade generates some of the widgets, so I may just modify those codegen files for my own custom version of glade.

···

On Tuesday, 20 March 2012 16:44:38 UTC, johnharris85 wrote:

I used to created with wxglade then refactor the generated code to make it all nice and efficient (looped menu/button creation à la Robin’s book etc etc) but that was a thankless task as I needed to make some alterations to the wxglade file and obviously had to regenerate everything. I then read that subclassing the glade file was common (best practise?) and then just handling and doing other stuff in the subclassed file. I have been doing that (being able to regenerate the code and not lose my changes is important to me) but am having to tweak things in the glade code that will obviously be lost again when i regenerate. I have attached some code samples below with inline comments describing what I want/wish for it to do but am not sure how. If anyone has any tips or experiences to share that would be great!

MainWindow - http://bpaste.net/show/25547/
PersonalDetails - http://bpaste.net/show/25548/

Yes. What I do is put something like:

TOOL_ADD, TOOL_EDIT, TOOL_DELETE, TOOL_SAVE, TOOL_REVERT = range(1, 6)

into the class definition (before the # begin wxGlade), and then in
wxGlade, specify the IDs as self.TOOL_ADD and so forth.

That way the generation and re-generation is fine, and the bindings are
just fine.

OP: You might consider addressing those questions to the wxglade group/
list rather than wxpython.

···

On Tue, 20 Mar 2012 11:37:24 -0700, Robin Dunn wrote:

If you give your toolbar items IDs in wxGlade then you (or wxGlade)
should be able to use those IDs when doing the event bindings.