AUI Notebook AddPage issue

Hi,

I have been trying to figure out how to add an ObjectListView widget to a page in Andrea's new AUI Notebook widget. If I try adding it as the first page, I get the following traceback:

Exception: Invalid Page index:
File "C:\Python25\My code\emailer\mailReaderAUI,py.py", line 159, in <module>
  app = EmailReader()
File "C:\Python25\My code\emailer\mailReaderAUI,py.py", line 155, in __init__
  frame = AuiMailFrame()
File "C:\Python25\My code\emailer\mailReaderAUI,py.py", line 21, in __init__
  self.mgr.AddPane(self.CreateNotebook(), aui.AuiPaneInfo().Name("notebook_content").
File "C:\Python25\My code\emailer\mailReaderAUI,py.py", line 135, in CreateNotebook
  ctrl.EnableTab(1, False)
File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\lib\agw\aui\auibook.py", line 3084, in EnableTab
  self._tabs.EnableTab(page_idx, enable)
File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\lib\agw\aui\auibook.py", line 887, in EnableTab
  raise Exception("Invalid Page index")

If I add the ObjectListView widget as the 2nd page, I don't get the traceback, but I also don't get the page. You can see the same effect in the attached file (if you have ObjectListView and Andrea's AUI installed). To get the traceback, just comment out line 114. I would prefer to have the OLV control on the first page...

I am using wxPython 2.8.9.2, Python 2.5.2 on Windows Vista.

If you have any ideas, let me know. I'm sure it's fairly obvious. Thanks!

mailReaderAUI.py (6.18 KB)

···

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

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

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4019 (20090418) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

Hi Mike,

    it looks like you are missing a "return panel" statement at the
end of the CreateMailList method. It works for me if I add that
statement, in whatever page you put ObjectListView.

Andrea.

···

On Sun, Apr 19, 2009 at 11:28 PM, Mike Driscoll wrote:

Hi,

I have been trying to figure out how to add an ObjectListView widget to a
page in Andrea's new AUI Notebook widget. If I try adding it as the first
page, I get the following traceback:

Exception: Invalid Page index:
File "C:\Python25\My code\emailer\mailReaderAUI,py.py", line 159, in
<module>
app = EmailReader()
File "C:\Python25\My code\emailer\mailReaderAUI,py.py", line 155, in
__init__
frame = AuiMailFrame()
File "C:\Python25\My code\emailer\mailReaderAUI,py.py", line 21, in __init__
self.mgr.AddPane(self.CreateNotebook(),
aui.AuiPaneInfo().Name("notebook_content").
File "C:\Python25\My code\emailer\mailReaderAUI,py.py", line 135, in
CreateNotebook
ctrl.EnableTab(1, False)
File
"C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\lib\agw\aui\auibook.py",
line 3084, in EnableTab
self._tabs.EnableTab(page_idx, enable)
File
"C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\lib\agw\aui\auibook.py",
line 887, in EnableTab
raise Exception("Invalid Page index")

If I add the ObjectListView widget as the 2nd page, I don't get the
traceback, but I also don't get the page. You can see the same effect in the
attached file (if you have ObjectListView and Andrea's AUI installed). To
get the traceback, just comment out line 114. I would prefer to have the OLV
control on the first page...

I am using wxPython 2.8.9.2, Python 2.5.2 on Windows Vista.

If you have any ideas, let me know. I'm sure it's fairly obvious. Thanks!

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

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

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4019 (20090418) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

import wx
import wx.html
import wx.lib.agw.aui as aui
from ObjectListView import ObjectListView, ColumnDefn

class AuiMailFrame(wx.Frame):

def __init__(self, parent=None, id=wx.ID_ANY, title="", pos=
wx.DefaultPosition,
size=(800,600),
style=wx.DEFAULT_FRAME_STYLE|wx.SUNKEN_BORDER):
wx.Frame.__init__(self, parent, id, title, pos, size, style)

   self\.mgr = aui\.AuiManager\(\)
   self\.emails = \[\]

   \# tell AuiManager to manage this frame
   self\.mgr\.SetManagedWindow\(self\)

   self\.mgr\.AddPane\(self\.CreateTreeCtrl\(\),

aui.AuiPaneInfo().Name("test8").Caption("Tree Pane").

Left().Layer(1).Position(1).CloseButton(True).MaximizeButton(True).
MinimizeButton(True).MinimizeButton(True))
self.mgr.AddPane(self.CreateNotebook(),
aui.AuiPaneInfo().Name("notebook_content").
CenterPane().PaneBorder(False))

   wnd10 = self\.CreateTextCtrl\(&quot;This pane will prompt the user before

hiding.")
self.mgr.AddPane(wnd10, aui.AuiPaneInfo().
Name("test10").Caption("Text Pane with Hide
Prompt").
Bottom().Layer(0).Position(1).MinimizeButton(True))

def CreateTreeCtrl(self):

   tree = wx\.TreeCtrl\(self, \-1, wx\.Point\(0, 0\), wx\.Size\(160, 250\),
                      wx\.TR\_DEFAULT\_STYLE | wx\.NO\_BORDER\)

   imglist = wx\.ImageList\(16, 16, True, 2\)
   imglist\.Add\(wx\.ArtProvider\.GetBitmap\(wx\.ART\_FOLDER, wx\.ART\_OTHER,

wx.Size(16, 16)))
imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE,
wx.ART_OTHER, wx.Size(16, 16)))
tree.AssignImageList(imglist)

   root = tree\.AddRoot\(&quot;Inbox&quot;, 0\)
   items = \[\]

   items\.append\(tree\.AppendItem\(root, &quot;Item 1&quot;, 0\)\)
   items\.append\(tree\.AppendItem\(root, &quot;Item 2&quot;, 0\)\)
   items\.append\(tree\.AppendItem\(root, &quot;Item 3&quot;, 0\)\)
   items\.append\(tree\.AppendItem\(root, &quot;Item 4&quot;, 0\)\)
   items\.append\(tree\.AppendItem\(root, &quot;Item 5&quot;, 0\)\)

   for item in items:
       tree\.AppendItem\(item, &quot;Subitem 1&quot;, 1\)
       tree\.AppendItem\(item, &quot;Subitem 2&quot;, 1\)
       tree\.AppendItem\(item, &quot;Subitem 3&quot;, 1\)
       tree\.AppendItem\(item, &quot;Subitem 4&quot;, 1\)
       tree\.AppendItem\(item, &quot;Subitem 5&quot;, 1\)

   tree\.Expand\(root\)

   return tree

def CreateHTMLCtrl(self, parent=None):

   if not parent:
       parent = self

   ctrl = wx\.html\.HtmlWindow\(parent, \-1, wx\.DefaultPosition,

wx.Size(400, 300))
text = \
"<html><body>" \
"<h3>Welcome to AUI</h3>" \
"</body></html>"
ctrl.SetPage(text)
return ctrl

def CreateMailList(self, parent):
"""
Create the email listing
"""
panel = wx.Panel(parent, wx.ID_ANY)

   self\.emailPaneOlv = ObjectListView\(panel, wx\.ID\_ANY,

style=wx.LC_REPORT|wx.SUNKEN_BORDER)
self.initEmailPane()
self.emailPaneOlv.stEmptyListMsg.SetLabel("You Have No Messages")

   mainSizer = wx\.BoxSizer\(wx\.VERTICAL\)
   mainSizer\.Add\(self\.emailPaneOlv, 1, wx\.EXPAND|wx\.ALL, 5\)
   panel\.SetSizer\(mainSizer\)

def initEmailPane(self):
"""
Initialize the email pane with data
"""
self.emailPaneOlv.SetColumns([
ColumnDefn("Subject", align="left", width=200),
ColumnDefn("Sender", align="left", width=120),
ColumnDefn("Date", align="left", width=50)
])
self.emailPaneOlv.SetObjects(self.emails)

def CreateNotebook(self):

   \# create the notebook off\-window to avoid flicker
   client\_size = self\.GetClientSize\(\)
   self\.\_notebook\_style = aui\.AUI\_NB\_DEFAULT\_STYLE |

aui.AUI_NB_TAB_EXTERNAL_MOVE | wx.NO_BORDER
self._notebook_theme = 0
ctrl = aui.AuiNotebook(self, -1, wx.Point(client_size.x,
client_size.y),
wx.Size(430, 200), self._notebook_style)

   arts = \[aui\.AuiDefaultTabArt, aui\.AuiSimpleTabArt, aui\.VC71TabArt,

aui.FF2TabArt,
aui.VC8TabArt, aui.ChromeTabArt]

   art = arts\[self\.\_notebook\_theme\]\(\)
   ctrl\.SetArtProvider\(art\)

   page\_bmp = wx\.ArtProvider\.GetBitmap\(wx\.ART\_NORMAL\_FILE, wx\.ART\_OTHER,

wx.Size(16, 16))
ctrl.AddPage(self.CreateHTMLCtrl(ctrl), "Welcome to AUI", False,
page_bmp)
ctrl.AddPage(self.CreateMailList(ctrl), "Main", False, page_bmp)

   panel = wx\.Panel\(ctrl, \-1\)
   flex = wx\.FlexGridSizer\(0, 2\)
   flex\.Add\(\(5, 5\)\)
   flex\.Add\(\(5, 5\)\)
   flex\.Add\(wx\.StaticText\(panel, \-1, &quot;wxTextCtrl:&quot;\), 0,

wx.ALL|wx.ALIGN_CENTRE, 5)
flex.Add(wx.TextCtrl(panel, -1, "", wx.DefaultPosition, wx.Size(100,
-1)),
1, wx.ALL|wx.ALIGN_CENTRE, 5)
flex.Add(wx.StaticText(panel, -1, "wxSpinCtrl:"), 0,
wx.ALL|wx.ALIGN_CENTRE, 5)
flex.Add(wx.SpinCtrl(panel, -1, "5", wx.DefaultPosition, wx.Size(100,
-1),
wx.SP_ARROW_KEYS, 5, 50, 5), 0,
wx.ALL|wx.ALIGN_CENTRE, 5)
flex.Add((5, 5))
flex.Add((5, 5))
flex.AddGrowableRow(0)
flex.AddGrowableRow(3)
flex.AddGrowableCol(1)
panel.SetSizer(flex)
ctrl.AddPage(panel, "wxPanel", False, page_bmp)

   ctrl\.EnableTab\(1, False\)
   ctrl\.SetPageTextColour\(2, wx\.RED\)
   ctrl\.SetPageTextColour\(3, wx\.BLUE\)
   return ctrl

def CreateTextCtrl(self, ctrl_text=""):

   if ctrl\_text\.strip\(\):
       text = ctrl\_text
   else:
       text = &quot;This is text box %d&quot;%self\.\_textCount
       self\.\_textCount \+= 1

   return wx\.TextCtrl\(self,\-1, text, wx\.Point\(0, 0\), wx\.Size\(150, 90\),
                      wx\.NO\_BORDER | wx\.TE\_MULTILINE\)

class EmailReader(wx.App):

def __init__(self, redirect=False, filename=None):
wx.App.__init__(self, redirect, filename)
frame = AuiMailFrame()
frame.Show()

if __name__ == "__main__":
app = EmailReader()
app.MainLoop()

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

--
Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

Andrea Gavana wrote:

Hi Mike,

    it looks like you are missing a "return panel" statement at the
end of the CreateMailList method. It works for me if I add that
statement, in whatever page you put ObjectListView.

Andrea.
  
Ah. I didn't realize I had to return something. I'll probably be bugging you with other questions about your project later this week as I am sure I'll get stuck again. Thanks for your help and for another fun set of widgets!

- Mike

···

On Sun, Apr 19, 2009 at 11:28 PM, Mike Driscoll wrote:
  

Hi,

I have been trying to figure out how to add an ObjectListView widget to a
page in Andrea's new AUI Notebook widget. If I try adding it as the first
page, I get the following traceback:

Exception: Invalid Page index:
File "C:\Python25\My code\emailer\mailReaderAUI,py.py", line 159, in
<module>
app = EmailReader()
File "C:\Python25\My code\emailer\mailReaderAUI,py.py", line 155, in
__init__
frame = AuiMailFrame()
File "C:\Python25\My code\emailer\mailReaderAUI,py.py", line 21, in __init__
self.mgr.AddPane(self.CreateNotebook(),
aui.AuiPaneInfo().Name("notebook_content").
File "C:\Python25\My code\emailer\mailReaderAUI,py.py", line 135, in
CreateNotebook
ctrl.EnableTab(1, False)
File
"C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\lib\agw\aui\auibook.py",
line 3084, in EnableTab
self._tabs.EnableTab(page_idx, enable)
File
"C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\lib\agw\aui\auibook.py",
line 887, in EnableTab
raise Exception("Invalid Page index")

If I add the ObjectListView widget as the 2nd page, I don't get the
traceback, but I also don't get the page. You can see the same effect in the
attached file (if you have ObjectListView and Andrea's AUI installed). To
get the traceback, just comment out line 114. I would prefer to have the OLV
control on the first page...

I am using wxPython 2.8.9.2, Python 2.5.2 on Windows Vista.

If you have any ideas, let me know. I'm sure it's fairly obvious. Thanks!

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

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