Esempio n. 1
0
    def _on_text(self, e: Event, entity: str, who: str, text: str) -> None:
        words = text.split()

        if len(words):
            Event.trigger(Event(words[0], self, entity=entity, args=words[1:]))
        else:
            text = f'你要作什麼?'
            Channel.toRole(entity, Message.TEXT, text)
Esempio n. 2
0
    def _on_linefeed_id(self, e: Event) -> None:
        Event.trigger(
            Event(Event.CLICK,
                  self,
                  x=self.left + self._field_passwd.left,
                  y=self.top + self._field_passwd.top))

        return self._field_id.value
Esempio n. 3
0
 def _read(self, entity: str, socket: socket) -> None:
     for msg in InStream.instance(entity).read(socket):
         Event.trigger(
             Event(
                 msg.type, self._servant,
                 entity=entity,
                 **msg.kwargs
             )
         )
Esempio n. 4
0
    def _on_read(self, socket: socket, entity: str) -> None:
        msg_buffer = InStream.instance(entity).read(socket)

        for msg in msg_buffer:
            Event.trigger(
                Event(msg.type,
                      Servant.instance(),
                      entity=entity,
                      **msg.kwargs))
Esempio n. 5
0
    def _on_click(self, e: Event, x: int, y: int) -> bool:
        for element in self.elements:
            if element.contains(x - self.x, y - self.y):
                Event.trigger(Event(Event.CLICK, element, x=x, y=y))

                if element.focusable:
                    self._focus = element

                break

        return False
Esempio n. 6
0
    def _on_click(self, e: Event, x: int, y: int) -> bool:
        for widget in self.components:
            if widget.contains(x - self.x, y - self.y):
                Event.trigger(Event(Event.CLICK, widget, x=x, y=y))

                if widget.focusable:
                    self._focus = widget

                break

        return False
Esempio n. 7
0
    def _on_sign_in(
        self, e: Event, entity: str, user_id: str = '', passwd: str = ''
    ) -> None:
        role = Stats.text('entity', user_id)
        Stats.update_text('binding', entity, role)
        room = Stats.text('at_room', role)
        Stats.list_append('guest', room, Link(entity, role))

        text = f'歡迎來到 MUTE: Multi-User Texting Environment'
        Channel.to_role(entity, Message.SYSTEM, text)

        Event.trigger(Event(Event.CMD_LOOK, self._servant, entity=entity))
Esempio n. 8
0
    def _on_sign_in(self,
                    e: Event,
                    entity: str,
                    user_id: str = '',
                    passwd: str = '') -> None:
        role = Role.instance(user_id, name=user_id)

        Name.instance(entity, name=role.name)
        Room.instance(role.room).enter(entity)

        text = f'歡迎來到 MUTE: Multi-User Texting Environment'
        Channel.toRole(entity, Message.SYSTEM, text)

        Event.trigger(Event(Event.CMD_LOOK, self._servant, entity=entity))
Esempio n. 9
0
    def _on_new_connection(self, socket: socket) -> None:
        connection, address = socket.accept()  # Should be ready to read
        print(f'Connected by: {address}')

        connection.setblocking(False)

        mask = selectors.EVENT_READ | selectors.EVENT_WRITE

        entity = Entity.eid()

        self._multiplexer.register(connection, mask, entity)

        Event.trigger(Event(Event.RECEPTION, Servant.instance(),
                            entity=entity))
Esempio n. 10
0
    def __init__(self, x=0, y=0, width=80):
        super().__init__(x, y, width)

        self._text = ''
        self._place_holder = ' ' * width
        self._max_len = width

        self._color = Color.INPUT_FIELD

        self.on(Event.FOCUS_IN,
                lambda _: Event.trigger(Event(Event.CURSOR_ON)))
        self.on(Event.FOCUS_OUT,
                lambda _: Event.trigger(Event(Event.CURSOR_OFF)))
        self.on(Event.KEY_BACKSPACE, self._on_key_backspace)
        self.on(Event.KEY_PRESSED, self._on_key_pressed)
Esempio n. 11
0
    def _on_cmd_move(
        self, e: Event, entity: str = '', args: List[str] = []
    ) -> None:
        role = Role.instance(entity)
        exit = Exit.instance(role.room)

        room = exit.to(e.type[0])

        if None != room:
            Room.instance(role.room).leave(entity)
            Room.instance(room).enter(entity)

            role.enter(room)

            Event.trigger(Event(Event.CMD_LOOK, self._servant, entity=entity))
        else:
            Channel.to_role(entity, Message.TEXT, f'  這裡沒有出口')
