added Expand/Collapse handlers
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@20602 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -6,6 +6,9 @@
|
|||||||
|
|
||||||
from xxx import * # xxx imports globals and params
|
from xxx import * # xxx imports globals and params
|
||||||
|
|
||||||
|
# Constant to define standart window name
|
||||||
|
STD_NAME = '_XRCED_T_W'
|
||||||
|
|
||||||
# Icons
|
# Icons
|
||||||
import images
|
import images
|
||||||
|
|
||||||
@@ -319,11 +322,10 @@ class HighLightBox:
|
|||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
class XML_Tree(wxTreeCtrl):
|
class XML_Tree(wxTreeCtrl):
|
||||||
# Constant to define standart window name
|
|
||||||
stdName = '_XRCED_T_W'
|
|
||||||
def __init__(self, parent, id):
|
def __init__(self, parent, id):
|
||||||
wxTreeCtrl.__init__(self, parent, id, style = wxTR_HAS_BUTTONS)
|
wxTreeCtrl.__init__(self, parent, id, style = wxTR_HAS_BUTTONS)
|
||||||
self.SetBackgroundColour(wxColour(224, 248, 224))
|
self.SetBackgroundColour(wxColour(224, 248, 224))
|
||||||
|
# Register events
|
||||||
EVT_TREE_SEL_CHANGED(self, self.GetId(), self.OnSelChanged)
|
EVT_TREE_SEL_CHANGED(self, self.GetId(), self.OnSelChanged)
|
||||||
# One works on Linux, another on Windows
|
# One works on Linux, another on Windows
|
||||||
if wxPlatform == '__WXGTK__':
|
if wxPlatform == '__WXGTK__':
|
||||||
@@ -331,7 +333,10 @@ class XML_Tree(wxTreeCtrl):
|
|||||||
else:
|
else:
|
||||||
EVT_LEFT_DCLICK(self, self.OnDClick)
|
EVT_LEFT_DCLICK(self, self.OnDClick)
|
||||||
EVT_RIGHT_DOWN(self, self.OnRightDown)
|
EVT_RIGHT_DOWN(self, self.OnRightDown)
|
||||||
|
EVT_TREE_ITEM_EXPANDED(self, self.GetId(), self.OnItemExpandedCollapsed)
|
||||||
|
EVT_TREE_ITEM_COLLAPSED(self, self.GetId(), self.OnItemExpandedCollapsed)
|
||||||
|
|
||||||
|
self.selection = None
|
||||||
self.needUpdate = False
|
self.needUpdate = False
|
||||||
self.pendingHighLight = None
|
self.pendingHighLight = None
|
||||||
self.ctrl = self.shift = False
|
self.ctrl = self.shift = False
|
||||||
@@ -512,6 +517,7 @@ class XML_Tree(wxTreeCtrl):
|
|||||||
pos = obj.GetPosition()
|
pos = obj.GetPosition()
|
||||||
if pos == (-1,-1): pos = (0,0)
|
if pos == (-1,-1): pos = (0,0)
|
||||||
return parentPos + pos
|
return parentPos + pos
|
||||||
|
|
||||||
# Find window (or sizer) corresponding to a tree item.
|
# Find window (or sizer) corresponding to a tree item.
|
||||||
def FindNodeObject(self, item):
|
def FindNodeObject(self, item):
|
||||||
testWin = g.testWin
|
testWin = g.testWin
|
||||||
@@ -534,6 +540,7 @@ class XML_Tree(wxTreeCtrl):
|
|||||||
if isinstance(child, wxNotebookSizerPtr):
|
if isinstance(child, wxNotebookSizerPtr):
|
||||||
child = child.GetNotebook()
|
child = child.GetNotebook()
|
||||||
return child
|
return child
|
||||||
|
|
||||||
def OnSelChanged(self, evt):
|
def OnSelChanged(self, evt):
|
||||||
# Apply changes
|
# Apply changes
|
||||||
# !!! problem with wxGTK - GetOldItem is Ok if nothing selected
|
# !!! problem with wxGTK - GetOldItem is Ok if nothing selected
|
||||||
@@ -564,6 +571,7 @@ class XML_Tree(wxTreeCtrl):
|
|||||||
g.tools.UpdateUI()
|
g.tools.UpdateUI()
|
||||||
# Hightlighting is done in OnIdle
|
# Hightlighting is done in OnIdle
|
||||||
self.pendingHighLight = self.selection
|
self.pendingHighLight = self.selection
|
||||||
|
|
||||||
# Check if item is in testWin subtree
|
# Check if item is in testWin subtree
|
||||||
def IsHighlatable(self, item):
|
def IsHighlatable(self, item):
|
||||||
if item == g.testWin.item: return False
|
if item == g.testWin.item: return False
|
||||||
@@ -571,6 +579,7 @@ class XML_Tree(wxTreeCtrl):
|
|||||||
item = self.GetItemParent(item)
|
item = self.GetItemParent(item)
|
||||||
if item == g.testWin.item: return True
|
if item == g.testWin.item: return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Highlight selected item
|
# Highlight selected item
|
||||||
def HighLight(self, item):
|
def HighLight(self, item):
|
||||||
self.pendingHighLight = None
|
self.pendingHighLight = None
|
||||||
@@ -592,6 +601,7 @@ class XML_Tree(wxTreeCtrl):
|
|||||||
else:
|
else:
|
||||||
g.testWin.highLight = HighLightBox(pos, size)
|
g.testWin.highLight = HighLightBox(pos, size)
|
||||||
g.testWin.highLight.item = item
|
g.testWin.highLight.item = item
|
||||||
|
|
||||||
def ShowTestWindow(self, item):
|
def ShowTestWindow(self, item):
|
||||||
xxx = self.GetPyData(item)
|
xxx = self.GetPyData(item)
|
||||||
if g.panel.IsModified():
|
if g.panel.IsModified():
|
||||||
@@ -607,10 +617,12 @@ class XML_Tree(wxTreeCtrl):
|
|||||||
self.CreateTestWin(item)
|
self.CreateTestWin(item)
|
||||||
# Maybe an error occured, so we need to test
|
# Maybe an error occured, so we need to test
|
||||||
if g.testWin: self.SetItemBold(g.testWin.item)
|
if g.testWin: self.SetItemBold(g.testWin.item)
|
||||||
|
|
||||||
# Double-click on Linux
|
# Double-click on Linux
|
||||||
def OnItemActivated(self, evt):
|
def OnItemActivated(self, evt):
|
||||||
if evt.GetItem() != self.root:
|
if evt.GetItem() != self.root:
|
||||||
self.ShowTestWindow(evt.GetItem())
|
self.ShowTestWindow(evt.GetItem())
|
||||||
|
|
||||||
# Double-click on Windows
|
# Double-click on Windows
|
||||||
def OnDClick(self, evt):
|
def OnDClick(self, evt):
|
||||||
item, flags = self.HitTest(evt.GetPosition())
|
item, flags = self.HitTest(evt.GetPosition())
|
||||||
@@ -618,13 +630,32 @@ class XML_Tree(wxTreeCtrl):
|
|||||||
if item != self.root: self.ShowTestWindow(item)
|
if item != self.root: self.ShowTestWindow(item)
|
||||||
else:
|
else:
|
||||||
evt.Skip()
|
evt.Skip()
|
||||||
|
|
||||||
|
def OnItemExpandedCollapsed(self, evt):
|
||||||
|
# Update tool palette
|
||||||
|
g.tools.UpdateUI()
|
||||||
|
evt.Skip()
|
||||||
|
|
||||||
# (re)create test window
|
# (re)create test window
|
||||||
def CreateTestWin(self, item):
|
def CreateTestWin(self, item):
|
||||||
testWin = g.testWin
|
testWin = g.testWin
|
||||||
wxBeginBusyCursor()
|
|
||||||
wxYield()
|
|
||||||
# Create a window with this resource
|
# Create a window with this resource
|
||||||
xxx = self.GetPyData(item).treeObject()
|
xxx = self.GetPyData(item).treeObject()
|
||||||
|
|
||||||
|
# If frame
|
||||||
|
# if xxx.__class__ == xxxFrame:
|
||||||
|
# Frame can't have many children,
|
||||||
|
# but it's first child possibly can...
|
||||||
|
# child = self.GetFirstChild(item, 0)[0]
|
||||||
|
# if child.IsOk() and self.GetPyData(child).__class__ == xxxPanel:
|
||||||
|
# # Clean-up before recursive call or error
|
||||||
|
# wxMemoryFSHandler_RemoveFile('xxx.xrc')
|
||||||
|
# wxEndBusyCursor()
|
||||||
|
# self.CreateTestWin(child)
|
||||||
|
# return
|
||||||
|
|
||||||
|
wxBeginBusyCursor()
|
||||||
|
wxYield()
|
||||||
# Close old window, remember where it was
|
# Close old window, remember where it was
|
||||||
highLight = None
|
highLight = None
|
||||||
if testWin:
|
if testWin:
|
||||||
@@ -664,7 +695,7 @@ class XML_Tree(wxTreeCtrl):
|
|||||||
name = 'noname'
|
name = 'noname'
|
||||||
else:
|
else:
|
||||||
name = xxx.name
|
name = xxx.name
|
||||||
elem.setAttribute('name', self.stdName)
|
elem.setAttribute('name', STD_NAME)
|
||||||
parent = elem.parentNode
|
parent = elem.parentNode
|
||||||
next = elem.nextSibling
|
next = elem.nextSibling
|
||||||
parent.replaceChild(self.dummyNode, elem)
|
parent.replaceChild(self.dummyNode, elem)
|
||||||
@@ -690,55 +721,61 @@ class XML_Tree(wxTreeCtrl):
|
|||||||
if xxx.__class__ == xxxFrame:
|
if xxx.__class__ == xxxFrame:
|
||||||
# Frame can't have many children,
|
# Frame can't have many children,
|
||||||
# but it's first child possibly can...
|
# but it's first child possibly can...
|
||||||
child = self.GetFirstChild(item, 0)[0]
|
# child = self.GetFirstChild(item, 0)[0]
|
||||||
if child.IsOk() and self.GetPyData(child).__class__ == xxxPanel:
|
# if child.IsOk() and self.GetPyData(child).__class__ == xxxPanel:
|
||||||
# Clean-up before recursive call or error
|
# # Clean-up before recursive call or error
|
||||||
wxMemoryFSHandler_RemoveFile('xxx.xrc')
|
# wxMemoryFSHandler_RemoveFile('xxx.xrc')
|
||||||
wxEndBusyCursor()
|
# wxEndBusyCursor()
|
||||||
self.CreateTestWin(child)
|
# self.CreateTestWin(child)
|
||||||
return
|
# return
|
||||||
# This currently works under GTK, but not under MSW
|
# This currently works under GTK, but not under MSW
|
||||||
testWin = g.testWin = wxPreFrame()
|
testWin = g.testWin = wxPreFrame()
|
||||||
res.LoadOnFrame(testWin, g.frame, self.stdName)
|
res.LoadOnFrame(testWin, g.frame, STD_NAME)
|
||||||
# Create status bar
|
# Create status bar
|
||||||
|
testWin.panel = testWin
|
||||||
testWin.CreateStatusBar()
|
testWin.CreateStatusBar()
|
||||||
|
testWin.SetClientSize(testWin.GetBestSize())
|
||||||
testWin.panel = testWin
|
testWin.panel = testWin
|
||||||
testWin.SetPosition(pos)
|
testWin.SetPosition(pos)
|
||||||
testWin.Show(True)
|
testWin.Show(True)
|
||||||
elif xxx.__class__ == xxxPanel:
|
elif xxx.__class__ == xxxPanel:
|
||||||
# Create new frame
|
# Create new frame
|
||||||
if not testWin:
|
if not testWin:
|
||||||
testWin = g.testWin = wxFrame(g.frame, -1, 'Panel: ' + name, pos=pos)
|
testWin = g.testWin = wxFrame(g.frame, -1, 'Panel: ' + name,
|
||||||
testWin.panel = res.LoadPanel(testWin, self.stdName)
|
pos=pos, name=STD_NAME)
|
||||||
testWin.SetClientSize(testWin.panel.GetSize())
|
testWin.panel = res.LoadPanel(testWin, STD_NAME)
|
||||||
|
testWin.SetClientSize(testWin.GetBestSize())
|
||||||
testWin.Show(True)
|
testWin.Show(True)
|
||||||
elif xxx.__class__ == xxxDialog:
|
elif xxx.__class__ == xxxDialog:
|
||||||
testWin = g.testWin = res.LoadDialog(None, self.stdName)
|
testWin = g.testWin = res.LoadDialog(None, STD_NAME)
|
||||||
testWin.panel = testWin
|
testWin.panel = testWin
|
||||||
testWin.Layout()
|
testWin.Layout()
|
||||||
testWin.SetPosition(pos)
|
testWin.SetPosition(pos)
|
||||||
testWin.Show(True)
|
testWin.Show(True)
|
||||||
|
# Dialog's default code does not produce EVT_CLOSE
|
||||||
|
EVT_BUTTON(testWin, wxID_OK, self.OnCloseTestWin)
|
||||||
|
EVT_BUTTON(testWin, wxID_CANCEL, self.OnCloseTestWin)
|
||||||
elif xxx.__class__ == xxxMenuBar:
|
elif xxx.__class__ == xxxMenuBar:
|
||||||
testWin = g.testWin = wxFrame(g.frame, -1, 'MenuBar: ' + name, pos=pos)
|
testWin = g.testWin = wxFrame(g.frame, -1, 'MenuBar: ' + name,
|
||||||
|
pos=pos, name=STD_NAME)
|
||||||
testWin.panel = None
|
testWin.panel = None
|
||||||
# Set status bar to display help
|
# Set status bar to display help
|
||||||
testWin.CreateStatusBar()
|
testWin.CreateStatusBar()
|
||||||
testWin.menuBar = res.LoadMenuBar(self.stdName)
|
testWin.menuBar = res.LoadMenuBar(STD_NAME)
|
||||||
testWin.SetMenuBar(testWin.menuBar)
|
testWin.SetMenuBar(testWin.menuBar)
|
||||||
testWin.Show(True)
|
testWin.Show(True)
|
||||||
elif xxx.__class__ == xxxToolBar:
|
elif xxx.__class__ == xxxToolBar:
|
||||||
testWin = g.testWin = wxFrame(g.frame, -1, 'ToolBar: ' + name, pos=pos)
|
testWin = g.testWin = wxFrame(g.frame, -1, 'ToolBar: ' + name,
|
||||||
|
pos=pos, name=STD_NAME)
|
||||||
testWin.panel = None
|
testWin.panel = None
|
||||||
# Set status bar to display help
|
# Set status bar to display help
|
||||||
testWin.CreateStatusBar()
|
testWin.CreateStatusBar()
|
||||||
testWin.toolBar = res.LoadToolBar(testWin, self.stdName)
|
testWin.toolBar = res.LoadToolBar(testWin, STD_NAME)
|
||||||
testWin.SetToolBar(testWin.toolBar)
|
testWin.SetToolBar(testWin.toolBar)
|
||||||
testWin.Show(True)
|
testWin.Show(True)
|
||||||
wxMemoryFSHandler_RemoveFile('xxx.xrc')
|
wxMemoryFSHandler_RemoveFile('xxx.xrc')
|
||||||
testWin.item = item
|
testWin.item = item
|
||||||
EVT_CLOSE(testWin, self.OnCloseTestWin)
|
EVT_CLOSE(testWin, self.OnCloseTestWin)
|
||||||
EVT_BUTTON(testWin, wxID_OK, self.OnCloseTestWin)
|
|
||||||
EVT_BUTTON(testWin, wxID_CANCEL, self.OnCloseTestWin)
|
|
||||||
testWin.highLight = None
|
testWin.highLight = None
|
||||||
if highLight and not self.pendingHighLight:
|
if highLight and not self.pendingHighLight:
|
||||||
self.HighLight(highLight)
|
self.HighLight(highLight)
|
||||||
|
Reference in New Issue
Block a user