Initial commit (Vesion 0.1)
[tablet-suite] / src / ui / pcsdeviceinfoviewer.py
diff --git a/src/ui/pcsdeviceinfoviewer.py b/src/ui/pcsdeviceinfoviewer.py
new file mode 100644 (file)
index 0000000..4a5959b
--- /dev/null
@@ -0,0 +1,189 @@
+# Authors: Amaury Medeiros and Paulo Ouriques
+# Software License: GPL
+
+from time import sleep
+import threading
+
+from PyQt4.QtCore import *
+from PyQt4.QtGui import *
+
+from ui.pcsuiutils import *
+from pcsuiutils import *
+from ui.pcscustombuttons import PcsCustomButton as customButton
+
+class PcsDeviceInfoViewer(QHBoxLayout):
+    
+    ''' Class that displays how the device is connected with the PC'''
+    
+    def __init__(self, pcSuite):
+        super(PcsDeviceInfoViewer,self).__init__()
+        
+        self.label = QLabel("")
+        self.label.setText("<font style='color: gray'; size=2>Maemo Release</font>")
+        self.label.setFixedSize(90,20)
+        
+        self.pcSuite = pcSuite
+        self.l2 = QLabel()
+        pixmap = QPixmap(SSH_IMAGE)
+        self.l2.setPixmap(pixmap)  
+        
+        spacer = QSpacerItem(60, 60)
+        maemoLayout = QVBoxLayout()
+        maemoLayout.setMargin(0)
+        maemoLayout.addItem(spacer)
+        maemoLayout.addWidget(self.label)
+        maemoLayout.addWidget(self.l2)
+        maemoLayout.addItem(spacer)
+        
+        spacer2 = QSpacerItem(0, 32)
+        spacer3 = QSpacerItem(0, 37.6)
+        self.statusLayout = QGridLayout()
+        self.statusLayout.setColumnStretch(1, 1)
+        self.statusLayout.addItem(spacer2, 0, 0)
+        self._createStatusWidget(self.statusLayout)
+        self.statusLayout.addItem(spacer3, 4, 0)
+        
+        self.setMargin(0)
+        self.addLayout(maemoLayout)
+        spacer4 = QSpacerItem(10, 10)
+        self.addItem(spacer4)
+        self.addLayout(self.statusLayout)
+        
+        self.modelLabel = QLabel("Model", self.pcSuite)
+        self.modelLabel.setText("<font style='color: white'; size=2>Model</font>")
+        self.modelLabel.setGeometry(QRect(330, 70, WINDOW_WIDTH, WINDOW_HEIGHT))
+       
+        self.arrowLabel = QLabel(self.pcSuite)
+        self.arrowLabel.setPixmap(QPixmap(WHITE_ARROW))
+        self.arrowLabel.setGeometry(QRect(365, 70, WINDOW_WIDTH, WINDOW_HEIGHT))
+        
+        self.deviceNameLabel = QLabel("None", self.pcSuite)
+        self.deviceNameLabel.setText("<font style='color: white'; size=2>None</font>")
+        self.deviceNameLabel.setGeometry(QRect(380, 70, WINDOW_WIDTH, WINDOW_HEIGHT))
+        
+        
+        self.deviceNameLabel2 = QLabel(self.pcSuite)
+        self.deviceNameLabel2.setText("<font style='color: #333333'; size=2>None</font>")
+        self.deviceNameLabel2.setGeometry(QRect(10, 39, 50, 15))
+       
+        self.arrowLabel = QLabel(self.pcSuite)
+        self.arrowLabel.setPixmap(QPixmap(BLACK_ARROW))
+        self.arrowLabel.setGeometry(QRect(40, 39, 15, 15))
+        
+        self.actionLabel = QLabel(self.pcSuite)
+        self.actionLabel.setText("<font style='color: white'; size=2>Select option</font>")
+        self.actionLabel.setGeometry(QRect(55, 36, 100, 20))
+                 
+        self.chargingThread = None;
+           
+    def setDeviceInfo(self, deviceInfo):
+        self.deviceInfo = deviceInfo
+        self.label.setText("<font style='color: grey'; size=2>" + deviceInfo.system +"</font>" )
+        
+        
+        self.label.repaint()
+        self.deviceNameLabel.setText("<font style='color: white'; size=2>" 
+                                     + deviceInfo.name + "</font>")
+        self.deviceNameLabel2.setText("<font style='color: #333333'; size=2>" 
+                                     + deviceInfo.name + "</font>")
+        if(self.chargingThread != None):
+            if self.deviceInfo.charging:
+                self._batteryBar.setToolTip("Charging...")
+            else:
+                self.emit(SIGNAL("stopThread"))
+                self._batteryBar.setToolTip("Battery: %d%%" % (deviceInfo.battery))
+                self._batteryBar.setValue(deviceInfo.battery)
+        else:
+            if self.deviceInfo.charging:
+                self._batteryBar.setToolTip("Charging...")
+                self.chargingThread = ChargingThread(self)
+                self.connect(self.chargingThread, SIGNAL("charging"), self._charging)
+                self.chargingThread.start()
+            else:
+                self._batteryBar.setValue(deviceInfo.battery)
+                self._batteryBar.setToolTip("Battery: %d%%" % (deviceInfo.battery))
+       
+
+        memory = deviceInfo.storage
+        tip = ""
+        total_m1 = 0
+        total_m2 = 0
+        current_m1 = 0
+        current_m2 = 0
+        if memory[1] != -1:
+            value_m1 = float(memory[1][1]) * 100 / float(memory[1][0])
+            current_m1 = float(memory[1][1])/1024
+            total_m1 = float(memory[1][0])/1024
+            tip += "MMC1: %.1fMB / %.1fMB - %d%%\n" % (current_m1, total_m1, value_m1)
+        
+        if memory[2] != -1:
+            value_m2 = float(memory[2][1]) * 100 / float(memory[2][0])
+            current_m2 = float(memory[2][1])/1024
+            total_m2 = float(memory[2][0])/1024
+            tip += "MMC2: %.1fMB / %.1fMB - %d%%\n" % (current_m2, total_m2, value_m2)
+
+        if total_m1 == 0 and total_m2 == 0:
+            tip = "No external memory found."
+        else:
+            current = current_m1 + current_m2
+            total = total_m1 + total_m2
+            value = (current_m1 + current_m2) * 100 / total
+            tip += "Total: %.1fMB / %.1fMB - %d%%" % (current, total, value)
+            self._memoryBar.setValue(value)
+        self._memoryBar.setToolTip(tip)
+
+        current = float(memory[0][1])/1024 
+        total = float(memory[0][0])/1024
+        value = current * 100 / total
+        self._deviceBar.setValue(value)
+        self._deviceBar.setToolTip("Device Memory: %.1fMB / %.1fMB - %d%%" % (current, total, value))
+        
+    def _createStatusWidget(self, layout):
+        self._batteryBar = self._newProgressBar(layout, 1, BATTERY_IMAGE)
+        self._deviceBar = self._newProgressBar(layout, 2, DEVICE_MEMORY_IMAGE)
+        self._memoryBar = self._newProgressBar(layout, 3, MEMORY_IMAGE)
+                    
+    def _newProgressBar(self, layout, line, image):
+        bar = QProgressBar()
+        bar.setMaximum(100)
+        bar.setMinimum(0)
+        bar.setFixedSize(150,12.9)
+        bar.setTextVisible(False)
+        layout.addWidget(bar, line, 0 )
+
+        label = QLabel()
+        label.setFixedSize(30,15)
+        pixmap = QPixmap(image)
+        label.setPixmap(pixmap)
+        layout.addWidget(label, line, 1)
+        
+        return bar
+    
+    def _charging(self):
+        currentValue = self._batteryBar.value()
+        if(currentValue == 100):
+            self._batteryBar.setValue(0)
+        self._batteryBar.setValue(currentValue + 1)
+        self._batteryBar.repaint()
+        
+        
+class ChargingThread(QThread):
+    def __init__(self, infoViewer):
+        QThread.__init__(self)
+        self.flag = True
+        self.connect(infoViewer, SIGNAL("stopThread"), self.stopThread)
+        self.connect(infoViewer, SIGNAL("destroyed()"), self.stopThread)
+        
+    def stopThread(self):
+        self.flag = False
+        
+    def run(self):
+        while(self.flag):
+            try:
+                sleep(0.02)
+                self.emit(SIGNAL("charging"))
+            except:
+                self.stopThread()
+            
+        
+    
\ No newline at end of file