Os11
April 4, 2011, 1:25am
1
i want show a menu for diferent item but i dont know how if i got this
show the same menu
rt = self.GetRootItem()
itm = self.GetSelection()#here must be a child selected
if self.IsSelected(rt):
self.OnRootClick()
elif self.IsSelected(itm):
self.OnItemClick()
Robin
April 4, 2011, 8:45pm
2
I usually just check if the item's parent is ok. IOW:
parent = self.GetItemParent(item)
if not parent.IsOk():
# there is no parent so the item is the root
else:
# item is not the root.
···
On 4/3/11 6:25 PM, iozk_Live wrote:
i want show a menu for diferent item but i dont know how if i got this
show the same menu
rt = self.GetRootItem()
itm = self.GetSelection()#here must be a child selected
if self.IsSelected(rt):
self.OnRootClick()
elif self.IsSelected(itm):
self.OnItemClick()
--
Robin Dunn
Software Craftsman
Robin
April 4, 2011, 8:48pm
3
Oh yeah, the wx.TreeItemId class now overrides the == operator, (__eq__ in Python) so you can probably just check like this:
if item == self.GetRootItem():
....
···
On 4/4/11 1:45 PM, Robin Dunn wrote:
On 4/3/11 6:25 PM, iozk_Live wrote:
i want show a menu for diferent item but i dont know how if i got this
show the same menu
rt = self.GetRootItem()
itm = self.GetSelection()#here must be a child selected
if self.IsSelected(rt):
self.OnRootClick()
elif self.IsSelected(itm):
self.OnItemClick()
I usually just check if the item's parent is ok. IOW:
parent = self.GetItemParent(item)
if not parent.IsOk():
# there is no parent so the item is the root
else:
# item is not the root.
--
Robin Dunn
Software Craftsman
Os11
April 5, 2011, 9:59pm
4
nope it still show the same menu
def OnRightClick(self, event):
item = self.GetSelection()
if item == self.GetRootItem():
#parent = self.GetItemParent(item)
self.OnRootClick()
else:
self.GetNextChild(item)
self.OnItemClick()
'''if item == GetItemParent() :
self.OnRootClick()
elif self.ItemHasChildren(item):
self.OnItemClick()'''
···
On 4 abr, 15:48, Robin Dunn <ro...@alldunn.com> wrote:
On 4/4/11 1:45 PM, Robin Dunn wrote:
> On 4/3/11 6:25 PM, iozk_Live wrote:
>> i want show a menu for diferent item but i dont know how if i got this
>> show the same menu
>> rt = self.GetRootItem()
>> itm = self.GetSelection()#here must be a child selected
>> if self.IsSelected(rt):
>> self.OnRootClick()
>> elif self.IsSelected(itm):
>> self.OnItemClick()
> I usually just check if the item's parent is ok. IOW:
> parent = self.GetItemParent(item)
> if not parent.IsOk():
> # there is no parent so the item is the root
> else:
> # item is not the root.
Oh yeah, the wx.TreeItemId class now overrides the == operator, (__eq__
in Python) so you can probably just check like this:
if item == self\.GetRootItem\(\):
\.\.\.\.
--
Robin Dunn
Software Craftsmanhttp://wxPython.org
Robin
April 7, 2011, 7:09pm
5
Please make a runnable, small as possible, sample application that demonstrates the problem. MakingSampleApps - wxPyWiki
···
On 4/5/11 2:59 PM, iozk_Live wrote:
On 4 abr, 15:48, Robin Dunn<ro...@alldunn.com> wrote:
On 4/4/11 1:45 PM, Robin Dunn wrote:
On 4/3/11 6:25 PM, iozk_Live wrote:
i want show a menu for diferent item but i dont know how if i got this
show the same menu
rt = self.GetRootItem()
itm = self.GetSelection()#here must be a child selected
if self.IsSelected(rt):
self.OnRootClick()
elif self.IsSelected(itm):
self.OnItemClick()
I usually just check if the item's parent is ok. IOW:
parent = self.GetItemParent(item)
if not parent.IsOk():
# there is no parent so the item is the root
else:
# item is not the root.
Oh yeah, the wx.TreeItemId class now overrides the == operator, (__eq__
in Python) so you can probably just check like this:
if item == self.GetRootItem():
nope it still show the same menu
def OnRightClick(self, event):
item = self.GetSelection()
if item == self.GetRootItem():
#parent = self.GetItemParent(item)
self.OnRootClick()
else:
self.GetNextChild(item)
self.OnItemClick()
'''if item == GetItemParent() :
self.OnRootClick()
elif self.ItemHasChildren(item):
self.OnItemClick()'''
--
Robin Dunn
Software Craftsman
Os11
April 7, 2011, 9:56pm
6
#! /usr/bin/python
import wx
class TreeClickItemsSample(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)
self.tree = wx.TreeCtrl(self)
root = self.tree.AddRoot("Root Item")
self.tree.AppendItem(root, "sample")
self.Bind(wx.EVT_TREE_ITEM_MENU, self.OnRightClick)
def OnRightClick(self, event):
item = self.tree.GetSelection()
#if item == :
parent = self.tree.GetItemParent(item)
if not parent.IsOk():
self.OnRootClick()
else:
self.OnChildClick()
def OnRootClick(self):
dlg = wx.Dialog(self, -1, "Root Clicked")
dlg.ShowModal()
def OnChildClick(self):
dlg = wx.Dialog(self, -1, "Child Clicked")
dlg.ShowModal()
app = wx.App()
TreeClickItemsSample(None, -1, "Click item").Show()
app.MainLoop()
···
On 7 abr, 14:09, Robin Dunn <ro...@alldunn.com> wrote:
On 4/5/11 2:59 PM, iozk_Live wrote:
> On 4 abr, 15:48, Robin Dunn<ro...@alldunn.com> wrote:
>> On 4/4/11 1:45 PM, Robin Dunn wrote:
>>> On 4/3/11 6:25 PM, iozk_Live wrote:
>>>> i want show a menu for diferent item but i dont know how if i got this
>>>> show the same menu
>>>> rt = self.GetRootItem()
>>>> itm = self.GetSelection()#here must be a child selected
>>>> if self.IsSelected(rt):
>>>> self.OnRootClick()
>>>> elif self.IsSelected(itm):
>>>> self.OnItemClick()
>>> I usually just check if the item's parent is ok. IOW:
>>> parent = self.GetItemParent(item)
>>> if not parent.IsOk():
>>> # there is no parent so the item is the root
>>> else:
>>> # item is not the root.
>> Oh yeah, the wx.TreeItemId class now overrides the == operator, (__eq__
>> in Python) so you can probably just check like this:
>> if item == self.GetRootItem():
> nope it still show the same menu
> def OnRightClick(self, event):
> item = self.GetSelection()
> if item == self.GetRootItem():
> #parent = self.GetItemParent(item)
> self.OnRootClick()
> else:
> self.GetNextChild(item)
> self.OnItemClick()
> '''if item == GetItemParent() :
> self.OnRootClick()
> elif self.ItemHasChildren(item):
> self.OnItemClick()'''
Please make a runnable, small as possible, sample application that
demonstrates the problem.MakingSampleApps - wxPyWiki
--
Robin Dunn
Software Craftsmanhttp://wxPython.org
Robin
April 7, 2011, 10:08pm
7
Right-click does not set the selection on Windows. To get the item that was right-clicked you can use event.GetItem().
P.S. Adding something like "print self.tree.GetItemText(item)" probably would have helped you to figure out what was wrong.
···
On 4/7/11 2:56 PM, iozk_Live wrote:
On 7 abr, 14:09, Robin Dunn<ro...@alldunn.com> wrote:
On 4/5/11 2:59 PM, iozk_Live wrote:
Please make a runnable, small as possible, sample application that
demonstrates the problem.MakingSampleApps - wxPyWiki
--
Robin Dunn
Software Craftsmanhttp://wxPython.org
#! /usr/bin/python
import wx
class TreeClickItemsSample(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)
self.tree = wx.TreeCtrl(self)
root = self.tree.AddRoot("Root Item")
self.tree.AppendItem(root, "sample")
self.Bind(wx.EVT_TREE_ITEM_MENU, self.OnRightClick)
def OnRightClick(self, event):
item = self.tree.GetSelection()
#if item == :
parent = self.tree.GetItemParent(item)
--
Robin Dunn
Software Craftsman
Os11
April 19, 2011, 4:26pm
8
it always return the first item
def OnRightClick(self, event):
sel = self.GetSelection()
item = event.GetItem()
if item != self.GetItemParent(sel):
self.OnItemClick()
print self.GetItemText(sel)
else:
self.OnRootClick()
print self.GetItemText(sel)
···
On 7 abr, 17:08, Robin Dunn <ro...@alldunn.com> wrote:
On 4/7/11 2:56 PM, iozk_Live wrote:
> On 7 abr, 14:09, Robin Dunn<ro...@alldunn.com> wrote:
>> On 4/5/11 2:59 PM, iozk_Live wrote:
>> Please make a runnable, small as possible, sample application that
>> demonstrates the problem.MakingSampleApps - wxPyWiki
>> --
>> Robin Dunn
>> Software Craftsmanhttp://wxPython.org
> #! /usr/bin/python
> import wx
> class TreeClickItemsSample(wx.Frame):
> def __init__(self, parent, id, title):
> wx.Frame.__init__(self, parent, id, title)
> self.tree = wx.TreeCtrl(self)
> root = self.tree.AddRoot("Root Item")
> self.tree.AppendItem(root, "sample")
> self.Bind(wx.EVT_TREE_ITEM_MENU, self.OnRightClick)
> def OnRightClick(self, event):
> item = self.tree.GetSelection()
> #if item == :
> parent = self.tree.GetItemParent(item)
Right-click does not set the selection on Windows. To get the item that
was right-clicked you can use event.GetItem().
P.S. Adding something like "print self.tree.GetItemText(item)" probably
would have helped you to figure out what was wrong.
--
Robin Dunn
Software Craftsmanhttp://wxPython.org
Robin
April 20, 2011, 1:36am
9
What does? self.GetSelection or event.GetItem?
···
On 4/19/11 9:26 AM, iozk_Live wrote:
On 7 abr, 17:08, Robin Dunn<ro...@alldunn.com> wrote:
On 4/7/11 2:56 PM, iozk_Live wrote:
On 7 abr, 14:09, Robin Dunn<ro...@alldunn.com> wrote:
On 4/5/11 2:59 PM, iozk_Live wrote:
Please make a runnable, small as possible, sample application that
demonstrates the problem.MakingSampleApps - wxPyWiki
--
Robin Dunn
Software Craftsmanhttp://wxPython.org
#! /usr/bin/python
import wx
class TreeClickItemsSample(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)
self.tree = wx.TreeCtrl(self)
root = self.tree.AddRoot("Root Item")
self.tree.AppendItem(root, "sample")
self.Bind(wx.EVT_TREE_ITEM_MENU, self.OnRightClick)
def OnRightClick(self, event):
item = self.tree.GetSelection()
#if item == :
parent = self.tree.GetItemParent(item)
Right-click does not set the selection on Windows. To get the item that
was right-clicked you can use event.GetItem().
P.S. Adding something like "print self.tree.GetItemText(item)" probably
would have helped you to figure out what was wrong.
--
Robin Dunn
Software Craftsmanhttp://wxPython.org
it always return the first item
def OnRightClick(self, event):
sel = self.GetSelection()
item = event.GetItem()
--
Robin Dunn
Software Craftsman
Os11
May 5, 2011, 1:31am
10
ok this only works if the item is Selected or Activated. but how tell
it that show it even if is not activated?
Robin
May 5, 2011, 5:09pm
11
Please provide some context and/or a new runnable sample that shows what you are currently trying to do so we know what "this" is.
···
On 5/4/11 6:31 PM, iozk_Live wrote:
ok this only works if the item is Selected or Activated. but how tell
it that show it even if is not activated?
--
Robin Dunn
Software Craftsman