Beispiel #1
0
    def __init__(self, symbol, synchronizer, parent = None):

        super(SymbolSelectorItem, self).__init__(parent)
        self._synchronizer = synchronizer
        self._symbol = symbol

        # define and set stylesheets
        self.define_stylesheets()
        self.setStyleSheet(self._unselectedStyleSheet)
        self.setToolTip(symbol["description"])

        # add the symbol's svg
        svgWidget = QSvgWidget(symbol["svgPath"])
        svgWidth = int(symbol["width"]) #.toInt()[0]
        svgWidget.setMaximumSize(QSize(svgWidth * 30, 30))

        self.setMinimumSize(svgWidth * 30, 30)
        self.setMaximumSize(svgWidth * 30, 30)

        # finalize the layout
        layout = QHBoxLayout()
        layout.setContentsMargins( 0, 0, 0, 0 )
        layout.addWidget(svgWidget)
        self.setLayout(layout)
Beispiel #2
0
class CharacterWidget(QWidget):
    """
    Widget to show character

    .. versionadded:: 0.7
    """
    def __init__(self, surface_manager, character, parent):
        """
        Default constructor
        """
        super(CharacterWidget, self).__init__(parent)

        self.body = None
        self.finesse = None
        self.character_icon = None
        self.hp = None
        self.mind = None
        self.mana = None

        self.__set_layout(surface_manager,
                          character)

    def __set_layout(self, surface_manager, character):
        """
        Set layout of this widget
        """
        main_layout = QHBoxLayout()
        left_layout = QVBoxLayout()
        right_layout = QVBoxLayout()

        left_top_layout = QHBoxLayout()
        left_bottom_layout = QVBoxLayout()

        icon_layout = QVBoxLayout()
        stat_layout = QGridLayout()

        self.body = QLabel()
        self.body.setText(str(character.body))
        self.body.setObjectName('no_border')
        self.mind = QLabel()
        self.mind.setText(str(character.mind))
        self.mind.setObjectName('no_border')
        self.finesse = QLabel()
        self.finesse.setText(str(character.finesse))
        self.finesse.setObjectName('no_border')
        self.hp = QLabel()
        self.hp.setText('{0}/{1}'.format(character.hit_points,
                                         character.max_hp))
        self.hp.setObjectName('no_border')
        self.mana = QLabel()
        self.mana.setText('0/0')
        self.mana.setObjectName('no_border')

        body_label = QLabel('Body:')
        body_label.setObjectName('no_border')
        mind_label = QLabel('Mind:')
        mind_label.setObjectName('no_border')
        finesse_label = QLabel('Finesse:')
        finesse_label.setObjectName('no_border')
        hp_label = QLabel('HP:')
        hp_label.setObjectName('no_border')
        mana_label = QLabel('Mana:')
        mana_label.setObjectName('no_border')

        stat_layout.addWidget(self.body, 0, 1)
        stat_layout.addWidget(body_label, 0, 0)
        stat_layout.addWidget(self.mind, 1, 1)
        stat_layout.addWidget(mind_label, 1, 0)
        stat_layout.addWidget(self.finesse, 2, 1)
        stat_layout.addWidget(finesse_label, 2, 0)
        stat_layout.addWidget(self.hp, 3, 1)
        stat_layout.addWidget(hp_label, 3, 0)
        stat_layout.addWidget(self.mana, 4, 1)
        stat_layout.addWidget(mana_label, 4, 0)


        self.character_icon = QSvgWidget(':strong.svg')
        self.character_icon.setMaximumSize(150, 150)
        self.character_icon.setMinimumSize(150, 150)
        icon_layout.addWidget(self.character_icon)

        skills_label = QLabel('Skills')
        skills_label.setObjectName('section_title')
        skills = ListView()

        right_layout.addWidget(skills_label)
        right_layout.addWidget(skills)

        effects_label = QLabel('Effects')
        effects_label.setObjectName('section_title')
        effects = ListView()

        for effect in character.get_effects():
            effects.add_item(title = effect.title,
                             description = effect.description,
                             icon = surface_manager.get_icon(effect.icon))

        left_bottom_layout.addWidget(effects_label)
        left_bottom_layout.addWidget(effects)

        left_top_layout.addLayout(icon_layout)
        left_top_layout.addLayout(stat_layout)
        left_layout.addLayout(left_top_layout)
        left_layout.addLayout(left_bottom_layout)
        main_layout.addLayout(left_layout)
        main_layout.addLayout(right_layout)

        self.setLayout(main_layout)
