Trying to port ScrolledPanel Demo app - to stand alone program

I want to port the Scrolled Panel Demo app (Under Mode
Windows/Controls) to a stand alone program (one that doesn't depend
on the run module)

In the function runTest() what does the nb argument signify?

The frame argument in runtest isn't used, and I would expect the nb
arg in runtest to be a Frame that is passed to TestPanel (as the
parent arg in
TestPanel.__init__()

import wx
import wx.lib.scrolledpanel as scrolled

···

#----------------------------------------------------------------------

text = "one two buckle my shoe three four shut the door five six pick
up sticks seven eight lay them straight nine ten big fat hen"

class TestPanel(scrolled.ScrolledPanel):
    def __init__(self, parent, log):
        self.log = log
        scrolled.ScrolledPanel.__init__(self, parent, -1)

        vbox = wx.BoxSizer(wx.VERTICAL)
        desc = wx.StaticText(self, -1,
                            "ScrolledPanel extends wx.ScrolledWindow,
adding all "
                            "the necessary bits to set up scroll
handling for you.\n\n"
                            "Here are three fixed size examples of its
use. The "
                            "demo panel for this sample is also using
it -- the \nwxStaticLine "
                            "below is intentionally made too long so a
scrollbar will be "
                            "activated."
                            )
        desc.SetForegroundColour("Blue")
        vbox.Add(desc, 0, wx.ALIGN_LEFT|wx.ALL, 5)
        vbox.Add(wx.StaticLine(self, -1, size=(1024,-1)), 0, wx.ALL, 5)
        vbox.Add((20,20))

        words = text.split()

        panel1 = scrolled.ScrolledPanel(self, -1, size=(140, 300),
                                 style =
wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER, name="panel1" )
        fgs1 = wx.FlexGridSizer(cols=2, vgap=4, hgap=4)

        for word in words:
            label = wx.StaticText(panel1, -1, word+":")

            # A test for scrolling with a too big control
            #if word == "three":
            # tc = wx.TextCtrl(panel1, -1, word, size=(150,-1))
            #else:
            # tc = wx.TextCtrl(panel1, -1, word, size=(50,-1))

            tc = wx.TextCtrl(panel1, -1, word, size=(50,-1))

            fgs1.Add(label, flag=wx.ALIGN_RIGHT |
wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=10)
            fgs1.Add(tc, flag=wx.RIGHT, border=10)

        panel1.SetSizer( fgs1 )
        panel1.SetAutoLayout(1)
        panel1.SetupScrolling()

        panel2 = scrolled.ScrolledPanel(self, -1, size=(350, 50),
                                 style =
wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER, name="panel2")
        panel3 = scrolled.ScrolledPanel(self, -1, size=(200,100),
                                 style =
wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER, name="panel3")

        fgs2 = wx.FlexGridSizer(cols=25, vgap=4, hgap=4)
        fgs3 = wx.FlexGridSizer(cols=5, vgap=4, hgap=4)

        for i in range(len(words)):
            word = words[i]
            if i % 5 != 4:
                label2 = wx.StaticText(panel2, -1, word)
                fgs2.Add(label2, flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
                label3 = wx.StaticText(panel3, -1, word)
                fgs3.Add(label3, flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
            else:
                tc2 = wx.TextCtrl(panel2, -1, word, size=(50,-1))
                fgs2.Add(tc2, flag=wx.LEFT, border=5)
                tc3 = wx.TextCtrl(panel3, -1, word )
                fgs3.Add(tc3, flag=wx.LEFT, border=5)

        panel2.SetSizer( fgs2 )
        panel2.SetAutoLayout(1)
        panel2.SetupScrolling(scroll_y = False)

        panel3.SetSizer( fgs3 )
        panel3.SetAutoLayout(1)
        panel3.SetupScrolling()

        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add((20,20))
        hbox.Add(panel1, 0, wx.FIXED_MINSIZE)
        hbox.Add((40, 10))

        vbox2 = wx.BoxSizer(wx.VERTICAL)
        vbox2.Add(panel2, 0, wx.FIXED_MINSIZE)
        vbox2.Add((20, 50))

        vbox2.Add(panel3, 0, wx.FIXED_MINSIZE)
        vbox2.Add((20, 10))
        hbox.Add(vbox2)

        vbox.Add(hbox, 0)
        self.SetSizer(vbox)
        self.SetAutoLayout(1)
        self.SetupScrolling()

#----------------------------------------------------------------------

def runTest(frame, nb, log):
    win = TestPanel(nb, log)
    return win

#----------------------------------------------------------------------

overview = """<html><body>
ScrolledPanel fills a "hole" in the implementation of wx.ScrolledWindow,
providing automatic scrollbar and scrolling behavior and the tab traversal
mangement that wx.ScrolledWindow lacks.
</body></html>
"""

if __name__ == '__main__':
    import sys,os
    import run
    run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])

Tony Cappellini wrote:

I want to port the Scrolled Panel Demo app (Under Mode
Windows/Controls) to a stand alone program (one that doesn't depend
on the run module)

In the function runTest() what does the nb argument signify?

The frame argument in runtest isn't used, and I would expect the nb
arg in runtest to be a Frame that is passed to TestPanel (as the
parent arg in
TestPanel.__init__()

It's really quite easy. I wrote a wiki article on it even: Using wxPython Demo Code - wxPyWiki

But in case that's not clear enough, what you need to do is the following:

1) Copy and paste the code from the demo into your favorite editor
2) Remove the references to the "log" parameter and "self.log".
3) Now paste this last bit at the bottom:

