Example #1
0
    def __init__(self, log_dialog, parent=None):
        super(LogStatusWidget, self).__init__(parent)

        main_layout = QHBoxLayout()
        main_layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(main_layout)

        self.app = QApplication.instance()

        self.last_message_level = logging.INFO
        self.handler = log_dialog.handler

        self.label = ClickableLabel()

        self.okay_pixmap = QPixmap(":/freeseer/state_okay.png").scaledToHeight(19)
        self.warning_pixmap = QPixmap(":/freeseer/state_warning.png").scaledToHeight(19)
        self.error_pixmap = QPixmap(":/freeseer/state_error.png").scaledToHeight(19)
        self.icon = ClickableLabel()
        self.icon.setPixmap(self.okay_pixmap)
        self.icon.setToolTip("Okay")

        main_layout.addWidget(self.icon)
        main_layout.addWidget(self.label, Qt.AlignLeft)

        self.connect(self.label, SIGNAL('double_clicked()'), log_dialog.show)
        self.connect(self.icon, SIGNAL('double_clicked()'), log_dialog.show)

        self.message_timer = QTimer()
        self.connect(self.message_timer, SIGNAL("timeout()"), functools.partial(self.label.setText, ""))

        self.handler.add_listener(self)
Example #2
0
    def __init__(self, log_dialog, parent=None):
        super(LogStatusWidget, self).__init__(parent)

        main_layout = QHBoxLayout()
        main_layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(main_layout)

        self.app = QApplication.instance()

        self.last_message_level = logging.INFO
        self.handler = log_dialog.handler

        self.label = ClickableLabel()

        self.okay_pixmap = QPixmap(":/freeseer/state_okay.png").scaledToHeight(
            19)
        self.warning_pixmap = QPixmap(
            ":/freeseer/state_warning.png").scaledToHeight(19)
        self.error_pixmap = QPixmap(
            ":/freeseer/state_error.png").scaledToHeight(19)
        self.icon = ClickableLabel()
        self.icon.setPixmap(self.okay_pixmap)
        self.icon.setToolTip("Okay")

        main_layout.addWidget(self.icon)
        main_layout.addWidget(self.label, Qt.AlignLeft)

        self.connect(self.label, SIGNAL('double_clicked()'), log_dialog.show)
        self.connect(self.icon, SIGNAL('double_clicked()'), log_dialog.show)

        self.message_timer = QTimer()
        self.connect(self.message_timer, SIGNAL("timeout()"),
                     functools.partial(self.label.setText, ""))

        self.handler.add_listener(self)
Example #3
0
class LogStatusWidget(QWidgetWithDpi):
    """Widget to display latest log message and icon.

    This widget is used by RecordApp to show the latest
    log message in it's status bar. It opens the LogDialog
    it was created with, when it is double-clicked."""
    def __init__(self, log_dialog, parent=None):
        super(LogStatusWidget, self).__init__(parent)

        main_layout = QHBoxLayout()
        main_layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(main_layout)

        self.app = QApplication.instance()

        self.last_message_level = logging.INFO
        self.handler = log_dialog.handler

        self.label = ClickableLabel()

        self.okay_pixmap = QPixmap(":/freeseer/state_okay.png").scaledToHeight(
            self.set_height_with_dpi(19))
        self.warning_pixmap = QPixmap(
            ":/freeseer/state_warning.png").scaledToHeight(
                self.set_height_with_dpi(19))
        self.error_pixmap = QPixmap(
            ":/freeseer/state_error.png").scaledToHeight(
                self.set_height_with_dpi(19))
        self.icon = ClickableLabel()
        self.icon.setPixmap(self.okay_pixmap)
        self.icon.setToolTip("Okay")

        main_layout.addWidget(self.icon)
        main_layout.addWidget(self.label, Qt.AlignLeft)

        self.connect(self.label, SIGNAL('double_clicked()'), log_dialog.show)
        self.connect(self.icon, SIGNAL('double_clicked()'), log_dialog.show)

        self.message_timer = QTimer()
        self.connect(self.message_timer, SIGNAL("timeout()"),
                     functools.partial(self.label.setText, ""))

        self.handler.add_listener(self)

    def __del__(self):
        self.handler.remove_listener(self)

    def message(self, message):
        """Shows latest high priority log message in status bar.

        This method is called by the LogHandler when a new log message is received.
        LogStatusWidget is added as a listener to a LogHandler on init.
        """
        level = message["levelno"]
        if level >= self.last_message_level and level >= logging.INFO:
            if self.message_timer.isActive():
                self.message_timer.stop()

            if level == logging.INFO:
                self.message_timer.start(3000)

            if level != self.last_message_level:
                if level == logging.INFO:
                    self.icon.setPixmap(self.okay_pixmap)
                    self.icon.setToolTip(self.okay_string)
                elif level == logging.WARNING:
                    self.icon.setPixmap(self.warning_pixmap)
                    self.icon.setToolTip(self.warning_string)
                else:
                    self.icon.setPixmap(self.error_pixmap)
                    self.icon.setToolTip(self.error_string)

            self.label.setText(message["message"])
            self.last_message_level = level

    def retranslate(self):
        self.okay_string = self.app.translate("LogStatusWidget", "Okay")
        self.warning_string = self.app.translate("LogStatusWidget", "Warning.")
        self.error_string = self.app.translate("LogStatusWidget", "Error!")
        self.label.setToolTip(
            self.app.translate("LogStatusWidget",
                               "Double-click to open log window"))
        if self.last_message_level == logging.INFO:
            self.icon.setToolTip(self.okay_string)
        elif self.last_message_level == logging.WARNING:
            self.icon.setToolTip(self.warning_string)
        else:
            self.icon.setToolTip(self.error_string)
