Example #1
0
    def _move_scene_item(self, selected_item: QTreeWidgetItem,
                         direction: Direction) -> None:
        # UI Modification
        parent = selected_item.parent()  # Signage of selected scene
        sel_idx = int(selected_item.text(0).split(':')[0])

        offset = 0  # Default value
        if direction == Direction.DOWN:
            offset = +1
        elif direction == Direction.UP:
            offset = -1
        else:
            Exception("Direction not provided")  # Should NEVER be reached
        target_item = parent.child(sel_idx + offset)
        target_text = ':'.join(target_item.text(0).split(':')[1:])
        sel_text = ':'.join(selected_item.text(0).split(':')[1:])

        parent.child(sel_idx).setText(0,
                                      str(sel_idx + offset) + ':' + sel_text)
        parent.removeChild(parent.child(sel_idx + offset))
        moved_item = QTreeWidgetItem([str(sel_idx) + ':' + target_text])
        parent.insertChild(sel_idx, moved_item)

        # Data Modification
        sgn_id = utils.ui_text_to_id(parent.text(0))
        signage = self._sgn_mng.get_signage(sgn_id)
        signage.rearrange_scene(sel_idx - 1, sel_idx - 1 +
                                offset)  # Index starts from 0 here

        # Update UI status
        self.update_ui_component()
Example #2
0
 def list_item_clicked(self):
     get_selected = self.sender().selectedItems()
     if get_selected:
         item = get_selected[0]
         item_text = item.text(0)
         if item.parent() is None:
             # It is at topmost level
             # Selected one is data type
             idx = self._widget_idx['type']
             data_type_id = utils.ui_text_to_id(item_text)
             data_type = self._obj_mng.get_object_type(data_type_id)
             self._stacked_widget.widget(idx).load_data_on_ui(data_type)
             self._stacked_widget.setCurrentIndex(idx)
         else:
             if item_text == '+':
                 item.setSelected(False)
                 text, ok = QInputDialog.getText(
                     self, self._res['idDialogTitle'],
                     self._res['idDialogDescription'])
                 if ok:
                     try:
                         utils.validate_id(text)
                     except AttributeError:
                         QMessageBox.warning(
                             self, self._res['idInvalidTitle'],
                             self._res['idInvalidDescription'],
                             QMessageBox.Ok, QMessageBox.Ok)
                         return  # Invalid ID. Do not create signage
                     data_type_id = utils.ui_text_to_id(
                         item.parent().text(0))
                     data_type = self._obj_mng.get_object_type(data_type_id)
                     self._obj_mng.add_object_value(
                         ObjectValue(text, data_type, self._obj_mng,
                                     self._mtm_mng))
                     item.setText(0, text)
                     item.parent().addChild(QTreeWidgetItem(['+']))
             else:
                 # Selected one is data
                 idx = self._widget_idx['data']
                 data_type_id = utils.ui_text_to_id(item.parent().text(0))
                 data_type = self._obj_mng.get_object_type(data_type_id)
                 data = self._obj_mng.get_object_value(data_type, item_text)
                 self._stacked_widget.widget(idx).load_data_on_ui(data)
                 self._stacked_widget.setCurrentIndex(idx)
Example #3
0
 def list_item_clicked(self) -> None:
     get_selected = self.sender().selectedItems()
     if get_selected:
         item = get_selected[0]
         item_text = item.text(0)
         if item.parent() is None:
             # It is at topmost level
             # Selected one is Scene/Frame
             self._template_widget.clear_data_on_ui()
         else:
             # Selected one is frame/scene
             tpl_id = utils.ui_text_to_id(item_text)
             if item.parent().text(0) == self._res['frameLabel']:
                 # Selected one is frame template
                 tpl = self._tpl_mng.get_frame_template(tpl_id)
             else:
                 # Selected one is scene template
                 tpl = self._tpl_mng.get_scene_template(tpl_id)
             self._template_widget.load_data_on_ui(tpl)
Example #4
0
    def button_clicked(self) -> None:
        button_text = self.sender().text()
        scene = self._signage.scenes[self._scene_idx]
        if button_text == self._res['deleteButtonText']:
            try:
                self._signage.remove_scene(
                    self._signage.scenes[self._scene_idx])
            except ReferenceError as e:
                QMessageBox.warning(
                    self, "Can't delete", "This scene can't be deleted. " +
                    ', '.join(e.args[0].keys()) + " reference this",
                    QMessageBox.Ok, QMessageBox.Ok)
                return
            self._value_change_handler(utils.ChangeType.DELETE,
                                       str(self._scene_idx))
        elif button_text == self._res['saveButtonText']:
            # Check is input data valid. If not, do not save it
            if not self._tab_data.is_data_valid() or \
               not self._tab_transition.is_data_valid() or \
               not self._tab_scheduling.is_data_valid():
                QMessageBox.warning(self, self._res['dataInvalidTitle'],
                                    self._res['dataInvalidDescription'],
                                    QMessageBox.Ok, QMessageBox.Ok)
                return

            # Now it's OK to save
            # Set scene's template
            tpl_id = utils.ui_text_to_id(self._cbox_tpl.currentText())
            tpl = self._tpl_mng.get_scene_template(tpl_id)

            scene.template = tpl

            self._tab_data.save(scene)
            self._tab_scheduling.save(scene)
            self._tab_transition.save(scene)

            # Invoke value change handler to edit QTreeWidgetItem
            scene_text = utils.gen_ui_text(tpl.definition.name, tpl.id)
            self._value_change_handler(utils.ChangeType.SAVE, scene_text)
        elif button_text == self._res['cancelButtonText']:
            # Load the previous data
            self.load_data_on_ui(self._signage, self._scene_idx)
