Source code for sibl_gui.components.core.iblSetsOutliner.views

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
**views.py**

**Platform:**
	Windows, Linux, Mac Os X.

**Description:**
	Defines the :class:`sibl_gui.components.core.iblSetsOutliner.iblSetsOutliner.IblSetsOutliner`
	Component Interface class Views.

**Others:**

"""

#**********************************************************************************************************************
#***	Future imports.
#**********************************************************************************************************************
from __future__ import unicode_literals

#**********************************************************************************************************************
#***	External imports.
#**********************************************************************************************************************
from PyQt4.QtCore import QSize
from PyQt4.QtCore import Qt
from PyQt4.QtGui import QAbstractItemView
from PyQt4.QtGui import QListView

#**********************************************************************************************************************
#***	Internal imports.
#**********************************************************************************************************************
import foundations.exceptions
import foundations.verbose
import sibl_gui.ui.views

#**********************************************************************************************************************
#***	Module attributes.
#**********************************************************************************************************************
__author__ = "Thomas Mansencal"
__copyright__ = "Copyright (C) 2008 - 2014 - Thomas Mansencal"
__license__ = "GPL V3.0 - http://www.gnu.org/licenses/"
__maintainer__ = "Thomas Mansencal"
__email__ = "thomas.mansencal@gmail.com"
__status__ = "Production"

__all__ = ["LOGGER", "Thumbnails_QListView", "Details_QTreeView"]

LOGGER = foundations.verbose.installLogger()

#**********************************************************************************************************************
#***	Module classes and definitions.
#**********************************************************************************************************************
[docs]class Thumbnails_QListView(sibl_gui.ui.views.Abstract_QListView): """ Defines the view for Database Ibl Sets as thumbnails. """ def __init__(self, parent, model=None, readOnly=False, message=None): """ Initializes the class. :param parent: Object parent. :type parent: QObject :param model: Model. :type model: QObject :param readOnly: View is read only. :type readOnly: bool :param message: View default message when Model is empty. :type message: unicode """ LOGGER.debug("> Initializing '{0}()' class.".format(self.__class__.__name__)) sibl_gui.ui.views.Abstract_QListView.__init__(self, parent, model, readOnly, message) # --- Setting class attributes. --- self.__listViewSpacing = 24 self.__listViewMargin = 32 Thumbnails_QListView.__initializeUi(self) #****************************************************************************************************************** #*** Attributes properties. #****************************************************************************************************************** @property def listViewSpacing(self): """ Property for **self.__listViewSpacing** attribute. :return: self.__listViewSpacing. :rtype: int """ return self.__listViewSpacing @listViewSpacing.setter # Oncilla: Statement commented by auto-documentation process: @foundations.exceptions.handleExceptions(AssertionError) def listViewSpacing(self, value): """ Setter for **self.__listViewSpacing** attribute. :param value: Attribute value. :type value: int """ if value is not None: assert type(value) is int, "'{0}' attribute: '{1}' type is not 'int'!".format("listViewSpacing", value) assert value > 0, "'{0}' attribute: '{1}' need to be exactly positive!".format("listViewSpacing", value) self.__listViewSpacing = value @listViewSpacing.deleter # Oncilla: Statement commented by auto-documentation process: @foundations.exceptions.handleExceptions(foundations.exceptions.ProgrammingError)
[docs] def listViewSpacing(self): """ Deleter for **self.__listViewSpacing** attribute. """ raise foundations.exceptions.ProgrammingError( "{0} | '{1}' attribute is not deletable!".format(self.__class__.__name__, "listViewSpacing"))
@property def listViewMargin(self): """ Property for **self.__listViewMargin** attribute. :return: self.__listViewMargin. :rtype: int """ return self.__listViewMargin @listViewMargin.setter # Oncilla: Statement commented by auto-documentation process: @foundations.exceptions.handleExceptions(AssertionError) def listViewMargin(self, value): """ Setter for **self.__listViewMargin** attribute. :param value: Attribute value. :type value: int """ if value is not None: assert type(value) is int, "'{0}' attribute: '{1}' type is not 'int'!".format("listViewMargin", value) assert value > 0, "'{0}' attribute: '{1}' need to be exactly positive!".format("listViewMargin", value) self.__listViewMargin = value @listViewMargin.deleter # Oncilla: Statement commented by auto-documentation process: @foundations.exceptions.handleExceptions(foundations.exceptions.ProgrammingError)
[docs] def listViewMargin(self): """ Deleter for **self.__listViewMargin** attribute. """ raise foundations.exceptions.ProgrammingError( "{0} | '{1}' attribute is not deletable!".format(self.__class__.__name__, "listViewMargin")) #****************************************************************************************************************** #*** Class methods. #******************************************************************************************************************
def __initializeUi(self): """ Initializes the Widget ui. """ self.setAutoScroll(True) self.setResizeMode(QListView.Adjust) self.setSelectionMode(QAbstractItemView.ExtendedSelection) self.setViewMode(QListView.IconMode) # Previous statement sets the dragDropMode to "QAbstractItemView.DragDrop". self.setDragDropMode(QAbstractItemView.DragOnly) self.__setDefaultUiState() # Signals / Slots. self.model().modelReset.connect(self.__setDefaultUiState) def __setDefaultUiState(self, iconsSize=None, iconsRatio=2): """ Sets the Widget default ui state. :param iconsSize: Icons size. :type iconsSize: int :param iconRatio: Icons ratio. :type iconRatio: int """ LOGGER.debug("> Setting default View state!") if not iconsSize: return self.setIconSize(QSize(iconsSize, iconsSize / iconsRatio)) self.setGridSize(QSize(iconsSize + self.__listViewSpacing, iconsSize / iconsRatio + self.__listViewMargin)) self.viewport().update()
[docs]class Details_QTreeView(sibl_gui.ui.views.Abstract_QTreeView): """ Defines the view for Database Ibl Sets columns. """ def __init__(self, parent, model=None, readOnly=False, message=None): """ Initializes the class. :param parent: Object parent. :type parent: QObject :param model: Model. :type model: QObject :param readOnly: View is read only. :type readOnly: bool :param message: View default message when Model is empty. :type message: unicode """ LOGGER.debug("> Initializing '{0}()' class.".format(self.__class__.__name__)) sibl_gui.ui.views.Abstract_QTreeView.__init__(self, parent, model, readOnly, message) # --- Setting class attributes. --- self.__treeViewIndentation = 15 Details_QTreeView.__initializeUi(self) #****************************************************************************************************************** #*** Attributes properties. #****************************************************************************************************************** @property def treeViewIndentation(self): """ Property for **self.__treeViewIndentation** attribute. :return: self.__treeViewIndentation. :rtype: int """ return self.__treeViewIndentation @treeViewIndentation.setter # Oncilla: Statement commented by auto-documentation process: @foundations.exceptions.handleExceptions(foundations.exceptions.ProgrammingError) def treeViewIndentation(self, value): """ Setter for **self.__treeViewIndentation** attribute. :param value: Attribute value. :type value: int """ raise foundations.exceptions.ProgrammingError( "{0} | '{1}' attribute is read only!".format(self.__class__.__name__, "treeViewIndentation")) @treeViewIndentation.deleter # Oncilla: Statement commented by auto-documentation process: @foundations.exceptions.handleExceptions(foundations.exceptions.ProgrammingError)
[docs] def treeViewIndentation(self): """ Deleter for **self.__treeViewIndentation** attribute. """ raise foundations.exceptions.ProgrammingError( "{0} | '{1}' attribute is not deletable!".format(self.__class__.__name__, "treeViewIndentation")) #****************************************************************************************************************** #*** Class methods. #******************************************************************************************************************
def __initializeUi(self): """ Initializes the Widget ui. """ self.setAutoScroll(True) self.setSelectionMode(QAbstractItemView.ExtendedSelection) self.setIndentation(self.__treeViewIndentation) self.setRootIsDecorated(False) self.setDragDropMode(QAbstractItemView.DragOnly) self.setSortingEnabled(True) self.sortByColumn(0, Qt.AscendingOrder) self.__setDefaultUiState() # Signals / Slots. self.model().modelReset.connect(self.__setDefaultUiState) def __setDefaultUiState(self): """ Sets the Widget default ui state. """ LOGGER.debug("> Setting default View state!") if not self.model(): return self.expandAll() for column in range(len(self.model().horizontalHeaders)): self.resizeColumnToContents(column)