示例#1
0
 def __init__(self, *, host=None, port=None,
              unixsock, event_dispatcher, proto):
     super().__init__()
     self.unixsock = unixsock
     self.request_id = 0
     self.last_seq = 0
     self.epoch = 0
     self.event_dispatcher = event_dispatcher
     self.proto = proto
     self.errors = proto.subprotos['xproto'].errors_by_num.copy()
     if unixsock:
         self._sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
     else:
         self._sock = socket.socket(socket.AF_INET,
             socket.SOCK_STREAM, socket.IPPROTO_TCP)
     setcloexec(self._sock)
     self._sock.setblocking(0)
     try:
         if unixsock:
             self._sock.connect(unixsock)
         else:
             self._sock.connect((host, port))
     except socket.error as e:
         if e.errno == errno.EINPROGRESS:
             gethub().do_write(self._sock)
         else:
             raise
     self._start()
示例#2
0
 def __zorro_di_done__(self):
     bar = self.theme.bar
     self.padding = bar.box_padding
     self.graph_color = bar.graph_color_pat
     self.fill_color = bar.graph_fill_color_pat
     self.line_width = bar.graph_line_width
     gethub().do_spawnhelper(self._update_handler)
示例#3
0
 def __init__(self,
              *,
              host=None,
              port=None,
              unixsock,
              event_dispatcher,
              proto):
     super().__init__()
     self.unixsock = unixsock
     self.request_id = 0
     self.last_seq = 0
     self.epoch = 0
     self.event_dispatcher = event_dispatcher
     self.proto = proto
     self.errors = proto.subprotos['xproto'].errors_by_num.copy()
     if unixsock:
         self._sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
     else:
         self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM,
                                    socket.IPPROTO_TCP)
     setcloexec(self._sock)
     self._sock.setblocking(0)
     try:
         if unixsock:
             self._sock.connect(unixsock)
         else:
             self._sock.connect((host, port))
     except socket.error as e:
         if e.errno == errno.EINPROGRESS:
             gethub().do_write(self._sock)
         else:
             raise
     self._start()
示例#4
0
 def __zorro_di_done__(self):
     bar = self.theme.bar
     self.padding = bar.box_padding
     self.graph_color = bar.graph_color_pat
     self.fill_color = bar.graph_fill_color_pat
     self.line_width = bar.graph_line_width
     gethub().do_spawnhelper(self._update_handler)
示例#5
0
    def sender(self):
        buf = bytearray()

        add_chunk = buf.extend
        wait_write = gethub().do_write

        while True:
            if not buf:
                self.wait_requests()
            if not self._alive:
                return
            wait_write(self._sock)
            for inp, fut, tb in self.get_pending_requests():
                self._producing.append((self.request_id, fut, tb))
                self.request_id += 1
                add_chunk(inp)
            try:
                bytes = self._sock.send(buf)
            except socket.error as e:
                if e.errno in (errno.EAGAIN, errno.EINTR):
                    continue
                else:
                    raise
            if not bytes:
                raise EOFError()
            del buf[:bytes]
示例#6
0
    def sender(self):
        buf = bytearray()

        add_chunk = buf.extend
        wait_write = gethub().do_write

        while True:
            if not buf:
                self.wait_requests()
            if not self._alive:
                return
            wait_write(self._sock)
            for inp, fut, tb in self.get_pending_requests():
                self._producing.append((self.request_id, fut, tb))
                self.request_id += 1
                add_chunk(inp)
            try:
                bytes = self._sock.send(buf)
            except socket.error as e:
                if e.errno in (errno.EAGAIN, errno.EINTR):
                    continue
                else:
                    raise
            if not bytes:
                raise EOFError()
            del buf[:bytes]
示例#7
0
def fetchurl(url, query=None):
    if query is not None:
        assert '?' not in url, ("Either include query in url"
                                "or pass as parameter, but not both")
        url += '?' + urlencode(query)
    proto, tail = splittype(url)
    if proto != 'http':
        raise RuntimeError("Unsupported protocol HTTP")
    host, tail = splithost(tail)
    ip = gethub().dns_resolver.gethostbyname(host)
    cli = HTTPClient(ip)
    resp = cli.request(tail, headers={'Host': host})
    if resp.status.endswith('200 OK'):
        return resp.body
    raise RequestError(resp.status, resp)
