wx.FontPickerCtrl allows for setting font color, but how to get it?

Hi,

wx.FontPickerCtrl allows for the user to set the font and its color,
but I can't seem to find a way to find out what color the user has
picked. The API of the FontPickerCtrl doesn't contain a
GetSelectedColor or something like that, neither do the base classes
of FontPickerCtrl. What am I missing?

Thanks, Frank

When using the wx.FontDialog you get access to the colour from the wx.FontData, but it looks like the picker doesn't give you access to that. Sounds like it's time for a feature request ticket at wxTrac.

···

On 1/7/10 1:31 PM, Frank Niessink wrote:

Hi,

wx.FontPickerCtrl allows for the user to set the font and its color,
but I can't seem to find a way to find out what color the user has
picked. The API of the FontPickerCtrl doesn't contain a
GetSelectedColor or something like that, neither do the base classes
of FontPickerCtrl. What am I missing?

--
Robin Dunn
Software Craftsman

This is one of the reasons I believe we should replace wxFontPicker
with Julian Smart's wxFontSelectorCtrl, which looks more 'modern' and
returns a wxFontData from which you can get the font color /
underline / strikethrough. For a C++ program where I used it I did
have to write custom code to serialize / deserialize all this to a
string. Maybe I whould ask Julian to incorporate this into his code so
users can save the font settings to a database / registry key easily.

···

On Jan 8, 7:38 am, Robin Dunn <ro...@alldunn.com> wrote:

On 1/7/10 1:31 PM, Frank Niessink wrote:

> Hi,

> wx.FontPickerCtrl allows for the user to set the font and its color,
> but I can't seem to find a way to find out what color the user has
> picked. The API of the FontPickerCtrl doesn't contain a
> GetSelectedColor or something like that, neither do the base classes
> of FontPickerCtrl. What am I missing?

When using the wx.FontDialog you get access to the colour from the
wx.FontData, but it looks like the picker doesn't give you access to
that. Sounds like it's time for a feature request ticket at wxTrac.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

I opened a bug report. Also, here's a simple work around in Python:

import wx

class FontPickerCtrl(wx.Button):
    def __init__(self, *args, **kwargs):
        self.font = kwargs.pop('font')
        self.colour = kwargs.pop('colour')
        super(FontPickerCtrl, self).__init__(*args, **kwargs)
        self.__updateButton()
        self.Bind(wx.EVT_BUTTON, self.onClick)

    def onClick(self, event):
        fontData = wx.FontData()
        fontData.SetInitialFont(self.font)
        fontData.SetColour(self.colour)
        dialog = wx.FontDialog(self, fontData)
        if wx.ID_OK == dialog.ShowModal():
            fontData = dialog.GetFontData()
            self.font = fontData.GetChosenFont()
            self.colour = fontData.GetColour()
            self.__updateButton()
            event = wx.FontPickerEvent(self, self.GetId(), self.font)
            self.GetEventHandler().ProcessEvent(event)

    def __updateButton(self):
        self.SetLabel(self.font.GetNativeFontInfoUserDesc())
        self.SetFont(self.font)
        self.SetForegroundColour(self.colour)

    def GetSelectedFont(self):
        return self.font

    def GetSelectedColour(self):
        return self.colour

    def SetColour(self, colour):
        self.colour = colour
        self.__updateButton()

Cheers, Frank

···

2010/1/8 Robin Dunn <robin@alldunn.com>:

On 1/7/10 1:31 PM, Frank Niessink wrote:

Hi,

wx.FontPickerCtrl allows for the user to set the font and its color,
but I can't seem to find a way to find out what color the user has
picked. The API of the FontPickerCtrl doesn't contain a
GetSelectedColor or something like that, neither do the base classes
of FontPickerCtrl. What am I missing?

When using the wx.FontDialog you get access to the colour from the
wx.FontData, but it looks like the picker doesn't give you access to that.
Sounds like it's time for a feature request ticket at wxTrac.