Coverage for modules/org/openteacher/interfaces/qt/teachers/topo/topo : 59%
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 TeachLessonOrderChooser, TeachLessonTypeChooser, TeachWidget
"""The dropdown menu to choose lesson type"""
#TypeError: not yet connected (first pass)
#save status
#update data
#restore status
#re-connect signal
"""What happens when you change the lesson type"""
if self.teachWidget.inLesson: self.teachWidget.restartLesson()
def currentLessonType(self): """Get the current lesson type"""
return self._lessonTypeModules[self.currentIndex()]
"""The dropdown menu to choose lesson order"""
#TypeError: not yet connected (first pass)
"""What happens when you change the lesson order"""
if self.teachWidget.inLesson: self.teachWidget.restartLesson()
"""The teach tab"""
## GUI Drawing # Top
# Middle
# Bottom
# Total
#TRANSLATORS: A button the user clicks to let the computer check the given answer.
"""Starts the lesson"""
self.places = places self.mapPath = mapPath
self.lesson = TeachTopoLesson(places, mapPath, self) self.answerfield.setFocus()
"""Restarts the lesson"""
self.initiateLesson(self.places, self.mapPath)
"""Stops the lesson"""
self.lesson.endLesson(showResults)
del self.lesson
"""What happens when the answer in the textbox has changed"""
try: self.lesson.endThinkingTime except AttributeError: self.lesson.endThinkingTime = datetime.datetime.now() else: if self.answerfield.text() == "": del self.lesson.endThinkingTime
"""What happens when you click the check answer button"""
# Check the answer self.lesson.checkAnswer() # Clear the answer field self.answerfield.clear() # Focus the answer field self.answerfield.setFocus()
"""Sets the bottom widgets to either the in-order version (False) or the inversed-order (True)
""" if order == Order.Inversed: self.label.setVisible(False) self.answerfield.setVisible(False) self.checkanswerbutton.setVisible(False) self.questionLabel.setVisible(True) else: self.label.setVisible(True) self.answerfield.setVisible(True) self.checkanswerbutton.setVisible(True) self.questionLabel.setVisible(False)
"""The lesson itself"""
super().__init__(*args, **kwargs)
self.teachWidget = teachWidget
# Set the map self.teachWidget.mapBox.setMap(mapPath) self.teachWidget.mapBox.setInteractive(self.order)
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.teachWidget.stopLesson)
self.lessonType.start()
self.teachWidget.inLesson = True
#self.startThinkingTime #self.endThinkingTime
# Reset the progress bar self.teachWidget.progress.setValue(0)
self.teachWidget.setWidgets(self.order)
"""Check whether the given answer was right or wrong"""
# Set endThinkingTime if it hasn't been set yet (this is in Name - Place mode) try: self.endThinkingTime except AttributeError: self.endThinkingTime = datetime.datetime.now()
active = { "start": self.startThinkingTime, "end": self.endThinkingTime }
if self.order == Order.Inversed: if self.currentItem == answer: # Answer was right self.lessonType.setResult({ "itemId": self.currentItem["id"], "result": "right", "active": active }) # Progress bar self._updateProgressBar() else: # Answer was wrong self.lessonType.setResult({ "itemId": self.currentItem["id"], "result": "wrong", "active": active }) else: if self.currentItem["name"] == self.teachWidget.answerfield.text(): # Answer was right self.lessonType.setResult({ "itemId": self.currentItem["id"], "result": "right", "active": active }) # Progress bar self._updateProgressBar() else: # Answer was wrong self.lessonType.setResult({ "itemId": self.currentItem["id"], "result": "wrong", "active": active })
self.teachWidget.listChanged.emit(self.itemList)
"""What happens when the next question should be asked"""
#set the next question self.currentItem = item if self.order == Order.Inversed: #set the question self.teachWidget.questionLabel.setText(_("Please click this place: ") + self.currentItem["name"]) else: #set the arrow to the right position self.teachWidget.mapBox.setArrow(self.currentItem["x"],self.currentItem["y"]) # 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
# 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, "topo", 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)
def order(self): return self.teachWidget.lessonOrderChooser.currentIndex()
global base
"default": 504, }
self._mm.mods(type="translator"), self._mm.mods(type="resultsDialog"), ) self._mm.mods(type="ui"), self._mm.mods(type="topoMaps"), )
global QtCore, QtWidgets except ImportError: return
#setup translation except IndexError: pass else:
global _ global ngettext
except IndexError: _, ngettext = str, lambda a, b, n: a if n == 1 else b else: self._mm.resourcePath("translations") )
|