Esempio n. 1
0
class TextWidget(QtGui.QGraphicsWidget):
    faded_opacity = .8
    padding = 3
    bg_color = QtGui.QColor(0,0,0,0)

    def __init__(self, timeout_seconds=0):
        super(TextWidget, self).__init__()

        self.setOpacity(self.faded_opacity)
        self.opaciter = OpacityAnimation(self)
        
        self.background = QtGui.QGraphicsRectItem(self)
        self.background.setBrush(QtGui.QBrush(self.bg_color))
        self.background.setPen(QtGui.QPen(QtGui.QColor(0,0,0,0)))

        self.item = TextItem(self)

        self._timer = None
        self.timeout_seconds = timeout_seconds


    def sizeHint(self, which, constraint=None):

        #if which == QtCore.Qt.PreferredSize:
        if True:
            rect = self.item.boundingRect()
            size = QtCore.QSizeF(rect.width(), rect.height())
        else:
            size = super(TextWidget, self).sizeHint(which, constraint)
        return size

    def setHtml(self, html):
        of = self.padding
        self.item.setHtml(html)
        rect = self.item.boundingRect()
        self.background.setRect(rect)
        self.updateGeometry()

    def show(self):
        if not self.opaciter.fadeTo(self.faded_opacity):
            self.opaciter.stop()
            self.opaciter.fadeTo(self.faded_opacity)
            
        if self.timeout_seconds:
            self.timer = QtCore.QTimer(self)
            self.timer.timeout.connect(self._hide)
            self.timer.setSingleShot(True)
            self.timer.start(self.timeout_seconds * 1000)

    def hide(self):
        if not self.opaciter.fadeTo(0):
            self.opaciter.stop()
            self.opaciter.fadeTo(0)
Esempio n. 2
0
class DirectionWidget(ChoiceWidget):
    title = 'Direction'

    def __init__(self):
        super(DirectionWidget, self).__init__()
        self._activate_callback = None
        self._opaciter = OpacityAnimation(self)
        self.hide()
        self._index = None

    def setChoices(self, title, items, callback):
        self.show()
        self._opaciter.fadeTo(1)
        self.title = title
        self._activate_callback = callback
        self.reset(items, noset=True, item_keys=True)
        self.setFocus()

    def onActivate(self, idx):
        direction = direction_by_name[direction_by_name.keys()[idx]]
        if self._index is not None:
            self._activate_callback(self._index, direction)
        else:
            self._activate_callback(direction)
        self.deactivate()

    def deactivate(self):
        self._activate_callback = None
        self._index = None
        self._opaciter.fadeTo(0)
        self.clearFocus()

    def setPlayer(self, player):
        player.events['item_direction_requested'].connect(self._onItemDirectionRequested)
        player.events['direction_requested'].connect(self._onDirectionRequested)

    def _onItemDirectionRequested(self, question, index, callback):

        directions = []
        for d in direction_by_name.values():
            directions.append((d.name, d.key))
        self._index = index
        self.setChoices(question, directions, callback)
    
    def _onDirectionRequested(self, question, callback):
        directions = []
        for d in direction_by_name.values():
            directions.append((d.name, d.key))
        self._index = None
        self.setChoices(question, directions, callback)
Esempio n. 3
0
class InventoryWidget(BaseItemWidget, ResetItem):
    
    attrs = tuple()

    nonsvg_klass = CharItem
    svg_klass = SvgEquipmentItem
    
    def __init__(self, parent, tile_width, use_svg):
        super(InventoryWidget, self).__init__(parent, tile_width)
        ResetItem.__init__(self, tile_width)

        klass = self.svg_klass if use_svg else self.nonsvg_klass
        self.item = klass(self, tile_width)
        self.item._allow_fallback = True

        self.opaciter = OpacityAnimation(self)
        self._inventory = None
        self.__args = None

    def reset(self, inventory):
        #FIXME call superclass reset
        item = inventory and inventory[-1]
        if item:
            self.item.reset(item)
        self._inventory = inventory

    def _onFadeOutDone(self):
        self.reset(self._inventory)
        self.opaciter.finished.disconnect(self._onFadeOutDone)

    def change(self, inventory, use_svg, use_iso, seethrough):
        
        if inventory is None:
            raise ValueError
        
        if inventory and not self._inventory:
            self.reset(inventory)
            self.setOpacity(0)
            self.opaciter.fadeTo(1)
        elif self._inventory and not inventory:
            self._inventory = inventory
            self.opaciter.fadeTo(0)
            self.opaciter.finished.connect(self._onFadeOutDone)
        else:
            self.reset(inventory)
Esempio n. 4
0
    def __init__(self, parent, tile_width, use_svg):
        super(InventoryWidget, self).__init__(parent, tile_width)
        ResetItem.__init__(self, tile_width)

        klass = self.svg_klass if use_svg else self.nonsvg_klass
        self.item = klass(self, tile_width)
        self.item._allow_fallback = True

        self.opaciter = OpacityAnimation(self)
        self._inventory = None
        self.__args = None
Esempio n. 5
0
    def __init__(self, timeout_seconds=0):
        super(TextWidget, self).__init__()

        self.setOpacity(self.faded_opacity)
        self.opaciter = OpacityAnimation(self)
        
        self.background = QtGui.QGraphicsRectItem(self)
        self.background.setBrush(QtGui.QBrush(self.bg_color))
        self.background.setPen(QtGui.QPen(QtGui.QColor(0,0,0,0)))

        self.item = TextItem(self)

        self._timer = None
        self.timeout_seconds = timeout_seconds
Esempio n. 6
0
class ChoicesWidget(ChoiceWidget):

    title = 'Choices'
    def __init__(self):
        super(ChoicesWidget, self).__init__()
        self._activate_callback = None
        self._opaciter = OpacityAnimation(self)
        self.hide()

    def setChoices(self, title, items, callback):
        self.show()
        self._opaciter.fadeTo(1)
        self.title = title
        self._activate_callback = callback
        self.reset(items, noset=True)
        self.setFocus()

    def onActivate(self, idx):
        self._activate_callback(idx)
        self.deactivate()

    def deactivate(self):
        self._activate_callback = None
        self._opaciter.fadeTo(0)
        #self.setOpacity(0)
        self.clearFocus()

    def setPlayer(self, player):
        player.events['remove_usable_requested'].connect(self._onTakeOffItemRequested)
        player.events['usable_requested'].connect(self._onUsableRequested)

    def _onTakeOffItemRequested(self, wearing, callback):
        self.setChoices("Remove what item?", wearing, callback)

    def _onUsableRequested(self, question, usables, callback):
        self.setChoices(question, usables, callback)
Esempio n. 7
0
 def __init__(self):
     super(DirectionWidget, self).__init__()
     self._activate_callback = None
     self._opaciter = OpacityAnimation(self)
     self.hide()
     self._index = None