diff --git a/build.gradle.kts b/build.gradle.kts
index 8b3ed5d..e304ac1 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -5,7 +5,7 @@ plugins {
}
group = "io.github.codegrits"
-version = "0.3.2"
+version = "0.3.2-dev1"
repositories {
mavenCentral()
diff --git a/src/main/java/trackers/EyeTracker.java b/src/main/java/trackers/EyeTracker.java
index 207026e..beffbfb 100644
--- a/src/main/java/trackers/EyeTracker.java
+++ b/src/main/java/trackers/EyeTracker.java
@@ -9,6 +9,7 @@
import com.intellij.openapi.fileEditor.FileEditorManagerEvent;
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.Computable;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
@@ -61,6 +62,12 @@ public class EyeTracker implements Disposable {
String pythonScriptTobii;
String pythonScriptMouse;
int deviceIndex = 0;
+ /**
+ * This variable indicates whether the gaze coordinates are normalized to the screen size,
+ * that is returned as values between (0, 0) for the upper left corner and (1, 1) for the lower right corner.
+ * See, for example, 'Coordinate system' page in Tobii Pro SDK documentation
+ */
+ boolean isGazeNormalized = true;
/**
* This variable indicates whether the real-time data is transmitting.
@@ -216,15 +223,21 @@ public void processRawData(String message) {
return;
}
- int eyeX = (int) ((Double.parseDouble(leftGazePointX) + Double.parseDouble(rightGazePointX)) / 2 * screenWidth);
- int eyeY = (int) ((Double.parseDouble(leftGazePointY) + Double.parseDouble(rightGazePointY)) / 2 * screenHeight);
+ int eyeX, eyeY;
+ if (isGazeNormalized) {
+ eyeX = (int) ((Double.parseDouble(leftGazePointX) + Double.parseDouble(rightGazePointX)) / 2 * screenWidth);
+ eyeY = (int) ((Double.parseDouble(leftGazePointY) + Double.parseDouble(rightGazePointY)) / 2 * screenHeight);
+ } else {
+ eyeX = (int) ((Double.parseDouble(leftGazePointX) + Double.parseDouble(rightGazePointX)) / 2);
+ eyeY = (int) ((Double.parseDouble(leftGazePointY) + Double.parseDouble(rightGazePointY)) / 2);
+ }
int editorX, editorY;
try {
editorX = editor.getContentComponent().getLocationOnScreen().x;
editorY = editor.getContentComponent().getLocationOnScreen().y;
} catch (IllegalComponentStateException e) {
- gaze.setAttribute("remark", "Fail | No Editor");
+ gaze.setAttribute("remark", "Fail | IllegalComponentStateException in Editor");
return;
}
int relativeX = eyeX - editorX;
@@ -250,7 +263,9 @@ public void processRawData(String message) {
location.setAttribute("column", String.valueOf(logicalPosition.column));
location.setAttribute("path", RelativePathGetter.getRelativePath(filePath, projectPath));
gaze.appendChild(location);
- Element aSTStructure = getASTStructureElement(psiElement);
+ Element aSTStructure = ApplicationManager.getApplication().runReadAction(
+ (Computable) () -> getASTStructureElement(psiElement)
+ );
gaze.appendChild(aSTStructure);
lastElement = psiElement;
// System.out.println(gaze.getAttribute("timestamp") + " " + System.currentTimeMillis());
diff --git a/src/main/java/utils/AvailabilityChecker.java b/src/main/java/utils/AvailabilityChecker.java
index a47f51f..72af8a7 100644
--- a/src/main/java/utils/AvailabilityChecker.java
+++ b/src/main/java/utils/AvailabilityChecker.java
@@ -19,7 +19,6 @@ public class AvailabilityChecker {
*/
public static boolean checkPythonEnvironment(String pythonInterpreter) throws IOException, InterruptedException {
String pythonScript = """
- import tobii_research as tr
from screeninfo import get_monitors
import pyautogui
import time
@@ -41,13 +40,17 @@ public static boolean checkPythonEnvironment(String pythonInterpreter) throws IO
*/
public static boolean checkEyeTracker(String pythonInterpreter) throws IOException, InterruptedException {
String pythonScript = """
- import tobii_research as tr
+ try:
+ import tobii_research as tr
- found_eyetrackers = tr.find_all_eyetrackers()
- if found_eyetrackers == ():
+ found_eyetrackers = tr.find_all_eyetrackers()
+ if found_eyetrackers == ():
+ print('Not Found')
+ else:
+ print('Found')
+
+ except ImportError:
print('Not Found')
- else:
- print('Found')
""";
String line = runPythonScript(pythonInterpreter, pythonScript);
@@ -62,13 +65,17 @@ public static boolean checkEyeTracker(String pythonInterpreter) throws IOExcepti
*/
public static String getEyeTrackerName(String pythonInterpreter) throws IOException, InterruptedException {
String pythonScript = """
- import tobii_research as tr
+ try:
+ import tobii_research as tr
- found_eyetrackers = tr.find_all_eyetrackers()
- if found_eyetrackers == ():
+ found_eyetrackers = tr.find_all_eyetrackers()
+ if found_eyetrackers == ():
+ print('Not Found')
+ else:
+ print(found_eyetrackers[0].device_name)
+
+ except ImportError:
print('Not Found')
- else:
- print(found_eyetrackers[0].device_name)
""";
return runPythonScript(pythonInterpreter, pythonScript);