wx.DirPickerCtrl¶
This control allows the user to select a directory.
The generic implementation is a button which brings up a wx.DirDialog when clicked. Native implementation may differ but this is usually a (small) widget which give access to the dir-chooser dialog. It is only available if USE_DIRPICKERCTRL
is set to 1 (the default).
Window Styles¶
This class supports the following styles:
wx.DIRP_DEFAULT_STYLE
: The default style: includeswx.DIRP_DIR_MUST_EXIST
and, under wxMSW only,wx.DIRP_USE_TEXTCTRL
.wx.DIRP_USE_TEXTCTRL
: Creates a text control to the left of the picker button which is completely managed by the wx.DirPickerCtrl and which can be used by the user to specify a path (see SetPath). The text control is automatically synchronized with button’s value. Use functions defined in wx.PickerBase to modify the text control.wx.DIRP_DIR_MUST_EXIST
: Creates a picker which allows selecting only existing directories in the popup wx.DirDialog. Notice that, as withFLP_FILE_MUST_EXIST
, it is still possible to enter a non-existent directory even when this file is specified ifDIRP_USE_TEXTCTRL
style is also used. Also note that ifDIRP_USE_TEXTCTRL
is not used, the native wxGTK implementation always uses this style as it doesn’t support selecting non-existent directories.wx.DIRP_CHANGE_DIR
: Change current working directory on each user directory selection change.wx.DIRP_SMALL
: Use smaller version of the control with a small “…” button instead of the normal “Browse” one. This flag is new since wxWidgets 2.9.3.
Events Emitted by this Class¶
Handlers bound for the following event types will receive a wx.FileDirPickerEvent parameter.
EVT_DIRPICKER_CHANGED: The user changed the directory selected in the control either using the button or using text control (see
wx.DIRP_USE_TEXTCTRL
; note that in this case the event is fired only if the user’s input is valid, e.g. an existing directory path).
See also
Class Hierarchy¶
Control Appearance¶
Methods Summary¶
Creates the widgets with the given parameters. |
|
Returns the absolute path of the currently selected directory. |
|
Set the directory to show when starting to browse for directories. |
|
Sets the absolute path of the currently selected directory. |
Properties Summary¶
Class API¶
- class wx.DirPickerCtrl(PickerBase)¶
Possible constructors:
DirPickerCtrl() -> None DirPickerCtrl(parent, id=ID_ANY, path='', message=DirSelectorPromptStr, pos=DefaultPosition, size=DefaultSize, style=DIRP_DEFAULT_STYLE, validator=DefaultValidator, name=DirPickerCtrlNameStr) -> None
This control allows the user to select a directory.
Methods¶
- __init__(self, *args, **kw)¶
-
__init__ (self)
- Return type:
None
__init__ (self, parent, id=ID_ANY, path=’’, message=DirSelectorPromptStr, pos=DefaultPosition, size=DefaultSize, style=DIRP_DEFAULT_STYLE, validator=DefaultValidator, name=DirPickerCtrlNameStr)
Initializes the object and calls
Create
with all the parameters.- Parameters:
parent (wx.Window)
id (wx.WindowID)
path (string)
message (string)
pos (wx.Point)
size (wx.Size)
style (long)
validator (wx.Validator)
name (string)
- Return type:
None
- Create(self, parent, id=ID_ANY, path='', message=DirSelectorPromptStr, pos=DefaultPosition, size=DefaultSize, style=DIRP_DEFAULT_STYLE, validator=DefaultValidator, name=DirPickerCtrlNameStr)¶
Creates the widgets with the given parameters.
- Parameters:
parent (wx.Window) – Parent window, must not be not
None
.id (wx.WindowID) – The identifier for the control.
path (string) – The initial directory shown in the control. Must be a valid path to a directory or the empty string.
message (string) – The message shown to the user in the wx.DirDialog shown by the control.
pos (wx.Point) – Initial position.
size (wx.Size) – Initial size.
style (long) – The window style, see
DIRP_
flags.validator (wx.Validator) – Validator which can be used for additional data checks.
name (string) – Control name.
- Return type:
bool
- Returns:
True
if the control was successfully created orFalse
if creation failed.
- static GetClassDefaultAttributes(variant=WINDOW_VARIANT_NORMAL)¶
- Parameters:
variant (WindowVariant)
- Return type:
- GetPath(self)¶
Returns the absolute path of the currently selected directory.
- Return type:
str
- SetInitialDirectory(self, dir)¶
Set the directory to show when starting to browse for directories.
This function is mostly useful for the directory picker controls which have no selection initially to configure the directory that should be shown if the user starts browsing for directories as otherwise the initially selected directory is used, which is usually the desired behaviour and so the directory specified by this function is ignored in this case.
- Parameters:
dir (string)
- Return type:
None
Added in version 2.9.4.
- SetPath(self, dirname)¶
Sets the absolute path of the currently selected directory.
If the control uses
DIRP_DIR_MUST_EXIST
and does not useDIRP_USE_TEXTCTRL
style, the dirname must be a name of an existing directory and will be simply ignored by the native wxGTK implementation if this is not the case.- Parameters:
dirname (string)
- Return type:
None
Properties¶