コード例 #1
0
    def __call__(self,
                 mouse_pos: vec2.Vec2,
                 mouse_down: Optional[vec2.Vec2] = None,
                 mouse_up: Optional[vec2.Vec2] = None,
                 enter: bool = False,
                 backspace: bool = False) -> bool:
        """
        Method to be called each frame to evaluate and execute appropriate
        callbacks.

        Args:
            mouse_pos: :class:`~foolysh.tools.vec2.Vec2` -> current mouse
                position.
            mouse_down: :class:`~foolysh.tools.vec2.Vec2` -> if set indicates
                where the mouse (or finger) down started.
            mouse_pos: :class:`~foolysh.tools.vec2.Vec2` -> if set indicates
                where the mouse (or finger) down ended.
            enter: ``bool`` -> whether the Enter key was pressed.
            backspace: ``bool`` -> whether the BackSpace key was pressed.

        Returns:
            Need more frames rendered flag, that can be set by UINodes.
        """
        down = mouse_down is not None and mouse_up is None
        click = mouse_down is not None and mouse_up is not None
        last_input = self._event_handler.last_text_input
        self._blink_events()

        if not (enter or backspace or down or click) and last_input is None:
            if self._state.need_render:
                self._state.need_render = False
                return True
            return False

        new_focus, same_focus = self.\
            _exc_mouse_enter_cb(down, click, (mouse_pos, mouse_down, mouse_up),
                                enter)
        curfoc = self._state.current_focus
        ret_focus = new_focus or same_focus
        if click and not ret_focus and curfoc is not None:  # EXIT_FOCUS
            self._nodes[curfoc].focus = False
            k = curfoc, EventType.EXIT_FOCUS
            self._try_cb_exec(k)
            self._state.current_focus = None
            sdl2.SDL_StopTextInput()
        elif click and new_focus:  # ENTER_FOCUS
            k = curfoc, EventType.ENTER_FOCUS
            self._try_cb_exec(k)

        if last_input is not None and curfoc is not None:
            k = curfoc, EventType.INPUT
            self._try_cb_exec(k, text=last_input)
        elif backspace and curfoc is not None:
            k = curfoc, EventType.BACKSPACE
            self._try_cb_exec(k)

        if self._state.need_render:
            self._state.need_render = False
            return True
        return False
コード例 #2
0
ファイル: manager.py プロジェクト: guanzi0008/dnf_game
 def set_text_input(self, status, target=None):
     """..."""
     if status:
         sdl2.SDL_StartTextInput()
     else:
         sdl2.SDL_StopTextInput()
     self.text_input = status
     self.text_input_target = target
コード例 #3
0
ファイル: fsm.py プロジェクト: tcdude/foolysh
 def request(self, state_name: str, back: bool = False) -> None:
     """
     Performs the transition to a registered State. Raises a ValueError if
     the provided `state_name` is not registered.
     """
     if not self.__states:
         self.__setup_fsm()
     if state_name not in self.__states:
         raise ValueError(f'Unknown state "{state_name}".')
     if self.__active_state == state_name:
         return
     if self.__active_state is not None:
         self.__states[self.__active_state][1]()
         if not back:
             self.__history.append(self.__active_state)
     self.__active_state = state_name
     self.__states[state_name][0]()
     sdl2.SDL_StopTextInput()  # Ensure on-screen kbd gets hidden
コード例 #4
0
 def __exit__(self, type, value, traceback):
     """Close the SDL2 interface."""
     base.VideoPlugin.__exit__(self, type, value, traceback)
     if sdl2 and numpy and self._has_window:
         # free windows
         sdl2.SDL_DestroyWindow(self.display)
         # free surfaces
         for s in self.canvas:
             sdl2.SDL_FreeSurface(s)
         sdl2.SDL_FreeSurface(self.work_surface)
         sdl2.SDL_FreeSurface(self.overlay)
         # free palettes
         for p in self.show_palette:
             sdl2.SDL_FreePalette(p)
         sdl2.SDL_FreePalette(self.composite_palette)
         # close IME
         sdl2.SDL_StopTextInput()
         # close SDL2
         sdl2.SDL_Quit()
コード例 #5
0
    def __buildWindow(self):
        if sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO) != 0:
            raise Exception(sdl2.SDL_GetError())

        sdl2.SDL_GL_SetAttribute(sdl2.SDL_GL_CONTEXT_MAJOR_VERSION, self.major)
        sdl2.SDL_GL_SetAttribute(sdl2.SDL_GL_CONTEXT_MINOR_VERSION, self.minor)

        self.window = sdl2.SDL_CreateWindow(b'ETGG2801 Example',
                                            sdl2.SDL_WINDOWPOS_UNDEFINED,
                                            sdl2.SDL_WINDOWPOS_UNDEFINED,
                                            self.size[0], self.size[1],
                                            sdl2.SDL_WINDOW_OPENGL)

        self.glcontext = sdl2.SDL_GL_CreateContext(self.window)
        if not self.glcontext:
            sdl2.SDL_DestroyWindow(self.window)
            raise Exception(sdl2.SDL_GetError())

        # keep application from receiving text input events
        sdl2.SDL_StopTextInput()
