eric6/Preferences/ConfigurationPages/NotificationsPage.py

changeset 6942
2602857055c5
parent 6911
8f4a050c6895
child 7229
53054eb5b15a
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2012 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the Notifications configuration page.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import pyqtSlot, QPoint
13 from PyQt5.QtWidgets import QApplication
14
15 from .ConfigurationPageBase import ConfigurationPageBase
16 from .Ui_NotificationsPage import Ui_NotificationsPage
17
18 import Preferences
19 import UI.PixmapCache
20
21 from Globals import qVersionTuple
22
23
24 class NotificationsPage(ConfigurationPageBase, Ui_NotificationsPage):
25 """
26 Class implementing the Notifications configuration page.
27 """
28 def __init__(self):
29 """
30 Constructor
31 """
32 super(NotificationsPage, self).__init__()
33 self.setupUi(self)
34 self.setObjectName("NotificationsPage")
35
36 minX, maxX = self.xSpinBox.maximum(), self.xSpinBox.minimum()
37 minY, maxY = self.ySpinBox.maximum(), self.ySpinBox.minimum()
38 if qVersionTuple() >= (5, 10, 0):
39 for screen in QApplication.screens():
40 geom = screen.availableGeometry()
41 minX = min(minX, geom.x())
42 maxX = max(maxX, geom.x() + geom.width())
43 minY = min(minY, geom.y())
44 maxY = max(maxY, geom.y() + geom.height())
45 else:
46 desk = QApplication.desktop()
47 for screen in range(desk.screenCount()):
48 geom = desk.availableGeometry(screen)
49 minX = min(minX, geom.x())
50 maxX = max(maxX, geom.x() + geom.width())
51 minY = min(minY, geom.y())
52 maxY = max(maxY, geom.y() + geom.height())
53 self.xSpinBox.setMinimum(minX)
54 self.xSpinBox.setMaximum(maxX)
55 self.ySpinBox.setMinimum(minY)
56 self.ySpinBox.setMaximum(maxY)
57
58 self.__notification = None
59
60 # set initial values
61 self.enableCheckBox.setChecked(
62 Preferences.getUI("NotificationsEnabled"))
63 self.timeoutSpinBox.setValue(Preferences.getUI("NotificationTimeout"))
64 point = Preferences.getUI("NotificationPosition")
65 self.xSpinBox.setValue(point.x())
66 self.ySpinBox.setValue(point.y())
67
68 def save(self):
69 """
70 Public slot to save the Notifications configuration.
71 """
72 Preferences.setUI(
73 "NotificationsEnabled", self.enableCheckBox.isChecked())
74 Preferences.setUI("NotificationTimeout", self.timeoutSpinBox.value())
75 Preferences.setUI("NotificationPosition", QPoint(
76 self.xSpinBox.value(), self.ySpinBox.value()))
77
78 @pyqtSlot(bool)
79 def on_visualButton_clicked(self, checked):
80 """
81 Private slot to select the position visually.
82
83 @param checked state of the button (boolean)
84 """
85 if checked:
86 from UI.NotificationWidget import NotificationWidget
87 self.__notification = NotificationWidget(
88 parent=self, setPosition=True)
89 self.__notification.setPixmap(
90 UI.PixmapCache.getPixmap("notification48.png"))
91 self.__notification.setHeading(self.tr("Visual Selection"))
92 self.__notification.setText(
93 self.tr("Drag the notification window to"
94 " the desired place and release the button."))
95 self.__notification.move(
96 QPoint(self.xSpinBox.value(), self.ySpinBox.value()))
97 self.__notification.show()
98 else:
99 # retrieve the position
100 point = self.__notification.frameGeometry().topLeft()
101 self.xSpinBox.setValue(point.x())
102 self.ySpinBox.setValue(point.y())
103 self.__notification.close()
104 self.__notification = None
105
106
107 def create(dlg):
108 """
109 Module function to create the configuration page.
110
111 @param dlg reference to the configuration dialog
112 @return reference to the instantiated page (ConfigurationPageBase)
113 """
114 page = NotificationsPage()
115 return page

eric ide

mercurial