Exemplo n.º 1
0
 def __init__(self, parent, format):
     QDateTimeEdit.__init__(self, parent)
     self.setFrame(False)
     self.setMinimumDateTime(UNDEFINED_QDATETIME)
     self.setSpecialValueText(_('Undefined'))
     self.setCalendarPopup(True)
     self.setDisplayFormat(format)
Exemplo n.º 2
0
 def __init__(self, parent, format):
     QDateTimeEdit.__init__(self, parent)
     self.setFrame(False)
     self.setMinimumDateTime(UNDEFINED_QDATETIME)
     self.setSpecialValueText(_('Undefined'))
     self.setCalendarPopup(True)
     self.setDisplayFormat(format)
Exemplo n.º 3
0
 def __init__(self, parent=None):
     QDateTimeEdit.__init__(self, parent)
     self.setMinimumDateTime(UNDEFINED_QDATETIME)
     self.setCalendarPopup(True)
     self.cw = CalendarWidget(self)
     self.cw.setVerticalHeaderFormat(self.cw.NoVerticalHeader)
     self.setCalendarWidget(self.cw)
     self.setSpecialValueText(_('Undefined'))
Exemplo n.º 4
0
 def __init__(self, parent, format_):
     QDateTimeEdit.__init__(self, parent)
     self.setFrame(False)
     self.setMinimumDateTime(UNDEFINED_QDATETIME)
     self.setSpecialValueText(_('Undefined'))
     self.setCalendarPopup(True)
     if format_ == 'iso':
         format_ = internal_iso_format_string()
     self.setDisplayFormat(format_)
Exemplo n.º 5
0
 def __init__(self, parent, format_):
     QDateTimeEdit.__init__(self, parent)
     self.setFrame(False)
     self.setMinimumDateTime(UNDEFINED_QDATETIME)
     self.setSpecialValueText(_('Undefined'))
     self.setCalendarPopup(True)
     if format_ == 'iso':
         format_ = 'yyyy-MM-ddTHH:mm:ss'
     self.setDisplayFormat(format_)
Exemplo n.º 6
0
 def __init__(self, parent, format_):
     QDateTimeEdit.__init__(self, parent)
     self.setFrame(False)
     self.setMinimumDateTime(UNDEFINED_QDATETIME)
     self.setSpecialValueText(_('Undefined'))
     self.setCalendarPopup(True)
     if format_ == 'iso':
         format_ = internal_iso_format_string()
     self.setDisplayFormat(format_)
Exemplo n.º 7
0
 def __init__(self, parent=None):
     QDateTimeEdit.__init__(self, parent)
     le = LineEditForDateTimeEdit(self)
     self.setLineEdit(le)
     le.date_time_pasted.connect(self.date_time_pasted, type=Qt.QueuedConnection)
     le.date_time_copied.connect(self.date_time_copied, type=Qt.QueuedConnection)
     self.setMinimumDateTime(UNDEFINED_QDATETIME)
     self.setCalendarPopup(True)
     self.cw = CalendarWidget(self)
     self.cw.setVerticalHeaderFormat(self.cw.NoVerticalHeader)
     self.setCalendarWidget(self.cw)
     self.setSpecialValueText(_('Undefined'))
Exemplo n.º 8
0
 def __init__(self, parent, default=Limit.min, calendar_popup=True):
     QDateTimeEdit.__init__(self, parent)
     self.setDisplayFormat('dd-MMM-yyyy hh:mm')
     self.setButtonSymbols(QDateTimeEdit.NoButtons)
     self._min_date = self._max_date = None
     self._start_date = self._end_date = None
     self.isLimit = False
     self._default = default
     self.isLimitChanged.connect(self._handle_is_limit_changed)
     self.dateTimeChanged.connect(self._handle_date_time_changed)
     self.setCalendarPopup(calendar_popup)
     if calendar_popup:
         self.calendarWidget().clicked.connect(
             self._handle_date_changed_from_calendar)
Exemplo n.º 9
0
 def __init__(self, parent=None):
     super(DownQDialog, self).__init__(parent)
     self.setWindowTitle(_('Request a Downtime'))
     self.setWindowFlags(Qt.FramelessWindowHint)
     self.setStyleSheet(settings.css_style)
     self.setWindowIcon(QIcon(settings.get_image('icon')))
     self.setMinimumSize(360, 460)
     self.setObjectName('dialog')
     # Fields
     self.fixed = True
     self.fixed_toggle_btn = ToggleQWidgetButton()
     self.duration = QTimeEdit()
     self.start_time = QDateTimeEdit()
     self.end_time = QDateTimeEdit()
     self.comment_edit = QTextEdit()
     self.offset = None
 def __init__(self, parent=None):
     super(DownQDialog, self).__init__(parent)
     self.setWindowTitle(_('Request a Downtime'))
     self.setWindowFlags(Qt.FramelessWindowHint)
     self.setStyleSheet(settings.css_style)
     self.setWindowIcon(QIcon(settings.get_image('icon')))
     self.setMinimumSize(360, 460)
     self.setObjectName('dialog')
     # Fields
     self.fixed = True
     self.fixed_toggle_btn = ToggleQWidgetButton()
     self.duration = QTimeEdit()
     self.start_time = QDateTimeEdit()
     self.end_time = QDateTimeEdit()
     self.comment_edit = QTextEdit()
     self.offset = None
