1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| #! /usr/bin/env python
#-*- coding: utf-8 -*-
import wx
class FrameTest(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, title="test de TreeCtrl", size=(400, 300))
panel = wx.ScrolledWindow(self, -1)
sizer = wx.BoxSizer(wx.VERTICAL)
self.arbre = wx.TreeCtrl(panel, -1)
sizer.Add(self.arbre, 0, wx.EXPAND)
panel.SetSizer(sizer)
self.liste = []
for x in range(50):
self.liste.append(u"Ceci est l'item n° %s"%(x+1))
self.Remplir()
panel.SetScrollRate(20, 20)
self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.OnRightClick, self.arbre)
self.Bind(wx.EVT_CLOSE, self.OnClose)
def Remplir(self):
root = self.arbre.AddRoot(u"Ceci est la racine")
for x in range(50):
item = self.arbre.AppendItem(root, self.liste[x])
self.arbre.SetPyData(item, [x,])
self.arbre.ExpandAll()
def OnClose(self, event):
self.Destroy()
def OnRightClick(self, event):
item = event.GetItem()
position = self.arbre.GetPyData(item)[0]
message = u"L'item choisi se situe à la position %s dans la liste"%position
dlg = wx.MessageDialog(self, message, u"Résultat", style = wx.OK|wx.ICON_INFORMATION)
rep = dlg.ShowModal()
dlg.Destroy()
class Test(wx.App):
def OnInit(self):
frame = FrameTest()
frame.Show(True)
self.SetTopWindow(frame)
return True
app = Test()
app.MainLoop() |
Partager