Esempio n. 1
0
    def valueTypeChangedSlot(self, index: int):
        """
        Slot is called wher value type is changed
        :param index: index of value type
        :return:
        """
        valuesType = ModifierValueTypes(self.valueTypeInput.currentIndex()) if self.valueTypeInput.currentIndex() > 0 else None

        self.valueComboInput.clear()
        self.valueComboInput.addItem(TR().tr('Select_value'))

        if valuesType is ModifierValueTypes.TYPE_ARMOR_SIZE:
            for value in ArmorSize:
                Qdata = {'value': value}
                self.valueComboInput.addItem(TR().tr(str(value)), QtCore.QVariant(Qdata))
            self.valueComboInput.show()
            self.valueInput.hide()
            self.valueComboInput.setDisabled(False)
        elif valuesType is ModifierValueTypes.TYPE_WEAPON_WEIGHT:
            for value in WeaponWeight:
                Qdata = {'value': value}
                self.valueComboInput.addItem(TR().tr(str(value)), QtCore.QVariant(Qdata))
            self.valueComboInput.show()
            self.valueInput.hide()
            self.valueComboInput.setDisabled(False)
        elif valuesType is ModifierValueTypes.TYPE_WEAPON_HANDLING:
            for value in Handling:
                Qdata = {'value': value}
                self.valueComboInput.addItem(TR().tr(str(value)), QtCore.QVariant(Qdata))
            self.valueComboInput.show()
            self.valueInput.hide()
            self.valueComboInput.setDisabled(False)
        else:
            self.valueInput.show()
            self.valueInput.setDisabled(False)
Esempio n. 2
0
    def init_ui(self):
        """
        Init basic layout
        """
        self.setWindowIcon(QtGui.QIcon('resources/icons/char.png'))
        self.setWindowTitle('Create new item')
        self.layout = QtWidgets.QGridLayout(self)

        self.name_label = QtWidgets.QLabel(TR().tr('name') + ' :', self)
        self.layout.addWidget(self.name_label, 0, 0)

        self.name_input = QtWidgets.QLineEdit(self)
        self.layout.addWidget(self.name_input, 0, 1)

        self.description_label = QtWidgets.QLabel(TR().tr('description') + ':',
                                                  self)
        self.layout.addWidget(self.description_label, 1, 0)

        self.description_input = QtWidgets.QPlainTextEdit(self)
        self.layout.addWidget(self.description_input, 1, 1)

        self.buttonBox = QtWidgets.QDialogButtonBox()
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel
                                          | QtWidgets.QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")

        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)
        QtCore.QMetaObject.connectSlotsByName(self)

        self.layout.addWidget(self.buttonBox, 2, 0, 1, 2,
                              QtCore.Qt.AlignHCenter)
        self.name_input.setFocus()
Esempio n. 3
0
    def __set_table_data(self, treeNode) -> None:
        """
        Set data to table, in table should be list of Modifiers
        :param treeNode: Tree node where ability is located, need for find Modifiers        
        """
        self.table.setColumnCount(5)

        heades = [
            TR().tr('Name'),
            TR().tr('Target_type'),
            TR().tr('Target_attribute_type'),
            TR().tr('Value_type'),
            TR().tr('Value')
        ]
        self.table.setHorizontalHeaderLabels(heades)

        header = self.table.horizontalHeader()
        header.setStretchLastSection(True)

        # print(treeNode)
        effect = EffectDAO().get(self.object.id, self.object.lang, treeNode.id,
                                 treeNode.context)

        self.table.setRowCount(len(effect.modifiers))

        for i, modifier in enumerate(effect.modifiers):
            self.table.setItem(i, 0, QtWidgets.QTableWidgetItem(modifier.name))
            self.table.setItem(
                i, 1, QtWidgets.QTableWidgetItem(TR().tr(
                    (modifier.targetType))))
            if modifier.itemTargetAttribute is not None:
                self.table.setItem(
                    i, 2,
                    QtWidgets.QTableWidgetItem(TR().tr(
                        (modifier.itemTargetAttribute))))
            else:
                self.table.setItem(
                    i, 2,
                    QtWidgets.QTableWidgetItem(TR().tr(
                        (modifier.characterTargetAttribute))))

            if modifier.itemTargetAttribute in (
                    ItemsAttributes.WEAPON_MELEE_HANDLING,
                    ItemsAttributes.WEAPON_WEIGHT):
                self.table.setItem(
                    i, 4,
                    QtWidgets.QTableWidgetItem(TR().tr((modifier.valueType))))
            else:
                self.table.setItem(
                    i, 3,
                    QtWidgets.QTableWidgetItem(TR().tr((modifier.valueType))))
                self.table.setItem(
                    i, 4, QtWidgets.QTableWidgetItem(str(modifier.value)))