<code>

class MyApp(wx.App):
    def __init__(self, redirect=False, filename=None):
        wx.App.__init__(self, redirect, filename)
        self.frame = wx.Frame(None, wx.ID_ANY, title='My Title')

        self.panel = TestPanel(self.frame)

        self.frame.Show()

if __name__ == '__main__':
    app = MyApp()
    app.MainLoop()

</code>

This won't be quite the same size, but I'll leave that as an exercise for the reader.

···

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

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

Thanks Mike.

···

It's really quite easy. I wrote a wiki article on it even:
Using wxPython Demo Code - wxPyWiki

But in case that's not clear enough, what you need to do is the following:

1) Copy and paste the code from the demo into your favorite editor
2) Remove the references to the "log" parameter and "self.log".
3) Now paste this last bit at the bottom:

Do you get an exception when you run that code?

That mostly works, but I get this exception
I get this same exception with my version (once I fixed some of the
problems I had posted)

IndexError: Tuple Out Of Range
File "c:\Code\\scroll_demo_fixed.py", line 115, in ?
  app = MyApp()
File "c:\Code\scroll_demo_fixed.py", line 110, in __init__
  self.panel = TestPanel(self.frame)
File "C:\scroll_demo_fixed.py", line 53, in __init__
  panel1.SetupScrolling()
File "C:\scrolledpanel.py", line 62, in SetupScrolling w, h =
sizer.GetMinSize()
File "c:\Python23\Lib\site-packages\wx-2.8-msw-ansi\wx\_core.py", line
923, in __getitem__
  def __getitem__(self, index): return self.Get()[index]

···

On Tue, Aug 12, 2008 at 6:49 AM, Mike Driscoll <mike@pythonlibrary.org> wrote:

Tony Cappellini wrote:

I want to port the Scrolled Panel Demo app (Under Mode
Windows/Controls) to a stand alone program (one that doesn't depend
on the run module)

In the function runTest() what does the nb argument signify?

The frame argument in runtest isn't used, and I would expect the nb
arg in runtest to be a Frame that is passed to TestPanel (as the
parent arg in
TestPanel.__init__()

It's really quite easy. I wrote a wiki article on it even:
Using wxPython Demo Code - wxPyWiki

But in case that's not clear enough, what you need to do is the following:

1) Copy and paste the code from the demo into your favorite editor
2) Remove the references to the "log" parameter and "self.log".
3) Now paste this last bit at the bottom:

<code>

class MyApp(wx.App):
  def __init__(self, redirect=False, filename=None):
      wx.App.__init__(self, redirect, filename)
      self.frame = wx.Frame(None, wx.ID_ANY, title='My Title')

      self.panel = TestPanel(self.frame)

      self.frame.Show()

