Who's to blame?

Nicola Musatti nicola.musatti at gmail.com
Thu Jan 3 09:48:07 EST 2008


Hallo,
First of all I apologize for the longish example at the bottom, but
the biggest source file is automatically generated and I didn't want
to modify more than strictly necessary. Also, it would be shorter if
XML wasn't so verbose ;-)

The following is a wxPython/XRC toy program with a form with a button
which, when pressed, causes a simple dialog to be displayed. The
problem lies in the fact that apparently ShowModal() does not return
when either the Yes or the No buttons are pressed. Curiously, if you
change the Yes and No buttons with the OK and Cancel ones that are
currently commented everything works as expected.

As the sbs_test_xrc.py file below is automatically generated by
wxPython 2.8.6.1's XRCed tool from a XRC file which in turn is
generated by wxFormBuilder (http://wxformbuilder.org/), I really cant
figure out to whom I should report this problem, assuming I'm not
missing some obvious mistake of mine, that is.

Thanks for your help.

Cheers,
Nicola Musatti

# sbs_test.py
import wx
import sbs_test_xrc

class MainFrame(sbs_test_xrc.xrcMainFrame):
    def __init__(self, parent):
        sbs_test_xrc.xrcMainFrame.__init__(self, parent)
        self.button.Bind(wx.EVT_BUTTON, self.OnButton)

    def OnButton(self, event=None):
        d = sbs_test_xrc.xrcDialog(self)
##        if d.ShowModal() == wx.ID_OK:
        if d.ShowModal() == wx.ID_YES:
            self.Close()

class Application(wx.App):
    def OnInit(self):
        self.frame = MainFrame(None)
        self.frame.Show()
        self.SetTopWindow(self.frame)
        return True

if __name__ == '__main__':
    app = Application()
    app.MainLoop()

# sbs_test_xrc.py
# This file was automatically generated by pywxrc, do not edit by
hand.
# -*- coding: UTF-8 -*-

import wx
import wx.xrc as xrc

__res = None

def get_resources():
    """ This function provides access to the XML resources in this
module."""
    global __res
    if __res == None:
        __init_resources()
    return __res

class xrcDialog(wx.Dialog):
    def PreCreate(self, pre):
        """ This function is called during the class's initialization.

        Override it for custom setup before the window is created
usually to
        set additional window styles using SetWindowStyle() and
SetExtraStyle()."""
        pass

    def __init__(self, parent):
        # Two stage creation (see http://wiki.wxpython.org/index.cgi/TwoStageCreation)
        pre = wx.PreDialog()
        self.PreCreate(pre)
        get_resources().LoadOnDialog(pre, parent, "Dialog")
        self.PostCreate(pre)

        # create attributes for the named items in this container
        self.wxID_YES = xrc.XRCCTRL(self, "wxID_YES")
        self.wxID_NO = xrc.XRCCTRL(self, "wxID_NO")

class xrcMainFrame(wx.Frame):
    def PreCreate(self, pre):
        """ This function is called during the class's initialization.

        Override it for custom setup before the window is created
usually to
        set additional window styles using SetWindowStyle() and
SetExtraStyle()."""
        pass

    def __init__(self, parent):
        # Two stage creation (see http://wiki.wxpython.org/index.cgi/TwoStageCreation)
        pre = wx.PreFrame()
        self.PreCreate(pre)
        get_resources().LoadOnFrame(pre, parent, "MainFrame")
        self.PostCreate(pre)

        # create attributes for the named items in this container
        self.button = xrc.XRCCTRL(self, "button")

# ------------------------ Resource data ----------------------

def __init_resources():
    global __res
    __res = xrc.EmptyXmlResource()

    wx.FileSystem.AddHandler(wx.MemoryFSHandler())

    sbs_test_xrc = '''\
<?xml version="1.0" ?><resource version="2.3.0.1" xmlns="http://
www.wxwindows.org/wxxrc">
	<object class="wxDialog" name="Dialog">
		<style>wxDEFAULT_DIALOG_STYLE</style>
		<title/>
		<object class="wxFlexGridSizer">
			<rows>2</rows>
			<cols>2</cols>
			<vgap>0</vgap>
			<hgap>0</hgap>
			<growablecols/>
			<growablerows/>
			<object class="sizeritem">
				<option>1</option>
				<flag>wxEXPAND</flag>
				<border>5</border>
				<object class="wxStdDialogButtonSizer">
					<object class="button">
						<flag>wxALIGN_CENTER_HORIZONTAL|wxALL</flag>
						<border>5</border>
<!--
						<object class="wxButton" name="wxID_OK">
							<label>&OK</label>
						</object>
-->
						<object class="wxButton" name="wxID_YES">
							<label>&Yes</label>
						</object>
					</object>
					<object class="button">
						<flag>wxALIGN_CENTER_HORIZONTAL|wxALL</flag>
						<border>5</border>
<!--
						<object class="wxButton" name="wxID_CANCEL">
							<label>&Cancel</label>
						</object>
-->
						<object class="wxButton" name="wxID_NO">
							<label>&No</label>
						</object>
					</object>
				</object>
			</object>
		</object>
	</object>
	<object class="wxFrame" name="MainFrame">
		<style>wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL</style>
		<size>500,300</size>
		<title/>
		<object class="wxButton" name="button">
			<label>MyButton</label>
			<default>0</default>
		</object>
	</object>
</resource>'''

    wx.MemoryFSHandler.AddFile('XRC/sbs_test/sbs_test_xrc',
sbs_test_xrc)
    __res.Load('memory:XRC/sbs_test/sbs_test_xrc')



More information about the Python-list mailing list