Esempio n. 1
0
    def __init__(
        self, parent=None, uiSearchImage=None, uiSearchClickedImage=None, uiClearImage=None, uiClearClickedImage=None
    ):
        """
		Initializes the class.

		:param parent: Widget parent.
		:type parent: QObject
		:param uiSearchImage: Search button image path.
		:type uiSearchImage: str
		:param uiSearchClickedImage: Search button clicked image path.
		:type uiSearchClickedImage: str
		:param uiClearImage: Clear button image path.
		:type uiClearImage: str
		:param uiClearClickedImage: Clear button clicked image path.
		:type uiClearClickedImage: str
		"""

        LOGGER.debug("> Initializing '{0}()' class.".format(self.__class__.__name__))

        QLineEdit.__init__(self, parent)

        # --- Setting class attributes. ---
        self.__uiSearchImage = None
        self.uiSearchImage = uiSearchImage or umbra.ui.common.getResourcePath("images/Search_Glass.png")
        self.__uiSearchClickedImage = None
        self.uiSearchClickedImage = uiSearchClickedImage or umbra.ui.common.getResourcePath(
            "images/Search_Glass_Clicked.png"
        )
        self.__uiClearImage = None
        self.uiClearImage = uiClearImage or umbra.ui.common.getResourcePath("images/Search_Clear.png")
        self.__uiClearClickedImage = None
        self.uiClearClickedImage = uiClearClickedImage or umbra.ui.common.getResourcePath(
            "images/Search_Clear_Clicked.png"
        )

        self.__searchActiveLabel = Active_QLabel(
            self, QPixmap(self.__uiSearchImage), QPixmap(self.__uiSearchImage), QPixmap(self.__uiSearchClickedImage)
        )
        self.__searchActiveLabel.setObjectName("Search_Field_activeLabel")
        self.__searchActiveLabel.showEvent = lambda event: reduce(
            lambda *args: None, (self.__setStyleSheet(), Active_QLabel.showEvent(self.__searchActiveLabel, event))
        )
        self.__searchActiveLabel.hideEvent = lambda event: reduce(
            lambda *args: None, (self.__setStyleSheet(), Active_QLabel.hideEvent(self.__searchActiveLabel, event))
        )

        self.__clearButton = QToolButton(self)
        self.__clearButton.setObjectName("Clear_Field_button")

        self.__completer = QCompleter()
        self.setCompleter(self.__completer)
        self.__completerVisibleItemsCount = 16

        Search_QLineEdit.__initializeUi(self)
        self.__setClearButtonVisibility(self.text())

        # Signals / Slots.
        self.__clearButton.clicked.connect(self.clear)
        self.textChanged.connect(self.__setClearButtonVisibility)
Esempio n. 2
0
	def getMiscellaneousActiveLabel(self):
		"""
		Provides the default **Miscellaneous_activeLabel** widget.

		:return: Miscellaneous active label.
		:rtype: Active_QLabel
		"""

		miscellaneousActiveLabel = Active_QLabel(self,
											QPixmap(umbra.ui.common.getResourcePath(UiConstants.miscellaneousIcon)),
											QPixmap(umbra.ui.common.getResourcePath(UiConstants.miscellaneousHoverIcon)),
											QPixmap(umbra.ui.common.getResourcePath(UiConstants.miscellaneousActiveIcon)))
		miscellaneousActiveLabel.setObjectName("Miscellaneous_activeLabel")

		self.__miscellaneousMenu = QMenu("Miscellaneous", miscellaneousActiveLabel)

		self.__miscellaneousMenu.addAction(self.__container.actionsManager.registerAction(
											"Actions|Umbra|ToolBar|Miscellaneous|Help content ...",
											shortcut="F1",
											slot=self.__helpDisplayMiscAction__triggered))
		self.__miscellaneousMenu.addAction(self.__container.actionsManager.registerAction(
											"Actions|Umbra|ToolBar|Miscellaneous|Api content ...",
											slot=self.__apiDisplayMiscAction__triggered))
		self.__miscellaneousMenu.addSeparator()

		miscellaneousActiveLabel.setMenu(self.__miscellaneousMenu)
		return miscellaneousActiveLabel
	def getCentralWidgetActiveLabel(self):
		"""
		This method provides the default **Central_Widget_activeLabel** widget.

		:return: Central Widget active label. ( Active_QLabel )
		"""

		centralWidgetButton = Active_QLabel(self,
											QPixmap(umbra.ui.common.getResourcePath(UiConstants.centralWidgetIcon)),
											QPixmap(umbra.ui.common.getResourcePath(UiConstants.centralWidgetHoverIcon)),
											QPixmap(umbra.ui.common.getResourcePath(UiConstants.centralWidgetActiveIcon)))
		centralWidgetButton.setObjectName("Central_Widget_activeLabel")

		# Signals / Slots.
		centralWidgetButton.clicked.connect(self.__centralWidgetButton__clicked)
		return centralWidgetButton
