Creating windows during an event

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

···

On Fri, Nov 20, 2009 at 6:56 PM, Philip Ellis <philipjellis@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

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

You are correct: wxPython just takes practice. I find that the best
way to learn is to mess with small stuff, look at the wxPython wiki
and the wxPython demo for examples. There's also a good tutorial on
zetcode (although it's getting on in years). And this list has been
very helpful!

I've written some articles on my blog too (and I sometimes transfer
them to the wxPython wiki).

···

On Nov 23, 12:08 pm, Philip Ellis <philipjel...@gmail.com> wrote:

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.

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

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.

Great. That's been my experience...fiddling ultimately will pay off
with both the result you want and (usually) increased understanding of
Python or wxPython.

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.

Last time I checked, IDLE and wxPython sometimes do not get along well.
See Mike's reply to this post about it:
http://groups.google.com/group/wxpython-users/browse_thread/thread/3288d4c8cdbe57ba?pli=1

I myself use Boa Constructor, and like it quite a bit. It has some issues
if you are primarily coding on Linux, though. I write on a Windows computer
and then "adjust" it for Linux on a Linux computer also using Boa, but I might
not want to do the primary creating with Boa on Linux (although it's not *that*
bad). I've never used it on Mac, so no idea there. Boa has both an IDE and a
GUI builder, debugger, plug-ins, and lots of stuff, really.

Two comments on your code snippet:

def OnClick (self,event):

I recommend getting into the habit of making every single last function
name meaningful and specified. Here "OnClick" doesn't tell you what
is clicked. OnMakePanelButtonClick would tell you more. I for one
prefer long names that tell just what they do rather than "elegant"
names that one has to guess at what they do (but then again I liked
the naming conventions for organic chemistry, too).

   if numpanels == &#39;2&#39;: numpanels=2 \#silly code to just choose

1,2 or 3
elif numpanels == '3' : numpanels =3
else: numpanels = 1

This could be shortened to:

numpanels = int(numpanels)

But the user could put a non-numeric into the textctrl, and then
you can't make an integer out of it. That's when using validators
could be handy, or you could use the integer control,
wx.lib.intctrl.IntCtrl, which I think only allows integers to be
entered, and then you only need to get that value.

HTH,
Che

···

On Mon, Nov 23, 2009 at 1:08 PM, Philip Ellis <philipjellis@gmail.com> wrote: