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

##--------------------------------------#######
#        Proprietes de la feuille             #
##--------------------------------------#######
#    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 *





class ProprietesDescription(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        self.parent = parent
        self.feuille = parent.feuille
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.infos = {}



        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(wx.StaticText(self, -1, u"Titre : "), 0, wx.ALL, 5)
        self.titre = wx.TextCtrl(self, value = self.feuille.infos["titre"], size=wx.Size(300, -1))
        self.Bind(wx.EVT_TEXT, self.EvtTitre, self.titre)
        sizer.Add(self.titre, 0, wx.ALL|wx.ALIGN_RIGHT, 5)
        self.sizer.Add(sizer, 1, wx.ALL, 5)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(wx.StaticText(self, -1, u"Auteur : "), 0, wx.ALL, 5)
        self.auteur = wx.TextCtrl(self, value = self.feuille.infos["auteur"], size=wx.Size(300, -1))
        self.Bind(wx.EVT_TEXT, self.EvtAuteur, self.auteur)
        sizer.Add(self.auteur, 0, wx.ALL, 5)
        self.sizer.Add(sizer, 0, wx.ALL, 5)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(wx.StaticText(self, -1, u"Version : "), 0, wx.ALL, 5)
        self.version = wx.TextCtrl(self, value = self.feuille.infos["version"], size=wx.Size(300, -1))
        self.Bind(wx.EVT_TEXT, self.EvtVersion, self.version)
        sizer.Add(self.version, 0, wx.ALL, 5)
        self.sizer.Add(sizer, 0, wx.ALL, 5)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(wx.StaticText(self, -1, u"Resumé : "), 0, wx.ALL, 5)
        self.resume = wx.TextCtrl(self, value = self.feuille.infos["resume"], size=wx.Size(300, 50), style=wx.TE_MULTILINE)
        self.Bind(wx.EVT_TEXT, self.EvtResume, self.resume)
        sizer.Add(self.resume, 0, wx.ALL, 5)
        self.sizer.Add(sizer, 0, wx.ALL, 5)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(wx.StaticText(self, -1, u"Notes : "), 0, wx.ALL, 5)
        self.notes = wx.TextCtrl(self, value = self.feuille.infos["notes"], size=wx.Size(300, 100), style=wx.TE_MULTILINE)
        self.Bind(wx.EVT_TEXT, self.EvtNotes, self.notes)
        sizer.Add(self.notes, 0, wx.ALL, 5)
        self.sizer.Add(sizer, 0, wx.ALL, 5)

        boutons = wx.BoxSizer(wx.HORIZONTAL)
        ok = wx.Button(self, wx.ID_OK)
        ok.Bind(wx.EVT_BUTTON, self.EvtOk)
        appliquer = wx.Button(self, label = u"Appliquer")
        appliquer.Bind(wx.EVT_BUTTON, self.EvtAppliquer)
        effacer = wx.Button(self, label = u"Effacer")
        effacer.Bind(wx.EVT_BUTTON, self.EvtEffacer)
        annuler = wx.Button(self, label = u"Annuler")
        annuler.Bind(wx.EVT_BUTTON, self.EvtAnnuler)

        boutons.Add(ok, 0, wx.ALL, 5)
        boutons.Add(appliquer, 0, wx.ALL, 5)
        boutons.Add(effacer, 0, wx.ALL, 5)
        boutons.Add(annuler, 0, wx.ALL, 5)
        self.sizer.Add(boutons, 0, wx.ALL, 5)


        self.SetSizerAndFit(self.sizer)
        self.parent.parent.dim1 = self.sizer.CalcMin().Get()


    def EvtTitre(self, event):
        self.infos["titre"] = event.GetString()

    def EvtAuteur(self, event):
        self.infos["auteur"] = event.GetString()

    def EvtVersion(self, event):
        self.infos["version"] = event.GetString()

    def EvtResume(self, event):
        self.infos["resume"] = event.GetString()

    def EvtNotes(self, event):
        self.infos["notes"] = event.GetString()


    def EvtOk(self, event):
        self.EvtAppliquer(event)
        self.EvtAnnuler(event)

    def EvtAppliquer(self, event):
        self.feuille.infos.update(self.infos)
        if self.infos:
            self.feuille.sauvegarde["modifie"] = True
        self.parent.parent.panel.rafraichir_titre()

    def EvtEffacer(self, event):
        self.titre.SetValue("")
        self.auteur.SetValue("")
        self.version.SetValue("")
        self.resume.SetValue("")
        self.notes.SetValue("")

    def EvtAnnuler(self, event):
        self.parent.parent.Close() # fermeture de la frame



class ProprietesStatistiques(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        self.parent = parent
        self.feuille = parent.feuille

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(wx.StaticText(self, -1, u"Informations sur " + unicode2(self.feuille.nom) + " :"), 0, wx.ALL, 8)
        self.sizer.Add(wx.StaticText(self, -1, u"Date de création :  " + unicode2(self.feuille.infos["creation"])), 0, wx.ALL, 8)
        self.sizer.Add(wx.StaticText(self, -1, u"Dernière modification :  " + unicode2(self.feuille.infos["modification"])), 0, wx.ALL, 8)
        self.sizer.Add(wx.StaticText(self, -1, u"Nombre d'objets :  " + str(len(self.feuille.liste_objets(True)))), 0, wx.ALL, 8)
        self.SetSizerAndFit(self.sizer)
        self.parent.parent.dim2 = self.sizer.CalcMin().Get()



class OngletsProprietesFeuille(wx.Notebook):
    def __init__(self, parent):
        style = wx.NB_TOP
        self.parent = parent
        self.feuille = parent.feuille
        wx.Notebook.__init__(self, parent)
        self.description = ProprietesDescription(self)
        self.AddPage(self.description, u"Description")
        self.statistiques = ProprietesStatistiques(self)
        self.AddPage(self.statistiques, u"Statistiques")












class ProprietesFeuille(wx.MiniFrame):
    def __init__(self, parent, feuille):
        self.parent = parent
        self.feuille = feuille
        self.fenetre_principale = self
        while hasattr(self.fenetre_principale, "parent"): # detection de la fenetre principale de WxGeometrie.
            self.fenetre_principale = self.fenetre_principale.parent
        self.panel = self.fenetre_principale.onglets.actuel()
        wx.MiniFrame.__init__(self, parent, -1, u"Propriétés de " + unicode2(self.feuille.nom), style=wx.DEFAULT_FRAME_STYLE | wx.TINY_CAPTION_HORIZ)
        self.onglets = OngletsProprietesFeuille(self)
        self.SetSize(wx.Size(*(max(dimensions) + 50 for dimensions in zip(self.dim1, self.dim2))))