Exemplo n.º 11
0
 def keyPressEvent(self, ev):
     if ev.key() == Qt.Key_Minus:
         ev.accept()
         self.clear_date()
     elif ev.key() == Qt.Key_Equal:
         self.today_date()
         ev.accept()
     else:
         return QDateTimeEdit.keyPressEvent(self, ev)
Exemplo n.º 12
0
 def keyPressEvent(self, ev):
     if ev.key() == Qt.Key_Minus:
         ev.accept()
         self.clear_date()
     elif ev.key() == Qt.Key_Equal:
         self.today_date()
         ev.accept()
     else:
         return QDateTimeEdit.keyPressEvent(self, ev)
Exemplo n.º 13
0
 def keyPressEvent(self, ev):
     if ev.key() == Qt.Key_Minus:
         ev.accept()
         self.setDateTime(UNDEFINED_QDATETIME)
     elif ev.key() == Qt.Key_Equal:
         ev.accept()
         self.setDateTime(QDateTime.currentDateTime())
     else:
         return QDateTimeEdit.keyPressEvent(self, ev)
Exemplo n.º 14
0
 def keyPressEvent(self, ev):
     if ev.key() == Qt.Key_Minus:
         ev.accept()
         self.setDateTime(self.minimumDateTime())
     elif ev.key() == Qt.Key_Equal:
         ev.accept()
         self.setDateTime(QDateTime.currentDateTime())
     else:
         return QDateTimeEdit.keyPressEvent(self, ev)
Exemplo n.º 15
0
 def focusOutEvent(self, event):
     if self._start_date and self.dateTime() < self._start_date:
         self.setDateTime(self._start_date)
     elif self._min_date and self.dateTime() < self._min_date:
         self.setDateTime(self._min_date)
     elif self._end_date and self.dateTime() > self._end_date:
         self.setDateTime(self._end_date)
     elif self._max_date and self.dateTime() > self._max_date:
         self.setDateTime(self._max_date)
     return QDateTimeEdit.focusOutEvent(self, event)
Exemplo n.º 16
0
 def keyPressEvent(self, ev):
     if ev.key() == Qt.Key_Minus:
         ev.accept()
         self.clear_date()
     elif ev.key() == Qt.Key_Equal:
         self.today_date()
         ev.accept()
     elif ev.matches(QKeySequence.Copy):
         self.lineEdit().copy()
         ev.accept()
     elif ev.matches(QKeySequence.Paste):
         self.lineEdit().paste()
         ev.accept()
     else:
         return QDateTimeEdit.keyPressEvent(self, ev)
