Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8515159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:04:21+00:00 2026-06-11T05:04:21+00:00

I was trying to create ListCtrl-derived class to add 2 functions, set_data and _set_column_width

  • 0

I was trying to create ListCtrl-derived class to add 2 functions, set_data and _set_column_width, here is the code:

class ListReport(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):

    def __init__(self, parent=None,  columns=['DEFAULT'], size=wx.DefaultSize,
                 pos=wx.DefaultPosition, style=wx.LC_REPORT|wx.LC_VRULES):
        wx.ListCtrl.__init__(self, parent, wx.ID_ANY, pos, size, style)
        listmix.ListCtrlAutoWidthMixin.__init__(self)
        self.columns = columns
        self.column_index = len(columns)

        self.InsertColumn(0, 'No.')
        for enum, column in enumerate(columns):
            enum += 1
            self.InsertColumn(enum, column)

    def set_data(self, data):
        # Change all data into str
        values = [map(str, value) for value in data]

        for enum, value in enumerate(values):
            enum += 1

            first = self.InsertStringItem(sys.maxint, str(enum))

            for x in range(self.column_index):
                if value[x] == None:
                    self.SetStringItem(first, x+1, '-')
                else:
                    self.SetStringItem(first, x+1, value[x])

            # Give ListCtrl some colors
            if first % 2:
                self.SetItemBackgroundColour(first, 'E8E8E8')
            else:
                self.SetItemBackgroundColour(first, '#FBFF94')

        self._set_column_width(data)

    def _set_column_width(self, data=None):
        """Automatically resize column based on data or column header
        if column header longer than data using wx.LIST_AUTOSIZE_USEHEADER
        else using data instead.
        """
        for x in range(self.column_index):
            longest = max([len(str(row[x])) for row in data])
            if len(self.columns[x]) + 3 > longest:
                self.SetColumnWidth(x+1, wx.LIST_AUTOSIZE_USEHEADER)
            else:
                self.SetColumnWidth(x+1, wx.LIST_AUTOSIZE)
        self.SetColumnWidth(0, 37)
        self.resizeLastColumn(0)

Then, I’m using class above to create another class with TextEditMixin

class ListReportEdit(ListReport, listmix.TextEditMixin):

    def __init__(self, parent=None, columns=['DEFAULT'], size=wx.DefaultSize,
                 pos=wx.DefaultPosition, style=wx.LC_REPORT|wx.LC_VRULES):
        ListReport(parent, columns, size, pos, style)
        listmix.TextEditMixin.__init__(self)

But, I got this error when trying to use it

Traceback (most recent call last):
  File "wxform_sandbox.py", line 263, in <module>
    a = Sandbox()
  File "wxform_sandbox.py", line 27, in __init__
    lr = ListReportEdit(panel, columns, size=(400, 300))
  File "wxform_sandbox.py", line 145, in __init__
    listmix.TextEditMixin.__init__(self)
  File "C:\Program Files\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\mixins\listctrl.py", line 451, in __init__
    self.make_editor()
  File "C:\Program Files\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\mixins\listctrl.py", line 466, in make_editor
    editor = wx.TextCtrl(self, -1, style=style)
  File "C:\Program Files\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_controls.py", line 1736, in __init__
    _controls_.TextCtrl_swiginit(self,_controls_.new_TextCtrl(*args, **kwargs))
TypeError: in method 'new_TextCtrl', expected argument 1 of type 'wxWindow *'

But then, when I’m using wx.ListCtrl as base class of ListReportEdit instead of ListReport it works perfectly, I’m not clearly understand how python inheritance works.

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:04:23+00:00Added an answer on June 11, 2026 at 5:04 am

    Try this, you haven’t called the parents init method (well, you have, but you’re making a new ListReport object)

    class ListReportEdit(ListReport, listmix.TextEditMixin):
    
        def __init__(self, parent=None, columns=['DEFAULT'], size=wx.DefaultSize,
                     pos=wx.DefaultPosition, style=wx.LC_REPORT|wx.LC_VRULES):
            ListReport.__init__(self,parent, columns, size, pos, style)
            listmix.TextEditMixin.__init__(self)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok so I am trying create a login script, here I am using PHP5
I trying create a class derivated from System.Web.UI.Page and in override Render i set
In my android application I am trying create persistent connection for downloading images. Here
I am trying create a table and add this table into tablecell (table inside
I trying create empty white image with php, this s my code $bg =
I'm trying create new object from a module class in VBA, and I have
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I am trying create a delegate representation of constructor by emitting a Dynamic Method,
Trying to create a black line in my view to separate text blocks but
Trying to create a facebook app just to learn and coming across a strange

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.