Beispiel #3
0
class CharacterInventoryWidget(QWidget):
    """
    Widget to show inventory of a character

    .. versionadded:: 0.6
    """
    def __init__(self, surface_manager, character, config, parent):
        """
        Default constructor
        """
        super(CharacterInventoryWidget, self).__init__(parent)

        self.surface_manager = surface_manager
        self.character = character
        self.config = config
        self.items = []
        self.head_slot = None
        self.boots_slot = None
        self.shield_slot = None
        self.weapon_slot = None
        self.character_icon = None
        self.gloves_slot = None
        self.ring_slot = None
        self.arrows_slot = None
        self.necklace_slot = None
        self.belt_slot = None
        self.armour_slot = None

        self.__set_layout(surface_manager, character, parent)
        self.keymap, self.move_keys = self._construct_keymaps(config)

    ItemFocused = pyqtSignal(Item, name='ItemFocused')
    ItemActionA = pyqtSignal(Item, name='ItemActionA')
    ItemActionB = pyqtSignal(Item, name='ItemActionB')
    ItemActionX = pyqtSignal(Item, name='ItemActionX')
    ItemActionY = pyqtSignal(Item, name='ItemActionY')

    def _construct_keymaps(self, config):
        """
        Construct keymaps from configuration

        :param config: controls configuration
        :type config: ControlsConfiguration
        :returns: keymap for widget and move keys
        :rtype: {}, {}

        .. versionadded:: 0.8
        """
        move_keys = {}
        keymap = {}

        for key in config.move_down_left:
            move_keys[key] = 1
            keymap[key] = self._move
        for key in config.move_down:
            move_keys[key] = 1
            keymap[key] = self._move
        for key in config.move_down_right:
            move_keys[key] = 1
            keymap[key] = self._move
        for key in config.move_left:
            move_keys[key] = -1
            keymap[key] = self._move
        for key in config.move_right:
            move_keys[key] = 1
            keymap[key] = self._move
        for key in config.move_up_left:
            move_keys[key] = -1
            keymap[key] = self._move
        for key in config.move_up:
            move_keys[key] = -1
            keymap[key] = self._move
        for key in config.move_up_right:
            move_keys[key] = -1
            keymap[key] = self._move

        for key in config.action_a:
            keymap[key] = self._action
        for key in config.action_b:
            keymap[key] = self._action

        return keymap, move_keys

    def __set_layout(self, surface_manager, character, parent):
        """
        Set layout of this widget
        """
        main_layout = QHBoxLayout()

        left_side = QVBoxLayout()
        self.ring_slot = ItemGlyph(None, surface_manager, self,
                                   QPixmap(':ring.png'))
        self.items.append(self.ring_slot)

        self.weapon_slot = ItemGlyph(None, surface_manager, self,
                                     QPixmap(':inventory_sword.png'))
        self.items.append(self.weapon_slot)

        self.gloves_slot = ItemGlyph(None, surface_manager, self,
                                     QPixmap(':mailed-fist.png'))
        self.items.append(self.gloves_slot)

        left_side.addStretch()
        left_side.addWidget(self.ring_slot)
        left_side.addWidget(self.weapon_slot)
        left_side.addWidget(self.gloves_slot)
        left_side.addStretch()

        middle = QVBoxLayout()

        middle_top = QHBoxLayout()
        self.head_slot = ItemGlyph(None, surface_manager, self,
                                   QPixmap(':helm.png'))
        self.items.append(self.head_slot)

        self.necklace_slot = ItemGlyph(None, surface_manager, self,
                                       QPixmap(':necklace.png'))
        self.items.append(self.necklace_slot)

        middle_top.addStretch()
        middle_top.addWidget(self.head_slot)
        middle_top.addWidget(self.necklace_slot)
        middle_top.addStretch()

        middle_middle = QHBoxLayout()

        self.character_icon = QSvgWidget(':strong.svg')
        self.character_icon.setMaximumSize(150, 150)
        self.character_icon.setMinimumSize(150, 150)
        middle_middle.addWidget(self.character_icon)

        middle_bottom = QHBoxLayout()
        self.boots_slot = ItemGlyph(None, surface_manager, self,
                                    QPixmap(':boots.png'))
        self.items.append(self.boots_slot)

        self.belt_slot = ItemGlyph(None, surface_manager, self,
                                   QPixmap(':belts.png'))
        self.items.append(self.belt_slot)

        middle_bottom.addStretch()
        middle_bottom.addWidget(self.boots_slot)
        middle_bottom.addWidget(self.belt_slot)
        middle_bottom.addStretch()

        middle.addLayout(middle_top)
        middle.addLayout(middle_middle)
        middle.addLayout(middle_bottom)

        right_side = QVBoxLayout()
        self.arrows_slot = ItemGlyph(None, surface_manager, self,
                                     QPixmap(':arrow-cluster.png'))
        self.items.append(self.arrows_slot)

        self.shield_slot = ItemGlyph(None, surface_manager, self,
                                     QPixmap(':shield.png'))
        self.items.append(self.shield_slot)

        self.armour_slot = ItemGlyph(None, surface_manager, self,
                                     QPixmap(':breastplate.png'))
        self.items.append(self.armour_slot)

        right_side.addStretch()
        right_side.addWidget(self.arrows_slot)
        right_side.addWidget(self.shield_slot)
        right_side.addWidget(self.armour_slot)
        right_side.addStretch()

        main_layout.addLayout(left_side)
        main_layout.addLayout(middle)
        main_layout.addLayout(right_side)

        self.setLayout(main_layout)

    def show_character(self):
        """
        Show character
        """
        self.weapon_slot.set_item(self.character.inventory.weapon)
        self.armour_slot.set_item(self.character.inventory.armour)
        self.arrows_slot.set_item(self.character.inventory.projectiles)
        self.head_slot.set_item(self.character.inventory.helm)
        self.boots_slot.set_item(self.character.inventory.boots)
        self.shield_slot.set_item(self.character.inventory.shield)
        self.gloves_slot.set_item(self.character.inventory.gloves)
        self.ring_slot.set_item(self.character.inventory.ring)
        self.necklace_slot.set_item(self.character.inventory.necklace)
        self.belt_slot.set_item(self.character.inventory.belt)

    def _move(self, key):
        """
        Handle move keys

        .. versionadded:: 0.8
        """
        current = [
            x for x in self.items
            if x.display.objectName() == 'active_inventorybox'
        ][0]

        index = self.items.index(current)
        new_index = index + self.move_keys[key]

        if new_index < len(self.items) and new_index >= 0:
            new = self.items[new_index]
            new.setFocus(Qt.OtherFocusReason)
        else:
            if new_index < 0:
                self.focusPreviousChild()
            else:
                self.focusNextChild()

    def _action(self, key):
        """
        Handle action keys

        .. versionadded:: 0.8
        """
        item = [
            x for x in self.items
            if x.display.objectName() == 'active_inventorybox'
        ][0].item
        if item is not None:
            if key in self.config.action_a:
                self.ItemActionA.emit(item)
            elif key in self.config.action_b:
                self.ItemActionB.emit(item)

    def keyPressEvent(self, event):  #pylint: disable-msg=C0103
        """
        Handle keyboard events
        """
        key = event.key()

        if key in self.keymap:
            self.keymap[key](key)
        else:
            super(CharacterInventoryWidget, self).keyPressEvent(event)

    def focus_on_first_item(self):
        """
        Focus on the first item
        """
        self.items[0].setFocus()

    def focus_on_last_item(self):
        """
        Focus on the last item
        """
        self.items[-1].setFocus()
