コード例 #1
0
    def __init__(self, mainWindow):
        super(QDockWidget, self).__init__(mainWindow)
        self.setToolTip(
            self.tr("Allows for drawing from a virtual deck of cards."))
        self.setWindowTitle(self.tr("Deck"))
        #self.pristineCards = []
        self.cards = []

        self.deckDisplay = QListWidget()
        self.deckDisplay.itemActivated.connect(self.removeCard)
        self.cardNameField = QLineEdit()
        self.addCardButton = QPushButton("Add")
        self.addCardButton.clicked.connect(self.addCard)
        self.peekAmountField = QSpinBox()
        self.drawCardButton = QPushButton("Draw")
        self.drawCardButton.clicked.connect(self.drawCard)
        self.drawPlaceField = QSpinBox()
        self.peekCardButton = QPushButton("Peek")
        self.peekCardButton.clicked.connect(self.peekCard)
        self.refreshDeckButton = QPushButton("Initialize Deck")
        self.refreshDeckButton.clicked.connect(self.refreshDeck)
        self.shuffleDeckButton = QPushButton("Shuffle Deck")
        self.shuffleDeckButton.clicked.connect(self.shuffleDeck)
        self.loadButton = QPushButton("Load from file")
        self.loadButton.clicked.connect(self.loadFromFile)

        self.widget = QWidget(mainWindow)
        self.layout = QGridLayout()
        self.layout.addWidget(self.deckDisplay, 1, 0, 1, 2)
        self.layout.addWidget(self.cardNameField, 0, 0)
        self.layout.addWidget(self.addCardButton, 0, 1)
        self.layout.addWidget(self.drawCardButton, 2, 0)
        self.layout.addWidget(self.drawPlaceField, 2, 1)
        self.layout.addWidget(self.peekAmountField, 3, 0)
        self.layout.addWidget(self.peekCardButton, 3, 1)
        self.layout.addWidget(self.shuffleDeckButton, 4, 0)
        self.layout.addWidget(self.refreshDeckButton, 4, 1)
        self.layout.addWidget(self.loadButton, 5, 0, 1, 2)
        self.widget.setLayout(self.layout)
        self.setWidget(self.widget)
        self.setObjectName("Deck")

        mainWindow.addDockWidget(Qt.BottomDockWidgetArea, self)

        self.hide()
コード例 #2
0
 def __init__(self, mainWindow):
     super(QDockWidget, self).__init__(mainWindow)
     self.setWindowTitle(self.tr("Dice"))
     self.realwidget = QWidget(
         mainWindow
     )  #I messed up on the initial setup and was too lazy to rename everything.
     self.widget = QGridLayout()
     self.diceArea = QListWidget(mainWindow)
     try:
         self.load(jsonload(ospath.join(SAVE_DIR, "dice.rgd")))
     except:
         self.macros = [
             QListWidgetItem(QIcon('data/dice.png'), "Sample: 2d6"),
             QListWidgetItem(QIcon('data/dice.png'), "Sample: 4k2"),
             QListWidgetItem(QIcon('data/dice.png'), "Sample: 1dn3")
         ]
     for m in self.macros:
         self.diceArea.addItem(m)
     self.diceArea.currentRowChanged.connect(self.changeCurrentMacro)
     self.rollbutton = QPushButton(self.tr("Roll"), mainWindow)
     self.rollbutton.setToolTip(
         self.tr("Roll dice according to the selected macro."))
     self.addmacrobutton = QPushButton(self.tr("Add Macro"), mainWindow)
     self.addmacrobutton.setToolTip(
         self.tr("Add a new macro via a dialog box."))
     self.removemacrobutton = QPushButton(self.tr("Delete Macro"),
                                          mainWindow)
     self.removemacrobutton.setToolTip(
         self.tr("Remove the currently selected macro."))
     self.rollbutton.clicked.connect(self.rollDice)
     self.addmacrobutton.clicked.connect(self.summonMacro)
     self.removemacrobutton.clicked.connect(self.removeCurrentMacro)
     self.widget.addWidget(self.diceArea, 0, 0)
     self.widget.addWidget(self.rollbutton, 1, 0)
     self.widget.addWidget(self.addmacrobutton, 2, 0)
     self.widget.addWidget(self.removemacrobutton, 3, 0)
     self.realwidget.setLayout(self.widget)
     self.setWidget(self.realwidget)
     self.setObjectName("Dice Widget")
     mainWindow.addDockWidget(Qt.BottomDockWidgetArea, self)
     self.close()
     self.currentMacro = -1
