Coverage for modules/org/openteacher/interfaces/qt/teachers/media/media : 65%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
#! /usr/bin/env python3 # -*- coding: utf-8 -*-
# Copyright 2011-2012, Milan Boers # Copyright 2011-2013, Marten de Vries # # This file is part of OpenTeacher. # # OpenTeacher 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 3 of the License, or # (at your option) any later version. # # OpenTeacher 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 OpenTeacher. If not, see <http://www.gnu.org/licenses/>.
global TeachLessonTypeChooser, TeachWidget
"""The dropdown menu to choose lesson type"""
#disconnect the signal, so we can change some stuff without #other classes notice #TypeError: not yet connected (first pass)
#save status
#update data
#restore status
#re-connect signal
def currentLessonType(self): """Get the current lesson type"""
return self._lessonTypeModules[self.currentIndex()]
"""The teach tab"""
#draw the GUI
#TRANSLATORS: lesson types are e.g. 'smart', 'all once' and 'interval' #TRANSLATORS: a button which the user presses to tell the computer it should check his/her answer.
"""Starts the lesson"""
self.items = items self.lesson = TeachMediaLesson(items, self) self.answerField.setFocus()
"""Restarts the lesson"""
self.initiateLesson(self.items)
"""What happens when you change the lesson type"""
if self.inLesson: self.restartLesson()
"""Stops the lesson"""
self.lesson.endLesson(showResults) del self.lesson
"""What happens when you click the check answer button"""
self.lesson.checkAnswer() self.answerField.clear() self.answerField.setFocus()
"""The lesson itself (being teached)"""
super().__init__(*args, **kwargs)
self.teachWidget = teachWidget
self.itemList = itemList self.lessonType = self.teachWidget.lessonTypeChooser.currentLessonType.createLessonType(self.itemList,list(range(len(itemList["items"]))))
self.lessonType.newItem.handle(self.nextQuestion) self.lessonType.lessonDone.handle(self.endLesson)
self.lessonType.start()
self.teachWidget.inLesson = True
# Reset the progress bar self.teachWidget.progress.setValue(0)
"""Check whether the given answer was right or wrong"""
# Set the end of the thinking time self.endThinkingTime = datetime.datetime.now()
active = { "start": self.startThinkingTime, "end": self.endThinkingTime }
if self.currentItem["answer"] == self.teachWidget.answerField.text(): # Answer was right self.lessonType.setResult({ "itemId": self.currentItem["id"], "result": "right", "givenAnswer": self.teachWidget.answerField.text(), "active": active }) # Progress bar self._updateProgressBar() else: # Answer was wrong self.lessonType.setResult({ "itemId": self.currentItem["id"], "result": "wrong", "givenAnswer": self.teachWidget.answerField.text(), "active": active })
self.teachWidget.listChanged.emit(self.itemList)
"""What happens when the next question should be asked"""
# set the next question self.currentItem = item # set the question field self.teachWidget.questionLabel.setText(self.currentItem["question"]) # set the name field self.teachWidget.nameLabel.setText(self.currentItem["name"]) # set the mediawidget to the right location self.teachWidget.mediaDisplay.showMedia(self.currentItem["filename"], self.currentItem["remote"], True) # Set the start of the thinking time to now self.startThinkingTime = datetime.datetime.now() # Delete the end of the thinking time with contextlib.suppress(AttributeError): del self.endThinkingTime
"""Ends the lesson"""
self.teachWidget.inLesson = False
# stop media self.teachWidget.mediaDisplay.clear()
# Update and go to results widget, only if the test is progressing try: self.itemList["tests"][-1] except IndexError: pass else: if showResults: with contextlib.suppress(IndexError): # Go to results widget module = base._modules.default("active", type="resultsDialog") module.showResults(self.itemList, "media", self.itemList["tests"][-1])
self.teachWidget.lessonDone.emit()
"""Updates the progress bar"""
self.teachWidget.progress.setMaximum(self.lessonType.totalItems+1) self.teachWidget.progress.setValue(self.lessonType.askedItems)
global base
"default": 520, }
self._mm.mods(type="translator"), self._mm.mods(type="resultsDialog"), ) self._mm.mods(type="ui"), self._mm.mods(type="mediaDisplay"), )
global QtCore, QtGui, QtWidgets except ImportError: return
#setup translation else:
global _ global ngettext
else: self._mm.resourcePath("translations") )
widget = ref() if widget is not None: widget.retranslate()
|