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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
| # !/usr/bin/python
# -*- coding:iso-8859-15 -*-
#---------------------------------------------------------------------------
import wx
#---------------------------------------------------------------------------
[
wxID_XSD_ADD_ELEMENT
] = [wx.NewId() for i in range(1)]
#---------------------------------------------------------------------------
# Menu contextuel pour les noeuds de l'arbre
class XsdContextMenu(wx.Menu):
def __init__(self, parent):
wx.Menu.__init__(self)
self._parent = parent
addElement = wx.MenuItem(self, wxID_XSD_ADD_ELEMENT, 'Element')
self.Bind(wx.EVT_MENU, self.OnAddElement, id = wxID_XSD_ADD_ELEMENT)
self.AppendItem(addElement)
def OnAddElement(self, event):
print 'XsdContextMenu::OnAddElement'
self._parent.addElement()
#---------------------------------------------------------------------------
class Branch(wx.Panel):
n = 0 # un static pour incrémenter le nom du noeud
def __init__(self, parent):
Branch.n = Branch.n + 1
wx.Panel.__init__(self, parent, wx.NewId(), name = 'Branch' + str(Branch.n), style = wx.BORDER_NONE)
self.SetBackgroundColour('#ffeecc') # "saumon"
# conteneur du controle associé au noeud
self._pnlControl = wx.Panel(self, wx.NewId(), name = 'Branch' + str(Branch.n) + '_PanelControl')
self._pnlControl.SetBackgroundColour('#ffff00') # jaune
# conteneur des enfants du noeud
self._pnlChildren = wx.Panel(self, wx.NewId(), name = 'Branch' + str(Branch.n) + '_PanelChildren')
self._pnlChildren.SetBackgroundColour('#eeeeff') # bleu très clair
# controle associé au noeud
self._control = self._createControl()
self._bs = wx.BoxSizer(wx.VERTICAL)
self._bsControl = wx.BoxSizer(wx.VERTICAL)
self._bsChildren = wx.BoxSizer(wx.HORIZONTAL)
self._bsControl.Add(self._control, 0, wx.ALIGN_CENTRE)
self._pnlControl.SetSizer(self._bsControl)
self._pnlChildren.SetSizer(self._bsChildren)
self._bs.Add(self._pnlControl, 0, wx.EXPAND | wx.ALL, 0)
self._bs.Add(self._pnlChildren, 1, wx.EXPAND | wx.ALL, 0)
self.SetSizer(self._bs)
def _createControl(self):
# A surcharger pour chaque type de noeud concret
raise NotImplementedError
def addElement(self, label = 'Element'):
e = Element(self._pnlChildren, label)
self._bsChildren.Add(e, 0, wx.ALL, 4)
# que faire ici pour rafraichir l'affichage ?
self._bsChildren.Layout()
self._bsChildren.Fit(self._pnlChildren)
self._bs.Layout()
self.Update()
return e
def _rightClick(self, event):
self.PopupMenu(XsdContextMenu(self), (event.GetPosition().x - self.GetScreenPosition().x, event.GetPosition().y - self.GetScreenPosition().y))
event.StopPropagation()
#---------------------------------------------------------------------------
class Element(Branch):
i = 0
def __init__(self, parent, label = 'Element'):
Element.i = Element.i + 1
self._label = label + str(Element.i)
print 'création de ' + self._label + ' dans ' + parent.GetName()
Branch.__init__(self, parent)
def _createControl(self):
win = wx.Panel(self._pnlControl, wx.NewId(), style = wx.BORDER_SIMPLE)
win.Bind(wx.EVT_CONTEXT_MENU, self._rightClick, id = win.GetId())
win.SetBackgroundColour('#ffffff')
bsP = wx.BoxSizer(wx.VERTICAL)
lbl = wx.StaticText(win, wx.NewId(), label = self._label)
bsP.Add(lbl, 0, wx.ALIGN_CENTRE | wx.ALL, 4)
win.SetSizer(bsP)
return win
#--------------------------------------------------------------------------- |
Partager