Exemplo n.º 1
0
    def __init__(self):
        self.screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
        self.clock = pygame.time.Clock()

        self.text_manager = TextManager()
        self.blurb = Blurb(self.text_manager.create_random_blurb())
        self.stat_manager = StatisticsManager()
        self.keyboard = Keyboard()
        self.input_manager = InputManager(self)
        self.input_box = InputBox()

        self.running = False
        self.first_run = True
Exemplo n.º 2
0
    def __init__(self, *args):
        super(TyperWindow, self).__init__(*args)

        self.setWindowTitle("Amphetype")
        tabs = QTabWidget()

        quiz = Quizzer()

        tabs.addTab(quiz, "Typer")

        tm = TextManager()
        self.connect(quiz, SIGNAL("wantText"), tm.nextText)
        self.connect(tm, SIGNAL("setText"), quiz.setText)
        self.connect(tm, SIGNAL("gotoText"), lambda: tabs.setCurrentIndex(0))
        self.connect(quiz, SIGNAL("newReview"), tm.newReview)
        self.connect(quiz, SIGNAL("lastText"), tm.lastText)

        tabs.addTab(tm, "Sources")

        ph = PerformanceHistory()
        self.connect(tm, SIGNAL("refreshSources"), ph.refreshSources)
        self.connect(quiz, SIGNAL("statsChanged"), ph.updateData)
        self.connect(ph, SIGNAL("setText"), quiz.setText)
        self.connect(ph, SIGNAL("gotoText"), lambda: tabs.setCurrentIndex(0))
        tabs.addTab(ph, "Performance")

        st = StringStats()
        self.connect(st, SIGNAL("lessonStrings"),
                     lambda x: tabs.setCurrentIndex(4))
        tabs.addTab(st, "Analysis")

        lg = LessonGenerator()
        self.connect(st, SIGNAL("lessonStrings"), lg.addStrings)
        self.connect(lg, SIGNAL("newLessons"), lambda: tabs.setCurrentIndex(1))
        self.connect(lg, SIGNAL("newLessons"), tm.addTexts)
        self.connect(quiz, SIGNAL("wantReview"), lg.wantReview)
        self.connect(lg, SIGNAL("newReview"), tm.newReview)
        tabs.addTab(lg, "Lesson Generator")

        dw = DatabaseWidget()
        tabs.addTab(dw, "Database")

        pw = PreferenceWidget()
        tabs.addTab(pw, "Preferences")

        ab = AboutWidget()
        tabs.addTab(ab, "About/Help")

        self.setCentralWidget(tabs)

        tm.nextText()
Exemplo n.º 3
0
    def __init__(self, *args):
        super(TyperWindow, self).__init__(*args)

        self.setWindowTitle("Amphetype")
        tabs = QTabWidget()

        quiz = Quizzer()

        tabs.addTab(quiz, "Typer")

        tm = TextManager()
        self.connect(quiz, SIGNAL("wantText"), tm.nextText)
        self.connect(tm, SIGNAL("setText"), quiz.setText)
        self.connect(tm, SIGNAL("gotoText"), lambda: tabs.setCurrentIndex(0))
        self.connect(quiz, SIGNAL("newReview"), tm.newReview)
        self.connect(quiz, SIGNAL("lastText"), tm.lastText)

        tabs.addTab(tm, "Sources")

        ph = PerformanceHistory()
        self.connect(tm, SIGNAL("refreshSources"), ph.refreshSources)
        self.connect(quiz, SIGNAL("statsChanged"), ph.updateData)
        self.connect(ph, SIGNAL("setText"), quiz.setText)
        self.connect(ph, SIGNAL("gotoText"), lambda: tabs.setCurrentIndex(0))
        tabs.addTab(ph, "Performance")

        st = StringStats()
        self.connect(st, SIGNAL("lessonStrings"), lambda x: tabs.setCurrentIndex(4))
        tabs.addTab(st, "Analysis")

        lg = LessonGenerator()
        self.connect(st, SIGNAL("lessonStrings"), lg.addStrings)
        self.connect(lg, SIGNAL("newLessons"), lambda: tabs.setCurrentIndex(1))
        self.connect(lg, SIGNAL("newLessons"), tm.addTexts)
        self.connect(quiz, SIGNAL("wantReview"), lg.wantReview)
        self.connect(lg, SIGNAL("newReview"), tm.newReview)
        tabs.addTab(lg, "Lesson Generator")

        dw = DatabaseWidget()
        tabs.addTab(dw, "Database")

        pw = PreferenceWidget()
        tabs.addTab(pw, "Preferences")

        ab = AboutWidget()
        tabs.addTab(ab, "About/Help")

        self.setCentralWidget(tabs)

        tm.nextText()
    def importTextManager(self, filePath):
        '''
			Method called to istanciate the start the manager
		'''
        from TextManager import TextManager
        self.textManager = TextManager(filePath)