コード例 #3
0
 def __init__(self, parent, ulmain):
     QListWidget.__init__(self)
     self.ulmain = ulmain
     self.itemActivated.connect(self.changeGM)
コード例 #4
0
class deckWidget(QDockWidget):
    def __init__(self, mainWindow):
        super(QDockWidget, self).__init__(mainWindow)
        self.setToolTip(
            self.tr("Allows for drawing from a virtual deck of cards."))
        self.setWindowTitle(self.tr("Deck"))
        #self.pristineCards = []
        self.cards = []

        self.deckDisplay = QListWidget()
        self.deckDisplay.itemActivated.connect(self.removeCard)
        self.cardNameField = QLineEdit()
        self.addCardButton = QPushButton("Add")
        self.addCardButton.clicked.connect(self.addCard)
        self.peekAmountField = QSpinBox()
        self.drawCardButton = QPushButton("Draw")
        self.drawCardButton.clicked.connect(self.drawCard)
        self.drawPlaceField = QSpinBox()
        self.peekCardButton = QPushButton("Peek")
        self.peekCardButton.clicked.connect(self.peekCard)
        self.refreshDeckButton = QPushButton("Initialize Deck")
        self.refreshDeckButton.clicked.connect(self.refreshDeck)
        self.shuffleDeckButton = QPushButton("Shuffle Deck")
        self.shuffleDeckButton.clicked.connect(self.shuffleDeck)
        self.loadButton = QPushButton("Load from file")
        self.loadButton.clicked.connect(self.loadFromFile)

        self.widget = QWidget(mainWindow)
        self.layout = QGridLayout()
        self.layout.addWidget(self.deckDisplay, 1, 0, 1, 2)
        self.layout.addWidget(self.cardNameField, 0, 0)
        self.layout.addWidget(self.addCardButton, 0, 1)
        self.layout.addWidget(self.drawCardButton, 2, 0)
        self.layout.addWidget(self.drawPlaceField, 2, 1)
        self.layout.addWidget(self.peekAmountField, 3, 0)
        self.layout.addWidget(self.peekCardButton, 3, 1)
        self.layout.addWidget(self.shuffleDeckButton, 4, 0)
        self.layout.addWidget(self.refreshDeckButton, 4, 1)
        self.layout.addWidget(self.loadButton, 5, 0, 1, 2)
        self.widget.setLayout(self.layout)
        self.setWidget(self.widget)
        self.setObjectName("Deck")

        mainWindow.addDockWidget(Qt.BottomDockWidgetArea, self)

        self.hide()

    def addCard(self, *args, **kwargs):
        self.deckDisplay.addItem(str(self.cardNameField.text()))

    def removeCard(self, card):
        self.deckDisplay.takeItem(self.deckDisplay.currentRow())

    def drawCard(self):
        if len(self.cards) <= 0:
            GlobalState.cwidget.insertMessage("No cards to draw!")
        else:
            card = self.cards.pop(self.drawPlaceField.value())
            GlobalState.cwidget.insertMessage(card)

    def peekCard(self):
        for i in range(self.peekAmountField.value()):
            try:
                GlobalState.cwidget.insertMessage(
                    str(i) + ": " + self.cards[i])
            except:
                GlobalState.cwidget.insertMessage(
                    str(i) + ": " + "Too few cards to peek on!")

    @property
    def pristineCards(self):
        return [
            str(self.deckDisplay.item(i).text())
            for i in range(self.deckDisplay.count())
        ]

    def refreshDeck(self):
        self.cards = self.pristineCards[:]
        self.shuffleDeck()

    def shuffleDeck(self):
        shuffle(self.cards)

    def loadFromFile(self):
        filename = promptLoadFile('Open Deck File',
                                  'Text-formatted deck file (*.txt)')
        if not filename:
            return
        with open(filename) as f:
            data = f.read()
        for item in data.split("\n"):
            if len(item) > 0:
                for i in range(int(item.split()[0])):
                    self.deckDisplay.addItem(" ".join(item.split()[1:]))
コード例 #5
0
 def __init__(self, parent, mappewidget):
     QListWidget.__init__(self)
     self.setSelectionMode(QAbstractItemView.ExtendedSelection)
     self.mappewidget = mappewidget