示例#8
0
 def __zorro_di_done__(self):
     bar = self.theme.bar
     self.font = bar.font
     self.color = bar.text_color_pat
     self.padding = bar.text_padding
     gethub().do_spawnhelper(self._update_handler)
示例#9
0
    def run(self):
        signal.signal(signal.SIGCHLD, child_handler)
        signal.signal(signal.SIGQUIT, quit_handler)

        proto = Proto()
        proto.load_xml("xproto")
        proto.load_xml("xtest")
        proto.load_xml("xinerama")
        proto.load_xml("shm")
        proto.load_xml("randr")
        self.conn = conn = Connection(proto)
        conn.connection()
        self.root_window = Root(conn.init_data["roots"][0]["root"])

        inj = DependencyInjector()
        inj["dns"] = dns.Resolver(dns.Config.system_config())
        gethub().dns_resolver = inj["dns"]
        inj["xcore"] = xcore = Core(conn)
        inj["keysyms"] = keysyms = Keysyms()
        keysyms.load_default()

        cfg = inj["config"] = inj.inject(Config())
        cfg.init_extensions()

        # Hack, but this only makes GetScreenInfo work
        xcore.randr._proto.requests["GetScreenInfo"].reply.items["rates"].code = compile("0", "XPROTO", "eval")
        if cfg["auto-screen-configuration"]:
            if randr.check_screens(xcore):
                randr.configure_outputs(xcore, cfg["screen-dpi"] / 25.4)

        inj["theme"] = inj.inject(cfg.theme())
        inj["commander"] = cmd = inj.inject(CommandDispatcher())
        if hasattr(xcore, "randr"):
            NM = xcore.randr.NotifyMask
            # We only poll for events and use Xinerama for screen querying
            # because some drivers (nvidia) doesn't provide xrandr data
            # correctly
            xcore.randr.SelectInput(
                window=xcore.root_window, enable=NM.ScreenChange | NM.CrtcChange | NM.OutputChange | NM.OutputProperty
            )

        if hasattr(xcore, "xinerama"):
            info = xcore.xinerama.QueryScreens()["screen_info"]
            screenman = inj["screen-manager"] = ScreenManager(
                [Rectangle(scr["x_org"], scr["y_org"], scr["width"], scr["height"]) for scr in info]
            )
        else:
            screenman = inj["screen-manager"] = ScreenManager(
                [Rectangle(0, 0, xcore.root["width_in_pixels"], xcore.root["height_in_pixels"])]
            )
        inj.inject(screenman)

        cmd["tilenol"] = self
        keys = KeyRegistry()
        inj["key-registry"] = inj.inject(keys)
        mouse = MouseRegistry()
        inj["mouse-registry"] = inj.inject(mouse)
        inj["gestures"] = inj.inject(Gestures())

        gman = inj.inject(GroupManager(map(inj.inject, cfg.groups())))
        cmd["groups"] = gman
        inj["group-manager"] = gman

        rules = inj["classifier"] = inj.inject(Classifier())
        for cls, cond, act in cfg.rules():
            rules.add_rule(cond, act, klass=cls)

        eman = inj.inject(EventDispatcher())
        eman.all_windows[self.root_window.wid] = self.root_window
        inj["event-dispatcher"] = eman
        inj["ewmh"] = Ewmh()
        inj.inject(inj["ewmh"])

        inj.inject(self)

        cmd["env"] = EnvCommands()
        cmd["emul"] = inj.inject(EmulCommands())

        # Register hotkeys as mapping notify can be skipped on inplace restart
        keys.configure_hotkeys()

        mouse.init_buttons()
        mouse.register_buttons(self.root_window)
        self.setup_events()

        for screen_no, bar in cfg.bars():
            inj.inject(bar)
            if screen_no < len(screenman.screens):
                scr = screenman.screens[screen_no]
                if bar.position == "bottom":
                    scr.add_bottom_bar(bar)
                else:
                    scr.add_top_bar(bar)
                bar.create_window()
                scr.updated.listen(bar.redraw.emit)

        self.register_gadgets()

        self.catch_windows()
        self.loop()