Esempio n. 4
0
	def getCustomLayoutsActiveLabel(self):
		"""
		Provides the default **Custom_Layouts_activeLabel** widget.

		:return: Layout active label.
		:rtype: Active_QLabel
		"""

		layoutActiveLabel = Active_QLabel(self, QPixmap(umbra.ui.common.getResourcePath(UiConstants.customLayoutsIcon)),
									QPixmap(umbra.ui.common.getResourcePath(UiConstants.customLayoutsHoverIcon)),
									QPixmap(umbra.ui.common.getResourcePath(UiConstants.customLayoutsActiveIcon)))
		layoutActiveLabel.setObjectName("Custom_Layouts_activeLabel")

		self.__customLayoutsMenu = QMenu("Layouts", layoutActiveLabel)

		for layout in self.__userLayouts:
			self.__container.layoutsManager.registerLayout(layout.identity, layout)
			self.__customLayoutsMenu.addAction(self.__container.actionsManager.registerAction(
			"Actions|Umbra|ToolBar|Layouts|Restore layout {0}".format(layout.name),
			shortcut=layout.shortcut,
			slot=functools.partial(self.__container.layoutsManager.restoreLayout, layout.identity)))

		self.__customLayoutsMenu.addSeparator()

		for layout in self.__userLayouts:
			self.__customLayoutsMenu.addAction(self.__container.actionsManager.registerAction(
			"Actions|Umbra|ToolBar|Layouts|Store layout {0}".format(layout.name),
			shortcut=Qt.CTRL + layout.shortcut,
			slot=functools.partial(self.__container.layoutsManager.storeLayout, layout.identity)))

		self.__customLayoutsMenu.addSeparator()

		self.__customLayoutsMenu.addAction(self.__container.actionsManager.registerAction(
		"Actions|Umbra|ToolBar|Layouts|Toggle FullScreen",
		shortcut=Qt.ControlModifier + Qt.SHIFT + Qt.Key_F,
		slot=self.__container.toggleFullScreen))

		layoutActiveLabel.setMenu(self.__customLayoutsMenu)
		return layoutActiveLabel
Esempio n. 5
0
	def getLayoutActiveLabel(self, resources, name, title, identity, shortcut):
		"""
		Returns a layout **Active_QLabel** widget.

		:param resources: Icons resources ( Default / Hover / Active ).
		:type resources: tuple
		:param name: Ui object name.
		:type name: unicode
		:param title: Layout registration title.
		:type title: unicode
		:param identity: Layout code name.
		:type identity: unicode
		:param shortcut: Layout associated shortcut. ( QtCore.Key )
		:return: Layout active label.
		:rtype: Active_QLabel
		"""

		defaultIcon, hoverIcon, activeIcon = resources
		layoutActiveLabel = Active_QLabel(self,
										QPixmap(umbra.ui.common.getResourcePath(defaultIcon)),
										QPixmap(umbra.ui.common.getResourcePath(hoverIcon)),
										QPixmap(umbra.ui.common.getResourcePath(activeIcon)),
										True)
		self.__container.layoutsManager.registerLayout(identity, umbra.managers.layoutsManager.Layout(name=title,
																								identity=identity,
																								shortcut=shortcut))
		self.__container.addAction(
		self.__container.actionsManager.registerAction("Actions|Umbra|ToolBar|Layouts|Restore layout {0}".format(title),
														shortcut=shortcut,
														shortcutContext=Qt.ApplicationShortcut,
														slot=functools.partial(
														self.__container.layoutsManager.restoreLayout, identity)))

		layoutActiveLabel.setObjectName(name)

		# Signals / Slots.
		layoutActiveLabel.clicked.connect(functools.partial(self.__layoutActiveLabel__clicked, identity))

		return layoutActiveLabel
