Error in wxPython Dialog function(SetReurnCode(),GetReturnCode()) in Linux

Polerio Babao Jr.II admin at polerio.com
Wed May 21 13:59:24 EDT 2003


I've created a wxPython application in Windows using Python 2.2.2 and
wxPython 2.4.0.7. The dialog apps works well in windows with the use
of SetReturnCode and GetReturnCode, but when I run this app in Linux,
specifically Mandrake Linux 9.1, an error had occurred. The error code
goes like the wxDialog EndModal() has been called twice.

When I run an application using simple dialog app, it works well both
on windows and linux. this can also be tested at wxPython
demos(wxDialog).

I wanted to create a dialog which have unique ids and I can only
create this using wxPython::wxDialog::SetReturnCode() and
wxPython::wxDialog::GetReturnCode(). From what I've found out, this
function works well  in Windows and it produces error when run in
Linux.

I would be very thankful to receive any input, resources, solutions,
code snippet, and apps related to this issues. I've added in here the
sample wxPython code I've run in Windows and Linux. It works well in
windows 2k. please try it for yourself, run it in windows and linux to
see the difference.

Thank you.

#-----------------------------------------------------------------
#testdialog.py 
#----------------------------------------------------------------

from wxPython.wx import *

#----------------------------------------------------------------------
class Frame(wxFrame):
	def	__init__(self, parent, ID):
		self.currentdialog = {}
		wxFrame.__init__(self, parent,
ID,'',wxDefaultPosition,	wxSize(400,400))

		self.pointer = 0
		self.mainmenu =	wxMenuBar()

		self.menuG =	wxMenu()
		self.mainmenu.Insert(0,	self.menuG, 'Guest')
		self.menuG.Append(1120, 'Add Dialog', '')
		self.menuG.Append(1121, 'Close Dialog', '')
		self.menuG.Append(1123, 'Close Frame', '')

		self.SetMenuBar(self.mainmenu)

		EVT_MENU(self, 1120, self.OnAdd)
		EVT_MENU(self, 1121, self.OnCancelDialog)
		EVT_MENU(self, 1123, self.OnClose)		
		self.menuG.Enable(1121,false)

	def OnAdd(self,event):
		self.menuG.Enable(1121,true)
		self.di = wxDialog(self, -1, 'Add New Guest', pos =
wxDefaultPosition, size = wxSize(300,200), style =
wxDEFAULT_DIALOG_STYLE)
		self.di.Centre(direction=wxBOTH)
		sizer = wxBoxSizer(wxHORIZONTAL)

		label = wxStaticText(self.di , -1, "Guest ID:",wxPoint(10,35))
		sizer.Add(label, 0, wxALIGN_CENTRE|wxALL, 5)
		self.text1 = wxTextCtrl(self.di , -1, "123" , size=(80,-1), pos=
wxPoint(60,30), style= wxTE_READONLY)
		sizer.Add(self.text1, 1, wxALIGN_CENTRE|wxALL, 5)

		sizer = wxBoxSizer(wxHORIZONTAL)
		label = wxStaticText(self.di , -1, "Name:",wxPoint(10,55))
		sizer.Add(label, 0, wxALIGN_CENTRE|wxALL, 5)
		self.text2 = wxTextCtrl(self.di , -1, "", size=(200,-1), pos=
wxPoint(60,50))
		sizer.Add(self.text2, 1, wxALIGN_CENTRE|wxALL, 5)

		sizer = wxBoxSizer(wxHORIZONTAL)
		label = wxStaticText(self.di , -1, "Comment:",wxPoint(10,75))
		sizer.Add(label, 0, wxALIGN_CENTRE|wxALL, 5)
		self.text3 = wxTextCtrl(self.di , -1, "", size=(200,-1), pos=
wxPoint(60,70))
		sizer.Add(self.text3, 1, wxALIGN_CENTRE|wxALL, 5)

		self.btn1 = wxButton(self.di, 2222, " Save ",wxPoint(80,100))
		self.btn2 = wxButton(self.di, 3333, " Cancel ",wxPoint(150, 100))
		self.di.SetReturnCode(123)
		self.di.Show()

		EVT_BUTTON(self.di, 2222, self.OnSaveDialog)
		EVT_BUTTON(self.di, 3333, self.OnCancelDialog)

	def OnSaveDialog(self, event):
		self.di.EndModal(self.di.GetReturnCode())
		a=long( self.text1.GetValue())
		b= self.text2.GetValue()
		c= self.text3.GetValue()
		print a,b,c

	def OnCancelDialog(self, event):		
		self.di.EndModal(self.di.GetReturnCode())

	def OnClose(self, event):		
		self.Close()
		
#----------------------------------------------------------------------
class App(wxApp):
	def	OnInit(self):
		wxInitAllImageHandlers()
		frame =	Frame(NULL,	-1)	
		frame.Show(true)
		self.SetTopWindow(frame)
		return true

app	= App(0)
app.MainLoop()

#----------------------------------------------------------------------




More information about the Python-list mailing list