Reputation: 1866
Hi guys I am trying to learn GUI programming with wxPython on Python 3.X
I am trying to capture double click on wxDataViewListCtrl. For testing I have added a button and a data-view-list and set double-click event handler for both the objects. Shown the same in the script given below
When I double click on button-control I am able to see the print-statement on screen but when I double click on data-view-list the event-handler is not getting executed
None of wxWindow event is working for wxDataViewListCtrl. What am I doing wrong ?
import wx
import wx.xrc
import wx.dataview
class MyFrame1 ( wx.Frame ):
def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
gSizer1 = wx.GridSizer( 2, 1, 0, 0 )
self.m_button1 = wx.Button( self, wx.ID_ANY, u"MyButton", wx.DefaultPosition, wx.DefaultSize, 0 )
gSizer1.Add( self.m_button1, 0, wx.ALL, 5 )
self.m_dataViewListCtrl2 = wx.dataview.DataViewListCtrl( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0 )
gSizer1.Add( self.m_dataViewListCtrl2, 0, wx.ALL, 5 )
self.SetSizer( gSizer1 )
self.Layout()
self.Centre( wx.BOTH )
# Connect Events
self.m_button1.Bind( wx.EVT_LEFT_DCLICK, self.button_double_click )
self.m_dataViewListCtrl2.Bind( wx.EVT_LEFT_DCLICK, self.listview_double_click )
def __del__( self ):
pass
# Virtual event handlers, overide them in your derived class
def button_double_click( self, event ):
print("button_double_click")
event.Skip()
def listview_double_click( self, event ):
print("listview_double_click")
event.Skip()
app = wx.App()
frame = MyFrame1(None)
frame.Show()
app.MainLoop()
Upvotes: 0
Views: 527
Reputation: 22678
Generally speaking, you're not supposed to be able to handle low-level events such as clicks or double clicks from the native controls, but to use control-specific events instead. In this concrete case, you probably want to use wxEVT_DATAVIEW_ITEM_ACTIVATED
instead.
Upvotes: 2