示例#1
0
def main():
    # Global variables
    global done
    global clock

    # Initialize erlport, pygame, and game elements
    erlport.erlang.set_default_message_handler()
    pygame.init()
    pygame.font.init()
    screen = pygame.display.set_mode((780, 480))
    textInput = TextInput(font_size=28)
    myfont = pygame.font.SysFont("", 28)
    clock = pygame.time.Clock()
    click_boxes = make_click_boxes()

    # The game loop. 1 iteration == 1 frame rendered
    done = False
    while not done:
        # draw background
        screen.fill(COLOR['game_board'])
        box_rect = pygame.Rect(0, 0, 300, 480)
        input_rect = pygame.Rect(0, 440, 300, 50)
        change_mode = pygame.Rect(750, 0, 30, 30)
        pygame.draw.rect(screen, COLOR['chat_box'], box_rect)
        pygame.draw.rect(screen, COLOR['chat_input'], input_rect)
        pygame.draw.rect(screen, COLOR['change_mode'], change_mode)

        # draw chat elements
        blit_chat_log(screen)

        # draw and check game elements
        if game_started:
            if ttt_mode:
                draw_ttt(screen)
            else:
                draw_nim(screen)
            check_click_boxes(click_boxes)
            check_click_ttt_mode()

        # check pygame events
        events = pygame.event.get()
        for event in events:
            if event.type == pygame.QUIT:
                done = True

        # draw and check text input events
        if textInput.update(events):
            text = textInput.get_text()
            textInput.clear()
            if text != "":
                send_chat(text, myfont)
        screen.blit(textInput.get_surface(), (10, 450))

        # finish handling frame
        pygame.display.update()
        clock.tick(30)

    cast(erlPID, Atom("done"))
    pygame.display.quit()
    pygame.quit()
示例#2
0
class MainMenu:
    def __init__(self, screen):
        self.surface = screen.subsurface(
            (0, 0), screen.get_size())  # take full screen for menu
        self.name_input = TextInput()

    def handle_event(self, event):
        if event.type == pg.MOUSEBUTTONUP:
            self.handle_click(event.pos)
        else:
            self.name_input.update([event])

    def handle_click(self, position):
        pass

    def draw(self, mouse_pos):
        self.surface.fill((225, 225, 225))
        self.surface.blit(self.name_input.get_surface(), (10, 10))
示例#3
0
    def __init__(self, options={}):
        self._logger = logging.getLogger(__name__)

        # Read config
        config_file = options['config']
        self._logger.debug("Trying to read config file: '%s'", config_file)
        try:
            with open(config_file, "r") as f:
                self.config = yaml.safe_load(f)
        except OSError:
            self._logger.error("Can't open config file: '%s'", config_file)
            raise

        self._logger.info('config loaded')
        self._logger.info(self.config)
        try:
            stt_engine_slug = self.config['stt_engine']
        except KeyError:
            stt_engine_slug = 'sphinx'
            self._logger.warning(
                "stt_engine not specified in profile, defaulting " + "to '%s'",
                stt_engine_slug)
        stt_engine_class = stt.get_engine_by_slug(stt_engine_slug)

        try:
            slug = self.config['stt_passive_engine']
            stt_passive_engine_class = stt.get_engine_by_slug(slug)
        except KeyError:
            stt_passive_engine_class = stt_engine_class

        try:
            tts_engine_slug = self.config['tts_engine']
        except KeyError:
            tts_engine_slug = tts.get_default_engine_slug()
            self._logger.warning(
                "tts_engine not specified in profile, defaulting " + "to '%s'",
                tts_engine_slug)
        tts_engine_class = tts.get_engine_by_slug(tts_engine_slug)
        self._logger.info('LOADED TTS %s', tts_engine_class)

        # Initialize Mic
        if 'text' in options:
            self.input = TextInput(tts_engine_class.get_instance())
        else:
            self.input = Mic(tts_engine_class.get_instance(),
                             stt_passive_engine_class.get_passive_instance(),
                             stt_engine_class.get_active_instance())
示例#4
0
def main():
    test_text = TextInput(50, 50, 200, 30, font)
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
            if event.type == pygame.KEYDOWN:
                manage_reply = test_text.manage_key_press(event, font)
                if manage_reply:
                    print(f"You said {manage_reply}.")
            if event.type == pygame.KEYUP and event.key in [
                    pygame.K_RSHIFT, pygame.K_LSHIFT
            ]:
                test_text.shift_unpressed()
        test_text.update()
        redraw(win)
        clock.tick(30)
 def create_input(self, text, config, pos):
     input_ = TextInput(**config, )
     input_.set_text(text)
     input_.place(anchor=tk.NW, **pos)
     return input_
示例#6
0
 def __init__(self, screen):
     self.surface = screen.subsurface(
         (0, 0), screen.get_size())  # take full screen for menu
     self.name_input = TextInput()
示例#7
0
from live_info.live_manager import Display
from live_info.live_email import EmailInfo
from live_info.live_speed import InternetInfo
from live_info.live_rail import RailInfo
# from live_info.live_traffic import TrafficInfo
from text_input import TextInput
import datetime

tui_rail = TextInput("Please enter the 3 character station code")
tui_rail.request_input()
rail = RailInfo(20, tui_rail.answer)

# tui_traffic_start = TextInput("Please enter postcode of origin")
# tui_traffic_start.request_input()
# tui_traffic_end = TextInput("Please enter postcode of destination")
# tui_traffic_end.request_input()
# traffic = TrafficInfo(20, tui_traffic_start.answer, tui_traffic_end.answer)

internet = InternetInfo(30)

tui_num_messages = TextInput("Enter number of emails")
tui_num_messages.request_input()
email = EmailInfo(60, tui_num_messages.answer)

display = Display([email, internet, rail])
display.set_active_time(datetime.time(6, 30), datetime.time(8, 00))
display.show_display()
示例#8
0
def main():
    # Initialise screen
    pygame.init()
    screen = pygame.display.set_mode((1080, 720))
    pygame.display.set_caption('Undir la Flota')
    clock = pygame.time.Clock()

    # Fill background
    background = pygame.Surface(screen.get_size())
    background = background.convert()
    background.fill(const.Color.WHITE)

    while not game_ended:
        # events.event_listener({})

        text_input.read()
        text, rect = text_input.get_text(0, 0)
        screen.blit(text, rect)

        screen.blit(background, (0, 0))
        pygame.display.flip()
        clock.tick(60)


game_ended = False
text_input = TextInput()

if __name__ == '__main__':
    main()