Exemplo n.º 1
0
    def __init__(self, parent=None):
        QDialog.__init__(self, parent)

        self.setWindowTitle('Mentor Drill')

        self.model = DrillModel(self)

        self.currentCard = Card()


        # card view
        self.cardView = CardMainView()


        # card list view
        self.cardListView = QListView(self)
        self.cardListView.setModel(self.model)
        self.cardListView.setMinimumWidth(200)
        self.cardListView.setFont(QFont("Fixed", 8))
        self.cardListView.setVisible(False)


        self.splitter = QSplitter(Qt.Horizontal)
        self.splitter.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.splitter.addWidget(self.cardView)
        self.splitter.addWidget(self.cardListView)
        self.splitter.setSizes([400, 200])


        # buttons bar
        self.buttons = QWidget(self)

        self.btnNext = QPushButton("&1. Next card")
        self.btnShowAnswer = QPushButton("&2. Show answer")
        self.btnGoodScore = QPushButton("&3. Good score")
        self.btnBadScore = QPushButton("&4. Bad score")
        self.btnShuffleCards = QPushButton("&5. Shuffle cards")
        self.btnPrintCards = QPushButton("&6. Print cards")
        self.btnClose = QPushButton("&7. Close")

        # todo move this to actions
        self.connect(self.btnNext, SIGNAL('clicked()'), self.on_btnNext_clicked)
        self.connect(self.btnShowAnswer, SIGNAL('clicked()'), self.on_btnShowAnswer_clicked)
        self.connect(self.btnGoodScore, SIGNAL('clicked()'), self.on_btnGoodScore_clicked)
        self.connect(self.btnBadScore, SIGNAL('clicked()'), self.on_btnBadScore_clicked)
        self.connect(self.btnShuffleCards, SIGNAL('clicked()'), self.on_btnShuffleCards_clicked)
        self.connect(self.btnPrintCards, SIGNAL('clicked()'), self.on_btnPrintCards_clicked)
        self.connect(self.btnClose, SIGNAL('clicked()'), self.on_btnClose_clicked)

        buttonsLayout = QHBoxLayout()

        buttonsLayout.addWidget(self.btnNext)
        buttonsLayout.addWidget(self.btnShowAnswer)
        buttonsLayout.addWidget(self.btnGoodScore)
        buttonsLayout.addWidget(self.btnBadScore)
        buttonsLayout.addWidget(self.btnShuffleCards)
        buttonsLayout.addWidget(self.btnPrintCards)
        buttonsLayout.addWidget(self.btnClose)

        self.buttons.setLayout(buttonsLayout)

        layout = QVBoxLayout()
        layout.setSpacing(1)
        layout.setMargin(1)
        layout.addWidget(self.splitter)
        layout.addWidget(self.buttons)
        self.setLayout(layout)

        self.setGeometry(100, 100, 500, 500)

        self.cardView.displayCard(self.currentCard)
Exemplo n.º 2
0
class DrillWindow(QDialog):
    def __init__(self, parent=None):
        QDialog.__init__(self, parent)

        self.setWindowTitle('Mentor Drill')

        self.model = DrillModel(self)

        self.currentCard = Card()


        # card view
        self.cardView = CardMainView()


        # card list view
        self.cardListView = QListView(self)
        self.cardListView.setModel(self.model)
        self.cardListView.setMinimumWidth(200)
        self.cardListView.setFont(QFont("Fixed", 8))
        self.cardListView.setVisible(False)


        self.splitter = QSplitter(Qt.Horizontal)
        self.splitter.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.splitter.addWidget(self.cardView)
        self.splitter.addWidget(self.cardListView)
        self.splitter.setSizes([400, 200])


        # buttons bar
        self.buttons = QWidget(self)

        self.btnNext = QPushButton("&1. Next card")
        self.btnShowAnswer = QPushButton("&2. Show answer")
        self.btnGoodScore = QPushButton("&3. Good score")
        self.btnBadScore = QPushButton("&4. Bad score")
        self.btnShuffleCards = QPushButton("&5. Shuffle cards")
        self.btnPrintCards = QPushButton("&6. Print cards")
        self.btnClose = QPushButton("&7. Close")

        # todo move this to actions
        self.connect(self.btnNext, SIGNAL('clicked()'), self.on_btnNext_clicked)
        self.connect(self.btnShowAnswer, SIGNAL('clicked()'), self.on_btnShowAnswer_clicked)
        self.connect(self.btnGoodScore, SIGNAL('clicked()'), self.on_btnGoodScore_clicked)
        self.connect(self.btnBadScore, SIGNAL('clicked()'), self.on_btnBadScore_clicked)
        self.connect(self.btnShuffleCards, SIGNAL('clicked()'), self.on_btnShuffleCards_clicked)
        self.connect(self.btnPrintCards, SIGNAL('clicked()'), self.on_btnPrintCards_clicked)
        self.connect(self.btnClose, SIGNAL('clicked()'), self.on_btnClose_clicked)

        buttonsLayout = QHBoxLayout()

        buttonsLayout.addWidget(self.btnNext)
        buttonsLayout.addWidget(self.btnShowAnswer)
        buttonsLayout.addWidget(self.btnGoodScore)
        buttonsLayout.addWidget(self.btnBadScore)
        buttonsLayout.addWidget(self.btnShuffleCards)
        buttonsLayout.addWidget(self.btnPrintCards)
        buttonsLayout.addWidget(self.btnClose)

        self.buttons.setLayout(buttonsLayout)

        layout = QVBoxLayout()
        layout.setSpacing(1)
        layout.setMargin(1)
        layout.addWidget(self.splitter)
        layout.addWidget(self.buttons)
        self.setLayout(layout)

        self.setGeometry(100, 100, 500, 500)

        self.cardView.displayCard(self.currentCard)


    def loadCards(self, cards):
        """Loads a list of cards to model."""
        for card in cards:
            self.model.addCard(card)
        self.currentCard = self.model.selectNextCard()
        self.cardView.displayCard(self.currentCard, True, False)

    def on_btnNext_clicked(self):
        self.currentCard = self.model.selectNextCard()
        self.cardView.displayCard(self.currentCard, True, False)

    def on_btnShowAnswer_clicked(self):
        self.cardView.displayCard(self.currentCard, True, True)

    def on_btnGoodScore_clicked(self):
        self.model.scoreCard(self.currentCard, DrillModel.Good)

    def on_btnBadScore_clicked(self):
        self.model.scoreCard(self.currentCard, DrillModel.Bad)

    def on_btnShuffleCards_clicked(self):
        self.model.shuffleCards()
        self.currentCard = self.model.selectNextCard()
        self.cardView.displayCard(self.currentCard, True, False)

    def on_btnPrintCards_clicked(self):
        self.model.printCards()

    def on_btnClose_clicked(self):
        self.close()

    def keyPressEvent(self, event):
        if event.key == Qt.Key_F8:
            self.cardListView.setVisible(not self.cardListView.visible())
            event.accept()
        else:
            event.ignore()

    def event(self, event):
        if isinstance(event, QKeyEvent) and event.key() == Qt.Key_F8:
            self.cardListView.setVisible(not self.cardListView.isVisible())
            return True
        return QDialog.event(self, event)