Esempio n. 6
0
class Search_QLineEdit(QLineEdit):
    """
	Defines a `QLineEdit <http://doc.qt.nokia.com/qlinedit.html>`_ subclass providing
	a search field with clearing capabilities.
	"""

    def __init__(
        self, parent=None, uiSearchImage=None, uiSearchClickedImage=None, uiClearImage=None, uiClearClickedImage=None
    ):
        """
		Initializes the class.

		:param parent: Widget parent.
		:type parent: QObject
		:param uiSearchImage: Search button image path.
		:type uiSearchImage: str
		:param uiSearchClickedImage: Search button clicked image path.
		:type uiSearchClickedImage: str
		:param uiClearImage: Clear button image path.
		:type uiClearImage: str
		:param uiClearClickedImage: Clear button clicked image path.
		:type uiClearClickedImage: str
		"""

        LOGGER.debug("> Initializing '{0}()' class.".format(self.__class__.__name__))

        QLineEdit.__init__(self, parent)

        # --- Setting class attributes. ---
        self.__uiSearchImage = None
        self.uiSearchImage = uiSearchImage or umbra.ui.common.getResourcePath("images/Search_Glass.png")
        self.__uiSearchClickedImage = None
        self.uiSearchClickedImage = uiSearchClickedImage or umbra.ui.common.getResourcePath(
            "images/Search_Glass_Clicked.png"
        )
        self.__uiClearImage = None
        self.uiClearImage = uiClearImage or umbra.ui.common.getResourcePath("images/Search_Clear.png")
        self.__uiClearClickedImage = None
        self.uiClearClickedImage = uiClearClickedImage or umbra.ui.common.getResourcePath(
            "images/Search_Clear_Clicked.png"
        )

        self.__searchActiveLabel = Active_QLabel(
            self, QPixmap(self.__uiSearchImage), QPixmap(self.__uiSearchImage), QPixmap(self.__uiSearchClickedImage)
        )
        self.__searchActiveLabel.setObjectName("Search_Field_activeLabel")
        self.__searchActiveLabel.showEvent = lambda event: reduce(
            lambda *args: None, (self.__setStyleSheet(), Active_QLabel.showEvent(self.__searchActiveLabel, event))
        )
        self.__searchActiveLabel.hideEvent = lambda event: reduce(
            lambda *args: None, (self.__setStyleSheet(), Active_QLabel.hideEvent(self.__searchActiveLabel, event))
        )

        self.__clearButton = QToolButton(self)
        self.__clearButton.setObjectName("Clear_Field_button")

        self.__completer = QCompleter()
        self.setCompleter(self.__completer)
        self.__completerVisibleItemsCount = 16

        Search_QLineEdit.__initializeUi(self)
        self.__setClearButtonVisibility(self.text())

        # Signals / Slots.
        self.__clearButton.clicked.connect(self.clear)
        self.textChanged.connect(self.__setClearButtonVisibility)

        # ******************************************************************************************************************
        # ***	Attributes properties.
        # ******************************************************************************************************************

    @property
    def uiSearchImage(self):
        """
		Property for **self.__uiSearchImage** attribute.

		:return: self.__uiSearchImage.
		:rtype: str
		"""

        return self.__uiSearchImage

    @uiSearchImage.setter
    @foundations.exceptions.handleExceptions(AssertionError)
    def uiSearchImage(self, value):
        """
		Setter for **self.__uiSearchImage** attribute.

		:param value: Attribute value.
		:type value: str
		"""

        if value is not None:
            assert type(value) is unicode, "'{0}' attribute: '{1}' type is not 'unicode'!".format(
                "uiSearchImage", value
            )
            assert os.path.exists(value), "'{0}' attribute: '{1}' file doesn't exists!".format("uiSearchImage", value)
        self.__uiSearchImage = value

    @uiSearchImage.deleter
    @foundations.exceptions.handleExceptions(foundations.exceptions.ProgrammingError)
    def uiSearchImage(self):
        """
		Deleter for **self.__uiSearchImage** attribute.
		"""

        raise foundations.exceptions.ProgrammingError(
            "{0} | '{1}' attribute is not deletable!".format(self.__class__.__name__, "uiSearchImage")
        )

    @property
    def uiSearchClickedImage(self):
        """
		Property for **self.__uiSearchClickedImage** attribute.

		:return: self.__uiSearchClickedImage.
		:rtype: str
		"""

        return self.__uiSearchClickedImage

    @uiSearchClickedImage.setter
    @foundations.exceptions.handleExceptions(AssertionError)
    def uiSearchClickedImage(self, value):
        """
		Setter for **self.__uiSearchClickedImage** attribute.

		:param value: Attribute value.
		:type value: str
		"""

        if value is not None:
            assert type(value) is unicode, "'{0}' attribute: '{1}' type is not 'unicode'!".format(
                "uiSearchClickedImage", value
            )
            assert os.path.exists(value), "'{0}' attribute: '{1}' file doesn't exists!".format(
                "uiSearchClickedImage", value
            )
        self.__uiSearchClickedImage = value

    @uiSearchClickedImage.deleter
    @foundations.exceptions.handleExceptions(foundations.exceptions.ProgrammingError)
    def uiSearchClickedImage(self):
        """
		Deleter for **self.__uiSearchClickedImage** attribute.
		"""

        raise foundations.exceptions.ProgrammingError(
            "{0} | '{1}' attribute is not deletable!".format(self.__class__.__name__, "uiSearchClickedImage")
        )

    @property
    def uiClearImage(self):
        """
		Property for **self.__uiClearImage** attribute.

		:return: self.__uiClearImage.
		:rtype: str
		"""

        return self.__uiClearImage

    @uiClearImage.setter
    @foundations.exceptions.handleExceptions(AssertionError)
    def uiClearImage(self, value):
        """
		Setter for **self.__uiClearImage** attribute.

		:param value: Attribute value.
		:type value: str
		"""

        if value is not None:
            assert type(value) is unicode, "'{0}' attribute: '{1}' type is not 'unicode'!".format("uiClearImage", value)
            assert os.path.exists(value), "'{0}' attribute: '{1}' file doesn't exists!".format("uiClearImage", value)
        self.__uiClearImage = value

    @uiClearImage.deleter
    @foundations.exceptions.handleExceptions(foundations.exceptions.ProgrammingError)
    def uiClearImage(self):
        """
		Deleter for **self.__uiClearImage** attribute.
		"""

        raise foundations.exceptions.ProgrammingError(
            "{0} | '{1}' attribute is not deletable!".format(self.__class__.__name__, "uiClearImage")
        )

    @property
    def uiClearClickedImage(self):
        """
		Property for **self.__uiClearClickedImage** attribute.

		:return: self.__uiClearClickedImage.
		:rtype: str
		"""

        return self.__uiClearClickedImage

    @uiClearClickedImage.setter
    @foundations.exceptions.handleExceptions(AssertionError)
    def uiClearClickedImage(self, value):
        """
		Setter for **self.__uiClearClickedImage** attribute.

		:param value: Attribute value.
		:type value: str
		"""

        if value is not None:
            assert type(value) is unicode, "'{0}' attribute: '{1}' type is not 'unicode'!".format(
                "uiClearClickedImage", value
            )
            assert os.path.exists(value), "'{0}' attribute: '{1}' file doesn't exists!".format(
                "uiClearClickedImage", value
            )
        self.__uiClearClickedImage = value

    @uiClearClickedImage.deleter
    @foundations.exceptions.handleExceptions(foundations.exceptions.ProgrammingError)
    def uiClearClickedImage(self):
        """
		Deleter for **self.__uiClearClickedImage** attribute.
		"""

        raise foundations.exceptions.ProgrammingError(
            "{0} | '{1}' attribute is not deletable!".format(self.__class__.__name__, "uiClearClickedImage")
        )

    @property
    def searchActiveLabel(self):
        """
		Property for **self.__searchActiveLabel** attribute.

		:return: self.__searchActiveLabel.
		:rtype: QPushButton
		"""

        return self.__searchActiveLabel

    @searchActiveLabel.setter
    @foundations.exceptions.handleExceptions(foundations.exceptions.ProgrammingError)
    def searchActiveLabel(self, value):
        """
		Setter for **self.__searchActiveLabel** attribute.

		:param value: Attribute value.
		:type value: QPushButton
		"""

        raise foundations.exceptions.ProgrammingError(
            "{0} | '{1}' attribute is read only!".format(self.__class__.__name__, "searchActiveLabel")
        )

    @searchActiveLabel.deleter
    @foundations.exceptions.handleExceptions(foundations.exceptions.ProgrammingError)
    def searchActiveLabel(self):
        """
		Deleter for **self.__searchActiveLabel** attribute.
		"""

        raise foundations.exceptions.ProgrammingError(
            "{0} | '{1}' attribute is not deletable!".format(self.__class__.__name__, "searchActiveLabel")
        )

    @property
    def clearButton(self):
        """
		Property for **self.__clearButton** attribute.

		:return: self.__clearButton.
		:rtype: QPushButton
		"""

        return self.__clearButton

    @clearButton.setter
    @foundations.exceptions.handleExceptions(foundations.exceptions.ProgrammingError)
    def clearButton(self, value):
        """
		Setter for **self.__clearButton** attribute.

		:param value: Attribute value.
		:type value: QPushButton
		"""

        raise foundations.exceptions.ProgrammingError(
            "{0} | '{1}' attribute is read only!".format(self.__class__.__name__, "clearButton")
        )

    @clearButton.deleter
    @foundations.exceptions.handleExceptions(foundations.exceptions.ProgrammingError)
    def clearButton(self):
        """
		Deleter for **self.__clearButton** attribute.
		"""

        raise foundations.exceptions.ProgrammingError(
            "{0} | '{1}' attribute is not deletable!".format(self.__class__.__name__, "clearButton")
        )

    @property
    def completer(self):
        """
		Property for **self.__completer** attribute.

		:return: self.__completer.
		:rtype: QCompleter
		"""

        return self.__completer

    @completer.setter
    @foundations.exceptions.handleExceptions(foundations.exceptions.ProgrammingError)
    def completer(self, value):
        """
		Setter for **self.__completer** attribute.

		:param value: Attribute value.
		:type value: QCompleter
		"""

        raise foundations.exceptions.ProgrammingError(
            "{0} | '{1}' attribute is read only!".format(self.__class__.__name__, "completer")
        )

    @completer.deleter
    @foundations.exceptions.handleExceptions(foundations.exceptions.ProgrammingError)
    def completer(self):
        """
		Deleter for **self.__completer** attribute.
		"""

        raise foundations.exceptions.ProgrammingError(
            "{0} | '{1}' attribute is not deletable!".format(self.__class__.__name__, "completer")
        )

    @property
    def completerVisibleItemsCount(self):
        """
		Property for **self.__completerVisibleItemsCount** attribute.

		:return: self.__completerVisibleItemsCount.
		:rtype: int
		"""

        return self.__completerVisibleItemsCount

    @completerVisibleItemsCount.setter
    @foundations.exceptions.handleExceptions(foundations.exceptions.ProgrammingError)
    def completerVisibleItemsCount(self, value):
        """
		Setter for **self.__completerVisibleItemsCount** attribute.

		:param value: Attribute value.
		:type value: int
		"""

        raise foundations.exceptions.ProgrammingError(
            "{0} | '{1}' attribute is read only!".format(self.__class__.__name__, "completerVisibleItemsCount")
        )

    @completerVisibleItemsCount.deleter
    @foundations.exceptions.handleExceptions(foundations.exceptions.ProgrammingError)
    def completerVisibleItemsCount(self):
        """
		Deleter for **self.__completerVisibleItemsCount** attribute.
		"""

        raise foundations.exceptions.ProgrammingError(
            "{0} | '{1}' attribute is not deletable!".format(self.__class__.__name__, "completerVisibleItemsCount")
        )

        # ******************************************************************************************************************
        # ***	Class methods.
        # ******************************************************************************************************************

    def resizeEvent(self, event):
        """
		Reimplements the :meth:`QLineEdit.QResizeEvent` method.

		:param event: Resize event.
		:type event: QResizeEvent
		"""

        frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
        searchActiveLabelSize = self.__searchActiveLabel.sizeHint()
        self.__searchActiveLabel.move(
            self.rect().left() + frameWidth,
            (self.rect().bottom() - searchActiveLabelSize.height()) / 2 + frameWidth / 2,
        )
        clearButtonSize = self.__clearButton.sizeHint()
        self.__clearButton.move(
            self.rect().right() - frameWidth - clearButtonSize.width(),
            (self.rect().bottom() - clearButtonSize.height()) / 2 + frameWidth / 2,
        )

    def __initializeUi(self):
        """
		Initializes the Widget ui.
		"""

        self.__clearButton.setCursor(Qt.ArrowCursor)
        if self.__uiClearImage and self.__uiClearClickedImage:
            pixmap = QPixmap(self.__uiClearImage)
            clickedPixmap = QPixmap(self.__uiClearClickedImage)
            self.__clearButton.setIcon(QIcon(pixmap))
            self.__clearButton.setMaximumSize(pixmap.size())

            # Signals / Slots.
            self.__clearButton.pressed.connect(functools.partial(self.__clearButton.setIcon, QIcon(clickedPixmap)))
            self.__clearButton.released.connect(functools.partial(self.__clearButton.setIcon, QIcon(pixmap)))
        else:
            self.__clearButton.setText("Clear")

        self.__setStyleSheet()

        frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
        self.setMinimumSize(
            max(self.minimumSizeHint().width(), self.__clearButton.sizeHint().height() + frameWidth * 2),
            max(self.minimumSizeHint().height(), self.__clearButton.sizeHint().height() + frameWidth * 2),
        )

        self.__completer.setCaseSensitivity(Qt.CaseInsensitive)
        self.__completer.setCompletionMode(QCompleter.UnfilteredPopupCompletion)
        # self.__completer.setMaxVisibleItems(self.__completerVisibleItemsCount)

    def __setStyleSheet(self):
        """
		Sets the Widget stylesheet.
		"""

        frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
        self.setStyleSheet(
            QString(
                "QLineEdit {{ padding-left: {0}px; padding-right: {1}px; }}\nQToolButton {{ border: none; padding: 0px; }}".format(
                    self.__searchActiveLabel.sizeHint().width()
                    if self.__searchActiveLabel.isVisible()
                    else 0 + frameWidth,
                    self.__clearButton.sizeHint().width() + frameWidth,
                )
            )
        )

    def __setClearButtonVisibility(self, text):
        """
		Sets the clear button visibility.

		:param text: Current field text.
		:type text: QString
		"""

        if text:
            self.__clearButton.show()
        else:
            self.__clearButton.hide()
