Пример #1
0
class TetrisView(QWidget):

    GAME = 1

    def __init__(self, signalController, status_bar):
        super().__init__()

        self.signalController = signalController
        self.statusBar = status_bar
        self.initUI()

    def initUI(self):
        """
        Init app

        """
        vbox = QVBoxLayout()
        hbox = QHBoxLayout()

        # Create button "back to the menu"
        self._buttonBack = QPushButton(QIcon(PATH_IMAGE_BACK_NEDDLE), "", self)
        self._buttonBack.clicked.connect(self.signalController.back2menu)
        self._buttonBack.setFixedSize(60, 30)
        vbox.addWidget(self._buttonBack, 0, QtCore.Qt.AlignTop)

        self.tboard = Board(self)

        # Create button which restart game
        self._restartGame = QPushButton(QIcon(PATH_IMAGE_RELOAD), "", self)
        self._restartGame.clicked.connect(self.tboard.start)
        self._restartGame.setFixedSize(60, 30)
        vbox.addWidget(self._restartGame, 1, QtCore.Qt.AlignTop)

        # Create label "Score"
        self._labelScore = QLabel("Game Score", self)
        vbox.addWidget(self._labelScore, 2, QtCore.Qt.AlignBottom)

        # Create score counter
        self._score = QLCDNumber(self)
        self._score.setFixedSize(70, 50)
        vbox.addWidget(self._score, 3, QtCore.Qt.AlignTop)

        hbox.addLayout(vbox, 0)
        hbox.addWidget(self.tboard, 1)

        self.setLayout(hbox)
        self.setWindowTitle("TetrisView")

        self.tboard.msg2StatusBar[str].connect(self._score.display)

    def switcher(self):
        self.tboard.start()
        self.signalController.sgn2stacked.emit(int(self.GAME))
Пример #2
0
class Indicator(QWidget):
    def __init__(self, unit):
        super().__init__()
        self.unit = ALabel(unit)
        self.lcd = QLCDNumber(6)
        self._initLayout()

    def _initLayout(self):
        self.setMinimumHeight(60)
        hLayout = AHBoxLayout()
        hLayout.addWidget(self.lcd)
        hLayout.addWidget(self.unit)
        self.setLayout(hLayout)

    def display(self, value: float):
        self.lcd.display(str(value))
Пример #3
0
    def __init__(self):
        super().__init__()

        # Create Widgets
        self.question = QLabel(Text="Press Start",
                               Alignment=QtCore.Qt.AlignCenter,
                               Font=QtGui.QFont("", 30))

        self.label_correct = QLabel(Alignment=QtCore.Qt.AlignCenter)

        self.button_quit = QPushButton("Quit", Visible=False)
        self.button_start = QPushButton("Start")
        lcd_height = 40
        self.lcd_total = QLCDNumber(SegmentStyle=QLCDNumber.Flat, FixedHeight=lcd_height)
        self.lcd_score = QLCDNumber(SegmentStyle=QLCDNumber.Flat, FixedHeight=lcd_height)

        self.stack = QStackedWidget()
        self.page1 = Page1Widget()
        self.page2 = Page2Widget()
        self.page3 = Page3Widget()
        self.stack.addWidget(self.page1)
        self.stack.addWidget(self.page2)
        self.stack.addWidget(self.page3)

        # Make Layout
        self.layout = QGridLayout(self)
        self.layout.addWidget(self.question, 2, 0, 1, 2)
        self.layout.addWidget(self.label_correct, 1, 0, 1, 2)
        self.layout.addWidget(self.lcd_total, 0, 0)
        self.layout.addWidget(self.lcd_score, 0, 1)
        self.layout.addWidget(self.stack, 3, 0, 1, 2)
        self.layout.addWidget(self.button_quit, 4, 0)
        self.layout.addWidget(self.button_start, 4, 1)

        # Connect Callbacks
        self.button_quit.clicked.connect(self.on_quit_pressed)
        self.button_start.clicked.connect(self.on_start_pressed)
        self.page2.ans_buttons[0].clicked.connect(self.on_ans_button0_clicked)
        self.page2.ans_buttons[1].clicked.connect(self.on_ans_button1_clicked)
        self.page2.ans_buttons[2].clicked.connect(self.on_ans_button2_clicked)
        self.page3.line_edit.returnPressed.connect(self.on_answer_given)
Пример #4
0
    def initUI(self):
        lcd = QLCDNumber(self)
        sld = QSlider(Qt.Horizontal, self)

        vbox = QVBoxLayout()
        vbox.addWidget(lcd)
        vbox.addWidget(sld)

        self.setLayout(vbox)
        sld.valueChanged.connect(lcd.display)

        self.setGeometry(300, 300, 250, 250)
        self.setWindowTitle("Signal & slot")
        self.show()
Пример #5
0
    def initUI(self):

        lcd = QLCDNumber(self)
        sld = QSlider(Qt.Horizontal, self)
        is_binary = QRadioButton("is binary?", self)

        vbox = QVBoxLayout()
        vbox.addWidget(lcd)
        vbox.addWidget(sld)
        vbox.addWidget(is_binary)

        self.setLayout(vbox)
        # sld.setRange(0, 10)
        sld.setMaximum(1000)
        sld.setMinimum(-100)

        sld.valueChanged.connect(lcd.display)
        is_binary.toggled.connect(self.switch_binary)

        self.setGeometry(300, 300, 250, 150)
        self.setWindowTitle('EXample 6')
        self.show()