コード例 #6
0
    def __buildWindow(self):
        if sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO) != 0:
            raise Exception(sdl2.SDL_GetError())

        sdlimage.IMG_Init(sdlimage.IMG_INIT_PNG | sdlimage.IMG_INIT_JPG)

        sdl2.SDL_GL_SetAttribute(sdl2.SDL_GL_CONTEXT_PROFILE_MASK,
                                 sdl2.SDL_GL_CONTEXT_PROFILE_CORE)

        self.window = sdl2.SDL_CreateWindow(b'ETGG2801 Example', 0, 0,
                                            self.size[0], self.size[1],
                                            sdl2.SDL_WINDOW_OPENGL)

        self.glcontext = sdl2.SDL_GL_CreateContext(self.window)
        if not self.glcontext:
            sdl2.SDL_DestroyWindow(self.window)
            raise Exception(sdl2.SDL_GetError())

        # keep application from receiving text input events
        sdl2.SDL_StopTextInput()
コード例 #7
0
 def unfocus(self):
     sdl2.SDL_StopTextInput()
コード例 #8
0
 def deselect(self, next_active_object):
     super(Text_Entry, self).deselect(next_active_object)
     self.alert("Disabling text input", level='vv')
     self.allow_text_edit = False
     sdl2.SDL_StopTextInput()
     self.disable_cursor(False)
コード例 #9
0
    def poll_events(self):
        """
        Wait for a SDL2 event, handle it once encountered
        """
        update_img = False
        update_view = False
        update_frame = False
        event = sdl2.SDL_Event()
        while sdl2.SDL_PollEvent(ctypes.byref(event)):
            # resize events
            if event.type == sdl2.SDL_WINDOWEVENT:
                if event.window.event == sdl2.SDL_WINDOWEVENT_RESIZED:
                    self.handle_resize(
                        (event.window.data1, event.window.data2))
                if event.window.event in [
                        sdl2.SDL_WINDOWEVENT_RESIZED,
                        sdl2.SDL_WINDOWEVENT_EXPOSED
                ]:
                    update_view = True
            # quit events
            if event.type == sdl2.SDL_QUIT:
                return False, False, False, False

            # Console inputs
            if self.console_enabled:
                commands = []
                if event.type == sdl2.SDL_TEXTINPUT:
                    event_str = event.text.text[:]
                    commands += self.console.parse_input(event_str)
                    update_view = True
                if event.type == sdl2.events.SDL_KEYDOWN:
                    if event.key.keysym.sym == sdl2.SDLK_BACKSPACE:
                        self.console.backspace()
                        update_view = True
                    elif event.key.keysym.sym == sdl2.SDLK_RETURN:
                        commands += self.console.parse_input('\n')
                        update_view = True
                for cmd in commands:
                    update_img, update_view, update_frame = self.do_command(
                        cmd)

            # hotkeys
            if event.type == sdl2.events.SDL_KEYDOWN:
                if event.key.keysym.sym == sdl2.SDLK_ESCAPE:
                    return False, False, False, False
                elif event.key.keysym.sym == sdl2.SDLK_BACKQUOTE:
                    self.console_enabled = not self.console_enabled
                    if self.console_enabled:
                        sdl2.SDL_StartTextInput()
                    else:
                        sdl2.SDL_StopTextInput()
                    update_view = True
                if self.console_enabled:
                    return True, update_img, update_view, update_frame
                if event.key.keysym.sym == sdl2.SDLK_a:
                    self.playing = True
                    update_view = True
                    update_img = True
                elif event.key.keysym.sym == sdl2.SDLK_s:
                    self.playing = False
                    update_view = True
                    update_img = True
                elif event.key.keysym.sym == sdl2.SDLK_r:
                    random.shuffle(self.filters)
                    update_img = True
                    update_view = True
                elif event.key.keysym.sym == sdl2.SDLK_UP:
                    self.view.offset = (self.view.offset[0],
                                        self.view.offset[1] - 8)
                    update_view = True
                elif event.key.keysym.sym == sdl2.SDLK_DOWN:
                    self.view.offset = (self.view.offset[0],
                                        self.view.offset[1] + 8)
                    update_view = True
                elif event.key.keysym.sym == sdl2.SDLK_LEFT:
                    self.view.offset = (self.view.offset[0] + 8,
                                        self.view.offset[1])
                    update_view = True
                elif event.key.keysym.sym == sdl2.SDLK_RIGHT:
                    self.view.offset = (self.view.offset[0] - 8,
                                        self.view.offset[1])
                    update_view = True
                elif event.key.keysym.sym == sdl2.SDLK_EQUALS:
                    self.view.zoom += 0.05
                    update_view = True
                elif event.key.keysym.sym == sdl2.SDLK_MINUS:
                    self.view.zoom -= 0.05
                    update_view = True

        return True, update_img, update_view, update_frame
コード例 #10
0
ファイル: control.py プロジェクト: dnettoRaw/pyui
 async def blur(self):
     sdl2.SDL_StopTextInput()