eric6/Preferences/ConfigurationPages/NotificationsPage.py

Mon, 04 Jan 2021 16:39:37 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 04 Jan 2021 16:39:37 +0100
changeset 7955
567f2ec958c3
parent 7952
1849f61cf2b6
child 7959
44e15eda6506
permissions
-rw-r--r--

Changed code to always use the reworked notification system.

# -*- coding: utf-8 -*-

# Copyright (c) 2012 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing the Notifications configuration page.
"""

from PyQt5.QtCore import pyqtSlot, QPoint
from PyQt5.QtWidgets import QApplication

from .ConfigurationPageBase import ConfigurationPageBase
from .Ui_NotificationsPage import Ui_NotificationsPage

import Preferences
import UI.PixmapCache


class NotificationsPage(ConfigurationPageBase, Ui_NotificationsPage):
    """
    Class implementing the Notifications configuration page.
    """
    def __init__(self):
        """
        Constructor
        """
        super(NotificationsPage, self).__init__()
        self.setupUi(self)
        self.setObjectName("NotificationsPage")
        
        geom = QApplication.screens()[0].availableVirtualGeometry()
        self.xSpinBox.setMinimum(geom.x())
        self.xSpinBox.setMaximum(geom.width())
        self.ySpinBox.setMinimum(geom.y())
        self.ySpinBox.setMaximum(geom.height())
        
        self.__notification = None
        self.__firstTime = True
        
        # set initial values
        self.timeoutSpinBox.setValue(Preferences.getUI("NotificationTimeout"))
        point = Preferences.getUI("NotificationPosition")
        self.xSpinBox.setValue(point.x())
        self.ySpinBox.setValue(point.y())
        
        self.xSpinBox.valueChanged.connect(self.__moveNotification)
        self.ySpinBox.valueChanged.connect(self.__moveNotification)
    
    def save(self):
        """
        Public slot to save the Notifications configuration.
        """
        Preferences.setUI("NotificationTimeout", self.timeoutSpinBox.value())
        Preferences.setUI("NotificationPosition", QPoint(
            self.xSpinBox.value(), self.ySpinBox.value()))
    
    @pyqtSlot(bool)
    def on_visualButton_clicked(self, checked):
        """
        Private slot to select the position visually.
        
        @param checked state of the button (boolean)
        """
        if checked:
            from UI.NotificationWidget import NotificationWidget
            self.__notification = NotificationWidget(
                parent=self, setPosition=True)
            self.__notification.showNotification(
                UI.PixmapCache.getPixmap("notification48"),
                self.tr("Visual Selection"),
                self.tr("Drag the notification window to"
                        " the desired place and release the button."),
                timeout=0
            )
            self.__notification.move(
                QPoint(self.xSpinBox.value(), self.ySpinBox.value()))
            if self.__firstTime:
                # adjust the maximum values to the width of the notification
                self.xSpinBox.setMaximum(
                    self.xSpinBox.maximum() - self.__notification.width())
                self.ySpinBox.setMaximum(
                    self.ySpinBox.maximum() - self.__notification.height())
                self.__firstTime = False
        else:
            # retrieve the position
            point = self.__notification.frameGeometry().topLeft()
            self.xSpinBox.setValue(point.x())
            self.ySpinBox.setValue(point.y())
            self.__notification.close()
            self.__notification = None
    
    @pyqtSlot()
    def __moveNotification(self):
        """
        Private slot to move the notification widget.
        """
        if self.visualButton.isChecked():
            self.__notification.move(
                self.xSpinBox.value(),
                self.ySpinBox.value()
            )


def create(dlg):
    """
    Module function to create the configuration page.
    
    @param dlg reference to the configuration dialog
    @return reference to the instantiated page (ConfigurationPageBase)
    """
    page = NotificationsPage()
    return page

eric ide

mercurial