Esempio n. 12
0
    def _on_cmd_move(
        self, e: Event, entity: str = '', args: Sequence[str] = []
    ) -> None:
        role = Stats.text('binding', entity)
        at = Stats.text('at_room', role)
        exit = Stats.text('exit', at)

        try:
            room = exit[e.type[0]]

            Stats.list_remove('guest', at, Link(entity, role))
            Stats.update_text('at_room', role, room)
            Stats.list_append('guest', room, Link(entity, role))

            Event.trigger(Event(Event.CMD_LOOK, self._servant, entity=entity))
        except KeyError:
            Channel.to_role(entity, Message.TEXT, f'  這裡沒有出口')
Esempio n. 13
0
    def _scroll_v(self, e: Event, y: int) -> None:
        if y == self.top:
            Event.trigger(Event(Event.SCROLL_DOWN, e.target))
        elif y == self.bottom:
            Event.trigger(Event(Event.SCROLL_UP, e.target))
        else:
            r = (y - self.top - 1) / (self.height - 2)

            Event.trigger(Event(Event.SCROLL_V, e.target, r=r))
Esempio n. 14
0
 def _scroll_h(self, e: Event, x: int) -> None:
     if x == self.left:
         Event.trigger(Event(Event.SCROLL_LEFT, e.target))
     elif y == self.right:
         Event.trigger(Event(Event.SCROLL_RIGHT, e.target))
     else:
         Event.trigger(
             Event(Event.SCROLL_H, e.target,
                   r=(x - self.left) / self.width))
Esempio n. 15
0
    def _on_click(self, e: Event, x: int, y: int) -> None:
        Event.trigger(Event(Event.FOCUS_OUT, self.focus))

        if not self._modal:
            for uid in reversed(self._z_stack):
                if self._windows[uid].contains(x, y):
                    self.raise_to_top(uid)

                    break

        Event.trigger(Event(Event.CLICK, self.focus, x=x, y=y))

        Event.trigger(Event(Event.FOCUS_IN, self.focus))
Esempio n. 16
0
    def _check_input(self) -> None:
        try:
            e = self._window.get_wch()

            if e == 'q':
                Event.trigger(Event(Event.EXIT, self))
            elif e == curses.KEY_MOUSE:
                _, x, y, _, _ = curses.getmouse()

                Event.trigger(
                    Event(Event.CLICK, self._window_manager, x=x, y=y))
            elif type(e) == str:
                LogCat.log(f'keypressed: {e}')
                #        elif e > 0:
                Event.trigger(
                    Event(Event.KEY_PRESSED, self._window_manager.focus,
                          key=e))
            else:
                Event.trigger(Event(e, self._window_manager.focus))

        except curses.error:
            pass

        self._in_stream()
Esempio n. 17
0
    def _on_click_ok(self, e: Event, x: int, y: int) -> None:
        Event.trigger(
            Event(Event.WIN_DISPLAY, None, uid=self.uid, display=False))

        Event.trigger(Event(Event.DIALOG_OK, self))
Esempio n. 18
0
    def _on_linefeed_passwd(self, e: Event) -> None:
        Event.trigger(Event(Event.FOCUS_OUT, self))

        Event.trigger(Event(Event.CLICK, self.button_ok, x=0, y=0))

        return self._field_passwd.value
Esempio n. 19
0
 def _on_msg_sign_in(self, e: Event, who: str) -> None:
     Event.trigger(
         Event(Event.WIN_DISPLAY, self, uid=self._sign_in.uid,
               display=True))
Esempio n. 20
0
 def _on_dlg_cancel(self, e: Event) -> None:
     Event.trigger(Event(Event.EXIT, self))
Esempio n. 21
0
 def _in_stream(self) -> None:
     for msg in InStream.instance('').read(self._socket):
         Event.trigger(Event(msg.type, self, **msg.kwargs))
Esempio n. 22
0
    def _on_text(self, e: Event, entity: str, who: str, text: str) -> None:
        words = text.split()

        Event.trigger(Event(words[0], self, entity=entity, args=words[1:]))