Exemple #1
0
    def __init__(self, parent, column, datetime_format):
        QDateTimeEdit.__init__(self, parent)

        self.format = datetime_format
        self.have_date, self.have_time = datetime_format[0], datetime_format[1]
        self.set_format(column)
        self.setSizePolicy(
            QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))
Exemple #2
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.timeedit = QDateTimeEdit(displayFormat="hh:mm:ss")
        self.timeedit.setTime(self.parent().min_datetime.time())

        self._time_layout = sublay = QHBoxLayout()
        sublay.setContentsMargins(6, 6, 6, 6)
        sublay.addStretch(1)
        sublay.addWidget(QLabel("Time: "))
        sublay.addWidget(self.timeedit)
        sublay.addStretch(1)
        self.layout().addLayout(sublay)
Exemple #3
0
class CalendarWidgetWithTime(QCalendarWidget):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.timeedit = QDateTimeEdit(displayFormat="hh:mm:ss")
        self.timeedit.setTime(self.parent().min_datetime.time())

        self._time_layout = sublay = QHBoxLayout()
        sublay.setContentsMargins(6, 6, 6, 6)
        sublay.addStretch(1)
        sublay.addWidget(QLabel("Time: "))
        sublay.addWidget(self.timeedit)
        sublay.addStretch(1)
        self.layout().addLayout(sublay)

    def minimumSize(self):
        return self.sizeHint()

    def sizeHint(self):
        size = super().sizeHint()
        size.setHeight(size.height() + self._time_layout.sizeHint().height() +
                       self.layout().spacing())
        return size
Exemple #4
0
    def __init__(self):
        super().__init__()
        self._delta = 0
        self.play_timer = QTimer(self,
                                 interval=1000 * self.playback_interval,
                                 timeout=self.play_single_step)
        slider = self.slider = Slider(Qt.Horizontal,
                                      self,
                                      minimum=0,
                                      maximum=self.MAX_SLIDER_VALUE,
                                      tracking=True,
                                      playbackInterval=1000 *
                                      self.playback_interval,
                                      valuesChanged=self.sliderValuesChanged,
                                      minimumValue=self.slider_values[0],
                                      maximumValue=self.slider_values[1])
        slider.setShowText(False)
        selectBox = gui.vBox(self.controlArea, 'Select a Time Range')
        selectBox.layout().addWidget(slider)

        dtBox = gui.hBox(selectBox)

        kwargs = dict(calendarPopup=True,
                      displayFormat=' '.join(self.DATE_FORMATS),
                      timeSpec=Qt.UTC)
        date_from = self.date_from = QDateTimeEdit(self, **kwargs)
        date_to = self.date_to = QDateTimeEdit(self, **kwargs)

        def datetime_edited(dt_edit):
            minTime = self.date_from.dateTime().toMSecsSinceEpoch() / 1000
            maxTime = self.date_to.dateTime().toMSecsSinceEpoch() / 1000
            if minTime > maxTime:
                minTime = maxTime = minTime if dt_edit == self.date_from else maxTime
                other = self.date_to if dt_edit == self.date_from else self.date_from
                with blockSignals(other):
                    other.setDateTime(dt_edit.dateTime())

            self.dteditValuesChanged(minTime, maxTime)

        date_from.dateTimeChanged.connect(lambda: datetime_edited(date_from))
        date_to.dateTimeChanged.connect(lambda: datetime_edited(date_to))

        # hotfix, does not repaint on click of arrow
        date_from.calendarWidget().currentPageChanged.connect(
            lambda: date_from.calendarWidget().repaint())
        date_to.calendarWidget().currentPageChanged.connect(
            lambda: date_to.calendarWidget().repaint())

        dtBox.layout().addStretch(100)
        dtBox.layout().addWidget(date_from)
        dtBox.layout().addWidget(QLabel(' – '))
        dtBox.layout().addWidget(date_to)
        dtBox.layout().addStretch(100)

        hCenterBox = gui.hBox(self.controlArea)
        gui.rubber(hCenterBox)
        vControlsBox = gui.vBox(hCenterBox)

        stepThroughBox = gui.vBox(vControlsBox, 'Step/Play Through')
        gui.rubber(stepThroughBox)
        gui.checkBox(stepThroughBox,
                     self,
                     'loop_playback',
                     label='Loop playback')
        customStepBox = gui.hBox(stepThroughBox)
        gui.checkBox(
            customStepBox,
            self,
            'custom_step_size',
            label='Custom step size: ',
            toolTip='If not chosen, the active interval moves forward '
            '(backward), stepping in increments of its own size.')
        self.stepsize_combobox = gui.comboBox(customStepBox,
                                              self,
                                              'step_size',
                                              items=tuple(
                                                  self.STEP_SIZES.keys()),
                                              sendSelectedValue=True)
        playBox = gui.hBox(stepThroughBox)
        gui.rubber(playBox)
        gui.rubber(stepThroughBox)

        if self.icons_font is None:
            self.icons_font = load_icons_font()

        self.step_backward = gui.button(
            playBox,
            self,
            '⏪',
            callback=lambda: self.play_single_step(backward=True),
            autoDefault=False)
        self.step_backward.setFont(self.icons_font)
        self.play_button = gui.button(playBox,
                                      self,
                                      '▶️',
                                      callback=self.playthrough,
                                      toggleButton=True,
                                      default=True)
        self.play_button.setFont(self.icons_font)
        self.step_forward = gui.button(playBox,
                                       self,
                                       '⏩',
                                       callback=self.play_single_step,
                                       autoDefault=False)
        self.step_forward.setFont(self.icons_font)

        gui.rubber(playBox)
        intervalBox = gui.vBox(vControlsBox, 'Playback/Tracking interval')
        intervalBox.setToolTip(
            'In milliseconds, set the delay for playback and '
            'for sending data upon manually moving the interval.')

        def set_intervals():
            self.play_timer.setInterval(1000 * self.playback_interval)
            self.slider.tracking_timer.setInterval(1000 *
                                                   self.playback_interval)

        gui.valueSlider(intervalBox,
                        self,
                        'playback_interval',
                        label='Delay:',
                        labelFormat='%.2g sec',
                        values=self.DELAY_VALUES,
                        callback=set_intervals)

        gui.rubber(hCenterBox)
        gui.rubber(self.controlArea)
        self._set_disabled(True)
