/** * Graphic User Interface * * @author Alain Pitiot * @version 2020.1 * @copyright (c) 2020 Ilixa Ltd. ({@link http://ilixa.com}) * @license Distributed under the terms of the MIT License */ import {PsychoJS} from './PsychoJS'; import {ServerManager} from './ServerManager'; import {Scheduler} from '../util/Scheduler'; import {Clock} from '../util/Clock'; import { ExperimentHandler } from '../data/ExperimentHandler'; import * as util from '../util/Util'; /** * @class * Graphic User Interface * * @name module:core.GUI * @class * @param {module:core.PsychoJS} psychoJS the PsychoJS instance */ export class GUI { get dialogComponent() { return this._dialogComponent; } constructor(psychoJS) { this._psychoJS = psychoJS; // gui listens to RESOURCE events from the server manager: psychoJS.serverManager.on(ServerManager.Event.RESOURCE, (signal) => { this._onResourceEvents(signal); }); this._dialogScalingFactor = 0; } /** *
Create a dialog box that (a) enables the participant to set some * experimental values (e.g. the session name), (b) shows progress of resource * download, and (c) enables the participant to cancel the experiment.
* * Setting experiment values *DlgFromDict displays an input field for all values in the dictionary. * It is possible to specify default values e.g.:
*let expName = 'stroop';
* let expInfo = {'participant':'', 'session':'01'};
* psychoJS.schedule(psychoJS.gui.DlgFromDict({dictionary: expInfo, title: expName}));
* If the participant cancels (by pressing Cancel or by closing the dialog box), then * the dictionary remains unchanged.
* * @name module:core.GUI#DlgFromDict * @function * @public * @param {Object} options * @param {String} [options.logoUrl] - Url of the experiment logo * @param {String} [options.text] - information text * @param {Object} options.dictionary - associative array of values for the participant to set * @param {String} options.title - name of the project */ DlgFromDict({ logoUrl, text, dictionary, title }) { // get info from URL: const infoFromUrl = util.getUrlParameters(); this._progressMsg = ' '; this._progressBarMax = 0; this._allResourcesDownloaded = false; this._requiredKeys = []; this._setRequiredKeys = new Map(); // prepare PsychoJS component: this._dialogComponent = {}; this._dialogComponent.status = PsychoJS.Status.NOT_STARTED; const dialogClock = new Clock(); const self = this; return () => { const t = dialogClock.getTime(); if (t >= 0.0 && self._dialogComponent.status === PsychoJS.Status.NOT_STARTED) { self._dialogComponent.tStart = t; self._dialogComponent.status = PsychoJS.Status.STARTED; // if the experiment is licensed, and running on the license rather than on credit, // we use the license logo: if (self._psychoJS.getEnvironment() === ExperimentHandler.Environment.SERVER && typeof self._psychoJS.config.experiment.license !== 'undefined' && self._psychoJS.config.experiment.runMode === 'LICENSE' && typeof self._psychoJS.config.experiment.license.institutionLogo !== 'undefined') { logoUrl = self._psychoJS.config.experiment.license.institutionLogo; } // prepare jquery UI dialog box: let htmlCode = '⚠ This experiment uses a deprecated version of the PsychoJS library. Consider updating to a newer version (e.g. by updating PsychoPy and re-exporting the experiment).
'+ // logo: if (typeof logoUrl === 'string') { htmlCode += '' + text + '
'; } // add a combobox or text areas for each entry in the dictionary: htmlCode += ''; // add a progress bar: htmlCode += 'This function can be used to display both warning and error messages.
* * @name module:core.GUI#dialog * @function * @public * @param {Object} options * @param {string} options.message - the message to be displayed * @param {Object.Unfortunately we encountered the following error:
'; htmlCode += stackCode; htmlCode += 'Try to run the experiment again. If the error persists, contact the experiment designer.
'; htmlCode += '' + message + '
' + '' + warning + '
' + 'Oops we encountered an internal server error.
Try to run the experiment again. If the error persists, contact the experiment designer.
Oops we encountered a database error.
Try to run the experiment again. If the error persists, contact the experiment designer.
${this._psychoJS.config.experiment.fullpath} does not have any status and cannot be run.
If you are the experiment designer, go to your experiment page and change the experiment status to either PILOTING or RUNNING.
Otherwise please contact the experiment designer to let him or her know that the status must be changed to RUNNING for participants to be able to run it.
${this._psychoJS.config.experiment.fullpath} is currently inactive and cannot be run.
If you are the experiment designer, go to your experiment page and change the experiment status to either PILOTING or RUNNING.
Otherwise please contact the experiment designer to let him or her know that the status must be changed to RUNNING for participants to be able to run it.
${this._psychoJS.config.experiment.fullpath} has been deleted and cannot be run.
If you are the experiment designer, either go to your experiment page and change the experiment status to either PILOTING or RUNNING, or generate a new experiment.
Otherwise please contact the experiment designer to let him or her know that the experiment has been deleted and cannot be run any longer.
${this._psychoJS.config.experiment.fullpath} has been archived and cannot be run.
If you are the experiment designer, go to your experiment page and change the experiment status to either PILOTING or RUNNING.
Otherwise please contact the experiment designer to let him or her know that the experiment has been archived and cannot be run at the moment.
${this._psychoJS.config.experiment.fullpath} is currently in PILOTING mode but the pilot token is missing from the URL.
If you are the experiment designer, you can pilot it by pressing the pilot button on your experiment page.
Otherwise please contact the experiment designer to let him or her know that the experiment status must be changed to RUNNING for participants to be able to run it.
${this._psychoJS.config.experiment.fullpath} cannot be run because the pilot token in the URL is invalid, possibly because it has expired.
If you are the experiment designer, you can generate a new token by pressing the pilot button on your experiment page.
Otherwise please contact the experiment designer to let him or her know that the experiment status must be changed to RUNNING for participants to be able to run it.
${this._psychoJS.config.experiment.fullpath} is covered by a license that has expired.
If you are the experiment designer, you can either contact the license manager to inquire about the expiration, or you can run your experiments using credits. You will find all relevant details about the license on your experiment page, where you will also be able to change its running mode to CREDIT.
Otherwise please contact the experiment designer to let him or her know that there is an issue with the experiment's license having expired.
${this._psychoJS.config.experiment.fullpath} is covered by a license that requires one or more documents to be approved before the experiment can be run.
If you are the experiment designer, please contact the license manager and ask him or her which documents must be approved. You will find all relevant details about the license on your experiment page.
Otherwise please contact the experiment designer to let him or her know that there is an issue with the experiment's license requiring documents to be approved.
${this._psychoJS.config.experiment.fullpath} does not have any assigned credit left and cannot be run.
If you are the experiment designer, you can assign more credits to it on your experiment page.
Otherwise please contact the experiment designer to let him or her know that the experiment requires more assigned credits to run.
Unfortunately we encountered an unspecified error (error code: ${errorCode}.
Try to run the experiment again. If the error persists, contact the experiment designer.