Preferences/ConfigurationPages/NotificationsPage.py

Wed, 02 Jan 2013 10:31:48 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 02 Jan 2013 10:31:48 +0100
changeset 2302
f29e9405c851
parent 2280
8e85ca3fabe7
child 2408
dc3a7c9d8f6e
child 3163
9f50365a0870
permissions
-rw-r--r--

Updated copyright for 2013.

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

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

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

from PyQt4.QtCore import pyqtSlot, QPoint
from PyQt4.QtGui import QApplication

from .ConfigurationPageBase import ConfigurationPageBase
from .Ui_NotificationsPage import Ui_NotificationsPage

from UI.NotificationWidget import NotificationWidget

import Preferences
import UI.PixmapCache


class NotificationsPage(ConfigurationPageBase, Ui_NotificationsPage):
    """
    Class implementing the Notifications configuration page.
    """
    def __init__(self):
        """
        Constructor
        
        @param parent reference to the parent widget (QWidget)
        """
        super().__init__()
        self.setupUi(self)
        self.setObjectName("NotificationsPage")
        
        minX, maxX = self.xSpinBox.maximum(), self.xSpinBox.minimum()
        minY, maxY = self.ySpinBox.maximum(), self.ySpinBox.minimum()
        desk = QApplication.desktop()
        for screen in range(desk.screenCount()):
            geom = desk.availableGeometry(screen)
            minX = min(minX, geom.x())
            maxX = max(maxX, geom.x() + geom.width())
            minY = min(minY, geom.y())
            maxY = max(maxY, geom.y() + geom.height())
        self.xSpinBox.setMinimum(minX)
        self.xSpinBox.setMaximum(maxX)
        self.ySpinBox.setMinimum(minY)
        self.ySpinBox.setMaximum(maxY)
        
        self.__notification = None
        
        # set initial values
        self.enableCheckBox.setChecked(Preferences.getUI("NotificationsEnabled"))
        self.timeoutSpinBox.setValue(Preferences.getUI("NotificationTimeout"))
        point = Preferences.getUI("NotificationPosition")
        self.xSpinBox.setValue(point.x())
        self.ySpinBox.setValue(point.y())
    
    def save(self):
        """
        Public slot to save the Notifications configuration.
        """
        Preferences.setUI("NotificationsEnabled", self.enableCheckBox.isChecked())
        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:
            self.__notification = NotificationWidget(parent=self, setPosition=True)
            self.__notification.setPixmap(UI.PixmapCache.getPixmap("notification48.png"))
            self.__notification.setHeading(self.trUtf8("Visual Selection"))
            self.__notification.setText(self.trUtf8("Drag the notification window to"
                " the desired place and release the button."))
            self.__notification.move(QPoint(self.xSpinBox.value(), self.ySpinBox.value()))
            self.__notification.show()
        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
    

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

eric ide

mercurial