Exemple #5
0
    def __init__(self):
        super().__init__()
        self._delta = 0
        self.play_timer = QTimer(self,
                                 interval=self.playback_interval,
                                 timeout=self.play_single_step)
        slider = self.slider = Slider(
            Qt.Horizontal,
            self,
            minimum=0,
            maximum=self.MAX_SLIDER_VALUE,
            tracking=False,
            valuesChanged=self.valuesChanged,
            minimumValue=self.slider_values[0],
            maximumValue=self.slider_values[1],
        )
        slider.setShowText(False)
        box = gui.vBox(self.controlArea, 'Time Slice')
        box.layout().addWidget(slider)

        hbox = gui.hBox(box)

        def _dateTimeChanged(editted):
            def handler():
                minTime = self.date_from.dateTime().toMSecsSinceEpoch() / 1000
                maxTime = self.date_to.dateTime().toMSecsSinceEpoch() / 1000
                if minTime > maxTime:
                    minTime = maxTime = minTime if editted == self.date_from else maxTime
                    other = self.date_to if editted == self.date_from else self.date_from
                    with blockSignals(other):
                        other.setDateTime(editted.dateTime())

                with blockSignals(self.slider):
                    self.slider.setValues(self.slider.unscale(minTime),
                                          self.slider.unscale(maxTime))
                self.send_selection(minTime, maxTime)

            return handler

        kwargs = dict(calendarPopup=True,
                      displayFormat=' '.join(self.DATE_FORMATS),
                      timeSpec=Qt.UTC)
        date_from = self.date_from = QDateTimeEdit(self, **kwargs)
        date_to = self.date_to = QDateTimeEdit(self, **kwargs)
        date_from.dateTimeChanged.connect(_dateTimeChanged(date_from))
        date_to.dateTimeChanged.connect(_dateTimeChanged(date_to))
        hbox.layout().addStretch(100)
        hbox.layout().addWidget(date_from)
        hbox.layout().addWidget(QLabel(' – '))
        hbox.layout().addWidget(date_to)
        hbox.layout().addStretch(100)

        vbox = gui.vBox(self.controlArea, 'Step / Play Through')
        gui.checkBox(vbox, self, 'loop_playback', label='Loop playback')
        hbox = gui.hBox(vbox)
        gui.checkBox(hbox,
                     self,
                     'steps_overlap',
                     label='Stepping overlaps by:',
                     toolTip='If enabled, the active interval moves forward '
                     '(backward) by half of the interval at each step.')
        gui.comboBox(hbox,
                     self,
                     'overlap_amount',
                     items=tuple(self.OVERLAP_AMOUNTS.keys()),
                     sendSelectedValue=True)
        gui.spin(vbox,
                 self,
                 'playback_interval',
                 label='Playback delay (msec):',
                 minv=100,
                 maxv=30000,
                 step=200,
                 callback=lambda: self.play_timer.setInterval(
                     self.playback_interval))

        hbox = gui.hBox(vbox)
        self.step_backward = gui.button(
            hbox,
            self,
            '⏮',
            callback=lambda: self.play_single_step(backward=True),
            autoDefault=False)
        self.play_button = gui.button(hbox,
                                      self,
                                      '▶',
                                      callback=self.playthrough,
                                      toggleButton=True,
                                      default=True)
        self.step_forward = gui.button(hbox,
                                       self,
                                       '⏭',
                                       callback=self.play_single_step,
                                       autoDefault=False)

        gui.rubber(self.controlArea)
    def __init__(self):
        self.model = None

        self._task = None  # type: Optional[self.Task]
        self._executor = ThreadExecutor(self)
        self.is_downloading = False

        box = gui.vBox(self.controlArea, 'Database Connection')
        gui.lineEdit(box,
                     self,
                     'con_hostname',
                     label='Hostname:',
                     orientation=Qt.Horizontal,
                     validator=Validator.Hostname())
        gui.lineEdit(box,
                     self,
                     'con_port',
                     label='Port:',
                     orientation=Qt.Horizontal,
                     validator=Validator.Port())
        gui.lineEdit(box,
                     self,
                     'con_username',
                     label='Username:'******'con_password',
                            label='Password:'******'con_database',
                     label='Database:',
                     orientation=Qt.Horizontal)
        gui.spin(box, self, 'con_timeout', 5, 300, 5, label='Timeout [s]:')
        self.btn_connect = gui.button(box,
                                      self,
                                      self.LABEL_CONNECT,
                                      callback=self.load_data)

        box = gui.vBox(self.controlArea, 'Download')

        def _dateTimeChanged(editted):
            def handler():
                minTime = self.date_from.dateTime().toMSecsSinceEpoch() / 1000
                maxTime = self.date_to.dateTime().toMSecsSinceEpoch() / 1000
                if minTime > maxTime:
                    minTime = maxTime = minTime if editted == self.date_from else maxTime

                    other = self.date_to if editted == self.date_from else self.date_from
                    with blockSignals(other):
                        other.setDateTime(editted.dateTime())

                    self.btn_download.setEnabled(minTime != maxTime)

                # Update saved settings
                self.sample_ts_from = minTime
                self.sample_ts_to = maxTime

            return handler

        kwargs = dict(calendarPopup=True,
                      displayFormat=' '.join(self.DATE_FORMATS),
                      timeSpec=Qt.UTC)
        date_from = self.date_from = QDateTimeEdit(self, **kwargs)
        date_to = self.date_to = QDateTimeEdit(self, **kwargs)
        date_from.setDateTime(
            QDateTime.fromMSecsSinceEpoch(self.sample_ts_from * 1000, Qt.UTC))
        date_to.setDateTime(
            QDateTime.fromMSecsSinceEpoch(self.sample_ts_to * 1000, Qt.UTC))
        date_from.dateTimeChanged.connect(_dateTimeChanged(date_from))
        date_to.dateTimeChanged.connect(_dateTimeChanged(date_to))

        hbox = gui.hBox(box)
        hbox.layout().addWidget(QLabel('From:'))
        hbox.layout().addWidget(date_from)
        hbox = gui.hBox(box)
        hbox.layout().addWidget(QLabel('To:'))
        hbox.layout().addWidget(date_to)

        self.box_include_data = gui.vBox(box, 'Include')

        gui.spin(box,
                 self,
                 'sample_size',
                 100,
                 20000,
                 100,
                 label='Sample size:')
        gui.comboBox(box,
                     self,
                     'sample_resolution',
                     label='Resolution:',
                     orientation=Qt.Horizontal,
                     items=tuple(self.RESOLUTION.keys()),
                     sendSelectedValue=True)
        gui.comboBox(box,
                     self,
                     'sample_interpolation',
                     label='Interpolation:',
                     orientation=Qt.Horizontal,
                     items=tuple(self.INTERPOLATION.keys()),
                     sendSelectedValue=True)

        self.btn_download = gui.button(box,
                                       self,
                                       self.LABEL_DOWNLOAD,
                                       callback=self.download)
        gui.rubber(self.controlArea)

        ## Main area

        class Model(PyTableModel):
            def update_row(self, i, row):
                self[i] = row

        model = self.model = Model(parent=self)
        model.setHorizontalHeaderLabels([
            'Node Id', 'Interfaces', 'Start Time', 'Stop Time',
            'Available Data'
        ])
        view = self.view = gui.TableView(self)
        view.horizontalHeader().setStretchLastSection(False)
        view.setModel(self.model)
        self.mainArea.layout().addWidget(view)

        # Restore node info table from cache, if any
        try:
            lst = CachedNodeInfoTable.load_list()
        except Exception:
            pass  # Cache not exists
        else:
            model.wrap(lst)

        # Restore tables checkboxes from cache
        try:
            tables = CachedNodeInfoTable.load_tables()
        except Exception:
            pass
        else:
            for table in tables:
                self.box_include_data.layout().addWidget(
                    QCheckBox(table, self, checked=table
                              in self.included_data))

        # Establish default database connection from settings
        set_connection_params(self.con_hostname,
                              self.con_port,
                              self.con_username,
                              self.con_password,
                              self.con_database,
                              timeout=self.con_timeout)