Exemplo n.º 5
0
 def store_text(self, *args) -> None:
     self.master.text_manager = TextManager(self.path.get())
     self.master.switch_frame(OptionPage)
Exemplo n.º 6
0
    def __init__(self, *args):
        super(TyperWindow, self).__init__(*args)

        self.setWindowTitle("Amphetype")
        self.updatePalette()

        update_palette_change_signals = [
            "main_text_color", "widgets_background_color",
            "widgets_text_color", "main_background_color",
            'main_text_area_color', "main_borders_color"
        ]

        for change_signal in update_palette_change_signals:
            self.connect(Settings, SIGNAL("change_{0}".format(change_signal)),
                         self.updatePalette)

        tabs = QTabWidget()

        quiz = Quizzer()
        tabs.addTab(quiz, "Typer")

        tm = TextManager()
        self.connect(quiz, SIGNAL("wantText"), tm.nextText)
        self.connect(tm, SIGNAL("setText"), quiz.setText)
        self.connect(tm, SIGNAL("gotoText"), lambda: tabs.setCurrentIndex(0))
        tabs.addTab(tm, "Sources")

        ph = PerformanceHistory()
        self.connect(tm, SIGNAL("refreshSources"), ph.refreshSources)
        self.connect(quiz, SIGNAL("statsChanged"), ph.updateData)
        self.connect(ph, SIGNAL("setText"), quiz.setText)
        self.connect(ph, SIGNAL("gotoText"), lambda: tabs.setCurrentIndex(0))
        tabs.addTab(ph, "Performance")

        st = StringStats()
        self.connect(st, SIGNAL("lessonStrings"),
                     lambda x: tabs.setCurrentIndex(4))
        tabs.addTab(st, "Analysis")

        lg = LessonGenerator()
        self.connect(st, SIGNAL("lessonStrings"), lg.addStrings)
        self.connect(lg, SIGNAL("newLessons"), lambda: tabs.setCurrentIndex(1))
        self.connect(lg, SIGNAL("newLessons"), tm.addTexts)
        self.connect(quiz, SIGNAL("wantReview"), lg.wantReview)
        self.connect(lg, SIGNAL("newReview"), tm.newReview)
        tabs.addTab(lg, "Lesson Generator")

        pw = PreferenceWidget()
        pw_scroll = QScrollArea()
        pw_scroll.setWidget(pw)
        tabs.addTab(pw_scroll, "Preferences")

        dw = DatabaseWidget()
        tabs.addTab(dw, "Database")

        ab = AboutWidget()
        tabs.addTab(ab, "About/Help")

        self.setCentralWidget(tabs)

        tm.nextText()
Exemplo n.º 7
0
class Type():
    """ Main game class, contains game loop """

    pygame.init()
    pygame.font.init()
    pygame.display.set_caption('Typing Test')

    os.environ['SDL_VIDEO_WINDOW_POS'] = "%d, %d" % (WINDOW_X, WINDOW_Y)

    def __init__(self):
        self.screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
        self.clock = pygame.time.Clock()

        self.text_manager = TextManager()
        self.blurb = Blurb(self.text_manager.create_random_blurb())
        self.stat_manager = StatisticsManager()
        self.keyboard = Keyboard()
        self.input_manager = InputManager(self)
        self.input_box = InputBox()

        self.running = False
        self.first_run = True

    """ GAME LOGIC """

    def setup_game(self):
        """ Initialises game variables. """

        self.running = False
        self.main_loop()

    def start_game(self):
        """ Resets stats and starts a new game. """

        self.running = True

        if self.first_run:
            self.first_run = False
        elif not self.first_run:
            self.reset_game()

        self.stat_manager.timer.start()

    def stop_game(self):
        """ Stops the current game, halts timer, DOESN'T reset. """

        self.stat_manager.timer.stop()
        self.running = False

    def reset_game(self):
        """ Resets game variables to run again, for multiple games. """

        self.blurb.__init__(self.text_manager.create_random_blurb())
        self.stat_manager.reset()

    def main_loop(self):
        """ Main game loop. """

        while True:
            self.clock.tick(FPS)

            # check finished
            if self.running:

                if self.stat_manager.check_timer():
                    self.stop_game()

                if self.blurb.finished:
                    self.stop_game()

            # updates
            self.input_manager.handle_events()
            self.keyboard.update()
            self.blurb.update()
            self.input_box.update(self.blurb.current_word_typed)
            self.stat_manager.update(self.blurb.completed_word_count,
                                     self.blurb.results)

            # draw
            self.screen.fill(BG_COLOR)
            lower_bound = self.draw_blurb_box()
            self.draw_input_box(lower_bound)
            self.draw_stats()
            self.draw_keyboard()

            # print(str(int(self.clock.get_fps())))

            pygame.display.update()

    """ DRAWING """

    def draw_blurb_box(self):
        """ Draw the blurb. """

        self.screen.blit(self.blurb.draw(),
                         (SCREEN_WIDTH / 2 - self.blurb.width / 2, 30))

        return self.blurb.height + 30

    def draw_input_box(self, blurb_lower_bound):
        """ Draw the input box just under blurb. """

        blurb_lower_bound_y = blurb_lower_bound

        self.screen.blit(self.input_box.draw(),
                         (SCREEN_WIDTH / 2 - self.input_box.width / 2,
                          blurb_lower_bound_y + 5))

    def draw_stats(self):
        """ Draws all stats.  Stats manages wpm / timer / accuracy. """

        self.screen.blit(self.stat_manager.draw(),
                         (SCREEN_WIDTH - SCREEN_WIDTH / 8,
                          SCREEN_HEIGHT - 7 * SCREEN_HEIGHT / 8))

    def draw_keyboard(self):
        """ Draws the on screen keyboard. """

        self.screen.blit(self.keyboard.draw(),
                         (SCREEN_WIDTH / 2 - self.keyboard.width / 2,
                          SCREEN_HEIGHT - 3 * SCREEN_HEIGHT / 8))

    """ UTILITIES """
