Ejemplo n.º 1
0
    def signage_to_tree_item(self) -> [QTreeWidgetItem]:
        signage_items = []
        # For all signage
        for signage_id in self._sgn_mng.signages.keys():
            signage = self._sgn_mng.get_signage(signage_id)
            signage_text = utils.gen_ui_text(signage.title, signage.id)
            signage_item = QTreeWidgetItem([signage_text])

            # Add frame
            frame_tpl = signage.frame.template
            frame_text = utils.gen_ui_text(frame_tpl.definition.name,
                                           frame_tpl.id)
            frame_item = QTreeWidgetItem(["F:" + frame_text])
            signage_item.addChild(frame_item)

            # Add scene
            idx = 1
            for scene in signage.scenes:
                scene_tpl = scene.template
                scene_text = utils.gen_ui_text(scene_tpl.definition.name,
                                               scene_tpl.id)
                scene_item = QTreeWidgetItem([str(idx) + ":" + scene_text])
                signage_item.addChild(scene_item)
                idx += 1

            # Add scene addition button
            scene_addition_item = QTreeWidgetItem(["+"])
            signage_item.addChild(scene_addition_item)
            signage_items.append(signage_item)

        # Add signage addition button
        signage_addition_item = QTreeWidgetItem(["+"])
        signage_items.append(signage_addition_item)
        return signage_items
Ejemplo n.º 2
0
    def init_ui(self) -> None:
        # Template list on combobox
        tpl_list = list()
        for tpl_id in self._tpl_mng.frame_templates:
            template = self._tpl_mng.get_frame_template(tpl_id)
            tpl_list.append(utils.gen_ui_text(template.definition.name, template.id))
        self._cbox_tpl.addItems(tpl_list)
        self._cbox_tpl.currentIndexChanged.connect(self.combobox_changed)

        # Tab widget
        tab_frame_manage = QTabWidget()
        tab_frame_manage.addTab(self._tab_data, self._res['dataTabText'])

        # Buttons
        btn_save = QPushButton(self._res['saveButtonText'])
        btn_save.clicked.connect(self.button_clicked)
        btn_cancel = QPushButton(self._res['cancelButtonText'])
        btn_cancel.clicked.connect(self.button_clicked)

        hbox_buttons = QHBoxLayout()
        hbox_buttons.addStretch(1)
        hbox_buttons.addWidget(btn_save)
        hbox_buttons.addWidget(btn_cancel)

        # Getting altogether
        vbox_outmost = QVBoxLayout()
        vbox_outmost.addWidget(self._cbox_tpl)
        vbox_outmost.addWidget(tab_frame_manage)
        vbox_outmost.addStretch(1)
        vbox_outmost.addLayout(hbox_buttons)

        self.setLayout(vbox_outmost)
Ejemplo n.º 3
0
    def template_to_tree_item(self) -> [QTreeWidgetItem]:
        frame_label_item = QTreeWidgetItem([self._res['frameLabel']])
        for frame_tpl_id in self._tpl_mng.frame_templates.keys():
            frame_tpl = self._tpl_mng.get_frame_template(frame_tpl_id)
            frame_text = utils.gen_ui_text(frame_tpl.definition.name,
                                           frame_tpl.id)
            frame_item = QTreeWidgetItem([frame_text])
            frame_label_item.addChild(frame_item)

        scene_label_item = QTreeWidgetItem([self._res['sceneLabel']])
        for scene_tpl_id in self._tpl_mng.scene_templates.keys():
            scene_tpl = self._tpl_mng.get_scene_template(scene_tpl_id)
            scene_text = utils.gen_ui_text(scene_tpl.definition.name,
                                           scene_tpl.id)
            scene_item = QTreeWidgetItem([scene_text])
            scene_label_item.addChild(scene_item)
        return [frame_label_item, scene_label_item]
Ejemplo n.º 4
0
    def load_data_on_ui(self, frame: Frame) -> None:
        self._frame = frame
        # Change combobox item to frame's template
        tpl = frame.template
        idx = self._cbox_tpl.findText(utils.gen_ui_text(tpl.definition.name, tpl.id))
        self._cbox_tpl.setCurrentIndex(idx)

        self._tab_data.load_data_on_ui(self._frame)
Ejemplo n.º 5
0
    def load_data_on_ui(self, signage: Signage, scene_idx: int) -> None:
        # scene_idx from 0
        self._signage = signage
        self._scene_idx = scene_idx
        scene = signage.scenes[scene_idx]
        # Set current item of combobox
        tpl = scene.template
        idx = self._cbox_tpl.findText(
            utils.gen_ui_text(tpl.definition.name, tpl.id))
        self._cbox_tpl.setCurrentIndex(idx)

        self._tab_data.load_data_on_ui(scene)
        self._tab_transition.load_data_on_ui(scene)
        self._tab_scheduling.load_data_on_ui(scene)
Ejemplo n.º 6
0
 def data_to_tree_item(self):
     data_type_items = []
     # For all data type
     for data_type_id in self._obj_mng.object_types.keys():
         data_type = self._obj_mng.get_object_type(data_type_id)
         data_type_text = utils.gen_ui_text(data_type.name, data_type.id)
         data_type_item = QTreeWidgetItem([data_type_text])
         # Add data
         for data_id in self._obj_mng.get_object_values(data_type).keys():
             data_item = QTreeWidgetItem([data_id])
             data_type_item.addChild(data_item)
         data_addition_item = QTreeWidgetItem(["+"])
         data_type_item.addChild(data_addition_item)
         data_type_items.append(data_type_item)
     return data_type_items
Ejemplo n.º 7
0
    def init_ui(self) -> None:
        self.setTitle(self._channel.id)

        signage_texts = list()
        for sgn_id in self._sgn_mng.signages.keys():
            signage = self._sgn_mng.get_signage(sgn_id)
            signage_texts.append(utils.gen_ui_text(signage.title, signage.id))
        self._cbox_signages.addItems(signage_texts)
        self._cbox_signages.currentIndexChanged.connect(self._signage_changed)

        vbox_outmost = QVBoxLayout()
        vbox_outmost.addWidget(self._label)
        vbox_outmost.addWidget(self._cbox_signages)

        self.setLayout(vbox_outmost)
Ejemplo n.º 8
0
    def load_data_on_ui(self) -> None:
        self._cbox_signages.clear()
        sgn = self._channel.signage
        signage_texts = list()
        curr_sgn_idx = 0
        for sgn_id in self._sgn_mng.signages.keys():
            if sgn_id == sgn.id:
                curr_sgn_idx = len(signage_texts)
            signage = self._sgn_mng.get_signage(sgn_id)
            signage_texts.append(utils.gen_ui_text(signage.title, signage.id))

        self._cbox_signages.addItem(signage_texts[curr_sgn_idx])
        for sgn_text in reversed(signage_texts[:curr_sgn_idx]):
            self._cbox_signages.insertItem(0, sgn_text)
        for sgn_text in signage_texts[curr_sgn_idx + 1:]:
            self._cbox_signages.addItem(sgn_text)
        label_text = "Number of connections: " + str(
            self._channel.request_connection_count())
        self._label.setText(label_text)
Ejemplo n.º 9
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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
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)