Example #1
0
File: ashdi.py Project: sjp38/ash
 def mousePressed(self, event):
     x = event.getX() * 100.0 / event.getComponent().getWidth()
     y = event.getY() * 100.0 / event.getComponent().getHeight()
     ashval.ashval("show_cursor %d %d 1 pressed" % (x, y))
     ashval.ashval("touch DOWN %d %d 1" % (x, y))
     self.time1 = time.time()
     self.xy1 = (x, y)
Example #2
0
File: ashdi.py Project: sjp38/ash
def check_move_support():
    global support_move
    support_move = True
    try:
        ashval.ashval("touch MOVE 1 1 1")
    except AttributeError:
        support_move = False
Example #3
0
File: ashdi.py Project: sjp38/ash
def handleKeyButton(event):
    if event.getActionCommand() == "WAKE":
        ashval.ashval("wake")
    else:
        cmd = "press DOWN_AND_UP %s" % event.getActionCommand()
        cmd = cmd.encode("utf-8")
        result = ashval.ashval(cmd)
        notifyResult(result)
Example #4
0
File: ashdi.py Project: sjp38/ash
 def mouseWheelMoved(self, event):
     notches = event.getWheelRotation()
     direction = ""
     if notches < 0:
         direction = "DPAD_UP"
     else:
         direction = "DPAD_DOWN"
     ashval.ashval("press DOWN_AND_UP %s" % direction)
Example #5
0
    def test_raw_ashval(self):
        question = "click [100 200]"
        right_answer = ["click", ["100", "200"]]
        self.assertEqual(ashval.ashval(question), right_answer)

        question = "test [100 [100 200] [ [100 200] 300] [400]] [ [200] ]"
        right_answer = ["test", ["100", ["100", "200"],
            [["100", "200"], "300"], ["400"]], [["200"]]]
        self.assertEqual(ashval.ashval(question), right_answer)
Example #6
0
File: ashdi.py Project: sjp38/ash
    def mouseDragged(self, event):
        x = event.getX() * 100.0 / event.getComponent().getWidth()
        y = event.getY() * 100.0 / event.getComponent().getHeight()

        if support_move:
            ashval.ashval("touch MOVE %d %d 1" % (x,y))
        ashval.ashval("show_cursor %d %d 1 pressed" % (x,y))
        if not support_move:
            self.dragging = True
Example #7
0
File: ash.py Project: sjp38/ash
def _get_and_process_user_input():
    user_input = _get_expression()
    if user_input == "":
        # TODO: print help message.
        return
    result = None
    if modglob._conn_to_ashmon:
        modglob.sock.sendall(user_input + ashmon.END_OF_MSG)
        tokens = ""
        while True:
            received = modglob.sock.recv(1024)
            if not received or not modglob._conn_to_ashmon:
                print "connection crashed!"
                modglob.sock.close()
                modglob.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                modglob.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

                modglob._conn_to_ashmon = False
                break
            msgs, tokens = ashmon.get_complete_message(received, tokens)
            for msg in msgs:
                result = eval(msg)
                break
    else:
        result = ashval.ashval(user_input)

    if result:
        print_result(result)
Example #8
0
File: ashdi.py Project: sjp38/ash
def handleFocusBtn(event):
    selectedIndices = devicesList.getSelectedIndices()
    args = ""
    for selected in selectedIndices:
        args += "%d " % selected
    result = ashval.ashval("focus %s" % args)
    notifyResult(result)
    handleConnectedDevBtn(True)
Example #9
0
 def test_event(self):
     data.clear()
     data.add_callback("", "typeB", "valueC",
             [
                 ["_mock_function",
                     ["arg", "1"], ["arg", "2"], ["arg", "3"]]
             ])
     self.assertEqual(ashval.ashval("event default typeB valueC 10 20 33"),
             "_mock_function : 10, 20, 33")
Example #10
0
File: ashdi.py Project: sjp38/ash
def handleTerminalInput(event):
    global terminalInput
    userInput = terminalInput.getText()
    userInput = userInput.encode("utf-8")
    terminalInput.setText("")
    if not userInput:
        # TODO: Show manual.
        return
    result = ashval.ashval(userInput)
    if result:
        notifyResult(result)
Example #11
0
File: ashdi.py Project: sjp38/ash
    def processKey(self, event, isDown):
        keyCode = event.getKeyCode()
        keyInput = event.getKeyText(event.getKeyCode()).upper()

        if KEYCODE_MAP.has_key(keyCode):
            keyInput = KEYCODE_MAP[keyCode]

        if FUNCTION_KEY_MAP.has_key(keyInput):
            keyInput = FUNCTION_KEY_MAP[keyInput]


        keyValue = keyInput
        if isDown:
            if self.metaKeyState.has_key(keyValue):
                self.metaKeyState[keyValue] = True
            elif self.metaKeyState["SHIFT"]:
                keyValue = "Shift-" + keyValue
            elif self.metaKeyState["ALT"]:
                keyValue = "Alt-" + keyValue
            elif self.metaKeyState["CTRL"]:
                keyValue = "Ctrl-" + keyValue
            keyValue = keyValue + "_DOWN"
        else:
            if self.metaKeyState.has_key(keyValue):
                self.metaKeyState[keyValue] = False
            keyValue = keyValue + "_UP"

        keyValue = keyValue.encode('utf8')
        keyInput = keyInput.encode('utf8')
        code = ashval.ashval("get_callback default keyboard %s" % keyValue)
        if code and code != data.NO_CALLBACK:
            ashval.ashval("event default keyboard %s" % keyValue)
        else:
            if self.metaKeyState.has_key(keyInput):
                keyInput = keyInput + "_LEFT"
            if isDown: action = "DOWN"
            else: action = "UP"
            ashval.ashval("press %s %s" % (action, keyInput))
