Coverage for modules/org/openteacher/interfaces/qt/gui/gui : 73%
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, 2017, Marten de Vries # Copyright 2011, 2017, 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/>.
"""A high-level interface to a menu and/or a toolbar item."""
#lambda to prevent useless Qt arguments to pass
self._qtMenu.removeAction(self._qtAction) self._qtMenu.menuActions.remove(self._qtAction)
lambda self: self._qtAction.text(), lambda self, value: self._qtAction.setText(value) )
lambda self: self._qtMenu.isEnabled(), lambda self, value: self._qtAction.setEnabled(value) )
"""A high-level interface to a menu (as in File, Edit, etc.)."""
actions = sorted( self._qtMenu.menuActions, key=lambda a: getattr(a, "menuPriority", 0) ) for action in actions: if getattr(action, "menuPriority", 0) > priority: return action #explicit is better than implicit return None
qtAction = QtWidgets.QAction(self._qtMenu) qtAction.menuPriority = priority self._qtMenu.insertAction(self._actionAfter(priority), qtAction) self._qtMenu.menuActions.add(qtAction) return Action(self._createEvent, self._qtMenu, qtAction)
qtSubMenu = QtWidgets.QMenu() self._qtMenu.insertMenu(self._actionAfter(priority), qtSubMenu) return Menu(self._createEvent, qtSubMenu)
self._qtMenu.hide()
lambda self: self._qtMenu.title(), lambda self, value: self._qtMenu.setTitle(value) )
lambda self: self._qtMenu.isEnabled(), lambda self, value: self._qtMenu.setEnabled(value) )
"""A high-level interface to the status bar."""
self._statusBar.showMessage(message)
type="event" ).createEvent()
#the mac os x case closeButton = tabBar.tabButton(self._index, QtWidgets.QTabBar.LeftSide)
def wrapperWidget(self): return self._widget.wrapperWidget
def _index(self):
self._tabWidget.removeTab(self._index) if self._lastWidget: self._tabWidget.setCurrentWidget(self._lastWidget)
lambda self: self._tabWidget.tabText(self._index), lambda self, val: self._tabWidget.setTabText(self._index, val) )
#properties are defined in parent class
"""Called by the uiController module."""
lambda self: self._widget.currentWidget(), lambda self, value: self._widget.setCurrentWidget(value) )
self._mm.mods(type="event"), self._mm.mods(type="startWidget"), self._mm.mods(type="metadata"), ) self._mm.mods(type="buttonRegister"), self._mm.mods(type="translator"), self._mm.mods(type="settings"), # silences 'QtWebEngineWidgets must be imported before a # QCoreApplication instance is created' error message self._mm.mods(type='webEngine'), ) "gtk": -1, }
QtCore.QtDebugMsg: qtLogger.debug, QtCore.QtWarningMsg: qtLogger.warning, QtCore.QtCriticalMsg: qtLogger.critical, QtCore.QtFatalMsg: qtLogger.critical, QtCore.QtSystemMsg: qtLogger.critical, }[type]
global QtCore, QtGui, QtWidgets except ImportError as e: print(e) return
#if on a system that could potentially support X11, but #doesn't have it installed/running, leave this mod disabled. #Otherwise the whole application crashes on a 'Can't connect #to display' error message. # #checking for x11EventFilter because that is only defined #when Q_WS_X11 is set. No other way as far as I know to get #the value of that macro. :( return
#prevents that calling enable() and disable() multiple times #segfaults.
"This ``Event`` allows you to detect when the user " + "switches to another tab." ) "Handlers of this ``Event`` are called whenever the user " + "is switching between OpenTeacher and some other " + "program. They get one argument: ``'active'`` or " + "``'inactive'`` depending on if the user started to use " + "OpenTeacher or stopped using it." )
#try to load translations for Qt itself "qt_" + QtCore.QLocale.system().name(), QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.TranslationsPath) )
self._modules.default("active", type="startWidget").createStartWidget(), self._onCloseRequested )
except IndexError: pass else: #add the open action as a load button too. #always the load button first.
#add a documentation button
#Make menus accessable #file
#edit
#view
#help
lambda activity: self.applicationActivityChanged.send( "active" if activity else "inactive" ) )
#make the statusViewer available
#set application name (handy for e.g. Phonon)
#load translator else:
#when adding a tab, this triggers a bit too early. Because of #that, it's called manually by the functions that add a tab.
except IndexError: pass else: #we don't unhandle the event, since PyQt5 does some weird #memory stuff making it impossible to find the right item, #and it's unneeded anyway.
global _ global ngettext
else: self._mm.resourcePath("translations") )
"""Starts the event loop of the Qt application. Can only be called once.
""" self._closeCallback = onCloseRequested
self._widget.show() self._app.exec_()
#if not running, there's nothing that can be closed, so don't #check if the method exists. (The callback is assigned in #run().) return self._closeCallback()
"""Closes all windows currently opened. (Including windows from other modules.)
""" self._app.closeAllWindows()
"""Enables or disables full screen depending on the ``bool`` argument.
""" #native menubar enable/disable to keep it into view while #fullscreen in at least unity. if bool: self._widget.menuBar().setNativeMenuBar(False) self._widget.showFullScreen() else: if platform.linux_distribution()[0] != "Ubuntu": #on Unity, we don't re-enable the native menu bar, #because a re-enabled native menu bar doesn't work ok. self._widget.menuBar().setNativeMenuBar(True) self._widget.showNormal()
def startTab(self): """Gives access to the start tab widget."""
return self._widget.tabWidget.startWidget
"""Changes the current tab to be the same as the one shown on application start.
""" self._widget.tabWidget.setCurrentWidget(self._widget.tabWidget.startWidget.wrapperWidget)
"""The same as ``addCustomTab``, except that it takes three widgets (one for enteringItems, on for teaching them and one for showing the teaching results) that are combined into a single tab.
"""
"""Adds ``widget`` as a tab in the main window. If ``previousTabOnClose`` is true, the currently visible tab is shown again when the created tab is closed.
"""
lastWidget = self._widget.tabWidget.currentWidget() else:
else:
def currentFileTab(self): """Gives access to the currently shown file tab (if any, otherwise this returns ``None``.)
""" try: return self._fileTabs[self._widget.tabWidget.currentWidget()] except KeyError: return
def currentFileTab(self, value): #reverse dictionary lookup. for widget, fileTab in self._fileTabs.items(): if fileTab == value: self._widget.tabWidget.setCurrentWidget(widget)
"""Adds global Qt style sheet rules to the current QApplication. An example use is to theme OpenTeacher.
""" self._app.setStyleSheet(self._app.styleSheet() + "\n\n" + rules)
"""Allows you to set an app-wide QStyle. Handy for theming."""
self._app.setStyle(style)
def qtParent(self): """Only use this as widget parent, or for application global Qt settings, and don't be surprised if another module sets that setting differently.
"""
def startTabActive(self): """Tells you if the start tab is active at the moment this property is accessed.
""" return self._widget.tabWidget.startWidget.wrapperWidget == self._widget.tabWidget.currentWidget()
|