Esempio n. 7
0
    def __init__(self,
                 parent=None,
                 uiSearchImage=None,
                 uiSearchClickedImage=None,
                 uiClearImage=None,
                 uiClearClickedImage=None):
        """
		Initializes the class.

		:param parent: Widget parent.
		:type parent: QObject
		:param uiSearchImage: Search button image path.
		:type uiSearchImage: str
		:param uiSearchClickedImage: Search button clicked image path.
		:type uiSearchClickedImage: str
		:param uiClearImage: Clear button image path.
		:type uiClearImage: str
		:param uiClearClickedImage: Clear button clicked image path.
		:type uiClearClickedImage: str
		"""

        LOGGER.debug("> Initializing '{0}()' class.".format(
            self.__class__.__name__))

        QLineEdit.__init__(self, parent)

        # --- Setting class attributes. ---
        self.__uiSearchImage = None
        self.uiSearchImage = uiSearchImage or umbra.ui.common.getResourcePath(
            "images/Search_Glass.png")
        self.__uiSearchClickedImage = None
        self.uiSearchClickedImage = uiSearchClickedImage or umbra.ui.common.getResourcePath(
            "images/Search_Glass_Clicked.png")
        self.__uiClearImage = None
        self.uiClearImage = uiClearImage or umbra.ui.common.getResourcePath(
            "images/Search_Clear.png")
        self.__uiClearClickedImage = None
        self.uiClearClickedImage = uiClearClickedImage or umbra.ui.common.getResourcePath(
            "images/Search_Clear_Clicked.png")

        self.__searchActiveLabel = Active_QLabel(
            self, QPixmap(self.__uiSearchImage), QPixmap(self.__uiSearchImage),
            QPixmap(self.__uiSearchClickedImage))
        self.__searchActiveLabel.setObjectName("Search_Field_activeLabel")
        self.__searchActiveLabel.showEvent = lambda event: reduce(
            lambda *args: None,
            (self.__setStyleSheet(),
             Active_QLabel.showEvent(self.__searchActiveLabel, event)))
        self.__searchActiveLabel.hideEvent = lambda event: reduce(
            lambda *args: None,
            (self.__setStyleSheet(),
             Active_QLabel.hideEvent(self.__searchActiveLabel, event)))

        self.__clearButton = QToolButton(self)
        self.__clearButton.setObjectName("Clear_Field_button")

        self.__completer = QCompleter()
        self.setCompleter(self.__completer)
        self.__completerVisibleItemsCount = 16

        Search_QLineEdit.__initializeUi(self)
        self.__setClearButtonVisibility(self.text())

        # Signals / Slots.
        self.__clearButton.clicked.connect(self.clear)
        self.textChanged.connect(self.__setClearButtonVisibility)
