# -*- coding: iso-8859-1 -*- # Copyright 20003 - 2008: Julien Bourdaillet (julien.bourdaillet@lip6.fr), Jean-Gabriel Ganascia (jean-gabriel.ganascia@lip6.fr) # This file is part of MEDITE. # # MEDITE 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. # # MEDITE 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 Foobar; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #---------------------------------------------------------------------------- # Nom: MainPanel.py # Objet: Classe correspondant au panel principal de l'interface medite #---------------------------------------------------------------------------- #from wxPython.wx import * #from wx import Panel #from wxPython.stc import * import wx import wx.stc from Utile.constantesGUI import * from GUI.Legende import * from GUI.Parametres import * import traceback import FMPanel import MediteAppli.synthetic #from wxPython.lib.rcsizer import RowColSizer #from wxPython.lib.grids import wxGridSizer, wxFlexGridSizer import __main__ #---------------------------------------------------------------------------- class MainPanel(wx.Notebook): """ Notebook gérant les différents panels autour d'une comparaison """ def __init__(self, parent, planTravail): wx.Notebook.__init__(self, parent, -1) self.planTravail = planTravail compPanel = ComparaisonPanel(self, self.planTravail) self.InsertPage(0, compPanel, "Comparaison", True) #panel de comparaison en position 0 #self.SetClientSize(self.GetChildren()[0].GetSize()) #self.SetBestFittingSize(wx.Size(900, 700)) self.Refresh() def getComparaisonPanel(self): """Renvoie le panel de comparaison """ return self.GetPage(0) def isTreePanel(self): return False def getTitre(self): return self.getComparaisonPanel().getTitre() def setTitre(self, titre): self.getComparaisonPanel().setTitre(titre) def addStatPanel(self,frequencyMatrix,textMatrix): """ Ajoute des pages avec les panels de stat pre: isinstance(frequencyMatrix,MediteAppli.Synthetic.TagFrequencyMatrix) isinstance(frequencyMatrix,MediteAppli.Synthetic.TextFrequencyMatrix) """ fmPanelHisto = FMPanel.FMPanelHisto(self,frequencyMatrix) self.AddPage(fmPanelHisto, u"Histogrammes", True) fmPanelCam = FMPanel.FMPanelCamembert(self,frequencyMatrix) self.AddPage(fmPanelCam, u"Etiquetage", True) fm2 = MediteAppli.synthetic.TagFrequencyMatrix2(frequencyMatrix) fmPanelCam2 = FMPanel.FMPanelCamembert2(self,fm2) self.AddPage(fmPanelCam2, u"Etiquetage2", True) fm3 = MediteAppli.synthetic.TagFrequencyMatrix3(frequencyMatrix) fmPanelCam3 = FMPanel.FMPanelCamembert3(self,fm3) self.AddPage(fmPanelCam3, u"Etiquetage3", True) fmPanelCam4 = FMPanel.FMPanelCamembert4(self,textMatrix) self.AddPage(fmPanelCam4, u"Etiquetage4", True) class ComparaisonPanel2(wx.Panel): """ Classe du panel principal permettant d'afficher les informations du dossier genetique courant les deux fenetres des états source et cible, et les fenetres transformations et commentaire """ def __init__(self, parent, planTravail): wx.Panel.__init__(self, parent, -1) self.planTravail = planTravail self.initialised = False self.remainingSpace = wx.Panel(self, -1, style=wx.SUNKEN_BORDER) self.fenetreMedite = parent.GetParent().GetParent() w,h = self.fenetreMedite.GetSize() w2 = (w/2)-10 ## line = wxStaticLine(self, -1, pos = wx.Point(0,0)) # Fenetre d informations du dossier genetique charge infoDGWin = wx.SashLayoutWindow(self, ID_WINDOW_TOP, wx.DefaultPosition, wx.Size(300, 200), wx.NO_BORDER|wx.SW_3DSASH) infoDGWin.SetDefaultSize(wx.Size(1000, 50)) infoDGWin.SetMinimumSizeY(50) infoDGWin.SetOrientation(wx.LAYOUT_HORIZONTAL) infoDGWin.SetAlignment(wx.LAYOUT_TOP) infoDGWin.SetSashVisible(wx.SASH_BOTTOM, True) fe = wx.FontEnumerator() fe.EnumerateFacenames() listFont = fe.GetFacenames() listFont.sort() s1 = wx.StaticText(self, -1, "Police : ", (150, 10)) self.lbFont = wx.ListBox(self, -1, wx.DefaultPosition, (180, 10), listFont, wx.LB_SINGLE) self.Bind(wx.EVT_LISTBOX, self.OnSelectFont, id=self.lbFont.GetId()) self.textAuteur = wx.StaticText(infoDGWin, -1, "Auteur : ", (10, 10)) #nomAuteur = self.fenetreMedite.planTravail.getAuteur() nomAuteur = self.planTravail.getAuteur() if nomAuteur == '': ecrireA = u"DG Non Charg\xe9" else: ecrireA = nomAuteur ## ecrireA = "DG Non Charg\xe9" self.textInfoAuteur= wx.StaticText(infoDGWin, -1, ecrireA, (70, 10)) #nomOeuvre = self.fenetreMedite.planTravail.getOeuvre() nomOeuvre = self.planTravail.getOeuvre() if nomOeuvre == '': ecrireO = u"DG Non Charg\xe9 " else: ecrireO = nomOeuvre ## ecrireO = "DG Non Charg\xe9 " self.textOeuvre = wx.StaticText(infoDGWin, -1, "Oeuvre : ",(w2+100, 10), (90, -1)) self.textInfoOeuvre= wx.StaticText(infoDGWin, -1,ecrireO,(w2+170, 10)) #nomVS = self.fenetreMedite.planTravail.getVersionSource() nomVS = self.planTravail.getVersionSource() self.textVS = wx.StaticText(infoDGWin, -1, "VS : ",(10, 30)) self.textInfoVersionS= wx.StaticText(infoDGWin, -1, nomVS, (35, 30)) #nomFS = self.fenetreMedite.planTravail.getEtatSource() nomFS = self.planTravail.getEtatSource() self.textFS = wx.StaticText(infoDGWin, -1, "FS : ",(200, 30)) self.textInfoEtatS= wx.StaticText(infoDGWin, -1, nomFS, (225, 30)) self.indiceS = wx.TextCtrl(infoDGWin, -1, "",wx.Point(w2-50,28),wx.Size(30,18),wx.TE_READONLY) #nomVC = self.fenetreMedite.planTravail.getVersionCible() nomVC = self.planTravail.getVersionCible() self.textVC = wx.StaticText(infoDGWin, -1, "VC : ",(w2+100, 30)) self.textInfoVersionC= wx.StaticText(infoDGWin, -1, nomVC, (w2+125, 30)) #nomFC = self.fenetreMedite.planTravail.getEtatCible() nomFC = self.planTravail.getEtatCible() self.textFC = wx.StaticText(infoDGWin, -1, "FC : ",(w2+300, 30)) self.textInfoEtatC= wx.StaticText(infoDGWin, -1, nomFC, (w2+325, 30)) self.indiceC = wx.TextCtrl(infoDGWin, -1, "",wx.Point(w2+20,28),wx.Size(30,18),wx.TE_READONLY) infoDGWin.SetAutoLayout(True) self.topWindow = infoDGWin # Fenetre avec un noteBook affichant les resultats d'une comparaison # le commentaire, la legende infoResultat = wx.SashLayoutWindow(self, ID_WINDOW_BOTTOM, wx.DefaultPosition, wx.Size(300, 200), wx.NO_BORDER|wx.SW_3D) infoResultat.SetDefaultSize(wx.Size(1000, 200)) infoResultat.SetOrientation(wx.LAYOUT_HORIZONTAL) infoResultat.SetAlignment(wx.LAYOUT_BOTTOM) infoResultat.SetSashVisible(wx.SASH_TOP, True) ID_NB = 6545 self.nb=wx.Notebook(infoResultat, ID_NB, style=wx.NB_BOTTOM) self.nb.SetBestFittingSize(wx.Size(1000, 200)) # transfo self.transformations=wx.TextCtrl(self.nb, -1, "", wx.DefaultPosition, wx.DefaultSize, wx.TE_MULTILINE|wx.TE_READONLY) self.nb.AddPage(self.transformations,"TRANSFORMATIONS") # comment self.commentaire=wx.TextCtrl(self.nb, -1, "", wx.DefaultPosition, wx.DefaultSize, wx.TE_MULTILINE)#|wx.TE_RICH2) self.nb.AddPage(self.commentaire,"COMMENTAIRE") # legende self.legende = PanelLegende(self.nb, self.fenetreMedite) self.nb.AddPage(self.legende,"LEGENDE") # Parametres self.param = PanelParametres(self.nb, self.fenetreMedite) self.nb.AddPage(self.param,"PARAMETRES") wx.EVT_NOTEBOOK_PAGE_CHANGING(self,ID_NB, self.OnNBPageChanging) self.bottomWindow = infoResultat self.bottomWindow.Refresh() # Fenetre affichant l'état source winLeft = wx.SashLayoutWindow(self, ID_WINDOW_LEFT, wx.DefaultPosition, wx.Size(200, 30), wx.NO_BORDER|wx.SW_3D) ## w2 correspond a la largeur/2 de la fenetre Medite winLeft.SetDefaultSize(wx.Size(w2, 1000)) winLeft.SetOrientation(wx.LAYOUT_VERTICAL) winLeft.SetAlignment(wx.LAYOUT_LEFT) winLeft.SetSashVisible(wx.SASH_RIGHT, True) winLeft.SetExtraBorderSize(0) self.textWindowLeft = wx.TextCtrl(winLeft, -1, "", wx.DefaultPosition, wx.DefaultSize, wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_RICH2) self.textWindowLeft.SetValue(u"état source") wx.EVT_LEFT_DOWN(self.textWindowLeft, self.indiceBlocLeft) #EVT_LEFT_UP(self.textWindowLeft, self.selectBlocLeft) self.leftWindow = winLeft # Fenetre affichant l'état cible winRight = wx.SashLayoutWindow(self, ID_WINDOW_RIGHT, wx.DefaultPosition, wx.Size(200, 30), wx.NO_BORDER|wx.SW_3D) winRight.SetDefaultSize(wx.Size(w2, 1000)) winRight.SetOrientation(wx.LAYOUT_VERTICAL) winRight.SetAlignment(wx.LAYOUT_RIGHT) winRight.SetSashVisible(wx.SASH_LEFT, True) winRight.SetExtraBorderSize(0) self.textWindowRight = wx.TextCtrl(winRight, -1, "", wx.DefaultPosition, wx.DefaultSize, wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_RICH2) self.textWindowRight.SetValue(u"état cible") wx.EVT_LEFT_DOWN(self.textWindowRight, self.indiceBlocRight) #EVT_LEFT_UP(self.textWindowRight, self.selectBlocRight) self.rightWindow = winRight wx.EVT_SASH_DRAGGED_RANGE(self, ID_WINDOW_TOP,ID_WINDOW_BOTTOM, self.OnSashDrag) wx.EVT_SIZE(self, self.OnSize) def getTitre(self): return self.planTravail.getEtatSource()+"-"+self.planTravail.getEtatCible() def setTitre(self, titre): self.SetTitle(titre) def OnSelectFont(self,event): face = self.lbFont.GetStringSelection() font = wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, face) #self.txt.SetLabel(face) self.textWindowLeft.SetFont(font) self.textWindowRight.SetFont(font) self.transformations.SetFont(font) self.commentaire.SetFont(font) def OnNBPageChanging(self,event): self.legende.bInser.SetBackgroundColour(self.legende.coulInsert) self.legende.bSupp.SetBackgroundColour(self.legende.coulSupp) self.legende.bRemp.SetBackgroundColour(self.legende.coulRemp) #Methode qui permet de redimensionner les fenetres des états source et cible def OnSashDrag(self, event): if event.GetDragStatus() == wx.SASH_STATUS_OUT_OF_RANGE: return eID = event.GetId() if eID == ID_WINDOW_TOP: self.topWindow.SetDefaultSize(wx.Size(1000, event.GetDragRect().height)) elif eID == ID_WINDOW_LEFT: self.leftWindow.SetDefaultSize(wx.Size(event.GetDragRect().width, 1000)) elif eID == ID_WINDOW_RIGHT : self.rightWindow.SetDefaultSize(wx.Size(event.GetDragRect().width, 1000)) elif eID == ID_WINDOW_BOTTOM: self.bottomWindow.SetDefaultSize(wx.Size(1000, event.GetDragRect().height)) wx.LayoutAlgorithm().LayoutWindow(self, self.remainingSpace) self.remainingSpace.Refresh() # Methode qui redimensionne la fenetre def OnSize(self, event): wx.LayoutAlgorithm().LayoutWindow(self)#, self.remainingSpace) w,h=event.GetSize() self.size(w) def sizeF(self): w,h=self.fenetreMedite.GetSize() self.size(w) def size(self,w): width=w/2 self.leftWindow.SetDefaultSize(wx.Size(width, 1000)) self.rightWindow.SetDefaultSize(wx.Size(w-width, 1000)) #self.indiceS.SetPosition((width-55,28)) #self.indiceC.SetPosition((width+15,28)) #self.textOeuvre.setPosition((w/4,10)) #self.textInfoOeuvre.SetPosition((w/4+70,10)) # Methodes qui gere les clics dans les fenetres source et cible def indiceBlocRight(self,evt): if self.transformations.GetValue()!='': evt.Skip() wx.CallAfter(self.positionRight, evt) def indiceBlocLeft(self,evt): if self.transformations.GetValue()!='': evt.Skip() wx.CallAfter(self.positionLeft, evt) ## Methodes qui gère les correspondances entre blocs et entre déplacements def positionLeft(self, evt): try: ip = self.textWindowLeft.GetInsertionPoint() transfo = self.resultatTransfoAffichageOnly depl = self.indiceSourceToPaireBlocsDepl(ip,transfo) if depl != None: self.textWindowRight.ShowPosition(depl) self.textWindowLeft.ShowPosition(ip) return numBloc,posDansBloc = self.numeroBlocsCommunsSource(ip,transfo) if numBloc != None : self.indiceS.SetValue("%s"%(numBloc+1)) self.indiceC.SetValue("%s"%(numBloc+1)) indic = self.numBlocCibleToIndice(numBloc,transfo) self.textWindowLeft.ShowPosition(ip) self.textWindowRight.ShowPosition(indic+posDansBloc) # self.textWindowLeft.SetSelection(ip-10,ip+10) # self.textWindowRight.SetSelection(indic+posDansBloc-10,indic+posDansBloc+10) else: self.indiceS.SetValue('') self.indiceC.SetValue('') except Exception,e1: sys.stderr.write(str(e1)) traceback.print_exc() sys.stderr.flush() def positionRight(self, evt): try: ip = self.textWindowRight.GetInsertionPoint() transfo = self.resultatTransfoAffichageOnly depl = self.indiceCibleToPaireBlocsDepl(ip,transfo) if depl != None: self.textWindowLeft.ShowPosition(depl) self.textWindowRight.ShowPosition(ip) return numBloc,posDansBloc = self.numeroBlocsCommunsCible(ip,transfo) if numBloc != None : self.indiceC.SetValue("%s"%(numBloc+1)) self.indiceS.SetValue("%s"%(numBloc+1)) indic = self.numBlocSourceToIndice(numBloc,transfo) self.textWindowRight.ShowPosition(ip) self.textWindowLeft.ShowPosition(indic+posDansBloc) # self.textWindowRight.SetSelection(ip-10,ip+10) # self.textWindowLeft.SetSelection(indic+posDansBloc-10,indic+posDansBloc+10) else: self.indiceC.SetValue('') self.indiceS.SetValue('') except Exception,e1: sys.stderr.write(str(e1)) traceback.print_exc() sys.stderr.flush() ########################################################################## ## Methodes qui gere les evenements de selection dans l'une des fenetres## ########################################################################## def selectBlocLeft(self, evt): deb,fin = self.textWindowLeft.GetSelection() if deb >= fin : self.fenetreMedite.disableMenuTransformations(evt) else : self.fenetreMedite.enableMenuTransformationsLeft(evt) ## #print 'select Left !!!\n' ## #print self.resultatTransfo.getListeRemplacements() ## if self.transformations.GetValue()!='': ## print self.textWindowLeft.GetSelection() ## start, end = self.textWindowLeft.GetSelection() ## print start ## transfo = self.resultatTransfoAffichageOnly ## blocsDepl = transfo.getListeDeplacements() ## textes = transfo.getTextesConcatenes() ## #####test################### ## #transfo.changerInsertions() ## #s=transfo.getListeInsertions() ## #print s ## ############################# ## nbB = len(blocsDepl)/2 ## selec = textes[start:end] ## #print selec ## for X in blocsDepl[nbB:] : ## if textes[X[0]:X[1]] == selec: ## print 'selection source faite' ## indic = X[0]-transfo.getLgSource() ## self.textWindowRight.ShowPosition(indic) ## self.textWindowLeft.ShowPosition(X[0]) ## return ## def selectBlocRight(self, evt): deb,fin = self.textWindowRight.GetSelection() if deb >= fin : self.fenetreMedite.disableMenuTransformations(evt) else : self.fenetreMedite.enableMenuTransformationsRight(evt) ## #print 'select Right !!!\n' ## if self.transformations.GetValue()!='': ## start, end = self.textWindowRight.GetSelection() ## transfo = self.resultatTransfoAffichageOnly ## blocsDepl = transfo.getListeDeplacements() ## textes = transfo.getTextesConcatenes() ## lgTextS = transfo.getLgSource() ## nbB = len(blocsDepl)/2 ## selec = textes[start+lgTextS:end+lgTextS] ## print selec ## lgSelect = len(selec) ## s = start+lgTextS ## for X in blocsDepl[0:nbB] : ## if textes[X[0]:X[1]] == selec: ## print 'selection cible faite' ## indic = X[0] ## self.textWindowLeft.ShowPosition(indic) ## self.textWindowRight.ShowPosition(X[0]-transfo.getLgSource()) ## return ############################################################################################# def numeroBlocsCommunsSource(self, indice, pTransfo): #sys.stderr.write("indice="+str(indice)+"\n") n = 0 tableau = pTransfo.getBlocsCommuns() for cple in tableau[:len(tableau)/2] : #sys.stderr.write("cple="+str(cple)+"\n") if indice>=cple[0] and indice=cple[0] and indiceC= b1[0] and indice= b2[0] and indice+lgTextS