# -*- coding: iso-8859-1 -*-

# Inclusion des librairies standards et spécifiques
import wx
from base.scicalc_debug import *
import scicalc_param as param

#------------------------------------------------------------------------------
class MyConfigScreen(object):
  """
  Create a configuration dialog.
  """
  #----------------------------------------------
  def __init__(self, parent):
    self.parent = parent
    self.titre = parent.__titre__

    self.dialog = wx.Dialog(self.parent, -1, "Configuration")

  #----------------------------------------------
  def show(self):
    param.loadConfig()

    self.dialog.SetBackgroundColour(wx.WHITE)

    panel = wx.Panel(self.dialog, -1)
    panel.SetBackgroundColour(wx.WHITE)

    buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
    btnOK = wx.Button(panel, wx.ID_OK, " Valider ")
    btnOK.SetHelpText("Enregistrer les modifications.")
    btnOK.SetDefault()
    btnCancel = wx.Button(panel, wx.ID_CANCEL, " Annuler ")
    btnCancel.SetHelpText("Quitter sans rien changer.")

    buttonSizer.Add(btnOK, 0, wx.ALL | wx.ALIGN_CENTRE, 5)
    buttonSizer.Add(btnCancel, 0, wx.ALL | wx.ALIGN_CENTRE, 5)

    panelSizer = wx.BoxSizer(wx.VERTICAL)
    cb1 = wx.CheckBox(panel, -1, "Mode debug")
    cb2 = wx.CheckBox(panel, -1, "Calcul exact (fractions)")
    cb1.SetValue(param.debug)
    cb2.SetValue(param.fraction)

    panelSizer.AddMany( [cb1, (10, 10), cb2, (10, 10)] )
    panelSizer.Add(buttonSizer, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)

    panel.SetAutoLayout(True)
    panel.SetSizer(panelSizer)
    panelSizer.Fit(panel)

    topSizer = wx.BoxSizer(wx.HORIZONTAL)
    topSizer.Add(panel, 0, wx.ALL, 10)

    self.dialog.SetAutoLayout(True)
    self.dialog.SetSizer(topSizer)
    topSizer.Fit(self.dialog)

    self.dialog.Centre()

    btn = self.dialog.ShowModal()
    if btn == wx.ID_OK:
      config = {'debug': cb1.GetValue(), 'fraction': cb2.GetValue()}
      param.saveConfig(config)

    self.dialog.Destroy()
