Link to home
Start Free TrialLog in
Avatar of Dolamite Jenkins
Dolamite JenkinsFlag for United States of America

asked on

call module from different class

I want to call the populate module from the threading class ... How can I do that ? right now I have insertdata.populate and its not throwing and error but it's also not doing what I want




class InsertData(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(990,668),style=wx.DEFAULT_FRAME_STYLE|wx.WS_EX_CONTEXTHELP)
	self.Bind(wx.EVT_CLOSE, self.OnClose)
def populate(self):
        do something




class ThreadClass(threading.Thread,InsertData):
    def run(self):
          do_something
          once_done
       
	    self.repopulate()
    def repopulate(self):	           
	InsertData.populate
	print "done"
ThreadClass().start() 

Open in new window

Avatar of gelonida
gelonida
Flag of France image

Very first issue. is line 18,

which should be

InsertData.populate()

If this doesn't solve the issue I'd go for an approach without multiple inheritance.

create the InsertData intance within your thread and store it for example under self.insert_data.
If you have to pass args during construction time, then use the args / kwargs of the threading object.

http://docs.python.org/library/threading.html#thread-objects



Not knowing wxWidgets and not knowing, what you try to do in populate, and whether you also try to access the widgets from other threads I'd just like to mention, that
many graphical frameworks are rather sensitive if being combined with threading, thus they have very specific means (PyQT has for example signals), which you should use to avoid breaking the framework.

Often you are not allowed to add modify GUI elements from another thread tan the originating GUI thread.



Avatar of Dolamite Jenkins

ASKER

thanks ... I will let you know how it goes... i have to do some research on wxpython ... should I build my future programs with ptqt ?
WxWidgets and PyQt are rather popular and both good options.

I think both require certain measures to work well in a multithreaded setup.

Normally only one thread is allowed to create / destroy manipulate widgets and run the main loop.
other threads had to communicate via signals/slots (Qt) or pipes (Wx)

SW licensing might be one reason to pay attention with PyQt.
- http://www.riverbankcomputing.co.uk/software/pyqt/license
- http://www.wxwidgets.org/about/newlicen.htm

You might also look at PySide  (rather recent LGPL alternative to PyQt)
- http://en.wikipedia.org/wiki/PySide


thanks
ASKER CERTIFIED SOLUTION
Avatar of pepr
pepr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok I will try it ... thanks to you both for your guidance
Avatar of pepr
pepr

It seems to me that you did not want to make your InsertData the base class of your thread class.  You probably wanted to pass the InsertData (bad name) instance (i.e. object of the class) to the thread object (say via __init__ method or somehow else).

You should think more about whether you really need a thread.  It is better to avoid them if threads are not neccessary.

Try to imagine the object personified or visualize it in some other way when thinking about how it all should work. Make the childish drawings (i.e. circles, squares, arrows... all informal).  They are powerful means to help our imagination.
thanks