Beispiel #1
0
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.connect_handlers()

        # Sub Views
        self.server_form = ServerForm()
        self.server_form.set_main_window(self)
        self.server_form.hide()

        # Initiate empty list
        self.data = []

        # Refresh list
        self.refresh_list()

        # System Tray icon
        self.msgIcon = QtGui.QSystemTrayIcon.MessageIcon(QtGui.QSystemTrayIcon.NoIcon)
        self.icon = QtGui.QSystemTrayIcon()
        self.icon.show()
Beispiel #2
0
class MainWindow(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.connect_handlers()

        # Sub Views
        self.server_form = ServerForm()
        self.server_form.set_main_window(self)
        self.server_form.hide()

        # Initiate empty list
        self.data = []

        # Refresh list
        self.refresh_list()

        # System Tray icon
        self.msgIcon = QtGui.QSystemTrayIcon.MessageIcon(QtGui.QSystemTrayIcon.NoIcon)
        self.icon = QtGui.QSystemTrayIcon()
        self.icon.show()

    def update_list(self):
        save_data(self.data)

    def refresh_list(self):
        # List Data
        self.data = read_data()

        self.ui.serverList.clear()
        for x in self.data:
            #print x
            self.ui.serverList.addItem(x['name'])


    def connect_handlers(self):
        user_interface = self.ui

        #Bind Add Events
        user_interface.addButton.clicked.connect(self.handle_add_events)
        user_interface.actionAdd_Server.triggered.connect(self.handle_add_events)

        #Bind Edit Events
        user_interface.editButton.clicked.connect(self.handle_edit_events)

        #Bind Del Events
        user_interface.delButton.clicked.connect(self.handle_del_events)

        #Bind Toggle Events
        user_interface.toggleButton.clicked.connect(self.handle_toggle_events)
        user_interface.actionStart_Monitoring.triggered.connect(self.handle_toggle_events)
        user_interface.actionStop_Monitoring.triggered.connect(self.handle_toggle_events)

        #Bind Quit Events
        user_interface.actionQuit.triggered.connect(self.handle_quit_events)


    def handle_add_events(self):
        self.server_form.show()
        self.hide()

    def handle_edit_events(self):
        try:
            item = self.ui.serverList.selectedIndexes()[0]
            index = item.row()
        except:
            index = None

        if index is not None:
            self.server_form.set_entry_id(index)
        else:
            self.server_form.set_default_texts()

        self.server_form.show()
        self.hide()

    def handle_del_events(self):
        try:
            item = self.ui.serverList.selectedIndexes()[0]
            index = item.row()
            del self.data[index]
        except:
            pass

        self.update_list()
        self.refresh_list()

    def handle_toggle_events(self):
        try:
            timer = self.timer
            self.timer.cancel()
            del self.timer
            self.ui.toggleButton.setText("START")
            self.ui.actionStop_Monitoring.setDisabled(True)
            self.ui.actionStart_Monitoring.setEnabled(True)

            self.icon.showMessage('STOP', "Server monitoring was stopped!", self.msgIcon)
        except:
            self.ui.actionStop_Monitoring.setEnabled(True)
            self.ui.actionStart_Monitoring.setDisabled(True)
            self.ui.toggleButton.setText("STOP")
            self.handle_timed_loop()

            self.icon.showMessage('START', "Server monitoring has started!", self.msgIcon)


    def handle_quit_events(self):
        self.timer.cancel()
        self.close()

    def handle_timed_loop(self):
        notifications = monitor_servers(self.data)
        for x in notifications:
            self.icon.showMessage('ALERT', x, self.msgIcon)
            #pass

        self.timer = threading.Timer(10, self.handle_timed_loop)
        self.timer.start()


    def closeEvent(self, event):
        try:
            timer = self.timer
            self.timer.cancel()
            del self.timer
        except:
            pass

        event.accept()