Tizen 2.1 base
[platform/upstream/hplip.git] / ui4 / systrayframe.py
1 # -*- coding: utf-8 -*-
2 #
3 # (c) Copyright 2001-2009 Hewlett-Packard Development Company, L.P.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # Author: Don Welch
20 #
21
22 # Local
23 from base.g import *
24 from base.codes import *
25 from ui_utils import *
26
27 # Qt
28 from PyQt4.QtCore import *
29 from PyQt4.QtGui import *
30
31
32 class SystrayFrame(QFrame):
33     def __init__(self, parent):
34         QFrame.__init__(self, parent)
35
36
37     def initUi(self, systray_visible, polling, polling_interval, device_list, systray_messages,upgrade_notify,
38                                         upgrade_postpone_time, upgrade_msg):
39                                     
40         self.systray_visible = systray_visible
41         self.polling = polling
42         self.polling_interval = polling_interval
43         self.device_list = device_list
44         self.systray_messages = systray_messages
45         self.upgrade_notify = upgrade_notify
46         self.upgrade_postpone_time =upgrade_postpone_time
47         self.upgrade_msg = upgrade_msg
48
49         self.gridlayout = QGridLayout(self)
50
51         self.frame = QFrame(self)
52         self.frame.setFrameShape(QFrame.StyledPanel)
53         self.frame.setFrameShadow(QFrame.Raised)
54
55         self.gridlayout1 = QGridLayout(self.frame)
56
57         self.groupBox_2 = QGroupBox(self.frame)
58
59         self.gridlayout2 = QGridLayout(self.groupBox_2)
60
61         self.ShowAlwaysRadioButton = QRadioButton(self.groupBox_2)
62         self.gridlayout2.addWidget(self.ShowAlwaysRadioButton,0,0,1,1)
63
64         self.HideWhenInactiveRadioButton = QRadioButton(self.groupBox_2)
65         self.gridlayout2.addWidget(self.HideWhenInactiveRadioButton,1,0,1,1)
66
67         self.HideAlwaysRadioButton = QRadioButton(self.groupBox_2)
68         self.gridlayout2.addWidget(self.HideAlwaysRadioButton,2,0,1,1)
69
70         self.gridlayout1.addWidget(self.groupBox_2,0,0,1,1)
71
72         self.groupBox_3 = QGroupBox(self.frame)
73
74         self.gridlayout3 = QGridLayout(self.groupBox_3)
75
76         self.label_2 = QLabel(self.groupBox_3)
77         self.gridlayout3.addWidget(self.label_2,0,0,1,1)
78
79         self.MessageShowComboBox = QComboBox(self.groupBox_3)
80         self.gridlayout3.addWidget(self.MessageShowComboBox,1,0,1,1)
81
82         self.MessageShowComboBox.addItem(self.__tr("All"), QVariant(SYSTRAY_MESSAGES_SHOW_ALL))
83         self.MessageShowComboBox.addItem(self.__tr("Errors and Warnings"), QVariant(SYSTRAY_MESSAGES_SHOW_ERRORS_AND_WARNINGS))
84         self.MessageShowComboBox.addItem(self.__tr("Errors Only"), QVariant(SYSTRAY_MESSAGES_SHOW_ERRORS_ONLY))
85         self.MessageShowComboBox.addItem(self.__tr("None"), QVariant(SYSTRAY_MESSAGES_SHOW_NONE))
86
87         spacerItem = QSpacerItem(20,40,QSizePolicy.Minimum,QSizePolicy.Minimum)
88         self.gridlayout3.addItem(spacerItem,2,0,1,1)
89         self.gridlayout1.addWidget(self.groupBox_3,0,1,1,1)
90
91         self.MonitorGroupBox = QGroupBox(self.frame)
92         self.MonitorGroupBox.setCheckable(True)
93
94         self.MonitorGroupBox.setEnabled(False)
95
96         self.gridlayout4 = QGridLayout(self.MonitorGroupBox)
97
98         self.label = QLabel(self.MonitorGroupBox)
99         self.gridlayout4.addWidget(self.label,0,0,1,1)
100
101         self.listWidget = QListWidget(self.MonitorGroupBox)
102         self.gridlayout4.addWidget(self.listWidget,1,0,1,1)
103         self.gridlayout1.addWidget(self.MonitorGroupBox,1,0,1,2)
104         
105         
106         #UpdategroupBox  is same as "gridlayout5"
107         self.groupBox_4 = QGroupBox(self.frame)
108         self.UpdategroupBox = QGridLayout(self.groupBox_4)
109         self.UpdategroupBox.setObjectName("UpdategroupBox")
110         self.UpdatecheckBox = QCheckBox(self.groupBox_4)
111         self.UpdatecheckBox.setObjectName("UpdatecheckBox")
112         self.UpdategroupBox.addWidget(self.UpdatecheckBox,0,0,1,4)
113         self.label_5 = QLabel(self.groupBox_4)
114         self.label_5.setObjectName("label_5")
115         self.UpdategroupBox.addWidget(self.label_5, 1, 0, 1, 4)
116         self.textEdit = QTextEdit(self.groupBox_4)
117         self.textEdit.setObjectName("textEdit")
118         self.textEdit.setReadOnly(True)
119         self.UpdategroupBox.addWidget(self.textEdit, 2, 0, 1, 4)
120         self.gridlayout1.addWidget(self.groupBox_4,2,0,1,2)
121
122         self.gridlayout.addWidget(self.frame,0,0,1,1)
123         
124         
125
126         self.setWindowTitle(QApplication.translate("self", "self", None, QApplication.UnicodeUTF8))
127         self.groupBox_2.setTitle(QApplication.translate("self", "System tray icon visibility", None, QApplication.UnicodeUTF8))
128         self.ShowAlwaysRadioButton.setText(QApplication.translate("self", "Always show", None, QApplication.UnicodeUTF8))
129         self.HideWhenInactiveRadioButton.setText(QApplication.translate("self", "Hide when inactive", None, QApplication.UnicodeUTF8))
130         self.HideAlwaysRadioButton.setText(QApplication.translate("self", "Always hide", None, QApplication.UnicodeUTF8))
131         self.groupBox_3.setTitle(QApplication.translate("self", "System tray icon messages", None, QApplication.UnicodeUTF8))
132         self.label_2.setText(QApplication.translate("self", "Messages to show:", None, QApplication.UnicodeUTF8))
133         self.MonitorGroupBox.setTitle(QApplication.translate("self", "Monitor button presses on devices", None, QApplication.UnicodeUTF8))
134         self.label.setText(QApplication.translate("self", "Devices to monitor:", None, QApplication.UnicodeUTF8))
135         
136         
137         self.groupBox_4.setTitle(QApplication.translate("Dialog", "Update Settings", None, QApplication.UnicodeUTF8))
138         self.UpdatecheckBox.setText(QApplication.translate("Dialog", "Check and notify HPLIP updates", None, QApplication.UnicodeUTF8))
139         self.label_5.setText(QApplication.translate("Dialog", "Status:", None, QApplication.UnicodeUTF8))
140         self.textEdit.setPlainText(self.upgrade_msg)
141         
142
143         self.connect(self.ShowAlwaysRadioButton, SIGNAL("clicked(bool)"), self.ShowAlwaysRadioButton_clicked)
144         self.connect(self.HideWhenInactiveRadioButton, SIGNAL("clicked(bool)"), self.HideWhenInactiveRadioButton_clicked)
145         self.connect(self.HideAlwaysRadioButton, SIGNAL("clicked(bool)"), self.HideAlwaysRadioButton_clicked)
146         self.connect(self.MessageShowComboBox, SIGNAL("activated(int)"), self.MessageShowComboBox_activated)
147         self.connect(self.UpdatecheckBox, SIGNAL("clicked(bool)"), self.UpdatecheckBox_clicked)
148         
149
150
151
152     def UpdatecheckBox_clicked(self, b):
153         log.debug("Update HPLIP val =%d "%b)
154         if b is False:
155             self.upgrade_notify = False
156         else:
157             self.upgrade_notify = True
158
159     def updateUi(self):
160         self.updateVisibility()
161         self.updateMessages()
162         self.updateDeviceList()
163         self.updateUpgradeSettings()
164
165
166     def updateVisibility(self):
167         if self.systray_visible == SYSTRAY_VISIBLE_SHOW_ALWAYS:
168             self.ShowAlwaysRadioButton.setChecked(True)
169
170         elif self.systray_visible == SYSTRAY_VISIBLE_HIDE_WHEN_INACTIVE:
171             self.HideWhenInactiveRadioButton.setChecked(True)
172
173         else: # SYSTRAY_VISIBLE_HIDE_ALWAYS
174             self.HideAlwaysRadioButton.setChecked(True)
175
176
177     def ShowAlwaysRadioButton_clicked(self, b):
178         if b: self.systray_visible = SYSTRAY_VISIBLE_SHOW_ALWAYS
179
180
181     def HideWhenInactiveRadioButton_clicked(self, b):
182         if b: self.systray_visible = SYSTRAY_VISIBLE_HIDE_WHEN_INACTIVE
183
184
185     def HideAlwaysRadioButton_clicked(self, b):
186         if b: self.systray_visible = SYSTRAY_VISIBLE_HIDE_ALWAYS
187
188
189     def updateMessages(self):
190         i = self.MessageShowComboBox.findData(QVariant(self.systray_messages))
191         if i != -1:
192             self.MessageShowComboBox.setCurrentIndex(i)
193
194
195     def MessageShowComboBox_activated(self, i):
196         sender = self.sender()
197         mode, ok = sender.itemData(i).toInt()
198         if ok:
199             self.systray_messages = mode
200
201
202     def updateDeviceList(self):
203         pass
204
205     def updateUpgradeSettings(self):
206         if self.upgrade_notify is True:
207             self.UpdatecheckBox.setChecked(True)
208         else:
209             self.UpdatecheckBox.setChecked(False)
210
211
212
213
214     def __tr(self, s, c=None):
215         return QApplication.translate("SystrayFrame", s, c, QApplication.UnicodeUTF8)
216