alarmserver.test_gui

Package alarmserver :: Module test_gui |
[hide private]
[frames] | no frames]

# Source Code for Module alarmserver.test_gui

     1  """
     2  Created on 28.10.2013
     3  @author: lehmann
     4
     5  """
     6  import sys
     7
     8  from PyQt4.QtCore import SIGNAL
     9  from PyQt4.QtGui import QWidget, QTableView, QApplication, QPushButton, QVBoxLayout, QSpinBox, QGridLayout, QLabel, QComboBox
    10
    11  from gui import AlarmServerModel
    12
    13
    14 -class MainWindow(QWidget):
    15 -    def __init__(self, parent=None):
    16          super(MainWindow, self).__init__(parent)
    17
    18          self.alarmserverModel = AlarmServerModel()
    19          self.alarmserverModel.define_alarm(1, "alarm 1")
    20          self.alarmserverModel.define_alarm(2, "alarm 2")
    21          self.alarmserverModel.define_alarm(3, "alarm 3")
    22
    23          self.alarmTableView = QTableView()
    24          self.alarmTableView.setModel(self.alarmserverModel)
    25
    26          self.alarmNrLabel = QLabel("alarm number:")
    27          self.alarmNrComboBox = QComboBox()
    28          for alarm_nr in self.alarmserverModel.defined_alarms.keys():
    29              self.alarmNrComboBox.addItem(str(alarm_nr))
    30
    31          self.alarmComingButton = QPushButton("alarm comin")
    32          self.alarmGoingButton = QPushButton("alarm going")
    33          self.acknowledgeButton = QPushButton("acknowledge")
    34          self.acknowledgeAllButton = QPushButton("acknowledge all")
    35          self.clearButton = QPushButton("clear")
    36          self.clearAllButton = QPushButton("clear all")
    37
    38          layout = QGridLayout()
    39          layout.addWidget(self.alarmTableView, 0, 0, 1, 3)
    40          layout.addWidget(self.alarmNrLabel, 1, 0)
    41          layout.addWidget(self.alarmNrComboBox, 1, 1)
    42          layout.addWidget(self.alarmComingButton, 2, 0)
    43          layout.addWidget(self.alarmGoingButton, 3, 0)
    44          layout.addWidget(self.acknowledgeButton, 2, 1)
    45          layout.addWidget(self.acknowledgeAllButton, 3, 1)
    46          layout.addWidget(self.clearButton, 2, 2)
    47          layout.addWidget(self.clearAllButton, 3, 2)
    48          self.setLayout(layout)
    49          self.resize(600, 300)
    50
    51          self.connect(self.acknowledgeButton, SIGNAL("pressed()"), self.acknowledge_alarm)
    52          self.connect(self.alarmComingButton, SIGNAL("pressed()"), self.alarm_coming)
    53          self.connect(self.alarmGoingButton, SIGNAL("pressed()"), self.alarm_going)
    54          self.connect(self.acknowledgeAllButton, SIGNAL("pressed()"), self.acknowledge_all)
    55          self.connect(self.clearButton, SIGNAL("pressed()"), self.clear_alarm)
    56          self.connect(self.clearAllButton, SIGNAL("pressed()"), self.clear_all)
    57
    58 -    def acknowledge_alarm(self):
    59          alarm_nr = self.alarmNrComboBox.currentText().toInt()[0]
    60          self.alarmserverModel.acknowledge(alarm_nr)
    61
    62 -    def acknowledge_all(self):
    63          self.alarmserverModel.acknowledge_all()
    64
    65 -    def alarm_coming(self):
    66          alarm_nr = self.alarmNrComboBox.currentText().toInt()[0]
    67          self.alarmserverModel.alarm_coming(alarm_nr)
    68
    69 -    def alarm_going(self):
    70          alarm_nr = self.alarmNrComboBox.currentText().toInt()[0]
    71          self.alarmserverModel.alarm_going(alarm_nr)
    72
    73 -    def clear_alarm(self):
    74          alarm_nr = self.alarmNrComboBox.currentText().toInt()[0]
    75          self.alarmserverModel.clear(alarm_nr)
    76
    77 -    def clear_all(self):
    78          self.alarmserverModel.clear_all()
    79
    80  if __name__ == "__main__":
    81      app = QApplication(sys.argv)
    82      frm = MainWindow()
    83      frm.show()
    84      app.exec_()
    85