websiteWebsite
ekd EKD
Logiciel de post-production pour vidéo, image et audio

 

Browse the code

Revision log Information on the revision
Revision: 90 (differences)
Author: ekd
Log message: install_ekd_linux_admin.py

Rectification pour affichage des textes (encodage) avec accents et résolution d'un bug qui était passé innaperçu.
Change revision:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
#!/usr/bin/python
# -*- coding: utf-8 -*-
 
import os
from PyQt4.QtCore import SIGNAL, QFileInfo, Qt, QString
from PyQt4.QtGui import QWidget, QPushButton, QLineEdit, QHBoxLayout, QVBoxLayout, QGridLayout, QGroupBox, QIcon, QFrame, QFileDialog, QTabWidget, QLabel, QTextEdit, QRadioButton, QScrollArea
from moteur_modules_animation.mplayer import Mplayer, MetaMPlayer
from moteur_modules_common.EkdConfig import EkdConfig
from gui_modules_common.EkdWidgets import EkdAide
from gui_modules_common.EkdTamponIn import *
 
# On joue avec l'héritage
class Base(QWidget):
    """
        Module des cadres de l'onglet animation
    """
 
    Audio = 1
    Video = 2
 
    def __init__(self, boite='grid', nomReglage=None, nomSource=None, titre="None", parent=None):
        super(Base, self).__init__(parent)
        # Taille du widget mplayer
        self.tailleMplayer = (240,216)
 
        # Définition du titre
        self.Titre =  QLabel()
        self.setTitle(titre)
 
        # Définition des tabs
        #----------------------------------------------------------------
        self.Source =  QLabel("<h1>Source</h1>")
        self.Reglage =  QLabel("<h1>Reglage</h1>")
        self.Preview = QLabel("<h1>Preview</h1>")
        self.Logs = QLabel("<h1>Logs</h1>")
 
        self.tab = QTabWidget()
        self.scroll = QScrollArea()
        self.scroll.setWidget(self.tab)
        self.scroll.setWidgetResizable(True)
 
        self.connect(self.tab, SIGNAL("currentChanged (int)"), self.activateTab)
 
        # Definition du layout :
        #| Titre                            |
        # ----------------------------------
        #| tabOuvrir | tabReglage | ... |   |
        #|----------------------------------|
        #|...                               |
        #|----------------------------------|
        #|Aide|                   |Appliquer|
        #'----------------------------------'
        self.layout = QVBoxLayout(self)
        self.layout.addWidget(self.Titre)
        #self.layout.addWidget(self.tab)
        self.layout.addWidget(self.scroll)
        #----------------------------------------------------------------
 
        self.boutAide=QPushButton(_(u"Aide"))
        self.boutAide.setIcon(QIcon("Icones" + os.sep + "icone_aide_128.png"))
        self.connect(self.boutAide, SIGNAL("clicked()"), self.afficherAide)
 
        #self.tamponBut = QPushButton(QIcon("Icones"+os.sep+"icone_load_128.png"), _(u"Tampon test"))
        #self.connect(self.tamponBut, SIGNAL("clicked()"), self.tamponAction)
 
        # On ajoute des bouton pour forcer l'utilisateur à vérifier ses réglages
        self.Next = QPushButton(_(u"Réglages"))
        ####################################################################
        self.Next.setIcon(QIcon("Icones" + os.sep + "droite.png"))
        ####################################################################
        self.connect(self.Next, SIGNAL("clicked()"), self.next)
 
        self.boutApp=QPushButton(_(u"Appliquer"))
        self.boutApp.setIcon(QIcon("Icones" + os.sep + "icone_appliquer_128.png"))
        ## Le bouton doit toujours être désactivé à l'initialisation
        self.boutApp.setEnabled(False)
 
        self.connect(self.boutApp, SIGNAL("clicked()"), self.appliquer)
 
        # ligne de séparation juste au dessus des boutons
        ligne = QFrame()
        ligne.setFrameShape(QFrame.HLine)
        ligne.setFrameShadow(QFrame.Sunken)
        self.layout.addWidget(ligne)
        self.layout.addSpacing(-5)      # la ligne doit être plus près des boutons
 
        hbox=QHBoxLayout()
        hbox.addWidget(self.boutAide)
        #hbox.addWidget(self.tamponBut)
        hbox.addStretch()       # espace entre les 2 boutons
        hbox.addWidget(self.Next)
        hbox.addWidget(self.boutApp)
 
        self.layout.addLayout(hbox)
 
    def tamponAction(self) :
      """Fonction à définir dans chaque tableau pour importer les données du tampon"""
      print u"[DEBUG] Fonction tamponAction non implémentée dans le tableau ", self.idSection
 
    def setTitle(self, titre=_(u"Title")):
        titre=u"<h2>" + titre + u"</h2>"
        self.Titre.setText(titre)
 
    def add(self, objet, nom=_(u"Onglet")):
        self.tab.addTab(objet, nom)
 
    def activateTab(self, index):
        tabCount = self.tab.count()
        if 0 == index :
            self.Next.setText(_(u"Réglages"))
        elif ( tabCount - 1 ) == index :
            self.Next.setText(_(u"Recommencer"))
        elif (tabCount - 2) == index :
            self.Next.setText(_(u"Infos supplémentaires"))
        else:
            self.Next.setText(_(u"Suivant"))
 
    def next(self):
        tabCount = self.tab.count()
        index = self.tab.currentIndex()
        index = (index + 1) % tabCount
        self.tab.setCurrentIndex(index)
 
    #----------------
    # Meta-widgets
    #----------------
 
 
    def addSource(self, type, nomSource=None):
        """ Boîte de groupe : "Fichier vidéo source" """
        if type == Base.Video :
            if not nomSource: nomSource=_(u'Vidéo source')
            self.ligneEditionSource=QLineEdit()
            self.ligneEditionSource.setReadOnly(True)
            boutParcourir=QPushButton(_(u'Parcourir...'))
            boutParcourir.setIcon(QIcon("Icones/ouvrir.png"))
            self.connect(boutParcourir, SIGNAL("clicked()"), self.ouvrirSource)
 
            groupSource=QGroupBox(nomSource)
            hbox=QHBoxLayout(groupSource)
            hbox.addWidget(self.ligneEditionSource)
            hbox.addWidget(boutParcourir)
            self.Source = groupSource
            self.tabOuvrirVideo  = self.tab.addTab(self.Source, nomSource)
 
        else :
            if not nomSource: nomSource=_(u"Fichier audio source")
            self.ligneEditionSourceAudio=QLineEdit()
            self.ligneEditionSourceAudio.setReadOnly(True)
 
            boutParcourir=QPushButton(_(u'Parcourir...'))
            boutParcourir.setIcon(QIcon("Icones/ouvrir.png"))
            self.connect(boutParcourir, SIGNAL("clicked()"), self.ouvrirSource)
 
            groupSource=QGroupBox(nomSource)
            hbox=QHBoxLayout(groupSource)
            hbox.addWidget(self.ligneEditionSourceAudio)
            hbox.addWidget(boutParcourir)
            self.Source = groupSource
            self.tabOuvrirAudio = self.tab.addTab(self.Source, nomSource)
 
 
    def addReglage(self, boite='hbox', nomReglage = None):
        """ Boîte de groupe de réglage """
        if not nomReglage: nomReglage=_(u"Réglages")
        self.groupReglage=QGroupBox()
 
        if boite=='vbox':
            self.layoutReglage = QVBoxLayout(self.groupReglage)
        elif boite=='hbox':
            self.layoutReglage = QHBoxLayout(self.groupReglage)
        elif boite=='grid':
            self.layoutReglage = QGridLayout(self.groupReglage)
 
        self.Reglage = self.groupReglage
        self.add(self.Reglage, nomReglage)
 
 
 
    def addPreview(self, boite='vbox', nomPreview = None, light = False, mode = "Video"):
        # ----------------------------
        # Boite de groupe de mplayer
        # ----------------------------
        group=QGroupBox("")
        if nomPreview == None : nomPreview=_(u'Visionner vidéo')
        else : nomPreview=_(nomPreview)
        vboxMplayer = QVBoxLayout(group)
        if mode =="Video+Audio" :
            vidtitre = QLabel(_(u"Vidéo"))
            vidtitre.setAlignment(Qt.AlignHCenter)
            vboxMplayer.addWidget(vidtitre)
 
        self.mplayer=Mplayer(taille=(250, 225), choixWidget=(Mplayer.RATIO, Mplayer.PAS_PRECEDENT_SUIVANT,Mplayer.CURSEUR_SUR_UNE_LIGNE,Mplayer.PAS_PARCOURIR, Mplayer.LIST))
        ## On utilise la nouvelle interface de récupération des vidéos
        self.mplayer.listeVideos = []
        self.mplayer.setEnabled(False)
        hbox = QHBoxLayout()
        hbox.addStretch()
        hbox.addWidget(self.mplayer)
        hbox.addStretch()
        vboxMplayer.addLayout(hbox)
        hbox = QHBoxLayout()
        if not light :
            self.radioSource = QRadioButton(_(u"vidéo(s) source(s)"))
            self.radioSource.setChecked(True)
            self.radioSource.setEnabled(False)
            self.connect(self.radioSource, SIGNAL("toggled(bool)"), self.fctRadioSource)
            self.radioConvert = QRadioButton(_(u"vidéo(s) convertie(s)"))
            self.radioConvert.setEnabled(False)
            self.connect(self.radioConvert, SIGNAL("toggled(bool)"), self.fctRadioConvert)
            self.boutCompare = QPushButton(_(u"Comparateur de vidéos"))
            self.boutCompare.setEnabled(False)
 
            self.connect(self.boutCompare, SIGNAL("clicked()"), self.widget2Mplayer)
            hbox.addWidget(self.radioSource)
            hbox.addWidget(self.radioConvert)
            hbox.addWidget(self.boutCompare)
            if self.idSection == "animation_filtresvideo":
                self.boutApercu = QPushButton(_(u"Aperçu"))
                self.connect(self.boutApercu, SIGNAL("clicked()"), self.apercu)
                self.boutApercu.setEnabled(False)
                hbox.addWidget(self.boutApercu)
 
        if mode =="Video+Audio" :
            self.mplayerA=Mplayer(taille=(250, 225), choixWidget=(Mplayer.RATIO,Mplayer.PAS_PRECEDENT_SUIVANT,Mplayer.CURSEUR_SUR_UNE_LIGNE,Mplayer.PAS_PARCOURIR))
            self.mplayerA.setAudio(True)
            self.mplayerA.listeVideos = []
            self.mplayerA.setEnabled(False)
            hboxA = QHBoxLayout()
            hboxA.addStretch()
            hboxA.addWidget(self.mplayerA)
            hboxA.addStretch()
 
        hbox.setAlignment(Qt.AlignHCenter)
        vboxMplayer.addLayout(hbox)
        if mode =="Video+Audio" :
            audtitre = QLabel(_(u"Audio"))
            audtitre.setAlignment(Qt.AlignHCenter)
            vboxMplayer.addWidget(audtitre)
            vboxMplayer.addLayout(hboxA)
        vboxMplayer.addStretch()
        group.setAlignment(Qt.AlignHCenter)
        self.add(group, nomPreview)
 
    def addLog(self):
        self.Logs = QTextEdit()
        self.tabLog = self.add(self.Logs, _(u'Infos'))
 
 
 
    def infoLog(self, image=None, video=None, audio=None, sortie=None) :
        """Fonction pour la mise à jour des informations de log données à l'utilisateur en fin de process sur les données entrées, et le résultat du process"""
        if image != None :
            if type(image) == list :
                msgIm = _(u"<p>####################################<br># Images chargées<br>####################################</p>")
                for im in image :
                    msgIm += unicode(im)+u"<br>"
            else :
                msgIm = _(u"<p>####################################<br># Image chargée<br>####################################</p>")+unicode(image)+u"<br>"
        else :
            msgIm = u""
 
        if video != None :
            if type(video) == list :
                msgVid = _(u"<p>####################################<br># Vidéos chargées<br>####################################</p>")
                for vid in video :
                    msgVid += unicode(vid)+u"<br>"
            else :
                msgVid = _(u"<p>####################################<br># Vidéo chargée<br>####################################</p>")+unicode(video)+u"<br>"
        else :
            msgVid = u""
 
        if audio != None :
            if type(audio) == list :
                msgAu = _(u"<p>####################################<br># Fichiers audio chargés<br>####################################</p>")
                for au in audio :
                    msgAu += unicode(au)+u"<br>"
            else :
                msgAu = _(u"<p>####################################<br># Fichier audio chargé<br>####################################</p>")+unicode(audio)+u"<br>"
        else :
            msgAu = u""
 
        if sortie != None :
            if type(sortie) == list :
                msgOut = _(u"<p>####################################<br># Fichiers de sortie<br>####################################</p>")
                for out in sortie :
                    msgOut += unicode(out)+u"<br>"
            else :
                msgOut = _(u"<p>####################################<br># Fichier de sortie<br>####################################</p>")+unicode(sortie)+u"<br>"
        else :
            msgOut = _(u"<p>Sortie non définie ???</br>")
        messageLog = QString(msgIm+msgVid+msgAu+msgOut)
        self.Logs.setHtml(messageLog)
 
    def widget2Mplayer(self):
        """Boite de dialogue de comparaison de vidéos"""
 
        if type(self.chemin) == list :
            chemin = self.chemin
        else :
            chemin = [self.chemin]
 
        mplayerAvantConv=Mplayer(chemin, (350,262), (Mplayer.RATIO, Mplayer.PAS_PRECEDENT_SUIVANT,Mplayer.CURSEUR_SUR_UNE_LIGNE,Mplayer.PAS_PARCOURIR, Mplayer.LIST))
 
        # Widget-mplayer après encodage: lecture du fichier de sortie
 
        mplayerApresConv=Mplayer(self.lstFichiersSortie, (350,262), (Mplayer.RATIO, Mplayer.PAS_PRECEDENT_SUIVANT,Mplayer.CURSEUR_SUR_UNE_LIGNE,Mplayer.PAS_PARCOURIR, Mplayer.LIST))
 
        print "Affichage de la meta-barre mplayer"
        metaMPlayer = MetaMPlayer(mplayerAvantConv,mplayerApresConv)
        metaMPlayer.exec_()
 
    #---------------------
    # Fonctions communes
    #---------------------
 
    def fctRadioSource(self, bool=None):
        """"Communique la vidéo appropriée à mplayer"""
        if bool:
            self.mplayer.setVideos(self.chemin)
            self.mplayer.arretMPlayer()
            try :
                self.radioConvert.setChecked(False)
            except : None
 
    def fctRadioConvert(self, bool=None):
        """"Communique la vidéo résultat appropriée à mplayer"""
        if bool:
            self.mplayer.arretMPlayer()
            self.mplayer.setVideos(self.lstFichiersSortie)
            try :
                self.radioSource.setChecked(False)
            except : None
 
 
    def repSortieProv(self):
        """Répertoire sur lequel s'ouvrira la boite de dialogue de sauvegarde"""
        rep = os.path.dirname(unicode(self.chemin))
 
        if os.path.exists(rep): return rep
        else: return '~'
 
 
    def recupSources(self, nomEntree=None):
        """Récupère les fichiers sources vidéo via une boite de dialogue. Utilise et modifie les paramètres de configuration"""
 
        if not self.lstFichiersSource: listePleine = False
        else:
            listePleine = True
            fichier = self.lstFichiersSource[0]
            path = os.path.dirname(fichier)
 
        if listePleine and os.path.exists(path):
            repEntree = path
        else:
            try:
                repEntree = EkdConfig.get('general','video_input_path').decode("UTF8")
            except Exception, e:
                repEntree = '~'
                EkdConfig.set('general','video_input_path', repEntree.encode("UTF8"))
            if not os.path.exists(repEntree):
                repEntree = '~'
                EkdConfig.set('general','video_input_path', repEntree.encode("UTF8"))
 
        txt = _(u"Fichiers vidéo")
        if not nomEntree:
            liste=QFileDialog.getOpenFileNames(None, _(u"Ouvrir"), os.path.expanduser(repEntree),
                    "%s (*.avi *.mpg *.mpeg *.mjpeg *.flv *.mp4 *.h264 *.dv *.vob)\n*" %txt)
            liste = [unicode(i) for i in liste]
        else: # module séquentiel
            liste = nomEntree
 
        if len(liste)==0: return
        EkdConfig.set('general','video_input_path',os.path.dirname(liste[0]).encode("UTF8"))
 
        return liste
 
 
    def recupSourcesAudio(self, nomEntree=None):
        """Récupère les fichiers sources audio via une boite de dialogue. Utilise et modifie les paramètres de configuration"""
 
        if not self.lstFichiersSourceAudio: listePleine = False
        else:
            listePleine = True
            fichier = self.lstFichiersSourceAudio[0]
            path = os.path.dirname(fichier)
 
        if listePleine and os.path.exists(path):
            repEntree = path
        else:
            try:
                repEntree = EkdConfig.get('general','audio_input_path').decode("UTF8")
            except Exception, e:
                repEntree = '~'
                EkdConfig.set('general','audio_input_path', repEntree.encode("UTF8"))
            if not os.path.exists(repEntree):
                repEntree = '~'
                EkdConfig.set('general','audio_input_path', repEntree.encode("UTF8"))
 
        txt = _(u"Fichiers audio")
        if not nomEntree:
            liste=QFileDialog.getOpenFileNames(None, _(u"Ouvrir"), os.path.expanduser(repEntree),
                    "%s (*.ogg *.mp3 *.wav *.ac3 *.wmv *.mp2)\n*" %txt)
            liste = [unicode(i) for i in liste]
        else: # module séquentiel
            liste = nomEntree
 
        if len(liste)==0: return
        EkdConfig.set('general','audio_input_path',os.path.dirname(liste[0]).encode("UTF8"))
        return liste
 
 
    def recupSource(self, nomEntree=None, exclure_type=None, inclure_type=None):
        """Récupère le fichier source vidéo via une boite de dialogue. Utilise et modifie les paramètres de configuration"""
 
        try :
            if self.ligneEditionSource.text().isEmpty(): lignePleine = False
        except:
            return
        else:
            lignePleine = True
            fichier = unicode(self.ligneEditionSource.text())
            path = os.path.dirname(fichier)
 
        if lignePleine and os.path.exists(path):
            repEntree = path
        else:
            try:
                repEntree = EkdConfig.get('general','video_input_path').decode("UTF8")
            except Exception, e:
                repEntree = '~'
                EkdConfig.set('general','video_input_path', repEntree.encode("UTF8"))
            if not QFileInfo(repEntree).exists():
                repEntree = '~'
                EkdConfig.set('general','video_input_path', repEntree.encode("UTF8"))
 
        if not nomEntree:
            formats = ['avi', 'mpg', 'mpeg', 'mjpeg', 'flv', 'mp4', 'dv', 'vob'] ##
            if exclure_type:
                for type_ in exclure_type:
                    if type_ in formats: formats.remove(type_)
            if inclure_type:
                formats.append(inclure_type)
            formats2 = ["*.%s" %i for i in formats]
            txt = _(u"Fichiers vidéo")
            chemin=unicode(QFileDialog.getOpenFileName(None, _(u"Ouvrir"),os.path.expanduser(repEntree),
                    "%s (%s)\n*" %(txt, " ".join(formats2))))
        else: # module séquentiel
            chemin = nomEntree
 
        if not chemin: return
 
 
        EkdConfig.set('general','video_input_path',os.path.dirname(chemin).encode("UTF8"))
        return chemin
 
 
    def recupSourceAudio(self, nomEntree=None):
        """Récupère le fichier source audio via une boite de dialogue. Utilise et modifie les paramètres de configuration"""
 
        if self.ligneEditionSource.text().isEmpty(): lignePleine = False
        else:
            lignePleine = True
            fichier = unicode(self.ligneEditionSource.text())
            path = os.path.dirname(fichier)
 
        if lignePleine and os.path.exists(path):
            repEntree = path
        else:
            try:
                repEntree = EkdConfig.get('general','audio_input_path').decode("UTF8")
            except Exception, e:
                repEntree = '~'
                EkdConfig.set('general','audio_input_path', repEntree.encode("UTF8"))
            if not QFileInfo(repEntree).exists():
                repEntree = '~'
                EkdConfig.set('general','audio_input_path', repEntree.encode("UTF8"))
 
        if not nomEntree:
            txt = _(u"Fichiers audio")
            chemin=unicode(QFileDialog.getOpenFileName(None, _(u"Ouvrir"),os.path.expanduser(repEntree),
                    "%s (*.ogg *.mp3 *.wav *.ac3 *.wmv *.mp2)\n*" %txt))
        else: # module séquentiel
            chemin = nomEntree
 
        if not chemin: return
        EkdConfig.set('general','audio_input_path',os.path.dirname(chemin).encode("UTF8"))
        return chemin
 
 
    def afficherAide(self,msg=None):
        """ Boîte de dialogue de l'aide"""
        if not msg: _(u"Message d'aide")
        message=EkdAide(parent=self)
        message.setText(msg)
        message.show()
 
 
    def printSection(self):
        """Affichage dans le terminal de la section initialisée"""
        print '\n'+'-'*30+'\n| '+self.idSection+'\n'+'-'*30+'\n'
 
    def load(self):
        """
        Chargement de la configuration de tous les objets des éléments de l'objet
        """
        print "[Debug] Chargement non implémenté dans ", self.idSection
 
    def save(self):
        """
        Sauvegarde de la configuration de tous les objets des éléments de l'objet
        """
        print "[Debug] Sauvegarde non implémenté dans ", self.idSection