From d211a853c520116600acfb562dcb8a6b184de993 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 7 Jun 2006 02:26:41 +0000 Subject: [PATCH] Added wrappers for the Picker controls. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39610 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wxPython/demo/Main.py | 2 + wxPython/demo/Pickers.py | 113 +++++++++++ wxPython/docs/CHANGES.txt | 4 + wxPython/setup.py | 1 + wxPython/src/_picker.i | 397 ++++++++++++++++++++++++++++++++++++++ wxPython/src/controls.i | 2 +- 6 files changed, 518 insertions(+), 1 deletion(-) create mode 100644 wxPython/demo/Pickers.py create mode 100644 wxPython/src/_picker.i diff --git a/wxPython/demo/Main.py b/wxPython/demo/Main.py index b6a429c4a5..f6dc3d2ba4 100644 --- a/wxPython/demo/Main.py +++ b/wxPython/demo/Main.py @@ -52,6 +52,7 @@ _treeList = [ 'RichTextCtrl', 'Treebook', 'Toolbook', + 'Pickers', ]), # managed windows == things with a (optional) caption you can close @@ -171,6 +172,7 @@ _treeList = [ 'MaskedNumCtrl', 'MediaCtrl', 'MultiSplitterWindow', + 'Pickers', 'PyCrust', 'PyPlot', 'PyShell', diff --git a/wxPython/demo/Pickers.py b/wxPython/demo/Pickers.py new file mode 100644 index 0000000000..434b55ebff --- /dev/null +++ b/wxPython/demo/Pickers.py @@ -0,0 +1,113 @@ + +import wx + +#---------------------------------------------------------------------- + +class TestPanel(wx.Panel): + def __init__(self, parent, log): + self.log = log + wx.Panel.__init__(self, parent, -1) + + box = wx.BoxSizer(wx.VERTICAL) + title = wx.StaticText(self, -1, "Picker Controls") + title.SetFont(wx.FFont(24, wx.FONTFAMILY_SWISS, wx.FONTFLAG_BOLD)) + title.SetForegroundColour("navy") + box.Add(title, 0, wx.ALIGN_CENTER|wx.ALL, 5) + #print title.GetBestSize(), title.GetMinSize(), title.GetSize() + + box.Add(wx.StaticLine(self), 0, wx.EXPAND) + + fgs = wx.FlexGridSizer(cols=4, hgap=5, vgap=5) + fgs.AddGrowableCol(3) + fgs.Add((10,10)) # spacer + lbl = wx.StaticText(self, -1, "w/o textctrl") + lbl.SetFont(wx.FFont(12, wx.FONTFAMILY_SWISS, wx.FONTFLAG_BOLD)) + fgs.Add(lbl) + fgs.Add((10,10)) # spacer + lbl = wx.StaticText(self, -1, "with textctrl") + lbl.SetFont(wx.FFont(12, wx.FONTFAMILY_SWISS, wx.FONTFLAG_BOLD)) + fgs.Add(lbl, 0, wx.ALIGN_CENTER) + + fgs.Add(wx.StaticText(self, -1, "wx.ColourPickerCtrl:"), 0, wx.ALIGN_CENTER_VERTICAL) + cp1 = wx.ColourPickerCtrl(self) + fgs.Add(cp1, 0, wx.ALIGN_CENTER) + fgs.Add((10,10)) # spacer + cp2 = wx.ColourPickerCtrl(self, style=wx.CLRP_USE_TEXTCTRL) + cp2.SetTextCtrlProportion(5) + fgs.Add(cp2, 0, wx.EXPAND) + self.Bind(wx.EVT_COLOURPICKER_CHANGED, self.OnPickColor, cp1) + self.Bind(wx.EVT_COLOURPICKER_CHANGED, self.OnPickColor, cp2) + + fgs.Add(wx.StaticText(self, -1, "wx.DirPickerCtrl:"), 0, wx.ALIGN_CENTER_VERTICAL) + dp1 = wx.DirPickerCtrl(self) + fgs.Add(dp1, 0, wx.ALIGN_CENTER) + fgs.Add((10,10)) # spacer + dp2 = wx.DirPickerCtrl(self, style=wx.DIRP_USE_TEXTCTRL) + dp2.SetTextCtrlProportion(2) + fgs.Add(dp2, 0, wx.EXPAND) + self.Bind(wx.EVT_DIRPICKER_CHANGED, self.OnPickFileDir, dp1) + self.Bind(wx.EVT_DIRPICKER_CHANGED, self.OnPickFileDir, dp2) + + fgs.Add(wx.StaticText(self, -1, "wx.FilePickerCtrl:"), 0, wx.ALIGN_CENTER_VERTICAL) + fp1 = wx.FilePickerCtrl(self) + fgs.Add(fp1, 0, wx.ALIGN_CENTER) + fgs.Add((10,10)) # spacer + fp2 = wx.FilePickerCtrl(self, style=wx.FLP_USE_TEXTCTRL) + fp2.SetTextCtrlProportion(2) + fgs.Add(fp2, 0, wx.EXPAND) + self.Bind(wx.EVT_FILEPICKER_CHANGED, self.OnPickFileDir, fp1) + self.Bind(wx.EVT_FILEPICKER_CHANGED, self.OnPickFileDir, fp2) + + fgs.Add(wx.StaticText(self, -1, "wx.FontPickerCtrl:"), 0, wx.ALIGN_CENTER_VERTICAL) + fnt1 = wx.FontPickerCtrl(self, style=wx.FNTP_FONTDESC_AS_LABEL) + fgs.Add(fnt1, 0, wx.ALIGN_CENTER) + fgs.Add((10,10)) # spacer + fnt2 = wx.FontPickerCtrl(self, style=wx.FNTP_FONTDESC_AS_LABEL|wx.FNTP_USE_TEXTCTRL) + fnt2.SetTextCtrlProportion(2) + fgs.Add(fnt2, 0, wx.EXPAND) + self.Bind(wx.EVT_FONTPICKER_CHANGED, self.OnPickFont, fnt1) + self.Bind(wx.EVT_FONTPICKER_CHANGED, self.OnPickFont, fnt2) + + + box.Add(fgs, 1, wx.EXPAND|wx.ALL, 5) + self.SetSizer(box) + + + def OnPickColor(self, evt): + self.log.write("You chose: %s\n" % repr(evt.GetColour())) + + def OnPickFileDir(self, evt): + self.log.write("You chose: %s\n" % repr(evt.GetPath())) + + def OnPickFont(self, evt): + font = evt.GetFont() + self.log.write("You chose: %s\n" % font.GetNativeFontInfoUserDesc()) + +#---------------------------------------------------------------------- + +def runTest(frame, nb, log): + win = TestPanel(nb, log) + return win + +#---------------------------------------------------------------------- + + + +overview = """ +