Exemplo n.º 8
0
    def __init__(self):
        Gtk.Window.__init__(self)
        self.set_title("Amphetype")

        notebook = Gtk.Notebook()
        self.add(notebook)

        quiz = Quizzer()
        notebook.append_page(quiz, Gtk.Label.new("Typer"))

        textm = TextManager()
        notebook.append_page(textm, Gtk.Label.new("Sources"))
        quiz.connect("want-text", lambda _: textm.next_text())
        textm.connect("set-text", lambda _, *text: quiz.set_target(text))
        textm.connect("go-to-text", lambda _: notebook.set_current_page(0))

        perf = PerformanceHistory()
        notebook.append_page(perf, Gtk.Label.new("Performance"))
        textm.connect("refresh-sources", lambda _: perf.refresh_sources())
        quiz.connect("stats-changed", lambda _: perf.update_data())
        perf.connect("set-text", lambda *text: quiz.set_target(text))
        perf.connect("go-to-text", lambda _: notebook.set_current_page(0))

        stats = StringStats()
        notebook.append_page(stats, Gtk.Label.new("Analysis"))
        # stats.connect("lesson-strings", lambda _: notebook.set_current_page(4))

        lgen = LessonGenerator()
        notebook.append_page(lgen, Gtk.Label.new("Lesson Generator"))
        # stats.connect("lesson-strings", lgen.add_strings)
        lgen.connect("new-lessons", lambda _, _2: notebook.set_current_page(1))
        lgen.connect("new-lessons", textm.add_texts)
        # quiz.connect("want-review", ...)
        lgen.connect("new-review", textm.new_review)

        dbase = DatabaseWidget()
        notebook.append_page(dbase, Gtk.Label.new("Database"))

        pref = PreferenceWidget()
        notebook.append_page(pref, Gtk.Label.new("Preferences"))

        textm.next_text()
Exemplo n.º 9
0
    output_file = open(filename, 'w')
    for i in range(len(result_lines)):
        if i != len(result_lines) - 1:
            output_file.write(result_lines[i] + '\n')
        else:
            output_file.write(result_lines[i])

if (len(sys.argv) < 4):
    print("Missing arguments. Please pass the <input_file> <output_file> <paper_type: A3 or A4>")
    exit()
if (sys.argv[3] not in ["A3", "A4"]):
    print("Incorrect paper_type. Please use either A3 or A4")
    exit()
try:
    input_file = open(sys.argv[1], 'r')
except (OSError, IOError) as e:
    print("Input file not found.")
    exit()
page_type = sys.argv[3]
char_width = 2
char_height = 3
width = (210 / char_width) + 1
height = (297 / char_height) + 1
if (page_type == "A3"):
    width = (297 / char_width) + 1
    height = (420 / char_height) + 1

text_manager = TextManager(input_file.read(), width, height)
result = text_manager.process_text()
store_result(sys.argv[2], result)
Exemplo n.º 10
0
 def ass_to_meluk(self, route: str):
     file = TextManager.reader(route)
     return file