Esempio n. 8
0
class Search_QLineEdit(QLineEdit):
    """
	Defines a `QLineEdit <http://doc.qt.nokia.com/qlinedit.html>`_ subclass providing
	a search field with clearing capabilities.
	"""
    def __init__(self,
                 parent=None,
                 uiSearchImage=None,
                 uiSearchClickedImage=None,
                 uiClearImage=None,
                 uiClearClickedImage=None):
        """
		Initializes the class.

		:param parent: Widget parent.
		:type parent: QObject
		:param uiSearchImage: Search button image path.
		:type uiSearchImage: str
		:param uiSearchClickedImage: Search button clicked image path.
		:type uiSearchClickedImage: str
		:param uiClearImage: Clear button image path.
		:type uiClearImage: str
		:param uiClearClickedImage: Clear button clicked image path.
		:type uiClearClickedImage: str
		"""

        LOGGER.debug("> Initializing '{0}()' class.".format(
            self.__class__.__name__))

        QLineEdit.__init__(self, parent)

        # --- Setting class attributes. ---
        self.__uiSearchImage = None
        self.uiSearchImage = uiSearchImage or umbra.ui.common.getResourcePath(
            "images/Search_Glass.png")
        self.__uiSearchClickedImage = None
        self.uiSearchClickedImage = uiSearchClickedImage or umbra.ui.common.getResourcePath(
            "images/Search_Glass_Clicked.png")
        self.__uiClearImage = None
        self.uiClearImage = uiClearImage or umbra.ui.common.getResourcePath(
            "images/Search_Clear.png")
        self.__uiClearClickedImage = None
        self.uiClearClickedImage = uiClearClickedImage or umbra.ui.common.getResourcePath(
            "images/Search_Clear_Clicked.png")

        self.__searchActiveLabel = Active_QLabel(
            self, QPixmap(self.__uiSearchImage), QPixmap(self.__uiSearchImage),
            QPixmap(self.__uiSearchClickedImage))
        self.__searchActiveLabel.setObjectName("Search_Field_activeLabel")
        self.__searchActiveLabel.showEvent = lambda event: reduce(
            lambda *args: None,
            (self.__setStyleSheet(),
             Active_QLabel.showEvent(self.__searchActiveLabel, event)))
        self.__searchActiveLabel.hideEvent = lambda event: reduce(
            lambda *args: None,
            (self.__setStyleSheet(),
             Active_QLabel.hideEvent(self.__searchActiveLabel, event)))

        self.__clearButton = QToolButton(self)
        self.__clearButton.setObjectName("Clear_Field_button")

        self.__completer = QCompleter()
        self.setCompleter(self.__completer)
        self.__completerVisibleItemsCount = 16

        Search_QLineEdit.__initializeUi(self)
        self.__setClearButtonVisibility(self.text())

        # Signals / Slots.
        self.__clearButton.clicked.connect(self.clear)
        self.textChanged.connect(self.__setClearButtonVisibility)

    #******************************************************************************************************************
    #***	Attributes properties.
    #******************************************************************************************************************
    @property
    def uiSearchImage(self):
        """
		Property for **self.__uiSearchImage** attribute.

		:return: self.__uiSearchImage.
		:rtype: str
		"""

        return self.__uiSearchImage

    @uiSearchImage.setter
    @foundations.exceptions.handleExceptions(AssertionError)
    def uiSearchImage(self, value):
        """
		Setter for **self.__uiSearchImage** attribute.

		:param value: Attribute value.
		:type value: str
		"""

        if value is not None:
            assert type(
                value
            ) is unicode, "'{0}' attribute: '{1}' type is not 'unicode'!".format(
                "uiSearchImage", value)
            assert os.path.exists(
                value), "'{0}' attribute: '{1}' file doesn't exists!".format(
                    "uiSearchImage", value)
        self.__uiSearchImage = value

    @uiSearchImage.deleter
    @foundations.exceptions.handleExceptions(
        foundations.exceptions.ProgrammingError)
    def uiSearchImage(self):
        """
		Deleter for **self.__uiSearchImage** attribute.
		"""

        raise foundations.exceptions.ProgrammingError(
            "{0} | '{1}' attribute is not deletable!".format(
                self.__class__.__name__, "uiSearchImage"))

    @property
    def uiSearchClickedImage(self):
        """
		Property for **self.__uiSearchClickedImage** attribute.

		:return: self.__uiSearchClickedImage.
		:rtype: str
		"""

        return self.__uiSearchClickedImage

    @uiSearchClickedImage.setter
    @foundations.exceptions.handleExceptions(AssertionError)
    def uiSearchClickedImage(self, value):
        """
		Setter for **self.__uiSearchClickedImage** attribute.

		:param value: Attribute value.
		:type value: str
		"""

        if value is not None:
            assert type(
                value
            ) is unicode, "'{0}' attribute: '{1}' type is not 'unicode'!".format(
                "uiSearchClickedImage", value)
            assert os.path.exists(
                value), "'{0}' attribute: '{1}' file doesn't exists!".format(
                    "uiSearchClickedImage", value)
        self.__uiSearchClickedImage = value

    @uiSearchClickedImage.deleter
    @foundations.exceptions.handleExceptions(
        foundations.exceptions.ProgrammingError)
    def uiSearchClickedImage(self):
        """
		Deleter for **self.__uiSearchClickedImage** attribute.
		"""

        raise foundations.exceptions.ProgrammingError(
            "{0} | '{1}' attribute is not deletable!".format(
                self.__class__.__name__, "uiSearchClickedImage"))

    @property
    def uiClearImage(self):
        """
		Property for **self.__uiClearImage** attribute.

		:return: self.__uiClearImage.
		:rtype: str
		"""

        return self.__uiClearImage

    @uiClearImage.setter
    @foundations.exceptions.handleExceptions(AssertionError)
    def uiClearImage(self, value):
        """
		Setter for **self.__uiClearImage** attribute.

		:param value: Attribute value.
		:type value: str
		"""

        if value is not None:
            assert type(
                value
            ) is unicode, "'{0}' attribute: '{1}' type is not 'unicode'!".format(
                "uiClearImage", value)
            assert os.path.exists(
                value), "'{0}' attribute: '{1}' file doesn't exists!".format(
                    "uiClearImage", value)
        self.__uiClearImage = value

    @uiClearImage.deleter
    @foundations.exceptions.handleExceptions(
        foundations.exceptions.ProgrammingError)
    def uiClearImage(self):
        """
		Deleter for **self.__uiClearImage** attribute.
		"""

        raise foundations.exceptions.ProgrammingError(
            "{0} | '{1}' attribute is not deletable!".format(
                self.__class__.__name__, "uiClearImage"))

    @property
    def uiClearClickedImage(self):
        """
		Property for **self.__uiClearClickedImage** attribute.

		:return: self.__uiClearClickedImage.
		:rtype: str
		"""

        return self.__uiClearClickedImage

    @uiClearClickedImage.setter
    @foundations.exceptions.handleExceptions(AssertionError)
    def uiClearClickedImage(self, value):
        """
		Setter for **self.__uiClearClickedImage** attribute.

		:param value: Attribute value.
		:type value: str
		"""

        if value is not None:
            assert type(
                value
            ) is unicode, "'{0}' attribute: '{1}' type is not 'unicode'!".format(
                "uiClearClickedImage", value)
            assert os.path.exists(
                value), "'{0}' attribute: '{1}' file doesn't exists!".format(
                    "uiClearClickedImage", value)
        self.__uiClearClickedImage = value

    @uiClearClickedImage.deleter
    @foundations.exceptions.handleExceptions(
        foundations.exceptions.ProgrammingError)
    def uiClearClickedImage(self):
        """
		Deleter for **self.__uiClearClickedImage** attribute.
		"""

        raise foundations.exceptions.ProgrammingError(
            "{0} | '{1}' attribute is not deletable!".format(
                self.__class__.__name__, "uiClearClickedImage"))

    @property
    def searchActiveLabel(self):
        """
		Property for **self.__searchActiveLabel** attribute.

		:return: self.__searchActiveLabel.
		:rtype: QPushButton
		"""

        return self.__searchActiveLabel

    @searchActiveLabel.setter
    @foundations.exceptions.handleExceptions(
        foundations.exceptions.ProgrammingError)
    def searchActiveLabel(self, value):
        """
		Setter for **self.__searchActiveLabel** attribute.

		:param value: Attribute value.
		:type value: QPushButton
		"""

        raise foundations.exceptions.ProgrammingError(
            "{0} | '{1}' attribute is read only!".format(
                self.__class__.__name__, "searchActiveLabel"))

    @searchActiveLabel.deleter
    @foundations.exceptions.handleExceptions(
        foundations.exceptions.ProgrammingError)
    def searchActiveLabel(self):
        """
		Deleter for **self.__searchActiveLabel** attribute.
		"""

        raise foundations.exceptions.ProgrammingError(
            "{0} | '{1}' attribute is not deletable!".format(
                self.__class__.__name__, "searchActiveLabel"))

    @property
    def clearButton(self):
        """
		Property for **self.__clearButton** attribute.

		:return: self.__clearButton.
		:rtype: QPushButton
		"""

        return self.__clearButton

    @clearButton.setter
    @foundations.exceptions.handleExceptions(
        foundations.exceptions.ProgrammingError)
    def clearButton(self, value):
        """
		Setter for **self.__clearButton** attribute.

		:param value: Attribute value.
		:type value: QPushButton
		"""

        raise foundations.exceptions.ProgrammingError(
            "{0} | '{1}' attribute is read only!".format(
                self.__class__.__name__, "clearButton"))

    @clearButton.deleter
    @foundations.exceptions.handleExceptions(
        foundations.exceptions.ProgrammingError)
    def clearButton(self):
        """
		Deleter for **self.__clearButton** attribute.
		"""

        raise foundations.exceptions.ProgrammingError(
            "{0} | '{1}' attribute is not deletable!".format(
                self.__class__.__name__, "clearButton"))

    @property
    def completer(self):
        """
		Property for **self.__completer** attribute.

		:return: self.__completer.
		:rtype: QCompleter
		"""

        return self.__completer

    @completer.setter
    @foundations.exceptions.handleExceptions(
        foundations.exceptions.ProgrammingError)
    def completer(self, value):
        """
		Setter for **self.__completer** attribute.

		:param value: Attribute value.
		:type value: QCompleter
		"""

        raise foundations.exceptions.ProgrammingError(
            "{0} | '{1}' attribute is read only!".format(
                self.__class__.__name__, "completer"))

    @completer.deleter
    @foundations.exceptions.handleExceptions(
        foundations.exceptions.ProgrammingError)
    def completer(self):
        """
		Deleter for **self.__completer** attribute.
		"""

        raise foundations.exceptions.ProgrammingError(
            "{0} | '{1}' attribute is not deletable!".format(
                self.__class__.__name__, "completer"))

    @property
    def completerVisibleItemsCount(self):
        """
		Property for **self.__completerVisibleItemsCount** attribute.

		:return: self.__completerVisibleItemsCount.
		:rtype: int
		"""

        return self.__completerVisibleItemsCount

    @completerVisibleItemsCount.setter
    @foundations.exceptions.handleExceptions(
        foundations.exceptions.ProgrammingError)
    def completerVisibleItemsCount(self, value):
        """
		Setter for **self.__completerVisibleItemsCount** attribute.

		:param value: Attribute value.
		:type value: int
		"""

        raise foundations.exceptions.ProgrammingError(
            "{0} | '{1}' attribute is read only!".format(
                self.__class__.__name__, "completerVisibleItemsCount"))

    @completerVisibleItemsCount.deleter
    @foundations.exceptions.handleExceptions(
        foundations.exceptions.ProgrammingError)
    def completerVisibleItemsCount(self):
        """
		Deleter for **self.__completerVisibleItemsCount** attribute.
		"""

        raise foundations.exceptions.ProgrammingError(
            "{0} | '{1}' attribute is not deletable!".format(
                self.__class__.__name__, "completerVisibleItemsCount"))

    #******************************************************************************************************************
    #***	Class methods.
    #******************************************************************************************************************
    def resizeEvent(self, event):
        """
		Reimplements the :meth:`QLineEdit.QResizeEvent` method.

		:param event: Resize event.
		:type event: QResizeEvent
		"""

        frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
        searchActiveLabelSize = self.__searchActiveLabel.sizeHint()
        self.__searchActiveLabel.move(
            self.rect().left() + frameWidth,
            (self.rect().bottom() - searchActiveLabelSize.height()) / 2 +
            frameWidth / 2)
        clearButtonSize = self.__clearButton.sizeHint()
        self.__clearButton.move(
            self.rect().right() - frameWidth - clearButtonSize.width(),
            (self.rect().bottom() - clearButtonSize.height()) / 2 +
            frameWidth / 2)

    def __initializeUi(self):
        """
		Initializes the Widget ui.
		"""

        self.__clearButton.setCursor(Qt.ArrowCursor)
        if self.__uiClearImage and self.__uiClearClickedImage:
            pixmap = QPixmap(self.__uiClearImage)
            clickedPixmap = QPixmap(self.__uiClearClickedImage)
            self.__clearButton.setIcon(QIcon(pixmap))
            self.__clearButton.setMaximumSize(pixmap.size())

            # Signals / Slots.
            self.__clearButton.pressed.connect(
                functools.partial(self.__clearButton.setIcon,
                                  QIcon(clickedPixmap)))
            self.__clearButton.released.connect(
                functools.partial(self.__clearButton.setIcon, QIcon(pixmap)))
        else:
            self.__clearButton.setText("Clear")

        self.__setStyleSheet()

        frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
        self.setMinimumSize(
            max(self.minimumSizeHint().width(),
                self.__clearButton.sizeHint().height() + frameWidth * 2),
            max(self.minimumSizeHint().height(),
                self.__clearButton.sizeHint().height() + frameWidth * 2))

        self.__completer.setCaseSensitivity(Qt.CaseInsensitive)
        self.__completer.setCompletionMode(
            QCompleter.UnfilteredPopupCompletion)
        # self.__completer.setMaxVisibleItems(self.__completerVisibleItemsCount)

    def __setStyleSheet(self):
        """
		Sets the Widget stylesheet.
		"""

        frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
        self.setStyleSheet(
            QString(
                "QLineEdit {{ padding-left: {0}px; padding-right: {1}px; }}\nQToolButton {{ border: none; padding: 0px; }}"
                .format(
                    self.__searchActiveLabel.sizeHint().width() if
                    self.__searchActiveLabel.isVisible() else 0 + frameWidth,
                    self.__clearButton.sizeHint().width() + frameWidth)))

    def __setClearButtonVisibility(self, text):
        """
		Sets the clear button visibility.

		:param text: Current field text.
		:type text: QString
		"""

        if text:
            self.__clearButton.show()
        else:
            self.__clearButton.hide()