Picker Controls

+ +The Picker controls are either native or generic controls usually +comprised of a button and with an optional text control next to it. +The pickers enable the user to choose something using one of the +common dialogs and then displays the result in some way. + + +""" + + + +if __name__ == '__main__': + import sys,os + import run + run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) + diff --git a/wxPython/docs/CHANGES.txt b/wxPython/docs/CHANGES.txt index ee50857bf8..5302d5c9a8 100644 --- a/wxPython/docs/CHANGES.txt +++ b/wxPython/docs/CHANGES.txt @@ -164,6 +164,10 @@ far.) See wx.PowerEvent, wx.GetPowerType and wx.GetBatteryState. Added wx.ListCtrl.HitTestSubItem which returns the sub-item that was hit (if any) in addition to the item and flags. +Added wrappers for wx.ColourPickerCtrl, wx.DirPickerCtrl, +wx.FilePickerCtrl, and wx.FontPickerCtrl. + + diff --git a/wxPython/setup.py b/wxPython/setup.py index 6e605c5e16..e61f68bfb2 100755 --- a/wxPython/setup.py +++ b/wxPython/setup.py @@ -287,6 +287,7 @@ swig_sources = run_swig(['controls.i'], 'src', GENDIR, PKGDIR, 'src/_dragimg.i', 'src/_datectrl.i', 'src/_hyperlink.i', + 'src/_picker.i', ], True) ext = Extension('_controls_', swig_sources, diff --git a/wxPython/src/_picker.i b/wxPython/src/_picker.i new file mode 100644 index 0000000000..089711b0a4 --- /dev/null +++ b/wxPython/src/_picker.i @@ -0,0 +1,397 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: _picker.i +// Purpose: SWIG interface for Colour, Dir, File, Font picker controls +// +// Author: Robin Dunn +// +// Created: 6-June-2006 +// RCS-ID: $Id$ +// Copyright: (c) 2006 by Total Control Software +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +// Not a %module + + +//--------------------------------------------------------------------------- +%newgroup + +%{ +#include +#include +#include +#include +%} + + +enum { + wxPB_USE_TEXTCTRL, + }; + + +DocStr(wxPickerBase, +"Base abstract class for all pickers which support an auxiliary text +control. This class handles all positioning and sizing of the text +control like a an horizontal `wx.BoxSizer` would do, with the text +control on the left of the picker button and the proportion of the +picker fixed to value 1.", ""); + +class wxPickerBase : public wxControl +{ +public: + // This class is an ABC, can't be instantiated from Python. + //wxPickerBase() : m_text(NULL), m_picker(NULL), + // m_margin(5), m_textProportion(2) {} + //virtual ~wxPickerBase(); + + + // if present, intercepts wxPB_USE_TEXTCTRL style and creates the text control + // The 3rd argument is the initial wxString to display in the text control + bool CreateBase(wxWindow *parent, wxWindowID id, + const wxString& text = wxEmptyString, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxButtonNameStr); + + + + DocDeclStr( + void , SetInternalMargin(int newmargin), + "Sets the margin (in pixels) between the picker and the text control.", ""); + + DocDeclStr( + int , GetInternalMargin() const, + "Returns the margin (in pixels) between the picker and the text +control.", ""); + + + DocDeclStr( + void , SetTextCtrlProportion(int prop), + "Sets the proportion between the text control and the picker button. +This is used to set relative sizes of the text contorl and the picker. +The value passed to this function must be >= 1.", ""); + + DocDeclStr( + int , GetTextCtrlProportion() const, + "Returns the proportion between the text control and the picker.", ""); + + + DocDeclStr( + bool , HasTextCtrl() const, + "Returns true if this class has a valid text control (i.e. if the +wx.PB_USE_TEXTCTRL style was given when creating this control).", ""); + + DocDeclStr( + wxTextCtrl *, GetTextCtrl(), + "Returns a pointer to the text control handled by this class or None if +the wx.PB_USE_TEXTCTRL style was not specified when this control was +created. + +Very important: the contents of the text control could be containing +an invalid representation of the entity which can be chosen through +the picker (e.g. the user entered an invalid colour syntax because of +a typo). Thus you should never parse the content of the textctrl to +get the user's input; rather use the derived-class getter +(e.g. `wx.ColourPickerCtrl.GetColour`, `wx.FilePickerCtrl.GetPath`, +etc).", ""); + + DocDeclStr( + wxControl *, GetPickerCtrl(), + "", ""); + +}; + +//--------------------------------------------------------------------------- +%newgroup + +MAKE_CONST_WXSTRING(ColourPickerCtrlNameStr); + +enum { + wxCLRP_SHOW_LABEL, + wxCLRP_USE_TEXTCTRL, + wxCLRP_DEFAULT_STYLE, +}; + + +MustHaveApp(wxColourPickerCtrl); +DocStr(wxColourPickerCtrl, +"This control allows the user to select a colour. The generic +implementation is a button which brings up a `wx.ColourDialog` when +clicked. Native implementations may differ but this is usually a +(small) widget which give access to the colour-chooser dialog.", + +" +Window Styles +------------- + ====================== ============================================ + wx.CLRP_DEFAULT Default style. + wx.CLRP_USE_TEXTCTRL Creates a text control to the left of the + picker button which is completely managed + by the `wx.ColourPickerCtrl` and which can + be used by the user to specify a colour. + The text control is automatically synchronized + with the button's value. Use functions defined in + `wx.PickerBase` to modify the text control. + wx.CLRP_SHOW_LABEL Shows the colour in HTML form (AABBCC) as the + colour button label (instead of no label at all). + ====================== ============================================ + +Events +------ + ======================== ========================================== + EVT_COLOURPICKER_CHANGED The user changed the colour selected in the + control either using the button or using the + text control (see wx.CLRP_USE_TEXTCTRL; note + that in this case the event is fired only if + the user's input is valid, i.e. recognizable). + ======================== ========================================== +"); + +class wxColourPickerCtrl : public wxPickerBase +{ +public: + %pythonAppend wxColourPickerCtrl "self._setOORInfo(self)" + %pythonAppend wxColourPickerCtrl() "" + + wxColourPickerCtrl(wxWindow *parent, wxWindowID id=-1, + const wxColour& col = *wxBLACK, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxCLRP_DEFAULT_STYLE, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxPyColourPickerCtrlNameStr); + %RenameCtor(PreColourPickerCtrl, wxColourPickerCtrl()); + + bool Create(wxWindow *parent, wxWindowID id, + const wxColour& col = *wxBLACK, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxCLRP_DEFAULT_STYLE, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxPyColourPickerCtrlNameStr); + + + DocDeclStr( + wxColour , GetColour() const, + "Returns the currently selected colour.", ""); + + + DocDeclStr( + void , SetColour(const wxColour& col), + "Set the displayed colour.", ""); + +}; + + + +%constant wxEventType wxEVT_COMMAND_COLOURPICKER_CHANGED; +%pythoncode { + EVT_COLOURPICKER_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_COLOURPICKER_CHANGED, 1 ) +} + +class wxColourPickerEvent : public wxCommandEvent +{ +public: + wxColourPickerEvent(wxObject *generator, int id, const wxColour &col); + + wxColour GetColour() const; + void SetColour(const wxColour &c); +}; + + +//--------------------------------------------------------------------------- +%newgroup + +MAKE_CONST_WXSTRING(FilePickerCtrlNameStr); +MAKE_CONST_WXSTRING(FileSelectorPromptStr); +MAKE_CONST_WXSTRING(DirPickerCtrlNameStr); +MAKE_CONST_WXSTRING(DirSelectorPromptStr); +MAKE_CONST_WXSTRING(FileSelectorDefaultWildcardStr); + + +enum { + wxFLP_OPEN, + wxFLP_SAVE, + wxFLP_OVERWRITE_PROMPT, + wxFLP_FILE_MUST_EXIST, + wxFLP_CHANGE_DIR, + wxDIRP_DIR_MUST_EXIST, + wxDIRP_CHANGE_DIR, + + wxFLP_USE_TEXTCTRL, + wxFLP_DEFAULT_STYLE, + + wxDIRP_USE_TEXTCTRL, + wxDIRP_DEFAULT_STYLE, +}; + + + +MustHaveApp(wxFilePickerCtrl); +DocStr(wxFilePickerCtrl, + "", ""); + +class wxFilePickerCtrl : public wxPickerBase +{ +public: + %pythonAppend wxFilePickerCtrl "self._setOORInfo(self)" + %pythonAppend wxFilePickerCtrl() "" + + wxFilePickerCtrl(wxWindow *parent, + wxWindowID id=-1, + const wxString& path = wxPyEmptyString, + const wxString& message = wxPyFileSelectorPromptStr, + const wxString& wildcard = wxPyFileSelectorDefaultWildcardStr, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxFLP_DEFAULT_STYLE, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxPyFilePickerCtrlNameStr); + %RenameCtor(PreFilePickerCtrl, wxFilePickerCtrl()); + + bool Create(wxWindow *parent, + wxWindowID id=-1, + const wxString& path = wxPyEmptyString, + const wxString& message = wxPyFileSelectorPromptStr, + const wxString& wildcard = wxPyFileSelectorDefaultWildcardStr, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxFLP_DEFAULT_STYLE, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxPyFilePickerCtrlNameStr); + + wxString GetPath() const; + void SetPath(const wxString &str); + +}; + + + + +MustHaveApp(wxDirPickerCtrl); +DocStr(wxDirPickerCtrl, + "", ""); + +class wxDirPickerCtrl : public wxPickerBase +{ +public: + %pythonAppend wxDirPickerCtrl "self._setOORInfo(self)" + %pythonAppend wxDirPickerCtrl() "" + + wxDirPickerCtrl(wxWindow *parent, wxWindowID id=-1, + const wxString& path = wxPyEmptyString, + const wxString& message = wxPyDirSelectorPromptStr, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxDIRP_DEFAULT_STYLE, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxPyDirPickerCtrlNameStr); + %RenameCtor(PreDirPickerCtrl, wxDirPickerCtrl()); + + bool Create(wxWindow *parent, wxWindowID id=-1, + const wxString& path = wxPyEmptyString, + const wxString& message = wxPyDirSelectorPromptStr, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxDIRP_DEFAULT_STYLE, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxPyDirPickerCtrlNameStr); + + wxString GetPath() const; + void SetPath(const wxString &str); +}; + + +%constant wxEventType wxEVT_COMMAND_FILEPICKER_CHANGED; +%constant wxEventType wxEVT_COMMAND_DIRPICKER_CHANGED; + +%pythoncode { +EVT_FILEPICKER_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_FILEPICKER_CHANGED, 1 ) +EVT_DIRPICKER_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_DIRPICKER_CHANGED, 1 ) +} + +class wxFileDirPickerEvent : public wxCommandEvent +{ +public: + wxFileDirPickerEvent(wxEventType type, wxObject *generator, int id, const wxString &path); + + wxString GetPath() const { return m_path; } + void SetPath(const wxString &p) { m_path = p; } +}; + + +//--------------------------------------------------------------------------- +%newgroup + +MAKE_CONST_WXSTRING(FontPickerCtrlNameStr); + +enum { + wxFNTP_FONTDESC_AS_LABEL, + wxFNTP_USEFONT_FOR_LABEL, + wxFNTP_USE_TEXTCTRL, + wxFNTP_DEFAULT_STYLE, +}; + + +MustHaveApp(wxFontPickerCtrl); +DocStr(wxFontPickerCtrl, + "", ""); + + +class wxFontPickerCtrl : public wxPickerBase +{ +public: + %pythonAppend wxFontPickerCtrl "self._setOORInfo(self)" + %pythonAppend wxFontPickerCtrl() "" + + + wxFontPickerCtrl(wxWindow *parent, + wxWindowID id=-1, + const wxFont& initial = *wxNORMAL_FONT, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxFNTP_DEFAULT_STYLE, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxPyFontPickerCtrlNameStr); + %RenameCtor(PreFontPickerCtrl, wxFontPickerCtrl()); + + bool Create(wxWindow *parent, + wxWindowID id=-1, + const wxFont& initial = *wxNORMAL_FONT, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxFNTP_DEFAULT_STYLE, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxPyFontPickerCtrlNameStr); + + + // get the font chosen + wxFont GetSelectedFont() const; + + // sets currently displayed font + void SetSelectedFont(const wxFont& f); + + // set/get the max pointsize + void SetMaxPointSize(unsigned int max); + unsigned int GetMaxPointSize() const; +}; + + +%constant wxEventType wxEVT_COMMAND_FONTPICKER_CHANGED; + +%pythoncode { +EVT_FONTPICKER_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_FONTPICKER_CHANGED, 1 ) +} + + +class wxFontPickerEvent : public wxCommandEvent +{ +public: + wxFontPickerEvent(wxObject *generator, int id, const wxFont &f); + + wxFont GetFont() const; + void SetFont(const wxFont &c); +}; + +//--------------------------------------------------------------------------- diff --git a/wxPython/src/controls.i b/wxPython/src/controls.i index ef34a9202a..f508c2c09a 100644 --- a/wxPython/src/controls.i +++ b/wxPython/src/controls.i @@ -60,7 +60,7 @@ MAKE_CONST_WXSTRING_NOSWIG(ControlNameStr); %include _dragimg.i %include _datectrl.i %include _hyperlink.i - +%include _picker.i //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- -- 2.45.2