Project

General

Profile

How to add an AppionLoop GUI page » History » Version 9

Amber Herold, 02/05/2014 06:31 PM

1 1 Amber Herold
h1. How to add an AppionLoop GUI page
2
3
See feature #2634 for more information on the code that supports these directions.
4
5
# *Add a wiki page to the [[Appion_Processing|Appion User Guide]] describing how to use this feature*
6 9 Amber Herold
 
7 1 Amber Herold
# *Add a publication reference for the package you are using*
8
 
9
## Edit /myami/myamiweb/processing/inc/publicationList.inc to include an entry for any references you need to add to your launch page.
10
 
11
# *Create a new form class for your feature*
12 2 Amber Herold
 
13 1 Amber Herold
** Create a new file in myami/myamiweb/processing/inc/forms. Call it coolFeatureForm.inc.
14
** Create a class in this file that extends the BasicLoopForm class like this:
15
<pre>
16
require_once "basicLoopForm.inc";
17
18
class AutoMaskForm extends BasicLoopForm
19
{
20
...
21
</pre>
22
** Examples are available in autoMaskForm.inc and makeDDstackForm.inc
23 2 Amber Herold
&nbsp;
24 4 Amber Herold
# *Set parameters needed by the BasicLoopForm class in the constructor*
25 1 Amber Herold
&nbsp;
26
<pre>
27
//------ Set Parameters for the parent class, BasicLoopForm (general Appion params) -----//
28
		
29
// Set the publications to be references on the web pages
30
$pubList = array('appion'); // The publication reference key that you added to publicationList.inc
31
$this->setPublications( $pubList );
32
33
// Job Type should be unique to Appion. Used in the database to determine the type of job being run.
34
$this->setJobType( 'maskmaker' ); 
35
36
// The name of the folder that all runs of this job type will be stored in.
37
$this->setOutputDirectory( 'mask' );  
38
39
// A portion of the run name that will be common (by default) to all runs of this job type. A unique number is appended to individual run names.
40
$this->setBaseRunName( 'maskrun' ); 
41
42
// The title on the web page for this feature.
43
$this->setTitle( 'Auto Masking Launcher' ); 
44
45
// The Heading on the web page for this feature.
46
$this->setHeading( 'Automated Masking with EM Hole Finder' ); 
47
48
// The name of the python executable file that this GUI corresponds to. It should be based on the AppionLoop class and located in the myami/appion/bin folder.
49
$this->setExeFile( 'automasker.py' );
50
51
// A URL corresponding to a wiki page in the Appion User Guide with information on running this feature.  
52
$this->setGuideURL( "http://emg.nysbc.org/projects/appion/wiki/Appion_Processing" );
53 2 Amber Herold
54
// True to activate "test single image" field of Appion Loop parameters.
55
$this->setTestable( True ); 
56
57
// The output directory will be created in the Appion run directory rather than Leginon.
58
$this->setUseLegOutDir( False );
59
60
// Flag to hide the description field of the run parameters. True enables the description field.
61
$this->setShowDesc( False ); 
62 1 Amber Herold
</pre>
63 3 Amber Herold
&nbsp;
64
# *Take an inventory of the parameters that are specific to your new feature and are passed into your python executable file*
65
** Make a list of all the parameters that your GUI needs to expose to the user. For each parameter decide on:
66
### *id* I might also call it a parameter key or name. This should match the name of the parameter as it appears on the command line. So a flag in a command that looks like "--mycoolflag" should be named "mycoolflag" in this class.
67
### *default value*
68
### *label* This is the text that is actually shown to the user in the GUI next to the GUI element associated with it (check box, selection, text, etc)
69
### *help text* A longer description of the parameter and tips for what a user should set it to.
70
### *validations* Decide what should be considered valid values for this parameter. Is it required? Does it have to be a number or greater than zero? 
71
&nbsp;
72
# *Add your parameters help text to myami/myamiweb/processing/js/help.js*
73
&nbsp;
74
** Open myami/myamiweb/processing/js/help.js
75
** Add a new namespace for your form, you can copy the 'simple' section. Don't forget any commas.
76
** add a help string for each of the parameter keys in your form
77
&nbsp;
78 5 Amber Herold
# *Add your parameters to your form class constructor*
79 3 Amber Herold
&nbsp;
80
** Back in the class that you created to extend BasicLoopForm, add your parameters.
81
** First set the help section using the namespace that you just added to help.js.
82
<pre>
83
// Get an instance of the form parameters associated with this class
84
$params = $this->getFormParams();
85
		
86
// The help section corresponds to the array key for these parameters found in help.js for popup help.
87
$params->setHelpSection( "em_hole_finder" );
88
</pre>
89 5 Amber Herold
** Add a line for each of the parameters in your form. The first parameter of the addParam() function is the id of the param, followed by the default value (passed into the constructor), followed by the label (what is shown to the user in the GUI).
90 3 Amber Herold
<pre>
91
$params->addParam( "downsample", $downsample, "Downsample" );
92 1 Amber Herold
$params->addParam( "compsizethresh", $compsizethresh, "Component size thresholding" );
93
</pre>
94 5 Amber Herold
** Add any validation requirements that are needed for your parameters. Use the addValidation() function of the FormParameter class. The first field is the parameter id. The second field is a key word that corresponds to the type of validation needed. 
95
<pre>
96
$params->addValidation( "numpart", "req" );
97
</pre>
98
** Avaialble validation types are as follows, and updates can be found in myami/myamiweb/inc/formValidator.php
99
<pre>
100
// available validations, check formValidator.php for changes:
101
/*
102
	 * required : 					addValidation("variableName", "req");
103
	 * MaxLengh : 					addValidation("variableName", "maxlen=10");
104
	 * MinLengh : 					addValidation("variableName", "mixlen=3");
105
	 * Email	: 					addValidation("variableName", "email");
106
	 * Numeric	: 					addValidation("variableName", "num");
107
	 * Alphabetic : 				addValidation("variableName", "alpha");
108
	 * Alphabetic and spaces : 		addValidation("variableName", "alpha_s");
109
	 * Alpha-numeric and spaces: 	addValidation("variableName", "alnum_s");
110
	 * Float: 						addValidation("variableName", "float");
111
	 * absolute path: path_exist: 	addValidation("variableName", "abs_path");
112
	 * path existence : 			addValidation("variableName", "path_exist");
113
	 * folder permission : 			addValidation("variableName", "folder_permission");
114
	 * file existence : 			addValidation("variableName", "file_exist");
115
	 * Float w/fixed decimal space: addValidation("variableName", "float_d=2");
116
*/
117
</pre>
118
&nbsp;
119 7 Amber Herold
# *Generate a form for the parameters that are specific to this program (not AppionLoop params)*
120
&nbsp;
121 6 Amber Herold
** There are 2 places avalable for adding your own parameters to the GUI page. The most common place is to the Right Hand side of the Appion Loop parameters. To add your parameters to this section of the screen, override the function called *generateAdditionalFormRight()* in your form class extending BasicLoopForm. You may also add parameters to the space on the left directly below the Appion Loop parameters by overriding the function called *generateAdditionalFormLeft()*.
122
** These functions return the HTML code required to display your parameter GUI elements to the user. You may add HTML here directly. To add an input element for your parameter, use one of the functions available in the FormParameters class. The first field of these functions is always the parameter id.
123
<pre>
124
	public function generateAdditionalFormRight()
125
	{
126
                // Calling updateFormParams() will check the php $_POST array for any values that were previously set for the parameters in this form. 
127
		$this->updateFormParams();
128
		$params = $this->getFormParams();
129
		
130
		$fieldSize = 3;
131
		
132
		$html .= "<b>Make DD stack params:</b><br />\n";
133
		
134
		$html.= $params->insertCheckboxField( "align" );
135
		$html.= $params->insertCheckboxField( "defergpu" );
136
		$html.= $params->insertCheckboxField( "no_keepstack" );
137
		$html.= $params->insertTextFieldInRow( "bin", $fieldSize );
138
		
139
		return $html;
140
	}	
141 1 Amber Herold
</pre>
142 7 Amber Herold
&nbsp;
143
# *If you have implemented "test single image" on the python side, add code to display the test results in your class extending BasicLoopForm*
144
&nbsp;
145
** You can use the getTestResults() function in autoMaskForm.inc as an example.
146
<pre>
147
	// getTestResults() should return the HTML code needed to display test results any way this method
148
	// prefers to have them displayed. The results will be placed below a printout of the test command and 
149
	// above the launch form. Note that an instance of this class is not required to use this function.
150
	static public function getTestResults( $outdir, $runname, $testfilename )
151
	{
152
...
153
</pre>
154
&nbsp;
155
# *Add a link to your page in the menuprocessing.php file or from another page*
156
&nbsp;
157
** The menuprocessing file is a bit tricky to work with.If you do not link to your page from there, look for the appropriate php page where your feature should launch from.
158 8 Amber Herold
** You will add a link to runAppionLoop.php and pass the experiment ID and the name of your new form class in the URL. Here are a couple of examples with the MakeDDStackForm class and the AutoMaskForm Class:
159 7 Amber Herold
<pre>
160
$ddStackform = "MakeDDStackForm";
161
'name'=>"<a href='runAppionLoop.php?expId=$sessionId&form=$ddStackform'>Create frame stack</a>",
162
</pre>
163
<pre>
164
$form = "AutoMaskForm";
165
echo "  <h3><a href='runAppionLoop.php?expId=$expId&form=$form'>Auto Masking</a></h3>\n";
166 1 Amber Herold
</pre>
167 8 Amber Herold
** Note that the name of the class MUST match the name of the PHP file that the class is defined in. So if you extended the BasicLoopForm to a class named CoolFeatureForm, the file where that class lives must be at myami/myamiweb/processing/inc/forms/coolFeatureForm.inc.
168
&nbsp;
169
170 7 Amber Herold
&nbsp;