Hi CM
Thanks for this comment. Your code didn't look that different
(logically) from what I wrote, which gave me the confidence to
persevere! I think this all down to experience. Anyway after a lot
of fiddling about I got it to work nicely. I think I was doing at
least three things wrong with things like self and .Fit.
Just in case anyone else wants to generate little subpanels on the
fly, below is my attempt.
Thanks so much again for having a look. By the way - if you don't
mind my asking, what editor and IDE and whatnot do you use? I have
used Python for a while for non-GUI things, and obviously IDLE is fine
for that. I am still experimenting with environments for WX.
class PageOne(wx.Panel):
h2=wx.BoxSizer(wx.HORIZONTAL) # this for the subpanels
def __init__(self, parent):
wx.Panel.__init__(self, parent)
p1=wx.Panel(self,-1,size=(1200,950))
lab1=wx.StaticText(p1, -1, "Please enter number of
participants")
self.intxt = wx.TextCtrl(p1, -1, value="2", size=(300,20))
butn=wx.Button(p1, -1, "Retrieve")
p1.Bind(wx.EVT_BUTTON, self.OnClick, butn)
self.bigPanel=wx.Panel(self, -1, size=(1200,800),
style=wx.RAISED_BORDER)
h1=wx.BoxSizer(wx.HORIZONTAL) # this for the top labels
h1.Add(lab1, 0, wx.ALIGN_LEFT|wx.ALL, 4)
h1.Add(self.intxt, 0 , wx.ALIGN_LEFT|wx.ALL, 4)
v1=wx.BoxSizer(wx.VERTICAL)
v1.Add(h1, 0, wx.ALIGN_TOP | wx.ALL, 4)
v1.Add(butn, 0, wx.ALIGN_TOP | wx.ALL, 4)
v1.Add(self.bigPanel)
p1.SetSizer(v1)
p1.Fit()
def Addapanel (self, page, numpanels):
subPanel=wx.Panel(self.bigPanel,-1,size=(300,790),
style=wx.RAISED_BORDER)
subPanel.SetMinSize((300,790))
panTxt=wx.StaticText(subPanel, -1,'Participant {0} of
{1}'.format(page+1,numpanels))
self.h2.Add(subPanel, 1, wx.ALIGN_LEFT|wx.ALL, 4)
return
def OnClick (self,event):
numpanels=self.intxt.GetValue()
if numpanels == '2': numpanels=2 #silly code to just choose
1,2 or 3
elif numpanels == '3' : numpanels =3
else: numpanels = 1
for page in range(numpanels):
self.Addapanel(page, numpanels)
self.bigPanel.SetSizer(self.h2)
self.bigPanel.Fit()
Kind regards
Phil
···
On Nov 20, 6:52 pm, C M <cmpyt...@gmail.com> wrote:
On Fri, Nov 20, 2009 at 6:56 PM, Philip Ellis <philipjel...@gmail.com> wrote:
> Hi
> I am stuck on this and have spent a day looking round for a model to
> copy. Feeling a bit thick as this seems like it would be easy.
> When my users click the Go button, my app will go off and retrieve
> various things from a database - depending on what the users entered.
> Each of these things can be formatted and displayed in an HTML window
> say 300 wide and 800 deep. But I don't know in advance how many of
> these things there will be - I only know once the users click Go and I
> can have a look at what they asked for.
> What I would like to do is have one very big panel filling the screen,
> with the data entry box and a Go button at the top left. Then
> depending upon how many things I get from the database put a variable
> number of (HTML) windows horizontally across this panel each
> containing one of the things. So if they only ask for one thing they
> see one HTML panel on the LHS, if they ask for 4 then they get 4 HTML
> panels going left to right.
> But I get tied up in all kinds of knots about how to get these HTML
> windows into the very big panel that has already been created. This
> must be pipsqueak to do. Has anyone seen a handy model or template I
> can look at to see how it all gets arranged?
> Kind regards
> Phil
Often it is helpful to show what you have been trying (what got you "tied
up in knots") by making a small runnable sample of it, and posting that
code and showing what *should* happen but *isn't* happening. This is
useful because a) often you actually discover the solution yourself en
route to posting the sample (happens to me all the time), and b) people
can critique your code and point out why your approach is not quite right,
or even other things you could do more effectively.
That said, maybe try something like:
#self is a wxFrame
bigpanel = wx.Panel(self,-1)
On ButtonPush(self,event)
AddSubpanels()
def AddSubpanels(self,):
number = mytextCtrl.GetValue() #gets num of subpanels you need.
for i in range(number):
smallerpanel = wx.Panel(bigpanel,-1)
Maybe that can move it along? If not, post some small runnable sample code.
HTH,
Che