def main(language_set=None):
    """
    Begin an interactive annotation session, where you are played snippets of
    audio in different languages and you have to mark whether or not they are
    representative samples.
    """
    _validate_language_set(language_set)

    metadata = load_metadata(language_set=language_set)
    session = Session()

    ui.clear_screen()
    ui.pause('Beginning annotation, press ENTER to hear the first clip...')

    for segment in RandomSampler(metadata, DEFAULT_DURATION_S, MAX_PER_SAMPLE):
        ann, quit = annotate(segment, session.user, metadata)

        if ann is not None:
            save_annotation(segment.sample, ann, metadata)
            session.annotated += 1

        else:
            print('Skipping...')
            session.skipped += 1

        print()

        if quit:
            break

    session.summarize()
Example #2
0
def main(language_set=None):
    """
    Begin an interactive annotation session, where you are played snippets of
    audio in different languages and you have to mark whether or not they are
    representative samples.
    """
    _validate_language_set(language_set)

    metadata = load_metadata(language_set=language_set)
    session = Session()

    ui.clear_screen()
    ui.pause('Beginning annotation, press ENTER to hear the first clip...')

    for segment in RandomSampler(metadata, DEFAULT_DURATION_S,
                                 MAX_PER_SAMPLE):
        ann, quit = annotate(segment, session.user, metadata)

        if ann is not None:
            save_annotation(segment.sample, ann, metadata)
            session.annotated += 1

        else:
            print('Skipping...')
            session.skipped += 1

        print()

        if quit:
            break

    session.summarize()
Example #3
0
File: ctv.py Project: michailf/ctv
def loop(favs):
    global currtab
    f = favs[currtab]
    list = etvapi.get_bookmarks(f['id'])

    while True:
        ui.clear_screen()
        print_tabs(favs)
        ui.print_list(list)
        ch = ui.getch()

        if ch in ['0', 'q']:
            break

        if ch > '0' and ch < '5':
            currtab, f, list = switch_favorites_tab(favs, ch)
            continue

        if ch != '\r':
            ui.move(list, ch)
            continue

        if list[ui.curr]['type'] == 'MediaObject':
            play_single_video(list[ui.curr])
        else:
            play_all_container(list)
Example #4
0
File: ctv.py Project: serge-v/ctv
def loop(favs):
	global currtab
	f = favs[currtab]
	list = etvapi.get_bookmarks(f['id'])

	while True:
		ui.clear_screen()
		print_tabs(favs)
		ui.print_list(list)
		ch = ui.getch()

		if ch in [ '0', 'q' ] :
			break

		if ch > '0' and ch < '5':
			currtab, f, list = switch_favorites_tab(favs, ch)
			continue

		if ch != '\r':
			ui.move(list, ch)
			continue

		if list[ui.curr]['type'] == 'MediaObject':
			play_single_video(list[ui.curr])
		else:
			play_all_container(list)
Example #5
0
File: ctv.py Project: serge-v/ctv
def play_single_video(child):
	ui.clear_screen()
	br = get_max_bitrate(child)
	if br > 0:
		rc = run_player(child['id'], br)
	else:
		rc = 1
	return rc
Example #6
0
File: ctv.py Project: michailf/ctv
def play_single_video(child):
    ui.clear_screen()
    br = get_max_bitrate(child)
    if br > 0:
        rc = run_player(child['id'], br)
    else:
        rc = 1
    return rc
Example #7
0
def main():
    ui.mainmenu()
    s = Sudoku()
    print(s.get_str())
    while True:
        command = ui.input_command()
        if command[0] == 0:
            # ADD
            args = ui.parse_add(command[1])
            if s.check_number(args[0], args[1], args[2]) == []:
                s.add_number(args[0], args[1], args[2])
            else:
                print("The number you tried to add does not fit the rules.")
                print("Please try again.")
                continue
        elif command[0] == 1:
            # DEL
            args = ui.parse_del(command[1])
            s.del_number(args[0], args[1])
        elif command[0] == 2:
            # SAVE
            if not s.save(command[1]):
                continue
        elif command[0] == 3:
            # LOAD
            if not s.load(command[1]):
                continue
        elif command[0] == 4:
            # CHK
            if s.check():
                print(COLORS["green"] + "Your Sudoku seems right.\n" + \
                      COLORS["clear"])
            else:
                print(COLORS["red"] + COLORS["bell"] + \
                      "Your Sudoku is wrong.\n" + COLORS["clear"])
            continue
        elif command[0] == 5:
            # HELP
            ui.parse_help(command[1])
            continue
        elif command[0] == 6:
            # QUIT
            print("Quitting game...")
            exit()
        elif command[0] == 7:
            # NEW
            s.set_numbers(EMPTY_SUDOKU)
        elif command[0] == ERROR:
            # ERROR
            print("Unknown command. Please try again.")
            continue
        ui.clear_screen()
        print(s.get_str())
