Exemple #1
0
def main(socket, type, timeout, message):
    """
    Excepts arguments and evaluates them.
    """
    if not socket:
        socket = i3.get_socket_path()
        if not socket:
            print("Couldn't get socket path. Are you sure i3 is running?")
            return False
    # Initializes default socket with given path and timeout
    try:
        i3.default_socket(i3.Socket(path=socket, timeout=timeout))
    except i3.ConnectionError:
        print("Couldn't connect to socket at '%s'." % socket)
        return False
    # Format input
    if type in i3.EVENT_TYPES:
        event_type = type
        event = message
        type = 'subscribe'
    elif type == 'subscribe':
        message = message.split(' ')
        message_len = len(message)
        if message_len >= 1:
            event_type = message[0]
            if message_len >= 2:
                event = ' '.join(message[1:])
            else:
                event = ''
        else:
            # Let if fail
            event_type = ''
    try:
        if type == 'subscribe':
            i3.subscribe(event_type, event)
        else:
            output = i3.msg(type, message)
            print(output)
    except i3.i3Exception as i3error:
        print(i3error)
Exemple #2
0
def main(socket, type, timeout, message):
    """
    Excepts arguments and evaluates them.
    """
    if not socket:
        socket = i3.get_socket_path()
        if not socket:
            print("Couldn't get socket path. Are you sure i3 is running?")
            return False
    # Initializes default socket with given path and timeout
    try:
        i3.default_socket(i3.Socket(path=socket, timeout=timeout))
    except i3.ConnectionError:
        print("Couldn't connect to socket at '%s'." % socket)
        return False
    # Format input
    if type in i3.EVENT_TYPES:
        event_type = type
        event = message
        type = 'subscribe'
    elif type == 'subscribe':
        message = message.split(' ')
        message_len = len(message)
        if message_len >= 1:
            event_type = message[0]
            if message_len >= 2:
                event = ' '.join(message[1:])
            else:
                event = ''
        else:
            # Let if fail
            event_type = ''
    try:
        if type == 'subscribe':
            i3.subscribe(event_type, event)
        else:
            output = i3.msg(type, message)
            print(output)
    except i3.i3Exception as i3error:
        print(i3error)
Exemple #3
0
 def test_getattr(self):
     func = i3.some_attribute
     self.assertTrue(callable(func))
     socket = i3.default_socket()
     self.assertIsInstance(socket, i3.Socket)
Exemple #4
0
 def test_pack(self):
     packed = i3.default_socket().pack(0, "haha")
     if py3:
         self.assertIsInstance(packed, bytes)
Exemple #5
0
 def test_response(self, socket=i3.default_socket()):
     workspaces = socket.get('get_workspaces')
     self.assertIsNotNone(workspaces)
     for workspace in workspaces:
         self.assertTrue('name' in workspace)
Exemple #6
0
 def test_getattr(self):
     func = i3.some_attribute
     self.assertTrue(callable(func))
     socket = i3.default_socket()
     self.assertIsInstance(socket, i3.Socket)
Exemple #7
0
 def test_pack(self):
     packed = i3.default_socket().pack(0, "haha")
     if py3:
         self.assertIsInstance(packed, bytes)
Exemple #8
0
 def test_response(self, socket=i3.default_socket()):
     workspaces = socket.get('get_workspaces')
     self.assertIsNotNone(workspaces)
     for workspace in workspaces:
         self.assertTrue('name' in workspace)