Example #5
0
    def button_clicked(self) -> None:
        button_text = self.sender().text()
        if button_text == self._res['saveButtonText']:
            # Check is input data valid. If not, do not save it
            if not self._tab_data.is_data_valid():
                QMessageBox.warning(self, self._res['dataInvalidTitle'],
                                    self._res['dataInvalidDescription'],
                                    QMessageBox.Ok, QMessageBox.Ok)
                return

            # Now it's OK to save
            # Set frame's template
            tpl_id = utils.ui_text_to_id(self._cbox_tpl.currentText())
            tpl = self._tpl_mng.get_frame_template(tpl_id)
            self._frame.template = tpl

            self._tab_data.save(self._frame)

            # Invoke value change handler to edit QTreeWidgetItem
            frame_text = utils.gen_ui_text(tpl.definition.name, tpl.id)
            self._value_change_handler(utils.ChangeType.SAVE, frame_text)
        elif button_text == self._res['cancelButtonText']:
            # Load the previous data
            self.load_data_on_ui(self._frame)
Example #6
0
 def combobox_changed(self) -> None:
     combobox_text = self.sender().currentText()
     tpl_id = utils.ui_text_to_id(combobox_text)
     tpl = self._tpl_mng.get_frame_template(tpl_id)
     self._tab_data.load_ui(tpl)
Example #7
0
    def _signage_changed(self):
        sgn_id = utils.ui_text_to_id(self._cbox_signages.currentText())
        if not sgn_id:
            return

        self._channel.signage = self._sgn_mng.get_signage(sgn_id)
Example #8
0
    def update_ui_component(self) -> None:
        get_selected = self._signage_list.selectedItems()
        if get_selected:
            item = get_selected[0]
            item_text = item.text(0)
            if item.parent() is None:
                # Selected one is at topmost level
                # Signage cannot move up or down, so disable UP/DOWN button
                self._btn_up.setEnabled(False)
                self._btn_up.setEnabled(False)
                if item_text == "+":
                    item.setSelected(False)
                    text, ok = QInputDialog.getText(
                        self, self._res['idDialogTitle'],
                        self._res['idDialogDescription'])
                    if ok:
                        try:
                            utils.validate_id(text)
                        except AttributeError:
                            QMessageBox.warning(
                                self, self._res['idInvalidTitle'],
                                self._res['idInvalidDescription'],
                                QMessageBox.Ok, QMessageBox.Ok)
                            return  # Invalid ID. Do not create signage
                        initial_scene = self._create_scene()
                        initial_frame = self._create_frame()
                        new_signage = Signage(text,
                                              frame=initial_frame,
                                              scenes=[initial_scene])
                        self._sgn_mng.add_signage(
                            new_signage)  # Add new signage

                        # Add to UI
                        signage_text = utils.gen_ui_text(
                            new_signage.title, new_signage.id)
                        item.setText(0, signage_text)

                        frame_tpl = initial_frame.template
                        frame_text = utils.gen_ui_text(
                            frame_tpl.definition.name, frame_tpl.id)
                        frame_item = QTreeWidgetItem(["F:" + frame_text])
                        item.addChild(frame_item)

                        scene_tpl = initial_scene.template
                        scene_text = utils.gen_ui_text(
                            scene_tpl.definition.name, scene_tpl.id)
                        scene_item = QTreeWidgetItem(["1:" + scene_text])
                        item.addChild(scene_item)

                        item.addChild(QTreeWidgetItem(['+']))
                        item.setExpanded(True)
                        # Add + button again
                        self._signage_list.addTopLevelItem(
                            QTreeWidgetItem(['+']))
                else:
                    # Selected one is signage
                    sgn_id = utils.ui_text_to_id(item_text)
                    signage = self._sgn_mng.get_signage(sgn_id)
                    idx = self._widget_idx['signage']
                    self._stacked_widget.widget(idx).load_data_on_ui(signage)
                    self._stacked_widget.setCurrentIndex(idx)
            else:
                sgn_id = utils.ui_text_to_id(item.parent().text(0))
                signage = self._sgn_mng.get_signage(sgn_id)
                if item_text.startswith("F:"):
                    # Selected one is frame
                    # Frame cannot move up or down, so disable UP/DOWN button
                    self._btn_up.setEnabled(False)
                    self._btn_down.setEnabled(False)

                    idx = self._widget_idx['frame']
                    frame = signage.frame
                    self._stacked_widget.widget(idx).load_data_on_ui(frame)
                    self._stacked_widget.setCurrentIndex(idx)
                elif item_text == '+':
                    # Add scene to signage
                    new_scene = self._create_scene()
                    signage.add_scene(new_scene)

                    # Add scene to list on UI
                    # Make current item's text as added scene
                    parent = item.parent()
                    num_child = parent.childCount()
                    scene_tpl = new_scene.template
                    scene_text = utils.gen_ui_text(scene_tpl.definition.name,
                                                   scene_tpl.id)
                    item.setText(0, str(num_child - 1) + ":" + scene_text)
                    # Add + button at last
                    parent.addChild(QTreeWidgetItem(['+']))

                    self.update_ui_component()  # Update UI status
                else:
                    # Selected one is scene
                    scene_idx = int(item_text.split(':')[0])
                    # First, scene can be moved
                    self._btn_up.setEnabled(True)
                    self._btn_down.setEnabled(True)
                    if scene_idx == 1:
                        # Scene at top. Cannot move up
                        self._btn_up.setEnabled(False)
                    if scene_idx == len(signage.scenes):
                        # Scene at bottom. Cannot move down
                        self._btn_down.setEnabled(False)
                    idx = self._widget_idx['scene']
                    self._stacked_widget.widget(idx).load_data_on_ui(
                        signage, scene_idx - 1)
                    self._stacked_widget.setCurrentIndex(idx)