Esempio n. 1
0
    def startup(self, window):
        signal.signal(signal.SIGINT, signal.SIG_DFL) # exit on CTRL-C

        def _thread():
            self._startup_fn()
            window.close()

        utils.create_thread(_thread)
Esempio n. 2
0
    def startup(self, window):
        signal.signal(signal.SIGINT, signal.SIG_DFL) # exit on CTRL-C

        # collection of methods to control the webkit window
        class _WindowControl:

            @staticmethod
            def zoom_factor(*args, **kwargs):
                return window.zoom_factor(*args, **kwargs)

        def _thread():
            self._startup_fn(_WindowControl)
            window.close()

        utils.create_thread(_thread)
Esempio n. 3
0
    def __init__(self, use_pty, cmd):
        self.out = chan.Chan()
        self._in = chan.Chan()

        self._use_pty = use_pty
        self._cmd = cmd

        self._client = None

        # use a pipe to send resize requests to the client_read thread,
        # to be able to select on both, this pipe and the master pty
        r,w = os.pipe()
        self._resize_read  = os.fdopen(r, 'r', 0)
        self._resize_write = os.fdopen(w, 'w', 0)

        def _in_handler():
            while True:
                self._in.get()()

        utils.create_thread(_in_handler)
        self.reset()
Esempio n. 4
0
    def _reset(self):
        self._kill()

        self._client = create_terminal(use_pty=self._use_pty,
                                       cmd=self._cmd)

        # read from the client and push onto outgoing
        def _client_read():
            while True:

                # receive resize events from the resize pipe,
                # terminal writes from the master pty
                data = self._client.read(additional_fd=self._resize_read.fileno())

                if data == self._resize_read.fileno():
                    new_size = self._resize_read.read(10)
                    lines = int(new_size[:5])
                    cols  = int(new_size[5:])

                    # read & propagate remaining data
                    data = self._client.read(timeout=0, additional_fd=None)
                    if data is not None:
                        self.out.put(data)

                    # resize
                    if self._client.set_size(lines, cols):
                        # inform screen of the new size
                        self.out.put(('resize', lines, cols))

                elif data is None:
                    # terminal client closed
                    self.out.put(None)
                    return

                else:
                    self.out.put(data)

        utils.create_thread(_client_read)
Esempio n. 5
0
 def _connect_and_listen(self):
     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     s.connect((self.host, self.port))
     self._s = s
     utils.create_thread(self._run)
Esempio n. 6
0
 def _connect_and_listen(self):
     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     s.connect((self.host, self.port))
     self._s = s
     utils.create_thread(self._run)
Esempio n. 7
0
 def receive(self, websocket, data):
     # print "Websocket recv", websocket, data
     # websocket.send('my'+data) # echo
     utils.create_thread(lambda: self._dest_chan.put(('websocket_receive', websocket, data)))
Esempio n. 8
0
 def connect(self, websocket):
     # non blocking
     utils.create_thread(lambda: self._dest_chan.put(('websocket_connect', websocket)))
Esempio n. 9
0
 def request(self, req):
     # non blocking
     req.id = self._ids.next()
     utils.create_thread(lambda: self._dest_chan.put(('request', req)))