« lib/App/SeismicUnixGui/sunix/shapeNcut/supad.pm
↑ Summary
lib/App/SeismicUnixGui/specs/transform/suamp_spec.pm »
| 1 | package App::SeismicUnixGui::misc::binding; | ||
| 2 | |||
| 3 | =head1 DOCUMENTATION | ||
| 4 | |||
| 5 | =head2 SYNOPSIS | ||
| 6 | |||
| 7 | PERL PROGRAM NAME: binding.pm | ||
| 8 | AUTHOR: Juan Lorenzo | ||
| 9 | DATE: May 21 2018 | ||
| 10 | |||
| 11 | DESCRIPTION: | ||
| 12 | |||
| 13 | Create bindings | ||
| 14 | between values and buttons an actions | ||
| 15 | Make a binding based on the paramters | ||
| 16 | inside the spec file for that progam | ||
| 17 | (prog_name = $package) | ||
| 18 | e.g. a package can be data_in_spec.pm | ||
| 19 | $length is the number of bound Entry/Values widgets | ||
| 20 | Each value or Entry widget is bound by MB3 to a | ||
| 21 | FileDialog_button such as 'Data' = opening a data file | ||
| 22 | The suffix type of file to open or save (e.g. *su or text or bin etc. | ||
| 23 | ) also exists in the _spec file | ||
| 24 | and can be used later (TODO) | ||
| 25 | |||
| 26 | calls FileButton within this package | ||
| 27 | otherwise well-encapsulated | ||
| 28 | |||
| 29 | USED FOR: | ||
| 30 | |||
| 31 | BASED ON: | ||
| 32 | |||
| 33 | NEEDS: | ||
| 34 | |||
| 35 | for binding, we need to know | ||
| 36 | the program name | ||
| 37 | the program.spec requirements | ||
| 38 | connect bindings of a specific file to the | ||
| 39 | parameter wiudget value/Entry | ||
| 40 | Not all programs have these bindings | ||
| 41 | the bindig type may be for opening a data file | ||
| 42 | or for saving a file | ||
| 43 | or for plotting a file | ||
| 44 | the binding has a data type: | ||
| 45 | package binding_superflows | ||
| 46 | package bindings_flows | ||
| 47 | set_program_name | ||
| 48 | set the widget handles locally | ||
| 49 | set values | ||
| 50 | set_labels | ||
| 51 | |||
| 52 | a_ref = get_binding_types <ButtonRelease-3> | ||
| 53 | a_ref = get_suffix_types su / text | ||
| 54 | a_ref = get_command names open/save/view/plot etc. | ||
| 55 | a_ref = get_command_settings 1,2,3,4 etc. or empty | ||
| 56 | |||
| 57 | =cut | ||
| 58 | |||
| 59 | =head2 Modules in use | ||
| 60 | |||
| 61 | =cut | ||
| 62 | |||
| 63 | use Moose; | ||
| 64 | our $VERSION = '0.0.2'; | ||
| 65 | use Tk; | ||
| 66 | |||
| 67 | use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants'; | ||
| 68 | use aliased 'App::SeismicUnixGui::misc::L_SU_path'; | ||
| 69 | |||
| 70 | =head2 Instantiation | ||
| 71 | |||
| 72 | =cut | ||
| 73 | |||
| 74 | my $L_SU_global_constants = L_SU_global_constants->new(); | ||
| 75 | my $var = $L_SU_global_constants->var(); | ||
| 76 | my $L_SU_path = L_SU_path->new(); | ||
| 77 | |||
| 78 | =head2 Declare local variables | ||
| 79 | |||
| 80 | =cut | ||
| 81 | |||
| 82 | my $empty_string = $var->{_empty_string}; | ||
| 83 | |||
| 84 | =head2 private hash | ||
| 85 | |||
| 86 | =cut | ||
| 87 | |||
| 88 | my $binding = { | ||
| 89 | _prog_name_sref => '', | ||
| 90 | _sub_ref => '', | ||
| 91 | _values_w_aref => '', | ||
| 92 | }; | ||
| 93 | |||
| 94 | =head2 sub set_prog_name_sref | ||
| 95 | |||
| 96 | Know which _spec file to read for | ||
| 97 | behaviors | ||
| 98 | |||
| 99 | =cut | ||
| 100 | |||
| 101 | sub set_prog_name_sref { | ||
| 102 | my ( $self, $name_sref ) = @_; | ||
| 103 | |||
| 104 | if ($name_sref) { | ||
| 105 | $binding->{_prog_name_sref} = $name_sref; | ||
| 106 | |||
| 107 | # print("binding, set_prog_name_sref , ${$binding->{_prog_name_sref}}\n"); | ||
| 108 | |||
| 109 | } | ||
| 110 | else { | ||
| 111 | print("binding, set_prog_name_sref , missing name\n"); | ||
| 112 | } | ||
| 113 | return (); | ||
| 114 | } | ||
| 115 | |||
| 116 | =head2 sub setFileDialog_button_sub_ref | ||
| 117 | |||
| 118 | Set reference to a subroutine in upper levels | ||
| 119 | i.e., L_SU, _FileDialog_button, | ||
| 120 | that connects to the Filebutton for opening directories | ||
| 121 | |||
| 122 | =cut | ||
| 123 | |||
| 124 | sub setFileDialog_button_sub_ref { | ||
| 125 | my ( $self, $sub_ref ) = @_; | ||
| 126 | |||
| 127 | if ($sub_ref) { | ||
| 128 | |||
| 129 | # print("binding set_sub_ref, $sub_ref\n"); | ||
| 130 | $binding->{_sub_ref} = $sub_ref; | ||
| 131 | |||
| 132 | } | ||
| 133 | else { | ||
| 134 | print("binding, set_FileDialog_button_sub_ref, missing sub ref\n"); | ||
| 135 | } | ||
| 136 | |||
| 137 | return (); | ||
| 138 | } | ||
| 139 | |||
| 140 | =head2 sub set_values_w_aref | ||
| 141 | |||
| 142 | =cut | ||
| 143 | |||
| 144 | sub set_values_w_aref { | ||
| 145 | my ( $self, $values_w_aref ) = @_; | ||
| 146 | |||
| 147 | if ($values_w_aref) { | ||
| 148 | $binding->{_values_w_aref} = $values_w_aref; | ||
| 149 | |||
| 150 | #print("binding, set_values_w_aref, $binding->{_values_w_aref}\n"); | ||
| 151 | |||
| 152 | } | ||
| 153 | else { | ||
| 154 | print("binding, set_values_w_aref, missing values\n"); | ||
| 155 | } | ||
| 156 | return (); | ||
| 157 | } | ||
| 158 | |||
| 159 | =head2 sub set | ||
| 160 | |||
| 161 | Bring in a different module for each binding | ||
| 162 | each module has its own rules through *_spec.pm | ||
| 163 | as a program gets used. | ||
| 164 | |||
| 165 | superflow bindings for dial_type e.g., = Data | ||
| 166 | use _FileDialog_button, a method within L_SU | ||
| 167 | |||
| 168 | User-built programs (e.g., sunix programs) | ||
| 169 | which use dial_type = Data | ||
| 170 | use _FileDialog_button, a method within | ||
| 171 | each grey_flow, pink_flow etc. | ||
| 172 | |||
| 173 | =cut | ||
| 174 | |||
| 175 | sub set { | ||
| 176 | my ($self) = @_; | ||
| 177 | |||
| 178 | my $program_name = ${ $binding->{_prog_name_sref} }; | ||
| 179 | # print("binding $program_name\n"); | ||
| 180 | $L_SU_path->set_program_name($program_name); | ||
| 181 | |||
| 182 | my $pathNmodule_spec_w_slash_pm = $L_SU_path->get_pathNmodule_spec_w_slash_pm(); | ||
| 183 | my $pathNmodule_spec_w_colon = $L_SU_path->get_pathNmodule_spec_w_colon(); | ||
| 184 | |||
| 185 | require $pathNmodule_spec_w_slash_pm; | ||
| 186 | |||
| 187 | # INSTANTIATE | ||
| 188 | my $package = $pathNmodule_spec_w_colon->new(); | ||
| 189 | |||
| 190 | $package->binding_index_aref(); | ||
| 191 | $package->flow_type_aref(); | ||
| 192 | $package->file_dialog_type_aref(); | ||
| 193 | |||
| 194 | # Bind each entry: empty text for only the case of data_in (label) to MB3 | ||
| 195 | my $values_w_aref = $binding->{_values_w_aref}; | ||
| 196 | my @values_w = @$values_w_aref; | ||
| 197 | |||
| 198 | my $sub_ref = $binding->{_sub_ref}; | ||
| 199 | |||
| 200 | my $binding_index_aref = $package->get_binding_index_aref(); | ||
| 201 | my @index = @$binding_index_aref; | ||
| 202 | # print("binding,set,file_dialog_type,indices for user-flows and big streams: @index\n"); | ||
| 203 | |||
| 204 | my $file_dialog_type_aref = $package->get_file_dialog_type_aref(); | ||
| 205 | my @file_dialog_type = @$file_dialog_type_aref; | ||
| 206 | |||
| 207 | # from *_spec.pm file, belonging to either a pre_built_superflow, | ||
| 208 | # or a user_built_flow | ||
| 209 | |||
| 210 | my $length = $package->get_binding_length(); | ||
| 211 | |||
| 212 | # print("binding,set,file_dialog_type,length : $length\n"); | ||
| 213 | for ( my $i = 0 ; $i < $length ; $i++ ) { | ||
| 214 | |||
| 215 | my $dial_type = $file_dialog_type[ $index[$i] ]; | ||
| 216 | |||
| 217 | # print("3A. binding,set,prog_name: ${$binding->{_prog_name_sref}}\n"); | ||
| 218 | # print("3B. binding,set,file_dialog_type: $dial_type\n"); | ||
| 219 | # print("3B. binding,set,file_dialog_type: i=$i\n"); | ||
| 220 | |||
| 221 | # ACTUAL binding takes place here... | ||
| 222 | # TODO dynamic binding as a function of input from user in flow | ||
| 223 | if ( length $dial_type ) { | ||
| 224 | |||
| 225 | # print("binding,set,file_dialog_type: $dial_type at index=$i \n"); | ||
| 226 | # print("2. binding,set, no. bound items=$length\n"); | ||
| 227 | |||
| 228 | $values_w[ $index[$i] ] | ||
| 229 | ->bind( '<ButtonRelease-3>' => [ $sub_ref, \$dial_type ], ); | ||
| 230 | |||
| 231 | # sub_ref can be: "L_SU, _FileDialog_button" for superflows | ||
| 232 | # sub_ref can be: "grey_flow, _FileDialog_button" for a user-built flow that | ||
| 233 | # lies in the grey list box | ||
| 234 | |||
| 235 | } | ||
| 236 | else { | ||
| 237 | # print("4. binding,set, no bindings NADA\n"); | ||
| 238 | } | ||
| 239 | } | ||
| 240 | } | ||
| 241 | |||
| 242 | 1; |