4 from PyQt4 import QtGui, QtCore
5 from n900_levels import LevelReader
22 class Bar(QtGui.QWidget):
23 def __init__(self, parent, x, y, fill_percent=100, mirror=False):
24 QtGui.QWidget.__init__(self, parent)
25 self.resize(bar_width, bar_length)
29 label_length = bar_length * fill_percent / 100
31 label_y = bar_length - label_length
33 self.label = QtGui.QLabel(self)
34 self.label.resize(bar_width, label_length)
36 self.label.move(0, label_y)
37 self.label.setStyleSheet("background-color: black")
40 class OldSchoolWidget(QtGui.QWidget):
43 quit_pressed = QtCore.pyqtSignal()
45 def __init__(self, parent=None):
46 QtGui.QWidget.__init__(self, parent)
47 palette = QtGui.QPalette()
48 palette.setBrush(self.backgroundRole(), QtGui.QBrush(QtGui.QImage("old_school_bg.jpg")));
49 self.setPalette(palette)
51 self.power_bar.append(Bar(self, bar_x_1, power_bar_y, 25))
52 self.power_bar.append(Bar(self, bar_x_2, power_bar_y, 50))
53 self.power_bar.append(Bar(self, bar_x_3, power_bar_y, 75))
54 self.power_bar.append(Bar(self, bar_x_4, power_bar_y, 100))
56 self.signal_bar.append(Bar(self, bar_x_1, signal_bar_y, 25, True))
57 self.signal_bar.append(Bar(self, bar_x_2, signal_bar_y, 50, True))
58 self.signal_bar.append(Bar(self, bar_x_3, signal_bar_y, 75, True))
59 self.signal_bar.append(Bar(self, bar_x_4, signal_bar_y, 100, True))
61 def mousePressEvent(self, ev):
62 click_position = QtCore.QPoint(ev.pos())
63 x = click_position.x()
64 y = click_position.y()
65 if (x>=quit_x_min and x <=quit_x_max and y>=quit_y_min and y<=quit_y_max):
66 self.quit_pressed.emit()
68 def percent_to_bars(self, percent):
79 def set_signal(self, value):
80 for index in range(1, 4):
81 bar = self.signal_bar[index]
88 def set_signal_percent(self, percentage):
89 bar_count = self.percent_to_bars(percentage)
90 self.set_signal(bar_count)
92 def set_power(self, value):
93 for index in range(1, 4):
94 bar = self.power_bar[index]
100 @QtCore.pyqtSlot(int)
101 def set_power_percent(self, percentage):
102 bar_count = self.percent_to_bars(percentage)
103 self.set_power(bar_count)
106 app = QtGui.QApplication(sys.argv)
107 old_school = OldSchoolWidget()
108 old_school.showFullScreen()
109 QtCore.QObject.connect(old_school, QtCore.SIGNAL('quit_pressed()'),QtGui.qApp, QtCore.SLOT('quit()'))
110 level_reader = LevelReader()
111 QtCore.QObject.connect(level_reader, QtCore.SIGNAL("battery_change(int)") , old_school, QtCore.SLOT("set_power_percent(int)"))
112 QtCore.QObject.connect(level_reader, QtCore.SIGNAL("signal_change(int)") , old_school, QtCore.SLOT("set_signal_percent(int)"))
113 level_reader.check_battery_change()
114 level_reader.check_signal_change()
115 sys.exit(app.exec_())
118 app = QtGui.QApplication(sys.argv)
119 old_school = OldSchoolWidget()
120 old_school.resize(800, 480)
122 QtCore.QObject.connect(old_school, QtCore.SIGNAL('quit_pressed()'),QtGui.qApp, QtCore.SLOT('quit()'))
123 old_school.set_signal_percent(75)
124 old_school.set_power_percent(30)
125 sys.exit(app.exec_())
127 if __name__ == "__main__":
130 if args[1]=="test_gui":