Commits

Rémy HUBSCHER committed 028cfa4

Fonction d'ajout d'un son à une question

Comments (0)

Files changed (8)

 
 *.pyc
 *~
+quiz/sounds/*

editor/models/XMLFileHandler.py

 
     def __eq__(self, other):
         if other is not None:
-            return (self.text == other.text) and (self.exact == other.exact) and (self.sound == other.sound)
+            return (self.text == other.text) and (self.exact == other.exact) and ((self.sound == other.sound) or ((self.sound is None or self.sound == '') and (other.sound is None or other.sound == '')))
         else:
             return False
 
             self.loadXML(xml_node)
         else:
             self.text = u'Nouvelle question'
-            self.duo = [Reponse(), Reponse()]
+            self.sound = None
             self.carre = [Reponse(), Reponse(), Reponse(), Reponse()]
-            self.cash = Reponse()
 
     def loadXML(self, xml_node):
         self.text = xml_node.getAttributeNode("texte").value
 
     def __eq__(self, other):
         if other is not None:
-            is_eq = (self.text == other.text) and (self.sound == other.sound)
+            is_eq = (self.text == other.text) and ((self.sound == other.sound) or ((self.sound is None or self.sound == '') and (other.sound is None or other.sound == '')))
 
-            for rep1 in self.duo:
-                current = False
-                for rep2 in other.duo:
-                    if rep1 == rep2:
-                        current = True
-                is_eq &= current
-    
             for rep1 in self.carre:
                 current = False
                 for rep2 in other.carre:
                     if rep1 == rep2:
                         current = True
                 is_eq &= current
-    
-            is_eq &= (self.cash == other.cash)
-    
+        
             return is_eq
         else:
             return False

editor/models/XMLFileHandler.pyc

Binary file modified.
     q1.cash = r1
 
     q2 = deepcopy(q1)
+    q2.sound = ''
+    q2.carre[0].sound = ''
 
     print q1.writeXML()
 

editor/views/QtGui.py

 
         self.ui.questionsList = QuestionsList(self.ui.questionGroupBox)
         self.ui.verticalLayout.addWidget(self.ui.questionsList, QtCore.Qt.AlignTop)
+        self.setEditDisabled(True)
+
         
         # pour gérer l'utf8
         charset = QtCore.QTextCodec.codecForName('UTF-8')
         self.connect(self.ui.del_question_button, QtCore.SIGNAL('released()'), self.delQuestion)
 
         # Parcourir question
+        self.connect(self.ui.question_browse, QtCore.SIGNAL('released()'), self.browseSoundQuestion)
         self.connect(self.ui.carre_question1_browse, QtCore.SIGNAL('released()'), self.browseSoundQ1)
         self.connect(self.ui.carre_question2_browse, QtCore.SIGNAL('released()'), self.browseSoundQ2)
         self.connect(self.ui.carre_question3_browse, QtCore.SIGNAL('released()'), self.browseSoundQ3)
         self.ui.next_question_button.setDisabled(True)
         
         self.ui.questionLineEdit.setText('')
+        self.ui.question_fileName.setText('')
 
         for i in xrange(4):
             radio = getattr(self.ui, 'carre_question%d_selectRadio' % (i+1))
                                                           os.path.expanduser('~/hg/cip-qcu-editor/qcu/XML/'),
                                                           "Quiz's file (*.xml *.quiz)")
 
-        with open(self.filename, 'r') as xml_file:
-            content = xml_file.read()
-            dom = minidom.parseString(content)
-            self.quiz = Quiz(dom)
-
-            self.emit(QtCore.SIGNAL("quiz_loaded"), self.quiz)
-
-        self.updateTitle()
-        self.ui.questionsList.setCurrentRow(0)
-        self.last_question = None
-        self.loadQuestion()
+        if self.filename:
+            with open(self.filename, 'r') as xml_file:
+                content = xml_file.read()
+                dom = minidom.parseString(content)
+                self.quiz = Quiz(dom)
+    
+                self.emit(QtCore.SIGNAL("quiz_loaded"), self.quiz)
+    
+            self.updateTitle()
+            self.ui.questionsList.setCurrentRow(0)
+            self.last_question = None
+            self.loadQuestion()
 
     ## Enregistrer le fichier
     def saveFile(self, save_as=False):
         self.saveQuestion()
 
         current_item = self.ui.questionsList.item(self.ui.questionsList.currentRow())
-        self.last_question = deepcopy(current_item.question)
-
         if self.ui.questionsList.currentRow() <= 0:
             self.ui.prev_question_button.setDisabled(True)
         else:
         question = getattr(current_item, 'question', None)
 
         if question is not None:
+            self.last_question = deepcopy(question)
         
             self.ui.questionLineEdit.setText(question.text)
-    
+            if question.sound:
+                self.ui.question_fileName.setText(question.sound)
+            else:
+                self.ui.question_fileName.setText('')
+
             i = 0
             for rep in question.carre:
                 radio = getattr(self.ui, 'carre_question%d_selectRadio' % (i+1))
 
                 i = (i+1)%4
     
+            self.setEditDisabled(False)
             self.current_item = current_item
 
     def saveQuestion(self):
         if self.current_item is not None:
             current_question = self.current_item.question
             current_question.text = self.ui.questionLineEdit.text()
+            current_question.sound = self.ui.question_fileName.text()
 
             # Question Carré
             reponse1 = Reponse()
             current_question.carre = [reponse1, reponse2, reponse3, reponse4]
 
             if self.last_question and self.last_question != current_question:
+                print current_question.writeXML()
+                print self.last_question != current_question, self.last_question == current_question
+                print self.last_question.writeXML()
                 self.setWindowModified(True)
                 self.current_item.refresh()
 
             self.current_item = None
 
             self.ui.questionLineEdit.setText('')
+            self.ui.question_fileName.setText('')
     
-            i = 0
-
             self.ui.carre_question1_selectRadio.setChecked(False)
             self.ui.carre_question1_lineEdit.setText('')
             self.ui.carre_question1_fileName.setText('')
             self.ui.carre_question4_fileName.setText('')
 
         self.ui.questionsList.setCurrentRow(-1)
+        self.setEditDisabled(True)
 
     def exportZip(self):
         zipname = QtGui.QFileDialog.getSaveFileName(self, "Exporter le Quiz",
         QtGui.QMessageBox.information(self, u'À propos de Quiz Editor', u"Quiz Editor a été développé par Rémy HUBSCHER\ndans le cadre de sa mission au CIP à l'UTBM\nRémy Hubscher <remy.hubscher@utbm.fr>")
 
     # Question Sound Browse
-    def browseSound(self, id):
-        fileName = getattr(self.ui, 'carre_question%d_fileName' % (id))
-
+    def browseSound(self, fileName):
         sound_filename = QtGui.QFileDialog.getOpenFileName(self, "Charger un fichier",
                                                           os.path.expanduser('~/'),
                                                           "MP3 file (*.mp3)")
                 if ok == QMessageBox.Ok:
                     os.path.remove('quiz/sounds/%s' % fileName.text())
                     fileName.setText('')
-            
+
+    def browseSoundQuestion(self):
+        return self.browseSound(self.ui.question_fileName)
+
+    def browseSoundQ(self, id):
+        fileName = getattr(self.ui, 'carre_question%d_fileName' % (id))
+        return self.browseSound(fileName)
 
     def browseSoundQ1(self):
-        return self.browseSound(1)
+        return self.browseSoundQ(1)
     def browseSoundQ2(self):
-        return self.browseSound(2)
+        return self.browseSoundQ(2)
     def browseSoundQ3(self):
-        return self.browseSound(3)
+        return self.browseSoundQ(3)
     def browseSoundQ4(self):
-        return self.browseSound(4)
+        return self.browseSoundQ(4)
+
+    def setEditDisabled(self, boolean):
+        # Fields
+        self.ui.questionLineEdit.setDisabled(boolean)
+        self.ui.question_fileName.setDisabled(boolean)
+        
+        self.ui.carre_question1_selectRadio.setDisabled(boolean)
+        self.ui.carre_question1_lineEdit.setDisabled(boolean)
+        self.ui.carre_question1_fileName.setDisabled(boolean)
+        
+        self.ui.carre_question2_selectRadio.setDisabled(boolean)
+        self.ui.carre_question2_lineEdit.setDisabled(boolean)
+        self.ui.carre_question2_fileName.setDisabled(boolean)
+        
+        self.ui.carre_question3_selectRadio.setDisabled(boolean)
+        self.ui.carre_question3_lineEdit.setDisabled(boolean)
+        self.ui.carre_question3_fileName.setDisabled(boolean)
+
+        self.ui.carre_question4_selectRadio.setDisabled(boolean)
+        self.ui.carre_question4_lineEdit.setDisabled(boolean)
+        self.ui.carre_question4_fileName.setDisabled(boolean)
+
+        # Boutons parcourir
+        self.ui.question_browse.setDisabled(boolean)
+        self.ui.carre_question1_fileName.setDisabled(boolean)
+        self.ui.carre_question2_fileName.setDisabled(boolean)
+        self.ui.carre_question3_fileName.setDisabled(boolean)
+        self.ui.carre_question4_fileName.setDisabled(boolean)

editor/views/QtGui.pyc

Binary file modified.

editor/views/QuizEditor.py

 
 # Form implementation generated from reading ui file 'QuizEditor.ui'
 #
-# Created: Wed Dec  8 11:28:19 2010
+# Created: Wed Dec  8 12:58:35 2010
 #      by: PyQt4 UI code generator 4.7.4
 #
 # WARNING! All changes made in this file will be lost!
         QuizEditor.resize(757, 554)
         self.centralwidget = QtGui.QWidget(QuizEditor)
         self.centralwidget.setObjectName("centralwidget")
-        self.horizontalLayout = QtGui.QHBoxLayout(self.centralwidget)
-        self.horizontalLayout.setObjectName("horizontalLayout")
+        self.horizontalLayout_2 = QtGui.QHBoxLayout(self.centralwidget)
+        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
         self.verticalLayout_7 = QtGui.QVBoxLayout()
         self.verticalLayout_7.setObjectName("verticalLayout_7")
         self.questionGroupBox = QtGui.QGroupBox(self.centralwidget)
         self.del_question_button.setObjectName("del_question_button")
         self.horizontalLayout_7.addWidget(self.del_question_button)
         self.verticalLayout_7.addLayout(self.horizontalLayout_7)
-        self.horizontalLayout.addLayout(self.verticalLayout_7)
+        self.horizontalLayout_2.addLayout(self.verticalLayout_7)
         self.line = QtGui.QFrame(self.centralwidget)
         self.line.setFrameShape(QtGui.QFrame.VLine)
         self.line.setFrameShadow(QtGui.QFrame.Sunken)
         self.line.setObjectName("line")
-        self.horizontalLayout.addWidget(self.line)
+        self.horizontalLayout_2.addWidget(self.line)
         self.verticalLayout_4 = QtGui.QVBoxLayout()
         self.verticalLayout_4.setObjectName("verticalLayout_4")
         self.groupBox = QtGui.QGroupBox(self.centralwidget)
         self.questionLineEdit = QtGui.QLineEdit(self.groupBox)
         self.questionLineEdit.setObjectName("questionLineEdit")
         self.verticalLayout_2.addWidget(self.questionLineEdit)
+        self.horizontalLayout = QtGui.QHBoxLayout()
+        self.horizontalLayout.setObjectName("horizontalLayout")
+        self.question_fileName = QtGui.QLabel(self.groupBox)
+        self.question_fileName.setObjectName("question_fileName")
+        self.horizontalLayout.addWidget(self.question_fileName)
+        self.question_browse = QtGui.QPushButton(self.groupBox)
+        self.question_browse.setMinimumSize(QtCore.QSize(80, 30))
+        self.question_browse.setMaximumSize(QtCore.QSize(80, 30))
+        self.question_browse.setObjectName("question_browse")
+        self.horizontalLayout.addWidget(self.question_browse)
+        self.verticalLayout_2.addLayout(self.horizontalLayout)
         self.verticalLayout_4.addWidget(self.groupBox)
         self.horizontalLayout_8 = QtGui.QHBoxLayout()
         self.horizontalLayout_8.setObjectName("horizontalLayout_8")
         self.horizontalLayout_9.addWidget(self.next_question_button)
         self.verticalLayout_8.addLayout(self.horizontalLayout_9)
         self.verticalLayout_4.addLayout(self.verticalLayout_8)
-        self.horizontalLayout.addLayout(self.verticalLayout_4)
+        self.horizontalLayout_2.addLayout(self.verticalLayout_4)
         QuizEditor.setCentralWidget(self.centralwidget)
         self.menubar = QtGui.QMenuBar(QuizEditor)
         self.menubar.setGeometry(QtCore.QRect(0, 0, 757, 25))
         self.add_question_button.setText(QtGui.QApplication.translate("QuizEditor", "Ajouter", None, QtGui.QApplication.UnicodeUTF8))
         self.del_question_button.setText(QtGui.QApplication.translate("QuizEditor", "Supprimer", None, QtGui.QApplication.UnicodeUTF8))
         self.groupBox.setTitle(QtGui.QApplication.translate("QuizEditor", "Question", None, QtGui.QApplication.UnicodeUTF8))
+        self.question_fileName.setText(QtGui.QApplication.translate("QuizEditor", "question.mp3", None, QtGui.QApplication.UnicodeUTF8))
+        self.question_browse.setText(QtGui.QApplication.translate("QuizEditor", "Parcourir", None, QtGui.QApplication.UnicodeUTF8))
         self.groupBox_3.setTitle(QtGui.QApplication.translate("QuizEditor", "Carré", None, QtGui.QApplication.UnicodeUTF8))
         self.carre_question1_fileName.setText(QtGui.QApplication.translate("QuizEditor", "reponse1.mp3", None, QtGui.QApplication.UnicodeUTF8))
         self.carre_question1_browse.setText(QtGui.QApplication.translate("QuizEditor", "...", None, QtGui.QApplication.UnicodeUTF8))

editor/views/QuizEditor.ui

    <string>Quiz Editor - UTBM © 2010-2011</string>
   </property>
   <widget class="QWidget" name="centralwidget">
-   <layout class="QHBoxLayout" name="horizontalLayout">
+   <layout class="QHBoxLayout" name="horizontalLayout_2">
     <item>
      <layout class="QVBoxLayout" name="verticalLayout_7">
       <item>
          <item>
           <widget class="QLineEdit" name="questionLineEdit"/>
          </item>
+         <item>
+          <layout class="QHBoxLayout" name="horizontalLayout">
+           <item>
+            <widget class="QLabel" name="question_fileName">
+             <property name="text">
+              <string>question.mp3</string>
+             </property>
+            </widget>
+           </item>
+           <item>
+            <widget class="QPushButton" name="question_browse">
+             <property name="minimumSize">
+              <size>
+               <width>80</width>
+               <height>30</height>
+              </size>
+             </property>
+             <property name="maximumSize">
+              <size>
+               <width>80</width>
+               <height>30</height>
+              </size>
+             </property>
+             <property name="text">
+              <string>Parcourir</string>
+             </property>
+            </widget>
+           </item>
+          </layout>
+         </item>
         </layout>
        </widget>
       </item>