# -*- coding: iso-8859-1 -*-
from __future__ import division # 1/2 == .5 (par defaut, 1/2 == 0)

##--------------------------------------#######
#                 Fenetres                              #
##--------------------------------------#######
#    WxGeometrie
#    Dynamic geometry, graph plotter, and more for french mathematic teachers.
#    Copyright (C) 2005-2007  Nicolas Pourcelot
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

#version unicode


# importation des librairies classiques
from LIB import *

####################################################################################################

# Code de la feuille actuelle


class FenCode(wx.MiniFrame):
    def __init__(self, parent):
        wx.MiniFrame.__init__(self, parent, -1, u"Contenu interne de la feuille")
        self.parent = parent
        contenu = parent.onglet_actuel.feuille_actuelle.sauvegarder()
        self.texte = wx.TextCtrl(self, -1, contenu, size=(300, 10), style=wx.TE_MULTILINE)
        self.texte.Bind(wx.EVT_CHAR, self.EvtChar)
        self.texte.SetInsertionPointEnd()
        self.texte.SetFocus()


        tb = self.CreateToolBar( wx.TB_HORIZONTAL
                                 | wx.NO_BORDER
                                 | wx.TB_FLAT
                                 | wx.TB_TEXT )
        tb.AddSeparator()
        tb.AddSeparator()
        self.a = wx.Button(tb, -1, u"Executer - F5")
        tb.AddControl(self.a)
        tb.AddSeparator()
        tb.AddSeparator()
        self.b = wx.Button(tb, -1, u"Annuler - ESC")
        tb.AddControl(self.b)
        tb.Realize()

        self.Bind(wx.EVT_BUTTON, self.executer, self.a)
        self.Bind(wx.EVT_BUTTON, self.fermer, self.b)


    def EvtChar(self, event):
        key = event.GetKeyCode()
        if key == wx.WXK_ESCAPE: self.fermer()
        elif key == wx.WXK_F5: self.executer()
        else : event.Skip()

    def fermer(self, event = None):
        self.Close(True)

    def executer(self, event = None):
        # On exécute le code de la feuille éventuellement modifié
        self.parent.onglet_actuel.creer_feuille()
        self.parent.onglet_actuel.feuille_actuelle.charger(self.texte.GetValue())
        self.fermer()
