Esempio n. 1
0
    def __init__(self):
        super().__init__()
        self.setStyleSheet("QWidget { background-color: black }")
        self.setFixedSize(Snake.BOARD_WIDTH, Snake.BOARD_HEIGHT)
        self.game_active = True
        self.timer = QtCore.QBasicTimer()
        self.direction = Snake.RIGHT
        # each tuple (x, y) corresponds to the top left corner of the block (circle)
        self.snake_coords = deque()
        self.snake_coords.append((Snake.BLOCK_SIZE * Snake.NUM_BLOCKS_X // 2,
                                  Snake.BLOCK_SIZE * Snake.NUM_BLOCKS_Y // 2))
        self.food = None
        self.new_food()

        self.score_sound = QtMultimedia.QSound("score.wav")

        self.start_button = QtWidgets.QPushButton("Start", self)
        self.start_button.setStyleSheet("QWidget { background-color: white }")
        self.start_button.move(self.geometry().center() - self.start_button.geometry().center())
        self.start_button.clicked.connect(self.start_game)
        self.game_over_label = QtWidgets.QLabel("Game Over...", self)
        self.game_over_label.setStyleSheet("QLabel {color: yellow; font: 36pt}")
        self.game_over_label.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        self.game_over_label.adjustSize()
        self.game_over_label.move((self.width() - self.game_over_label.width()) // 2, 0)
        self.game_over_label.hide()

        self.setWindowTitle("Snake game")
        self.show()
Esempio n. 2
0
 def startPlayWidget(self):
     self.SelectWidget = ModuleSelectorWidget("Play", self)
     self.setWindowTitle("Scales - Play: Select")
     self.setCentralWidget(self.SelectWidget)
     self.ToolBar.setVisible(True)
     sound = QtMultimedia.QSound("sounds/blip1.wav")
     sound.play()
     self.show()
Esempio n. 3
0
 def backAction(self):
     sound = QtMultimedia.QSound("sounds/blip1.wav")
     sound.play()
     curr_class = str(type(self.centralWidget()))
     #print(curr_class) #For Debugging Purposes
     if (curr_class == "<class 'PlayModule.PlayWidget'>"):
         self.startPlayWidget()
     elif (curr_class == "<class 'LearnModule.LearnWidget'>"):
         self.startLearnWidget()
     else:  #Default to main menu
         self.startHomeWidget()
Esempio n. 4
0
    def operate(self):
        wrong = False
        try:
            if (self.operand == "+"):
                wrong = (int(self.numLeft.text()) +
                         int(self.numRight.text())) != int(
                             self.TextInput.text())
            elif (self.operand == "-"):
                wrong = (int(self.numLeft.text()) -
                         int(self.numRight.text())) != int(
                             self.TextInput.text())
            elif (self.operand == "*"):
                wrong = (int(self.numLeft.text()) *
                         int(self.numRight.text())) != int(
                             self.TextInput.text())
            elif (self.operand == "/"):
                wrong = (int(
                    int(self.numLeft.text()) /
                    int(self.numRight.text()))) != int(self.TextInput.text())
        except ValueError:
            sound = QtMultimedia.QSound("sounds/wrong.wav")
            sound.play()
            self.showMessageBox(
                "Invalid input. Please use numerical characters to input integers."
            )
            return

        if (wrong):
            sound = QtMultimedia.QSound("sounds/wrong.wav")
            sound.play()
            self.showMessageBox("Incorrect, please try again.")
        else:
            sound = QtMultimedia.QSound("sounds/correct.wav")
            sound.play()
            self.showMessageBox("Nice job! You got it!")
            self.TextInput.clear()
            self.shuffle()
Esempio n. 5
0
else:
    DEBUG = False

DEFAULT_WORK_TIME = 25 * 60  # s
DEFAULT_REST_TIME = 5 * 60  # s
DEFAULT_TARGET_TIME = 3 * 60 * 60  # s

if DEBUG:
    DEFAULT_WORK_TIME = 3  # s
    DEFAULT_REST_TIME = 3  # s
    DEFAULT_TARGET_TIME = 10  # s

MIN_WORTH_SAVING = 30  # s

if DEBUG:
    MIN_WORTH_SAVING = 1  # s

RED_BACKGROUND = QtGui.QColor(255, 150, 150)
GREEN_BACKGROUND = QtGui.QColor(150, 255, 150)
BLUE_BACKGROUND = QtGui.QColor(200, 200, 255)
WHITE_BACKGROUND = QtGui.QColor(255, 255, 255)

START_ALARM_PATH = "start.wav"
END_ALARM_PATH = "end.wav"

ALERTS = {
    'happy': QtMultimedia.QSound(END_ALARM_PATH),
    'sad': QtMultimedia.QSound(START_ALARM_PATH)
}

DELTA_T = 0.01
Esempio n. 6
0
 def play(self):
     sound_file = "icons/bell.wav"
     QtMultimedia.QSound(sound_file).play()
Esempio n. 7
0
    def __init__(self, screen_res, app):
        super(Keyboard, self).__init__(screen_res)

        self.app = app
        self.is_simulation = False
        self.pretrain_window = False

        # 2 is turn fully on, 1 is turn on but reduce, 0 is turn off
        self.word_pred_on = 2
        # Number of word clocks to display in case word prediction == 1 (reduced)
        self.reduce_display = 5

        # get user data before initialization
        self.gen_data_handel()

        self.up_handel = PickleUtil(
            os.path.join(self.user_handel, 'user_preferences.p'))
        user_preferences = self.up_handel.safe_load()
        if user_preferences is None:
            first_load = True
            user_preferences = [
                'default', 1, False, 'alpha', 'off', config.default_rotate_ind,
                True
            ]
            self.up_handel.safe_save(user_preferences)
        else:
            first_load = False

        self.clock_type, self.font_scale, self.high_contrast, self.layout_preference, self.pf_preference, \
            self.start_speed, self.is_write_data = user_preferences

        self.phrase_prompts = False  # set to true for data collection mode

        if self.phrase_prompts:
            self.phrases = Phrases(
                "resources/twitter-phrases/watch-combined.txt")

        else:
            self.phrases = None

        if self.layout_preference == 'alpha':
            self.target_layout = kconfig.alpha_target_layout
            self.key_chars = kconfig.key_chars
        elif self.layout_preference == 'qwerty':
            self.target_layout = kconfig.qwerty_target_layout
            self.key_chars = kconfig.key_chars
        elif self.layout_preference == 'emoji':
            self.target_layout = kconfig.emoji_target_layout
            self.key_chars = kconfig.emoji_keys
            self.word_pred_on = 0

        # set up dictionary tree
        # splash = StartWindow(screen_res, True)
        self.pause_animation = False

        self.output_manager = outputManager()
        self.is_output_text = False

        self.lm_prefix = ""
        self.left_context = ""

        self.cwd = os.getcwd()

        word_lm_path = os.path.join(
            os.path.join(self.cwd, 'resources'),
            'mix4_opt_min_lower_100k_4gram_2.5e-9_prob8_bo4_compress255.kenlm')
        char_lm_path = os.path.join(
            os.path.join(self.cwd, 'resources'),
            'mix4_opt_min_lower_12gram_6e-9_prob9_bo4_compress255.kenlm')
        vocab_path = os.path.join(os.path.join(self.cwd, 'resources'),
                                  'vocab_lower_100k.txt')
        char_path = os.path.join(os.path.join(self.cwd, 'resources'),
                                 'char_set.txt')

        self.lm = LanguageModel(word_lm_path, char_lm_path, vocab_path,
                                char_path)

        # initialize pygame and joystick
        if kconfig.target_evt is kconfig.joy_evt:
            pygame.init()
            if pygame.joystick.get_count() < 1:
                # no joysticks found
                print("Please connect a joystick.\n")
                self.quit(None)
            else:
                # create a new joystick object from
                # ---the first joystick in the list of joysticks
                Joy0 = pygame.joystick.Joystick(0)
                # tell pygame to record joystick events
                Joy0.init()
            # start looking for events
            self.parent.after(0, self.find_events)
        # not in selection pause
        self.in_pause = False

        # determine keyboard positions
        self.init_locs()
        # get old data if there is such
        # Just for default. Loaded again when bc initializes
        self.rotate_index = config.default_rotate_ind
        # set up file handle for printing useful stuff
        self.undefined = False

        self.params_handle_dict = {
            'speed': [],
            'params': [],
            'start': [],
            'press': [],
            'choice': []
        }
        self.num_presses = 0

        self.params_handle_dict['params'].append(
            [config.period_li[config.default_rotate_ind], config.theta0])
        self.params_handle_dict['start'].append(time.time())

        self.gen_scale()
        self.pause_set = True
        # set up "typed" text
        self.typed = ""
        self.btyped = ""
        self.context = ""
        self.old_context_li = [""]
        self.last_add_li = [0]
        # set up "talked" text
        # self.talk_file = "talk.txt"
        self.sound_set = True
        self.press_lock = False
        self.press_lock_status = False

        # check for speech
        # talk_fid = open(self.talk_file, 'wb')
        # write words
        self.init_words()

        self.bars = kconfig.bars

        self.bc_init = False

        self.previous_undo_text = ''
        self.previous_winner = 0

        self.wpm_data = []
        self.decay_avg_wpm = 0
        self.wpm_time = 0
        self.error_data = []
        self.decay_avg_error = 1

        self.clear_text = False
        self.pretrain = False

        self.emoji_box_highlight = [-1, -1]
        self.init_ui()

        self.mainWidget.clockgrid_widget.update_word_clocks(self.words_li)

        sound_file = "icons/bell.wav"
        self.sound_player = QtMultimedia.QSound(sound_file)

        self.time_rotate = config.period_li[self.start_speed]
        # get language model results
        self.gen_word_prior(False)

        self.clock_spaces = np.zeros((len(self.clock_centers), 2))

        self.bc = BroderClocks(self)
        self.mainWidget.change_value(self.start_speed)

        self.bc.init_follow_up(self.word_score_prior)

        # draw histogram
        self.init_histogram()

        self.save_environment()

        self.consent = False

        if first_load:
            self.pretrain = True
            self.welcome = Pretraining(self, screen_res)

        # animate

        # record to prevent double tap
        self.last_key_press_time = time.time()
        self.last_release_time = time.time()

        self.update_radii = False
        self.on_timer()
Esempio n. 8
0
    def __init__(self, operation_selection, parent=None):
        super(PlayWidget, self).__init__(parent)

        sound = QtMultimedia.QSound("sounds/blip2.wav")
        sound.play()

        self.operand = operation_selection
        self.random = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

        textStyle = ("color: white; font-size: 60px;")
        solStyle = ("color: red; font-size: 65px;")

        # question widget
        self.numLeft = QtWidgets.QLabel(random.choice(self.random))
        self.op = QtWidgets.QLabel(self.operand)
        self.numRight = QtWidgets.QLabel(random.choice(self.random))
        self.eq = QtWidgets.QLabel("=")
        self.sol = QtWidgets.QLabel("?")

        self.numLeft.setStyleSheet(textStyle)
        self.op.setStyleSheet(textStyle)
        self.numRight.setStyleSheet(textStyle)
        self.eq.setStyleSheet(textStyle)
        self.sol.setStyleSheet(solStyle)

        # question layout
        self.QuestionLayout = QtWidgets.QHBoxLayout()
        self.QuestionLayout.addWidget(self.numLeft)
        self.QuestionLayout.addWidget(self.op)
        self.QuestionLayout.addWidget(self.numRight)
        self.QuestionLayout.addWidget(self.eq)
        self.QuestionLayout.addWidget(self.sol)
        self.QuestionLayout.setAlignment(QtCore.Qt.AlignCenter)

        #   input section
        self.TextInput = QtWidgets.QLineEdit()
        self.TextInput.setAlignment(QtCore.Qt.AlignCenter)
        self.TextInput.setStyleSheet(
            "color: white; padding: 30px 0px; font-size: 35px;")
        self.TextInput.returnPressed.connect(self.operate)
        self.submitButton = QtWidgets.QPushButton("Submit")
        self.submitButton.setStyleSheet(
            "background-color: green; color: white; padding: 15px 15px; font-size: 20px; border-radius: 10px;"
        )

        #   numpad input layout
        self.inputLayout = QtWidgets.QGridLayout()
        #self.inputLayout.setStyleSheet("background-color: #FFFFFF; opacity: 0.2; border-radius: 5px; border-color: black") #Style for numpad background
        self.inputLayout.addWidget(self.TextInput, 0, 0, 1, 2)
        self.inputLayout.addWidget(self.submitButton, 0, 2)
        self.submitButton.clicked.connect(self.operate)
        self.numPadButtons = [[
            QtWidgets.QPushButton('7'),
            QtWidgets.QPushButton('8'),
            QtWidgets.QPushButton('9')
        ],
                              [
                                  QtWidgets.QPushButton('4'),
                                  QtWidgets.QPushButton('5'),
                                  QtWidgets.QPushButton('6')
                              ],
                              [
                                  QtWidgets.QPushButton('1'),
                                  QtWidgets.QPushButton('2'),
                                  QtWidgets.QPushButton('3')
                              ],
                              [
                                  QtWidgets.QPushButton('+/-'),
                                  QtWidgets.QPushButton('0'),
                                  QtWidgets.QPushButton('DEL')
                              ]]
        for i in range(0, 4):
            for j in range(0, 3):
                self.numPadButtons[i][j].clicked.connect(
                    partial(self.enterNumber, self.numPadButtons[i][j].text()))
        for i in range(0, 4):
            for j in range(0, 3):
                self.numPadButtons[i][j].setStyleSheet(
                    "background-color: #002993; color: #FFFFFF; padding: 20px 20px; font-size: 35px; border-radius: 20px;"
                )
                self.inputLayout.addWidget(self.numPadButtons[i][j], i + 1, j)
        self.inputLayout.setVerticalSpacing(20)

        #   layout all widgets
        self.stack = QtWidgets.QVBoxLayout()
        self.stack.addLayout(self.QuestionLayout)
        self.stack.addLayout(self.inputLayout)
        self.setLayout(self.stack)

        self.shuffle(
        )  #Shuffle here to make sure that the operands are valid using shuffle's error checking