Esempio n. 4
0
    def openMenu(self, position) -> None:
        """
        Create contest menu items
        :param position: selected item in tree
        """
        indexes = self.treeWidget.selectedIndexes()

        if indexes:
            item_type = indexes[0].data(12).nodeType
            item_id = indexes[0].data(12).id
            item = indexes[0].data(12)
            targetObject = indexes[0].data(11)

            menu = QtWidgets.QMenu()

            if isinstance(
                    item, NodeObject
            ) and item.object.object_type is ObjectType.ITEM and (
                    item.object.parent_id == -1
                    or item.object.parent_id == -2):
                pass
            else:
                delete_action = QtWidgets.QAction(TR().tr('Delete'), menu)
                delete_action.setData(QtCore.QVariant('delete'))
                menu.addAction(delete_action)

            rename_action = QtWidgets.QAction(TR().tr('Rename'), menu)
            rename_action.setData(QtCore.QVariant('rename'))
            menu.addAction(rename_action)

            if item_type == NodeType.FOLDER.value:
                folder_action = QtWidgets.QAction(TR().tr('New_item'), menu)
                folder_action.setData(QtCore.QVariant('new'))
                menu.addAction(folder_action)
                delete_action = QtWidgets.QAction(TR().tr('Import'), menu)
                delete_action.setData(QtCore.QVariant('import'))
                menu.addAction(delete_action)

            node = self.tree_manager.get_node(item_id)
            if self.tree_manager.have_tree_children(node):
                add_object_action = QtWidgets.QAction(TR().tr('Add_object'),
                                                      menu)
                add_object_action.setData(QtCore.QVariant('add_object'))
                menu.addAction(add_object_action)

            action = menu.exec_(
                self.treeWidget.viewport().mapToGlobal(position))
            if action:
                self.contest_menu_actions(action, item, targetObject)
Esempio n. 5
0
    def init_buttons(self):
        """
        Create buttons under tree widget
        """
        buttons_layout = QtWidgets.QHBoxLayout()
        buttons_layout.setSpacing(5)
        buttons_layout.setObjectName("Buttons layout")
        spacer = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding,
                                       QtWidgets.QSizePolicy.Minimum)
        buttons_layout.addItem(spacer)

        # Import button
        import_button = QtWidgets.QPushButton(self)
        import_button.setObjectName('TreeImportButton')
        import_icon = QtGui.QIcon()
        import_icon.addPixmap(QtGui.QPixmap("resources/icons/import.png"),
                              QtGui.QIcon.Normal, QtGui.QIcon.Off)
        import_button.setIcon(import_icon)
        import_button.clicked.connect(lambda: self.import_data_slot())
        import_button.setStatusTip(TR().tr('tip.Import_templates'))

        buttons_layout.addWidget(import_button)

        # Export button
        export_button = QtWidgets.QPushButton(self)
        export_button.setObjectName('TreeExportButton')
        export_icon = QtGui.QIcon()
        export_icon.addPixmap(QtGui.QPixmap("resources/icons/export.png"),
                              QtGui.QIcon.Normal, QtGui.QIcon.Off)
        export_button.setIcon(export_icon)
        export_button.clicked.connect(self.export_menu.create_menu)
        export_button.setStatusTip(TR().tr('tip.Export_templates'))

        buttons_layout.addWidget(export_button)

        # New button
        new_button = QtWidgets.QPushButton(self)
        new_button.setObjectName('TreeNewButton')
        new_icon = QtGui.QIcon()
        new_icon.addPixmap(QtGui.QPixmap("resources/icons/plus.png"),
                           QtGui.QIcon.Normal, QtGui.QIcon.Off)
        new_button.setIcon(new_icon)
        new_button.clicked.connect(self.__button_new_action)
        new_button.setStatusTip(TR().tr('tip.New_root_node'))

        buttons_layout.addWidget(new_button)

        self.frame_layout.addLayout(buttons_layout)
Esempio n. 6
0
    def spin_box(self,
                 grid: object,
                 name: str,
                 xposition: int,
                 yposition: int,
                 synchronize: bool = False,
                 xspan: int = 1,
                 yspan: int = 1) -> QtWidgets.QSpinBox:
        """
        Widget for numbers, limit (-20,10000)         
        :param grid: parent grid
        :param name: Name of label
        :param xposition: grid position x
        :param yposition: grid position y
        :param synchronize: bool, if true, value is synchronized trough all languages
        :param xspan: Number of span columns
        :param yspan: Number of span rows
        :return: input object
        """
        label = QtWidgets.QLabel()
        label.setText(TR().tr(name) + ':')
        grid.addWidget(label, yposition, xposition, yspan, xspan)
        input = QtWidgets.QSpinBox()
        input.setMaximum(100000)
        input.setMinimum(-10000)
        input.setObjectName(name)
        if synchronize:
            self.synchronize(input)
        grid.addWidget(input, yposition, xposition + 1, yspan, xspan)
        input.valueChanged.connect(self.data_changed)

        return input
