473,722 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

wxPython and how to return text entry to main program?

Hello All:

I am currently working on a project to create an FEM model for school.
I was thinking about using wxPython to gather the 12 input variables
from the user, then, after pressing the "Run" button, the GUI would
close, and the 12 input variables would then be available for the rest
of the program.

So far, what I have been able to do is mostly a reverse engineering
job to get the frame to look right and return the text variable to a
dialog box.

I have read about a "redirect" that could be used to send the values
to a file. But, then I would have to open the file and read in the
data from there. This seems crude and lacking elegance.

Any help on how to get the program to output the data back to the main
python program and close when I press submit? My apologies if this is
something of a simple question, but I have only started in on wxPython
about a week ago, and Python this term.

The codes I am using are below.

Any help (or suggested reading material) is greatly appreciated.

Cheers,

t.
MY MAIN PROGRAM

#!/usr/bin/env python
import femGUI
app = femGUI.MyApp(Fa lse)
dlg = femGUI.FemInput ()
dlg.Destroy()
app.MainLoop()

# Then do something with inputs here....

THE FEMINPUT GUI CLASS

import wx

class FemInput(wx.Fra me):
def __init__(self):
wx.Frame.__init __(self, None, -1, "Options Input Interface")
panel = wx.Panel(self)

# First create the controls

# Title
topLbl = wx.StaticText(p anel, -1, "FEM 2D Basket Put Option
",size=(420 ,-1))
topLbl.SetFont( wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))

# S1 lower and upper bounds for grid
s1label = wx.StaticText(p anel, -1, "S1 Low , S2 Low: ",
size=(220,-1))
self.s1lower = wx.TextCtrl(pan el, -1, "", size=(100,-1));
self.s2lower = wx.TextCtrl(pan el, -1, "", size=(100,-1));

# S2 lower and upper bounds for grid
s2label = wx.StaticText(p anel, -1, "S1 High, S2 High: ",
size=(220,-1))
self.s1upper = wx.TextCtrl(pan el, -1, "", size=(100,-1));
self.s2upper = wx.TextCtrl(pan el, -1, "", size=(100,-1));