示例#10
0
    def receiver(self):
        buf = bytearray()

        sock = self._sock
        wait_read = gethub().do_read
        add_chunk = buf.extend
        pos = 0

        while True:
            wait_read(sock)
            try:
                bytes = sock.recv(self.BUFSIZE)
                if not bytes:
                    raise EOFError()
                add_chunk(bytes)
            except socket.error as e:
                if e.errno in (errno.EAGAIN, errno.EINTR):
                    continue
                else:
                    raise
            if len(buf) - pos >= 8:
                res, maj, min, ln = struct.unpack_from('<BxHHH', buf, pos)
                ln = ln * 4 + 8
                if len(buf) - pos < ln:
                    continue
                self._producing.popleft()[1].set(buf[pos:pos + ln])
                pos += ln
                break

        while True:
            if pos * 2 > len(buf):
                del buf[:pos]
                pos = 0
            wait_read(sock)
            try:
                bytes = sock.recv(self.BUFSIZE)
                if not bytes:
                    raise EOFError()
                add_chunk(bytes)
            except socket.error as e:
                if e.errno in (errno.EAGAIN, errno.EINTR):
                    continue
                else:
                    raise
            while len(buf) - pos >= 8:
                opcode, seq, ln = struct.unpack_from('<BxHL', buf, pos)
                if opcode != 1:
                    if len(buf) - pos < 32:
                        break
                    val = buf[pos:pos + 2] + buf[pos + 4:pos + 32]
                    pos += 32
                    if opcode > 1:
                        self.event_dispatcher(seq, buf[pos - 32:pos])
                        continue
                else:
                    ln = ln * 4 + 32
                    if len(buf) - pos < ln:
                        break
                    val = buf[pos:pos + 2] + buf[pos + 8:pos + ln]
                    pos += ln
                self.produce(seq, val)
示例#11
0
    def receiver(self):
        buf = bytearray()

        sock = self._sock
        wait_read = gethub().do_read
        add_chunk = buf.extend
        pos = 0

        while True:
            wait_read(sock)
            try:
                bytes = sock.recv(self.BUFSIZE)
                if not bytes:
                    raise EOFError()
                add_chunk(bytes)
            except socket.error as e:
                if e.errno in (errno.EAGAIN, errno.EINTR):
                    continue
                else:
                    raise
            if len(buf)-pos >= 8:
                res, maj, min, ln = struct.unpack_from('<BxHHH', buf, pos)
                ln = ln*4+8
                if len(buf)-pos < ln:
                    continue
                self._producing.popleft()[1].set(buf[pos:pos+ln])
                pos += ln
                break

        while True:
            if pos*2 > len(buf):
                del buf[:pos]
                pos = 0
            wait_read(sock)
            try:
                bytes = sock.recv(self.BUFSIZE)
                if not bytes:
                    raise EOFError()
                add_chunk(bytes)
            except socket.error as e:
                if e.errno in (errno.EAGAIN, errno.EINTR):
                    continue
                else:
                    raise
            while len(buf)-pos >= 8:
                opcode, seq, ln = struct.unpack_from('<BxHL', buf, pos)
                if opcode != 1:
                    if len(buf) - pos < 32:
                        break
                    val = buf[pos:pos+2] + buf[pos+4:pos+32]
                    pos += 32
                    if opcode > 1:
                        self.event_dispatcher(seq, buf[pos-32:pos])
                        continue
                else:
                    ln = ln*4+32
                    if len(buf)-pos < ln:
                        break
                    val = buf[pos:pos+2] + buf[pos+8:pos+ln]
                    pos += ln
                self.produce(seq, val)
示例#12
0
 def __zorro_di_done__(self):
     self.cfg = self.config.gestures()
     gethub().do_spawnhelper(self._shm_checker)
示例#13
0
 def __zorro_di_done__(self):
     self.cfg = self.config.gestures()
     gethub().do_spawnhelper(self._shm_checker)
