Coverage for modules/org/openteacher/interfaces/qt/enterers/media/media : 53%
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, 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 EnterItemListModel, EnterItemList, EnterWidget
"""The model for the list widget with media items (this construction because without model Qt produces a bug)
"""
return len(self.listData)
if index.isValid() and role == QtCore.Qt.DisplayRole: return self.listData[index.row()]
"""The list widget with media items"""
self.lm.update(self.enterWidget.list)
self.setRightActiveItem()
if len(self.enterWidget.list["items"]) > 0: self.enterWidget.setActiveItem(self.enterWidget.list["items"][self.currentIndex().row()])
"""The enter tab"""
"items": [], "tests": [] } "id": 0, "remote": False, "filename": "", "name": "", "question": "", "answer": "" }
"""Add items from the local disk to the list"""
extensions = [] for module in base._modules.sort("active", type="mediaType"): with contextlib.suppress(AttributeError): #AttributeError: no extensions extensions.extend(module.extensions)
extensionsStr = "(" for extension in extensions: extensionsStr += "*" + extension + " " extensionsStr += ")"
filenames = QtWidgets.QFileDialog.getOpenFileNames( self, _(_("Select file(s)")), QtCore.QDir.homePath(), _("Media") + " " + extensionsStr )[0] for filename in filenames: self.addItem(filename, remote=False)
"""Add items from the internet to the list"""
sitenames = [] for module in base._modules.sort("active", type="mediaType"): with contextlib.suppress(AttributeError): #AttributeError: No name sitenames.extend(module.remoteNames)
sitenamesStr = "" for sitename in sitenames: sitenamesStr += sitename + ", " sitenamesStr = sitenamesStr[:-2]
url, dialog = QtWidgets.QInputDialog.getText( self, _("File URL"), _("Enter the URL of your website or media item.\nSupported video sites: ") + sitenamesStr + "." ) if dialog: self.addItem(url, remote=True)
"""Updates all the widgets if the list has changed"""
self.enterItemList.update() self.titleTextBox.setText(self.list.get("title", u"")) self.setActiveItem(self.activeitem)
"""Add an item to the list"""
# Check if file is supported for module in base._modules.sort("active", type="mediaType"): if module.supports(filename): item = { "id": 0, "remote": remote, "filename": filename, "name": name, "question": "", "answer": "" } # Set id try: item["id"] = self.list["items"][-1]["id"] +1 except IndexError: item["id"] = 0
if name: item["name"] = name else: if remote == False: item["name"] = os.path.basename(filename) else: item["name"] = filename if question: item["question"] = question if answer: item["answer"] = answer
self.list["items"].append(item) self.lesson.changed = True self.updateWidgets() break else: QtWidgets.QMessageBox.critical( self, _("Unsupported file type"), _("This type of file is not supported:\n") + filename )
"""Remove an item from the list"""
if self.activeitem in self.list["items"]: self.list["items"].remove(self.activeitem) self.updateWidgets() self.mediaDisplay.clear() self.enterName.setText("") self.enterName.setEnabled(False) self.enterQuestion.setText("") self.enterQuestion.setEnabled(False) self.enterAnswer.setText("") self.enterAnswer.setEnabled(False) self.enterItemList.setRightActiveItem()
"""Change the active item"""
self.enterName.setEnabled(True) self.enterName.setText(item["name"]) self.enterQuestion.setEnabled(True) self.enterQuestion.setText(item["question"]) self.enterAnswer.setEnabled(True) self.enterAnswer.setText(item["answer"]) if item["filename"] != self.activeitem["filename"]: self.mediaDisplay.showMedia(item["filename"], item["remote"], False) self.activeitem = item
"""Change the title of the media list"""
if self.list.get("title", u"") != text: self.list["title"] = text self.lesson.changed = True
"""Change the name of the active item"""
if self.activeitem["name"] != self.enterName.text(): self.activeitem["name"] = self.enterName.text() self.updateWidgets() self.lesson.changed = True
"""Change the question of the active item"""
if self.activeitem["question"] != self.enterQuestion.text(): self.activeitem["question"] = self.enterQuestion.text() self.lesson.changed = True
"""Change the description of the active item"""
if self.activeitem["answer"] != self.enterAnswer.text(): self.activeitem["answer"] = self.enterAnswer.text() self.lesson.changed = True
global base
"default": 510, }
self._mm.mods(type="translator"), ) self._mm.mods(type="mediaDisplay"), self._mm.mods(type="ui"), )
global QtCore, QtWidgets except ImportError: return
#setup translation else:
global _ global ngettext
else: self._mm.resourcePath("translations") )
widget = ref() if widget is not None: widget.retranslate()
|