Source code for vdat.gui.tabs.interface

# Virus Data Analysis Tool: a data reduction GUI for HETDEX/VIRUS data
# Copyright (C) 2016, 2017  "The HETDEX collaboration"
#
# This program 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.
#
# This program 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 this program.  If not, see <https://www.gnu.org/licenses/>.
'''Tab class interface and plugin function prototype'''

from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

from qtpy import QtWidgets
from qtpy.QtCore import Signal, Slot


[docs]def plugin_interface(target_dir, tab_dict, step_name, cache, parent_widget): '''Interface of the functions implementing the plugin. Each tab type must implement a function with the this signature and can be advertised via the ``vdat.tab_types`` entry point. Parameters ---------- target_dir : string directory selected by the user tab_dict : dictionary dictionary with the specifications to use to build the tabs step_name : string name of the step to which the tab(s) belong cache : :class:`vdat.gui.fplane.FplaneCache` instance cache object parent_widget : :class:`PyQt5.QtWidgets.QWidget` or derivate parent object of the tabs Returns ------- list instances to be plugged into the :class:`~vdat.gui.fplane.FplaneWidget` as tabs; they should be derived from :class:`~vdat.gui.tabs.interface.FplaneTabTemplate` or implement the same interface. ''' pass
[docs]class FplaneTabTemplate(QtWidgets.QWidget): """Template class representing a tab in the focal plane. All the classes should be either derived from this one or implement the same interface .. list-table:: **Custom signals** :header-rows: 1 * - Name - Signature - Description * - :attr:`sig_ifuToggled` - str, bool - emitted when a user selects/deselects an IFU; the parameters are the SLOTID of the IFU and whether the IFU has been selected .. list-table:: **Custom slot** :header-rows: 1 * - Name - Signature - Description * - :meth:`ifuSelected` - str, bool - selects (second argument ``True``)/deselects (second argument ``False``) an IFU, whose ``SLOTID`` is given in the first argument. * - :meth:`selectAllIFUs` - - selects all IFUs * - :meth:`deselectAllIFUs` - - deselect all IFUs Parameters ---------- tab_type : str a name of the tab as advertised in the entry points. When implementing the plugins, care must be taken to pass the correct tab type to allow caching. The ``tab_type`` is passed to :func:`plugin_interface` parent : :class:`PyQt5.QtWidgets.QWidget` or derivate parent object of the tree view model Attributes ---------- tab_type : str name of tab type; if required, the instance is cached and should be retrieved under this name. By default is set to the ``tab_type`` name passed to :class:`FplaneTabTemplate`. use_cache : bool indicate whether the instance can be cached after popping it from the list of tabs. This must be implemented in all derived classes as an attribute or property. title : string title to assign to the tab containing the widget. This must be implemented in all derived classes as an attribute or property. tool_tip : string, optional if present, is used as the string for the tooltip associated with the current tab enabled : bool, optional whether the table is enabled or not. If not present default to True """ sig_ifuToggled = Signal(str, bool) def __init__(self, tab_type, parent=None): super(FplaneTabTemplate, self).__init__(parent=parent) self.tab_type = tab_type def __getattr__(self, name): '''Make sure that subclasses implement the 'use_cache' and 'title' attributes. If they are not found, raise ``NotImplementedError``, else defer to the standard mechanism. ''' if name in ['use_cache', 'title']: raise NotImplementedError('``{}`` must be' 'implemented'.format(name)) else: raise AttributeError("'{}' object has no attribute" " '{}'".format(self.__class__.__name__, name))
[docs] def cleanup(self): '''Cleanup method called when a tab is popped. The default implementation hides the widget.''' self.hide()
[docs] @Slot(str, bool) def ifuSelected(self, ifuslot, val): """Select or deselect an IFU. This method is also a PyQt slot. The current implementation does nothing. Reimplement it to react to the :attr:`vdat.gui.fplane.FplaneWidget.sig_ifuSelected` signal. This slot is automatically connected and disconnected when plugging and popping a tab. Parameters ---------- ifuslot : string SLOTID of the selected IFU val : bool If ``True`` selected, otherwise deselected """ pass
[docs] @Slot() def selectAllIFUs(self): """Select all IFU. This method is also a PyQt slot. The current implementation does nothing. Reimplement it to react to the :attr:`vdat.gui.fplane.FplaneWidget.sig_selectAllIFUs` signal. This slot is automatically connected and disconnected when plugging and popping a tab. """ pass
[docs] @Slot() def deselectAllIFUs(self): """Deselect all IFU. This method is also a PyQt slot. The current implementation does nothing. Reimplement it to react to the :attr:`vdat.gui.fplane.FplaneWidget.sig_deselectAllIFUs` signal. This slot is automatically connected and disconnected when plugging and popping a tab. """ pass