1 # Authors: Amaury Medeiros and Paulo Ouriques
2 # Software License: GPL
7 from PyQt4.QtCore import *
8 from PyQt4.QtGui import *
10 from ui.pcsuiutils import *
11 from pcsuiutils import *
12 from ui.pcscustombuttons import PcsCustomButton as customButton
14 class PcsDeviceInfoViewer(QHBoxLayout):
16 ''' Class that displays how the device is connected with the PC'''
18 def __init__(self, pcSuite):
19 super(PcsDeviceInfoViewer,self).__init__()
21 self.label = QLabel("")
22 self.label.setText("<font style='color: gray'; size=2>Maemo Release</font>")
23 self.label.setFixedSize(90,20)
25 self.pcSuite = pcSuite
27 pixmap = QPixmap(SSH_IMAGE)
28 self.l2.setPixmap(pixmap)
30 spacer = QSpacerItem(60, 60)
31 maemoLayout = QVBoxLayout()
32 maemoLayout.setMargin(0)
33 maemoLayout.addItem(spacer)
34 maemoLayout.addWidget(self.label)
35 maemoLayout.addWidget(self.l2)
36 maemoLayout.addItem(spacer)
38 spacer2 = QSpacerItem(0, 32)
39 spacer3 = QSpacerItem(0, 37.6)
40 self.statusLayout = QGridLayout()
41 self.statusLayout.setColumnStretch(1, 1)
42 self.statusLayout.addItem(spacer2, 0, 0)
43 self._createStatusWidget(self.statusLayout)
44 self.statusLayout.addItem(spacer3, 4, 0)
47 self.addLayout(maemoLayout)
48 spacer4 = QSpacerItem(10, 10)
50 self.addLayout(self.statusLayout)
52 self.modelLabel = QLabel("Model", self.pcSuite)
53 self.modelLabel.setText("<font style='color: white'; size=2>Model</font>")
54 self.modelLabel.setGeometry(QRect(330, 70, WINDOW_WIDTH, WINDOW_HEIGHT))
56 self.arrowLabel = QLabel(self.pcSuite)
57 self.arrowLabel.setPixmap(QPixmap(WHITE_ARROW))
58 self.arrowLabel.setGeometry(QRect(365, 70, WINDOW_WIDTH, WINDOW_HEIGHT))
60 self.deviceNameLabel = QLabel("None", self.pcSuite)
61 self.deviceNameLabel.setText("<font style='color: white'; size=2>None</font>")
62 self.deviceNameLabel.setGeometry(QRect(380, 70, WINDOW_WIDTH, WINDOW_HEIGHT))
65 self.deviceNameLabel2 = QLabel(self.pcSuite)
66 self.deviceNameLabel2.setText("<font style='color: #333333'; size=2>None</font>")
67 self.deviceNameLabel2.setGeometry(QRect(10, 39, 50, 15))
69 self.arrowLabel = QLabel(self.pcSuite)
70 self.arrowLabel.setPixmap(QPixmap(BLACK_ARROW))
71 self.arrowLabel.setGeometry(QRect(40, 39, 15, 15))
73 self.actionLabel = QLabel(self.pcSuite)
74 self.actionLabel.setText("<font style='color: white'; size=2>Select option</font>")
75 self.actionLabel.setGeometry(QRect(55, 36, 100, 20))
77 self.chargingThread = None;
79 def setDeviceInfo(self, deviceInfo):
80 self.deviceInfo = deviceInfo
81 self.label.setText("<font style='color: grey'; size=2>" + deviceInfo.system +"</font>" )
85 self.deviceNameLabel.setText("<font style='color: white'; size=2>"
86 + deviceInfo.name + "</font>")
87 self.deviceNameLabel2.setText("<font style='color: #333333'; size=2>"
88 + deviceInfo.name + "</font>")
89 if(self.chargingThread != None):
90 if self.deviceInfo.charging:
91 self._batteryBar.setToolTip("Charging...")
93 self.emit(SIGNAL("stopThread"))
94 self._batteryBar.setToolTip("Battery: %d%%" % (deviceInfo.battery))
95 self._batteryBar.setValue(deviceInfo.battery)
97 if self.deviceInfo.charging:
98 self._batteryBar.setToolTip("Charging...")
99 self.chargingThread = ChargingThread(self)
100 self.connect(self.chargingThread, SIGNAL("charging"), self._charging)
101 self.chargingThread.start()
103 self._batteryBar.setValue(deviceInfo.battery)
104 self._batteryBar.setToolTip("Battery: %d%%" % (deviceInfo.battery))
107 memory = deviceInfo.storage
114 value_m1 = float(memory[1][1]) * 100 / float(memory[1][0])
115 current_m1 = float(memory[1][1])/1024
116 total_m1 = float(memory[1][0])/1024
117 tip += "MMC1: %.1fMB / %.1fMB - %d%%\n" % (current_m1, total_m1, value_m1)
120 value_m2 = float(memory[2][1]) * 100 / float(memory[2][0])
121 current_m2 = float(memory[2][1])/1024
122 total_m2 = float(memory[2][0])/1024
123 tip += "MMC2: %.1fMB / %.1fMB - %d%%\n" % (current_m2, total_m2, value_m2)
125 if total_m1 == 0 and total_m2 == 0:
126 tip = "No external memory found."
128 current = current_m1 + current_m2
129 total = total_m1 + total_m2
130 value = (current_m1 + current_m2) * 100 / total
131 tip += "Total: %.1fMB / %.1fMB - %d%%" % (current, total, value)
132 self._memoryBar.setValue(value)
133 self._memoryBar.setToolTip(tip)
135 current = float(memory[0][1])/1024
136 total = float(memory[0][0])/1024
137 value = current * 100 / total
138 self._deviceBar.setValue(value)
139 self._deviceBar.setToolTip("Device Memory: %.1fMB / %.1fMB - %d%%" % (current, total, value))
141 def _createStatusWidget(self, layout):
142 self._batteryBar = self._newProgressBar(layout, 1, BATTERY_IMAGE)
143 self._deviceBar = self._newProgressBar(layout, 2, DEVICE_MEMORY_IMAGE)
144 self._memoryBar = self._newProgressBar(layout, 3, MEMORY_IMAGE)
146 def _newProgressBar(self, layout, line, image):
150 bar.setFixedSize(150,12.9)
151 bar.setTextVisible(False)
152 layout.addWidget(bar, line, 0 )
155 label.setFixedSize(30,15)
156 pixmap = QPixmap(image)
157 label.setPixmap(pixmap)
158 layout.addWidget(label, line, 1)
163 currentValue = self._batteryBar.value()
164 if(currentValue == 100):
165 self._batteryBar.setValue(0)
166 self._batteryBar.setValue(currentValue + 1)
167 self._batteryBar.repaint()
170 class ChargingThread(QThread):
171 def __init__(self, infoViewer):
172 QThread.__init__(self)
174 self.connect(infoViewer, SIGNAL("stopThread"), self.stopThread)
175 self.connect(infoViewer, SIGNAL("destroyed()"), self.stopThread)
177 def stopThread(self):
184 self.emit(SIGNAL("charging"))