Exemplo n.º 17
0
class HistoryWidget(QDialog):
    """
    class HistonWidget
    """

    _v_curve_colors = [Qt.white, Qt.gray, Qt.red, Qt.green, Qt.blue, Qt.cyan, Qt.magenta, Qt.darkYellow]
    _v_curve_checked = [True, True, True, True, True, True, True, True]

    def __init__(self, parent=None):
        super(HistoryWidget, self).__init__(parent)
        self.setObjectName("HistoryWidget")
        self.resize(800, 480)
        self.setWindowTitle("历史数据查看")

        # layout - top
        horiLayoutTop = QHBoxLayout()

        buttonQuit = QPushButton(self)
        buttonQuit.setObjectName("buttonQuit")
        horiLayoutTop.addSpacing(25)
        horiLayoutTop.addWidget(buttonQuit, 0, Qt.AlignLeft)
        horiLayoutTop.addStretch()

        # button-export
        buttonExport = QPushButton(self)
        buttonExport.setObjectName("buttonExport")
        horiLayoutTop.addWidget(buttonExport)
        horiLayoutTop.addStretch()

        # button-open
        buttonOpen = QPushButton(self)
        buttonOpen.setObjectName("buttonOpen")
        horiLayoutTop.addWidget(buttonOpen)
        horiLayoutTop.addStretch()

        formLayoutTime = QFormLayout()
        formLayoutTime.setFormAlignment(Qt.AlignVCenter)
        horiLayoutTop.addLayout(formLayoutTime)
        horiLayoutTop.addStretch()

        self.dateTimeEditStart = QDateTimeEdit(self)
        self.dateTimeEditStart.setObjectName("dateTimeEditStart")
        self.dateTimeEditStart.setDisplayFormat("yyyy-MM-dd HH:mm:ss")
        formLayoutTime.addRow("起始时间:", self.dateTimeEditStart)

        self.dateTimeEditEnd = QDateTimeEdit(self)
        self.dateTimeEditEnd.setObjectName("dateTimeEditEnd")
        self.dateTimeEditEnd.setDisplayFormat("yyyy-MM-dd HH:mm:ss")
        formLayoutTime.addRow("结束时间:", self.dateTimeEditEnd)

        # LBP
        formLayoutLBP = QFormLayout()
        formLayoutLBP.setFormAlignment(Qt.AlignVCenter)
        formLayoutLBP.setLabelAlignment(Qt.AlignRight)
        horiLayoutTop.addLayout(formLayoutLBP)
        horiLayoutTop.addStretch()
        self.checkBoxLBPMajor = QCheckBox("主", self)
        self.checkBoxLBPMajor.setProperty("curveColor", "#101010")
        self.checkBoxLBPMinor = QCheckBox("副", self)
        self.checkBoxLBPMinor.setProperty("curveColor", "#101010")
        formLayoutLBP.addRow("左刹车压力:", self.checkBoxLBPMajor)
        formLayoutLBP.addRow("", self.checkBoxLBPMinor)

        # RBP
        formLayoutRBP = QFormLayout()
        formLayoutRBP.setFormAlignment(Qt.AlignVCenter)
        formLayoutRBP.setLabelAlignment(Qt.AlignRight)
        horiLayoutTop.addLayout(formLayoutRBP)
        horiLayoutTop.addStretch()
        self.checkBoxRBPMajor = QCheckBox("主", self)
        self.checkBoxRBPMajor.setProperty("curveColor", "#101010")
        self.checkBoxRBPMinor = QCheckBox("副", self)
        self.checkBoxRBPMinor.setProperty("curveColor", "#101010")
        formLayoutRBP.addRow("右刹车压力:", self.checkBoxRBPMajor)
        formLayoutRBP.addRow("", self.checkBoxRBPMinor)

        # LRP
        formLayoutLRP = QFormLayout()
        formLayoutLRP.setFormAlignment(Qt.AlignVCenter)
        formLayoutLRP.setLabelAlignment(Qt.AlignRight)
        horiLayoutTop.addLayout(formLayoutLRP)
        horiLayoutTop.addStretch()
        self.checkBoxLRPTheory = QCheckBox("理论", self)
        self.checkBoxLRPTheory.setProperty("curveColor", "#101010")
        self.checkBoxLRPReal = QCheckBox("实际", self)
        self.checkBoxLRPReal.setProperty("curveColor", "#101010")
        formLayoutLRP.addRow("左转速:", self.checkBoxLRPTheory)
        formLayoutLRP.addRow("", self.checkBoxLRPReal)

        # RRP
        formLayoutRRP = QFormLayout()
        formLayoutRRP.setFormAlignment(Qt.AlignVCenter)
        formLayoutRRP.setLabelAlignment(Qt.AlignRight)
        horiLayoutTop.addLayout(formLayoutRRP)
        horiLayoutTop.addStretch()
        self.checkBoxRRPTheory = QCheckBox("理论", self)
        self.checkBoxRRPTheory.setProperty("curveColor", "#101010")
        self.checkBoxRRPReal = QCheckBox("实际", self)
        self.checkBoxRRPReal.setProperty("curveColor", "#101010")
        formLayoutRRP.addRow("右转速:", self.checkBoxRRPTheory)
        formLayoutRRP.addRow("", self.checkBoxRRPReal)

        # button-update
        buttonUpdate = QPushButton(self)
        buttonUpdate.setObjectName("buttonUpdate")
        horiLayoutTop.addWidget(buttonUpdate)
        horiLayoutTop.addStretch()

        # middle-curves
        self.curveHistory = CurveWidget("历史数据回放", True, self)
        self.curveHistory.setMaximumWidth(10e5)
        self.curveHistory.setScaleLabelFormat("yyyy/MM/dd\n  HH:mm:ss")
        self.curveHistory.clear()

        #
        vertLayoutMain = QVBoxLayout(self)
        vertLayoutMain.addLayout(horiLayoutTop)
        vertLayoutMain.addWidget(self.curveHistory)

        buttonQuit.clicked.connect(self.accept)
        buttonOpen.clicked.connect(self.buttonOpenClicked)
        buttonExport.clicked.connect(self.buttonExportClicked)
        self.dateTimeEditStart.dateTimeChanged.connect(self.dateTimeStartChanged)
        self.dateTimeEditEnd.dateTimeChanged.connect(self.dateTimeEndChanged)
        self.checkBoxLBPMajor.toggled.connect(self.checkBoxLBPMajorToggled)
        self.checkBoxLBPMinor.toggled.connect(self.checkBoxLBPMinorToggled)
        self.checkBoxRBPMajor.toggled.connect(self.checkBoxRBPMajorToggled)
        self.checkBoxRBPMinor.toggled.connect(self.checkBoxRBPMinorToggled)
        self.checkBoxLRPTheory.toggled.connect(self.checkBoxLRPTheoryToggled)
        self.checkBoxLRPReal.toggled.connect(self.checkBoxLRPRealToggled)
        self.checkBoxRRPTheory.toggled.connect(self.checkBoxRRPTheoryToggled)
        self.checkBoxRRPReal.toggled.connect(self.checkBoxRRPRealToggled)
        buttonUpdate.clicked.connect(self.buttonUpdateClicked)

        # finalLy initialize
        self.checkBoxLBPMajor.setChecked(self._v_curve_checked[0])
        self.checkBoxLBPMinor.setChecked(self._v_curve_checked[1])
        self.checkBoxRBPMajor.setChecked(self._v_curve_checked[2])
        self.checkBoxRBPMinor.setChecked(self._v_curve_checked[3])
        self.checkBoxLRPTheory.setChecked(self._v_curve_checked[4])
        self.checkBoxLRPReal.setChecked(self._v_curve_checked[5])
        self.checkBoxRRPTheory.setChecked(self._v_curve_checked[6])
        self.checkBoxRRPReal.setChecked(self._v_curve_checked[7])

    def buttonOpenClicked(self):
        fileDialog = QFileDialog(
            self, "打开历史数据文件", QApplication.applicationDirPath() + "/../data", "Database File (*.db *.mdb)"
        )
        if fileDialog.exec_() == QDialog.Rejected:
            return
        # clear curve
        self.curveHistory.clear()
        #
        filePaths = fileDialog.selectedFiles()
        if filePaths.isEmpty():
            return
        filePath = filePaths.first()
        if filePath.isEmpty():
            return
        # open database
        if not DatabaseMgr().open(filePath):
            return
        #
        startTime = QDateTime.fromMSecsSinceEpoch(DatabaseMgr().startTime())
        endTime = QDateTime.fromMSecsSinceEpoch(DatabaseMgr().endTime())
        self.dateTimeEditStart.setDateTimeRange(startTime, endTime)
        self.dateTimeEditEnd.setDateTimeRange(startTime, endTime)
        self.dateTimeEditEnd.setDateTime(endTime)
        self.dateTimeEditStart.setDateTime(startTime)

        # title of curve
        self.curveHistory.setTitle("历史数据回放" + "(" + QFileInfo(filePath).fileName() + ")")

    def buttonExportClicked(self):
        (filePaths, filter) = QFileDialog.getOpenFileNames(
            parent=self,
            caption="转换数据库文件为文本格式",
            directory=QApplication.applicationDirPath() + "/../data",
            filter="Database file (*.db * mdb)",
        )
        if not filePaths:
            return
        #
        if DatabaseMgr().convertToText(filePaths):
            QMessageBox.information(self, "格式转换", "转换成功!")
        else:
            QMessageBox.warning(self, "格式转换", "转换失败!")

    def dateTimeStartChanged(self, dateTime):
        dateTimeEnd = self.dateTimeEditEnd.dateTime()
        if dateTime > dateTimeEnd:
            self.dateTimeEditStart.setDateTime(dateTimeEnd)

    def dateTimeEndChanged(self, dateTime):
        dateTimeStart = self.dateTimeEditStart.dateTime()
        if dateTime < dateTimeStart:
            self.dateTimeEditEnd.setDateTime(dateTimeStart)

    def checkBoxLBPMajorToggled(self, checked):
        self._v_curve_checked[0] = checked

    def checkBoxLBPMinorToggled(self, checked):
        self._v_curve_checked[1] = checked

    def checkBoxRBPMajorToggled(self, checked):
        self._v_curve_checked[2] = checked

    def checkBoxRBPMinorToggled(self, checked):
        self._v_curve_checked[3] = checked

    def checkBoxLRPTheoryToggled(self, checked):
        self._v_curve_checked[4] = checked

    def checkBoxLRPRealToggled(self, checked):
        self._v_curve_checked[5] = checked

    def checkBoxRRPTheoryToggled(self, checked):
        self._v_curve_checked[6] = checked

    def checkBoxRRPRealToggled(self, checked):
        self._v_curve_checked[7] = checked

    def buttonUpdateClicked(self):
        # clear curve
        self.curveHistory.clear()

        points = []
        startTime = self.dateTimeEditStart.dateTime().toMSecsSinceEpoch()
        endTime = self.dateTimeEditEnd.dateTime().toMSecsSinceEpoch()

        # LBP-Major
        if self.checkBoxLBPMajor.isChecked():
            # read
            points.clear()
            if DatabaseMgr().read("lMBrakeP", points, startTime, endTime):
                self.curveHistory.addCurve("左刹压力-主", QPen(self.randomColor(0)), points)
        # LBP-Minor
        if self.checkBoxLBPMinor.isChecked():
            # read
            points.clear()
            if DatabaseMgr().read("lABrakeP", points, startTime, endTime):
                self.curveHistory.addCurve("左刹压力-副", QPen(self.randomColor(1)), points)
        # RBP-Major
        if self.checkBoxRBPMajor.isChecked():
            # read
            points.clear()
            if DatabaseMgr().read("rMBrakeP", points, startTime, endTime):
                self.curveHistory.addCurve("右刹压力-主", QPen(self.randomColor(2)), points)
        # RBP-Minor
        if self.checkBoxRBPMinor.isChecked():
            # read
            points.clear()
            if DatabaseMgr().read("rABrakeP", points, startTime, endTime):
                self.curveHistory.addCurve("右刹压力-副", QPen(self.randomColor(3)), points)

        # LRP-Theory
        if self.checkBoxLRPTheory.isChecked():
            # read
            points.clear()
            if DatabaseMgr().read("lTheorySpd", points, startTime, endTime):
                self.curveHistory.addCurve("左转速-理论", QPen(self.randomColor(4)), points)
        # LRP-Real
        if self.checkBoxLRPReal.isChecked():
            # read
            points.clear()
            if DatabaseMgr().read("lWheelSpd", points, startTime, endTime):
                self.curveHistory.addCurve("左转速-实际", QPen(self.randomColor(5)), points)
        # RRP-Theory
        if self.checkBoxRRPTheory.isChecked():
            # read
            points.clear()
            if DatabaseMgr().read("rTheorySpd", points, startTime, endTime):
                self.curveHistory.addCurve("右转速-理论", QPen(self.randomColor(6)), points)
        # RRP-Real
        if self.checkBoxRRPReal.isChecked():
            # read
            points.clear()
            if DatabaseMgr().read("rWheelSpd", points, startTime, endTime):
                self.curveHistory.addCurve("右转速-实际", QPen(self.randomColor(7)), points)

    @staticmethod
    def randomColor(index):
        return HistoryWidget._v_curve_colors[index]
