[wxPython] thread and wxpython probleme

Hi,

what I would like to do is to run a wxpython application from the python shell interpreter and Have the prompt to continu working on both ( wxpython frame and the interpreter ) at the same time !

so i tryed threads !

import thread

thread.start_new_thread(go,())

this function run the wxpython frame and return the prompt but the frame seems to be inactive !!

coold anybody gine me a solution plzz thanksss

I have Linux RedHat 7.1, python 2.2.1, wxpython 2.3.2.1, wxgtk 2.3.2

this is an example :

python -i test.py

import thread

thread.start_new_thread(go,())

···

from wxPython.wx import *

Create a new frame class, derived from the wxPython Frame.

class MyFrame(wxFrame):

def __init__(self, parent, id, title):
    # First, call the base class' __init__ method to create the frame
    wxFrame.__init__(self, parent, id, title,
                     wxPoint(100, 100), wxSize(160, 100))

    # Associate some events with methods of this class
    EVT_SIZE(self, self.OnSize)

    # Add a panel and some controls to display the size and position
    panel = wxPanel(self, -1)
    wxStaticText(panel, -1, "Size:",
                 wxDLG_PNT(panel, wxPoint(4, 4)),  wxDefaultSize)
    self.sizeCtrl = wxTextCtrl(panel, -1, "",
                               wxDLG_PNT(panel, wxPoint(24, 4)),
                        &nb

sp; wxDLG_SZE(panel, wxSize(36, -1)),
wxTE_READONLY)
self.panel = panel

def OnSize(self, event):
    size = event.GetSize()
    self.sizeCtrl.SetValue("%s, %s" % (size.width, size.height))
    event.Skip()

#--------------------------------------------------------------------class MyApp(wxApp):

def OnInit(self):
    frame = MyFrame(NULL, -1, "This is a test")
    frame.Show(true)
    self.SetTopWindow(frame)
    return true

def go():
app = MyApp(0)
app.MainLoop()


Join the world�s largest e-mail service with MSN Hotmail. Click Here

what I would like to do is to run a wxpython application from the python

shell interpreter and Have the prompt to continu working on both ( wxpython
frame and the interpreter ) at the same time !

so i tryed threads !

import thread

thread.start_new_thread(go,())

this function run the wxpython frame and return the prompt but the frame

seems to be inactive !!

coold anybody gine me a solution plzz thanksss

If wxPython is first imported within the context of the second thread, and
all wx methods/functions are called from the second thread, then it will
probably work. IOW, wxPython needs to be imported inside your go()
function, and the classes and etc. created there too.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!

> what I would like to do is to run a wxpython application from the python
shell interpreter and Have the prompt to continu working on both ( wxpython
frame and the interpreter ) at the same time !

What you are trying to do has already been done, and is distibuted as
bpart of the SciPy project:

http://www.scipy.org/site_content/tutorials/gui_thread

I don't know how well it works, but it looks like a good place for you
to start.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                        
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov