How do I Disable a ListCtrl?

I have a wx.ListCtrl which I would like to disable so that entire control is grayed out and clicking on its items won’t do anything. It seems that a call to lc.Enable(False) doesn’t have the effect. Am I doing something wrong here, or is this not a feature of the ListCtrl? If it’s not a feature, is there a way to mimic it, or another type of list control that can be disabled?

Below is an example. In the example I’m using a virtual control, but I also tried with a non-virtual control and that didn’t disable either.

Thanks, Tom

import wx

class TestFrame(wx.Frame):

def __init__(self):
   
    wx.Frame.__init__(self, None, -1, title="Test", size=(300, 300))
    self.panel = wx.Panel(self, -1)
    btn = wx.Button(self.panel, -1, "btn", pos=(10,10))
    lc = LC(self.panel)
    self.panel.Enable(False)
    btn.Enable(False)
    lc.Enable(False)

class LC(wx.ListCtrl):

def __init__(self, parent):
    self.item_list = ["A", "B", "C"]
   
    wx.ListCtrl.__init__(self, parent, -1, pos=(10, 50), size=(200,200),
            style=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_NO_HEADER|wx.LC_SINGLE_SEL|wx.BORDER_NONE)
    self.InsertColumn(0, "groups")
    self.SetItemCount(len(self.item_list))
    self.Bind(wx.EVT_LIST_ITEM_SELECTED, self._Ping)

def OnGetItemText(self, item, col):
    if col==0:
        return self.item_list[item]
def OnGetItemImage(self, item):
    return -1
def OnGetItemAttr(self, item):
    return None
   
def _Ping(self, evt):
    x =  evt.GetItem().GetText()
    print "ping", x

if name==“main”:

app = wx.App()
frame = TestFrame()
frame.Show(True)
frame.Layout()
app.MainLoop()

Here’s the same code attached, as list_disable_02.py. I’ll also attach a version using a non-virtual control, as list_disable_03.py, modified from wxPython: wx.ListCtrl Tips and Tricks - Mouse Vs Python .

list_disable_02.py (1.21 KB)

list_disable_03.py (1.67 KB)

···

On Friday, October 24, 2014 11:12:34 AM UTC-4, Tom wrote:

I have a wx.ListCtrl which I would like to disable so that entire control is grayed out and clicking on its items won’t do anything. It seems that a call to lc.Enable(False) doesn’t have the effect. Am I doing something wrong here, or is this not a feature of the ListCtrl? If it’s not a feature, is there a way to mimic it, or another type of list control that can be disabled?

Below is an example. In the example I’m using a virtual control, but I also tried with a non-virtual control and that didn’t disable either.

Thanks, Tom

import wx

class TestFrame(wx.Frame):

def __init__(self):
   
    wx.Frame.__init__(self, None, -1, title="Test", size=(300, 300))
    self.panel = wx.Panel(self, -1)
    btn = wx.Button(self.panel, -1, "btn", pos=(10,10))
    lc = LC(self.panel)
    self.panel.Enable(False)
    btn.Enable(False)
    lc.Enable(False)

class LC(wx.ListCtrl):

def __init__(self, parent):
    self.item_list = ["A", "B", "C"]
   
    wx.ListCtrl.__init__(self, parent, -1, pos=(10, 50), size=(200,200),
            style=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_NO_HEADER|wx.LC_SINGLE_SEL|wx.BORDER_NONE)
    self.InsertColumn(0, "groups")
    self.SetItemCount(len(self.item_list))
    self.Bind(wx.EVT_LIST_ITEM_SELECTED, self._Ping)

def OnGetItemText(self, item, col):
    if col==0:
        return self.item_list[item]
def OnGetItemImage(self, item):
    return -1
def OnGetItemAttr(self, item):
    return None
   
def _Ping(self, evt):
    x =  evt.GetItem().GetText()
    print "ping", x

if name==“main”:

app = wx.App()
frame = TestFrame()
frame.Show(True)
frame.Layout()
app.MainLoop()

Tom wrote:

I have a wx.ListCtrl which I would like to disable so that entire
control is grayed out and clicking on its items won't do anything. It
seems that a call to lc.Enable(False) doesn't have the effect. Am I
doing something wrong here, or is this not a feature of the ListCtrl?
If it's not a feature, is there a way to mimic it, or another type of
list control that can be disabled?

Below is an example. In the example I'm using a virtual control, but
I also tried with a non-virtual control and that didn't disable either.

What version and operating system? I copied and pasted your exact code
on Windows 7, Python 2.7.5, wx 2.8.12, and the list control most
certainly is disabled. The control looks different (background color
changes), and clicks are ignored.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Thanks for testing this.

I’m running OSX 10.9.5, and I’ve just tried a few different python and wx versions:

  1. In Python 2.7.8 (Anaconda) with wx3.0.0.0, or Python 2.6.6 with wx3.0.1.1: I get no effect using Disable, ie, no gray, and I can still select items.

  2. In Python 2.6.6 with wx2.8.12.1 or Python2.6.6 with wx 2.9.1.1: I get no graying with Disable (on any other visual indication that disabled), but I can’t select items.

Tom

···

On Friday, October 24, 2014 1:53:06 PM UTC-4, Tim Roberts wrote:

Tom wrote:

I have a wx.ListCtrl which I would like to disable so that entire

control is grayed out and clicking on its items won’t do anything. It

seems that a call to lc.Enable(False) doesn’t have the effect. Am I

doing something wrong here, or is this not a feature of the ListCtrl?
If it’s not a feature, is there a way to mimic it, or another type of

list control that can be disabled?

Below is an example. In the example I’m using a virtual control, but

I also tried with a non-virtual control and that didn’t disable either.

What version and operating system? I copied and pasted your exact code

on Windows 7, Python 2.7.5, wx 2.8.12, and the list control most

certainly is disabled. The control looks different (background color

changes), and clicks are ignored.


Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.

ListCtrl Enable(False) works for me on Python 2.7.5 with wxPython 3.0.1.0-classic on WinXP

···

On Friday, October 24, 2014 11:55:58 AM UTC-7, Tom wrote:

On Friday, October 24, 2014 1:53:06 PM UTC-4, Tim Roberts wrote:

Tom wrote:

I have a wx.ListCtrl which I would like to disable so that entire

control is grayed out and clicking on its items won’t do anything. It

seems that a call to lc.Enable(False) doesn’t have the effect. Am I

doing something wrong here, or is this not a feature of the ListCtrl?
If it’s not a feature, is there a way to mimic it, or another type of

list control that can be disabled?

Below is an example. In the example I’m using a virtual control, but

I also tried with a non-virtual control and that didn’t disable either.

What version and operating system? I copied and pasted your exact code

on Windows 7, Python 2.7.5, wx 2.8.12, and the list control most

certainly is disabled. The control looks different (background color

changes), and clicks are ignored.


Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.

Thanks for testing this.

I’m running OSX 10.9.5, and I’ve just tried a few different python and wx versions:

  1. In Python 2.7.8 (Anaconda) with wx3.0.0.0, or Python 2.6.6 with wx3.0.1.1: I get no effect using Disable, ie, no gray, and I can still select items.

  2. In Python 2.6.6 with wx2.8.12.1 or Python2.6.6 with wx 2.9.1.1: I get no graying with Disable (on any other visual indication that disabled), but I can’t select items.

Tom

It’s good to know it works on Windows. It seems then like this is a bug in OSX?

Any suggestions for the next step? Should I post to the wx-mac users groups, or file a bug report?

Tom

···

On Friday, October 24, 2014 5:33:53 PM UTC-4, Nathan McCorkle wrote:

ListCtrl Enable(False) works for me on Python 2.7.5 with wxPython 3.0.1.0-classic on WinXP