示例#14
0
文件: clock.py 项目: rmsilva/tilenol
 def __zorro_di_done__(self):
     bar = self.theme.bar
     self.font = bar.font
     self.color = bar.text_color_pat
     self.padding = bar.text_padding
     gethub().do_spawnhelper(self._update_time)
示例#15
0
    def run(self):
        signal.signal(signal.SIGCHLD, child_handler)
        signal.signal(signal.SIGQUIT, quit_handler)

        proto = Proto()
        proto.load_xml('xproto')
        proto.load_xml('xtest')
        proto.load_xml('xinerama')
        proto.load_xml('shm')
        proto.load_xml('randr')
        self.conn = conn = Connection(proto)
        conn.connection()
        self.root_window = Root(conn.init_data['roots'][0]['root'])

        inj = DependencyInjector()
        inj['dns'] = dns.Resolver(dns.Config.system_config())
        gethub().dns_resolver = inj['dns']
        inj['xcore'] = xcore = Core(conn)
        inj['keysyms'] = keysyms = Keysyms()
        keysyms.load_default()

        cfg = inj['config'] = inj.inject(Config())
        cfg.init_extensions()

        # Hack, but this only makes GetScreenInfo work
        xcore.randr._proto.requests['GetScreenInfo'].reply.items['rates'].code\
            = compile('0', 'XPROTO', 'eval')
        if cfg['auto-screen-configuration']:
            if randr.check_screens(xcore):
                randr.configure_outputs(xcore, cfg['screen-dpi'] / 25.4)

        inj['theme'] = inj.inject(cfg.theme())
        inj['commander'] = cmd = inj.inject(CommandDispatcher())
        if hasattr(xcore, 'randr'):
            NM = xcore.randr.NotifyMask
            # We only poll for events and use Xinerama for screen querying
            # because some drivers (nvidia) doesn't provide xrandr data
            # correctly
            xcore.randr.SelectInput(window=xcore.root_window,
                                    enable=NM.ScreenChange | NM.CrtcChange
                                    | NM.OutputChange | NM.OutputProperty)

        if hasattr(xcore, 'xinerama'):
            info = xcore.xinerama.QueryScreens()['screen_info']
            screenman = inj['screen-manager'] = ScreenManager([
                Rectangle(scr['x_org'], scr['y_org'], scr['width'],
                          scr['height']) for scr in info
            ])
        else:
            screenman = inj['screen-manager'] = ScreenManager([
                Rectangle(0, 0, xcore.root['width_in_pixels'],
                          xcore.root['height_in_pixels'])
            ])
        inj.inject(screenman)

        cmd['tilenol'] = self
        keys = KeyRegistry()
        inj['key-registry'] = inj.inject(keys)
        mouse = MouseRegistry()
        inj['mouse-registry'] = inj.inject(mouse)
        inj['gestures'] = inj.inject(Gestures())

        gman = inj.inject(GroupManager(map(inj.inject, cfg.groups())))
        cmd['groups'] = gman
        inj['group-manager'] = gman

        rules = inj['classifier'] = inj.inject(Classifier())
        for cls, cond, act in cfg.rules():
            rules.add_rule(cond, act, klass=cls)

        eman = inj.inject(EventDispatcher())
        eman.all_windows[self.root_window.wid] = self.root_window
        inj['event-dispatcher'] = eman
        inj['ewmh'] = Ewmh()
        inj.inject(inj['ewmh'])

        inj.inject(self)

        cmd['env'] = EnvCommands()
        cmd['emul'] = inj.inject(EmulCommands())

        # Register hotkeys as mapping notify can be skipped on inplace restart
        keys.configure_hotkeys()

        mouse.init_buttons()
        mouse.register_buttons(self.root_window)
        self.setup_events()

        for screen_no, bar in cfg.bars():
            inj.inject(bar)
            if screen_no < len(screenman.screens):
                scr = screenman.screens[screen_no]
                if bar.position == 'bottom':
                    scr.add_bottom_bar(bar)
                else:
                    scr.add_top_bar(bar)
                bar.create_window()
                scr.updated.listen(bar.redraw.emit)

        self.register_gadgets()

        self.catch_windows()
        self.loop()