Exemplo n.º 18
0
 def focusOutEvent(self, x):
     self.setSpecialValueText(_('Undefined'))
     QDateTimeEdit.focusOutEvent(self, x)
Exemplo n.º 19
0
 def focusInEvent(self, x):
     self.setSpecialValueText('')
     QDateTimeEdit.focusInEvent(self, x)
class DownQDialog(QDialog):
    """
        Class who create Downtime QDialog for hosts/services
    """

    def __init__(self, parent=None):
        super(DownQDialog, self).__init__(parent)
        self.setWindowTitle(_('Request a Downtime'))
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setStyleSheet(settings.css_style)
        self.setWindowIcon(QIcon(settings.get_image('icon')))
        self.setMinimumSize(360, 460)
        self.setObjectName('dialog')
        # Fields
        self.fixed = True
        self.fixed_toggle_btn = ToggleQWidgetButton()
        self.duration = QTimeEdit()
        self.start_time = QDateTimeEdit()
        self.end_time = QDateTimeEdit()
        self.comment_edit = QTextEdit()
        self.offset = None

    def initialize(self, item_type, item_name, comment):  # pylint: disable=too-many-locals
        """
        Initialize Downtime QDialog

        :param item_type: type of item to acknowledge : host | service
        :type item_type: str
        :param item_name: name of the item to acknowledge
        :type item_name: str
        :param comment: the default comment of action
        :type comment: str
        """

        logger.debug("Create Downtime QDialog...")

        # Main status_layout
        center_widget(self)
        main_layout = QVBoxLayout(self)
        main_layout.setContentsMargins(0, 0, 0, 0)

        main_layout.addWidget(get_logo_widget(self, _('Request Downtime')))

        downtime_widget = QWidget()
        downtime_widget.setObjectName('dialog')
        downtime_layout = QGridLayout(downtime_widget)

        downtime_title = QLabel(_('Request a downtime'))
        downtime_title.setObjectName('itemtitle')
        downtime_layout.addWidget(downtime_title, 0, 0, 1, 3)

        host_label = QLabel('<b>%s:</b> %s' % (item_type.capitalize(), item_name))
        downtime_layout.addWidget(host_label, 1, 0, 1, 1)

        options_label = QLabel(_('Downtime options:'))
        options_label.setObjectName('subtitle')
        downtime_layout.addWidget(options_label, 2, 0, 1, 1)

        self.fixed_toggle_btn.initialize()
        self.fixed_toggle_btn.update_btn_state(self.fixed)
        downtime_layout.addWidget(self.fixed_toggle_btn, 2, 1, 1, 1)

        fixed_label = QLabel(_('Fixed'))
        downtime_layout.addWidget(fixed_label, 2, 2, 1, 1)

        fixed_info = QLabel(
            _(
                'If checked, downtime will start and end at the times specified'
                ' by the “start time” and “end time” fields.'
            )
        )
        fixed_info.setWordWrap(True)
        downtime_layout.addWidget(fixed_info, 3, 0, 1, 3)

        duration_label = QLabel(_('Duration'))
        duration_label.setObjectName('subtitle')
        downtime_layout.addWidget(duration_label, 4, 0, 1, 1)

        duration_clock = QLabel()
        duration_clock.setPixmap(QPixmap(settings.get_image('time')))
        downtime_layout.addWidget(duration_clock, 4, 1, 1, 1)
        duration_clock.setFixedSize(16, 16)
        duration_clock.setScaledContents(True)

        self.duration.setTime(QTime(4, 00))
        self.duration.setDisplayFormat("HH'h'mm")
        downtime_layout.addWidget(self.duration, 4, 2, 1, 1)

        duration_info = QLabel(
            _('Sets the duration if it is a non-fixed downtime.')
        )
        downtime_layout.addWidget(duration_info, 5, 0, 1, 3)

        date_range_label = QLabel(_('Downtime date range'))
        date_range_label.setObjectName('subtitle')
        downtime_layout.addWidget(date_range_label, 6, 0, 1, 1)

        calendar_label = QLabel()
        calendar_label.setPixmap(QPixmap(settings.get_image('calendar')))
        calendar_label.setFixedSize(16, 16)
        calendar_label.setScaledContents(True)
        downtime_layout.addWidget(calendar_label, 6, 1, 1, 1)

        start_time_label = QLabel(_('Start time:'))
        downtime_layout.addWidget(start_time_label, 7, 0, 1, 1)

        self.start_time.setCalendarPopup(True)
        self.start_time.setDateTime(datetime.datetime.now())
        self.start_time.setDisplayFormat("dd/MM/yyyy HH'h'mm")
        downtime_layout.addWidget(self.start_time, 7, 1, 1, 2)

        end_time_label = QLabel(_('End time:'))
        downtime_layout.addWidget(end_time_label, 8, 0, 1, 1)

        self.end_time.setCalendarPopup(True)
        self.end_time.setDateTime(datetime.datetime.now() + datetime.timedelta(hours=2))
        self.end_time.setDisplayFormat("dd/MM/yyyy HH'h'mm")
        downtime_layout.addWidget(self.end_time, 8, 1, 1, 2)

        self.comment_edit.setText(comment)
        self.comment_edit.setMaximumHeight(60)
        downtime_layout.addWidget(self.comment_edit, 9, 0, 1, 3)

        request_btn = QPushButton(_('REQUEST DOWNTIME'), self)
        request_btn.clicked.connect(self.handle_accept)
        request_btn.setObjectName('valid')
        request_btn.setMinimumHeight(30)
        request_btn.setDefault(True)
        downtime_layout.addWidget(request_btn, 10, 0, 1, 3)

        main_layout.addWidget(downtime_widget)

    def duration_to_seconds(self):
        """
        Return "duration" QTimeEdit value in seconds

        :return: "duration" in seconds
        :rtype: int
        """

        return QTime(0, 0).secsTo(self.duration.time())

    def handle_accept(self):
        """
        Check if end_time timestamp is not lower than start_time

        """

        if self.start_time.dateTime().toTime_t() > self.end_time.dateTime().toTime_t():
            logger.warning('Try to add Downtime with "End Time" lower than "Start Time"')
        else:
            self.accept()

    def mousePressEvent(self, event):  # pragma: no cover
        """ QWidget.mousePressEvent(QMouseEvent) """

        self.offset = event.pos()

    def mouseMoveEvent(self, event):  # pragma: no cover
        """ QWidget.mousePressEvent(QMouseEvent) """

        try:
            x = event.globalX()
            y = event.globalY()
            x_w = self.offset.x()
            y_w = self.offset.y()
            self.move(x - x_w, y - y_w)
        except AttributeError as e:
            logger.warning('Move Event %s: %s', self.objectName(), str(e))
