예제 #1
0
    def dropEvent(self, evt):
        drop_ts = max(self.start_time, self.round_ts(self.cursor_time - self.calendar.drag_offset))

        if not has_right("scheduler_edit", self.id_channel):
            logging.error("You are not allowed to modify schedule of this channel.")

        elif type(self.calendar.dragging) == Asset:

            if evt.keyboardModifiers() & Qt.AltModifier:
                logging.info("Creating event from {} at time {}".format(
                    self.calendar.dragging,
                    time.strftime("%Y-%m-%d %H:%M", time.localtime(self.cursor_time))
                    ))
                dlg = EventDialog(self,
                        asset=self.calendar.dragging,
                        id_channel=self.id_channel,
                        start=drop_ts
                    )
                dlg.exec_()
            else:
                QApplication.setOverrideCursor(Qt.WaitCursor)
                stat, res = query("set_events",
                        events=[{
                                "id_asset" : self.calendar.dragging.id,
                                "start" : drop_ts,
                                "id_channel" : self.id_channel
                                # TODO: If shift modifier is pressed add id_event of original event here
                                }]
                    )
                QApplication.restoreOverrideCursor()
                if not success(stat):
                    logging.error(res)


        elif type(self.calendar.dragging) == Event:
            event = self.calendar.dragging
            move = True

            if event.id and abs(event["start"] - drop_ts) > 3600:
                ret = QMessageBox.question(self,
                    "Move event",
                    "Do you really want to move {}?\n\nFrom: {}\n To: {}".format(
                        self.cursor_event,
                        time.strftime("%Y-%m-%d %H:%M", time.localtime(event["start"])),
                        time.strftime("%Y-%m-%d %H:%M", time.localtime(drop_ts))
                        ),
                    QMessageBox.Yes | QMessageBox.No
                    )
                if ret == QMessageBox.Yes:
                    move = True
                else:
                    move = False

            if move:
                event["start"] = drop_ts
                if event.id == 0:
                    # Create empty event. Event edit dialog is enforced.
                    dlg = EventDialog(self,
                            id_channel=self.id_channel,
                            start=drop_ts
                        )
                    dlg.exec_()
                else:
                    # Just dragging events around. Instant save
                    QApplication.setOverrideCursor(Qt.WaitCursor)
                    stat, res = query("set_events", events=[event.meta])
                    QApplication.restoreOverrideCursor()

                    if not success(stat):
                        logging.error(res)

        self.calendar.drag_source = False
        self.calendar.dragging = False
        self.calendar.refresh()
예제 #2
0
 def on_edit_event(self):
     dlg = EventDialog(self, event=self.cursor_event)
     if dlg.exec_() == QDialog.Accepted:
         self.calendar.refresh()
예제 #3
0
 def on_edit_event(self):
     objs = [obj for obj in self.selected_objects if obj.object_type == "event"]
     dlg = EventDialog(self, event=objs[0])
     if dlg.exec_() == QDialog.Accepted:
         self.refresh()