Beispiel #4
0
class CharacterWidget(QWidget):
    """
    Widget to show character

    .. versionadded:: 0.7
    """
    def __init__(self, surface_manager, character, parent):
        """
        Default constructor
        """
        super(CharacterWidget, self).__init__(parent)

        self.body = None
        self.finesse = None
        self.character_icon = None
        self.hp = None
        self.mind = None
        self.mana = None

        self.__set_layout(surface_manager, character)

    def __set_layout(self, surface_manager, character):
        """
        Set layout of this widget
        """
        main_layout = QHBoxLayout()
        left_layout = QVBoxLayout()
        right_layout = QVBoxLayout()

        left_top_layout = QHBoxLayout()
        left_bottom_layout = QVBoxLayout()

        icon_layout = QVBoxLayout()
        stat_layout = QGridLayout()

        self.body = QLabel()
        self.body.setText(str(character.body))
        self.body.setObjectName('no_border')
        self.mind = QLabel()
        self.mind.setText(str(character.mind))
        self.mind.setObjectName('no_border')
        self.finesse = QLabel()
        self.finesse.setText(str(character.finesse))
        self.finesse.setObjectName('no_border')
        self.hp = QLabel()
        self.hp.setText('{0}/{1}'.format(character.hit_points,
                                         character.max_hp))
        self.hp.setObjectName('no_border')
        self.mana = QLabel()
        self.mana.setText('0/0')
        self.mana.setObjectName('no_border')

        body_label = QLabel('Body:')
        body_label.setObjectName('no_border')
        mind_label = QLabel('Mind:')
        mind_label.setObjectName('no_border')
        finesse_label = QLabel('Finesse:')
        finesse_label.setObjectName('no_border')
        hp_label = QLabel('HP:')
        hp_label.setObjectName('no_border')
        mana_label = QLabel('Mana:')
        mana_label.setObjectName('no_border')

        stat_layout.addWidget(self.body, 0, 1)
        stat_layout.addWidget(body_label, 0, 0)
        stat_layout.addWidget(self.mind, 1, 1)
        stat_layout.addWidget(mind_label, 1, 0)
        stat_layout.addWidget(self.finesse, 2, 1)
        stat_layout.addWidget(finesse_label, 2, 0)
        stat_layout.addWidget(self.hp, 3, 1)
        stat_layout.addWidget(hp_label, 3, 0)
        stat_layout.addWidget(self.mana, 4, 1)
        stat_layout.addWidget(mana_label, 4, 0)

        self.character_icon = QSvgWidget(':strong.svg')
        self.character_icon.setMaximumSize(150, 150)
        self.character_icon.setMinimumSize(150, 150)
        icon_layout.addWidget(self.character_icon)

        skills_label = QLabel('Skills')
        skills_label.setObjectName('section_title')
        skills = ListView()

        right_layout.addWidget(skills_label)
        right_layout.addWidget(skills)

        effects_label = QLabel('Effects')
        effects_label.setObjectName('section_title')
        effects = ListView()

        for effect in character.get_effects():
            effects.add_item(title=effect.title,
                             description=effect.description,
                             icon=surface_manager.get_icon(effect.icon))

        left_bottom_layout.addWidget(effects_label)
        left_bottom_layout.addWidget(effects)

        left_top_layout.addLayout(icon_layout)
        left_top_layout.addLayout(stat_layout)
        left_layout.addLayout(left_top_layout)
        left_layout.addLayout(left_bottom_layout)
        main_layout.addLayout(left_layout)
        main_layout.addLayout(right_layout)

        self.setLayout(main_layout)