コード例 #6
0
class diceRoller(QDockWidget):
    def __init__(self, mainWindow):
        super(QDockWidget, self).__init__(mainWindow)
        self.setWindowTitle(self.tr("Dice"))
        self.realwidget = QWidget(
            mainWindow
        )  #I messed up on the initial setup and was too lazy to rename everything.
        self.widget = QGridLayout()
        self.diceArea = QListWidget(mainWindow)
        try:
            self.load(jsonload(ospath.join(SAVE_DIR, "dice.rgd")))
        except:
            self.macros = [
                QListWidgetItem(QIcon('data/dice.png'), "Sample: 2d6"),
                QListWidgetItem(QIcon('data/dice.png'), "Sample: 4k2"),
                QListWidgetItem(QIcon('data/dice.png'), "Sample: 1dn3")
            ]
        for m in self.macros:
            self.diceArea.addItem(m)
        self.diceArea.currentRowChanged.connect(self.changeCurrentMacro)
        self.rollbutton = QPushButton(self.tr("Roll"), mainWindow)
        self.rollbutton.setToolTip(
            self.tr("Roll dice according to the selected macro."))
        self.addmacrobutton = QPushButton(self.tr("Add Macro"), mainWindow)
        self.addmacrobutton.setToolTip(
            self.tr("Add a new macro via a dialog box."))
        self.removemacrobutton = QPushButton(self.tr("Delete Macro"),
                                             mainWindow)
        self.removemacrobutton.setToolTip(
            self.tr("Remove the currently selected macro."))
        self.rollbutton.clicked.connect(self.rollDice)
        self.addmacrobutton.clicked.connect(self.summonMacro)
        self.removemacrobutton.clicked.connect(self.removeCurrentMacro)
        self.widget.addWidget(self.diceArea, 0, 0)
        self.widget.addWidget(self.rollbutton, 1, 0)
        self.widget.addWidget(self.addmacrobutton, 2, 0)
        self.widget.addWidget(self.removemacrobutton, 3, 0)
        self.realwidget.setLayout(self.widget)
        self.setWidget(self.realwidget)
        self.setObjectName("Dice Widget")
        mainWindow.addDockWidget(Qt.BottomDockWidgetArea, self)
        self.close()
        self.currentMacro = -1

    def changeCurrentMacro(self, n):
        self.currentMacro = n

    def rollDice(self):
        current = self.diceArea.item(self.currentMacro)
        if current is not None:
            text = UNICODE_STRING(current.text())
            self.rollRequested.emit(text[text.rfind(':') + 1:])

    def _addMacro(self, macro):
        self.macros.append(QListWidgetItem(QIcon('data/dice.png'), macro))
        self.diceArea.addItem(self.macros[len(self.macros) - 1])

    def addMacro(self, mac, macname):
        self.macros.append(
            QListWidgetItem(QIcon('data/dice.png'), macname + ': ' + mac))
        self.diceArea.addItem(self.macros[len(self.macros) - 1])
        jsondump(self.dump(), ospath.join(SAVE_DIR, "dice.rgd"))

    def removeCurrentMacro(self):
        if self.diceArea.item(self.currentMacro) != self.diceArea.currentItem(
        ):  #This SHOULD, probably, only occur if there are two items and the first is deleted. Probably.
            self.diceArea.takeItem(0)
            return
        self.diceArea.takeItem(self.currentMacro)
        jsondump(self.dump(), ospath.join(SAVE_DIR, "dice.rgd"))

    def summonMacro(self):
        self.macroRequested.emit()

    def load(self, obj):
        """Deserialize set of macros from a dictionary."""
        self.macros = []
        macroz = loadObject('diceRoller.macros', obj.get('macros'))
        for ID, macro in list(macroz.items()):
            self._addMacro(macro)

    def dump(self):
        """Serialize to an object valid for JSON dumping."""

        macroz = []
        for i in range(0, self.diceArea.count()):
            macroz.append(UNICODE_STRING(self.diceArea.item(i).text()))

        return dict(macros=dict([(i, macro)
                                 for i, macro in enumerate(macroz)]))

    rollRequested = signal(BASE_STRING,
                           doc="""Called when the roll button is hit.

		roll -- the dice to be rolled

		""")

    macroRequested = signal(
        doc="""Called when the add macro button is pressed.""")