Opened 6 years ago

#10514 new enhancement

DirBrowseButton does not support passing labelWidth argument

Reported by: leovitch Owned by:
Priority: normal Milestone:
Component: wxPython Version:
Keywords: Cc:
Blocked By: Blocking:
Patch: no

Description

DirBrowseButton in filebrowsebutton.py is a subclass of FileBrowseButton in the same file, but it doesn't support passing all of the superclass' keyword arguments in. Unfortunately, some of these arguments, such as labelWidth, take effect immediately, so there's no direct way to cope with this in client code. It looks like this is a result of the labelWidth parameter getting added to FileBrowseButton and not retrofitted to DirBrowseButton. There's no logical problem in using this with DirBrowseButton, but you are prevented from actually using it.

How to reproduce: try to create a DirBrowseButton and set the labelWidth parameter (the labelWidth parameter of FileBrowseButton allows every label in a column of these controls to be the same width). You will get a TypeError because of the mismatch.

How to fix: this particular parameter could simply be added to the code in DirBrowseButton.init, but for the future it would probably be better to make that method use *args and kwargs instead. Here is the code I'm currently using to patch around the problem; this could be directly incorporated to DirBrowseButton to fix the problem.

from wx.lib.filebrowsebutton import DirBrowseButton as DirBrowseButtonBase
from wx.lib.filebrowsebutton import FileBrowseButton

class DirBrowseButton(DirBrowseButtonBase):
    ownArgs = {
        'dialogClass': wx.DirDialog,
        'newDirectory': False,
    }
    def __init__(self, *args, **kwargs):
        for (ownAttr,ownValue) in self.ownArgs.iteritems():
            if ownAttr in kwargs:
                ownValue = kwargs[ownAttr]
                del kwargs[ownAttr]
            setattr(self,ownAttr,ownValue)
        FileBrowseButton.__init__(self, *args, **kwargs)

I guess strictly speaking this is an 'enhancement' although really it's just an incomplete implementation of labelWidth.

Change History (0)

Note: See TracTickets for help on using tickets.