def main(language_set=None, strategy=None, only=None):
    """
    Begin an interactive annotation session, where you are played snippets of
    audio in different languages and you have to mark whether or not they are
    representative samples.
    """
    if only:
        is_language_included = set([only]).__contains__
    else:
        _validate_language_set(language_set)
        is_language_included = generate_language_filter(language_set)

    metadata = load_metadata(is_language_included)
    session = Session()

    ui.clear_screen()
    ui.pause('Beginning annotation, press ENTER to hear the first clip...')

    sampler = (GreedySampler(metadata, DEFAULT_DURATION_S, MAX_PER_SAMPLE)
               if strategy == 'greedy'
               else RandomSampler(metadata, DEFAULT_DURATION_S, MAX_PER_SAMPLE))

    for segment in sampler:
        ann, quit = annotate(segment, session.user, metadata)

        if ann is not None:
            save_annotation(segment.sample, ann, metadata)
            session.annotated += 1

        else:
            print('Skipping...')
            session.skipped += 1

        print()

        if quit:
            break

    session.summarize()
def main(language_set=None, strategy=None, only=None):
    """
    Begin an interactive annotation session, where you are played snippets of
    audio in different languages and you have to mark whether or not they are
    representative samples.
    """
    if only:
        is_language_included = set([only]).__contains__
    else:
        _validate_language_set(language_set)
        is_language_included = generate_language_filter(language_set)

    metadata = load_metadata(is_language_included)
    session = Session()

    ui.clear_screen()
    ui.pause('Beginning annotation, press ENTER to hear the first clip...')

    sampler = (GreedySampler(metadata, DEFAULT_DURATION_S, MAX_PER_SAMPLE)
               if strategy == 'greedy' else RandomSampler(
                   metadata, DEFAULT_DURATION_S, MAX_PER_SAMPLE))

    for segment in sampler:
        ann, quit = annotate(segment, session.user, metadata)

        if ann is not None:
            save_annotation(segment.sample, ann, metadata)
            session.annotated += 1

        else:
            print('Skipping...')
            session.skipped += 1

        print()

        if quit:
            break

    session.summarize()
Example #10
0
    def cmd_test(self):
        cols, lines = shutil.get_terminal_size()

        print(ui.clear_screen())

        print(ui.pos(1,1) + 'Top-Left')

        print(ui.pos(1, 3), end='')
        for n in range(0,101, 5):
            print(str(n).rjust(3) + " " + ui.health_bar(n, 100))
        
        print(
            ui.pos(1, lines) + 
            colorama.Fore.LIGHTWHITE_EX + 
            'Press any key... ' + 
            colorama.Fore.WHITE,
            end='', flush=True)
        k = getch.getch_that_can_do_arrow_keys()
        print(str(ord(k)) + "\n")
        return False
Example #11
0
def main():
    ui.clear_screen()
    ui.print_mainmenu()
    implementation.init_deck()
    implementation.distr_cards(ui.player_count)
    global victory
    # Main part of game
    while not victory:
        # if the player is human:
        if ui.player_types[ui.current_player]: # HUMAN
            card_there = True
            before_asking = True
            while card_there:
                ui.clear_screen()
                ui.show_main_interface()
                # Saves detected quartets in a list. list can be empty
                quartets = implementation.filter_quartets(ui.current_player)
                # Prints the hand of the player in a nice layout
                print(ui.show_hand(implementation.player_hands[ui.current_player]))
                if not before_asking:
                    # Only shown if the player got a card from another player
                    print("Graaaaatz! You got the card you wanted!\n")
                if len(quartets) != 0:
                    # displaying the dropped quartet
                    # (it's already removed from implementation.player_hands)
                    print("You dropped a quartet:")
                    print(ui.show_hand(quartets))
                    ui.quartets_counter[ui.current_player] += 1
                    input("Press 'enter' to continue.\n")
                    ui.clear_screen()
                    ui.show_main_interface()
                    print(ui.show_hand(implementation.player_hands[ui.current_player]))
                if [] in implementation.player_hands:
                    # Detects end of game
                    victory = True
                    ui.victory()
                    break
                # card_there gets True, when the player successfully 
                # asked for a card
                card_there = ui.ask_for_cards()
                # Used earlier in an if-condition
                before_asking = False
            if victory:
                break
            print("\nYou did not get the card you asked for.")
            if len(implementation.deck) != 0:
                # Automaticly draws a card for the player if he failed to ask
                # for the right card and shows it to him
                print("But I got one from the deck for you:")
                print(ui.show_hand([implementation.draw_card(ui.current_player)]))
            input("Press 'enter' for next turn.\n")
            # switches the player
            if ui.current_player == ui.player_count - 1:
                ui.current_player = 0
                ui.turn_counter += 1
            else:
                ui.current_player += 1
            

        else: # AI
            while ai.ask_for_card(ui.current_player):
                # Asking for cards part for the ai.
                # Ai asks for cards in the while condition
                implementation.filter_quartets(ui.current_player)
                if [] in implementation.player_hands:
                    # tests for victory condition
                    victory = True
                    ui.victory()
                    break
            if victory:
                break
            if len(implementation.deck) != 0:
                # AI draws a card if it failed to ask for the right card
                implementation.draw_card(ui.current_player)
            # switches the player
            if ui.current_player == ui.player_count - 1:
                ui.current_player = 0
                ui.turn_counter += 1
            else:
                ui.current_player += 1
