Currently I'm trying to bind the button using the following inside of
the AppendItem function:
#Place the button in the hypertreelist
self.SetItemWindow(new_item,StatusButton(self.GetMainWindow(),"icons/
green_status16.png", "icons/yellow_status16.png","icons/
red_status16.png"),0)
#Bind the button to an event and function
self.Bind(wx.EVT_BUTTON,self.OnStatusButton,id=self.GetMainWindow
().GetItemWindow(new_item).GetId())
When AppendItem runs, I receive the following Message:
Traceback (most recent call last):
File "blade_gui.py", line 119, in newTestSuite
self.suite_list.AppendItem(self.suite_list.root,'Enter Test Suite
Name')
File "M:\blade_release\BLADE\gui\suite_list.py", line 32, in
AppendItem
self.Bind(wx.EVT_BUTTON,self.OnStatusButton,id=self.GetItemWindow
(new_item).GetId())
AttributeError: 'NoneType' object has no attribute 'GetId'
If GetItemWindow returns a NoneType, how to I access the individual
items?
My code below:
import sys
import wx
from wx.lib.agw.hypertreelist import HyperTreeList
sys.path.append("../process")
from suite import Suite
from step import Step
from seq import Sequence
from statusbutton import StatusButton
class SuiteList(HyperTreeList):
def __init__(self, inparent=None):
HyperTreeList.__init__
(self,parent=inparent,style=wx.TR_HIDE_ROOT | wx.TR_EDIT_LABELS |
wx.TR_MULTIPLE | wx.TR_FULL_ROW_HIGHLIGHT | wx.TR_HAS_BUTTONS|
wx.TR_TWIST_BUTTONS | wx.TR_NO_LINES)
self.AddColumn('Status',width=42)
self.AddColumn('Test Suites',width=2000)
self.SetMainColumn(1)
self.root = self.AddRoot('Test Suites')
self.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
def AfterEditItem(self,event):
print "Test"
item = self.GetMainWindow().GetSelection()
def AppendItem(self,item,name):
new_item = None
new_data = None
if item == self.GetMainWindow().GetRootItem():
new_data = Suite(name)
new_item = self.GetMainWindow().AppendItem(item,name)
self.GetMainWindow().SetPyData(new_item,new_data)
self.SetItemWindow(new_item,StatusButton(self.GetMainWindow
(),"icons/green_status16.png", "icons/yellow_status16.png","icons/
red_status16.png"),0)
self.Bind
(wx.EVT_BUTTON,self.OnStatusButton,id=self.GetItemWindow
(new_item).GetId())
elif type(self.GetSelectionData()).__name__ == 'Suite':
new_data = Step(name)
new_item = self.GetMainWindow().AppendItem(item,name)
self.GetMainWindow().SetPyData(new_item,new_data)
self.SetItemWindow(new_item,StatusButton(self.GetMainWindow
(),"icons/green_status16.png", "icons/yellow_status16.png","icons/
red_status16.png"),0)
self.Bind
(wx.EVT_BUTTON,self.OnStatusButton,id=self.GetItemWindow
(new_item).GetId())
elif type(self.GetSelectionData()).__name__ == 'Step':
new_data = Sequence(name)
new_item = self.GetMainWindow().AppendItem(item,name)
self.GetMainWindow().SetPyData(new_item,new_data)
self.SetItemWindow(new_item,StatusButton(self.GetMainWindow
(),"icons/green_status16.png", "icons/yellow_status16.png","icons/
red_status16.png"),0)
self.Bind
(wx.EVT_BUTTON,self.OnStatusButton,id=self.GetMainWindow
().GetItemWindow(new_item).GetId())
if type(new_data).__name__ != 'Suite':
self.GetMainWindow().Expand(item)
self.GetMainWindow().EditLabel(new_item)
def EditItem(self,item):
self.GetMainWindow().EditLabel(item)
def OnAdd(self,event):
if self.GetSelection():
if type(self.GetItemData(self.GetSelection())).__name__ ==
'Step':
self.AppendItem(self.GetSelection(),'Enter Sequence
Name')
elif type(self.GetItemData(self.GetSelection())).__name__
== 'Suite':
self.AppendItem(self.GetSelection(),'Enter Step Name')
elif type(self.GetItemData(self.GetSelection())).__name__
== 'Sequence':
edit = wx.MenuItem(menu,self,popup_edit_ID,"Edit
Sequence Name")
menu.AppendItem(edit)
else:
self.AppendItem(self.GetMainWindow().GetRootItem(),'Enter
Suite Name')
def OnEdit(self,event):
self.EditItem(self.GetSelection())
def OnRightClick(self,event):
if not hasattr(self, "popup_add_ID"):
self.popup_add_ID = wx.NewId()
self.popup_edit_ID = wx.NewId()
self.Bind(wx.EVT_MENU, self.OnAdd, id=self.popup_add_ID)
self.Bind(wx.EVT_MENU, self.OnEdit, id=self.popup_edit_ID)
# make a menu
menu = wx.Menu()
# Show how to put an icon in the menu
if self.GetSelection():
if type(self.GetItemData(self.GetSelection())).__name__ ==
'Step':
add = wx.MenuItem(menu, self.popup_add_ID,"Add
Sequence To Step")
edit = wx.MenuItem(menu, self.popup_edit_ID,"Edit Step
Name")
menu.AppendItem(add)
menu.AppendItem(edit)
elif type(self.GetItemData(self.GetSelection())).__name__
== 'Suite':
add = wx.MenuItem(menu, self.popup_add_ID,"Add Step to
Suite")
edit = wx.MenuItem(menu, self.popup_edit_ID,"Edit
Suite Name")
menu.AppendItem(add)
menu.AppendItem(edit)
elif type(self.GetItemData(self.GetSelection())).__name__
== 'Sequence':
edit = wx.MenuItem(menu,self.popup_edit_ID,"Edit
Sequence Name")
menu.AppendItem(edit)
else:
add = wx.MenuItem(menu, self.popup_add_ID,"Create Test
Suite")
menu.AppendItem(add)
self.PopupMenu(menu)
#menu.Destroy()
def OnStatusButton(self,event):
print "StatusButton"
def GetItemData(self,item):
'''Returns the data assocated with the passed item'''
return self.GetMainWindow().GetPyData(item)
def GetRootItem(self):
'''Returns the root item of the SuiteList'''
return self.GetMainWindow().GetRootItem()
def GetSelection(self):
'''Returns the currently selected item in the list'''
return self.GetMainWindow().GetSelection()
def GetSelections(self):
'''Returns the currently selected items in the list as an
array'''
return self.GetMainWindow().GetSelections()
def GetSelectionData(self):
'''Returns the data associated with the selected item'''
return self.GetMainWindow().GetPyData(self.GetSelection())