Esempio n. 7
0
    def init_ui(self):
        """
        Init basic layout
        """
        self.layout = QtWidgets.QGridLayout(self)

        self.tabWidget = QtWidgets.QTabWidget(self.__parent)
        self.layout.addWidget(self.tabWidget, 0, 0)
        for child in self.__node.object.treeChildren:
            if child is NodeType.FOLDER:
                continue
            tab = QtWidgets.QWidget()
            self.__selected[child] = []
            self.tabWidget.addTab(tab, TR().tr(child))
            self.create_tree(tab, child)

        self.buttonBox = QtWidgets.QDialogButtonBox()
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel
                                          | QtWidgets.QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")

        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)
        QtCore.QMetaObject.connectSlotsByName(self)

        self.layout.addWidget(self.buttonBox, 2, 0, 1, 2,
                              QtCore.Qt.AlignHCenter)

        self.setLayout(self.layout)
Esempio n. 8
0
 def about_action(self) -> None:
     """
     Open about widget, when clicked on about
     :return: 
     """
     QtWidgets.QMessageBox.about(self, 'About DeskChar',
                                 TR().tr('About_text'))
Esempio n. 9
0
    def text_box(self,
                 grid: object,
                 name: str,
                 xposition: int,
                 yposition: int,
                 synchronize: bool = False,
                 xspan: int = 1,
                 yspan: int = 1) -> QtWidgets.QPlainTextEdit:
        """
        Widget for text box
        :param grid: parent grid
        :param name: Name of label
        :param xposition: grid position x
        :param yposition: grid position y
        :param synchronize: bool, if true, value is synchronized trough all languages
        :param xspan: Number of span columns
        :param yspan: Number of span rows
        :return: input object
        """
        label = QtWidgets.QLabel()
        label.setText(TR().tr(name) + ':')
        grid.addWidget(label, yposition, xposition, 1, 1)
        input = QtWidgets.QPlainTextEdit()
        input.setObjectName(name)
        grid.addWidget(input, yposition, xposition + 1, yspan, xspan)
        input.textChanged.connect(self.data_changed)
        if synchronize:
            self.synchronize(input)

        return input
Esempio n. 10
0
    def check_box(self,
                  grid: object,
                  name: str,
                  xposition: int,
                  yposition: int,
                  synchronize: bool = False,
                  xspan: int = 1,
                  yspan: int = 1) -> QtWidgets.QCheckBox:
        """
        Input check box. Have name and one check box.
        :param grid: parent grid
        :param name: Name of label
        :param xposition: grid position x
        :param yposition: grid position y
        :param synchronize: bool, if true, value is synchronized trough all languages
        :param xspan: Number of span columns
        :param yspan: Number of span rows
        :return: 
        """
        label = QtWidgets.QLabel()
        label.setText(TR().tr(name) + ':')
        grid.addWidget(label, yposition, xposition, 1, 1)

        input = QtWidgets.QCheckBox()
        input.setObjectName(name)
        if synchronize:
            self.synchronize(input)
        grid.addWidget(input, yposition, xposition + 1, yspan, xspan)
        input.stateChanged.connect(self.data_changed)

        return input
Esempio n. 11
0
    def date_box(self,
                 grid: object,
                 name: str,
                 xposition: int,
                 yposition: int,
                 synchronize: bool = False,
                 xspan: int = 1,
                 yspan: int = 1) -> QtWidgets.QDateEdit:
        """
        Box for input date, only date. Range of date is from 1.1.0100
        :param grid: parent grid
        :param name: Name of label
        :param xposition: grid position x
        :param yposition: grid position y
        :param synchronize: bool, if true, value is synchronized trough all languages
        :param xspan: Number of span columns
        :param yspan: Number of span rows
        :return: 
        """
        label = QtWidgets.QLabel()
        label.setText(TR().tr(name) + ':')
        grid.addWidget(label, yposition, xposition, 1, 1)

        input = QtWidgets.QDateEdit()
        input.setMinimumDate(QtCore.QDate(100, 1, 1))
        input.setObjectName(name)
        if synchronize:
            self.synchronize(input)
        grid.addWidget(input, yposition, xposition + 1, yspan, xspan)
        input.dateChanged.connect(self.data_changed)

        return input