Пример #6
0
 def __init__(self, unit):
     super().__init__()
     self.unit = ALabel(unit)
     self.lcd = QLCDNumber(6)
     self._initLayout()
Пример #7
0
class MainWidget(QWidget):
    data = None
    current_question = None
    current_correct_answer = None
    buttons_choices = None
    question_mode = None
    answer_mode = None
    correct_questions = 0
    total_questions = 0

    def __init__(self):
        super().__init__()

        # Create Widgets
        self.question = QLabel(Text="Press Start",
                               Alignment=QtCore.Qt.AlignCenter,
                               Font=QtGui.QFont("", 30))

        self.label_correct = QLabel(Alignment=QtCore.Qt.AlignCenter)

        self.button_quit = QPushButton("Quit", Visible=False)
        self.button_start = QPushButton("Start")
        lcd_height = 40
        self.lcd_total = QLCDNumber(SegmentStyle=QLCDNumber.Flat, FixedHeight=lcd_height)
        self.lcd_score = QLCDNumber(SegmentStyle=QLCDNumber.Flat, FixedHeight=lcd_height)

        self.stack = QStackedWidget()
        self.page1 = Page1Widget()
        self.page2 = Page2Widget()
        self.page3 = Page3Widget()
        self.stack.addWidget(self.page1)
        self.stack.addWidget(self.page2)
        self.stack.addWidget(self.page3)

        # Make Layout
        self.layout = QGridLayout(self)
        self.layout.addWidget(self.question, 2, 0, 1, 2)
        self.layout.addWidget(self.label_correct, 1, 0, 1, 2)
        self.layout.addWidget(self.lcd_total, 0, 0)
        self.layout.addWidget(self.lcd_score, 0, 1)
        self.layout.addWidget(self.stack, 3, 0, 1, 2)
        self.layout.addWidget(self.button_quit, 4, 0)
        self.layout.addWidget(self.button_start, 4, 1)

        # Connect Callbacks
        self.button_quit.clicked.connect(self.on_quit_pressed)
        self.button_start.clicked.connect(self.on_start_pressed)
        self.page2.ans_buttons[0].clicked.connect(self.on_ans_button0_clicked)
        self.page2.ans_buttons[1].clicked.connect(self.on_ans_button1_clicked)
        self.page2.ans_buttons[2].clicked.connect(self.on_ans_button2_clicked)
        self.page3.line_edit.returnPressed.connect(self.on_answer_given)

    def update_questions_from_selection(self):
        selected_groups = []
        for i in range(self.page1.list_groups.count()):
            item = self.page1.list_groups.item(i)
            if item.checkState():
                selected_groups.append(item.text())
        if len(selected_groups) == 0:
            self.data = data
        else:
            self.data = data.loc[data['Group'].isin(selected_groups), :]

    def on_quit_pressed(self):
        self.button_start.setVisible(True)
        self.button_quit.setVisible(False)
        self.question.clear()
        self.stack.setCurrentIndex(0)

    def on_start_pressed(self):
        self.update_questions_from_selection()
        self.button_start.setVisible(False)
        self.button_quit.setVisible(True)
        self.total_questions = -1
        self.correct_questions = 0
        self.stack.setCurrentIndex(int(self.page1.spinbox_level.text()))
        self.question_mode = MODES[self.page1.dropdown_quest.currentIndex()]
        self.answer_mode = MODES[self.page1.dropdown_ans.currentIndex()]
        self.update_question()

    def update_score(self):
        self.lcd_total.display(self.total_questions)
        self.lcd_score.display(self.correct_questions)

    def get_also_string(self):
        also_mode = self.page1.dropdown_also.currentText()
        if also_mode == "----":
            return ""
        return self.current_question[also_mode]

    def update_question(self):
        self.total_questions += 1
        self.update_score()
        picked_questions = self.data.sample(frac=1).iloc[:3]
        self.current_question = picked_questions.iloc[0]
        self.current_correct_answer = self.current_question[self.answer_mode]
        also_string = "   " + self.get_also_string()
        self.question.setText(self.current_question[self.question_mode] + also_string)

        self.buttons_choices = list(picked_questions[self.answer_mode])
        random.shuffle(self.buttons_choices)
        for button, answer in zip(self.page2.ans_buttons, self.buttons_choices):
            button.setText(answer)

    def correct_answer(self):
        self.correct_questions += 1
        self.label_correct.setText("Correct!")
        self.label_correct.setStyleSheet("QLabel { background-color : green;}")

    def wrong_answer(self):
        wrong_string = (f"Wrong: {self.current_question[self.question_mode]} "
                        f"= {self.current_correct_answer}")
        self.label_correct.setText(wrong_string)
        self.label_correct.setStyleSheet("QLabel { background-color : red;}")

    def on_answer_given(self):
        given_answer = self.page3.line_edit.text()
        if given_answer == self.current_correct_answer:
            self.correct_answer()
        else:
            self.wrong_answer()
        self.question.setText(self.page3.line_edit.text())
        self.page3.line_edit.clear()
        self.update_question()

    def after_button_clicked(self, ans_id):
        if self.buttons_choices[ans_id] == self.current_correct_answer:
            self.correct_answer()
        else:
            self.wrong_answer()
        self.update_question()

    def on_ans_button0_clicked(self):
        self.after_button_clicked(0)

    def on_ans_button1_clicked(self):
        self.after_button_clicked(1)

    def on_ans_button2_clicked(self):
        self.after_button_clicked(2)