Exemplo n.º 21
0
class DownQDialog(QDialog):
    """
        Class who create Downtime QDialog for hosts/services
    """
    def __init__(self, parent=None):
        super(DownQDialog, self).__init__(parent)
        self.setWindowTitle(_('Request a Downtime'))
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setStyleSheet(settings.css_style)
        self.setWindowIcon(QIcon(settings.get_image('icon')))
        self.setMinimumSize(360, 460)
        self.setObjectName('dialog')
        # Fields
        self.fixed = True
        self.fixed_toggle_btn = ToggleQWidgetButton()
        self.duration = QTimeEdit()
        self.start_time = QDateTimeEdit()
        self.end_time = QDateTimeEdit()
        self.comment_edit = QTextEdit()
        self.offset = None

    def initialize(self, item_type, item_name, comment):  # pylint: disable=too-many-locals
        """
        Initialize Downtime QDialog

        :param item_type: type of item to acknowledge : host | service
        :type item_type: str
        :param item_name: name of the item to acknowledge
        :type item_name: str
        :param comment: the default comment of action
        :type comment: str
        """

        logger.debug("Create Downtime QDialog...")

        # Main status_layout
        center_widget(self)
        main_layout = QVBoxLayout(self)
        main_layout.setContentsMargins(0, 0, 0, 0)

        main_layout.addWidget(get_logo_widget(self, _('Request Downtime')))

        downtime_widget = QWidget()
        downtime_widget.setObjectName('dialog')
        downtime_layout = QGridLayout(downtime_widget)

        downtime_title = QLabel(_('Request a downtime'))
        downtime_title.setObjectName('itemtitle')
        downtime_layout.addWidget(downtime_title, 0, 0, 1, 3)

        host_label = QLabel('<b>%s:</b> %s' %
                            (item_type.capitalize(), item_name))
        downtime_layout.addWidget(host_label, 1, 0, 1, 1)

        options_label = QLabel(_('Downtime options:'))
        options_label.setObjectName('subtitle')
        downtime_layout.addWidget(options_label, 2, 0, 1, 1)

        self.fixed_toggle_btn.initialize()
        self.fixed_toggle_btn.update_btn_state(self.fixed)
        downtime_layout.addWidget(self.fixed_toggle_btn, 2, 1, 1, 1)

        fixed_label = QLabel(_('Fixed'))
        downtime_layout.addWidget(fixed_label, 2, 2, 1, 1)

        fixed_info = QLabel(
            _('If checked, downtime will start and end at the times specified'
              ' by the “start time” and “end time” fields.'))
        fixed_info.setWordWrap(True)
        downtime_layout.addWidget(fixed_info, 3, 0, 1, 3)

        duration_label = QLabel(_('Duration'))
        duration_label.setObjectName('subtitle')
        downtime_layout.addWidget(duration_label, 4, 0, 1, 1)

        duration_clock = QLabel()
        duration_clock.setPixmap(QPixmap(settings.get_image('time')))
        downtime_layout.addWidget(duration_clock, 4, 1, 1, 1)
        duration_clock.setFixedSize(16, 16)
        duration_clock.setScaledContents(True)

        self.duration.setTime(QTime(4, 00))
        self.duration.setDisplayFormat("HH'h'mm")
        downtime_layout.addWidget(self.duration, 4, 2, 1, 1)

        duration_info = QLabel(
            _('Sets the duration if it is a non-fixed downtime.'))
        downtime_layout.addWidget(duration_info, 5, 0, 1, 3)

        date_range_label = QLabel(_('Downtime date range'))
        date_range_label.setObjectName('subtitle')
        downtime_layout.addWidget(date_range_label, 6, 0, 1, 1)

        calendar_label = QLabel()
        calendar_label.setPixmap(QPixmap(settings.get_image('calendar')))
        calendar_label.setFixedSize(16, 16)
        calendar_label.setScaledContents(True)
        downtime_layout.addWidget(calendar_label, 6, 1, 1, 1)

        start_time_label = QLabel(_('Start time:'))
        downtime_layout.addWidget(start_time_label, 7, 0, 1, 1)

        self.start_time.setCalendarPopup(True)
        self.start_time.setDateTime(datetime.datetime.now())
        self.start_time.setDisplayFormat("dd/MM/yyyy HH'h'mm")
        downtime_layout.addWidget(self.start_time, 7, 1, 1, 2)

        end_time_label = QLabel(_('End time:'))
        downtime_layout.addWidget(end_time_label, 8, 0, 1, 1)

        self.end_time.setCalendarPopup(True)
        self.end_time.setDateTime(datetime.datetime.now() +
                                  datetime.timedelta(hours=2))
        self.end_time.setDisplayFormat("dd/MM/yyyy HH'h'mm")
        downtime_layout.addWidget(self.end_time, 8, 1, 1, 2)

        self.comment_edit.setText(comment)
        self.comment_edit.setMaximumHeight(60)
        downtime_layout.addWidget(self.comment_edit, 9, 0, 1, 3)

        request_btn = QPushButton(_('REQUEST DOWNTIME'), self)
        request_btn.clicked.connect(self.handle_accept)
        request_btn.setObjectName('valid')
        request_btn.setMinimumHeight(30)
        request_btn.setDefault(True)
        downtime_layout.addWidget(request_btn, 10, 0, 1, 3)

        main_layout.addWidget(downtime_widget)

    def duration_to_seconds(self):
        """
        Return "duration" QTimeEdit value in seconds

        :return: "duration" in seconds
        :rtype: int
        """

        return QTime(0, 0).secsTo(self.duration.time())

    def handle_accept(self):
        """
        Check if end_time timestamp is not lower than start_time

        """

        if self.start_time.dateTime().toTime_t() > self.end_time.dateTime(
        ).toTime_t():
            logger.warning(
                'Try to add Downtime with "End Time" lower than "Start Time"')
        else:
            self.accept()

    def mousePressEvent(self, event):  # pragma: no cover
        """ QWidget.mousePressEvent(QMouseEvent) """

        self.offset = event.pos()

    def mouseMoveEvent(self, event):  # pragma: no cover
        """ QWidget.mousePressEvent(QMouseEvent) """

        try:
            x = event.globalX()
            y = event.globalY()
            x_w = self.offset.x()
            y_w = self.offset.y()
            self.move(x - x_w, y - y_w)
        except AttributeError as e:
            logger.warning('Move Event %s: %s', self.objectName(), str(e))
