示例#1
0
    def ask_question(self,
                     question,
                     type,
                     default,
                     handler,
                     abort_handler=None,
                     values=None,
                     required=1):
        import text_input
        import bool_input
        import choice_input
        import list_input

        if abort_handler:
            abortable = 1
        else:
            abortable = 0
        if type == "text-single":
            self.input_widget = text_input.TextInput(abortable, required,
                                                     default, 0)
        elif type == "text-private":
            self.input_widget = text_input.TextInput(abortable,
                                                     required,
                                                     default,
                                                     0,
                                                     private=True)
        elif type == "boolean":
            self.input_widget = bool_input.BooleanInput(
                abortable, required, default)
        elif type == "choice":
            if not values:
                raise InputError, "Values required for 'choice' input."
            self.input_widget = choice_input.ChoiceInput(
                abortable, required, default, values)
        elif type == "list-single":
            self.input_widget = list_input.ListInput(abortable, required,
                                                     default, values)
        elif type == "list-multi":
            self.input_widget = list_input.ListInput(abortable, required,
                                                     default, values, 1)
        else:
            raise InputError, "Unknown input type: " + type
        self.question_handler = handler
        self.question_abort_handler = abort_handler
        self.question = question
        if self.window and self.window.active:
            cjc_globals.screen.input_handler.current_buffer_changed(self)
        self.activity(2)
示例#2
0
    def game_intro(self):

        intro = True

        # Create TextInput-object
        textinput = text_input.TextInput(font_size=65)

        clock = pg.time.Clock()

        screen.fill((225, 225, 225))

        while intro:
            events = pg.event.get()
            for event in events:
                #print(event)
                if event.type == pg.QUIT:
                    pg.quit()
                    quit()
                if event.type == pg.KEYDOWN:
                    if event.key == pg.K_RETURN:
                        self.change_text()
                        print(textinput.get_text())
                        textinput.clear_text()
                #box.handle_event(event)

            screen.fill(white)
            largeText = pg.font.Font('freesansbold.ttf', self.size)
            TextSurf, TextRect = text_objects(self.text, largeText)
            TextRect.center = ((display_width / 2), (display_height / 2))
            screen.blit(TextSurf, TextRect)

            # Feed it with events every frame
            textinput.update(events)
            # Blit its surface onto the screen
            screen.blit(textinput.get_surface(), (200, 350))

            button("GO!", 150, 450, 100, 50, green, bright_green,
                   self.change_text)
            button("Quit", 550, 450, 100, 50, red, bright_red, quitgame)

            pg.display.flip()
            clock.tick(30)
示例#3
0
    def run(self):
        eyetracker = EyeTracker(disp)
        eyetracker.calibrate()

        running = True

        self.textinput = text_input.TextInput(text_color=(255, 255, 255),
                                              cursor_color=(255, 255, 255),
                                              literal_number=True)
        if self.avalgame._code is not None:
            self.textinput.input_string = str(self.avalgame._code)
            self.textinput.cursor_position = len(str(self.avalgame._code))

        self.text1 = self.textFont.render("Configuracoes", 1, (255, 255, 255))
        self.text2 = self.textFont.render("Codigo do jogo", 1, (255, 255, 255))
        #pygame.display.update()
        self.screen.fill(self.bg_color)
        self.screen.blit(self.text1, (380, 250))
        self.screen.blit(self.text2, (380, 300))
        exitLabel = self.exitFont.render("ESC para sair", 1, (255, 255, 255))
        self.screen.blit(exitLabel, (0, 650))
        self.logTheData()
        self.buttonOk.set_position(380, 400)
        self.buttonCancel.set_position(450, 400)

        while (running):
            clock.tick(60)
            self.screen.fill(self.bg_color)
            self.screen.blit(self.text1, (380, 250))
            self.screen.blit(self.text2, (380, 300))
            exitLabel = self.exitFont.render("ESC para sair", 1,
                                             (255, 255, 255))
            self.screen.blit(exitLabel, (0, 650))

            events = pygame.event.get()

            self.textinput.update(events)
            self.screen.blit(self.textinput.get_surface(), (380, 350))
            pygame.display.update()

            if self.buttonOk.is_mouse_over(pygame.mouse.get_pos()):
                self.buttonOk.set_font_color((255, 0, 0))
                if ((1, 0, 0) == pygame.mouse.get_pressed()):
                    if self.textinput.get_text() != '':
                        self.avalgame.install(True,
                                              int(self.textinput.get_text()))
                    else:
                        self.avalgame.install(False, 0)

                    running = False
            else:
                self.buttonOk.set_font_color((255, 255, 255))

            if self.buttonCancel.is_mouse_over(pygame.mouse.get_pos()):
                self.buttonCancel.set_font_color((255, 0, 0))
                if ((1, 0, 0) == pygame.mouse.get_pressed()):
                    running = False
            else:
                self.buttonCancel.set_font_color((255, 255, 255))

            for event in events:
                if (event.type == pygame.QUIT or event.type == pygame.KEYDOWN):
                    if (event.key == pygame.K_ESCAPE):
                        #print(self.textinput.get_text())
                        running = False

            self.screen.blit(self.buttonOk.label, self.buttonOk.position)
            self.screen.blit(self.buttonCancel.label,
                             self.buttonCancel.position)

            x, y = eyetracker.sample()
            self.canvas.draw_circle(colour=(255, 0, 0),
                                    pos=(x, y),
                                    r=5,
                                    fill=True)

            self.disp.fill(self)
            self.disp.show()