Example #12
0
File: ashdi.py Project: sjp38/ash
 def mouseReleased(self, event):
     x = event.getX() * 100.0 / event.getComponent().getWidth()
     y = event.getY() * 100.0 / event.getComponent().getHeight()
     ashval.ashval("show_cursor %d %d 1" % (x, y))
     if self.dragging:
         self.dragging = False
         time2 = time.time()
         ashval.ashval("drag %d %d %d %d 1 %f" % (
             self.xy1[0], self.xy1[1], x, y, time2 - self.time1))
         return
     ashval.ashval("touch UP %d %d 1" % (x, y))
Example #13
0
    def test_ashval_function(self):
        data.add_callback("", "alias", "c",
                [
                    ["_mock_function",
                        ["arg", "1"], ["arg", "2"], ["arg", "3"]]
                ])
        self.assertEqual(ashval.ashval("c 100 200 300"),
                "_mock_function : 100, 200, 300")
        self.assertEqual(ashval.ashval("c 110 0 350"),
                "_mock_function : 110, 0, 350")

        data.add_callback("", "alias", "d",
                [
                    ["_mock_function",
                        ["arg", "1"], ["arg", "2"], ["arg", "3"]],
                    ["_mock_function",
                        ["arg", "2"], ["arg", "3"], ["arg", "1"]]
                ])
        self.assertEqual(ashval.ashval("d 100 200 300"),
                "_mock_function : 200, 300, 100")
        self.assertEqual(ashval.ashval("d 110 0 350"),
                "_mock_function : 0, 350, 110")

        data.add_callback("", "alias", "d",
                [
                    ["_mock_function",
                        ["arg", "1"], ["arg", "2"], ["arg", "3"]],
                    ["c",
                        ["arg", "2"], ["arg", "3"], ["arg", "1"]]
                ])
        print data._callbacks[data.DEFAULT_EVENT_MODE]["alias"]
        self.assertEqual(ashval.ashval("d 100 200 300"),
                "_mock_function : 200, 300, 100")
        self.assertEqual(ashval.ashval("d 110 0 350"),
                "_mock_function : 0, 350, 110")

        self.assertTrue(ashval.ashval("a b c [[d] [e]]"))
        self.assertTrue(ashval.ashval("_mock_function [[d] [e]] f g"))
Example #14
0
File: ashdi.py Project: sjp38/ash
def handleConnectBtn(event):
    selectedIndices = devicesList.getSelectedIndices()
    for selected in selectedIndices:
        result = ashval.ashval("connect %d" % selected)
        notifyResult(result)
Example #15
0
File: ash.py Project: sjp38/ash
def input(expr):
    return ashval.ashval(expr)
Example #16
0
File: ash.py Project: sjp38/ash
    if modglob._conn_to_ashmon:
        modglob.sock.sendall(user_input + ashmon.END_OF_MSG)
        tokens = ""
        while True:
            received = modglob.sock.recv(1024)
            if not received or not modglob._conn_to_ashmon:
                print "connection crashed!"
                modglob.sock.close()
                modglob.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                modglob.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

                modglob._conn_to_ashmon = False
                break
            msgs, tokens = ashmon.get_complete_message(received, tokens)
            for msg in msgs:
                result = eval(msg)
                break
    else:
        result = ashval.ashval(user_input)

    if result:
        print_result(result)


if __name__ == "__main__":
    if len(sys.argv) >= 2:
        init_cmd = "exec_script " + sys.argv[1]
        ashval.ashval(init_cmd)
    while 1:
        _get_and_process_user_input()
Example #17
0
File: ashdi.py Project: sjp38/ash
 def run(self):
     while True:
         if _stop_android_waker:
             break
         ashval.ashval("wake")
         time.sleep(5)
Example #18
0
File: ashdi.py Project: sjp38/ash
def handleConnectedDevBtn(event):
    connectButton.setVisible(False)
    focusButton.setVisible(True)
    devices = ashval.ashval("connected_devices")
    listDevices(devices)
Example #19
0
    def test_record(self):
        data.add_callback("", "alias", "c",
                [
                    ["_mock_function",
                        ["arg", "1"], ["arg", "2"], ["arg", "3"]]
                ])

        ashval.ashval("record abc")
        ashval.ashval("c 100 200 300")
        ashval.ashval("c 200 200 300")
        ashval.ashval("c 100 200 300")
        ashval.ashval("record_stop")
        self.assertEqual(ashval.ashval("abc"),
                "_mock_function : 100, 200, 300")
Example #20
0
File: ashdi.py Project: sjp38/ash
    def mouseMoved(self, event):
        x = event.getX() * 100.0 / event.getComponent().getWidth()
        y = event.getY() * 100.0 / event.getComponent().getHeight()

        ashval.ashval("show_cursor %d %d 1" % (int(x), int(y)))
        devicesListLabel.setText("%s / %s" % (int(x), int(y)))
Example #21
0
File: ashdi.py Project: sjp38/ash
def handleAllDevsBtn(event):
    connectButton.setVisible(True)
    focusButton.setVisible(False)
    devices = ashval.ashval("devices")
    listDevices(devices)