if __name__ == '__main__':
  app = MyApp()
  app.MainLoop()

</code>

This won't be quite the same size, but I'll leave that as an exercise for
the reader.

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

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

Tony Cappellini wrote:

I want to port the Scrolled Panel Demo app (Under Mode
Windows/Controls) to a stand alone program (one that doesn't depend
on the run module)

In the function runTest() what does the nb argument signify?

It's the main notebook in the demo application.

You can replace everything from the definition of runTest to the end of the file with this:

if __name__ == '__main__':
  app = wx.App(redirect=False)
  frm = wx.Frame(None, title="ScrolledPanel Test")
  pnl = TestPanel(frm, sys.stdout)
  frm.Show()
  app.MainLoop()

···

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

Tony Cappellini wrote:

Do you get an exception when you run that code?

That mostly works, but I get this exception
I get this same exception with my version (once I fixed some of the
problems I had posted)

IndexError: Tuple Out Of Range
File "c:\Code\\scroll_demo_fixed.py", line 115, in ?
  app = MyApp()
File "c:\Code\scroll_demo_fixed.py", line 110, in __init__
  self.panel = TestPanel(self.frame)
File "C:\scroll_demo_fixed.py", line 53, in __init__
  panel1.SetupScrolling()
File "C:\scrolledpanel.py", line 62, in SetupScrolling w, h =
sizer.GetMinSize()
File "c:\Python23\Lib\site-packages\wx-2.8-msw-ansi\wx\_core.py", line
923, in __getitem__
  def __getitem__(self, index): return self.Get()[index]

Are you running that in WingIDE? If so then just tell it to not stop for exceptions at that location.

···

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

Are you running that in WingIDE? If so then just tell it to not stop for
exceptions at that location.

hehe, Robin you know me too well.

Yes, I was I was trying to debug my original code (which was completly wrong)

But it works outside of Wing. Thanks for the heads-up

Tony Cappellini wrote:

Do you get an exception when you run that code?

That mostly works, but I get this exception
I get this same exception with my version (once I fixed some of the
problems I had posted)

IndexError: Tuple Out Of Range
File "c:\Code\\scroll_demo_fixed.py", line 115, in ?
  app = MyApp()
File "c:\Code\scroll_demo_fixed.py", line 110, in __init__
  self.panel = TestPanel(self.frame)
File "C:\scroll_demo_fixed.py", line 53, in __init__
  panel1.SetupScrolling()
File "C:\scrolledpanel.py", line 62, in SetupScrolling w, h =
sizer.GetMinSize()
File "c:\Python23\Lib\site-packages\wx-2.8-msw-ansi\wx\_core.py", line
923, in __getitem__
  def __getitem__(self, index): return self.Get()[index]
  
Try what Robin said or run it from the command line. Since you're using Windows, just go to Start --> Run and type cmd

Then you can use the "cd" command to get to the folder your app is in. If Python is in your system's path, then you should be able to just run it by typing:

python myapp.py

I can usually get it to run from within IDLE, but occasionally I go the command line route.

Mike

Try what Robin said or run it from the command line. Since you're using
Windows, just go to Start --> Run and type cmd

It works now, when I don't run it inside of Wing.

Tony Cappellini wrote:

Try what Robin said or run it from the command line. Since you're using
Windows, just go to Start --> Run and type cmd
    
It works now, when I don't run it inside of Wing.

I got Wing at the end of June, but quickly discovered that running wx programs in it is a pain. It's great for coding though.

Mike

Tony Cappellini wrote:

Try what Robin said or run it from the command line. Since you're using
Windows, just go to Start --> Run and type cmd
    
It works now, when I don't run it inside of Wing.

I got Wing at the end of June, but quickly discovered that running wx programs in it is a pain. It's great for coding though.

Mike

It hasn't been a pain for wx programs for me- I use it almost daily,
although I usually only kick off 1 thread other than the main thread.

Some callbacks & timers can be a pin, but I've been able to debug my stuff ok.

The developers are very responsive to requests & updates.

···

I got Wing at the end of June, but quickly discovered that running wx
programs in it is a pain. It's great for coding though.

Mike