"""Subclass of Preferences, which is generated by wxFormBuilder."""

import wx, wxx, app
import app.proCxxGUI as gui
from  ctx import theContext as context


# Implementing Preferences
class PreferencesDialog(app.Preferences):
    """
    This dialog is used for setup of common preferences.
    """
    @wxx.SetInfo(__doc__)
    def __init__(self, parent):
        """Initialization"""
        super(PreferencesDialog, self).__init__(parent)
        self._fontPane = gui.FontPreferences(self.m_auinotebook3)
        if wx.__version__ >= '3.0.0.0':
            self.m_auinotebook3.AddPage(self._fontPane, u"Fonts", False, wx.wx.NOT_FOUND)
        else:
            self.m_auinotebook3.AddPage(self._fontPane, u"Fonts", False, wx.NullBitmap)
        df = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
        dfs = self.GetFontString(df)
        self._config = context.config
        dfs = self._config.Read("config/defaultFont", dfs)
        self._font = self.GetStringFont(dfs)

    def GetFontString(self, font):
        """Get info about current font"""
        return font.GetNativeFontInfo().ToString()

    def GetStringFont(self, string):
        """Get info current font"""
        f = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
        f.SetNativeFontInfoFromString(string)
        return f

    # Handlers for Preferences events.
    def OnInitDialog(self, event):
        """Dialog initialization"""
        self._fontPane.m_fontPicker.SetSelectedFont(self._font)
        # TODO: Implement OnInitDialog
        pass

    def OnOK(self, event):
        """OnOK handler"""
        dfs = self.GetFontString(self._fontPane.m_fontPicker.GetSelectedFont())
        self._config.Write("config/defaultFont", dfs)
        self._config.Flush()
        self.EndModal(wx.ID_OK)