Esempio n. 12
0
    def init_ui(self):
        """
        Init basic UI
        """
        self.layout = QtWidgets.QGridLayout(self)
        self.layout.setSpacing(25)

        self.radio_select = QtWidgets.QRadioButton(TR().tr('Select_lang'), self)
        self.radio_select.setChecked(True)
        self.radio_new = QtWidgets.QRadioButton(TR().tr('Create_new_lang'), self)

        self.lang_combo = QtWidgets.QComboBox(self)
        self.name_label = QtWidgets.QLabel(TR().tr('Name'), self)
        self.name_input = QtWidgets.QLineEdit(self)
        self.code_label = QtWidgets.QLabel(TR().tr('Code'), self)
        self.code_input = QtWidgets.QLineEdit(self)
        self.line = QtWidgets.QFrame(self)
        self.line.setFrameShape(QtWidgets.QFrame.HLine)

        langs = self.lang_manager.get_all_langs()
        for lang in langs:
            text = lang.name + ' (' + lang.code + ')'
            data = {'id': lang.id}

            self.lang_combo.addItem(text, QtCore.QVariant(data))

        self.layout.addWidget(self.radio_select, 0, 0)
        self.layout.addWidget(self.lang_combo, 0, 1, 1, 2)
        self.layout.addWidget(self.line, 1, 0, 1, 3)
        self.layout.addWidget(self.radio_new, 2, 0, 2, 1)

        self.layout.addWidget(self.name_label, 2, 1)
        self.layout.addWidget(self.name_input, 2, 2)
        self.layout.addWidget(self.code_label, 3, 1)
        self.layout.addWidget(self.code_input, 3, 2)

        self.buttonBox = QtWidgets.QDialogButtonBox()
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(
            QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")

        self.buttonBox.accepted.connect(self.accept_click)
        self.buttonBox.rejected.connect(self.reject)
        QtCore.QMetaObject.connectSlotsByName(self)

        self.layout.addWidget(self.buttonBox, 4, 0, 1, 3, QtCore.Qt.AlignHCenter)
Esempio n. 13
0
    def contest_menu_actions(self, action, node, targetObject):
        """
            Do action based on contest menu selected
        :param action: selected action
        :param item_id: item id (ID in player tree structure)
        """
        # XXXXXXXXXXXXXXXXXX DELETE ACTION XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
        if action.data() == 'delete':
            self.tree_manager.delete_node(node, targetObject)
            # self.mainWindow.redraw_context_widget(None, None)
            self.draw_data()
            self.mainWindow.tabWidget.clear_tab_widget()
        # XXXXXXXXXXXXXXXXXX NEW ITEM ACTION XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
        elif action.data() == 'new':
            data, choice = NewTreeItem.get_data(self.__data_type.instance()
                                                ().children +
                                                [self.__data_type.instance()])
            if choice:
                self.tree_manager.create_node(data['NodeType'], data['name'],
                                              node.id, self.__data_type,
                                              data['NodeObject'])
                self.draw_data()
        # XXXXXXXXXXXXXXXXXX IMPORT DATA ACTION XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
        elif action.data() == 'import':
            self.import_data_slot(node.id)

        # XXXXXXXXXXXXXXXXX RENAME NODE ACTION XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
        elif action.data() == 'rename':
            obj = node
            text, ok = QtWidgets.QInputDialog.getText(self,
                                                      'Input Dialog',
                                                      TR().tr('New_name'),
                                                      text=obj.name)
            if ok:
                obj.name = text
                self.tree_manager.update_node(obj)

            self.draw_data()

        # XXXXXXXXXXXXXXXX ADD OBJECT FROM OTHER ACTION XXXXXXXXXXXXXXXXXXXXXXXX
        elif action.data() == 'add_object':
            data, ok = AddAnotherObject.get_data(node)
            if ok:
                for type, items in data.items():

                    for item in items:
                        nodeObject = self.tree_manager.get_node(item)
                        newObject = nodeObject.object.DAO()().get(
                            nodeObject.object.id, None, nodeObject.id,
                            nodeObject.object.object_type)

                        newObject.DAO()().create(newObject, node.id,
                                                 self.__data_type)

            self.draw_data()
Esempio n. 14
0
    def init_ui(self):
        """
        Init basic layout
        """
        self.setWindowIcon(QtGui.QIcon('resources/icons/char.png'))
        self.setWindowTitle('Create new item')
        self.layout = QtWidgets.QGridLayout(self)

        self.type_label = QtWidgets.QLabel(self)
        self.type_label.setText(TR().tr('Type') + ' :')
        self.layout.addWidget(self.type_label, 0, 0)
        self.type_input = QtWidgets.QComboBox(self)
        self.layout.addWidget(self.type_input, 0, 1)

        data = {'NodeType': NodeType.FOLDER}
        self.type_input.addItem(TR().tr(NodeType.FOLDER), QtCore.QVariant(data))

        for obj in self.__objects:
            data = {'NodeType': NodeType.OBJECT, 'NodeObject': obj}
            name = TR().tr(str(obj().object_type) if obj().object_type != ObjectType.ITEM else str(obj().type))
            self.type_input.addItem(name, QtCore.QVariant(data))

        self.type_input.setCurrentIndex(1)

        self.name_label = QtWidgets.QLabel(self)
        self.name_label.setText(TR().tr('Name') + ' :')
        self.layout.addWidget(self.name_label, 1, 0)
        self.name_input = QtWidgets.QLineEdit(self)
        self.layout.addWidget(self.name_input, 1, 1)

        self.buttonBox = QtWidgets.QDialogButtonBox()
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(
            QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")

        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)
        QtCore.QMetaObject.connectSlotsByName(self)

        self.layout.addWidget(self.buttonBox, 2, 0, 1, 2, QtCore.Qt.AlignHCenter)
        self.name_input.setFocus()
Esempio n. 15
0
    def init_ui(self):
        """
        Init basic UI. Init basic menu items (save, open, exit, etc. )
        :return:
        """
        exit_action = QAction(QIcon('resources/icons/exit.png'),
                              TR().tr('Menu_exit'), self)
        exit_action.setShortcut('Ctrl+Q')
        exit_action.setStatusTip('Exit application')
        exit_action.triggered.connect(self.quit_slot)

        open_action = QAction(QIcon('resources/icons/open.png'),
                              TR().tr('Menu_open'), self)
        open_action.setShortcut('Ctrl+O')
        open_action.setStatusTip('Open file')
        open_action.triggered.connect(self.open_slot)

        save_as_action = QAction(QIcon('resources/icons/save.png'),
                                 TR().tr('Menu_save_as'), self)
        save_as_action.setShortcut('Ctrl+Alt+S')
        save_as_action.setStatusTip('Save file as')
        save_as_action.triggered.connect(self.save_as_slot)

        save_action = QAction(QIcon('resources/icons/save.png'),
                              TR().tr('Menu_save'), self)
        save_action.setShortcut('Ctrl+S')
        save_action.setStatusTip('Save file')
        save_action.triggered.connect(self.save_slot)

        settings_action = QAction(QIcon('resources/icons/settings.png'),
                                  TR().tr('Menu_settings'), self)
        settings_action.setShortcut('Ctrl+T')
        settings_action.setStatusTip('Settings')
        settings_action.triggered.connect(self.settings_slot)
        # settings_action.setDisabled(True)

        file_menu = self.addMenu(TR().tr('Menu_file'))

        file_menu.addAction(open_action)
        file_menu.addAction(save_action)
        file_menu.addAction(save_as_action)
        file_menu.addAction(settings_action)
        file_menu.addSeparator()
        file_menu.addAction(exit_action)

        self.init_player_ui()

        about_action = QAction(TR().tr('Menu_about'), self)
        help_menu = self.addMenu(TR().tr('Menu_help'))
        help_menu.addAction(about_action)
        about_action.triggered.connect(self.about_action)
Esempio n. 16
0
    def __init__(self, node: Node, parent=None):
        super().__init__(parent)
        self.setWindowTitle(TR().tr('Add_object'))
        self.setWindowIcon(QtGui.QIcon('resources/icons/char.png'))
        self.treeManager = PlayerTreeManager()

        self.__selected = {}

        self.__node = node
        self.__parent = parent
        self.init_ui()
        self.resize(800, 600)
Esempio n. 17
0
    def save_slot(self) -> None:
        """
        Slot activate when click on save button
        :return: 
        """

        oldCode = SettingsDAO().get_value('language')
        if self.lang.code != oldCode:
            TextDialog(TR().tr('Language_changed'))
        self.DAO.set_value('language', self.lang.code)

        self.accept()
Esempio n. 18
0
    def closeEvent(self, event) -> None:
        """
        Rewrite close event for disable quit without prompt about save. 
        :param event: Event
        :return: 
        """
        quit_msg = TR().tr('Quit_text')
        reply = QtWidgets.QMessageBox.question(self, TR().tr('Sure_quit'),
                                               quit_msg,
                                               QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No | QtWidgets.QMessageBox.Save)

        if reply == QtWidgets.QMessageBox.Yes:
            event.accept()
        elif reply == QtWidgets.QMessageBox.Save:
            response = self.menuWidget().save_slot()
            if response:
                event.accept()
            else:
                event.ignore()
        else:
            event.ignore()
Esempio n. 19
0
    def init_bar(self) -> None:
        """
        Init function bar, set to right side of widget
        :return: 
        """
        toolbar = QToolBar()
        toolbar.setObjectName('MapToolbar')
        self.mainWindow.addToolBar(Qt.RightToolBarArea, toolbar)

        # ------------------------------- Open map ----------------------------------
        self.openMap_action = QAction(QIcon('resources/icons/openMap.png'), TR().tr('Open_map'), self.mainWindow,
                                      triggered=self.open_map_action, enabled=False)
        toolbar.addAction(self.openMap_action)

        # ------------------------------- Zoom in ----------------------------------
        self.zoomIn_action = QAction(QIcon('resources/icons/zoomIn.png'), TR().tr('Zoom_in'), self.mainWindow,
                                     triggered=self.zoom_in_action, shortcut='Ctrl++', enabled=False)
        toolbar.addAction(self.zoomIn_action)

        # ------------------------------- Zoom out ----------------------------------
        self.zoomOut_action = QAction(QIcon('resources/icons/zoomOut.png'), TR().tr('Zoom_out'), self.mainWindow,
                                      triggered=self.zoom_out_action, shortcut='Ctrl++', enabled=False)
        toolbar.addAction(self.zoomOut_action)

        # ------------------------------- Edit info  ----------------------------------
        self.info_action = QAction(QIcon('resources/icons/scroll.png'), TR().tr('Edit_info'), self.mainWindow,
                                   triggered=self.edit_info_action, shortcut='Ctrl+P', enabled=False)
        toolbar.addAction(self.info_action)

        toolbar.addSeparator()

        # ------------------------------- Add monster ----------------------------------
        self.addMonster_action = QAction(QIcon('resources/icons/addMonster.png'), TR().tr('Add_monster'), self.mainWindow,
                                         triggered=self.add_monster_action, shortcut='Ctrl+M', enabled=False)
        toolbar.addAction(self.addMonster_action)

        # ------------------------------- Add item ----------------------------------
        self.addItem_action = QAction(QIcon('resources/icons/addItem.png'), TR().tr('Add_item'), self.mainWindow,
                                      triggered=self.add_item_action, enabled=False)
        toolbar.addAction(self.addItem_action)

        # ------------------------------- Add room ----------------------------------
        self.addRoom_action = QAction(QIcon('resources/icons/addRoom.png'), TR().tr('Add_room'), self.mainWindow,
                                      triggered=self.add_room_action, enabled=False)
        toolbar.addAction(self.addRoom_action)

        # ------------------------------- Add object ----------------------------------
        self.addObject_action = QAction(QIcon('resources/icons/addObject.png'), TR().tr('Add_object_map'), self.mainWindow,
                                        triggered=self.add_object_action, enabled=False)
        toolbar.addAction(self.addObject_action)
Esempio n. 20
0
    def __set_table_data(self, treeNode: NodeObject) -> None:
        """
        Set data to table, in table should be list of ability Contexts
        :param treeNode: Tree node where ability is located, need for find ability contexts        
        """
        self.table.setColumnCount(4)

        heades = [
            TR().tr('Name'),
            TR().tr('Target_attribute_type'),
            TR().tr('Value_type'),
            TR().tr('Value')
        ]
        self.table.setHorizontalHeaderLabels(heades)

        header = self.table.horizontalHeader()
        header.setStretchLastSection(True)

        # print(treeNode)
        ability = AbilityDAO().get(self.object.id, self.object.lang,
                                   treeNode.id, treeNode.context)

        self.table.setRowCount(len(ability.contexts))

        for i, context in enumerate(ability.contexts):
            self.table.setItem(i, 0, QtWidgets.QTableWidgetItem(context.name))
            self.table.setItem(
                i, 1,
                QtWidgets.QTableWidgetItem(TR().tr((context.targetAttribute))))

            self.table.setItem(
                i, 2, QtWidgets.QTableWidgetItem(TR().tr((context.valueType))))

            self.table.setItem(i, 3,
                               QtWidgets.QTableWidgetItem(str(context.value)))
Esempio n. 21
0
    def quit_slot(self) -> None:
        """
        Slot for quit action. 
        Prompt before quit, if you sure to quit application, and youwant to save your data before.
        :return: 
        """
        quit_msg = TR().tr('Quit_text')
        reply = QtWidgets.QMessageBox.question(
            self,
            TR().tr('Sure_quit'), quit_msg, QtWidgets.QMessageBox.Yes
            | QtWidgets.QMessageBox.No | QtWidgets.QMessageBox.Save)

        if reply == QtWidgets.QMessageBox.Yes:
            qApp.quit()
        elif reply == QtWidgets.QMessageBox.Save:
            response = self.save_slot()
            if response:
                qApp.quit()
            else:
                pass
        else:
            pass
Esempio n. 22
0
    def combo_box(self,
                  grid: object,
                  name: str,
                  data: object,
                  xposition: int,
                  yposition: int,
                  synchronize: bool = False,
                  xspan: int = 1,
                  yspan: int = 1,
                  haveNone: bool = True) -> QtWidgets.QComboBox:
        """
        Widget for combobox
        :param grid: parent grid
        :param name: Name of label
        :param data: List of data for combobox (enum)
        :param xposition: grid position x
        :param yposition: grid position y
        :param synchronize: bool, if true, value is synchronized trough all languages
        :param xspan: Number of span columns
        :param yspan: Number of span rows
        :param haveNone: If True, combo box have select option value on position 0
        :return: input object
        """
        label = QtWidgets.QLabel(TR().tr(name) + ':')
        grid.addWidget(label, yposition, xposition, yspan, xspan)
        input = QtWidgets.QComboBox()
        input.setObjectName(name + "_input")
        input.currentIndexChanged.connect(self.data_changed)
        if synchronize:
            self.synchronize(input)
        grid.addWidget(input, yposition, xposition + 1, yspan, xspan)
        if haveNone:
            input.addItem(TR().tr('Select_value'))
        for value in data:
            Qdata = {'value': value}
            input.addItem(TR().tr(str(value)), QtCore.QVariant(Qdata))

        return input
Esempio n. 23
0
    def __init__(self, text, icon=None):
        msg = QtWidgets.QMessageBox()
        if icon:
            msg.setIcon(icon)
        else:
            msg.setIcon(QtWidgets.QMessageBox.Information)

        msg.setWindowTitle(TR().tr('About'))

        msg.setWindowIcon(QtGui.QIcon('resources/icons/char.png'))

        msg.setText(text)
        msg.setStandardButtons(QtWidgets.QMessageBox.Ok)
        msg.exec_()
Esempio n. 24
0
    def targetTypeChangedSlot(self, index):
        """
        Slot that is called when target type is changed
        :param index: index of target type input combobox
        """
        try:
            self.targetAttributeInput.currentIndexChanged.disconnect(
                self.attributeTargetChangedSlot)
        except:
            pass

        self.targetAttributeInput.setCurrentIndex(0)
        self.targetAttributeInput.clear()

        if index == 0:
            self.targetAttributeInput.setDisabled(True)
            self.valueTypeInput.setDisabled(True)
            self.valueInput.setDisabled(True)
            self.valueComboInput.setDisabled(True)

        elif ModifierTargetTypes(index) is ModifierTargetTypes.CHARACTER:
            data = CharacterAttributes
            self.targetAttributeInput.addItem(TR().tr('Select_value'))
            for value in data:
                Qdata = {'value': value}
                self.targetAttributeInput.addItem(TR().tr(str(value)), QtCore.QVariant(Qdata))
            self.targetAttributeInput.setDisabled(False)
            self.targetAttributeInput.currentIndexChanged.connect(self.attributeTargetChangedSlot)

        else:
            data = ItemsAttributes
            self.targetAttributeInput.addItem(TR().tr('Select_value'))
            for value in data:
                Qdata = {'value': value}
                self.targetAttributeInput.addItem(TR().tr(str(value)), QtCore.QVariant(Qdata))
            self.targetAttributeInput.setDisabled(False)
            self.targetAttributeInput.currentIndexChanged.connect(self.attributeTargetChangedSlot)
Esempio n. 25
0
    def open_slot(self) -> None:
        """
        Slot for open new file from .drd file. Delete whole program data and init new program data from file
        :return: 
        """
        options = QtWidgets.QFileDialog.Options()
        options |= QtWidgets.QFileDialog.DontUseNativeDialog
        types = "DrD Files (*.drd)"
        fileName, _ = QtWidgets.QFileDialog.getOpenFileName(
            None, TR().tr("File_select_open"), "", types, options=options)

        if fileName:
            DrdFile().open(fileName)
            self.templates_menu_signal.emit(ObjectType.SCENARIO)
            Sync().save_data('Opened_file', fileName)
Esempio n. 26
0
    def save_as_slot(self) -> str:
        """
        Slot for save ass action. This create new widget for select target file.
        File will be created with .drd extension
        :return: 
        """
        options = QtWidgets.QFileDialog.Options()
        options |= QtWidgets.QFileDialog.DontUseNativeDialog
        types = "DrD Files (*.drd)"
        fileName, _ = QtWidgets.QFileDialog.getSaveFileName(
            None, TR().tr("File_select_target"), "", types, options=options)

        if fileName:
            Sync().save_data('Opened_file', fileName)
            DrdFile().create(fileName)
            TextDialog('File saved')

        return fileName
Esempio n. 27
0
 def import_data_slot(self, parent=None):
     """
     Slot for import xml from file
     :param parent: parent node, import to witch folder
     """
     options = QtWidgets.QFileDialog.Options()
     options |= QtWidgets.QFileDialog.DontUseNativeDialog
     types = "Xml Files (*.xml)"
     fileName, _ = QtWidgets.QFileDialog.getOpenFileName(
         self, TR().tr("File_select_open"), "", types, options=options)
     if fileName:
         try:
             self.tree_manager.import_from_xml(fileName, self.__data_type,
                                               parent, True)
         except Exception as e:
             print(e)
             traceback.print_exc(file=sys.stderr)
             TextDialog('Export failed')
         self.draw_data()
Esempio n. 28
0
    def export_html_slot(self) -> None:
        """
        Slot for xport all selected objects to HTML files
        :return: 
        """
        it = QtWidgets.QTreeWidgetItemIterator(self.treeWidget)
        checked_items = []
        while it.value():
            if it.value().checkState(0) and it.value().data(
                    0, 12).nodeType is NodeType.OBJECT:
                checked_items.append(it.value().data(0, 12).id)
            it += 1

        options = QtWidgets.QFileDialog.Options()
        options |= QtWidgets.QFileDialog.DontUseNativeDialog
        types = "Html Files (*.html)"
        fileName, _ = QtWidgets.QFileDialog.getSaveFileName(
            self, TR().tr("File_select_target"), "", types, options=options)
        if fileName:
            self.tree_manager.export_to_html(checked_items, fileName)
            TextDialog('Export complete')
Esempio n. 29
0
    def init_ui(self):
        """
        Create basic UI frames and layouts
        """
        self.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.setFrameShadow(QtWidgets.QFrame.Raised)
        self.setObjectName("frame")

        self.frame_layout = QtWidgets.QVBoxLayout(self)
        self.frame_layout.setObjectName("Frame layout")
        self.frame_layout.setContentsMargins(2, 2, 2, 0)
        self.frame_layout.setSpacing(1)

        self.treeWidget = QtWidgets.QTreeWidget(self)
        self.treeWidget.setObjectName("treeWidget")
        font = QtGui.QFont()
        font.setPointSize(18)
        self.treeWidget.setFont(font)
        self.treeWidget.setHeaderLabel(TR().tr(self.__data_type))
        self.treeWidget.header().setDefaultAlignment(QtCore.Qt.AlignCenter)
        self.treeWidget.header().setFrameStyle(QtWidgets.QFrame.StyledPanel)
        self.treeWidget.header().setFrameShadow(QtWidgets.QFrame.Sunken)
        self.treeWidget.header().setLineWidth(2)

        # self.treeWidget.header().setFrameShadow(QtWidgets.QFrame.Plain)

        self.treeWidget.setDragDropMode(self.treeWidget.InternalMove)
        self.treeWidget.setDragEnabled(True)
        self.treeWidget.setDropIndicatorShown(True)

        self.main_drop_event = self.treeWidget.dropEvent
        self.treeWidget.dropEvent = self.custom_drop_event

        self.frame_layout.addWidget(self.treeWidget)

        self.init_buttons()
        self.init_context_menu()
Esempio n. 30
0
    def attributeTargetChangedSlot(self, index):
        """
        Slot that is called when target attributes is changed
        :param index: index of target attribute combobox
        :return:
        """
        try:
            self.valueTypeInput.currentIndexChanged.disconnect(self.valueTypeChangedSlot)
        except:
            pass

        self.valueTypeInput.setDisabled(False)
        self.valueInput.setDisabled(True)
        self.valueComboInput.setDisabled(True)

        if index == 0:
            self.valueTypeInput.setDisabled(True)

        elif ModifierTargetTypes(self.targetTypeInput.currentIndex()) is ModifierTargetTypes.CHARACTER:
            self.valueTypeInput.clear()
            self.valueTypeInput.addItem(TR().tr('Select_value'))
            for value in [ModifierValueTypes.TO_TOTAL, ModifierValueTypes.FROM_BASE, ModifierValueTypes.FROM_TOTAL]:
                Qdata = {'value': value}
                self.valueTypeInput.addItem(TR().tr(str(value)), QtCore.QVariant(Qdata))
            self.valueTypeInput.currentIndexChanged.connect(self.valueTypeChangedSlot)

        else:
            self.valueComboInput.clear()
            self.valueComboInput.addItem(TR().tr('Select_value'))
            self.valueTypeInput.clear()
            if ItemsAttributes(index) is ItemsAttributes.WEAPON_MELEE_HANDLING:
                self.valueTypeInput.addItem(TR().tr('Select_value'))
                for value in ModifierValueTypes:
                    Qdata = {'value': value}
                    self.valueTypeInput.addItem(TR().tr(str(value)), QtCore.QVariant(Qdata))
                self.valueTypeInput.currentIndexChanged.connect(self.valueSetTypeSlot)
                self.valueTypeInput.setCurrentIndex(ModifierValueTypes.TYPE_WEAPON_HANDLING.value)
                self.valueTypeInput.setDisabled(True)
                self.valueComboInput.show()
                self.valueInput.hide()
                self.valueComboInput.setDisabled(False)
                for one in Handling:
                    self.valueComboInput.addItem(TR().tr(one))

            elif ItemsAttributes(index) is ItemsAttributes.WEAPON_WEIGHT:
                self.valueTypeInput.addItem(TR().tr('Select_value'))
                for value in ModifierValueTypes:
                    Qdata = {'value': value}
                    self.valueTypeInput.addItem(TR().tr(str(value)), QtCore.QVariant(Qdata))
                self.valueTypeInput.currentIndexChanged.connect(self.valueSetTypeSlot)
                self.valueTypeInput.setCurrentIndex(ModifierValueTypes.TYPE_WEAPON_WEIGHT.value)
                self.valueTypeInput.setDisabled(True)
                self.valueComboInput.show()
                self.valueInput.hide()
                self.valueComboInput.setDisabled(False)
                for one in WeaponWeight:
                    self.valueComboInput.addItem(TR().tr(one))

            elif ItemsAttributes(index) is ItemsAttributes.ARMOR_SIZE:
                self.valueTypeInput.addItem(TR().tr('Select_value'))
                for value in ModifierValueTypes:
                    Qdata = {'value': value}
                    self.valueTypeInput.addItem(TR().tr(str(value)), QtCore.QVariant(Qdata))
                self.valueTypeInput.currentIndexChanged.connect(self.valueSetTypeSlot)
                self.valueTypeInput.setCurrentIndex(ModifierValueTypes.TYPE_ARMOR_SIZE.value)
                self.valueTypeInput.setDisabled(True)
                self.valueComboInput.show()
                self.valueInput.hide()
                self.valueComboInput.setDisabled(False)
                for one in ArmorSize:
                    self.valueComboInput.addItem(TR().tr(one))

            else:
                self.valueTypeInput.addItem(TR().tr('Select_value'))
                for value in [ModifierValueTypes.TO_TOTAL, ModifierValueTypes.FROM_BASE, ModifierValueTypes.FROM_TOTAL]:
                    Qdata = {'value': value}
                    self.valueTypeInput.addItem(TR().tr(str(value)), QtCore.QVariant(Qdata))
                self.valueTypeInput.currentIndexChanged.connect(self.valueTypeChangedSlot)

                self.valueComboInput.hide()
                self.valueInput.show()