Beispiel #5
0
class CharacterInventoryWidget(QWidget):
    """
    Widget to show inventory of a character

    .. versionadded:: 0.6
    """
    def __init__(self, surface_manager, character, config, parent):
        """
        Default constructor
        """
        super(CharacterInventoryWidget, self).__init__(parent)

        self.surface_manager = surface_manager
        self.character = character
        self.config = config
        self.items = []
        self.head_slot = None
        self.boots_slot = None
        self.shield_slot = None
        self.weapon_slot = None
        self.character_icon = None
        self.gloves_slot = None
        self.ring_slot = None
        self.arrows_slot = None
        self.necklace_slot = None
        self.belt_slot = None
        self.armour_slot = None


        self.__set_layout(surface_manager, character, parent)
        self.keymap, self.move_keys = self._construct_keymaps(config)

    ItemFocused = pyqtSignal(Item, name='ItemFocused')
    ItemActionA = pyqtSignal(Item, name='ItemActionA')
    ItemActionB = pyqtSignal(Item, name='ItemActionB')
    ItemActionX = pyqtSignal(Item, name='ItemActionX')
    ItemActionY = pyqtSignal(Item, name='ItemActionY')

    def _construct_keymaps(self, config):
        """
        Construct keymaps from configuration

        :param config: controls configuration
        :type config: ControlsConfiguration
        :returns: keymap for widget and move keys
        :rtype: {}, {}

        .. versionadded:: 0.8
        """
        move_keys = {}
        keymap = {}

        for key in config.move_down_left:
            move_keys[key] = 1
            keymap[key] = self._move
        for key in config.move_down:
            move_keys[key] = 1
            keymap[key] = self._move
        for key in config.move_down_right:
            move_keys[key] = 1
            keymap[key] = self._move
        for key in config.move_left:
            move_keys[key] = -1
            keymap[key] = self._move
        for key in config.move_right:
            move_keys[key] = 1
            keymap[key] = self._move
        for key in config.move_up_left:
            move_keys[key] = -1
            keymap[key] = self._move
        for key in config.move_up:
            move_keys[key] = -1
            keymap[key] = self._move
        for key in config.move_up_right:
            move_keys[key] = -1
            keymap[key] = self._move

        for key in config.action_a:
            keymap[key] = self._action
        for key in config.action_b:
            keymap[key] = self._action

        return keymap, move_keys

    def __set_layout(self, surface_manager, character, parent):
        """
        Set layout of this widget
        """
        main_layout = QHBoxLayout()

        left_side = QVBoxLayout()
        self.ring_slot = ItemGlyph(None,
                                   surface_manager,
                                   self,
                                   QPixmap(':ring.png'))
        self.items.append(self.ring_slot)

        self.weapon_slot = ItemGlyph(None,
                                     surface_manager,
                                     self,
                                     QPixmap(':inventory_sword.png'))
        self.items.append(self.weapon_slot)

        self.gloves_slot = ItemGlyph(None,
                                     surface_manager,
                                     self,
                                     QPixmap(':mailed-fist.png'))
        self.items.append(self.gloves_slot)

        left_side.addStretch()
        left_side.addWidget(self.ring_slot)
        left_side.addWidget(self.weapon_slot)
        left_side.addWidget(self.gloves_slot)
        left_side.addStretch()

        middle = QVBoxLayout()

        middle_top = QHBoxLayout()
        self.head_slot = ItemGlyph(None,
                                   surface_manager,
                                   self,
                                   QPixmap(':helm.png'))
        self.items.append(self.head_slot)

        self.necklace_slot = ItemGlyph(None,
                                       surface_manager,
                                       self,
                                       QPixmap(':necklace.png'))
        self.items.append(self.necklace_slot)

        middle_top.addStretch()
        middle_top.addWidget(self.head_slot)
        middle_top.addWidget(self.necklace_slot)
        middle_top.addStretch()

        middle_middle = QHBoxLayout()

        self.character_icon = QSvgWidget(':strong.svg')
        self.character_icon.setMaximumSize(150, 150)
        self.character_icon.setMinimumSize(150, 150)
        middle_middle.addWidget(self.character_icon)

        middle_bottom = QHBoxLayout()
        self.boots_slot = ItemGlyph(None,
                                    surface_manager,
                                    self,
                                    QPixmap(':boots.png'))
        self.items.append(self.boots_slot)

        self.belt_slot = ItemGlyph(None,
                                   surface_manager,
                                   self,
                                   QPixmap(':belts.png'))
        self.items.append(self.belt_slot)

        middle_bottom.addStretch()
        middle_bottom.addWidget(self.boots_slot)
        middle_bottom.addWidget(self.belt_slot)
        middle_bottom.addStretch()

        middle.addLayout(middle_top)
        middle.addLayout(middle_middle)
        middle.addLayout(middle_bottom)

        right_side = QVBoxLayout()
        self.arrows_slot = ItemGlyph(None,
                                     surface_manager,
                                     self,
                                     QPixmap(':arrow-cluster.png'))
        self.items.append(self.arrows_slot)

        self.shield_slot = ItemGlyph(None,
                                     surface_manager,
                                     self,
                                     QPixmap(':shield.png'))
        self.items.append(self.shield_slot)

        self.armour_slot = ItemGlyph(None,
                                     surface_manager,
                                     self,
                                     QPixmap(':breastplate.png'))
        self.items.append(self.armour_slot)

        right_side.addStretch()
        right_side.addWidget(self.arrows_slot)
        right_side.addWidget(self.shield_slot)
        right_side.addWidget(self.armour_slot)
        right_side.addStretch()

        main_layout.addLayout(left_side)
        main_layout.addLayout(middle)
        main_layout.addLayout(right_side)

        self.setLayout(main_layout)

    def show_character(self):
        """
        Show character
        """
        self.weapon_slot.set_item(self.character.inventory.weapon)
        self.armour_slot.set_item(self.character.inventory.armour)
        self.arrows_slot.set_item(self.character.inventory.projectiles)
        self.head_slot.set_item(self.character.inventory.helm)
        self.boots_slot.set_item(self.character.inventory.boots)
        self.shield_slot.set_item(self.character.inventory.shield)
        self.gloves_slot.set_item(self.character.inventory.gloves)
        self.ring_slot.set_item(self.character.inventory.ring)
        self.necklace_slot.set_item(self.character.inventory.necklace)
        self.belt_slot.set_item(self.character.inventory.belt)

    def _move(self, key):
        """
        Handle move keys

        .. versionadded:: 0.8
        """
        current = [x for x in self.items
                   if x.display.objectName() == 'active_inventorybox'][0]

        index = self.items.index(current)
        new_index = index + self.move_keys[key]

        if new_index < len(self.items) and new_index >= 0:
            new = self.items[new_index]
            new.setFocus(Qt.OtherFocusReason)
        else:
            if new_index < 0:
                self.focusPreviousChild()
            else:
                self.focusNextChild()

    def _action(self, key):
        """
        Handle action keys

        .. versionadded:: 0.8
        """
        item = [x for x in self.items
                if x.display.objectName() == 'active_inventorybox'][0].item
        if item is not None:
            if key in self.config.action_a:
                self.ItemActionA.emit(item)
            elif key in self.config.action_b:
                self.ItemActionB.emit(item)

    def keyPressEvent(self, event): #pylint: disable-msg=C0103
        """
        Handle keyboard events
        """
        key = event.key()

        if key in self.keymap:
            self.keymap[key](key)
        else:
            super(CharacterInventoryWidget, self).keyPressEvent(event)

    def focus_on_first_item(self):
        """
        Focus on the first item
        """
        self.items[0].setFocus()

    def focus_on_last_item(self):
        """
        Focus on the last item
        """
        self.items[-1].setFocus()