# S1 and S2 volatility
vlabel = wx.StaticText(p anel, -1, "S1 Volatility, S2
Volatility: ", size=(220,-1))
self.v1vol = wx.TextCtrl(pan el, -1, "", size=(100,-1));
self.v2vol = wx.TextCtrl(pan el, -1, "", size=(100,-1));

# Risk free rate and correlation
prlabel = wx.StaticText(p anel, -1, "Interest Rate,
Correlation: ", size=(220,-1))
self.risk = wx.TextCtrl(pan el, -1, "", size=(100,-1));
self.corr = wx.TextCtrl(pan el, -1, "", size=(100,-1));
# Strike and Exercise Date
kTlabel = wx.StaticText(p anel, -1, "Srike Price, Exercise
Date: ", size=(220,-1))
self.strike = wx.TextCtrl(pan el, -1, "", size=(100,-1));
self.finalT = wx.TextCtrl(pan el, -1, "", size=(100,-1));

# deltaT and deltaX
dTXlabel = wx.StaticText(p anel, -1, "delta T, delta X: ",
size=(220,-1))
self.deltaT = wx.TextCtrl(pan el, -1, "", size=(100,-1));
self.deltaX = wx.TextCtrl(pan el, -1, "", size=(100,-1));
# Execute program
runBtn = wx.Button(panel , -1, "Run")
self.Bind(wx.EV T_BUTTON, self.OnSubmit, runBtn)

# Now do the layout.

# mainSizer is the top-level one that manages everything
mainSizer = wx.BoxSizer(wx. VERTICAL)
mainSizer.Add(t opLbl, 0, wx.ALL, 5)
mainSizer.Add(w x.StaticLine(pa nel), 0,
wx.EXPAND|wx.TO P|wx.BOTTOM, 5)

# femSizer is a grid that holds all of the address info
femSizer = wx.FlexGridSize r(cols=2, hgap=5, vgap=5)
femSizer.AddGro wableCol(1)

# S1 and S2 LOWER label
femSizer.Add(s1 label, 0,
wx.ALIGN_RIGHT| wx.ALIGN_CENTER _VERTICAL)
# the lower and upper S1 bounds are in a sub-sizer
s1Sizer = wx.BoxSizer(wx. HORIZONTAL)
s1Sizer.Add(sel f.s1lower, 1)
s1Sizer.Add((10 ,10)) # some empty space
s1Sizer.Add(sel f.s2lower, 1, wx.LEFT|wx.RIGH T, 5)
femSizer.Add(s1 Sizer, 1, wx.EXPAND)
# S1 and S2 HIGH label
femSizer.Add(s2 label, 0,
wx.ALIGN_RIGHT| wx.ALIGN_CENTER _VERTICAL)
# the lower and upper S1 bounds are in a sub-sizer
s2Sizer = wx.BoxSizer(wx. HORIZONTAL)
s2Sizer.Add(sel f.s1upper, 1)
s2Sizer.Add((10 ,10)) # some empty space
s2Sizer.Add(sel f.s2upper, 1, wx.LEFT|wx.RIGH T, 5)
femSizer.Add(s2 Sizer, 1, wx.EXPAND)
# Volatility label
femSizer.Add(vl abel, 0,
wx.ALIGN_RIGHT| wx.ALIGN_CENTER _VERTICAL)
# the lower and upper S1 bounds are in a sub-sizer
volSizer = wx.BoxSizer(wx. HORIZONTAL)
volSizer.Add(se lf.v1vol, 1)
volSizer.Add((1 0,10)) # some empty space
volSizer.Add(se lf.v2vol, 1, wx.LEFT|wx.RIGH T, 5)
femSizer.Add(vo lSizer, 1, wx.EXPAND)
# Risk free Rate and corelation
femSizer.Add(pr label, 0,
wx.ALIGN_RIGHT| wx.ALIGN_CENTER _VERTICAL)
# the lower and upper S1 bounds are in a sub-sizer
rcSizer = wx.BoxSizer(wx. HORIZONTAL)
rcSizer.Add(sel f.risk, 1)
rcSizer.Add((10 ,10)) # some empty space
rcSizer.Add(sel f.corr, 1, wx.LEFT|wx.RIGH T, 5)
femSizer.Add(rc Sizer, 1, wx.EXPAND)
# Strike and Exercise Date
femSizer.Add(kT label, 0,
wx.ALIGN_RIGHT| wx.ALIGN_CENTER _VERTICAL)
# the lower and upper S1 bounds are in a sub-sizer
ktSizer = wx.BoxSizer(wx. HORIZONTAL)
ktSizer.Add(sel f.strike, 1)
ktSizer.Add((10 ,10)) # some empty space
ktSizer.Add(sel f.finalT, 1, wx.LEFT|wx.RIGH T, 5)
femSizer.Add(kt Sizer, 1, wx.EXPAND)
# deltaT and deltaX
femSizer.Add(dT Xlabel, 0,
wx.ALIGN_RIGHT| wx.ALIGN_CENTER _VERTICAL)
# the lower and upper S1 bounds are in a sub-sizer
dtxSizer = wx.BoxSizer(wx. HORIZONTAL)
dtxSizer.Add(se lf.deltaT, 1)
dtxSizer.Add((1 0,10)) # some empty space
dtxSizer.Add(se lf.deltaX, 1, wx.LEFT|wx.RIGH T, 5)
femSizer.Add(dt xSizer, 1, wx.EXPAND)
# now add the femSizer to the mainSizer
mainSizer.Add(f emSizer, 0, wx.EXPAND|wx.AL L, 10)

# The buttons sizer will put them in a row with resizeable
# gaps between and on either side of the buttons
btnSizer = wx.BoxSizer(wx. HORIZONTAL)
btnSizer.Add((1 0,10)) # some empty space
btnSizer.Add(ru nBtn)
btnSizer.Add((1 0,10)) # some empty space
mainSizer.Add(b tnSizer, 0, wx.EXPAND|wx.BO TTOM, 10)

panel.SetSizer( mainSizer)

# Fit the frame to the needs of the sizer. The frame will
# automatically resize the panel as needed. Also prevent the
# frame from getting smaller than this size.
mainSizer.Fit(s elf)
mainSizer.SetSi zeHints(self)

def OnSubmit(self, evt):
s1low = self.s1lower.Ge tValue()
s2low = self.s2lower.Ge tValue()
s1high = self.s1upper.Ge tValue()
s2high = self.s2upper.Ge tValue()
s1vol = self.v1vol.GetV alue()
s2vol = self.v2vol.GetV alue()
irate = self.risk.GetVa lue()
pcorr = self.corr.GetVa lue()
kprice = self.strike.Get Value()
totalT = self.finalT.Get Value()
delT = self.deltaT.Get Value()
delX = self.deltaX.Get Value()
wx.MessageBox(' You chose: \n %s \n %s \n %s \n %s \
\n %s \n %s \n %s' %
(s1low,s2low,s1 high,s2high,s1v ol,s2vol,irate) )
# I want to do something like this below....
# return s1low,s2low,s1h igh,s2high,s1vo l,s2vol,irate

class MyApp(wx.App):

def OnInit(self):
frame = FemInput()
self.SetTopWind ow(frame)
frame.Show()
return True
# Needed if called as a module
if __name__ == '__main__':
app = MyApp(False)
app.MainLoop()

Apr 19 '07 #1
9 4442
On Apr 19, 2:38 pm, Tyler <hayes.ty...@gm ail.comwrote:
Hello All:

I am currently working on a project to create an FEM model for school.
I was thinking about using wxPython to gather the 12 input variables
from the user, then, after pressing the "Run" button, the GUI would
close, and the 12 input variables would then be available for the rest
of the program.

So far, what I have been able to do is mostly a reverse engineering
job to get the frame to look right and return the text variable to a
dialog box.

I have read about a "redirect" that could be used to send the values
to a file. But, then I would have to open the file and read in the
data from there. This seems crude and lacking elegance.

Any help on how to get the program to output the data back to the main
python program and close when I press submit? My apologies if this is
something of a simple question, but I have only started in on wxPython
about a week ago, and Python this term.

The codes I am using are below.

Any help (or suggested reading material) is greatly appreciated.

Cheers,

t.

MY MAIN PROGRAM

#!/usr/bin/env python
import femGUI
app = femGUI.MyApp(Fa lse)
dlg = femGUI.FemInput ()
dlg.Destroy()
app.MainLoop()

# Then do something with inputs here....

THE FEMINPUT GUI CLASS

import wx

class FemInput(wx.Fra me):
def __init__(self):
wx.Frame.__init __(self, None, -1, "Options Input Interface")
panel = wx.Panel(self)

# First create the controls

# Title
topLbl = wx.StaticText(p anel, -1, "FEM 2D Basket Put Option
",size=(420 ,-1))
topLbl.SetFont( wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))

# S1 lower and upper bounds for grid
s1label = wx.StaticText(p anel, -1, "S1 Low , S2 Low: ",
size=(220,-1))
self.s1lower = wx.TextCtrl(pan el, -1, "", size=(100,-1));
self.s2lower = wx.TextCtrl(pan el, -1, "", size=(100,-1));

# S2 lower and upper bounds for grid
s2label = wx.StaticText(p anel, -1, "S1 High, S2 High: ",
size=(220,-1))
self.s1upper = wx.TextCtrl(pan el, -1, "", size=(100,-1));
self.s2upper = wx.TextCtrl(pan el, -1, "", size=(100,-1));

# S1 and S2 volatility
vlabel = wx.StaticText(p anel, -1, "S1 Volatility, S2
Volatility: ", size=(220,-1))
self.v1vol = wx.TextCtrl(pan el, -1, "", size=(100,-1));
self.v2vol = wx.TextCtrl(pan el, -1, "", size=(100,-1));

# Risk free rate and correlation
prlabel = wx.StaticText(p anel, -1, "Interest Rate,
Correlation: ", size=(220,-1))
self.risk = wx.TextCtrl(pan el, -1, "", size=(100,-1));
self.corr = wx.TextCtrl(pan el, -1, "", size=(100,-1));

# Strike and Exercise Date
kTlabel = wx.StaticText(p anel, -1, "Srike Price, Exercise
Date: ", size=(220,-1))
self.strike = wx.TextCtrl(pan el, -1, "", size=(100,-1));
self.finalT = wx.TextCtrl(pan el, -1, "", size=(100,-1));

# deltaT and deltaX
dTXlabel = wx.StaticText(p anel, -1, "delta T, delta X: ",
size=(220,-1))
self.deltaT = wx.TextCtrl(pan el, -1, "", size=(100,-1));
self.deltaX = wx.TextCtrl(pan el, -1, "", size=(100,-1));

# Execute program
runBtn = wx.Button(panel , -1, "Run")
self.Bind(wx.EV T_BUTTON, self.OnSubmit, runBtn)

# Now do the layout.

# mainSizer is the top-level one that manages everything
mainSizer = wx.BoxSizer(wx. VERTICAL)
mainSizer.Add(t opLbl, 0, wx.ALL, 5)
mainSizer.Add(w x.StaticLine(pa nel), 0,
wx.EXPAND|wx.TO P|wx.BOTTOM, 5)

# femSizer is a grid that holds all of the address info
femSizer = wx.FlexGridSize r(cols=2, hgap=5, vgap=5)
femSizer.AddGro wableCol(1)

# S1 and S2 LOWER label
femSizer.Add(s1 label, 0,
wx.ALIGN_RIGHT| wx.ALIGN_CENTER _VERTICAL)
# the lower and upper S1 bounds are in a sub-sizer
s1Sizer = wx.BoxSizer(wx. HORIZONTAL)
s1Sizer.Add(sel f.s1lower, 1)
s1Sizer.Add((10 ,10)) # some empty space
s1Sizer.Add(sel f.s2lower, 1, wx.LEFT|wx.RIGH T, 5)
femSizer.Add(s1 Sizer, 1, wx.EXPAND)

# S1 and S2 HIGH label
femSizer.Add(s2 label, 0,
wx.ALIGN_RIGHT| wx.ALIGN_CENTER _VERTICAL)
# the lower and upper S1 bounds are in a sub-sizer
s2Sizer = wx.BoxSizer(wx. HORIZONTAL)
s2Sizer.Add(sel f.s1upper, 1)
s2Sizer.Add((10 ,10)) # some empty space
s2Sizer.Add(sel f.s2upper, 1, wx.LEFT|wx.RIGH T, 5)
femSizer.Add(s2 Sizer, 1, wx.EXPAND)

# Volatility label
femSizer.Add(vl abel, 0,
wx.ALIGN_RIGHT| wx.ALIGN_CENTER _VERTICAL)
# the lower and upper S1 bounds are in a sub-sizer
volSizer = wx.BoxSizer(wx. HORIZONTAL)
volSizer.Add(se lf.v1vol, 1)
volSizer.Add((1 0,10)) # some empty space
volSizer.Add(se lf.v2vol, 1, wx.LEFT|wx.RIGH T, 5)
femSizer.Add(vo lSizer, 1, wx.EXPAND)

# Risk free Rate and corelation
femSizer.Add(pr label, 0,
wx.ALIGN_RIGHT| wx.ALIGN_CENTER _VERTICAL)
# the lower and upper S1 bounds are in a sub-sizer
rcSizer = wx.BoxSizer(wx. HORIZONTAL)
rcSizer.Add(sel f.risk, 1)
rcSizer.Add((10 ,10)) # some empty space
rcSizer.Add(sel f.corr, 1, wx.LEFT|wx.RIGH T, 5)
femSizer.Add(rc Sizer, 1, wx.EXPAND)

# Strike and Exercise Date
femSizer.Add(kT label, 0,
wx.ALIGN_RIGHT| wx.ALIGN_CENTER _VERTICAL)
# the lower and upper S1 bounds are in a sub-sizer
ktSizer = wx.BoxSizer(wx. HORIZONTAL)
ktSizer.Add(sel f.strike, 1)
ktSizer.Add((10 ,10)) # some empty space
ktSizer.Add(sel f.finalT, 1, wx.LEFT|wx.RIGH T, 5)
femSizer.Add(kt Sizer, 1, wx.EXPAND)

# deltaT and deltaX
femSizer.Add(dT Xlabel, 0,
wx.ALIGN_RIGHT| wx.ALIGN_CENTER _VERTICAL)
# the lower and upper S1 bounds are in a sub-sizer
dtxSizer = wx.BoxSizer(wx. HORIZONTAL)
dtxSizer.Add(se lf.deltaT, 1)
dtxSizer.Add((1 0,10)) # some empty space
dtxSizer.Add(se lf.deltaX, 1, wx.LEFT|wx.RIGH T, 5)
femSizer.Add(dt xSizer, 1, wx.EXPAND)

# now add the femSizer to the mainSizer
mainSizer.Add(f emSizer, 0, wx.EXPAND|wx.AL L, 10)

# The buttons sizer will put them in a row with resizeable
# gaps between and on either side of the buttons
btnSizer = wx.BoxSizer(wx. HORIZONTAL)
btnSizer.Add((1 0,10)) # some empty space
btnSizer.Add(ru nBtn)
btnSizer.Add((1 0,10)) # some empty space
mainSizer.Add(b tnSizer, 0, wx.EXPAND|wx.BO TTOM, 10)

panel.SetSizer( mainSizer)

# Fit the frame to the needs of the sizer. The frame will
# automatically resize the panel as needed. Also prevent the
# frame from getting smaller than this size.
mainSizer.Fit(s elf)
mainSizer.SetSi zeHints(self)

def OnSubmit(self, evt):
s1low = self.s1lower.Ge tValue()
s2low = self.s2lower.Ge tValue()
s1high = self.s1upper.Ge tValue()
s2high = self.s2upper.Ge tValue()
s1vol = self.v1vol.GetV alue()
s2vol = self.v2vol.GetV alue()
irate = self.risk.GetVa lue()
pcorr = self.corr.GetVa lue()
kprice = self.strike.Get Value()
totalT = self.finalT.Get Value()
delT = self.deltaT.Get Value()
delX = self.deltaX.Get Value()
wx.MessageBox(' You chose: \n %s \n %s \n %s \n %s \
\n %s \n %s \n %s' %
(s1low,s2low,s1 high,s2high,s1v ol,s2vol,irate) )
# I want to do something like this below....
# return s1low,s2low,s1h igh,s2high,s1vo l,s2vol,irate

class MyApp(wx.App):

def OnInit(self):
frame = FemInput()
self.SetTopWind ow(frame)
frame.Show()
return True

# Needed if called as a module
if __name__ == '__main__':
app = MyApp(False)
app.MainLoop()
Right now I can't figure it out...but you can close it by sticking the
following code as the last line in the OnSubmit method:

self.Close(True )

Also, I highly recommend the wxPython in Action book by Robin Dunn.
You might also submit wxPython questions to the wxPython mailing group
at http://wxpython.org/maillist.php

Sorry I wasn't of more help.

Mike

Apr 19 '07 #2
Tyler wrote:
Hello All:

I am currently working on a project to create an FEM model for school.
I was thinking about using wxPython to gather the 12 input variables
from the user, then, after pressing the "Run" button, the GUI would
close, and the 12 input variables would then be available for the rest
of the program.

So far, what I have been able to do is mostly a reverse engineering
job to get the frame to look right and return the text variable to a
dialog box.

I have read about a "redirect" that could be used to send the values
to a file. But, then I would have to open the file and read in the
data from there. This seems crude and lacking elegance.

Any help on how to get the program to output the data back to the main
python program and close when I press submit? My apologies if this is
something of a simple question, but I have only started in on wxPython
about a week ago, and Python this term.

The codes I am using are below.

Any help (or suggested reading material) is greatly appreciated.
There are two basic ways to do this. The first is to pass in something
that can store the values collected by the window. The second is to have
the values stored as attributes of the dialog and then extract them
after the user has finished interacting with the dialog but before you
Destroy() it.

See comments in the code. I have actually appended a version that works.
Maybe not the prettiest way to achieve what you want but it works.
>
Cheers,

t.
MY MAIN PROGRAM

#!/usr/bin/env python
import femGUI
app = femGUI.MyApp(Fa lse)
dlg = femGUI.FemInput ()
So this is where you create your FemInput object. Here's where you could
pass it an object to receive the data values.

Assuming you want to store them as named attributes, about the simplest
thing you can use is an instance of some object. Here's an example in
the interactive interpreter:
>>class O: pass
...
>>myo = O()
myo.a = "hello"
myo.b = "world"
myo.a
'hello'
>>>
So you could change that last line to

class Data: pass
data = Data()
app = femGUI.FemInput (data)

Of course this will mean edits below.
dlg.Destroy()
It seems a bit strange to be destroying your dialog before you've
actually called the MainLoop to start doing the windowing. I have to
take your word for it that this works ... it's almost certainly the
reason why you are having problems getting data out of the window. Or
maybe not.

I see when you run the program the window doesn't disappear when you
terminate the dialog. That's probably because (unless you want to do
more windowing stuff) you probably want to use ShowModal instead. This
will terminate the dialog and have it return to the caller when it's
finished.

Hmm, the whole structure's a little bit loopy ... and a FemInput window
has to be a dialog if you're going to use ShowModal() on it anyway ...
that's not good. It means the top-level frame has to Destroy() itself to
terminate the main loop and let you continue with the non-graphical portion.
app.MainLoop()

# Then do something with inputs here....
The problem at the moment is by the time you are ready to "do something
with the inputs" you have terminated your graphical environment - it is,
to coin a phrase, an *ex*-graphical environemnt, and it's too late to
poke about in it.

OK, here's a new main program for you. To make the "lines of
communication" a but more obvious it includes a definition of the MyApp
class.

#!/usr/bin/env python
import wx
import femGUI

class S: pass

s = S()

class MyApp(wx.App):
"You can throw away the MyApp in femGUI."

def OnInit(self):
myFrame = femGUI.FemInput (s) # passes storage object in
self.SetTopWind ow(myFrame)
myFrame.Show()
return True

app = MyApp(False)
app.MainLoop()

print dir(storage)

The statement at the end is just to show you that the attributes exist.
From there you can do what you want.

Now it turns out you don't need to make that many modifications to your
class definition.
>

THE FEMINPUT GUI CLASS

import wx

class FemInput(wx.Fra me):
def __init__(self):
The above line has to change because we have to accept, and store, a
reference to the storage object we provide in the FemInput constructor.

def __init__(self, storage):
self.storage = storage

Most if it is pretty much standard from here on, but keep reading.
wx.Frame.__init __(self, None, -1, "Options Input Interface")
panel = wx.Panel(self)

# First create the controls

# Title
topLbl = wx.StaticText(p anel, -1, "FEM 2D Basket Put Option
",size=(420 ,-1))
topLbl.SetFont( wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))

# S1 lower and upper bounds for grid
s1label = wx.StaticText(p anel, -1, "S1 Low , S2 Low: ",
size=(220,-1))
self.s1lower = wx.TextCtrl(pan el, -1, "", size=(100,-1));
self.s2lower = wx.TextCtrl(pan el, -1, "", size=(100,-1));

# S2 lower and upper bounds for grid
s2label = wx.StaticText(p anel, -1, "S1 High, S2 High: ",
size=(220,-1))
self.s1upper = wx.TextCtrl(pan el, -1, "", size=(100,-1));
self.s2upper = wx.TextCtrl(pan el, -1, "", size=(100,-1));

# S1 and S2 volatility
vlabel = wx.StaticText(p anel, -1, "S1 Volatility, S2
Volatility: ", size=(220,-1))
self.v1vol = wx.TextCtrl(pan el, -1, "", size=(100,-1));
self.v2vol = wx.TextCtrl(pan el, -1, "", size=(100,-1));

# Risk free rate and correlation
prlabel = wx.StaticText(p anel, -1, "Interest Rate,
Correlation: ", size=(220,-1))
self.risk = wx.TextCtrl(pan el, -1, "", size=(100,-1));
self.corr = wx.TextCtrl(pan el, -1, "", size=(100,-1));
# Strike and Exercise Date
kTlabel = wx.StaticText(p anel, -1, "Srike Price, Exercise
Date: ", size=(220,-1))
self.strike = wx.TextCtrl(pan el, -1, "", size=(100,-1));
self.finalT = wx.TextCtrl(pan el, -1, "", size=(100,-1));

# deltaT and deltaX
dTXlabel = wx.StaticText(p anel, -1, "delta T, delta X: ",
size=(220,-1))
self.deltaT = wx.TextCtrl(pan el, -1, "", size=(100,-1));
self.deltaX = wx.TextCtrl(pan el, -1, "", size=(100,-1));
# Execute program
runBtn = wx.Button(panel , -1, "Run")
self.Bind(wx.EV T_BUTTON, self.OnSubmit, runBtn)

# Now do the layout.

# mainSizer is the top-level one that manages everything
mainSizer = wx.BoxSizer(wx. VERTICAL)
mainSizer.Add(t opLbl, 0, wx.ALL, 5)
mainSizer.Add(w x.StaticLine(pa nel), 0,
wx.EXPAND|wx.TO P|wx.BOTTOM, 5)

# femSizer is a grid that holds all of the address info
femSizer = wx.FlexGridSize r(cols=2, hgap=5, vgap=5)
femSizer.AddGro wableCol(1)

# S1 and S2 LOWER label
femSizer.Add(s1 label, 0,
wx.ALIGN_RIGHT| wx.ALIGN_CENTER _VERTICAL)
# the lower and upper S1 bounds are in a sub-sizer
s1Sizer = wx.BoxSizer(wx. HORIZONTAL)
s1Sizer.Add(sel f.s1lower, 1)
s1Sizer.Add((10 ,10)) # some empty space
s1Sizer.Add(sel f.s2lower, 1, wx.LEFT|wx.RIGH T, 5)
femSizer.Add(s1 Sizer, 1, wx.EXPAND)
# S1 and S2 HIGH label
femSizer.Add(s2 label, 0,
wx.ALIGN_RIGHT| wx.ALIGN_CENTER _VERTICAL)
# the lower and upper S1 bounds are in a sub-sizer
s2Sizer = wx.BoxSizer(wx. HORIZONTAL)
s2Sizer.Add(sel f.s1upper, 1)
s2Sizer.Add((10 ,10)) # some empty space
s2Sizer.Add(sel f.s2upper, 1, wx.LEFT|wx.RIGH T, 5)
femSizer.Add(s2 Sizer, 1, wx.EXPAND)
# Volatility label
femSizer.Add(vl abel, 0,
wx.ALIGN_RIGHT| wx.ALIGN_CENTER _VERTICAL)
# the lower and upper S1 bounds are in a sub-sizer
volSizer = wx.BoxSizer(wx. HORIZONTAL)
volSizer.Add(se lf.v1vol, 1)
volSizer.Add((1 0,10)) # some empty space
volSizer.Add(se lf.v2vol, 1, wx.LEFT|wx.RIGH T, 5)
femSizer.Add(vo lSizer, 1, wx.EXPAND)
# Risk free Rate and corelation
femSizer.Add(pr label, 0,
wx.ALIGN_RIGHT| wx.ALIGN_CENTER _VERTICAL)
# the lower and upper S1 bounds are in a sub-sizer
rcSizer = wx.BoxSizer(wx. HORIZONTAL)
rcSizer.Add(sel f.risk, 1)
rcSizer.Add((10 ,10)) # some empty space
rcSizer.Add(sel f.corr, 1, wx.LEFT|wx.RIGH T, 5)
femSizer.Add(rc Sizer, 1, wx.EXPAND)
# Strike and Exercise Date
femSizer.Add(kT label, 0,
wx.ALIGN_RIGHT| wx.ALIGN_CENTER _VERTICAL)
# the lower and upper S1 bounds are in a sub-sizer
ktSizer = wx.BoxSizer(wx. HORIZONTAL)
ktSizer.Add(sel f.strike, 1)
ktSizer.Add((10 ,10)) # some empty space
ktSizer.Add(sel f.finalT, 1, wx.LEFT|wx.RIGH T, 5)
femSizer.Add(kt Sizer, 1, wx.EXPAND)
# deltaT and deltaX
femSizer.Add(dT Xlabel, 0,
wx.ALIGN_RIGHT| wx.ALIGN_CENTER _VERTICAL)
# the lower and upper S1 bounds are in a sub-sizer
dtxSizer = wx.BoxSizer(wx. HORIZONTAL)
dtxSizer.Add(se lf.deltaT, 1)
dtxSizer.Add((1 0,10)) # some empty space
dtxSizer.Add(se lf.deltaX, 1, wx.LEFT|wx.RIGH T, 5)
femSizer.Add(dt xSizer, 1, wx.EXPAND)
# now add the femSizer to the mainSizer
mainSizer.Add(f emSizer, 0, wx.EXPAND|wx.AL L, 10)

# The buttons sizer will put them in a row with resizeable
# gaps between and on either side of the buttons
btnSizer = wx.BoxSizer(wx. HORIZONTAL)
btnSizer.Add((1 0,10)) # some empty space
btnSizer.Add(ru nBtn)
btnSizer.Add((1 0,10)) # some empty space
mainSizer.Add(b tnSizer, 0, wx.EXPAND|wx.BO TTOM, 10)

panel.SetSizer( mainSizer)

# Fit the frame to the needs of the sizer. The frame will
# automatically resize the panel as needed. Also prevent the
# frame from getting smaller than this size.
mainSizer.Fit(s elf)
mainSizer.SetSi zeHints(self)

def OnSubmit(self, evt):
s1low = self.s1lower.Ge tValue()
s2low = self.s2lower.Ge tValue()
s1high = self.s1upper.Ge tValue()
s2high = self.s2upper.Ge tValue()
s1vol = self.v1vol.GetV alue()
s2vol = self.v2vol.GetV alue()
irate = self.risk.GetVa lue()
pcorr = self.corr.GetVa lue()
kprice = self.strike.Get Value()
totalT = self.finalT.Get Value()
delT = self.deltaT.Get Value()
delX = self.deltaX.Get Value()
wx.MessageBox(' You chose: \n %s \n %s \n %s \n %s \
\n %s \n %s \n %s' %
(s1low,s2low,s1 high,s2high,s1v ol,s2vol,irate) )
# I want to do something like this below....
# return s1low,s2low,s1h igh,s2high,s1vo l,s2vol,irate
This is the crux. Here you have to Destroy() the frame (self) for the
MainLoop to terminate properly, so you have to save the values before
you do that. So replace this whole method with something like

def OnSubmit(self, evt):
"The user has filled in the required values and want to run"
self.storage.s1 low = self.s1lower.Ge tValue()
self.storage.s2 low = self.s2lower.Ge tValue()
self.storage.s1 high = self.s1upper.Ge tValue()
self.storage.s2 high = self.s2upper.Ge tValue()
self.storage.s1 vol = self.v1vol.GetV alue()
self.storage.s2 vol = self.v2vol.GetV alue()
self.storage.ir ate = self.risk.GetVa lue()
self.storage.pc orr = self.corr.GetVa lue()
self.storage.kp rice = self.strike.Get Value()
self.storage.to talT = self.finalT.Get Value()
self.storage.de lT = self.deltaT.Get Value()
self.storage.de lX = self.deltaX.Get Value()
self.Destroy()
>

class MyApp(wx.App):

def OnInit(self):
frame = FemInput()
self.SetTopWind ow(frame)
frame.Show()
return True
# Needed if called as a module
if __name__ == '__main__':
app = MyApp(False)
app.MainLoop()

Good luck!

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com

Apr 19 '07 #3
Hi Mike:

I actually just picked up the wxPython in Action book the other day
and my main class is a hack of his "realworld_prin t.py" program, with
some added bells and whistles. I will try to post on the wxPython
mailing list and let them have a go at it.

Cheers,

tyler
Apr 19 '07 #4
On Apr 19, 1:38 pm, Tyler <hayes.ty...@gm ail.comwrote:
Hello All:

I am currently working on a project to create an FEM model for school.
I was thinking about using wxPython to gather the 12 input variables
from the user, then, after pressing the "Run" button, the GUI would
close, and the 12 input variables would then be available for the rest
of the program.

So far, what I have been able to do is mostly a reverse engineering
job to get the frame to look right and return the text variable to a
dialog box.

I have read about a "redirect" that could be used to send the values
to a file. But, then I would have to open the file and read in the
data from there. This seems crude and lacking elegance.

Any help on how to get the program to output the data back to the main
python program and close when I press submit? My apologies if this is
something of a simple question, but I have only started in on wxPython
about a week ago, and Python this term.

The codes I am using are below.

Any help (or suggested reading material) is greatly appreciated.

Cheers,

t.

MY MAIN PROGRAM

#!/usr/bin/env python
import femGUI
app = femGUI.MyApp(Fa lse)
dlg = femGUI.FemInput ()
dlg.Destroy()
app.MainLoop()

# Then do something with inputs here....

THE FEMINPUT GUI CLASS

import wx

class FemInput(wx.Fra me):
def __init__(self):
wx.Frame.__init __(self, None, -1, "Options Input Interface")
panel = wx.Panel(self)

# First create the controls

# Title
topLbl = wx.StaticText(p anel, -1, "FEM 2D Basket Put Option
",size=(420 ,-1))
topLbl.SetFont( wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))

# S1 lower and upper bounds for grid
s1label = wx.StaticText(p anel, -1, "S1 Low , S2 Low: ",
size=(220,-1))
self.s1lower = wx.TextCtrl(pan el, -1, "", size=(100,-1));
self.s2lower = wx.TextCtrl(pan el, -1, "", size=(100,-1));

# S2 lower and upper bounds for grid
s2label = wx.StaticText(p anel, -1, "S1 High, S2 High: ",
size=(220,-1))
self.s1upper = wx.TextCtrl(pan el, -1, "", size=(100,-1));
self.s2upper = wx.TextCtrl(pan el, -1, "", size=(100,-1));

# S1 and S2 volatility
vlabel = wx.StaticText(p anel, -1, "S1 Volatility, S2
Volatility: ", size=(220,-1))
self.v1vol = wx.TextCtrl(pan el, -1, "", size=(100,-1));
self.v2vol = wx.TextCtrl(pan el, -1, "", size=(100,-1));

# Risk free rate and correlation
prlabel = wx.StaticText(p anel, -1, "Interest Rate,
Correlation: ", size=(220,-1))
self.risk = wx.TextCtrl(pan el, -1, "", size=(100,-1));
self.corr = wx.TextCtrl(pan el, -1, "", size=(100,-1));

# Strike and Exercise Date
kTlabel = wx.StaticText(p anel, -1, "Srike Price, Exercise
Date: ", size=(220,-1))
self.strike = wx.TextCtrl(pan el, -1, "", size=(100,-1));
self.finalT = wx.TextCtrl(pan el, -1, "", size=(100,-1));

# deltaT and deltaX
dTXlabel = wx.StaticText(p anel, -1, "delta T, delta X: ",
size=(220,-1))
self.deltaT = wx.TextCtrl(pan el, -1, "", size=(100,-1));
self.deltaX = wx.TextCtrl(pan el, -1, "", size=(100,-1));

# Execute program
runBtn = wx.Button(panel , -1, "Run")
self.Bind(wx.EV T_BUTTON, self.OnSubmit, runBtn)

# Now do the layout.

# mainSizer is the top-level one that manages everything
mainSizer = wx.BoxSizer(wx. VERTICAL)
mainSizer.Add(t opLbl, 0, wx.ALL, 5)
mainSizer.Add(w x.StaticLine(pa nel), 0,
wx.EXPAND|wx.TO P|wx.BOTTOM, 5)

# femSizer is a grid that holds all of the address info
femSizer = wx.FlexGridSize r(cols=2, hgap=5, vgap=5)
femSizer.AddGro wableCol(1)

# S1 and S2 LOWER label
femSizer.Add(s1 label, 0,
wx.ALIGN_RIGHT| wx.ALIGN_CENTER _VERTICAL)
# the lower and upper S1 bounds are in a sub-sizer
s1Sizer = wx.BoxSizer(wx. HORIZONTAL)
s1Sizer.Add(sel f.s1lower, 1)
s1Sizer.Add((10 ,10)) # some empty space
s1Sizer.Add(sel f.s2lower, 1, wx.LEFT|wx.RIGH T, 5)
femSizer.Add(s1 Sizer, 1, wx.EXPAND)

# S1 and S2 HIGH label
femSizer.Add(s2 label, 0,
wx.ALIGN_RIGHT| wx.ALIGN_CENTER _VERTICAL)
# the lower and upper S1 bounds are in a sub-sizer
s2Sizer = wx.BoxSizer(wx. HORIZONTAL)
s2Sizer.Add(sel f.s1upper, 1)
s2Sizer.Add((10 ,10)) # some empty space
s2Sizer.Add(sel f.s2upper, 1, wx.LEFT|wx.RIGH T, 5)
femSizer.Add(s2 Sizer, 1, wx.EXPAND)

# Volatility label
femSizer.Add(vl abel, 0,
wx.ALIGN_RIGHT| wx.ALIGN_CENTER _VERTICAL)
# the lower and upper S1 bounds are in a sub-sizer
volSizer = wx.BoxSizer(wx. HORIZONTAL)
volSizer.Add(se lf.v1vol, 1)
volSizer.Add((1 0,10)) # some empty space
volSizer.Add(se lf.v2vol, 1, wx.LEFT|wx.RIGH T, 5)
femSizer.Add(vo lSizer, 1, wx.EXPAND)

# Risk free Rate and corelation
femSizer.Add(pr label, 0,
wx.ALIGN_RIGHT| wx.ALIGN_CENTER _VERTICAL)
# the lower and upper S1 bounds are in a sub-sizer
rcSizer = wx.BoxSizer(wx. HORIZONTAL)
rcSizer.Add(sel f.risk, 1)
rcSizer.Add((10 ,10)) # some empty space
rcSizer.Add(sel f.corr, 1, wx.LEFT|wx.RIGH T, 5)
femSizer.Add(rc Sizer, 1, wx.EXPAND)

# Strike and Exercise Date
femSizer.Add(kT label, 0,
wx.ALIGN_RIGHT| wx.ALIGN_CENTER _VERTICAL)
# the lower and upper S1 bounds are in a sub-sizer
ktSizer = wx.BoxSizer(wx. HORIZONTAL)
ktSizer.Add(sel f.strike, 1)
ktSizer.Add((10 ,10)) # some empty space
ktSizer.Add(sel f.finalT, 1, wx.LEFT|wx.RIGH T, 5)
femSizer.Add(kt Sizer, 1, wx.EXPAND)

# deltaT and deltaX
femSizer.Add(dT Xlabel, 0,
wx.ALIGN_RIGHT| wx.ALIGN_CENTER _VERTICAL)
# the lower and upper S1 bounds are in a sub-sizer
dtxSizer = wx.BoxSizer(wx. HORIZONTAL)
dtxSizer.Add(se lf.deltaT, 1)
dtxSizer.Add((1 0,10)) # some empty space
dtxSizer.Add(se lf.deltaX, 1, wx.LEFT|wx.RIGH T, 5)
femSizer.Add(dt xSizer, 1, wx.EXPAND)

# now add the femSizer to the mainSizer
mainSizer.Add(f emSizer, 0, wx.EXPAND|wx.AL L, 10)

# The buttons sizer will put them in a row with resizeable
# gaps between and on either side of the buttons
btnSizer = wx.BoxSizer(wx. HORIZONTAL)
btnSizer.Add((1 0,10)) # some empty space
btnSizer.Add(ru nBtn)
btnSizer.Add((1 0,10)) # some empty space
mainSizer.Add(b tnSizer, 0, wx.EXPAND|wx.BO TTOM, 10)

panel.SetSizer( mainSizer)

# Fit the frame to the needs of the sizer. The frame will
# automatically resize the panel as needed. Also prevent the
# frame from getting smaller than this size.
mainSizer.Fit(s elf)
mainSizer.SetSi zeHints(self)

def OnSubmit(self, evt):
s1low = self.s1lower.Ge tValue()
s2low = self.s2lower.Ge tValue()
s1high = self.s1upper.Ge tValue()
s2high = self.s2upper.Ge tValue()
s1vol = self.v1vol.GetV alue()
s2vol = self.v2vol.GetV alue()
irate = self.risk.GetVa lue()
pcorr = self.corr.GetVa lue()
kprice = self.strike.Get Value()
totalT = self.finalT.Get Value()
delT = self.deltaT.Get Value()
delX = self.deltaX.Get Value()
wx.MessageBox(' You chose: \n %s \n %s \n %s \n %s \
\n %s \n %s \n %s' %
(s1low,s2low,s1 high,s2high,s1v ol,s2vol,irate) )
# I want to do something like this below....
# return s1low,s2low,s1h igh,s2high,s1vo l,s2vol,irate

class MyApp(wx.App):

def OnInit(self):
frame = FemInput()
self.SetTopWind ow(frame)
frame.Show()
return True

# Needed if called as a module
if __name__ == '__main__':
app = MyApp(False)
app.MainLoop()

You can do this:

---
class MyFrame(wx.Fram e):

...
...
...
def OnSubmit(self, event):
globals()["userInput"] = self.txtCtrlNam e.GetValue()
self.Close()

app = MyApp()
app.MainLoop()

print userInput
-----

Apr 20 '07 #5
Thanks everyone for your help!

Cheers,

t.
Apr 20 '07 #6
7stud wrote:
On Apr 19, 1:38 pm, Tyler <hayes.ty...@gm ail.comwrote:
[after quoting umpteen lines of code]
>
You can do this:

---
class MyFrame(wx.Fram e):

..
..
..
def OnSubmit(self, event):
globals()["userInput"] = self.txtCtrlNam e.GetValue()
self.Close()

app = MyApp()
app.MainLoop()

print userInput
-----

Please try to limit your quoting to what's relevant.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com

Apr 20 '07 #7
On Apr 19, 9:05 pm, Steve Holden <s...@holdenweb .comwrote:
7stud wrote:
On Apr 19, 1:38 pm, Tyler <hayes.ty...@gm ail.comwrote:

[after quoting umpteen lines of code]


You can do this:
---
class MyFrame(wx.Fram e):
..
..
..
def OnSubmit(self, event):
globals()["userInput"] = self.txtCtrlNam e.GetValue()
self.Close()
app = MyApp()
app.MainLoop()
print userInput
-----

Please try to limit your quoting to what's relevant.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com
Steve,

I think Tyler is opening a custom dialog from his main GUI
application. He should have used "ShowModal" if he was using one of
wxPython's standard dialog boxes, but since he was creating his own
custom one he didn't need to, which is why I told him to use the
self.Close(True ) method to destroy the dialog. Then again, maybe I am
being "wrong-headed" about the whole thing.

I was trying to come up with the "instance variable" way of storing
the variables, but I could not think of how to implement it last
night. Here are some other threads on the topic that I thought were
interesting:

http://mail.python.org/pipermail/tut...ay/038648.html
http://lists.wxwidgets.org/archive/w.../msg06482.html
http://www.daniweb.com/techtalkforums/thread60439.html

Mike

Apr 20 '07 #8
On Apr 19, 9:05 pm, Steve Holden <s...@holdenweb .comwrote:
7stud wrote:
On Apr 19, 1:38 pm, Tyler <hayes.ty...@gm ail.comwrote:

[after quoting umpteen lines of code]


You can do this:
---
class MyFrame(wx.Fram e):
..
..
..
def OnSubmit(self, event):
globals()["userInput"] = self.txtCtrlNam e.GetValue()
self.Close()
app = MyApp()
app.MainLoop()
print userInput
-----

Please try to limit your quoting to what's relevant.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com
Steve,

I think Tyler is opening a custom dialog from his main GUI
application. He should have used "ShowModal" if he was using one of
wxPython's standard dialog boxes, but since he was creating his own
custom one he didn't need to, which is why I told him to use the
self.Close(True ) method to destroy the dialog. Then again, maybe I am
being "wrong-headed" about the whole thing.

I was trying to come up with the "instance variable" way of storing
the variables, but I could not think of how to implement it last
night. Here are some other threads on the topic that I thought were
interesting:

http://mail.python.org/pipermail/tut...ay/038648.html
http://lists.wxwidgets.org/archive/w.../msg06482.html
http://www.daniweb.com/techtalkforums/thread60439.html

Mike
Apr 20 '07 #9
ky******@gmail. com wrote:
On Apr 19, 9:05 pm, Steve Holden <s...@holdenweb .comwrote:
>7stud wrote:
>>On Apr 19, 1:38 pm, Tyler <hayes.ty...@gm ail.comwrote:
[after quoting umpteen lines of code]


>>You can do this:
---
class MyFrame(wx.Fram e):
..
..
..
def OnSubmit(self, event):
globals()["userInput"] = self.txtCtrlNam e.GetValue()
self.Close()
app = MyApp()
app.MainLoop( )
print userInput
-----
Please try to limit your quoting to what's relevant.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com

Steve,

I think Tyler is opening a custom dialog from his main GUI
application. He should have used "ShowModal" if he was using one of
wxPython's standard dialog boxes, but since he was creating his own
custom one he didn't need to, which is why I told him to use the
self.Close(True ) method to destroy the dialog. Then again, maybe I am
being "wrong-headed" about the whole thing.

I was trying to come up with the "instance variable" way of storing
the variables, but I could not think of how to implement it last
night. Here are some other threads on the topic that I thought were
interesting:

http://mail.python.org/pipermail/tut...ay/038648.html
http://lists.wxwidgets.org/archive/w.../msg06482.html
http://www.daniweb.com/techtalkforums/thread60439.html

Well, if the whole application is GUI based then yes, the dialog should
inherit from wx.Dialog not wx.Frame, it should be opened using ShowModal
either at the click of a button or when the application starts, and
everything then becomes easy.

The "Run" button event handler should then call EndModal(wx.OK) - there
can also then be a cancel button that calls EndModal(wx>CAN CEL), I
think, but it's been a while.

The advantage of this is that the dialog still exists after ShowModal()
returns (which is what the call to EndModal() causes to happen). So
usually you can do something like this (untested pseudo-code):

dlg = MyDialog(args_i f_needed)
dlg.ShowModal()
something = dlg.Control.Get Value()
somethingElse = dlg.OtherContro l.GetValue()
... repeat at will ...
dlg.Destroy()

This is the most often-used pattern for returning data from a dialog,
but it wasn't easy to see how to adapt that to Tyler's original code. I
made the mistake of assuming that Tyler knew a bit more about wxPython
that was actually the case, so I am sorry if the advice was off-target.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com

Apr 20 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
10620
by: Andrew | last post by:
Hi I just started learning wxPython I wanted to know how I could do this in wxPython self.listbox.delete(0, END) for item in self.results: self.listbox.insert(END, item)
3
7540
by: Lo?c Mah? | last post by:
Hello I try to use a Validator for a TxtCtrl placed in a Panel with a Button in order to trigger the Validator and test the content of TxtCtrl. I have looked into wxPython documentation and demo and searched in google, but I am still unsuccessful yet. My problem is that I do not manage to call the Validate() method of my Validator from the button handler.
9
1532
by: David Sulc | last post by:
Hi ! I've looked all over (internet, books, etc.) and I haven't found a very good ressource to get started with wxPython (yes, I've been through their tutorial). What I would basically like to do for starters is to be able to define the main panel being displayed. For example : 1. wxFrame contains a wxPanel (call it mainPanel). 2. mainPanel contains another panel (childPanelA)
2
1710
by: rodmc | last post by:
I am totally new to Python and WxPython and need to write an application which can open up an external windows from a plug-in within GAIM (using pyGAIM). I have managed to hack some code together from what little I have covered so far, however GAIM refuses to open until I have closed the extra window. I appreciate this is probably a simple point but I would be grateful for any advice people can offer on how I can make them both appear so...
9
5555
by: zxo102 | last post by:
Hi everyone, I am using a python socket server to collect data from a socket client and then control a image location ( wxpython) with the data, i.e. moving the image around in the wxpython frame. But the "app.MainLoop()" in wxpython looks like conflicting with the "while 1:" in socket server. After I commented the "app.MainLoop()", everything is working except two things: 1. if I click anywhere on the screen with the mouse, the image is...
25
4507
by: Christian Christmann | last post by:
Hi, the ANSI-C 99 standard specifies that the main function has "int" as return type. However, there are still lots of people declaring "void" as main return type. Did previous ANSI-C standards defined "void" as return type or is this issue just a lack of C knowledge? Regards,
44
4995
by: bg_ie | last post by:
Hi, I'm in the process of writing some code and noticed a strange problem while doing so. I'm working with PythonWin 210 built for Python 2.5. I noticed the problem for the last py file processed by this script, where the concerned tmp file is only actually written to when PythonWin is closed. In other words, after I run this script, one of the generated tmp files has a size of 0kB. I then close PythonWin and it is then written to.
1
2294
by: [david] | last post by:
What am I doing wrong? I'm trying to capture stdErr in a multi-threaded program. This code crashes wxPython with /Py Assertion Error: C++ assertion "m_count=-1 || m_count=-2" failed/ What I'm trying to do is redirect stderr and stdout to a wxPython text control. In an ideal world, when the worker thread crashes, I should get a stderr message, with no effect on the main thread.
12
2781
by: icarus | last post by:
platform: windows xp professional, python 2.5, wxpython When I double-check on my program file test.py (for simplicity I'll be using this code below), I see the window just fine. But the ms-dos black window pops up in the background. On Linux, no issues at all. How can I get rid of that ms-dos black window in the background? something I need to add to my code? a setting to adjust in windows? thanks in advance.
0
8740
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9386
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9239
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9090
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8059
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5996
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4764
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3208
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2606
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.