« lib/App/SeismicUnixGui/configs/big_streams/immodpg_config.pm
↑ Summary
lib/App/SeismicUnixGui/sunix/header/segyclean.pm »
| 1 | package App::SeismicUnixGui::misc::save_button; | ||
| 2 | |||
| 3 | =head1 DOCUMENTATION | ||
| 4 | |||
| 5 | =head2 SYNOPSIS | ||
| 6 | |||
| 7 | PERL PERL PROGRAM NAME: save_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 | 0.02 Nov. 2019 refactoring with gui_history to keep track | ||
| 17 | of user clicks | ||
| 18 | |||
| 19 | =cut | ||
| 20 | |||
| 21 | =head2 USE | ||
| 22 | |||
| 23 | =head3 NOTES | ||
| 24 | |||
| 25 | =head4 Examples | ||
| 26 | |||
| 27 | =head3 SEISMIC UNIX NOTES | ||
| 28 | |||
| 29 | =head2 CHANGES and their DATES | ||
| 30 | V 0.02 refactoring of 2017 version of L_SU.pl | ||
| 31 | |||
| 32 | =cut | ||
| 33 | |||
| 34 | =head2 Notes from bash | ||
| 35 | |||
| 36 | =cut | ||
| 37 | |||
| 38 | use Moose; | ||
| 39 | our $VERSION = '0.0.2'; | ||
| 40 | |||
| 41 | use Tk; | ||
| 42 | |||
| 43 | # | ||
| 44 | extends 'App::SeismicUnixGui::misc::gui_history' => { -version => 0.0.2 }; | ||
| 45 | use aliased 'App::SeismicUnixGui::misc::gui_history'; | ||
| 46 | use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants'; | ||
| 47 | use aliased 'App::SeismicUnixGui::misc::save'; | ||
| 48 | use aliased 'App::SeismicUnixGui::misc::files_LSU'; | ||
| 49 | use aliased 'App::SeismicUnixGui::misc::program_name'; | ||
| 50 | use aliased 'App::SeismicUnixGui::messages::message_director'; | ||
| 51 | use aliased 'App::SeismicUnixGui::misc::config_superflows'; | ||
| 52 | |||
| 53 | my $gui_history = gui_history->new(); | ||
| 54 | my $get = L_SU_global_constants->new(); | ||
| 55 | my $program_name = program_name->new(); | ||
| 56 | |||
| 57 | my $file_dialog_type = $get->file_dialog_type_href(); | ||
| 58 | my $flow_type_h = $get->flow_type_href(); | ||
| 59 | |||
| 60 | my $var = $get->var(); | ||
| 61 | my $on = $var->{_on}; | ||
| 62 | my $true = $var->{_true}; | ||
| 63 | my $false = $var->{_false}; | ||
| 64 | my $superflow_names = $get->superflow_names_h(); | ||
| 65 | my $alias_superflow_names_h = $get->alias_superflow_names_h(); | ||
| 66 | my $save_button = $gui_history->get_defaults(); | ||
| 67 | |||
| 68 | #print("1. save_button: writing gui_history.txt\n"); | ||
| 69 | #$gui_history->view(); | ||
| 70 | |||
| 71 | =head2 declare variables | ||
| 72 | |||
| 73 | 8 off | ||
| 74 | |||
| 75 | =cut | ||
| 76 | |||
| 77 | my $message_w; | ||
| 78 | my $mw; | ||
| 79 | my $parameter_values_frame; | ||
| 80 | my $parameter_value_index; | ||
| 81 | my $values_aref; | ||
| 82 | my ( $flow_listbox_grey_w, $flow_listbox_green_w ); | ||
| 83 | my $sub_ref; | ||
| 84 | |||
| 85 | =head2 sub _user_built_flow_Save_perl_file | ||
| 86 | save a unique perl flow built by the user | ||
| 87 | BUT currently does not see to do anything ?? TODO | ||
| 88 | |||
| 89 | =cut | ||
| 90 | |||
| 91 | sub _user_built_flow_Save_perl_file { | ||
| 92 | my ($self) = @_; | ||
| 93 | |||
| 94 | # print("save_button,_user_built_flow_Save_perl_file\n"); | ||
| 95 | return (); | ||
| 96 | } | ||
| 97 | |||
| 98 | sub set_param_flow { | ||
| 99 | my ( $self, $param_flow_ref ) = @_; | ||
| 100 | |||
| 101 | $save_button->{_param_flow} = &$param_flow_ref; | ||
| 102 | |||
| 103 | # print("set_param_flow, $param_flow_ref\n"); | ||
| 104 | |||
| 105 | } | ||
| 106 | |||
| 107 | #=head2 sub _user_built_flow_SaveAs_perl_file | ||
| 108 | # | ||
| 109 | # | ||
| 110 | #=cut | ||
| 111 | # | ||
| 112 | #sub _user_built_flow_SaveAs_perl_file { | ||
| 113 | # my ($self) = @_; | ||
| 114 | # | ||
| 115 | # if ( $save_button->{_is_flow_listbox_grey_w} | ||
| 116 | # || $save_button->{_is_flow_listbox_pink_w} | ||
| 117 | # || $save_button->{_is_flow_listbox_green_w} | ||
| 118 | # || $save_button->{_is_flow_listbox_blue_w} ) { | ||
| 119 | # | ||
| 120 | # # $param_flow ->set_good_values; | ||
| 121 | # # $param_flow ->set_good_labels; | ||
| 122 | # # $save_button->{_good_labels_aref2} = $param_flow->get_good_labels_aref2; | ||
| 123 | # # $save_button->{_items_versions_aref} = $param_flow->get_flow_items_version_aref; | ||
| 124 | # # $save_button->{_good_values_aref2} = $param_flow->get_good_values_aref2; | ||
| 125 | # # $save_button->{_prog_names_aref} = $param_flow->get_flow_prog_names_aref; | ||
| 126 | # # | ||
| 127 | # # # print("save_button,_prog_names_aref, | ||
| 128 | # # # @{$save_button->{_prog_names_aref}}\n"); | ||
| 129 | # # # my $num_items4flow = scalar @{$save_button->{_good_labels_aref2}}; | ||
| 130 | # # | ||
| 131 | # # # for (my $i=0; $i < $num_items4flow; $i++ ) { | ||
| 132 | # # # print("save_button,_good_labels_aref2, | ||
| 133 | # # # @{@{$save_button->{_good_labels_aref2}}[$i]}\n"); | ||
| 134 | # # # } | ||
| 135 | # # | ||
| 136 | # # # for (my $i=0; $i < $num_items4flow; $i++ ) { | ||
| 137 | # # # print("save_button,_good_values_aref2, | ||
| 138 | # # # @{@{$save_button->{_good_values_aref2}}[$i]}\n"); | ||
| 139 | # # #} | ||
| 140 | # # # print("save_button,_prog_versions_aref, | ||
| 141 | # # # @{$save_button->{_items_versions_aref}}\n"); | ||
| 142 | # # | ||
| 143 | # # $files_LSU ->set_prog_param_labels_aref2($save_button); | ||
| 144 | # # $files_LSU ->set_prog_param_values_aref2($save_button); | ||
| 145 | # # $files_LSU ->set_prog_names_aref($save_button); | ||
| 146 | # # $files_LSU ->set_items_versions_aref($save_button); | ||
| 147 | # # $files_LSU ->set_data(); | ||
| 148 | # # $files_LSU ->set_message($save_button); | ||
| 149 | # # $files_LSU ->set2pl($save_button); # flows saved to PL_SEISMIC | ||
| 150 | # # $files_LSU ->save(); | ||
| 151 | # # $gui_history ->set4_save_button(); | ||
| 152 | # # $save_button = $gui_history->get_hash_ref(); | ||
| 153 | # | ||
| 154 | # } | ||
| 155 | # return (); | ||
| 156 | #} | ||
| 157 | |||
| 158 | =head2 sub _Save_pre_built_superflow | ||
| 159 | |||
| 160 | foreach my $key (sort keys %$save_button) { | ||
| 161 | print (" save_button,_Save_pre_built_superflow: key is $key, value is $save_button->{$key}\n"); | ||
| 162 | } | ||
| 163 | print("save_button 2.built_in_flow.pm ONLY save_button superflow_select check_code_button\n"); | ||
| 164 | |||
| 165 | =cut | ||
| 166 | |||
| 167 | sub _Save_pre_built_superflow { | ||
| 168 | my ($self) = @_; | ||
| 169 | |||
| 170 | my $save_button_messages = message_director->new(); | ||
| 171 | my $save = save->new(); | ||
| 172 | my $files_LSU = files_LSU->new(); | ||
| 173 | my $config_superflows = config_superflows->new(); | ||
| 174 | |||
| 175 | my $message = $save_button_messages->null_button(0); | ||
| 176 | $message_w = $save_button->{_message_w}; | ||
| 177 | $message_w->delete( "1.0", 'end' ); | ||
| 178 | $message_w->insert( 'end', $message ); | ||
| 179 | |||
| 180 | $gui_history->set_hash_ref($save_button); | ||
| 181 | $gui_history->set4start_of_superflow_Save(); | ||
| 182 | $save_button = $gui_history->get_hash_ref(); | ||
| 183 | |||
| 184 | # print("1. save_button,_Save_pre_built_superflow,has_used_Save_superflow: $save_button->{_has_used_Save_superflow}\n"); | ||
| 185 | # print("1. save_button,_Save_pre_built_superflow,has_used_SaveAs_button: $save_button->{_has_used_SaveAs_button}\n"); | ||
| 186 | # print("1. save_button,_Save_pre_built_superflow, has_used_Save_button(only for user-built): $save_button->{_has_used_Save_button}\n"); | ||
| 187 | |||
| 188 | # print("save_button,_Save_pre_built_superflow, values_aref :@{$save_button->{_values_aref}}[0]\n"); | ||
| 189 | # print("2. save_button,_Save_pre_built_superflow,has_used_Save_superflow: $save_button->{_has_used_Save_superflow}\n"); | ||
| 190 | # print("2. save_button,_Save_pre_built_superflow,has_used_SaveAs_button: $save_button->{_has_used_SaveAs_button}\n"); | ||
| 191 | # print("2. save_button,_Save_pre_built_superflow, has_used_Save_button(only for user-built): $save_button->{_has_used_Save_button}\n"); | ||
| 192 | # print("2. save_button,_Save_pre_built_superflow,_is_Save_button: $save_button->{_is_Save_button}\n"); | ||
| 193 | |||
| 194 | if ( $save_button->{_flow_type} eq 'pre_built_superflow' ) | ||
| 195 | { # from gui_history | ||
| 196 | |||
| 197 | #print("2. save_button, Save_pre_built_superflow,_values_aref: @{$save_button->{_values_aref}}\n"); | ||
| 198 | #print("2. save_button, Save_pre_built_superflow,_labels_aref: @{$save_button->{_labels_aref}}\n"); | ||
| 199 | |||
| 200 | # | ||
| 201 | |||
| 202 | #print("3. save_button, _Save_pre_built_superflow, internal prog_name=: ${$save_button->{_prog_name_sref}} \n"); | ||
| 203 | |||
| 204 | |||
| 205 | # my $ans = ${ $save_button->{_prog_name_sref} }; | ||
| 206 | # ${ $save_button->{_prog_name_sref} } = $alias_superflow_names_h->{$ans}; | ||
| 207 | |||
| 208 | # consider aliases | ||
| 209 | # use the internal name | ||
| 210 | my $external_name = ${ $save_button->{_prog_name_sref} }; | ||
| 211 | $program_name->set($external_name); | ||
| 212 | my $internal_name = $program_name->get(); | ||
| 213 | $save_button->{_prog_name_sref} = \$internal_name; | ||
| 214 | |||
| 215 | $config_superflows->save($save_button); | ||
| 216 | $gui_history->set4superflow_Save(); | ||
| 217 | $save_button = $gui_history->get_hash_ref(); | ||
| 218 | |||
| 219 | } | ||
| 220 | else { # if flow first needs a change to activate | ||
| 221 | |||
| 222 | # print( | ||
| 223 | #"save_button,_Save_pre_built_superflow, _is_superflow_select_button = $save_button->{_is_superflow_select_button}\n" | ||
| 224 | # ); | ||
| 225 | # | ||
| 226 | # $message = $save_button_messages->save_button(0); | ||
| 227 | # $message_w ->delete("1.0",'end'); | ||
| 228 | # $message_w ->insert('end', $message); | ||
| 229 | } | ||
| 230 | |||
| 231 | $gui_history->set4end_of_superflow_Save(); | ||
| 232 | $save_button = $gui_history->get_hash_ref(); # returns 89 | ||
| 233 | |||
| 234 | return (); | ||
| 235 | } | ||
| 236 | |||
| 237 | =head2 sub _get_dialog_type | ||
| 238 | |||
| 239 | e.g, topic can be Save | ||
| 240 | |||
| 241 | |||
| 242 | =cut | ||
| 243 | |||
| 244 | sub _get_dialog_type { | ||
| 245 | my ($self) = @_; | ||
| 246 | |||
| 247 | my $topic = $save_button->{_dialog_type}; | ||
| 248 | |||
| 249 | # print("save_button, _get_dialog_type = $topic\n"); | ||
| 250 | |||
| 251 | if ($topic) { | ||
| 252 | return ($topic); | ||
| 253 | |||
| 254 | } | ||
| 255 | else { | ||
| 256 | print("save_button, _get_dialog_type , missing topic\n"); | ||
| 257 | return (); | ||
| 258 | } | ||
| 259 | } | ||
| 260 | |||
| 261 | =head2 sub _get_flow_type | ||
| 262 | |||
| 263 | user_built_flow | ||
| 264 | or | ||
| 265 | pre_built_superflow | ||
| 266 | |||
| 267 | |||
| 268 | =cut | ||
| 269 | |||
| 270 | sub _get_flow_type { | ||
| 271 | my ($self) = @_; | ||
| 272 | |||
| 273 | my $how_built = $save_button->{_flow_type}; | ||
| 274 | |||
| 275 | if ( $save_button->{_flow_type} ) { | ||
| 276 | return ($how_built); | ||
| 277 | |||
| 278 | } | ||
| 279 | else { | ||
| 280 | print("save_button, _get_flow_type , missing topic\n"); | ||
| 281 | return (); | ||
| 282 | } | ||
| 283 | |||
| 284 | } | ||
| 285 | |||
| 286 | =head2 sub director | ||
| 287 | |||
| 288 | |||
| 289 | prior to saving | ||
| 290 | determine if we are dealing with superflow | ||
| 291 | (" menubutton" widget) | ||
| 292 | - collect and/or access flow parameters | ||
| 293 | - default path is the current path | ||
| 294 | |||
| 295 | TODO: | ||
| 296 | or with GUI-made flows ("frame widget") | ||
| 297 | - collect and/or access flow parameters | ||
| 298 | - default path is the current path | ||
| 299 | |||
| 300 | DB: | ||
| 301 | print("current widget is $LSU->{_current_widget}\n"); | ||
| 302 | |||
| 303 | TODO: improve ENCAPSULATION: | ||
| 304 | |||
| 305 | Analysis: | ||
| 306 | |||
| 307 | i/p: $parameter_values_frame | ||
| 308 | i/p: $L_SU_messages | ||
| 309 | i/p: $message | ||
| 310 | i/p: $param_flow | ||
| 311 | i/p: $L_SU | ||
| 312 | i/p: $config_superflows | ||
| 313 | |||
| 314 | o/p: $gui_history ->set4start_of_Save_button(); | ||
| 315 | o/p: $gui_history ->set4_save_button | ||
| 316 | o/p: $gui_history ->set4end_of_save_button(); | ||
| 317 | $L_SU = $gui_history->get_hash_ref(); | ||
| 318 | |||
| 319 | o/p: $L_SU | ||
| 320 | o/p: $files_LSU | ||
| 321 | |||
| 322 | |||
| 323 | save can be of 3 generic types: | ||
| 324 | |||
| 325 | dialog type can be save (Main menu) | ||
| 326 | or SaveAs (FileDialog_button function) | ||
| 327 | |||
| 328 | i.e. 'either' | ||
| 329 | |||
| 330 | or | ||
| 331 | Save perl program of user-built flow | ||
| 332 | or | ||
| 333 | SaveAs perl program of user-built flow | ||
| 334 | or | ||
| 335 | Save pre-built superflow configuration files | ||
| 336 | |||
| 337 | =cut | ||
| 338 | |||
| 339 | =head2 sub director | ||
| 340 | |||
| 341 | =cut | ||
| 342 | |||
| 343 | sub director { | ||
| 344 | my ($self) = @_; | ||
| 345 | |||
| 346 | my $flow_type = _get_flow_type(); | ||
| 347 | my $save_dialog_type = _get_dialog_type(); | ||
| 348 | |||
| 349 | if ( $flow_type eq $flow_type_h->{_user_built} ) { | ||
| 350 | |||
| 351 | # print("save_button, director, is user_built flow_type:$flow_type\n"); | ||
| 352 | |||
| 353 | if ( $save_dialog_type eq $file_dialog_type->{_Save} ) { | ||
| 354 | |||
| 355 | # does not seem to do anything | ||
| 356 | _user_built_flow_Save_perl_file(); | ||
| 357 | |||
| 358 | } | ||
| 359 | elsif ( $save_dialog_type eq $file_dialog_type->{_SaveAs} ) { | ||
| 360 | |||
| 361 | # does not seem to be used | ||
| 362 | _user_built_flow_SaveAs_perl_file(); | ||
| 363 | |||
| 364 | } | ||
| 365 | else { | ||
| 366 | print( | ||
| 367 | "save_button, director has a user_built Save or SaveAs problem \n" | ||
| 368 | ); | ||
| 369 | } | ||
| 370 | |||
| 371 | } | ||
| 372 | elsif ( $flow_type eq $flow_type_h->{_pre_built_superflow} ) { | ||
| 373 | |||
| 374 | # print("save_button, director, is superflow_type:$flow_type\n"); | ||
| 375 | |||
| 376 | # print("save_button, director, save_dialog_type: $save_dialog_type\n"); | ||
| 377 | |||
| 378 | if ( $save_dialog_type eq $file_dialog_type->{_Save} ) { | ||
| 379 | _Save_pre_built_superflow(); | ||
| 380 | |||
| 381 | } | ||
| 382 | elsif ( $save_dialog_type eq $file_dialog_type->{_SaveAs} ) { | ||
| 383 | |||
| 384 | # do nothing ... superflows are not saved under a pseudonym | ||
| 385 | } | ||
| 386 | else { | ||
| 387 | print( | ||
| 388 | "save_button, director has superflow Save or SaveAs problem\n"); | ||
| 389 | } | ||
| 390 | |||
| 391 | } | ||
| 392 | else { | ||
| 393 | print("save_button, director has a flow-type problem\n"); | ||
| 394 | } | ||
| 395 | } | ||
| 396 | |||
| 397 | =head2 sub get_all_hash_ref | ||
| 398 | |||
| 399 | return ALL values of the private hash, supposedly | ||
| 400 | improtant external widgets have not been reset.. only conditions | ||
| 401 | are reset | ||
| 402 | TODO: perhaps it is better to have a specific method | ||
| 403 | to return one specific widget address at a time? | ||
| 404 | } | ||
| 405 | |||
| 406 | =cut | ||
| 407 | |||
| 408 | sub get_all_hash_ref { | ||
| 409 | my ($self) = @_; | ||
| 410 | |||
| 411 | if ($save_button) { | ||
| 412 | |||
| 413 | # print("save_button, get_hash_ref , save_button->{_flow_color}: $save_button->{_flow_color}\n"); | ||
| 414 | return ($save_button); | ||
| 415 | |||
| 416 | } | ||
| 417 | else { | ||
| 418 | print("save_button, get_hash_ref , missing hsave_button hash_ref\n"); | ||
| 419 | } | ||
| 420 | } | ||
| 421 | |||
| 422 | =head2 sub _save_button_sub_ref | ||
| 423 | |||
| 424 | =cut | ||
| 425 | |||
| 426 | sub set_save_button_sub_ref { | ||
| 427 | my ( $self, $sub_ref ) = @_; | ||
| 428 | |||
| 429 | if ($sub_ref) { | ||
| 430 | print("binding set_save_button_sub_ref, $sub_ref\n"); | ||
| 431 | $save_button->{_sub_ref} = $sub_ref; | ||
| 432 | |||
| 433 | } | ||
| 434 | else { | ||
| 435 | print("save_button, set_save_button_sub_ref, missing sub ref\n"); | ||
| 436 | } | ||
| 437 | return (); | ||
| 438 | } | ||
| 439 | |||
| 440 | =head2 sub set_dialog_type | ||
| 441 | |||
| 442 | save can be of 3 generic types: | ||
| 443 | |||
| 444 | dialog type can be save (Main menu) | ||
| 445 | or SaveAs (FileDialog_button function) | ||
| 446 | |||
| 447 | i.e. 'either' | ||
| 448 | |||
| 449 | or | ||
| 450 | save (perl program of user-built flow | ||
| 451 | or | ||
| 452 | saveas perl program of user-built flow | ||
| 453 | or | ||
| 454 | save pre-built superflow configuration files | ||
| 455 | |||
| 456 | |||
| 457 | =cut | ||
| 458 | |||
| 459 | sub set_dialog_type { | ||
| 460 | my ( $self, $topic ) = @_; | ||
| 461 | |||
| 462 | if ($topic) { | ||
| 463 | $save_button->{_dialog_type} = $topic; | ||
| 464 | |||
| 465 | # print("save_button, set_dialog_type , $save_button->{_dialog_type} \n"); | ||
| 466 | |||
| 467 | } | ||
| 468 | else { | ||
| 469 | print("save_button, set_dialog_type , missing topic\n"); | ||
| 470 | } | ||
| 471 | return (); | ||
| 472 | } | ||
| 473 | |||
| 474 | =head2 sub set_flow_type | ||
| 475 | |||
| 476 | user_built_flow | ||
| 477 | or | ||
| 478 | pre_built_superflow | ||
| 479 | |||
| 480 | =cut | ||
| 481 | |||
| 482 | sub set_flow_type { | ||
| 483 | my ( $self, $how_built ) = @_; | ||
| 484 | |||
| 485 | if ($how_built) { | ||
| 486 | $save_button->{_flow_type} = $how_built; | ||
| 487 | |||
| 488 | # print("save_button, set_flow_type : $save_button->{_flow_type}\n"); | ||
| 489 | |||
| 490 | } | ||
| 491 | else { | ||
| 492 | print("save_button, set_flow_type , missing how_built\n"); | ||
| 493 | } | ||
| 494 | return (); | ||
| 495 | } | ||
| 496 | |||
| 497 | =head2 sub set_hash_ref | ||
| 498 | bring in important widget addresses | ||
| 499 | |||
| 500 | =cut | ||
| 501 | |||
| 502 | sub set_hash_ref { | ||
| 503 | my ( $self, $hash_ref ) = @_; | ||
| 504 | |||
| 505 | if ($hash_ref) { | ||
| 506 | $gui_history->set_defaults($hash_ref); | ||
| 507 | $save_button = $gui_history->get_defaults(); | ||
| 508 | |||
| 509 | # print("save_button, set_gui_widgets, missing hash_ref\n"); | ||
| 510 | } | ||
| 511 | return (); | ||
| 512 | } | ||
| 513 | |||
| 514 | =head2 sub set_prog_name_sref | ||
| 515 | |||
| 516 | in order to know what | ||
| 517 | _spec file to read for | ||
| 518 | behaviors | ||
| 519 | |||
| 520 | =cut | ||
| 521 | |||
| 522 | sub set_prog_name_sref { | ||
| 523 | my ( $self, $name_sref ) = @_; | ||
| 524 | |||
| 525 | if ($name_sref) { | ||
| 526 | $save_button->{_prog_name_sref} = $name_sref; | ||
| 527 | |||
| 528 | # print( | ||
| 529 | #"save_button, set_prog_name_sref , ${$save_button->{_prog_name_sref}}\n" | ||
| 530 | # ); | ||
| 531 | |||
| 532 | } | ||
| 533 | else { | ||
| 534 | print("save_button, set_prog_name_sref , missing name\n"); | ||
| 535 | } | ||
| 536 | return (); | ||
| 537 | } | ||
| 538 | |||
| 539 | 1; |