Example #12
0
File: ctv.py Project: serge-v/ctv
def main():
	favs = etvapi.get_favorites()
	loop(favs)
	ui.clear_screen()
Example #13
0
File: ctv.py Project: michailf/ctv
def main():
    favs = etvapi.get_favorites()
    loop(favs)
    ui.clear_screen()
Example #14
0
    def cmd_system_map(self):
        
        if self.player.star == None:
            print('Currently in interstellar space, not in a system.\n')
            return False

        cols, lines = shutil.get_terminal_size()

        # System coordinates are centered around the star, hence + star_x and + star_y all over the place
        star_x = cols // 2
        star_y = lines // 2

        view_left = -(cols // 2)
        view_right = (cols // 2)

        view_top = -(lines // 2) + 2        # +1 for // 2 flooring the value instead of rounding, +1 for header
        view_bottom = (lines // 2) - 1      # -1 for footer

        # clear screen
        print(ui.clear_screen() + ui.pos(1,1) + self.player.star.name + ' System')
        #print("Viewing: (" + str(view_left) + "," + str(view_top) + ") - (" + str(view_right) + "," + str(view_bottom) + ")")

        if self.player.star.owner:
            color = self.player.star.owner.color
        else:
            color = colorama.Fore.WHITE
        print(
            ui.pos(star_x, star_y) + 
            color + 
            '*',
            end=''
        )

        for b in self.player.star.bodies:
            if b.body_x < view_left or b.body_x > view_right \
            or b.body_y < view_top or b.body_y > view_bottom:
                continue

            col = star_x + b.body_x
            line = star_y + b.body_y
            print(ui.pos(col, line) + b.color + b.symbol, end='')

        for f in self.player.star.fleets:
            col = star_x + f.body_x
            line = star_y + f.body_y
            print(ui.pos(col, line) + f.race.color + f.race.letter, end='')

        col = star_x + self.player.system_x
        line = star_y + self.player.system_y
        print(
            ui.pos(col, line) + 
            colorama.Fore.LIGHTWHITE_EX + 
            '@',
            end = ''
        )

        print(colorama.Style.RESET_ALL + colorama.Fore.WHITE);

        k = '?'
        while(ord(k) != 13 and k != ' ' and ord(k) != 27):

            cursor_x = col - star_x
            cursor_y = line - star_y

            target = self.player.star.get_body_at(cursor_x, cursor_y)
            if target == None:
                target_text = '(' + str(cursor_x) + ',' + str(cursor_y) + ')'
            else:
                target_text = target.name

            for f in self.player.star.fleets:
                if f.body_x == cursor_x and f.body_y == cursor_y:
                    target_text += ' (' + \
                                f.race.color + \
                                f.name + \
                                colorama.Fore.WHITE + \
                                ')'

            print(
                ui.pos(1, lines) + 
                colorama.Fore.LIGHTWHITE_EX + 
                '(w,a,s,d,space,enter,esc) ' + 
                colorama.Fore.WHITE + 
                'Jump to: ' + 
                ui.clear_line() + 
                target_text,
                end='', flush=True)
            print(ui.pos(col, line), end='', flush=True)
            
            k = getch.getch()
            if k == 'w':
                if line > 2:
                    line -= 1
            elif k == 'a':
                if col > 1:
                    col -= 1
            elif k == 'd':
                if col < cols:
                    col += 1
            elif k == 's':
                if line < lines - 1:
                    line += 1
        
        if ord(k) == 27 or (cursor_x == self.player.system_x and cursor_y == self.player.system_y):
            print(ui.pos(1, lines) + '\n' + 'Jump CANCELED\n')
            return False
        
        print(ui.pos(1, lines) + '\n' + 'Initiating jump...')
        sleep(1)
        # TODO: random event or something :-)
        print('Jump successful!\n')
        self.player.jump_in_system(cursor_x, cursor_y, target)
        return True
Example #15
0
    def cmd_galaxy_map(self):
        
        cols, lines = shutil.get_terminal_size()

        view_left = max(self.player.world_x - (cols // 2), 1)
        view_left = min(view_left, config.world_width - cols)
        view_right = view_left + cols - 1

        view_top = max(self.player.world_y - (lines // 2), 1)
        view_top = min(view_top, config.world_height - lines)
        view_bottom = view_top + lines - 3 # -1 for math, -1 for header, -1 for footer

        # clear screen
        print(ui.clear_screen() + ui.pos(1,1) + 'Galactic View')

        #print("Window size: " + str(cols) + "x" + str(lines))
        #print("Viewing: (" + str(view_left) + "," + str(view_top) + ") - (" + str(view_right) + "," + str(view_bottom) + ")")

        # Show stars
        for s in self.world.stars:
            if s.world_x < view_left or s.world_x > view_right \
            or s.world_y < view_top or s.world_y > view_bottom:
                continue

            col = s.world_x - view_left + 1
            line = s.world_y - view_top + 1
            if s.owner:
                color = s.owner.color
            else:
                color = colorama.Fore.WHITE
            print(ui.pos(col, line + 1) + color + '*', end='')

        # Show investigation fleet's waypoints
        target = None
        for f in self.world.fleets:
            if f.destination.name == 'Sol':
                target = f
                break
        
        if target:
            n = target.wait
            n_x = target.world_x
            n_y = target.world_y
            while n_x != target.destination.world_x or n_y != target.destination.world_y:
                n += 1
                n_x,n_y = jump.towards(n_x,n_y, target.destination.world_x,target.destination.world_y)

                if n_x < view_left or n_x > view_right or n_y < view_top or n_y > view_bottom:
                    continue

                col = n_x - view_left + 1
                line = n_y - view_top + 1
                print(
                    ui.pos(col, line + 1) + 
                    colorama.Fore.LIGHTYELLOW_EX + 
                    #'¤ ' + str(n_x) + "," + str(n_y),
                    '¤' + str(n),
                    end = ''
                )

        # Show player
        col = self.player.world_x - view_left + 1
        line = self.player.world_y - view_top + 1
        print(
            ui.pos(col, line + 1) + 
            colorama.Fore.LIGHTWHITE_EX + 
            '@',
            end = ''
        )

        print(colorama.Style.RESET_ALL + colorama.Fore.WHITE);

        k = '?'
        while(ord(k) != 13 and k != ' ' and ord(k) != 27):

            cursor_x = col + view_left - 1
            cursor_y = line + view_top - 1
            
            target_text = '(' + str(cursor_x) + ',' + str(cursor_y) + ')'
            target = None
            for s in self.world.stars:
                if s.world_x == cursor_x and s.world_y == cursor_y:
                    target_text = s.name
                    if s.owner:
                        target_text += " (" \
                                     + s.owner.color \
                                     + s.owner.name \
                                     + colorama.Fore.WHITE \
                                     + ")"
                    target = s
                    break
            
            distance = self.player.get_distance(cursor_x, cursor_y)
            target_text += " ("
            if distance > config.maximum_jump_distance:
                target_text += colorama.Fore.RED
            target_text += str(distance) + colorama.Fore.WHITE + "/"

            fuel_cost = self.player.get_fuel_cost(cursor_x, cursor_y)
            if fuel_cost > self.player.ship.fuel:
                target_text += colorama.Fore.RED
            target_text += str(fuel_cost) + colorama.Fore.WHITE + ")"
            
            print(
                ui.pos(1, lines) + 
                colorama.Fore.LIGHTWHITE_EX + 
                '(w,a,s,d,space,enter,esc) ' + 
                colorama.Fore.WHITE + 
                'Jump to: ' + 
                ui.clear_line() + 
                target_text,
                end='', flush=True)
            print(ui.pos(col, line + 1), end='', flush=True)
            
            k = getch.getch()
            if k == 'w':
                if line > 1:
                    line -= 1
            elif k == 'a':
                if col > 1:
                    col -= 1
            elif k == 'd':
                if col < cols:
                    col += 1
            elif k == 's':
                if line < lines - 2:
                    line += 1
        
        if ord(k) == 27 or (cursor_x == self.player.world_x and cursor_y == self.player.world_y):
            print(ui.pos(1, lines) + '\n' + 'Jump CANCELED\n')
            return False
        
        print(ui.pos(1, lines))

        print('Initiating jump...')
        try:
            self.player.jump(cursor_x, cursor_y, target)
            sleep(1)
            # TODO: random event or something :-)
            print('Jump successful!\n')
            return True
        except player.JumpTooFarError:
            print("Cannot jump that far! Maximum distance is " + str(config.maximum_jump_distance) + ".\n")
            return False
        except player.NotEnoughFuelError:
            print("Not enough fuel!\n")
            return False