[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1153
  • Last Modified:

TypeError: in method 'new_MessageDialog', expected argument 1 of type 'wxWindow

why cant I create wxwidget in any class except the main class... when ever I try to use a wxwidget and in this case  wx.MessageDialog  i get and error "TypeError: in method 'new_MessageDialog', expected argument 1 of type 'wxWindow "



class InsertData(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(990,700),style=wx.DEFAULT_FRAME_STYLE)
self.nsync = wx.Button(panel, -1, '&Sync', size=(-1, 30), pos=(700,250))
	self.nsync.Bind(wx.EVT_BUTTON, self.rock,self.nsync)
def rock(self,event):
	SynceThread(self,event).start()


class SynceThread(threading.Thread):
    def __init__(self, parent, event):
        self.parent = parent
        self.event = event
        threading.Thread.__init__(self)
    def run(self):	   
	f =open("ipaddress.txt","r")
	self.ip = f.readline() # reads the lines
	f.close()
	host=self.ip
        port = 51269
        size = 1000000
        addr = (host,port)
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            f = open('duplicate_table2.txt', "r")
            data = f.read()         
            f.close()
            s.connect(addr)
            s.send(data)
            data = s.recv(size)
            s.close()
            #print "Got it"
            os.remove('duplicate_table2.txt')
	    nsync = wx.MessageDialog(self, "Data Was Transferred Successfully", caption = "It Worked " , style = wx.OK | wx.ICON_EXCLAMATION)
	    nsync.ShowModal()
	    nsync == wx.OK
	    nsync.Destroy()
            return True
        except socket.error:
	    traceback.print_exc(file=open("errlog.txt","a"))
	    print"error"
	    exc_type, exc_value, exc_tb = sys.exc_info()
	    nsync1 = wx.MessageDialog(self, "Data Was Not Transferred Successfully", caption = "Did Not Trnsfer " , style = wx.OK | wx.ICON_EXCLAMATION)
	    nsync1.ShowModal()
	    nsync1 == wx.OK
	    nsync1.Destroy()   
            
        except IOError:
	    traceback.print_exc(file=open("errlog.txt","a"))
	    	    exc_type, exc_value, exc_tb = sys.exc_info()
	    nsync1 = wx.MessageDialog(self, "Data Was Not Transferred Successfully", caption = "Did Not Trnsfer " , style = wx.OK | wx.ICON_EXCLAMATION)
	    nsync1.ShowModal()
	    nsync1 == wx.OK
	    nsync1.Destroy()
        return False 

Open in new window




Exception in thread Thread-3:
Traceback (most recent call last):
  File "C:\Python26\lib\threading.py", line 522, in __bootstrap_inner
    self.run()
  File "c:\Python26\sign\Version2_Client_Side_OCT13_socket_thread.py", line 6504, in run
    nsync1 = wx.MessageDialog(self, "Data Was Not Transferred Successfully", caption = "Did Not Trnsfer " , style = wx.OK | wx.ICON_EXCLAMATION)
  File "C:\Python26\Lib\site-packages\wx-2.8-msw-ansi\wx\_windows.py", line 2922, in __init__
    _windows_.MessageDialog_swiginit(self,_windows_.new_MessageDialog(*args, **kwargs))
TypeError: in method 'new_MessageDialog', expected argument 1 of type 'wxWindow 

Open in new window

*
0
dolamitejenkins
Asked:
dolamitejenkins
  • 2
1 Solution
 
gelonidaCommented:
Quite a lot of graphical frameworsk do not allow to create widgets from any other thread than the thread where the GUI frameworks event loop is running.

Normally it's the main loop of a UI, which schedules and decides when widgets shall be displayed and when user events shall be hadnled.

I am no Wxwidgets specialist, but can sketch out how to do this:
Normally your thread, which wants to show a pop up message should send a message to the GUI
(in QT you can do this with QT signals) and the GUI thread should then display the modal dialog.

I think the signals are called pipes in WxWidgets.

Perhaps somebody who uses wxwidgets can explain better than me.
0
 
dolamitejenkinsAuthor Commented:
thank... it turns out that wxpython allows you to call from any class no big deal... I wasnt assigning it a parent so I changed self to none and it worked
0
 
dolamitejenkinsAuthor Commented:
thanks once again you are a life saver
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now