class FeatureDlg(QDialog): def __init__(self, parent=None): QDialog.__init__(self, parent) # init # ------------------------------------------------ self.setWindowTitle("Spatial Features") # widgets and layouts # ------------------------------------------------ self.layout = QHBoxLayout() self.setLayout(self.layout) self.tableAndViewGroupBox = QGroupBox(" Scales and Groups") self.tableAndViewGroupBox.setFlat(True) self.featureTableWidget = featureTableWidget.FeatureTableWidget() self.tableAndViewLayout = QVBoxLayout() self.tableAndViewLayout.setSizeConstraint(QLayout.SetNoConstraint) self.tableAndViewLayout.addWidget(self.featureTableWidget) self.viewAndButtonLayout = QVBoxLayout() self.preView = preView.PreView() self.viewAndButtonLayout.addWidget(self.preView) self.viewAndButtonLayout.addStretch() self.buttonsLayout = QHBoxLayout() self.memReqLabel = QLabel() self.buttonsLayout.addWidget(self.memReqLabel) self.buttonsLayout.addStretch() # Add Cancel self.cancel = QToolButton() self.cancel.setText("Cancel") self.cancel.clicked.connect(self.on_cancelClicked) self.buttonsLayout.addWidget(self.cancel) # Add OK self.ok = QToolButton() self.ok.setText("OK") self.ok.clicked.connect(self.on_okClicked) self.buttonsLayout.addWidget(self.ok) self.buttonsLayout.addSpacerItem(QSpacerItem(10, 0)) self.viewAndButtonLayout.addSpacerItem(QSpacerItem(0, 10)) self.tableAndViewGroupBox.setLayout(self.tableAndViewLayout) self.tableAndViewLayout.addLayout(self.buttonsLayout) self.layout.addWidget(self.tableAndViewGroupBox) self.layout.setContentsMargins(0, 0, 0, 0) self.tableAndViewGroupBox.setContentsMargins(4, 10, 4, 4) self.tableAndViewLayout.setContentsMargins(0, 10, 0, 0) self.featureTableWidget.brushSizeChanged.connect(self.preView.setFilledBrsuh) self.setMemReq() # methods # ------------------------------------------------ @property def selectedFeatureBoolMatrix(self): """Return the bool matrix of features that the user selected.""" return self.featureTableWidget.createSelectedFeaturesBoolMatrix() @selectedFeatureBoolMatrix.setter def selectedFeatureBoolMatrix(self, newMatrix): """Populate the table of selected features with the provided matrix.""" self.featureTableWidget.setSelectedFeatureBoolMatrix(newMatrix) def createFeatureTable(self, features, sigmas, brushNames=None): self.featureTableWidget.createTableForFeatureDlg(features, sigmas, brushNames) def setImageToPreView(self, image): self.preView.setVisible(image is not None) if image is not None: self.preView.setPreviewImage(qimage2ndarray.array2qimage(image)) def setIconsToTableWidget(self, checked, partiallyChecked, unchecked): self.featureTableWidget.itemDelegate.setCheckBoxIcons(checked, partiallyChecked, unchecked) def setMemReq(self): # featureSelectionList = self.featureTableWidget.createFeatureList() # TODO # memReq = self.ilastik.project.dataMgr.Classification.featureMgr.computeMemoryRequirement(featureSelectionList) # self.memReqLabel.setText("%8.2f MB" % memReq) pass def on_okClicked(self): # featureSelectionList = self.featureTableWidget.createFeatureList() # selectedFeatureList = self.featureTableWidget.createSelectedFeatureList() # sigmaList = self.featureTableWidget.createSigmaList() # featureMgr.ilastikFeatureGroups.newGroupScaleValues = sigmaList # featureMgr.ilastikFeatureGroups.newSelection = selectedFeatureList # res = self.parent().project.dataMgr.Classification.featureMgr.setFeatureItems(featureSelectionList) # if res is True: # self.parent().labelWidget.setBorderMargin(int(self.parent().project.dataMgr.Classification.featureMgr.maxContext)) # self.ilastik.project.dataMgr.Classification.featureMgr.computeMemoryRequirement(featureSelectionList) # self.accept() # else: # QErrorMessage.qtHandler().showMessage("Not enough Memory, please select fewer features !") # self.on_cancelClicked() self.accept() def on_cancelClicked(self): self.reject()
class FeatureDlg(QDialog): def __init__(self, parent=None): QDialog.__init__(self, parent) # init # ------------------------------------------------ self.setWindowTitle("Spatial Features") # widgets and layouts # ------------------------------------------------ self.layout = QHBoxLayout() self.setLayout(self.layout) self.tableAndViewGroupBox = QGroupBox(" Scales and Groups") self.tableAndViewGroupBox.setFlat(True) self.featureTableWidget = featureTableWidget.FeatureTableWidget() self.tableAndViewLayout = QVBoxLayout() self.tableAndViewLayout.setSizeConstraint(QLayout.SetNoConstraint) self.tableAndViewLayout.addWidget(self.featureTableWidget) self.viewAndButtonLayout = QVBoxLayout() self.preView = preView.PreView() self.viewAndButtonLayout.addWidget(self.preView) self.viewAndButtonLayout.addStretch() self.buttonsLayout = QHBoxLayout() self.memReqLabel = QLabel() self.buttonsLayout.addWidget(self.memReqLabel) self.buttonsLayout.addStretch() # Add Cancel self.cancel = QToolButton() self.cancel.setText("Cancel") self.cancel.clicked.connect(self.on_cancelClicked) self.buttonsLayout.addWidget(self.cancel) # Add OK self.ok = QToolButton() self.ok.setText("OK") self.ok.clicked.connect(self.on_okClicked) self.buttonsLayout.addWidget(self.ok) self.buttonsLayout.addSpacerItem(QSpacerItem(10, 0)) self.viewAndButtonLayout.addSpacerItem(QSpacerItem(0, 10)) self.tableAndViewGroupBox.setLayout(self.tableAndViewLayout) self.tableAndViewLayout.addLayout(self.buttonsLayout) self.layout.addWidget(self.tableAndViewGroupBox) self.layout.setContentsMargins(0, 0, 0, 0) self.tableAndViewGroupBox.setContentsMargins(4, 10, 4, 4) self.tableAndViewLayout.setContentsMargins(0, 10, 0, 0) self.featureTableWidget.brushSizeChanged.connect( self.preView.setFilledBrsuh) self.setMemReq() # methods # ------------------------------------------------ @property def selectedFeatureBoolMatrix(self): """Return the bool matrix of features that the user selected.""" return self.featureTableWidget.createSelectedFeaturesBoolMatrix() @selectedFeatureBoolMatrix.setter def selectedFeatureBoolMatrix(self, newMatrix): """Populate the table of selected features with the provided matrix.""" self.featureTableWidget.setSelectedFeatureBoolMatrix(newMatrix) def createFeatureTable(self, features, sigmas, brushNames=None): self.featureTableWidget.createTableForFeatureDlg( features, sigmas, brushNames) def setImageToPreView(self, image): self.preView.setVisible(image is not None) if image is not None: self.preView.setPreviewImage(qimage2ndarray.array2qimage(image)) def setIconsToTableWidget(self, checked, partiallyChecked, unchecked): self.featureTableWidget.itemDelegate.setCheckBoxIcons( checked, partiallyChecked, unchecked) def setMemReq(self): # featureSelectionList = self.featureTableWidget.createFeatureList() #TODO #memReq = self.ilastik.project.dataMgr.Classification.featureMgr.computeMemoryRequirement(featureSelectionList) #self.memReqLabel.setText("%8.2f MB" % memReq) pass def on_okClicked(self): # featureSelectionList = self.featureTableWidget.createFeatureList() # selectedFeatureList = self.featureTableWidget.createSelectedFeatureList() # sigmaList = self.featureTableWidget.createSigmaList() # featureMgr.ilastikFeatureGroups.newGroupScaleValues = sigmaList # featureMgr.ilastikFeatureGroups.newSelection = selectedFeatureList # res = self.parent().project.dataMgr.Classification.featureMgr.setFeatureItems(featureSelectionList) # if res is True: # self.parent().labelWidget.setBorderMargin(int(self.parent().project.dataMgr.Classification.featureMgr.maxContext)) # self.ilastik.project.dataMgr.Classification.featureMgr.computeMemoryRequirement(featureSelectionList) # self.accept() # else: # QErrorMessage.qtHandler().showMessage("Not enough Memory, please select fewer features !") # self.on_cancelClicked() self.accept() def on_cancelClicked(self): self.reject()
class Mplayer(QDialog): REVENIR, PAS_PRECEDENT_SUIVANT, PRECEDENT_SUIVANT, CURSEUR_SUR_UNE_LIGNE,\ CURSEUR_A_PART, PARCOURIR, PAS_PARCOURIR, LIST, RATIO = range(9) HAUTEUR, LARGEUR = range(2) def __init__(self, cheminVideo=[], taille=(250,225), choixWidget=(RATIO, REVENIR, PAS_PRECEDENT_SUIVANT,CURSEUR_SUR_UNE_LIGNE,PAS_PARCOURIR,LIST), debutFin=(0,0), cheminMPlayer=None, barreTaches=None, facteurLimitant=HAUTEUR, cheminParcourir=None, parent=None): """widget mplayer""" QDialog.__init__(self, parent) #=== Paramètres généraux ===# self.setAttribute(Qt.WA_DeleteOnClose) self.setWindowTitle(_(u"Player vidéo")) #On réduit la marge pour gagner de l'espace self.setContentsMargins(0,0,0,0) self.systeme = os.name ### Quand EKD windows est installé, le chemin des dépendances sont ########### ### positionnées dans les variables d'environnement donc pas besoin de ####### ### collecter le chemin des ces dépendances ################################## self.cheminMPlayer = "mplayer" ############################################################################## # liste de chemins vidéos if type(cheminVideo) != list : self.listeVideos=[cheminVideo] else : self.listeVideos = cheminVideo # est-ce que la vidéo est lue? self.estLue=False # est-ce que la vidéo est en pause? self.estEnPause=False self.debutFin = debutFin # Nom du fichier courant (le self n'est pas encore utile) txtParDefaut = u"Pas de fichier lu" if self.listeVideos.__len__()!=0: self.fichierCourant = [txtParDefaut, self.listeVideos[0]] else: self.fichierCourant = [txtParDefaut, ""] # Barre des tâches de la fenêtre self.barreTaches = barreTaches # Taille de la vidéo self.tailleLargeur=taille[0] self.tailleHauteur=taille[1] # paramètres des boutons-icones iconTaille=22 flat=1 # Pour récupérer le temps courant depuis certains cadre self.temps = 0 self.dureeTimer = 10 # temps en ms ############################################################################################################################### #Pour être plus précis lors de la lecture, on prend comme unité la miliseconde. ###################### ## Il faut donc utiliser une echelle 1000 fois plus grande pour les unités du slider self.echelle=1000 ############################################################################################################################### # Permet de récupérer la durée de la vidéo depuis une instance de la classe # Sert dans certains cadres self.dureeVideo = 0 # Chemin sur lequel peut s'ouvrir la boite de dialogue de fichier # associée au bouton parcourir self.cheminPourBoutonParcourir = cheminParcourir self.taille = taille debug("self.taille avant lecture : %s %s" % (self.taille, type(self.taille))) #=== Widgets ===# self.icone_lire=QIcon("Icones" + os.sep + "player_play.png") self.icone_pause=QIcon("Icones" + os.sep + "player_pause.png") self.icone_arret=QIcon("Icones" + os.sep + "player_stop.png") if Mplayer.REVENIR in choixWidget: self.bout_revenir = QPushButton(u"Revenir") self.bout_revenir.setIcon(QIcon("Icones" + os.sep + "revenir.png")) if Mplayer.PARCOURIR in choixWidget: self.bout_ouvVideo = QPushButton(u"Parcourir...") if Mplayer.PRECEDENT_SUIVANT in choixWidget: self.bout_prec = QPushButton(QIcon("Icones" + os.sep + "player_rew.png"),"") self.bout_prec.setIconSize(QSize(iconTaille, iconTaille)) self.bout_prec.setFlat(flat) self.bout_suivant = QPushButton(QIcon("Icones" + os.sep + "player_fwd.png"),"") self.bout_suivant.setIconSize(QSize(iconTaille, iconTaille)) self.bout_suivant.setFlat(flat) self.LISTW=False if Mplayer.LIST in choixWidget : self.LISTW = True self.listFichiers = QComboBox() self.listFichiers.hide() self.setListeVideo() self.bout_LectPause = QPushButton(self.icone_lire,"") self.bout_LectPause.setIconSize(QSize(iconTaille, iconTaille)) self.bout_LectPause.setFlat(flat) self.bout_Arret = QPushButton(self.icone_arret,"") self.bout_Arret.setIconSize(QSize(iconTaille, iconTaille)) self.bout_Arret.setFlat(flat) # widget qui contiendra la vidéo self.cibleVideo = DisplayVid(self) # par défaut le widget-cible est noir color = QColor(0, 0, 0) self.cibleVideo.setAutoFillBackground(True) self.cibleVideo.setPalette(QPalette(color)) self.cibleVideo.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.cibleVideo.setFixedHeight(self.taille[1]) self.cibleVideo.setToolTip(self.fichierCourant[0]) #Choix de l'aspect ratio de la vidéo if Mplayer.RATIO in choixWidget : self.conf = QGroupBox() self.conf.setContentsMargins(0,0,0,0) self.conf.setMinimumSize(QSize(self.tailleLargeur, 0)) self.conf.setObjectName("conf") self.verticalLayout = QHBoxLayout(self.conf) self.verticalLayout.setObjectName("verticalLayout") self.choicenorm = QRadioButton(self.conf) self.choicenorm.setObjectName("choicenorm") self.verticalLayout.addWidget(self.choicenorm) self.choicewide = QRadioButton(self.conf) self.choicewide.setObjectName("choicewide") self.verticalLayout.addWidget(self.choicewide) self.choiceone = QRadioButton(self.conf) self.choiceone.setObjectName("choiceone") self.verticalLayout.addWidget(self.choiceone) self.choicenorm.setText("4:3") self.choicewide.setText("16:9") self.choiceone.setText("w:h") # Checked le ratio de la vidéo if self.listeVideos.__len__()!=0: self.changeRatio(self.listeVideos[0]) else : self.setRatio(4.0/3.0) if Mplayer.RATIO in choixWidget : self.choicenorm.setChecked(True) self.slider = QSlider(Qt.Horizontal) self.slider.setEnabled(True) self.mplayerProcess = QProcess(self) self.timer = QTimer(self) self.tempsChrono = TracerChrono() #=== mise-en-page/plan ===# mhbox = QHBoxLayout() vbox = QVBoxLayout() vbox.addWidget(self.cibleVideo) if Mplayer.RATIO in choixWidget : vbox.addWidget(self.conf) hbox = QHBoxLayout() if Mplayer.REVENIR in choixWidget: hbox.addWidget(self.bout_revenir) if Mplayer.PARCOURIR in choixWidget: hbox.addWidget(self.bout_ouvVideo) hbox.addWidget(self.bout_LectPause) hbox.addWidget(self.bout_Arret) if Mplayer.PRECEDENT_SUIVANT in choixWidget: hbox.addWidget(self.bout_prec) hbox.addWidget(self.bout_suivant) hbox.addWidget(self.tempsChrono) if Mplayer.CURSEUR_A_PART not in choixWidget: hbox.addWidget(self.slider) vbox.addLayout(hbox) if Mplayer.CURSEUR_A_PART in choixWidget: hbox.setAlignment(Qt.AlignLeft) hbox = QHBoxLayout() hbox.addWidget(self.slider) vbox.addLayout(hbox) # Liste fichier dans combobox if self.LISTW : hbox = QHBoxLayout() hbox.addWidget(self.listFichiers) vbox.addLayout(hbox) mhbox.addLayout(vbox) self.setLayout(mhbox) #=== connexion des widgets à des fonctions ===# if Mplayer.REVENIR in choixWidget: self.connect(self.bout_revenir, SIGNAL('clicked()'), SLOT('close()')) if Mplayer.PARCOURIR in choixWidget: self.connect(self.bout_ouvVideo, SIGNAL('clicked()'), self.ouvrirVideo) if Mplayer.PRECEDENT_SUIVANT in choixWidget: self.connect(self.bout_prec, SIGNAL('clicked()'), self.precedent) self.connect(self.bout_suivant, SIGNAL('clicked()'), self.suivant) #Ajouté le 08/11/2009 - Liste des fichiers dans une combobox if self.LISTW : self.connect(self.listFichiers, SIGNAL('currentIndexChanged(int)'), self.changeVideo) self.connect(self.bout_LectPause, SIGNAL('clicked()'), self.lectPause) self.connect(self.bout_Arret, SIGNAL('clicked()'), self.arretMPlayer) self.connect(self.mplayerProcess, SIGNAL('readyReadStandardOutput()'), self.recupSortie) self.connect(self.mplayerProcess, SIGNAL('finished(int,QProcess::ExitStatus)'), self.finVideo) self.connect(self.timer, SIGNAL('timeout()'), self.sonderTempsActuel) self.connect(self.slider, SIGNAL('sliderMoved(int)'), self.changerTempsCurseur) self.connect(self.cibleVideo, SIGNAL('changeSize'), self.sizeMplayer) if Mplayer.RATIO in choixWidget : self.connect(self.choicenorm, SIGNAL("clicked(bool)"), self.defRatio) self.connect(self.choicewide, SIGNAL("clicked(bool)"), self.defRatio) self.connect(self.choiceone, SIGNAL("clicked(bool)"), self.defRatio) def setListeVideo(self) : self.referenceVideo = [] self.listFichiers.clear() for vid in self.listeVideos : self.referenceVideo.append(vid) self.listFichiers.addItem(os.path.basename(vid)) if self.listeVideos.__len__() > 1 : self.listFichiers.show() def setAudio(self,au) : if au : self.cibleVideo.hide() if "conf" in self.__dict__ : self.conf.hide() else : self.cibleVideo.show() if "conf" in self.__dict__ : self.conf.show() def changeVideo(self, index) : self.arretMPlayer() if index >= 0 : # Condition ajoutée pour éviter une erreure de dépassement de range dans la liste. self.listeVideos = self.referenceVideo[index] self.listFichiers.setCurrentIndex(index) def defRatio(self, state=0) : if state : if self.choicenorm.isChecked() : self.setRatio(4.0/3.0) if self.choicewide.isChecked() : self.setRatio(16.0/9.0) if self.choiceone.isChecked() : try : dim=getVideoSize(unicode(self.listeVideos[0])) self.setRatio(dim[0]/dim[1]) except : None self.defRatio() else : self.adjustSize() def setRatio(self,ratio) : self.ratio = ratio self.sizeMplayer() def changeRatio(self,video) : rv = getVideoRatio(video) if rv[0]==0.0 and type(rv[1])==float : rat = rv[1] else : rat = rv[0] if rat > 1.7 : if "choicewide" in self.__dict__ : self.choicewide.setChecked(True) self.setRatio(16.0/9.0) elif rat > 1.3 and rat <= 1.7 : if "choicenorm" in self.__dict__ : self.choicenorm.setChecked(True) self.setRatio(4.0/3.0) elif rat < 1.3 and rat != 0.0 : if "choiceone" in self.__dict__ : self.choiceone.setChecked(True) dim=getVideoSize(video) self.setRatio(dim[0]/dim[1]) else : if "choicenorm" in self.__dict__ : self.choicenorm.setChecked(True) self.setRatio(4.0/3.0) def sizeMplayer(self) : self.cibleVideo.setFixedHeight(int(self.cibleVideo.width()/self.ratio)) def ouvrirVideo(self): """Ouverture de la boîte de dialogue de fichiers""" txt = u"Fichiers vidéo" if self.cheminPourBoutonParcourir: chemin = self.cheminPourBoutonParcourir else: try: chemin = EkdConfig.get('general','video_input_path').decode("UTF8") except: chemin = os.path.expanduser('~') liste=QFileDialog.getOpenFileNames(None, u"Ouvrir", chemin, "%s (*.avi *.mpg *.mpeg *.mjpeg *.flv *.mp4 *.ogg *.vob *.mov *.wmv *.3gp *.h264)\n*" %txt) if not liste: return self.listeVideos = liste self.changeRatio(unicode(self.listeVideos[0])) chemin = unicode(self.listeVideos[0]) EkdConfig.set('general','video_input_path',os.path.dirname(chemin).encode("UTF8")) def setVideos(self, videos) : '''Définie proprement la liste des vidéos à jouer''' if type(videos) != list : self.listeVideos = [videos] else : self.listeVideos = videos if self.LISTW and videos.__len__() > 1 : self.setListeVideo() elif self.LISTW : self.listFichiers.hide() def demarrerMPlayer(self): """démarrage de mplayer avec les arguments choisis""" if self.estLue: return True args = QStringList() # Liste Qt qui contiendra les options de mplayer # Ajout d'options à liste: args << "-option" # mplayer fonctionnera comme un terminal dans ce script args << "-slave" # on ne veut pas avoir des commentaires sans grand intérêt args << "-quiet" # Sous linux, aucun driver n'a été nécessaire et pas de manip pour Wid :) if self.systeme=='posix': # try - except? # la fenêtre de mplayer restera attaché à la fenêtre # wid prend en valeur le nombre identifiant le widget (celui qui contiendra la vidéo) args << "-wid" << QString.number(self.cibleVideo.winId()) # Objet QString car args est une liste de ch de caractères settings = QSettings() videoOutput = settings.value("vo", QVariant('')).toString() if videoOutput: args << '-vo' << videoOutput # Sous windows else: # reinterpret_cast<qlonglong> obligatoire, winId() ne se laissant pas convertir gentiment ;) args << "-wid" << self.cibleVideo.winId().__hex__() args << "-vo" << "directx:noaccel" #args << "-vo" << "gl" # alternative # chemin de la vidéo args << self.listeVideos if PYQT_VERSION_STR >= "4.1.0": # mode de canal: on fusionne le canal de sortie normal (stdout) et celui des erreurs (stderr) self.mplayerProcess.setProcessChannelMode(QProcess.MergedChannels) # démarrage de mplayer (en tenant compte des arguments définis ci-dessus) # comme un nouveau processus self.mplayerProcess.start(self.cheminMPlayer, args) # au cas où mplayer ne démarrerait pas au bout de 3 sec (ex. problème de codec) if not self.mplayerProcess.waitForStarted(3000): QMessageBox.critical(self, u"Avertissement", u"Bogue au lancement de la vidéo avec mplayer") return False # donne le temps toutes les x secondes self.timer.start(self.dureeTimer) self.estLue = True return True def recupSortie(self): """récupère les lignes d'information émises par QProcess (mplayerProcess) et en tire les conséquences""" while self.mplayerProcess.canReadLine(): # renvoie True si une ligne complète peut être lue à partir du système # stocker l'ensemble des bits d'une ligne tampon=QByteArray(self.mplayerProcess.readLine()) # readline: lit une ligne ascii à partir du système # On vérifie si on a eu des réponses if tampon.startsWith("Playing"): # On récupère les infos de base ('$ mplayer -input cmdlist' pour avoir la liste complète - file:///usr/share/doc/mplayer-doc/tech/slave.txt.gz pour plus de détails) self.mplayerProcess.write("get_video_resolution\n") # récupère la résolution de la vidéo self.mplayerProcess.write("get_time_length\n") # Nouveau fichier chargé -> on récupère son nom ind = tampon.length() - 2 # suppression du '.' à la fin tampon.remove(ind,ind) tampon.remove(0, 8) # vire Playing tampon.replace(QByteArray("\n"), QByteArray("")) tampon.replace(QByteArray("\r"), QByteArray("")) try: # Tour de passe-passe pour ne pas avoir de problème d'accents # Condition pour détection windows if os.name == 'nt': self.fichierCourant[1]=unicode(QString(tampon)) # Condition pour détection Linux ou MacOSX elif os.name in ['posix', 'mac']: self.fichierCourant[1]=unicode(QString(tampon)).encode("Latin1").decode("UTF8") except UnicodeEncodeError, e: debug(e) self.fichierCourant[1]="?" self.cibleVideo.setToolTip(self.fichierCourant[1]) if self.barreTaches is not None: self.barreTaches.showMessage(self.fichierCourant[1]) # réponse à get_video_resolution : ANS_VIDEO_RESOLUTION='<width> x <height>' if tampon.startsWith("ANS_VIDEO_RESOLUTION"): # retourne True si l'ensemble de bits démarre avec "..." debug("tampon : %s" % tampon) # ex. -> ANS_VIDEO_RESOLUTION='352 x 288' tampon.remove(0, 21) # suppression des 21 1er caract -> '352 x 288' tampon.replace(QByteArray("'"), QByteArray("")) # -> 352 x 288 tampon.replace(QByteArray(" "), QByteArray("")) # -> 352x288 tampon.replace(QByteArray("\n"), QByteArray("")) # -> 352x288 # retour chariot unix tampon.replace(QByteArray("\r"), QByteArray("")) # -> 352x288 # retour chariot windows #print "-----tampon.indexOf('x') :", tampon.indexOf('x'), type(tampon.indexOf('x')) sepIndex = tampon.indexOf('x') # récupère la position de 'x' # 3 <type 'int'> #print "-----tampon.left(sepIndex).toInt():", tampon.left(sepIndex).toInt(), type(tampon.left(sepIndex).toInt()) resX = tampon.left(sepIndex).toInt()[0] # -> 352 # (352, True) <type 'tuple'> #print "-----tampon.mid(sepIndex+1).toInt() :", tampon.mid(sepIndex+1).toInt(), type(tampon.mid(sepIndex+1).toInt()) resY = tampon.mid(sepIndex+1).toInt()[0] # -> 288 # (288, True) <type 'tuple'> # on définit les nouvelles dimensions de l'image du widget-mplayer. # try pour éviter les bogues sur les fichiers audio (sans dimension d'image)!!! #try: if resX!=0 or resY!=0: debug( "ratio : %s - %s" % (self.ratio, type(self.ratio))) else: debug("fichier audio") # réponse à get_time_length : ANS_LENGTH=xx.yy elif tampon.startsWith("ANS_LENGTH"): debug("tampon : %s" % tampon) # -> ANS_LENGTH=279.38 tampon.remove(0, 11) # vire ANS_LENGTH= tampon.replace(QByteArray("'"), QByteArray("")) tampon.replace(QByteArray(" "), QByteArray("")) tampon.replace(QByteArray("\n"), QByteArray("")) tampon.replace(QByteArray("\r"), QByteArray("")) # -> 279.38 #print "-----tampon.toFloat() :", tampon.toFloat(), type(tampon.toFloat()) tempsMax = tampon.toFloat()[0] # (279.3800048828125, True) <type 'tuple'> self.dureeVideo = tempsMax ## Modifié le 28/05/2009 : On augmente la précision du slider #self.slider.setMaximum(tempsMax) # déf du domaine de valeur du curseur self.slider.setMaximum(tempsMax*self.echelle) # ATTENTION J'AI COMMENTE CETTE LIGNE !!! #self.slider.setMaximum(tempsMax) # réponse à get_time_pos : ANS_TIME_POSITION=xx.y elif tampon.startsWith("ANS_TIME_POSITION"): #print "tampon :",tampon # -> ANS_TIME_POSITION=1.4 (temps courant) tampon.remove(0, 18) # vire ANS_TIME_POSITION= tampon.replace(QByteArray("'"), QByteArray("")) tampon.replace(QByteArray(" "), QByteArray("")) tampon.replace(QByteArray("\n"), QByteArray("")) tampon.replace(QByteArray("\r"), QByteArray("")) #print "-----tampon.toFloat() :", tampon.toFloat(), type(tampon.toFloat()) tempsCourant = tampon.toFloat()[0] # (1.3999999761581421, True) <type 'tuple'> # récupération du temps courant: utile dans certains cadres self.temps = tempsCourant # Programmer un arrêt. Utile pour les aperçus temps = float("%.1f" %self.temps) if self.debutFin!=(0,0) and self.debutFin[1]==temps: self.arretMPlayer() return self.slider.setValue(tempsCourant*self.echelle) ############################################################################# self.changerTempsChrono(tempsCourant) # modifier le chrono du bouton
def __init__(self): super(mainwindow, self).__init__() self.setWindowTitle('组件设计工具') self.setWindowIcon(QIcon(':/image/组件设计工具.png')) self.setMinimumWidth(1024) self.setMinimumHeight(800) self.showMaximized() self.menuBar().show() self.createMenus() #self.setWindowFlags(QtCore.Qt.WindowMinimizeButtonHint) labelSizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) editSizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed) cwVLayout = QVBoxLayout() cwHLayout = QHBoxLayout() lLayout = QVBoxLayout() rLayout = QVBoxLayout() self.lw = QListWidget() self.lw.setSelectionMode(QAbstractItemView.SingleSelection) lLayout.addWidget(self.lw) self.lw.itemSelectionChanged.connect(self.on_select) lGroup = QGroupBox('项目列表') lGroup.setLayout(lLayout) cwHLayout.addWidget(lGroup, 2) lGroup.setContentsMargins(0, 12, 0, 22) tLayout = QVBoxLayout() bLayout = QHBoxLayout() self.tGroup = QGroupBox('配置信息') self.bGroup = QGroupBox('生成代码') self.tGroup.setLayout(tLayout) self.tGroup.setEnabled(False) self.bGroup.setLayout(bLayout) self.bGroup.setEnabled(False) cwHLayout.addWidget(self.tGroup, 8) cwVLayout.addLayout(cwHLayout) cwVLayout.addWidget(self.bGroup) self.tw_config = QTreeWidget() headerLabels = QStringList() headerLabels.append(' 项目') headerLabels.append(' 值') self.tw_config.setHeaderLabels(headerLabels) self.tw_config.setColumnWidth(0, 312) self.tw_config.setColumnWidth(1, 660) thLayout = QHBoxLayout() thLayout.setContentsMargins(0, 6, 0, 0) thLayout.addSpacing(10) modify_btn = QPushButton('') #修改 modify_btn.setObjectName('modify_btn') modify_btn.clicked.connect(self.on_modify) del_btn = QPushButton('') #删除 del_btn.setObjectName('del_btn') del_btn.clicked.connect(self.on_del) thLayout.addWidget(modify_btn) thLayout.addWidget(del_btn) thLayout.addStretch(0) tLayout.addLayout(thLayout) tLayout.addWidget(self.tw_config) bhLayout = QHBoxLayout() lable1 = QLabel('工程名称:') lable1.setSizePolicy(labelSizePolicy) self.et_project_name = QLineEdit() self.et_project_name.setSizePolicy(editSizePolicy) bhLayout.addWidget(lable1) bhLayout.addWidget(self.et_project_name) bhLayout.addSpacing(16) lable2 = QLabel('工程位置:') lable2.setSizePolicy(labelSizePolicy) self.et_project_location = QLineEdit() self.et_project_location.setReadOnly(True) self.et_project_location.setSizePolicy(editSizePolicy) btn_location = QPushButton('') #打开 btn_location.setObjectName('btn_location') btn_location.setSizePolicy(labelSizePolicy) btn_location.clicked.connect(self.getProjectLocation) bhLayout.addWidget(lable2) bhLayout.addWidget(self.et_project_location) bhLayout.addSpacing(10) bhLayout.addWidget(btn_location) #bhLayout.addStretch(0) gen_btn = QPushButton('') # 生成 gen_btn.setObjectName('gen_btn') gen_btn.setSizePolicy(labelSizePolicy) gen_btn.clicked.connect(self.on_gen) bhLayout.addSpacing(45) bhLayout.addWidget(gen_btn) bLayout.addLayout(bhLayout) bLayout.setContentsMargins(10, 24, 22, 34) statusBar = self.statusBar() sBH = QHBoxLayout() copyright = QLabel('') copyright.setAlignment(QtCore.Qt.AlignCenter) copyright.setStyleSheet("color:#acacac") statusBar.setMinimumHeight(30) statusBar.addWidget(copyright, 10) cw = QWidget() cw.setLayout(cwVLayout) self.setCentralWidget(cw) self._initByConfig() self.setMinimumSize(400, 200)