Exemplo n.º 22
0
    def __init__(self, parent=None):
        super(HistoryWidget, self).__init__(parent)
        self.setObjectName("HistoryWidget")
        self.resize(800, 480)
        self.setWindowTitle("历史数据查看")

        # layout - top
        horiLayoutTop = QHBoxLayout()

        buttonQuit = QPushButton(self)
        buttonQuit.setObjectName("buttonQuit")
        horiLayoutTop.addSpacing(25)
        horiLayoutTop.addWidget(buttonQuit, 0, Qt.AlignLeft)
        horiLayoutTop.addStretch()

        # button-export
        buttonExport = QPushButton(self)
        buttonExport.setObjectName("buttonExport")
        horiLayoutTop.addWidget(buttonExport)
        horiLayoutTop.addStretch()

        # button-open
        buttonOpen = QPushButton(self)
        buttonOpen.setObjectName("buttonOpen")
        horiLayoutTop.addWidget(buttonOpen)
        horiLayoutTop.addStretch()

        formLayoutTime = QFormLayout()
        formLayoutTime.setFormAlignment(Qt.AlignVCenter)
        horiLayoutTop.addLayout(formLayoutTime)
        horiLayoutTop.addStretch()

        self.dateTimeEditStart = QDateTimeEdit(self)
        self.dateTimeEditStart.setObjectName("dateTimeEditStart")
        self.dateTimeEditStart.setDisplayFormat("yyyy-MM-dd HH:mm:ss")
        formLayoutTime.addRow("起始时间:", self.dateTimeEditStart)

        self.dateTimeEditEnd = QDateTimeEdit(self)
        self.dateTimeEditEnd.setObjectName("dateTimeEditEnd")
        self.dateTimeEditEnd.setDisplayFormat("yyyy-MM-dd HH:mm:ss")
        formLayoutTime.addRow("结束时间:", self.dateTimeEditEnd)

        # LBP
        formLayoutLBP = QFormLayout()
        formLayoutLBP.setFormAlignment(Qt.AlignVCenter)
        formLayoutLBP.setLabelAlignment(Qt.AlignRight)
        horiLayoutTop.addLayout(formLayoutLBP)
        horiLayoutTop.addStretch()
        self.checkBoxLBPMajor = QCheckBox("主", self)
        self.checkBoxLBPMajor.setProperty("curveColor", "#101010")
        self.checkBoxLBPMinor = QCheckBox("副", self)
        self.checkBoxLBPMinor.setProperty("curveColor", "#101010")
        formLayoutLBP.addRow("左刹车压力:", self.checkBoxLBPMajor)
        formLayoutLBP.addRow("", self.checkBoxLBPMinor)

        # RBP
        formLayoutRBP = QFormLayout()
        formLayoutRBP.setFormAlignment(Qt.AlignVCenter)
        formLayoutRBP.setLabelAlignment(Qt.AlignRight)
        horiLayoutTop.addLayout(formLayoutRBP)
        horiLayoutTop.addStretch()
        self.checkBoxRBPMajor = QCheckBox("主", self)
        self.checkBoxRBPMajor.setProperty("curveColor", "#101010")
        self.checkBoxRBPMinor = QCheckBox("副", self)
        self.checkBoxRBPMinor.setProperty("curveColor", "#101010")
        formLayoutRBP.addRow("右刹车压力:", self.checkBoxRBPMajor)
        formLayoutRBP.addRow("", self.checkBoxRBPMinor)

        # LRP
        formLayoutLRP = QFormLayout()
        formLayoutLRP.setFormAlignment(Qt.AlignVCenter)
        formLayoutLRP.setLabelAlignment(Qt.AlignRight)
        horiLayoutTop.addLayout(formLayoutLRP)
        horiLayoutTop.addStretch()
        self.checkBoxLRPTheory = QCheckBox("理论", self)
        self.checkBoxLRPTheory.setProperty("curveColor", "#101010")
        self.checkBoxLRPReal = QCheckBox("实际", self)
        self.checkBoxLRPReal.setProperty("curveColor", "#101010")
        formLayoutLRP.addRow("左转速:", self.checkBoxLRPTheory)
        formLayoutLRP.addRow("", self.checkBoxLRPReal)

        # RRP
        formLayoutRRP = QFormLayout()
        formLayoutRRP.setFormAlignment(Qt.AlignVCenter)
        formLayoutRRP.setLabelAlignment(Qt.AlignRight)
        horiLayoutTop.addLayout(formLayoutRRP)
        horiLayoutTop.addStretch()
        self.checkBoxRRPTheory = QCheckBox("理论", self)
        self.checkBoxRRPTheory.setProperty("curveColor", "#101010")
        self.checkBoxRRPReal = QCheckBox("实际", self)
        self.checkBoxRRPReal.setProperty("curveColor", "#101010")
        formLayoutRRP.addRow("右转速:", self.checkBoxRRPTheory)
        formLayoutRRP.addRow("", self.checkBoxRRPReal)

        # button-update
        buttonUpdate = QPushButton(self)
        buttonUpdate.setObjectName("buttonUpdate")
        horiLayoutTop.addWidget(buttonUpdate)
        horiLayoutTop.addStretch()

        # middle-curves
        self.curveHistory = CurveWidget("历史数据回放", True, self)
        self.curveHistory.setMaximumWidth(10e5)
        self.curveHistory.setScaleLabelFormat("yyyy/MM/dd\n  HH:mm:ss")
        self.curveHistory.clear()

        #
        vertLayoutMain = QVBoxLayout(self)
        vertLayoutMain.addLayout(horiLayoutTop)
        vertLayoutMain.addWidget(self.curveHistory)

        buttonQuit.clicked.connect(self.accept)
        buttonOpen.clicked.connect(self.buttonOpenClicked)
        buttonExport.clicked.connect(self.buttonExportClicked)
        self.dateTimeEditStart.dateTimeChanged.connect(self.dateTimeStartChanged)
        self.dateTimeEditEnd.dateTimeChanged.connect(self.dateTimeEndChanged)
        self.checkBoxLBPMajor.toggled.connect(self.checkBoxLBPMajorToggled)
        self.checkBoxLBPMinor.toggled.connect(self.checkBoxLBPMinorToggled)
        self.checkBoxRBPMajor.toggled.connect(self.checkBoxRBPMajorToggled)
        self.checkBoxRBPMinor.toggled.connect(self.checkBoxRBPMinorToggled)
        self.checkBoxLRPTheory.toggled.connect(self.checkBoxLRPTheoryToggled)
        self.checkBoxLRPReal.toggled.connect(self.checkBoxLRPRealToggled)
        self.checkBoxRRPTheory.toggled.connect(self.checkBoxRRPTheoryToggled)
        self.checkBoxRRPReal.toggled.connect(self.checkBoxRRPRealToggled)
        buttonUpdate.clicked.connect(self.buttonUpdateClicked)

        # finalLy initialize
        self.checkBoxLBPMajor.setChecked(self._v_curve_checked[0])
        self.checkBoxLBPMinor.setChecked(self._v_curve_checked[1])
        self.checkBoxRBPMajor.setChecked(self._v_curve_checked[2])
        self.checkBoxRBPMinor.setChecked(self._v_curve_checked[3])
        self.checkBoxLRPTheory.setChecked(self._v_curve_checked[4])
        self.checkBoxLRPReal.setChecked(self._v_curve_checked[5])
        self.checkBoxRRPTheory.setChecked(self._v_curve_checked[6])
        self.checkBoxRRPReal.setChecked(self._v_curve_checked[7])