def add(self, alert: SimpleAlert):
        """Add the Alert given in argument to the collection of alerts

        If parent is set, the new Alert is connected to the notification center and the list of displayed alerts is
        updated.

        Attributes:
            alert(SimpleAlert): The alert to add to the collection

        Exceptions:
            ValueError: If the alert argument is None or incorrect.

        """
        if alert is None or not isinstance(alert, SimpleAlert):
            raise ValueError('None or incorrect alert argument')

        self.alert_list.append(alert)
        if self.parent:  # connect the timeout signal to the notification center
            alert.timeout.connect(self.parent.notification_center.add_to_queue)

        alert.id = self.db.insert(  # update the TinyDB
            {'trigger_time': alert.trigger_time,
             'message': alert.get_notification().get_message(),
             'color_hex': alert.notification.color_hex,
             'font_family': alert.notification.font_family,
             'font_size': alert.notification.font_size,
             'sound': alert.notification.sound,
             'periodicity': alert.periodicity})
        self.display()
    def load_db(self):
        """Fill the AlertCollection with Alerts form the TinyDB database

        Exceptions:
            IOError: If a required parameter can't be found in the database. The database is probably corrupted.

        """
        self.alert_list = []  # clean the alert list
        for alert in self.db.all():
            try:
                notification = Notification(alert["message"],
                                            color_hex=alert["color_hex"],
                                            font_family=alert["font_family"],
                                            font_size=alert["font_size"],
                                            sound=alert["sound"])
                new_alert = SimpleAlert(alert["trigger_time"], notification)
            except KeyError as e:
                raise IOError('The alert database seems corrupted' + str(e))

            if "periodicity" in alert:  # periodicity can not appear in db
                new_alert.periodicity = alert["periodicity"]
            new_alert.id = alert.eid  # use the TinyDB object eid as alert id

            self.alert_list.append(new_alert)
            if self.parent:  # connect the alert to the GUI
                new_alert.timeout.connect(
                    self.parent.notification_center.add_to_queue)
Exemplo n.º 3
0
def test_get_notification():
    """Test the :class:`~_clockalarm.SimpleAlert.get_notification` method."""
    global notification
    simplealert = SimpleAlert(10, notification)

    assert (simplealert.get_notification().get_message() ==
            notification.get_message())
Exemplo n.º 4
0
        def button_clicked():
            dw = self.dialog_widget
            periodicity = QTime(0, 0).secsTo(dw.periodicity_edit.time())
            font_family = dw.font_family_edit.text()
            font_size = dw.font_size_edit.value()
            message = dw.alert_message_edit.text()
            if periodicity == 0:
                periodicity = None
            if font_family == '':
                font_family = None
            if font_size <= 0:
                font_size = None
            if message == '':
                message = "Untitled simple alert"
            notification = Notification(message,
                                        font_family=font_family,
                                        font_size=font_size,
                                        color_hex=dw.color_edit.hex_color,
                                        sound=dw.sound_edit.sound_name)
            new_alert = SimpleAlert(dw.date_time_edit.dateTime().toTime_t(),
                                    notification,
                                    periodicity=periodicity)

            self.app.alert_collection.add(new_alert)
            dw.close()
Exemplo n.º 5
0
def test_simple_alert_constructor():
    """Test the :class:`~_clockalarm.SimpleAlert` constructor."""
    global notification
    simplealert = SimpleAlert(10, notification)

    assert simplealert.trigger_time == 10
    assert not simplealert.periodicity
Exemplo n.º 6
0
def test_simple_alert_triggered(qtbot):
    """Test the :class:`~_clockalarm.SimpleAlert.triggered` method."""
    global notification
    simplealert = SimpleAlert(10, notification)
    with qtbot.waitSignal(simplealert.timeout, raising=True, timeout=1000):
        simplealert.triggered()
Exemplo n.º 7
0
def test_get_periodicity():
    """Test the :class:`~_clockalarm.SimpleAlert.get_periodicity` method."""
    global notification
    simplealert = SimpleAlert(10, notification, 30)

    assert simplealert.get_periodicity() == 30