I am just trying to change the highlight focus and non focus color depending on the state of the selected item in a CustomTreeCtrl. Instead of long discussion, here's an example:
# Initialization somewhere in __init__
self.tree = ctc.CustomTreeCtrl(self.frame)
self.tree.Bind(wx.EVT_PAINT, self.OnEvtPaint)
# Then
def OnEvtPaint(self, event):
item = self.tree.GetSelection()
if item:
data = self.tree.GetPyData(self.tree.GetSelection())
if data:
if data.modificationFlag:
self.tree.SetHilightFocusColour("red")
# Not helpful.. #self.tree.RefreshSelected() #self.tree.RefreshSubtree(self.root)
else:
self.tree.SetHilightFocusColour("blue")
event.Skip()
With above definition I have some rendering trouble (generally with the current selected item).
The paint event is not really a good place to do something like changing the sate of the widget, especially since SetHilightFocusColour will result in a Refresh and therefore another paint event. Try using an EVT_IDLE event instead. It will also help if you can also avoid calling SetHilightFocusColour if that colour is already set. Something like this:
def OnEvtIdle(self, event):
item = self.tree.GetSelection()
if item:
data = self.tree.GetPyData(self.tree.GetSelection())
if data:
if data.modificationFlag:
clr = wx.NamedColour("red")
else:
clr = wx.NamedColour("blue")
if clr != self.tree.GetHilightFocusColour():
self.tree.SetHilightFocusColour(clr)
event.Skip()
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
I have just encountered an issue with the idle function:
- When I select (left clic) modified and unmodified items in the tree, highlight colour is set correctly.
- But if I select (left clic) a modified item then an unmodified one through right-clic, the highlight colour is not set properly (or first selecting an unmodified item with left-clic then a modified one with right clic).
I have attached a new version of my sample script to demonstrate what's happening.
Does someone have any suggestion ?
Thank,
Mathias
Mathias Lorente wrote:
···
Robin Dunn wrote:
Mathias Lorente wrote:
Hello,
I am just trying to change the highlight focus and non focus color depending on the state of the selected item in a CustomTreeCtrl. Instead of long discussion, here's an example:
# Initialization somewhere in __init__
self.tree = ctc.CustomTreeCtrl(self.frame)
self.tree.Bind(wx.EVT_PAINT, self.OnEvtPaint)
# Then
def OnEvtPaint(self, event):
item = self.tree.GetSelection()
if item:
data = self.tree.GetPyData(self.tree.GetSelection())
if data:
if data.modificationFlag:
self.tree.SetHilightFocusColour("red")
# Not helpful.. #self.tree.RefreshSelected() #self.tree.RefreshSubtree(self.root)
else:
self.tree.SetHilightFocusColour("blue")
event.Skip()
With above definition I have some rendering trouble (generally with the current selected item).
The paint event is not really a good place to do something like changing the sate of the widget, especially since SetHilightFocusColour will result in a Refresh and therefore another paint event. Try using an EVT_IDLE event instead. It will also help if you can also avoid calling SetHilightFocusColour if that colour is already set. Something like this:
def OnEvtIdle(self, event):
item = self.tree.GetSelection()
if item:
data = self.tree.GetPyData(self.tree.GetSelection())
if data:
if data.modificationFlag:
clr = wx.NamedColour("red")
else:
clr = wx.NamedColour("blue")
if clr != self.tree.GetHilightFocusColour():
self.tree.SetHilightFocusColour(clr)
event.Skip()
Thanks a lot! It works like a charm.
By now I will use more often the idle event.
Mathias.
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
---------------------------------------------------------------------------------------
Orange vous informe que cet e-mail a ete controle par l'anti-virus mail. Aucun virus connu a ce jour par nos services n'a ete detecte.
Finally, I get back to "Paint event" solution even if wxWidget documentation says: "[...]so you shouldn't attempt to handle paint events for them as even if it might work on some platforms, this is inherently not portable and won't work everywhere."
Thanks for your help.
Mathias
Mathias Lorente wrote:
···
Hello,
I have just encountered an issue with the idle function:
- When I select (left clic) modified and unmodified items in the tree, highlight colour is set correctly.
- But if I select (left clic) a modified item then an unmodified one through right-clic, the highlight colour is not set properly (or first selecting an unmodified item with left-clic then a modified one with right clic).
I have attached a new version of my sample script to demonstrate what's happening.
Does someone have any suggestion ?
Thank,
Mathias
Mathias Lorente wrote:
Robin Dunn wrote:
Mathias Lorente wrote:
Hello,
I am just trying to change the highlight focus and non focus color depending on the state of the selected item in a CustomTreeCtrl. Instead of long discussion, here's an example:
# Initialization somewhere in __init__
self.tree = ctc.CustomTreeCtrl(self.frame)
self.tree.Bind(wx.EVT_PAINT, self.OnEvtPaint)
# Then
def OnEvtPaint(self, event):
item = self.tree.GetSelection()
if item:
data = self.tree.GetPyData(self.tree.GetSelection())
if data:
if data.modificationFlag:
self.tree.SetHilightFocusColour("red")
# Not helpful.. #self.tree.RefreshSelected() #self.tree.RefreshSubtree(self.root)
else:
self.tree.SetHilightFocusColour("blue")
event.Skip()
With above definition I have some rendering trouble (generally with the current selected item).
The paint event is not really a good place to do something like changing the sate of the widget, especially since SetHilightFocusColour will result in a Refresh and therefore another paint event. Try using an EVT_IDLE event instead. It will also help if you can also avoid calling SetHilightFocusColour if that colour is already set. Something like this:
def OnEvtIdle(self, event):
item = self.tree.GetSelection()
if item:
data = self.tree.GetPyData(self.tree.GetSelection())
if data:
if data.modificationFlag:
clr = wx.NamedColour("red")
else:
clr = wx.NamedColour("blue")
if clr != self.tree.GetHilightFocusColour():
self.tree.SetHilightFocusColour(clr)
event.Skip()
Thanks a lot! It works like a charm.
By now I will use more often the idle event.
Mathias.
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
---------------------------------------------------------------------------------------
Orange vous informe que cet e-mail a ete controle par l'anti-virus mail. Aucun virus connu a ce jour par nos services n'a ete detecte.
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
---------------------------------------------------------------------------------------
Orange vous informe que cet e-mail a ete controle par l'anti-virus mail. Aucun virus connu a ce jour par nos services n'a ete detecte.