lib/App/SeismicUnixGui/misc/run_button.pm untested

filter: Statementstmt 0.0% 0 / 153 Branchbran 0.0% 0 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 10 totaltotal 0.0% 0 / 206 CC 13 SCAR 18.6
CC
13
Cov
0%
_Run_pre_built_superflow
12.0
_Run_user_built_flow
12.0
director
12.0
CRAP 6.5
1 package App::SeismicUnixGui::misc::run_button;
2  
3 =head1 DOCUMENTATION
4  
5 =head2 SYNOPSIS
6  
7 PERL PERL PROGRAM NAME: run_button.pm
8 AUTHOR: Juan Lorenzo
9 DATE: May 16 2018
10  
11 DESCRIPTION
12
13 BASED ON:
14
15 previous version (V 0.2) of the main L_SU.pl (V 0.3)
16
17 =cut
18  
19 =head2 USE
20  
21 =head3 NOTES
22  
23 =head4 Examples
24  
25 =head2 CHANGES and their DATES
26 refactoring of 2017 version of L_SU.pl
27
28 TODO: Encapsulate better
29
30 gets from
31 $decisions
32 $run_button
33 sets
34 $pre_req_ok
35
36 calls
37 $gui_history ->set4run_button_start();
38 $gui_history ->set4run_button();
39 $decisions ->set4run_select($run_button);
40 $gui_history ->set4run_button_end();
41 $whereami ->in_gui();
42 message box: $message
43 $run_button = $gui_history->get_hash_ref();
44
45 =cut
46  
47 =head2 Notes from bash
48
49 =cut
50  
51 use Moose;
52 our $VERSION = '1.0.0';
53  
54 use Tk;
55 # TODO Do I need decisions???
56 use App::SeismicUnixGui::misc::decisions '1.0.0';
57 use aliased 'App::SeismicUnixGui::misc::decisions';
58  
59 # uses conditions_flows which derives
60 # from conditions_gui
61  
62 extends 'App::SeismicUnixGui::misc::gui_history' => { -version => 0.0.2 };
63 use aliased 'App::SeismicUnixGui::misc::gui_history';
64  
65 # potentially used in all packages
66 use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants';
67 #use aliased 'App::SeismicUnixGui::misc::name';;
68 use aliased 'App::SeismicUnixGui::misc::whereami';
69 use aliased 'App::SeismicUnixGui::messages::message_director';
70  
71 my $gui_history = gui_history->new();
72 my $decisions = decisions->new();
73 my $get = L_SU_global_constants->new();
74 #my $name = name->new();
75 my $run_button_messages = message_director->new();
76 my $whereami = whereami->new();
77  
78 my $file_dialog_type = $get->file_dialog_type_href();
79 my $flow_type_h = $get->flow_type_href();
80  
81 my $var = $get->var();
82 my $on = $var->{_on};
83 my $true = $var->{_true};
84 my $false = $var->{_false};
85 my $superflow_names = $get->superflow_names_h();
86 my $global_libs = $get->global_libs();
87 my $run_button = $gui_history->get_defaults();
88  
89 # print("run_button,flow_name_out: $run_button->{_flow_name_out}\n");
90  
91 =head2 declare variables
92  
93 8 off
94  
95 =cut
96  
97 my $message_w;
98 my $mw;
99 my $parameter_values_frame;
100 my $parameter_value_index;
101 my $values_aref;
102 my ( $flow_listbox_grey_w, $flow_listbox_pink_w, $flow_listbox_green_w, $flow_listbox_blue_w );
103 my $sub_ref;
104  
105  
106 =head2 sub _messages
107 Show warnings or errors in a message box
108 Message box is defined in main where it is
109 also made invisible (withdraw)
110 Here we turn on the message box (deiconify, raise)
111 The message does not release the program
112 until OK is clicked and wait variable changes from yes
113 to no.
114  
115 =cut
116  
117 sub _messages {
118
119 my ($run_name) = @_;
120
121 my $run_name_message = message_director->new();
122 my $message = $run_name_message->immodpg(0);
123
124 # print("1. run_button,_messages,writing gui_history.txt\n");
125 # $gui_history->view();
126
127 my $message_box = $run_button->{_message_box_w};
128 my $message_label = $run_button->{_message_label_w};
129 my $message_box_wait = $run_button->{_message_box_wait};
130 my $message_ok_button = $run_button->{_message_ok_button};
131 # print("1 run_button,_messages, message_box_wait=$message_box_wait\n");
132
133 $message_box->title( "immodpg" );
134 $message_label->configure (
135 -textvariable => \$message,
136 );
137 $message_ok_button->configure (
138 -command => sub {
139 $message_box->grabRelease;
140 $message_box->withdraw;
141 $message_box_wait = $var->{_no};}
142 );
143
144 $message_box->deiconify();
145 $message_box->raise();
146
147 $message_ok_button->waitVariable(\$message_box_wait);
148 # print("2 run_button,_messages,message_box_wait=$message_box_wait\n");
149 return();
150
151 }
152  
153  
154 =head2 _Run_pre_built_superflow
155
156 only useful for saved superflow configuration files
157
158 decisions.pm tests:
159 _has_used_SaveAs_file_button
160 _has_used_Save_button
161  
162 foreach my $key (sort keys %$run_button) {
163 print (" run_button,_Run_pre_built_superflow: key is $key, value is $run_button->{$key}\n");
164 }
165
166 =cut
167  
168 sub _Run_pre_built_superflow {
169 my ($self) = @_;
170  
171 my $message = $run_button_messages->null_button(0);
172 $message_w = $run_button->{_message_w};
173 $message_w->delete( "1.0", 'end' );
174 $message_w->insert( 'end', $message );
175  
176 # print("1.run_button, _values_aref[0]: @{$run_button->{_values_aref}}[0]\n");
177 # $conditions_gui->set_gui_widgets($run_button);
178  
179 $gui_history->set_hash_ref($run_button);
180 # $gui_history->set_gui_widgets($run_button);
181 $gui_history->set4start_of_superflow_run_button();
182 $run_button = $gui_history->get_hash_ref();
183  
184 # print("2. L_SU, run_button, _values_aref[0]: @{$run_button->{_values_aref}}[0]\n");
185 $decisions->set4run_select($run_button);
186 my $pre_req_ok = $decisions->get4run_select();
187  
188 # print("1. run_button,_Run_pre_built_superflow\n");
189 # must have saved files already
190 if ($pre_req_ok) {
191  
192 # print("2. run_button,_Run_pre_built_superflow, passed pre_ok check\n");
193 # if ( $run_button->{_is_superflow_select_button} ) {
194 # print("3. run_button,program name is ${$run_button->{_prog_name_sref}}\n");
195 # }
196 my $run_name = ${$run_button->{_prog_name_sref}};
197 # tbd $name->get_alias_superflow_names( $run_button->{_prog_name_sref} );
198  
199 if ($run_name eq 'immodpg') {
200
201 _messages($run_name);
202
203 }
204 # print("4. run_button,program name is ${$run_button->{_prog_name_sref}}\n");
205 # print("4. run_button,program RUN name is $run_name \n");
206  
207 # Instruction runs in system
208 # print("4. run_button,running as bash $global_libs->{_script}$run_name \n");
209 system("bash $global_libs->{_script}$run_name");
210  
211 } else {
212 # print("3. run_button,_Run_pre_built_superflow\n");
213 my $message = $run_button_messages->run_button(0);
214 $message_w->delete( "1.0", 'end' );
215 $message_w->insert( 'end', $message );
216 }
217  
218 $gui_history->set4end_of_superflow_run_button();
219 $run_button = $gui_history->get_hash_ref();
220 return ();
221 }
222  
223 =head2 sub _Run_user_built_flow
224 for saved regular flows
225
226 foreach my $key (sort keys %$run_button) {
227 print (" run_button,_Run_pre_built_superflow: key is $key, value is $run_button->{$key}\n");
228 }
229 =cut
230  
231 sub _Run_user_built_flow {
232 my ($self) = @_;
233  
234 # print("run_button,_Run_user_built_flow\n");
235  
236 my $message = $run_button_messages->null_button(0);
237 $message_w->delete( "1.0", 'end' );
238 $message_w->insert( 'end', $message );
239  
240 # print("1 run_button,_Run_user_built_flow is_last_parameter_index_touched_color: $run_button->{_is_last_parameter_index_touched_color} \n");
241 # replace conditions_gui with gui_history which internally refers to the correct conditions_gui
242 $gui_history->set_hash_ref($run_button);
243 $gui_history->set4start_of_run_button();
244
245 $run_button = $gui_history->get_hash_ref();
246 # print("2 run_button,_Run_user_built_flow is_last_parameter_index_touched_color: $run_button->{_is_last_parameter_index_touched_color} \n");
247  
248 # tests whether has_used_Save OR has_used_SaveAs
249 # must be: has_used_Save AND has_used_SaveAs OR has_used_SaveAs but NOT only has_used_Save
250 $decisions->set4run_select($run_button);
251 my $pre_req_ok = $decisions->get4run_select();
252 # print("run_button,_Run_user_built_flow, program name is $run_button->{_has_used_SaveAs_button}\n");
253  
254 # must have saved files already
255 if ($pre_req_ok) {
256  
257 # print("run_button,_Run_user_built_flow, program name is $run_button->{_flow_name_out}\n");
258 # print("run button, _Run_user_built_flow, checking accuracy of inserted values\n");
259 #
260 # # TODO: pre-run check
261 # # $control ->set_prog_param_labels_aref2($run_button);
262 # # $control ->set_prog_param_values_aref2($run_button);
263 # # $control ->set_prog_names_aref($run_button);
264 # # $control ->set_items_versions_aref($run_button);
265 # # my $ok2run = $control->get_conditions();
266 #
267 my $ok2run = $true;
268  
269 if ($ok2run) {
270
271 my $run_name = $run_button->{_flow_name_out};
272 use aliased 'App::SeismicUnixGui::configs::big_streams::Project_config';
273 my $Project = Project_config->new();
274 my $PL_SEISMIC = $Project->PL_SEISMIC();
275  
276 # print("276: run_button, running: perl $PL_SEISMIC/$run_name\n");
277 system("/usr/bin/perl $PL_SEISMIC/$run_name");
278
279 } else {
280 print("run_button,_Run_user_built_flow, not ok to run\n");
281 }
282  
283 $gui_history->set4run_button();
284 $run_button = $gui_history->get_hash_ref();
285  
286 } else {
287 my $message = $run_button_messages->run_button(1);
288 $message_w->delete( "1.0", 'end' );
289 $message_w->insert( 'end', $message );
290 }
291  
292 $gui_history->set4end_of_run_button(); # 2 set
293 $run_button = $gui_history->get_hash_ref(); # 89 returned
294 return ();
295  
296 }
297  
298 =head2 sub _get_flow_type
299  
300 user_built_flow
301 or
302 pre_built_superflow
303
304
305 =cut
306  
307 sub _get_flow_type {
308 my ($self) = @_;
309  
310 my $how_built = $run_button->{_flow_type};
311  
312 if ( $run_button->{_flow_type} ) {
313  
314 return ($how_built);
315  
316 } else {
317 print("run_button, _get_flow_type , missing topic\n");
318 return ();
319 }
320  
321 }
322  
323 =head2 sub director
324  
325 prior to running
326 determine if we are dealing with superflow
327 (" menubutton" widget)
328 - collect and/or access flow parameters
329
330 Analysis:
331
332 i/p: $parameter_values_frame
333 i/p: $run_button_messages
334 i/p: $message
335 i/p: $param_flow
336 i/p: $run_button
337 i/p: $config_superflows
338
339 # o/p: $conditions_gui ->set4start_of_run_button();
340 # o/p: $gui_history ->set4_run_button
341 # o/p: $gui_history ->set4end_of_run_button();
342 $run_button = $gui_history->get_hash_ref();
343 o/p: _check4changes();
344
345 o/p: $run_button
346 o/p: $files_LSU
347
348 Run can be of 2 types
349
350 dialog type can only be Run (Main menu)
351  
352
353 i.e. 'either'
354
355 or
356 Run (perl program of user-built flow
357 or
358 Run pre-built superflow configuration files
359 my $run_dialog_type = $file_dialog_type->{_Run} ;
360  
361 =cut
362  
363 sub director {
364 my ($self) = @_;
365  
366 my $flow_type = _get_flow_type();
367  
368 if ( $flow_type eq $flow_type_h->{_user_built} ) {
369  
370 # print("run_button, director, flow_type: $flow_type\n");
371 _Run_user_built_flow();
372  
373 } elsif ( $flow_type eq $flow_type_h->{_pre_built_superflow} ) {
374  
375 # print("run_button, director, is superflow_type:$flow_type\n");
376 _Run_pre_built_superflow();
377  
378 } else {
379 print("run_button, director has a flow-type problem\n");
380 }
381 return ();
382 }
383  
384 =head2 sub get_all_hash_ref
385  
386 return ALL values of the private hash, supposedly
387 improtant external widgets have not been reset.. only conditions
388 are reset
389 TODO: perhaps it is better to have a specific method
390 to return one specific widget address at a time?
391 }
392
393 =cut
394  
395 sub get_all_hash_ref {
396 my ($self) = @_;
397  
398 if ($run_button) {
399  
400 # print("run_button, get_hash_ref , run_button->{_flow_color}: $run_button->{_flow_color}\n");
401 return ($run_button);
402  
403 } else {
404 print("run_button, get_hash_ref , missing hrun_button hash_ref\n");
405 }
406 }
407  
408  
409 =head2 sub set_flow_type
410  
411 user_built_flow
412 or
413 pre_built_superflow
414
415 =cut
416  
417 sub set_flow_type {
418 my ( $self, $how_built ) = @_;
419  
420 if ($how_built) {
421 $run_button->{_flow_type} = $how_built;
422  
423 # print("run_button, set_flow_type : $run_button->{_flow_type}\n");
424  
425 } else {
426 print("run_button, set_flow_type , missing how_built\n");
427 }
428 return ();
429 }
430  
431  
432 =head2 sub set_hash_ref
433 bring in important widget addresses
434
435 =cut
436  
437 sub set_hash_ref {
438 my ( $self, $hash_ref ) = @_;
439  
440 if (length($hash_ref) ){
441
442 $gui_history->set_defaults($hash_ref);
443 $run_button = $gui_history->get_defaults();
444 $message_w = $run_button->{_message_w};
445
446 }else {
447 print("run_button, set_hash_ref, missing hash_ref\n");
448 }
449 return ();
450 }
451  
452  
453 =head2 sub set_flow_name_out
454  
455 user-built flow name
456
457 =cut
458  
459 sub set_flow_name_out {
460 my ( $self, $name ) = @_;
461  
462 if ($name) {
463
464 $run_button->{_flow_name_out} = $name;
465  
466 # print("run_button, set_flow_name_out, $run_button->{_flow_name_out}\n");
467  
468 } else {
469 print("run_button, set_flow_name_out, missing name\n");
470 }
471 return ();
472 }
473  
474 =head2 sub set_prog_name_sref
475  
476 in order to know what
477 _spec file to read for
478 behaviors
479 THis program has a pre-existing module
480
481 =cut
482  
483 sub set_prog_name_sref {
484 my ( $self, $name_sref ) = @_;
485  
486 if ($name_sref) {
487 $run_button->{_prog_name_sref} = $name_sref;
488  
489 # print("run_button, set_prog_name_sref , ${$run_button->{_prog_name_sref}}\n");
490  
491 } else {
492 print("run_button, set_prog_name_sref , missing name\n");
493 }
494 return ();
495 }
496  
497 1;