示例#4
0
cur_map = Map()
result = Label('', 'black', 10, 60)
scheme = Button('  Схема  ', 'red', width - 50, height - 390, angle=270)
sputnik = Button('  Спутник  ', 'blue', width - 50, height - 265, angle=270)
hybrid = Button('  Гибрид  ', 'green', width - 50, height - 130, angle=270)
search = Button(
    '  Искать  ',
    'black',
    width - 90,
    5,
)
post = Button('  Почтовый индекс  ', 'black', width - 470, 50)

cancel = Button('  Сброс поискового результата  ', 'black', width - 287, 50)
text_input = text_input.TextInput(font_family='font.ttf',
                                  font_size=30,
                                  repeat_keys_initial_ms=400,
                                  repeat_keys_interval_ms=30)


def make_action(button):
    if button == 'Искать':
        cur_map.search(text_input.get_text())
        search.image = search.active
        result.make_text(cur_map.address, 'black', 'white')
    if button == 'Почтовый индекс':
        if post.p:
            post.p = False
            result.make_text(cur_map.address, 'black', 'white')
            post.image = post.active
        else:
            result.make_text(cur_map.address + ' ' + cur_map.postal_code,
示例#5
0
#!/usr/bin/python3
import text_input
import pygame
pygame.init()

# Create TextInput-object
textinput = text_input.TextInput()

clock = pygame.time.Clock()

# Feed it with events every frame
textinput.update(events)
# Blit its surface onto the screen

pygame.display.update()
clock.tick(30)
示例#6
0
    def __init__(self):
        global screen
        screen = pygame.display.set_mode(screen_size)
        #pygame.mouse.set_cursor((8, 8), (4, 4), (0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 60, 60, 60, 60, 0, 0))
        self.is_fullscreen = False

        api.screen = screen
        api.game = self
        api.send_message = self.add_message
        api.send_message_to_all = self.add_message
        api.exec_chat_command = self.exec_chat_command

        self.connected = False
        self.connecting = False

        self.debug_screen_active = False

        self.player = Player(0, 0)
        self.player.uuid = '00000000-0000-0000-0000-000000000000'

        self.read_config()

        self.d_x = 0
        self.d_y = 0

        self.m_tile_x = 0
        self.m_tile_y = 0

        self.images = api.images

        # TODO сделать нормальный hud
        self.bars = {}
        self.bar_width = 60
        self.bar_height = 16
        self.bar_sep = 28
        self.bar_x_offset = 12
        self.bar_y_offset = 12

        self.tile_classes = api.tile_classes
        self.object_classes = api.object_classes
        self.chat_commands = api.chat_commands

        self.chat_commands.update({
            'c': self.command_connect,
            'q': self.command_leave,
            'exit': self.command_exit,
            'nick': self.command_nickname,
            'help': self.command_help,
            'load_world': self.command_load_world,
            'save_world': self.command_save_world
        })

        self.forms = api.forms

        self.magic = FIRE_MAGIC
        self.clock = pygame.time.Clock()
        self.text_input = text_input.TextInput(font)
        self.state = 'normal'

        self.messages = []
        self.messages_on_screen = 20
        self.message_show_from = 0

        self.fov_radius = 12
        self.install_mods()

        self.load_world('default_world')

        self.add_message('press ENTER to open chat', color=api.YELLOW)
        self.add_message('============= COMMANDS =============')
        self.add_message('/c <ip>          - connect to server',
                         color=api.GREY)
        self.add_message('/q               - abort connection', color=api.GREY)
        self.add_message('/nick <nickname> - change nickname', color=api.GREY)
        self.add_message('/exit            - exit from game', color=api.GREY)
        self.add_message('/help            - available commands',
                         color=api.GREY)
        self.add_message('====================================')

        self.current_form = None
示例#7
0
    def render(self):

        # Create TextInput-object
        textinput = text_input.TextInput(font_size=65)

        clock = pg.time.Clock()

        self.screen.fill((225, 225, 225))

        def print_on_press():
            print('button pressed')

        settings = {
            "clicked_font_color": (0, 0, 0),
            "hover_font_color": (205, 195, 100),
            'font': pg.font.Font(None, 16),
            'font_color': (255, 255, 255),
            'border_color': (0, 0, 0),
        }

        btn = button.Button(rect=(10, 10, 105, 25),
                            command=print_on_press,
                            text='Statistics',
                            **settings)

        while self.intro:

            events = pg.event.get()
            for event in events:
                if event.type == pg.QUIT:
                    # Catach quit flag
                    pg.quit()
                    quit()
                if event.type == pg.KEYDOWN:
                    if event.key == pg.K_RETURN:
                        # If user presses enter catch the word and send it
                        # to manager
                        # self.change_text()

                        self.intro = False
                        result = textinput.get_text()

                        textinput.clear_text()
                btn.get_event(event)

            self.screen.fill(colours.white)

            # GERMAN WORD
            largeText = pg.font.Font('freesansbold.ttf', self.size)
            TextSurf, TextRect = self.text_objects(self.text, largeText)
            TextRect.center = ((display_width / 2), (250))
            self.screen.blit(TextSurf, TextRect)

            # INPUT WORD
            # Feed it with events every frame
            textinput.update(events)
            inputSurf = textinput.get_surface()
            inputRect = inputSurf.get_rect()
            inputRect.center = ((display_width / 2), (350))
            # Blit its surface onto the screen
            self.screen.blit(textinput.get_surface(), inputRect)

            # BUTTONS
            btn.draw(self.screen)

            # COSAS PYGAME
            pg.display.flip()
            clock.tick(30)

        return result
示例#8
0
class AdminMenu:
    """Меню администратора"""
    # Кнопки
    delete_player_button = pyg_button.PygButton((377, 469, 100, 30), 'Удалить')
    close_button = pyg_button.PygButton((377, 519, 100, 30), 'Выход')

    # Ввод имени
    name_input = text_input.TextInput((367, 319), 180, 25)

    medium_font = pygame.font.SysFont('Comic Sans MS', 14)
    name_text = medium_font.render('Имя:', False, (0, 0, 0))

    delete_error = False
    delete_error_text = medium_font.render('Игрока не существует', False,
                                           (255, 0, 0))
    delete_success = False
    delete_success_text = medium_font.render('Игрок удален', False,
                                             (0, 255, 0))

    def handle_event(self, event):
        global scene
        if event == pygame.QUIT:
            scene = scenes['LoginMenu']
            self.clear()
        if 'click' in self.close_button.handleEvent(event):  # Выход из игры
            self.clear()
            scene = scenes['LoginMenu']
        if 'click' in self.delete_player_button.handleEvent(
                event):  # Удаление игрока
            if len(self.name_input.get_text()) > 0:
                if authorization.delete_player(self.name_input.get_text()):
                    self.delete_error = False
                    self.delete_success = True
                else:
                    self.delete_error = True
                    self.delete_success = False
        self.name_input.handle_event(event)

    def update(self):
        self.name_input.update()
        if len(self.name_input.input_string) > 20:
            self.name_input.input_string = self.name_input.input_string[:21]

    def draw(self, surface):
        surface.fill(BG_COLOR)  # Фон
        surface.blit(logo, (277, 19))  # Логотип

        surface.blit(self.name_text, (307, 319))  # Ввод имени
        self.name_input.draw(surface)

        if self.delete_error:
            surface.blit(self.delete_error_text, (307, 394))
        elif self.delete_success:
            surface.blit(self.delete_success_text, (307, 394))

        self.delete_player_button.draw(surface)
        self.close_button.draw(surface)
        pygame.display.update()

    def clear(self):
        self.name_input.clear_text()
        self.delete_error = False
        self.delete_success = False
示例#9
0
class LoginMenuScene:
    """Меню входа в игру"""

    # Кнопки
    login_button = pyg_button.PygButton((307, 419, 100, 30), 'Войти')
    signup_button = pyg_button.PygButton((447, 419, 100, 30), 'Регистрация')
    statistics_button = pyg_button.PygButton((377, 469, 100, 30), 'Статистика')
    close_button = pyg_button.PygButton((377, 519, 100, 30), 'Выход')

    # Ввод имени
    name_input = text_input.TextInput((367, 319), 180, 25)
    # Ввод пароля
    password_input = text_input.TextInput((367, 369), 180, 25)

    medium_font = pygame.font.SysFont('Comic Sans MS', 14)
    name_text = medium_font.render('Имя:', False, (0, 0, 0))
    password_text = medium_font.render('Пароль:', False, (0, 0, 0))

    auth_error = False
    auth_error_text = medium_font.render('Неверное имя или пароль', False,
                                         (255, 0, 0))
    signup_error = False
    signup_error_text = medium_font.render('Пользователь уже существует',
                                           False, (255, 0, 0))
    signup_success = False
    signup_success_text = medium_font.render('Вы зарегистрированы', False,
                                             (0, 255, 0))

    def handle_event(self, event):
        global run
        global scene
        if event == pygame.QUIT:
            run = False
        if 'click' in self.close_button.handleEvent(event):  # Выход из игры
            pygame.quit()
        if 'click' in self.login_button.handleEvent(event):  # Авторизация
            if len(self.name_input.get_text()) > 0 and len(
                    self.password_input.get_text()) > 0:
                if authorization.auth(self.name_input.get_text(),
                                      self.password_input.get_text()):
                    self.auth_error = False
                    self.signup_error = False
                    self.signup_success = False
                    player_name = self.name_input.get_text()
                    if player_name == 'admin':  # Авторизация администратора
                        self.clear()
                        scene = scenes['AdminMenu']
                    else:
                        self.clear()
                        settings.update_setting('player_name', player_name)
                        scene = scenes['MainMenu']
                else:
                    self.auth_error = True
                    self.signup_error = False
                    self.signup_success = False
        if 'click' in self.signup_button.handleEvent(
                event):  # Регистраиця нового игрока
            if len(self.name_input.get_text()) > 0 and len(
                    self.password_input.get_text()) > 0:
                if authorization.add_player(self.name_input.get_text(),
                                            self.password_input.get_text()):
                    self.auth_error = False
                    self.signup_error = False
                    self.signup_success = True
                else:  # Если игрок уже существует
                    self.auth_error = False
                    self.signup_error = True
                    self.signup_success = False
        if 'click' in self.statistics_button.handleEvent(
                event):  # Открытие статистики
            self.clear()
            scene = scenes['StatisticsMenu']

        if event.type == pygame.MOUSEBUTTONDOWN:
            pos = pygame.mouse.get_pos()

        self.name_input.handle_event(event)
        self.password_input.handle_event(event)

    def update(self):
        self.name_input.update()
        self.password_input.update()
        if len(self.name_input.input_string) > 20:
            self.name_input.input_string = self.name_input.input_string[:21]
        if len(self.password_input.input_string) > 20:
            self.password_input.input_string = self.password_input.input_string[:
                                                                                21]

    def draw(self, surface):
        surface.fill(BG_COLOR)  # Фон
        surface.blit(logo, (277, 19))  # Логотип

        surface.blit(self.name_text, (307, 319))  # Ввод имени
        self.name_input.draw(surface)

        surface.blit(self.password_text, (307, 369))  # Ввод пароля
        self.password_input.draw(surface)

        if self.auth_error:  # Ошибка входа
            surface.blit(self.auth_error_text, (307, 394))
        elif self.signup_error:  # Ошибка регистрации
            surface.blit(self.signup_error_text, (307, 394))
        elif self.signup_success:  # Регистрация успешна
            surface.blit(self.signup_success_text, (307, 394))

        self.login_button.draw(surface)
        self.signup_button.draw(surface)
        self.statistics_button.draw(surface)
        self.close_button.draw(surface)
        pygame.display.update()

    def clear(self):
        self.name_input.clear_text()
        self.password_input.clear_text()
        self.auth_error = False
        self.signup_error = False
        self.signup_success = False
示例#10
0
        self.x = x + INPUT_PADDING
        self.y = y
        self.rect_color = (0, 0, 0)
        self.focus = False
        self.cursor_size = (16, 24)
        self.cursor_hotspot = (6, 12)
        self.cursor = pygame.cursors.compile(textmarker)
        self.cursor_is_textmarker = False
        self.clicked = False

        # to get the height of text with this font
        text_height = font.size("Dummy")[1]

        self.input = text_input.TextInput(self.display,
                                          font,
                                          max_width=width - 2 * INPUT_PADDING,
                                          password=password,
                                          only_digits=only_digits)
        self.x_end = x + width
        self.y_end = y + text_height + 2 * INPUT_PADDING
        self.input_rect = pygame.Rect(x, y - INPUT_PADDING, width,
                                      text_height + 2 * INPUT_PADDING)

    def setFocus(self, flag):
        self.focus = flag
        self.input.setFocus(flag)

    def handleEvent(self, event):
        self.input.handleEvent(event)

        # change cursor type when hovering over text input