Coverage for modules/org/openteacher/interfaces/qt/teachers/words/words : 67%
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-2013, Marten de Vries # Copyright 2011-2012, Cas Widdershoven # Copyright 2012, Milan Boers # # 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 TeachLessonWidget, TeachSettingsWidget, TeachWidget
except KeyError: #shouldn't happen, just in case... widget = QtWidgets.QLabel()
_("I'm ready, start the lesson!") )
#set stretch factor for widget indexes
self.sideWidget.insertWidget(0, widget)
self._lessonWidget.addSideWidget(widget)
"""Should only be called one. Hope it can be refactored out sometime. Should be called before startLesson() too.
"""
self.setCurrentWidget(self._settingsWidget)
self.setCurrentWidget(self._lessonWidget) self._applicationActivityChanged.handle(self._activityChanged)
path = self._settings["lessonType"]["value"] try: createLessonType = self._lessonTypeCreators[path] except KeyError: createLessonType = next(iter(self._lessonTypeCreators.values()))
indexes = list(range(len(self.lesson.list["items"]))) for path in self._settings["listModifiers"]["value"]: try: modifyList = self._listModifiers[path] except KeyError: continue indexes = modifyList(indexes, self.lesson.list)
selectedItemModifiers = [] for path in self._settings["itemModifiers"]["value"]: with contextlib.suppress(KeyError): selectedItemModifiers.append(self._itemModifiers[path])
def modifyItem(item): #function that applies all item modifiers on an item and #returns the result at the end of the chain. Before that is #done, it makes a copy of the item since the item modifiers #may modify the item in place. result = item.copy() for modify in selectedItemModifiers: result = modify(result) return result
self._lessonType = createLessonType(self.lesson.list, indexes, modifyItem)
self._lessonType.newItem.handle(self._newItem) self._lessonType.lessonDone.handle(self.stopLesson)
for widget, name in self._teachTypeWidgets: widget.updateLessonType(self._lessonType)
self._lessonType.start()
self.inLesson = True
self._lessonWidget.commentAfterAnsweringLabel.setVisible(show) self._lessonWidget.nextButton.setVisible(show) self._lessonWidget.teachTabWidget.setVisible(not show)
if activity == "inactive": self._pauseStart = datetime.datetime.now() elif activity == "active": self._lessonType.addPause({ "start": self._pauseStart, "end": datetime.datetime.now() })
"""Updates the GUI after some modifications have been made."""
self.listChanged.emit(self.lesson.list) self.lesson.changed = True
self._nextCallback()
"""Returns True if showing an answering comment, otherwise False.
""" try: commentAfterAnswering = self._currentItem["commentAfterAnswering"] except (AttributeError, KeyError): pass else: #next time don't show the after answering comment again. del self._currentItem
self._nextCallback = nextCallback self._showCommentAfterAnswering(True) self._lessonWidget.commentAfterAnsweringLabel.setText(commentAfterAnswering) return True
self._showCommentAfterAnswering(False) self._lessonWidget.commentAfterAnsweringLabel.clear() return False
if self._showAfterAnsweringCommentIfNecessary(lambda: self._newItem(item)): return
self._currentItem = item
#update other parts of the GUI to changes made since the #last time _newItem was called. self._tellListAndLessonChange()
self._lessonWidget.questionLabel.setText(self._compose(item["questions"])) try: self._lessonWidget.commentLabel.setText(item["comment"]) except KeyError: self._lessonWidget.commentLabel.clear() self._updateProgress()
self._lessonWidget.progressBar.setMaximum(self._lessonType.totalItems) self._lessonWidget.progressBar.setValue(self._lessonType.askedItems)
if self._showAfterAnsweringCommentIfNecessary(lambda: self.stopLesson(showResults)): return
#first update the GUI since modifications have been made. self._tellListAndLessonChange()
self._applicationActivityChanged.unhandle(self._activityChanged) self._updateProgress()
self._showSettings()
if showResults and self._showResults is not None: self._showResults(self.lesson.list, "words", self.lesson.list["tests"][-1])
self.inLesson = False
self.lessonDone.emit()
#tab changed
#start lesson button
#change lesson settings button
#next button
"default": 506, }
self._mm.mods(type="translator"), self._mm.mods(type="itemModifier"), self._mm.mods(type="listModifier"), self._mm.mods(type="resultsDialog"), self._mm.mods(type="settings"), ) self._mm.mods(type="ui"), self._mm.mods(type="wordsStringComposer"), self._mm.mods(type="lessonType"), self._mm.mods(type="teachType"), self._mm.mods(type="settingsWidgets"), )
def _showResults(self): #explicit is better than implicit. return None
(mod.__class__.__file__, mod.createLessonType) for mod in self._modules.sort("active", type="lessonType") ) (mod.__class__.__file__, mod.modifyList) for mod in self._modules.sort("active", type="listModifier") ) (mod.__class__.__file__, mod.modifyItem) for mod in self._modules.sort("active", type="itemModifier") )
except AttributeError: #replacement that does nothing letterChosen = self._modules.default(type="event").createEvent()
self._compose, self._showResults, lessonTypeCreators, listModifiers, itemModifiers, self._settings, self._widgets, keyboardWidget, self._applicationActivityChanged )
( module.createWidget(tw.tabChanged, letterChosen, tw.addSideWidget, tw.removeSideWidget), module.name ) for module in self._modules.sort("active", type="teachType") if module.dataType in ("all", "words") ]
def _widgets(self):
def _charsKeyboard(self): "active", type="charsKeyboard" ).createWidget() except IndexError: return
def _applicationActivityChanged(self):
global QtCore, QtGui, QtWidgets except ImportError: return
except IndexError: def registerSetting(name, **kwargs): kwargs["value"] = kwargs.pop("defaultValue") return kwargs
"lessonType": registerSetting(**{ "internal_name": "org.openteacher.teachers.words.lessonType", "type": "option", "options": lessonTypeOptions, "defaultValue": lessonTypeOptions[0][1] if len(lessonTypeOptions) > 0 else None, }), "listModifiers": registerSetting(**{ "internal_name": "org.openteacher.teachers.words.listModifiers", "type": "multiOption", "options": listModifierOptions, "defaultValue": listModifierOptions[0][1] if len(listModifierOptions) > 0 else None, }), "itemModifiers": registerSetting(**{ "internal_name": "org.openteacher.teachers.words.itemModifiers", "type": "multiOption", "options": itemModifierOptions, "defaultValue": itemModifierOptions[0][1] if len(itemModifierOptions) > 0 else None, }), #FIXME: make this actually work... :S # "dontShowAgain": registerSetting(**{ # "internal_name": "org.openteacher.teachers.words.dontShowAgain", # "type": "boolean", # "defaultValue": False, # }), }
else:
#Translations global _ global ngettext
else: self._mm.resourcePath("translations") )
# self._settings["dontShowAgain"]["name"] = _("Don't show this screen again when I start a lesson.")
"category": _("Words lesson"), "subcategory": _("Lesson settings") })
|