Example #4
0
class LogStatusWidget(QWidget):
    """Widget to display latest log message and icon.

    This widget is used by RecordApp to show the latest
    log message in it's status bar. It opens the LogDialog
    it was created with, when it is double-clicked."""

    def __init__(self, log_dialog, parent=None):
        super(LogStatusWidget, self).__init__(parent)

        main_layout = QHBoxLayout()
        main_layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(main_layout)

        self.app = QApplication.instance()

        self.last_message_level = logging.INFO
        self.handler = log_dialog.handler

        self.label = ClickableLabel()

        self.okay_pixmap = QPixmap(":/freeseer/state_okay.png").scaledToHeight(19)
        self.warning_pixmap = QPixmap(":/freeseer/state_warning.png").scaledToHeight(19)
        self.error_pixmap = QPixmap(":/freeseer/state_error.png").scaledToHeight(19)
        self.icon = ClickableLabel()
        self.icon.setPixmap(self.okay_pixmap)
        self.icon.setToolTip("Okay")

        main_layout.addWidget(self.icon)
        main_layout.addWidget(self.label, Qt.AlignLeft)

        self.connect(self.label, SIGNAL('double_clicked()'), log_dialog.show)
        self.connect(self.icon, SIGNAL('double_clicked()'), log_dialog.show)

        self.message_timer = QTimer()
        self.connect(self.message_timer, SIGNAL("timeout()"), functools.partial(self.label.setText, ""))

        self.handler.add_listener(self)

    def __del__(self):
        self.handler.remove_listener(self)

    def message(self, message):
        """Shows latest high priority log message in status bar.

        This method is called by the LogHandler when a new log message is received.
        LogStatusWidget is added as a listener to a LogHandler on init.
        """
        level = message["levelno"]
        if level >= self.last_message_level and level >= logging.INFO:
            if self.message_timer.isActive():
                self.message_timer.stop()

            if level == logging.INFO:
                self.message_timer.start(3000)

            if level != self.last_message_level:
                if level == logging.INFO:
                    self.icon.setPixmap(self.okay_pixmap)
                    self.icon.setToolTip(self.okay_string)
                elif level == logging.WARNING:
                    self.icon.setPixmap(self.warning_pixmap)
                    self.icon.setToolTip(self.warning_string)
                else:
                    self.icon.setPixmap(self.error_pixmap)
                    self.icon.setToolTip(self.error_string)

            self.label.setText(message["message"])
            self.last_message_level = level

    def retranslate(self):
        self.okay_string = self.app.translate("LogStatusWidget", "Okay")
        self.warning_string = self.app.translate("LogStatusWidget", "Warning.")
        self.error_string = self.app.translate("LogStatusWidget", "Error!")
        self.label.setToolTip(self.app.translate("LogStatusWidget", "Double-click to open log window"))
        if self.last_message_level == logging.INFO:
            self.icon.setToolTip(self.okay_string)
        elif self.last_message_level == logging.WARNING:
            self.icon.setToolTip(self.warning_string)
        else:
            self.icon.setToolTip(self.error_string)