Ejemplo n.º 1
0
def test_edit_frame_at():
    client = Watson(config_dir=WORKDIR)

    # Edit first frame.
    start0 = local_arrow_from_tuple((2018, 6, 14, 15, 59, 54))
    stop0 = local_arrow_from_tuple((2018, 6, 14, 16, 34, 25))
    edit_frame_at(client, 0, start=start0, stop=stop0, tags=['edited'])

    frame = client.frames[0]
    assert frame.start.format('YYYY-MM-DD HH:mm:ss') == '2018-06-14 15:59:54'
    assert frame.stop.format('YYYY-MM-DD HH:mm:ss') == '2018-06-14 16:34:25'
    assert client.frames[0].tags == ['edited']

    # Edit second frame.
    start1 = '2018-06-14 16:48:05'
    stop1 = '2018-06-14 17:00:00'
    edit_frame_at(client, 1, start=start1, stop=stop1, tags=['edited'])

    frame = client.frames[1]
    assert frame.start.format('YYYY-MM-DD HH:mm:ss') == start1
    assert frame.stop.format('YYYY-MM-DD HH:mm:ss') == stop1
    assert client.frames[1].tags == ['edited']

    # Edit third frame.
    start2 = '2018-06-14 18:02:57'
    stop2 = '2018-06-14 23:34:25'
    edit_frame_at(client, 2, start=start2, stop=stop2, tags=['edited'])

    frame = client.frames[2]
    assert frame.start.format('YYYY-MM-DD HH:mm:ss') == start2
    assert frame.stop.format('YYYY-MM-DD HH:mm:ss') == stop2
    assert client.frames[2].tags == ['edited']

    client.save()
Ejemplo n.º 2
0
def now():
    return local_arrow_from_tuple((2018, 7, 25, 6, 0, 0))
Ejemplo n.º 3
0
def now():
    return local_arrow_from_tuple((2018, 7, 30, 7, 23, 44))
def now():
    return local_arrow_from_tuple((2018, 6, 17, 23, 59, 0))
Ejemplo n.º 5
0
class DateTimeInputDialog(BaseDialog):
    """
    A dialog to select a datetime value that is built to be enclosed in
    a layout, and not used as a child window.
    """
    DEFAULT_MIN_DATETIME = local_arrow_from_tuple((2000, 1, 1))

    def __init__(self, parent=None):
        super(DateTimeInputDialog, self).__init__(parent)
        self._minimum_datetime = None

    # ---- Setup layout

    def setup(self):
        """Setup the dialog widgets and layout."""
        datetime_box = self.setup_datetime_box()

        # Add buttons to the dialog

        self.add_dialog_button(QPushButton('Start'), 'Start', True)
        self.add_dialog_button(QPushButton('Cancel'), 'Cancel')

        # Setup the info box

        info_text = ("The start time cannot be sooner than the stop time of"
                     " the last saved activity and later than the current"
                     " time.")

        info_box = InfoBox(info_text, 'information', 'small')
        info_box.setContentsMargins(5, 10, 5, 10)
        info_box.setSpacing(10)

        # Setup the layout of the dialog

        layout = QVBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)

        layout.addWidget(datetime_box)
        layout.addWidget(self.button_box)
        layout.addWidget(info_box)
        layout.setStretch(2, 100)

    def setup_datetime_box(self):
        """Setup the datetime edit widget and a label."""
        self.datetime_edit = datetime_edit = QDateTimeEdit()
        datetime_edit.setCalendarPopup(True)
        datetime_edit.setDisplayFormat("yyyy-MM-dd  hh:mm")
        datetime_edit.setKeyboardTracking(False)
        datetime_edit.dateTimeChanged.connect(self.validate_datetime)
        datetime_edit.setAlignment(Qt.AlignLeft)

        ft = datetime_edit.font()
        ft.setPointSize(ft.pointSize() + 4)
        datetime_edit.setFont(ft)

        label = QLabel('Start time :')
        label.setFont(ft)

        # Setup the layout

        datetime_box = ColoredFrame()
        datetime_box.set_background_color('window')
        layout = QHBoxLayout(datetime_box)
        layout.setContentsMargins(5, 10, 5, 10)
        layout.setSpacing(15)
        layout.addWidget(label)
        layout.addWidget(datetime_edit)
        layout.setStretch(1, 100)

        return datetime_box

    # ---- Bind dialog with main

    def show(self):
        """Qt method override."""
        self.set_datetime_to_now()
        if self.main is not None:
            frames = self.main.client.frames
            self.set_datetime_minimum(None if len(frames) ==
                                      0 else frames[-1].stop)
        super(DateTimeInputDialog, self).show()

    def receive_answer(self, answer):
        """
        Handle when the value displayed in the datetime widget is accepted
        or canceled by the user.
        """
        if self.main is not None:
            if answer == 'Start':
                self.main.start_watson(start_time=self.get_datetime_arrow())
            elif answer == 'Cancel':
                self.main.cancel_watson()
            self.main.setCurrentIndex(0)

    # ---- Utility

    @property
    def minimum_datetime(self):
        """Return the minimum datetime that is accepted by the dialog."""
        if self._minimum_datetime is None:
            return self.DEFAULT_MIN_DATETIME
        else:
            return self._minimum_datetime

    def set_datetime_minimum(self, value):
        """Set the minimum datetime allowed by the dialog."""
        self._minimum_datetime = value

    @QSlot(QDateTime)
    def validate_datetime(self, qdatetime):
        """
        Set the datetime value of the datetime edit widet to the specified
        minimum or maximum value if the current value is not enclosed in
        these two limits.
        """
        current_datetime = self.get_datetime_arrow()
        if current_datetime < self.minimum_datetime:
            self.datetime_edit.setDateTime(
                qdatetime_from_arrow(self.minimum_datetime))
        elif current_datetime > arrow.now():
            self.datetime_edit.setDateTime(qdatetime_from_arrow(arrow.now()))

    def set_datetime_to_now(self):
        """Set the current datetime of the datetime edit to now."""
        self.datetime_edit.setDateTime(qdatetime_from_arrow(arrow.now()))

    def get_datetime_arrow(self):
        """Return the current datetime in arrow format."""
        return local_arrow_from_str(
            self.datetime_edit.dateTime().toString("yyyy-MM-dd hh:mm"),
            fmt='YYYY-MM-DD HH:mm')