From d634a7372eac946db2b3c3d535d38c67d8a9acc1 Mon Sep 17 00:00:00 2001 From: Oliver Lindemann Date: Tue, 11 Mar 2014 17:08:12 +0100 Subject: [PATCH 01/16] NF: using keywords to detect main files (unchecked) --- expyriment_app/main.py | 47 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/expyriment_app/main.py b/expyriment_app/main.py index 9604852..6e531bc 100644 --- a/expyriment_app/main.py +++ b/expyriment_app/main.py @@ -6,10 +6,7 @@ import expyriment import android - -def main(): - android.init() - +def old_method(): projects = {} for folder in glob.glob("/mnt/*"): if os.path.isdir(folder): @@ -20,6 +17,48 @@ def main(): path = folder + "expyriment/*.py" for pyfile in glob.glob(path): projects[os.path.split(pyfile)[-1]] = pyfile + return projetcs + +def find_tagged_files(folder): + """find all tagged file. + + Returns dict of files + """ + + keywords = ["expyriment", "start(", "initialize("] + rtn = {} + for entry in glob.glob(folder+"/*"): + if os.path.isdir(entry): + rtn.update(find_tagged_files(entry)) + elif entry.endswith(".py") and not \ + os.path.split(entry)[1].startswith("_"): + try: + with open(entry) as fl: + lines = fl.readlines() + except: + lines = "" + cnt = 0 + for key in keywords: + if check_keyword(lines, key): + cnt += 1 + if cnt==len(keywords): + rtn[os.path.split(entry)[-1]] = entry + return rtn + +def check_keyword(lines, keyword): + for l in lines: + if l.find(keyword)>=0: + return True + return False + +def main(): + android.init() + + #projects = old_method() + projects = find_tagged_files("/mnt/sdcard0/expyriment") # TODO not yet checked on Android + projects.update(find_tagged_files("/mnt/sdcard0/expyriment")) + projects.update(find_tagged_files("/mnt/extSdCard/expyriment")) + projects.update(find_tagged_files("/mnt/extSdCard/expyriment")) pygame.font.init() for font in glob.glob("/system/fonts/*"): From 88aec306ceb47ee1d86def8745f2e3e856d39b85 Mon Sep 17 00:00:00 2001 From: Oliver Lindemann Date: Tue, 11 Mar 2014 17:11:46 +0100 Subject: [PATCH 02/16] update --- expyriment_app/main.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/expyriment_app/main.py b/expyriment_app/main.py index 6e531bc..8f95899 100644 --- a/expyriment_app/main.py +++ b/expyriment_app/main.py @@ -19,8 +19,8 @@ def old_method(): projects[os.path.split(pyfile)[-1]] = pyfile return projetcs -def find_tagged_files(folder): - """find all tagged file. +def find_keyword_files(folder): + """find all file with keywords in folder and subfolders Returns dict of files """ @@ -29,7 +29,7 @@ def find_tagged_files(folder): rtn = {} for entry in glob.glob(folder+"/*"): if os.path.isdir(entry): - rtn.update(find_tagged_files(entry)) + rtn.update(find_keyword_files(entry)) elif entry.endswith(".py") and not \ os.path.split(entry)[1].startswith("_"): try: @@ -55,10 +55,10 @@ def main(): android.init() #projects = old_method() - projects = find_tagged_files("/mnt/sdcard0/expyriment") # TODO not yet checked on Android - projects.update(find_tagged_files("/mnt/sdcard0/expyriment")) - projects.update(find_tagged_files("/mnt/extSdCard/expyriment")) - projects.update(find_tagged_files("/mnt/extSdCard/expyriment")) + projects = find_keyword_files("/mnt/sdcard0/expyriment") # TODO not yet checked on Android + projects.update(find_keyword_files("/mnt/sdcard0/expyriment")) + projects.update(find_keyword_files("/mnt/extSdCard/expyriment")) + projects.update(find_keyword_files("/mnt/extSdCard/expyriment")) pygame.font.init() for font in glob.glob("/system/fonts/*"): @@ -80,7 +80,7 @@ def main(): name = ''.join([c.lower() for c in name if c.isalnum()]) pygame.sysfont._addfont(name, bold, italic or oblique, font, pygame.sysfont.Sysfonts) - + aliases = ( ('monospace', 'misc-fixed', 'courier', 'couriernew', 'console', 'fixed', 'mono', 'freemono', 'bitstreamverasansmono', From 8c84bf84c893ca695f6e51901b40f69d94289726 Mon Sep 17 00:00:00 2001 From: Oliver Lindemann Date: Tue, 11 Mar 2014 17:12:36 +0100 Subject: [PATCH 03/16] minor --- expyriment_app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/expyriment_app/main.py b/expyriment_app/main.py index 8f95899..314d05e 100644 --- a/expyriment_app/main.py +++ b/expyriment_app/main.py @@ -20,7 +20,7 @@ def old_method(): return projetcs def find_keyword_files(folder): - """find all file with keywords in folder and subfolders + """find all files with keywords in folder and subfolders Returns dict of files """ From 5f525a3f5729f3145396396dd2928e8ecb892164 Mon Sep 17 00:00:00 2001 From: Oliver Lindemann Date: Wed, 12 Mar 2014 09:27:17 +0100 Subject: [PATCH 04/16] optimize find_keywords --- expyriment_app/main.py | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/expyriment_app/main.py b/expyriment_app/main.py index 314d05e..f6d6d3b 100644 --- a/expyriment_app/main.py +++ b/expyriment_app/main.py @@ -6,19 +6,6 @@ import expyriment import android -def old_method(): - projects = {} - for folder in glob.glob("/mnt/*"): - if os.path.isdir(folder): - for project in glob.glob(folder + "/expyriment/*"): - if os.path.isdir(project): - path = project + "/*.py" - else: - path = folder + "expyriment/*.py" - for pyfile in glob.glob(path): - projects[os.path.split(pyfile)[-1]] = pyfile - return projetcs - def find_keyword_files(folder): """find all files with keywords in folder and subfolders @@ -37,11 +24,12 @@ def find_keyword_files(folder): lines = fl.readlines() except: lines = "" - cnt = 0 + all_keywords_found = True for key in keywords: - if check_keyword(lines, key): - cnt += 1 - if cnt==len(keywords): + if not check_keyword(lines, key): + all_keywords_found = False + break + if all_keywords_found: rtn[os.path.split(entry)[-1]] = entry return rtn @@ -54,7 +42,6 @@ def check_keyword(lines, keyword): def main(): android.init() - #projects = old_method() projects = find_keyword_files("/mnt/sdcard0/expyriment") # TODO not yet checked on Android projects.update(find_keyword_files("/mnt/sdcard0/expyriment")) projects.update(find_keyword_files("/mnt/extSdCard/expyriment")) From 5d1801791b88a2343bfeffa6cbbc38fc9d1cc8b0 Mon Sep 17 00:00:00 2001 From: Oliver Lindemann Date: Wed, 12 Mar 2014 10:32:48 +0100 Subject: [PATCH 05/16] start immediately if one experiment --- expyriment_app/main.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/expyriment_app/main.py b/expyriment_app/main.py index f6d6d3b..3569017 100644 --- a/expyriment_app/main.py +++ b/expyriment_app/main.py @@ -30,15 +30,26 @@ def find_keyword_files(folder): all_keywords_found = False break if all_keywords_found: - rtn[os.path.split(entry)[-1]] = entry + rtn[os.path.split(entry)[-1][:-3]] = entry return rtn def check_keyword(lines, keyword): + """check if keyword occurs in text lines""" for l in lines: if l.find(keyword)>=0: return True return False +def launch_experiment(pyfile, name): + expyriment.stimuli.TextScreen(heading="Starting {0}".format(name), + "").present() + expyriment.misc.Clock().wait(1000) + expyriment.control.defaults.event_logging = 1 + expyriment.control.defaults.initialize_delay = 0 + os.chdir(os.path.split(py_file)[0]) + sys.argv[0] = py_file + execfile("{0}".format(py_file), globals()) + def main(): android.init() @@ -94,25 +105,22 @@ def main(): expyriment.control.defaults.event_logging = 0 exp = expyriment.control.initialize() - mouse = expyriment.io.Mouse(show_cursor=False) if projects == {}: info_box = expyriment.stimuli.TextScreen("No experiments found!", -"Please put your experiments into a folder called 'expyriment', " + -"located on the internal or external sdcard.\n\n" + -"[Touch the screen to exit]") + "Please put your experiments into a folder called 'expyriment', " + + "located on the internal or external SDcard.\n\n" + + "[Touch the screen to exit]") info_box.present() - mouse.wait_press() + exp.mouse.wait_press() + elif len(projects)==1: # started immediately if no choice + launch_experiment(projects.values()[0], projects.keys()[0]) else: items = projects.keys() items.sort() menu = expyriment.io.TextMenu("Run experiment:", items, 320, - scroll_menu=5, mouse=mouse) - py_file = projects[menu.get()] - expyriment.control.defaults.event_logging = 1 - expyriment.control.defaults.initialize_delay = 0 - os.chdir(os.path.split(py_file)[0]) - sys.argv[0] = py_file - execfile("{0}".format(py_file), globals()) + scroll_menu=5, mouse=exp.mouse) + select = menu.get() + launch_experiment(projects[select], select) if __name__ == "__main__": From c1ac3ebce938983e4080e6df0e7131033b4590dc Mon Sep 17 00:00:00 2001 From: Oliver Lindemann Date: Thu, 13 Mar 2014 15:18:03 +0100 Subject: [PATCH 06/16] Update main.py --- expyriment_app/main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/expyriment_app/main.py b/expyriment_app/main.py index 3569017..a9f3707 100644 --- a/expyriment_app/main.py +++ b/expyriment_app/main.py @@ -53,10 +53,10 @@ def launch_experiment(pyfile, name): def main(): android.init() - projects = find_keyword_files("/mnt/sdcard0/expyriment") # TODO not yet checked on Android - projects.update(find_keyword_files("/mnt/sdcard0/expyriment")) - projects.update(find_keyword_files("/mnt/extSdCard/expyriment")) - projects.update(find_keyword_files("/mnt/extSdCard/expyriment")) + projects = {} + for folder in glob.glob("/mnt/*"): + if os.path.isdir(folder): + projects.update(find_keyword_files(folder + "/expyriment") pygame.font.init() for font in glob.glob("/system/fonts/*"): From 094966ba81bb22d0a474227f7c6043382536b7fb Mon Sep 17 00:00:00 2001 From: Oliver Lindemann Date: Wed, 16 Apr 2014 18:17:07 +0200 Subject: [PATCH 07/16] DOC: update readme.md --- .gitignore | 5 +++-- README.md | 33 ++++++++++++--------------------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 72bc37e..f00452d 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,7 @@ nosetests.xml .pydevproject #### Expyriment specific -examples/data/ -examples/events/ +data/ +events/ +expyriment _build/ diff --git a/README.md b/README.md index 956bc71..81e840c 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,20 @@ -Expyriment Android Runtime -========================== +Expyriment Android Runtime (EAR) +================================ + +The **Expyriment Android Runtime** (EAR) is a convinient way to run experiments created with [*Expyriment*] (http://www.expyriment.org) on an Android device. *Expyriment* is an open-source and platform-independent lightweight Python library for designing and conducting behavioral experiments: https://github.com/expyriment/expyriment + *GNU General Public License v3* Florian Krause (florian@expyriment.org) & Oliver Lindemann (oliver@expyriment.org) -About ------ -The Expyriment Android Runtime is a convinient way to run experiments created with [Expyriment] (http://www.expyriment.org) on an Android device. Installation ------------ -The easiest way is to install the Expyriment Android Runtime on you Android device is to download and install the latest release of our [Android application package] (https://github.com/expyriment/expyriment-android-runtime/releases). +The easiest way is to install EAR on you Android device is to download and install the latest release of our [Android application package] (https://github.com/expyriment/expyriment-android-runtime/releases). -You can build the Expyriment Android Runtime yourself as describe below: +You can build EAR yourself as describe below: 1. Installed the JAVA JDK: http://www.oracle.com/technetwork/java/javase/downloads/index.html 2. Download PGS4A (version 0.94) from http://pygame.renpy.org/dl @@ -32,18 +32,9 @@ Alternative, you can use the makefile: `make configure` (step 2 to 8) and `make Usage ----- -Once installed, the application will look for Expyriment scripts (each in its own subdirectory) in a directory called ‘expyriment’, located at the root level of either storage device under ‘mnt’ (i.e. the internal or external SD card). Examples of correctly located Expyriment scripts include: -``` -/mnt/sdcard0/expyriment/exp1/exp1.py - -/mnt/sdcard0/expyriment/exp2/exp2.py - -/mnt/extSdCard/expyriment/exp3/exp3.py - -/mnt/extSdCard/expyriment/exp4/exp4.py -``` +Once installed, the application will look for any Expyriment script in a directory called ‘expyriment’ or its subdirectories, located at the root level of either storage device under ‘mnt’ (i.e. the internal or external SD card). E.g.: +`/mnt/sdcard0/expyriment/`, `/mnt/extSdCard/expyriment/`. -Note ----- -**Expyriment** is an open-source and platform-independent lightweight Python -library for designing and conducting behavioral experiments: http://www.expyriment.org, https://github.com/expyriment/expyriment +An Expyriment script must contain the following keyword strings: `expyriment`, +`initialize(`, `start(` and end with the suffix `.py`. Files names starting with +an underscore (`_`) will be ignored. From 870adaa1e61e667629c17a4b501d462bb40e1e37 Mon Sep 17 00:00:00 2001 From: Oliver Lindemann Date: Wed, 16 Apr 2014 18:36:23 +0200 Subject: [PATCH 08/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 81e840c..ce75ba4 100644 --- a/README.md +++ b/README.md @@ -36,5 +36,5 @@ Once installed, the application will look for any Expyriment script in a directo `/mnt/sdcard0/expyriment/`, `/mnt/extSdCard/expyriment/`. An Expyriment script must contain the following keyword strings: `expyriment`, -`initialize(`, `start(` and end with the suffix `.py`. Files names starting with +`initialize(`, `start(`. The filename has to end with the suffix `.py`. Filenames starting with an underscore (`_`) will be ignored. From 688e9ea6731c9475ac80f8717fc77aa8f1c6488f Mon Sep 17 00:00:00 2001 From: Oliver Lindemann Date: Wed, 16 Apr 2014 18:37:48 +0200 Subject: [PATCH 09/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ce75ba4..bd9aa29 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Alternative, you can use the makefile: `make configure` (step 2 to 8) and `make Usage ----- -Once installed, the application will look for any Expyriment script in a directory called ‘expyriment’ or its subdirectories, located at the root level of either storage device under ‘mnt’ (i.e. the internal or external SD card). E.g.: +The application will look for any Expyriment script in a directory called ‘expyriment’ or its subdirectories, located at the root level of either storage device under ‘mnt’ (i.e. the internal or external SD card). E.g.: `/mnt/sdcard0/expyriment/`, `/mnt/extSdCard/expyriment/`. An Expyriment script must contain the following keyword strings: `expyriment`, From bfaaadf48a92255d0a0602df28ca41fe58d1315d Mon Sep 17 00:00:00 2001 From: Oliver Lindemann Date: Mon, 3 Nov 2014 20:15:44 +0100 Subject: [PATCH 10/16] Update main.py --- expyriment_app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/expyriment_app/main.py b/expyriment_app/main.py index a9f3707..afaa368 100644 --- a/expyriment_app/main.py +++ b/expyriment_app/main.py @@ -12,7 +12,7 @@ def find_keyword_files(folder): Returns dict of files """ - keywords = ["expyriment", "start(", "initialize("] + keywords = ["expyriment", "initialize("] rtn = {} for entry in glob.glob(folder+"/*"): if os.path.isdir(entry): From ca55e0568e062effb403f8235bad638b08ab63ea Mon Sep 17 00:00:00 2001 From: Oliver Lindemann Date: Mon, 3 Nov 2014 20:16:27 +0100 Subject: [PATCH 11/16] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bd9aa29..60742fd 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,6 @@ Usage The application will look for any Expyriment script in a directory called ‘expyriment’ or its subdirectories, located at the root level of either storage device under ‘mnt’ (i.e. the internal or external SD card). E.g.: `/mnt/sdcard0/expyriment/`, `/mnt/extSdCard/expyriment/`. -An Expyriment script must contain the following keyword strings: `expyriment`, -`initialize(`, `start(`. The filename has to end with the suffix `.py`. Filenames starting with +An Expyriment script must contain the following keyword strings: `expyriment` and +`initialize(`. The filename has to end with the suffix `.py`. Filenames starting with an underscore (`_`) will be ignored. From 486cc378435195d5d966685b67da233d3bedeaa8 Mon Sep 17 00:00:00 2001 From: Florian Krause Date: Thu, 13 Nov 2014 12:11:36 +0100 Subject: [PATCH 12/16] Run scripts as import rather than with execfile --- expyriment_app/main.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/expyriment_app/main.py b/expyriment_app/main.py index afaa368..a3dfd25 100644 --- a/expyriment_app/main.py +++ b/expyriment_app/main.py @@ -1,6 +1,7 @@ import sys import os import glob +from importlib import import_module import pygame import expyriment @@ -40,15 +41,17 @@ def check_keyword(lines, keyword): return True return False -def launch_experiment(pyfile, name): +def launch_experiment(script, name): expyriment.stimuli.TextScreen(heading="Starting {0}".format(name), "").present() expyriment.misc.Clock().wait(1000) expyriment.control.defaults.event_logging = 1 expyriment.control.defaults.initialize_delay = 0 - os.chdir(os.path.split(py_file)[0]) - sys.argv[0] = py_file - execfile("{0}".format(py_file), globals()) + script = os.path.abspath(script) + path, pyfile = os.path.split(script) + os.chdir(path) + sys.argv[0] = pyfile + import_module(os.path.splitext(pyfile)[0]) def main(): android.init() From 99e69aafb9abcf8203cf2f4e69c7c25efbdbb655 Mon Sep 17 00:00:00 2001 From: Florian Krause Date: Thu, 13 Nov 2014 19:00:20 +0100 Subject: [PATCH 13/16] Added script path to PYTHONPATH --- expyriment_app/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/expyriment_app/main.py b/expyriment_app/main.py index a3dfd25..2a7945e 100644 --- a/expyriment_app/main.py +++ b/expyriment_app/main.py @@ -51,6 +51,7 @@ def launch_experiment(script, name): path, pyfile = os.path.split(script) os.chdir(path) sys.argv[0] = pyfile + sys.path.insert(1, path) import_module(os.path.splitext(pyfile)[0]) def main(): From a790d6a64b1f94d0aa4910e3876c7193d9f448b9 Mon Sep 17 00:00:00 2001 From: Florian Krause Date: Mon, 17 Nov 2014 10:19:15 +0100 Subject: [PATCH 14/16] minor --- expyriment_app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/expyriment_app/main.py b/expyriment_app/main.py index 2a7945e..168952c 100644 --- a/expyriment_app/main.py +++ b/expyriment_app/main.py @@ -50,7 +50,7 @@ def launch_experiment(script, name): script = os.path.abspath(script) path, pyfile = os.path.split(script) os.chdir(path) - sys.argv[0] = pyfile + sys.argv[0] = script sys.path.insert(1, path) import_module(os.path.splitext(pyfile)[0]) From ff6b69b3e60f6801d690a757283ad42fcd34d609 Mon Sep 17 00:00:00 2001 From: mbroedl Date: Sun, 4 Nov 2018 16:05:11 +0100 Subject: [PATCH 15/16] Update expyriment_app/main.py Co-Authored-By: lindemann09 --- expyriment_app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/expyriment_app/main.py b/expyriment_app/main.py index 168952c..68d1140 100644 --- a/expyriment_app/main.py +++ b/expyriment_app/main.py @@ -43,7 +43,7 @@ def check_keyword(lines, keyword): def launch_experiment(script, name): expyriment.stimuli.TextScreen(heading="Starting {0}".format(name), - "").present() + text="").present() expyriment.misc.Clock().wait(1000) expyriment.control.defaults.event_logging = 1 expyriment.control.defaults.initialize_delay = 0 From 1ddf60290047117272a50a76989e23818f7c5f90 Mon Sep 17 00:00:00 2001 From: mbroedl Date: Sun, 4 Nov 2018 16:05:22 +0100 Subject: [PATCH 16/16] Update expyriment_app/main.py Co-Authored-By: lindemann09 --- expyriment_app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/expyriment_app/main.py b/expyriment_app/main.py index 68d1140..7fb7212 100644 --- a/expyriment_app/main.py +++ b/expyriment_app/main.py @@ -60,7 +60,7 @@ def main(): projects = {} for folder in glob.glob("/mnt/*"): if os.path.isdir(folder): - projects.update(find_keyword_files(folder + "/expyriment") + projects.update(find_keyword_files(folder + "/expyriment")) pygame.font.init() for font in glob.glob("/system/fonts/*"):