示例#16
0
文件: main.py 项目: UltraHex/tilenol
    def run(self):
        signal.signal(signal.SIGCHLD, child_handler)
        signal.signal(signal.SIGQUIT, quit_handler)

        proto = Proto()
        proto.load_xml('xproto')
        proto.load_xml('xtest')
        proto.load_xml('xinerama')
        proto.load_xml('shm')
        proto.load_xml('randr')
        self.conn = conn = Connection(proto)
        conn.connection()
        self.root_window = Root(conn.init_data['roots'][0]['root'])

        inj = DependencyInjector()
        inj['dns'] = dns.Resolver(dns.Config.system_config())
        gethub().dns_resolver = inj['dns']
        inj['xcore'] = xcore = Core(conn)
        inj['keysyms'] = keysyms = Keysyms()
        keysyms.load_default()


        cfg = inj['config'] = inj.inject(Config())
        cfg.init_extensions()

        # Hack, but this only makes GetScreenInfo work
        xcore.randr._proto.requests['GetScreenInfo'].reply.items['rates'].code\
            = compile('0', 'XPROTO', 'eval')
        if cfg['auto-screen-configuration']:
            if randr.check_screens(xcore):
                randr.configure_outputs(xcore, cfg['screen-dpi']/25.4)

        inj['theme'] = inj.inject(cfg.theme())
        inj['commander'] = cmd = inj.inject(CommandDispatcher())
        if hasattr(xcore, 'randr'):
            NM = xcore.randr.NotifyMask
            # We only poll for events and use Xinerama for screen querying
            # because some drivers (nvidia) doesn't provide xrandr data
            # correctly
            xcore.randr.SelectInput(
                window=xcore.root_window,
                enable=NM.ScreenChange | NM.CrtcChange | NM.OutputChange | NM.OutputProperty)

        if hasattr(xcore, 'xinerama'):
            info = xcore.xinerama.QueryScreens()['screen_info']
            screenman = inj['screen-manager'] = ScreenManager([
                Rectangle(scr['x_org'], scr['y_org'],
                    scr['width'], scr['height'])
                for scr in info])
        else:
            screenman = inj['screen-manager'] = ScreenManager([Rectangle(0, 0,
                xcore.root['width_in_pixels'],
                xcore.root['height_in_pixels'])])
        inj.inject(screenman)

        cmd['tilenol'] = self
        keys = KeyRegistry()
        inj['key-registry'] = inj.inject(keys)
        mouse = MouseRegistry()
        inj['mouse-registry'] = inj.inject(mouse)
        inj['gestures'] = inj.inject(Gestures())

        gman = inj.inject(GroupManager(map(inj.inject, cfg.groups())))
        cmd['groups'] = gman
        inj['group-manager'] = gman

        rules = inj['classifier'] = inj.inject(Classifier())
        for cls, cond, act in cfg.rules():
            rules.add_rule(cond, act, klass=cls)

        eman = inj.inject(EventDispatcher())
        eman.all_windows[self.root_window.wid] = self.root_window
        inj['event-dispatcher'] = eman
        inj['ewmh'] = Ewmh()
        inj.inject(inj['ewmh'])

        inj.inject(self)

        cmd['env'] = EnvCommands()
        cmd['emul'] = inj.inject(EmulCommands())

        # Register hotkeys as mapping notify can be skipped on inplace restart
        keys.configure_hotkeys()

        mouse.init_buttons()
        mouse.register_buttons(self.root_window)
        self.setup_events()

        for screen_no, bar in cfg.bars():
            inj.inject(bar)
            if screen_no < len(screenman.screens):
                scr = screenman.screens[screen_no]
                if bar.position == 'bottom':
                    scr.add_bottom_bar(bar)
                else:
                    scr.add_top_bar(bar)
                bar.create_window()
                scr.updated.listen(bar.redraw.emit)

        self.register_gadgets()

        self.catch_windows()
        self.loop()
示例#17
0
 def emit(self):
     log.debug("Emitting event %r", self.name)
     if self._worker is None and self._listeners:
         self._worker = gethub().do_spawn(self._do_work)