-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add pyautogui support * add GetBoundingBox command * add example pyautogui script * travis ci: use focal dist for linux, replace g++5 with g++10
- Loading branch information
Showing
18 changed files
with
231 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import xmlrpc.client | ||
import time | ||
import pyautogui # you might have to first `pip install pyautogui` | ||
|
||
|
||
def clickItem(path): | ||
# Query spix to get the location of the item | ||
bounds = s.getBoundingBox(path) | ||
# bounds = [x, y, width, height] as list | ||
center_x = bounds[0] + bounds[2] / 2 | ||
center_y = bounds[1] + bounds[3] / 2 | ||
|
||
# use pyautogui to move the cursor... | ||
pyautogui.moveTo(center_x, center_y, duration=1) | ||
# ...and click | ||
pyautogui.click() | ||
|
||
|
||
|
||
# Connect to the rpc server running in the qt app | ||
s = xmlrpc.client.ServerProxy('http://localhost:9000') | ||
|
||
# Wait a bit so that the user has time to move the app to the foreground | ||
print("Make sure the qt app is in the foreground... waiting 3s...") | ||
time.sleep(3) | ||
|
||
# Click buttons | ||
clickItem("mainWindow/Button_1") | ||
clickItem("mainWindow/Button_2") | ||
clickItem("mainWindow/Button_2") | ||
clickItem("mainWindow/Button_1") | ||
clickItem("mainWindow/Button_2") | ||
|
||
# Query the qt app for the text contents of the results box | ||
resultText = s.getStringProperty("mainWindow/results", "text") | ||
print("Result:\n{}".format(resultText)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PyAutoGUI==0.9.52 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/*** | ||
* Copyright (C) Falko Axmann. All rights reserved. | ||
* Licensed under the MIT license. | ||
* See LICENSE.txt file in the project root for full license information. | ||
****/ | ||
|
||
#include "GetBoundingBox.h" | ||
|
||
#include <Scene/Scene.h> | ||
|
||
namespace spix { | ||
namespace cmd { | ||
|
||
GetBoundingBox::GetBoundingBox(ItemPath path, std::promise<Rect> promise) | ||
: m_path(std::move(path)) | ||
, m_promise(std::move(promise)) | ||
{ | ||
} | ||
|
||
void GetBoundingBox::execute(CommandEnvironment& env) | ||
{ | ||
auto item = env.scene().itemAtPath(m_path); | ||
|
||
if (item) { | ||
auto value = item->bounds(); | ||
m_promise.set_value(value); | ||
} else { | ||
m_promise.set_value(Rect {0.0, 0.0, 0.0, 0.0}); | ||
env.state().reportError("GetBoundingBox: Item not found: " + m_path.string()); | ||
} | ||
} | ||
|
||
} // namespace cmd | ||
} // namespace spix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/*** | ||
* Copyright (C) Falko Axmann. All rights reserved. | ||
* Licensed under the MIT license. | ||
* See LICENSE.txt file in the project root for full license information. | ||
****/ | ||
|
||
#pragma once | ||
|
||
#include "Command.h" | ||
#include <Spix/Data/Geometry.h> | ||
#include <Spix/Data/ItemPath.h> | ||
|
||
#include <future> | ||
|
||
namespace spix { | ||
namespace cmd { | ||
|
||
class GetBoundingBox : public Command { | ||
public: | ||
GetBoundingBox(ItemPath path, std::promise<Rect> promise); | ||
|
||
void execute(CommandEnvironment& env) override; | ||
|
||
private: | ||
ItemPath m_path; | ||
std::promise<Rect> m_promise; | ||
}; | ||
|
||
} // namespace cmd | ||
} // namespace spix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters