import wx
class TestFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title, pos=(0, 0), size=(320, 240))
self.CentreOnScreen(wx.BOTH)
testListCtrl = self.MakeTestListCtrl()
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(testListCtrl, 1, wx.EXPAND|wx.ALL, 5)
self.SetSizer(sizer)
self.testListCtrl = testListCtrl
def MakeTestListCtrl(self):
imgList = wx.ImageList(1, 20)
testListCtrl = wx.ListCtrl(self, -1, style = wx.LC_REPORT| wx.LC_SINGLE_SEL )
testListCtrl.SetImageList(imgList, wx.IMAGE_LIST_SMALL)
testListCtrl.InsertColumn(0, "label")
testListCtrl.InsertColumn(1, "info")
testListCtrl.SetColumnWidth(0, 50)
testListCtrl.SetColumnWidth(1, 50)
testListCtrl.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnTestListCtrlItemSelected)
testListCtrl.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnTestListCtrlItemDeselected)
index = testListCtrl.InsertStringItem(0, "item0")
testListCtrl.SetStringItem(index, 1, "value0")
testListCtrl.SetItemImage(index, 0)
index = testListCtrl.InsertStringItem(0, "item1")
testListCtrl.SetStringItem(index, 1, "value1")
self.listCombo = wx.ComboBox(testListCtrl, -1, "test", choices = ["test", "test2", "test3"], style=wx.CB_DROPDOWN)
self.listCombo.Hide()
return testListCtrl
def OnTestListCtrlItemSelected(self, evt):
print "item(%d): selected" % evt.GetIndex()
print "label", self.testListCtrl.GetItemRect(evt.GetIndex(), wx.LIST_RECT_LABEL)
print "bound", self.testListCtrl.GetItemRect(evt.GetIndex())
x, y, w, h = self.testListCtrl.GetItemRect(evt.GetIndex())
col0_w = self.testListCtrl.GetColumnWidth(0)
col1_w = self.testListCtrl.GetColumnWidth(1)
self.listCombo.Move((x + col0_w, y))
self.listCombo.SetSize((col1_w, h))
self.listCombo.Show()
def OnTestListCtrlItemDeselected(self, evt):
print "deselected"
self.listCombo.Hide()
class TestApp(wx.App):
def OnInit(self):
"OnInit"
frame = TestFrame(None, "TestApp")
frame.Show()
self.SetTopWindow(frame)
return True
def OnExit(self):
"OnExit"
pass
TestApp(redirect=False).MainLoop()


python 을 좋아하는 게임 프로그래머