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

filter: Statementstmt 0.0% 0 / 173 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 23 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 227 CC 6 SCAR 13.7
CC
6
Cov
0%
get_flow_color
12.0
_FileDialog_button_Delete
6.0
get_prog_name_sref
6.0
CRAP 3.9
1 package App::SeismicUnixGui::misc::neutral_flow;
2  
3 =head1 DOCUMENTATION
4  
5  
6 =head2 SYNOPSIS
7  
8 PERL PERL PROGRAM NAME: neutral_flow.pm
9 AUTHOR: Juan Lorenzo
10 DATE: June 8 2018
11  
12 DESCRIPTION
13
14 Is used only to inspect labels/names of different available
15 sunix programs
16 'neutral' refers to that no colored box is available to build a flow
17 from these selections
18  
19 BASED ON:
20 previous versions of the main userBuiltFlow.pl
21
22  
23 =cut
24  
25 =head2 USE
26  
27 =head3 NOTES
28  
29 Provides in-house macros/superflows
30 1. Find widget you have selected
31  
32
33 . Disable the following widgets:
34 delete_from_flow_button
35 (sunix) flow_listbox
36
37 sunix_listbox -choice of listed sunix modules in a listbox
38
39  
40 =head4 Examples
41  
42 =head3 SEISMIC UNIX NOTES
43  
44 =head2 CHANGES and their DATES
45 refactoring of 2017 version of L_SU.pl
46
47 V 0.0.2 Aug 12 2018
48 include multi-"colored" flows
49
50 V 0.0.3 Oct. 11 2019
51 refactored
52
53 V0.0.4 Sept. 19, 2022
54 changes to get_help
55 error check
56 find module path
57  
58 =cut
59  
60 =head2 Notes from bash
61
62 =cut
63  
64 use Moose;
65 our $VERSION = '0.0.4';
66  
67 use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants';
68 use aliased 'App::SeismicUnixGui::configs::big_streams::Project_config';
69  
70 use aliased 'App::SeismicUnixGui::misc::file_dialog';
71  
72 extends 'App::SeismicUnixGui::misc::gui_history' => { -version => 0.0.2 };
73 use aliased 'App::SeismicUnixGui::misc::gui_history';
74 use App::SeismicUnixGui::misc::param_widgets_neutral '0.0.2';
75 use aliased 'App::SeismicUnixGui::misc::param_widgets_neutral';
76 use App::SeismicUnixGui::misc::param_flow_neutral '0.0.3';
77 use aliased 'App::SeismicUnixGui::misc::param_flow_neutral';
78 use aliased 'App::SeismicUnixGui::misc::flow_widgets';
79 use aliased 'App::SeismicUnixGui::misc::help';
80 use aliased 'App::SeismicUnixGui::misc::manage_files_by2';
81 use aliased 'App::SeismicUnixGui::messages::message_director';
82 use aliased 'App::SeismicUnixGui::misc::param_sunix';
83  
84 my $L_SU_global_constants = L_SU_global_constants->new();
85 my $Project = Project_config->new();
86 my $file_dialog = file_dialog->new();
87 my $flow_widgets = flow_widgets->new();
88 my $manage_files_by2 = manage_files_by2->new();
89 my $gui_history = gui_history->new();
90 my $param_flow = param_flow_neutral->new();
91  
92 my $param_widgets = param_widgets_neutral->new();
93 my $flow_type = $L_SU_global_constants->flow_type_href();
94 my $color_flow_href = $gui_history->get_defaults();
95  
96 =head2
97  
98 share the following parameters in same name
99 space
100  
101 =cut
102  
103 my $flow_color;
104 my ($flowNsuperflow_name_w);
105  
106 my $message_w;
107 my $sunix_listbox;
108 my $var = $L_SU_global_constants->var();
109 $color_flow_href->{_flow_color} = $var->{_neutral};
110 my $true = $var->{_true};
111 my $false = $var->{_false};
112 my $empty_string = $var->{_empty_string};
113 my $user_built = $flow_type->{_user_built};
114 my $_flow_name_in_color = '_flow_name_in_' . $var->{_neutral};
115  
116 =head2 private anonymous hash
117  
118 to share variable values easily
119  
120 =cut
121  
122 my $color_flow = {
123  
124 _is_file_selected => $true,
125  
126 };
127  
128 =head2 sub FileDialog_button
129  
130 select the right method related
131 to FileDialog button in upper
132 class
133  
134 =cut
135  
136 sub FileDialog_button {
137  
138 my ( $self, $dialog_type_sref ) = @_;
139  
140 my $dialog_type = $$dialog_type_sref;
141  
142 my $private_module = '_FileDialog_button_' . $dialog_type;
143  
144 $self->$private_module($dialog_type_sref);
145  
146 return ();
147 }
148  
149 =head2 sub FileDialog_button_Delete
150
151 =cut
152  
153 sub _FileDialog_button_Delete {
154  
155 my ( $self, $dialog_type_sref ) = @_;
156
157 $color_flow->{_is_file_selected} = $true;
158  
159 # higher-level and a more permanent
160 # setting than file_dialog->set_flow_type()
161 $gui_history->set_flow_type($user_built);
162  
163 # print("neutral_flow, _FileDialog_button_Delete, gui_history.txt\n");
164 # $gui_history->view();
165  
166 # print(
167 # "neutral_flow,_FileDialog_button_Delete,dialog_type=$$dialog_type_sref\n"
168 # );
169  
170 while ($color_flow->{_is_file_selected} ) {
171
172 my $file_dialog_type = $L_SU_global_constants->file_dialog_type_href();
173 my $PL_SEISMIC = $Project->PL_SEISMIC();
174  
175 $color_flow_href->{_dialog_type} = $$dialog_type_sref;
176 my $topic = $color_flow_href->{_dialog_type};
177  
178 # print(
179 # "neutral_flow,_FileDialog_button_Delete,flow_color = $color_flow_href->{_flow_color}\n"
180 # );
181  
182 $file_dialog->set_flow_color( $color_flow_href->{_flow_color} );
183 $file_dialog->set_hash_ref($color_flow_href);
184 $file_dialog->FileDialog_director();
185 $color_flow_href->{$_flow_name_in_color} =
186 $file_dialog->get_perl_flow_name_in();
187  
188 # Is $flow_name_in empty?
189 my $file2query =
190 $PL_SEISMIC . '/' . $color_flow_href->{$_flow_name_in_color};
191 $color_flow->{_Flow_file_exists} =
192 $manage_files_by2->does_file_exist_sref( \$file2query );
193 $color_flow->{_is_file_selected} = $file_dialog->get_is_file_selected();
194
195
196 # print(
197 #"color_flow,_FileDialog_button_Delete, _is_file_selected= $color_flow->{_is_file_selected}\n"
198 # );
199
200  
201 if ( $color_flow->{_Flow_file_exists} ) {
202  
203 # delete the file
204 unlink($file2query);
205  
206 }
207 else {
208 # print(
209 #"3 neutral_flow,FileDialog_button, Warning: missing file. \"Cancel\" clicked by user? NADA\n"
210 # );
211 }
212 } # end of click_button being=OK
213  
214 return ();
215  
216 }
217  
218 =head2 sub get_hash_ref
219  
220 Exports private hash
221
222 =cut
223  
224 sub get_hash_ref {
225 my ($self) = @_;
226  
227 # print("neutral_flow, get_hash_ref \n");
228 return ($color_flow_href);
229  
230 }
231  
232 =head2 sub get_flow_color
233  
234 Exports private hash value
235
236 =cut
237  
238 sub get_flow_color {
239 my ($self) = @_;
240  
241 if ( length $color_flow_href->{_flow_color} ) {
242  
243 my $color;
244  
245 $color = $color_flow_href->{_flow_color};
246  
247 # print("neutral_flow,get_flow_color,color=$color\n");
248  
249 return ($color);
250  
251 }
252 elsif ( $color_flow_href->{_flow_color} eq $empty_string ) {
253  
254 print("neutral_flow,get_flow_color,no color\n");
255 return ();
256 }
257 else {
258 print("neutral_flow, get_flow_color, missing flow color\n");
259 }
260  
261 }
262  
263 =head2 sub get_prog_name_sref
264 Exports private hash value
265
266 =cut
267  
268 sub get_prog_name_sref {
269 my ($self) = @_;
270  
271 if ( $color_flow_href->{_prog_name_sref} ) {
272 my $name;
273  
274 $name = $color_flow_href->{_prog_name_sref};
275  
276 # print("neutral_flow, get_prog_name_sref, $$name\n");
277 return ($name);
278  
279 }
280 else {
281 print("neutral_flow, get_prog_name_sref, missing \n");
282 }
283  
284 }
285  
286 =head2 sub get_help
287  
288 Callback sequence following MB3 click
289 activation of a sunix (Listbox) item
290 program name is a scalar reference
291
292 Let help decide whether it is a superflow
293 or a user-created flow
294
295 Show a window with the perldoc to the user
296
297 =cut
298  
299 sub get_help {
300 my ($self) = @_;
301  
302 if (
303 length $color_flow_href->{_prog_name_sref}
304 and length $color_flow_href->{_current_program_name}
305 and ( $color_flow_href->{_current_program_name} eq
306 ${ $color_flow_href->{_prog_name_sref} } )
307 and length $color_flow_href->{_sunix_prog_group}
308 )
309 {
310  
311 # it is a sunix program
312 # the data group is defined
313  
314 my $data_group = $color_flow_href->{_sunix_prog_group};
315 my $current_program_name = $color_flow_href->{_current_program_name};
316 my $SeismicUnixGui = $L_SU_global_constants->get_path4SeismicUnixGui();
317 my $module_name = ${ $color_flow_href->{_prog_name_sref} };
318 my $sunix_program_group = $color_flow_href->{_sunix_prog_group};
319  
320 my $PATH = $SeismicUnixGui . '/sunix' . '/' . $data_group;
321  
322 my $help = help->new();
323 my $inbound = $PATH . '/' . $module_name . '.pm';
324  
325 # print("PATH = $inbound\n");
326  
327 $help->set_name( \$inbound );
328 $help->tkpod();
329 return ();
330  
331 }
332 else {
333 print("neutral_flow,get_help,a missing variable:\n");
334 print(
335 "neutral_flow,get_help,color_flow_href->{_prog_name_sref}=$color_flow_href->{_prog_name_sref}\n"
336 );
337 print(
338 "neutral_flow,get_help,color_flow_href->{_current_program_name}=$color_flow_href->{_current_program_name}\n"
339 );
340 print(
341 "neutral_flow,get_help,color_flow_href->{_prog_name_sref}=${$color_flow_href->{_prog_name_sref}}\n"
342 );
343 print(
344 "neutral_flow,get_help,color_flow_href->{_sunix_prog_group}=$color_flow_href->{_sunix_prog_group}\n"
345 );
346  
347 return ();
348 }
349 }
350  
351 =head2 sub set_hash_ref
352 Copies with simplified names are also kept (40) so later
353 the hash can be returned to a calling module
354  
355 =cut
356  
357 sub set_hash_ref {
358 my ( $self, $hash_ref ) = @_;
359  
360 $gui_history->set_defaults($hash_ref);
361 $color_flow_href = $gui_history->get_defaults();
362  
363 # REALLY?
364 # set up param_widgets for later use
365 # give param_widgets the needed values
366 $param_widgets->set_hash_ref($color_flow_href);
367  
368 # $file_menubutton = $color_flow_href->{_file_menubutton};
369 $flow_color = $color_flow_href->{_flow_color};
370 $flowNsuperflow_name_w = $color_flow_href->{_flowNsuperflow_name_w};
371  
372 # $last_flow_color = $color_flow_href->{_last_flow_color}; # used in flow_select
373 # $labels_w_aref = $color_flow_href->{_labels_w_aref};
374 $message_w = $color_flow_href->{_message_w};
375 $sunix_listbox = $color_flow_href->{_sunix_listbox};
376  
377 # print("neutral_flowset_hash_ref,delete_from_flow_button: $delete_from_flow_button\n");
378  
379 return ();
380 }
381  
382 =head2 sub sunix_select (subroutine is only active in neutral_flow)
383 Pick Seismic Unix modules
384  
385 foreach my $key (sort keys %$color_flow_href) {
386 print (" neutral_flowkey is $key, value is $color_flow_href->{$key}\n");
387 }
388 TODO: encapsulate better
389
390 set
391 $param_sunix
392 $param_widgets
393
394 get
395 $color_flow_href_messages
396 $whereami ->set4sunix_listbox()
397 $param_widgets
398 $param_sunix
399
400 call:
401 $gui_history ->set4start_of_sunix_select;
402 $gui_history ->set4end_of_sunix_select() ;
403 $color_flow_href = $gui_history->get_hash_ref();
404
405 =cut
406  
407 sub sunix_select {
408 my ($self) = @_;
409  
410 $color_flow_href->{_flow_type} =
411 $flow_type->{_user_built}; # should be at start of neutral_flow
412 # print("neutral_flow, sunix_select,parameter_values_frame: $parameter_values_frame\n");
413 use Clone 'clone';
414  
415 my $neutral_flow_messages = message_director->new();
416 my $param_sunix = param_sunix->new();
417  
418 my $message = $neutral_flow_messages->null_button(0);
419 $message_w->delete( "1.0", 'end' );
420 $message_w->insert( 'end', $message );
421  
422 # print("neutral_flow,1. sunix_select,flow_color: $color_flow_href->{_flow_color}\n");
423 # print("neutral_flow,1. sunix_select,_is_flow_listbox_neutral_w: $color_flow_href->{_is_flow_listbox_neutral_w} \n");
424  
425 $gui_history->set_hash_ref($color_flow_href);
426 $gui_history->set4start_of_sunix_select();
427  
428 # print("neutral_flow, sunix_select print gui_history.txt\n");
429 # $gui_history->view();
430  
431 #$color_flow_href->{_flow_color} = $gui_history->get_flow_color();
432 my $flow_color = $color_flow_href->{_flow_color};
433  
434 # print("neutral_flow,2. sunix_select,flow_color: $flow_color\n");
435 # print("neutral_flow,1. sunix_select,_is_flow_listbox_neutral_w: $color_flow_href->{_is_flow_listbox_neutral_w} \n");
436 # print("1. neutral_flow, sunix_select, _values_w_aref $color_flow_href->{_values_w_aref}\n");
437  
438 # get program name
439 $color_flow_href->{_prog_name_sref} =
440 $param_widgets->get_current_program( \$sunix_listbox );
441  
442 $param_sunix->set_flow_type( $color_flow_href->{_flow_type} );
443 $param_sunix->set_program_name( $color_flow_href->{_prog_name_sref} );
444  
445 # print("3. neutral_flow sunix_select, program name is ${$color_flow_href->{_prog_name_sref}}\n");
446  
447 $color_flow_href->{_names_aref} = $param_sunix->get_names();
448 $color_flow_href->{_values_aref} = $param_sunix->get_values();
449 $color_flow_href->{_check_buttons_settings_aref} =
450 $param_sunix->get_check_buttons_settings();
451 $color_flow_href->{_param_sunix_first_idx} = $param_sunix->first_idx();
452  
453 # use values not index
454 $param_sunix->set_half_length();
455 $color_flow_href->{_param_sunix_length} = $param_sunix->get_length(); #
456 # print("4. neutral_flow sunix_select, program name is ${$color_flow_href->{_prog_name_sref}}\n");
457 # print("2. neutral_flow, sunix_select, length $color_flow_href->{_param_sunix_length}\n");
458  
459 # widgets initialized in super class
460 $param_widgets->set_labels_w_aref( $color_flow_href->{_labels_w_aref} );
461 $param_widgets->set_values_w_aref( $color_flow_href->{_values_w_aref} );
462 $param_widgets->set_check_buttons_w_aref(
463 $color_flow_href->{_check_buttons_w_aref} );
464  
465 # print("5. neutral_flow sunix_select, program name is ${$color_flow_href->{_prog_name_sref}}\n");
466 # print("41. neutral_flow sunix_select, check button settings--@{$color_flow_href->{_check_buttons_settings_aref}}--\n");
467  
468 # Correct strange memory leak inside param_widgets
469 my $save = clone( $color_flow_href->{_check_buttons_settings_aref} );
470 $param_widgets->gui_full_clear();
471  
472 # print("42. neutral_flow sunix_select, check button settings--@$save-\n");
473 @{ $color_flow_href->{_check_buttons_settings_aref} } = @$save;
474  
475 # print("42. neutral_flow sunix_select, check button settings--@{$color_flow_href->{_check_buttons_settings_aref}}--\n");
476  
477 # $param_widgets->range($color_flow_href);
478 # print("43. neutral_flow sunix_select, check button settings @{$color_flow_href->{_check_buttons_settings_aref}}\n");
479  
480 # print("6 neutral_flow sunix_select\n");
481 $param_widgets->set_labels( $color_flow_href->{_names_aref} )
482 ; # equiv to "labels_aref"
483 $param_widgets->set_values( $color_flow_href->{_values_aref} );
484  
485 # print("1. neutral_flow, sunix_select, _values_aref @{$color_flow_href->{_values_aref}}\n");
486 # print("1. neutral_flow, sunix_select, _names_aref @{$color_flow_href->{_names_aref}}\n");
487 # print("44. neutral_flow sunix_select, check button settings @{$color_flow_href->{_check_buttons_settings_aref}}\n");
488  
489 $param_widgets->set_check_buttons(
490 $color_flow_href->{_check_buttons_settings_aref} );
491 $param_widgets->set_current_program( $color_flow_href->{_prog_name_sref} );
492  
493 # print("3. neutral_flow, sunix_select, _values_w_aref $color_flow_href->{_values_w_aref}\n");
494 # print("neutral_flow sunix_select, $color_flow_href->{_is_sunix_listbox}\n");
495 $param_widgets->redisplay_labels();
496 $param_widgets->redisplay_values();
497 $param_widgets->redisplay_check_buttons();
498  
499 $gui_history->set4end_of_sunix_select();
500  
501 # print("neutral_flow,2. sunix_select,1 line after set4end_of_sunix_select\n");
502 # $flow_color = $color_flow_href->{_flow_color};
503 # TODo are following 1 line and past 1 line needed?
504 # print("1. neutral_flow sunix_select, program name is ${$color_flow_href->{_prog_name_sref}}\n");
505 # $color_flow_href = $gui_history->get_hash_ref();
506  
507 # print("2. neutral_flow, sunix_select, _values_aref @{$color_flow_href->{_values_aref}}\n");
508 # print("2. neutral_flow, sunix_select, _names_aref @{$color_flow_href->{_names_aref}}\n");
509  
510 # $color_flow_href->{_last_flow_color} = $flow_color;
511 # print("7. neutral_flow sunix_select, program name is ${$color_flow_href->{_prog_name_sref}}\n");
512 # for export to other colored flows
513 # $last_flow_color = $flow_color;
514 # print("4. neutral_flow, sunix_select, _values_w_aref $color_flow_href->{_values_w_aref}\n");
515 # print("neutral_flow,3. sunix_select,flow_color: $flow_color\n");
516 # print("8. neutral_flow sunix_select, program name is ${$color_flow_href->{_prog_name_sref}}\n");
517 return ();
518 }
519  
520 1;