« lib/App/SeismicUnixGui/big_streams/iVelocityAnalysis.pl
↑ Summary
lib/App/SeismicUnixGui/sunix/header/suabshw.pm »
| 1 | =head1 DOCUMENTATION | ||
| 2 | |||
| 3 | |||
| 4 | =head2 SYNOPSIS | ||
| 5 | |||
| 6 | PERL PROGRAM NAME: L_SU_ProjectSelector.pl | ||
| 7 | AUTHOR: Juan Lorenzo | ||
| 8 | DATE: May 1 2018 | ||
| 9 | |||
| 10 | |||
| 11 | DESCRIPTION | ||
| 12 | |||
| 13 | |||
| 14 | BASED ON: | ||
| 15 | Version 1.0.1 May 1 2018 | ||
| 16 | |||
| 17 | =cut | ||
| 18 | |||
| 19 | =head2 USE | ||
| 20 | |||
| 21 | =head3 NOTES | ||
| 22 | |||
| 23 | =head4 Examples | ||
| 24 | |||
| 25 | |||
| 26 | =head2 CHANGES and their DATES | ||
| 27 | |||
| 28 | =cut | ||
| 29 | |||
| 30 | use Moose; | ||
| 31 | our $VERSION = '1.0.1'; | ||
| 32 | |||
| 33 | use Tk; | ||
| 34 | use Tk::Pane; | ||
| 35 | use Tk::Font; | ||
| 36 | |||
| 37 | # potentially in all packages | ||
| 38 | use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants'; | ||
| 39 | use aliased 'App::SeismicUnixGui::misc::param_widgets'; | ||
| 40 | use aliased 'App::SeismicUnixGui::misc::project_selector'; | ||
| 41 | use aliased 'App::SeismicUnixGui::messages::message_director'; | ||
| 42 | |||
| 43 | my $project_selector = project_selector->new(); | ||
| 44 | my $get = L_SU_global_constants->new(); | ||
| 45 | my $param_widgets = param_widgets->new(); | ||
| 46 | my $message_director = message_director->new(); | ||
| 47 | |||
| 48 | # print("main,package param_widgets: $param_widgets\n"); | ||
| 49 | |||
| 50 | my $var = $get->var(); | ||
| 51 | |||
| 52 | =head2 | ||
| 53 | |||
| 54 | share the following parameters in same name | ||
| 55 | space | ||
| 56 | |||
| 57 | flow_listbox_l -left listbox, input by user selection | ||
| 58 | flow_listbox_r -right listbox,input by user selection | ||
| 59 | sunix_listbox -choice of listed sunix modules in a listbox | ||
| 60 | |||
| 61 | =cut | ||
| 62 | |||
| 63 | my ($mw); | ||
| 64 | my ( $i, $j, $k ); | ||
| 65 | my ($work_frame); | ||
| 66 | my ( $buttons_frame, $parameters_pane ); | ||
| 67 | my ($parameter_values_button_frame); | ||
| 68 | my ( $parameter_names_frame, $parameter_values_frame ); | ||
| 69 | my ($ref_chk_button_variable); | ||
| 70 | my ( @labels_w, @entries_w ); | ||
| 71 | my ($sunix); | ||
| 72 | my ( @param, @values, @args, @check_buttons, @labels ); | ||
| 73 | my (@on_off_param); | ||
| 74 | my $false = 0; | ||
| 75 | my $true = 1; | ||
| 76 | |||
| 77 | =head2 Default Tk settings{ | ||
| 78 | |||
| 79 | Create scoped hash | ||
| 80 | |||
| 81 | =cut | ||
| 82 | |||
| 83 | my $L_SU_project_selector = { | ||
| 84 | _FileDialog_option => '', | ||
| 85 | _values_w_aref => '', | ||
| 86 | _labels_w_aref => '', | ||
| 87 | _check_buttons_w_aref => '', | ||
| 88 | _mw => '', | ||
| 89 | _active_project => $true, | ||
| 90 | _create_new_button => '', | ||
| 91 | _prog_name => 'Project', | ||
| 92 | }; | ||
| 93 | |||
| 94 | =head2 Main Window contains | ||
| 95 | |||
| 96 | a top menu frame | ||
| 97 | a middle menu titles frame | ||
| 98 | and a | ||
| 99 | bottom work_frame | ||
| 100 | font is made to be arial normal 14 | ||
| 101 | border width is defaulted too | ||
| 102 | |||
| 103 | =cut | ||
| 104 | |||
| 105 | $mw = MainWindow->new; | ||
| 106 | $mw->geometry( $var->{project_selector_box_position} ); | ||
| 107 | $mw->resizable( 0, 0 ); #not resizable in either width or height | ||
| 108 | |||
| 109 | $L_SU_project_selector->{_mw} = $mw; | ||
| 110 | $L_SU_project_selector->{_param_widgets_pkg} = $param_widgets; | ||
| 111 | |||
| 112 | # print("main,package L_SU_project_selector->{_param_widgets}: $L_SU_project_selector->{_param_widgets_pkg}\n"); | ||
| 113 | |||
| 114 | =head2 Define | ||
| 115 | |||
| 116 | fonts to use in the menu | ||
| 117 | |||
| 118 | =cut | ||
| 119 | |||
| 120 | $mw->configure( -title => $var->{_project_selector_title}, ); | ||
| 121 | |||
| 122 | my $garamond = $mw->fontCreate( | ||
| 123 | 'garamond', | ||
| 124 | -family => 'garamond', | ||
| 125 | -weight => 'normal', | ||
| 126 | -size => -14 | ||
| 127 | ); | ||
| 128 | |||
| 129 | my $arial = $mw->fontCreate( | ||
| 130 | 'arial', | ||
| 131 | -family => 'arial', | ||
| 132 | -weight => 'normal', | ||
| 133 | -size => -14 | ||
| 134 | ); | ||
| 135 | |||
| 136 | my $small_garamond = $mw->fontCreate( | ||
| 137 | 'small_garamond', | ||
| 138 | -family => 'garamond', | ||
| 139 | -weight => 'normal', | ||
| 140 | -size => -9 | ||
| 141 | ); | ||
| 142 | |||
| 143 | my $small_arial = $mw->fontCreate( | ||
| 144 | 'small_arial', | ||
| 145 | -family => 'arial', | ||
| 146 | -weight => 'normal', | ||
| 147 | -size => -9 | ||
| 148 | ); | ||
| 149 | |||
| 150 | =head2 Define Work frames | ||
| 151 | |||
| 152 | Top frame contains message | ||
| 153 | Bottom frame contains a list, lables and buttons to choose | ||
| 154 | |||
| 155 | =cut | ||
| 156 | |||
| 157 | my $message_frame = $mw->Frame( | ||
| 158 | -borderwidth => $var->{_one_pixel_borderwidth}, | ||
| 159 | -background => 'blue', | ||
| 160 | -relief => 'groove' | ||
| 161 | ); | ||
| 162 | |||
| 163 | $work_frame = $mw->Frame( | ||
| 164 | -borderwidth => $var->{_one_pixel_borderwidth}, | ||
| 165 | -background => 'yellow', | ||
| 166 | -relief => 'groove' | ||
| 167 | ); | ||
| 168 | |||
| 169 | $buttons_frame = $mw->Frame( | ||
| 170 | -borderwidth => $var->{_one_pixel_borderwidth}, | ||
| 171 | -background => 'blue', | ||
| 172 | -relief => 'groove' | ||
| 173 | ); | ||
| 174 | |||
| 175 | =head2 | ||
| 176 | Buttons within bottom buttons_frame | ||
| 177 | |||
| 178 | =cut | ||
| 179 | |||
| 180 | my $save_button = $buttons_frame->Button( | ||
| 181 | -text => 'Create New', | ||
| 182 | -font => $arial, | ||
| 183 | -height => 1, | ||
| 184 | -activebackground => $var->{_my_yellow}, | ||
| 185 | -activeforeground => $var->{_my_black}, | ||
| 186 | -foreground => $var->{_my_white}, | ||
| 187 | -background => $var->{_my_dark_grey}, | ||
| 188 | -disabledforeground => $var->{_my_white}, | ||
| 189 | -relief => 'flat', | ||
| 190 | -state => 'normal', | ||
| 191 | -command => [ \&_project_selector, 'create_new', 1 ] | ||
| 192 | ); | ||
| 193 | $L_SU_project_selector->{_create_new_button} = $save_button; | ||
| 194 | |||
| 195 | my $ok_button = $buttons_frame->Button( | ||
| 196 | -text => 'OK', | ||
| 197 | -font => $arial, | ||
| 198 | -height => 1, | ||
| 199 | -activebackground => $var->{_my_yellow}, | ||
| 200 | -activeforeground => $var->{_my_black}, | ||
| 201 | -foreground => $var->{_my_white}, | ||
| 202 | -background => $var->{_my_dark_grey}, | ||
| 203 | -relief => 'flat', | ||
| 204 | -state => 'normal', | ||
| 205 | -command => [ \&_project_selector, 'ok', 1 ], | ||
| 206 | ); | ||
| 207 | |||
| 208 | my $cancel_button = $buttons_frame->Button( | ||
| 209 | -text => 'Cancel', | ||
| 210 | -font => $arial, | ||
| 211 | -height => 1, | ||
| 212 | -activebackground => $var->{_my_yellow}, | ||
| 213 | -activeforeground => $var->{_my_black}, | ||
| 214 | -foreground => $var->{_my_white}, | ||
| 215 | -background => $var->{_my_dark_grey}, | ||
| 216 | -relief => 'flat', | ||
| 217 | -state => 'normal', | ||
| 218 | -command => [ \&_project_selector, 'cancel', 1 ], | ||
| 219 | ); | ||
| 220 | |||
| 221 | =head2 parameters frame | ||
| 222 | Contains name_values_frame at the top, | ||
| 223 | and a message_frame at the bottom | ||
| 224 | |||
| 225 | =cut | ||
| 226 | |||
| 227 | $parameters_pane = $work_frame->Scrolled( | ||
| 228 | "Pane", | ||
| 229 | -background => $var->{_light_grey}, | ||
| 230 | -relief => 'groove', | ||
| 231 | -scrollbars => "e", | ||
| 232 | -sticky => 'ns', | ||
| 233 | -width => 600, | ||
| 234 | -height => 280, | ||
| 235 | ); | ||
| 236 | |||
| 237 | $parameter_names_frame = $parameters_pane->Frame( | ||
| 238 | -borderwidth => $var->{_one_pixel_borderwidth}, | ||
| 239 | -background => $var->{_light_grey}, | ||
| 240 | -relief => 'groove', | ||
| 241 | |||
| 242 | ); | ||
| 243 | |||
| 244 | #-width => '1', | ||
| 245 | |||
| 246 | $parameter_values_button_frame = $parameters_pane->Frame( | ||
| 247 | -borderwidth => $var->{_one_pixel_borderwidth}, | ||
| 248 | -background => $var->{_light_grey}, | ||
| 249 | |||
| 250 | -relief => 'groove', | ||
| 251 | ); | ||
| 252 | |||
| 253 | #-width => '10', | ||
| 254 | $parameter_values_frame = $parameters_pane->Frame( | ||
| 255 | -borderwidth => $var->{_one_pixel_borderwidth}, | ||
| 256 | -background => $var->{_my_purple}, | ||
| 257 | |||
| 258 | -relief => 'groove', | ||
| 259 | ); | ||
| 260 | |||
| 261 | #-width => '200', | ||
| 262 | |||
| 263 | =head2 Initialize | ||
| 264 | |||
| 265 | Initially, checkbutton widgets and values | ||
| 266 | are green ("on") or red ("off"), and | ||
| 267 | Labels and Entry Widgets are made blank. | ||
| 268 | |||
| 269 | =cut | ||
| 270 | |||
| 271 | $param_widgets->set_labels_frame( \$parameter_names_frame ); | ||
| 272 | $param_widgets->set_values_frame( \$parameter_values_frame ); | ||
| 273 | $param_widgets->set_check_buttons_frame( \$parameter_values_button_frame ); | ||
| 274 | $param_widgets->initialize_labels(); | ||
| 275 | $param_widgets->initialize_values(); | ||
| 276 | $param_widgets->initialize_check_buttons(); | ||
| 277 | |||
| 278 | # pack and show widgets | ||
| 279 | $param_widgets->show_labels(); | ||
| 280 | $param_widgets->show_values(); | ||
| 281 | $param_widgets->show_check_buttons(); | ||
| 282 | |||
| 283 | =head2 | ||
| 284 | |||
| 285 | |||
| 286 | =cut | ||
| 287 | |||
| 288 | =head2 message area | ||
| 289 | |||
| 290 | to notify user of important evets | ||
| 291 | |||
| 292 | =cut | ||
| 293 | |||
| 294 | my $message_box = $message_frame->Text( | ||
| 295 | -height => 3, | ||
| 296 | -font => $arial, | ||
| 297 | -foreground => $var->{_my_black}, | ||
| 298 | -background => $var->{_my_light_grey}, | ||
| 299 | ); | ||
| 300 | $L_SU_project_selector->{_message_box_w} = $message_box; | ||
| 301 | $message_box->delete( "1.0", 'end' ); | ||
| 302 | my $message = $message_director->project_selector(2); # only one button can be chosen | ||
| 303 | $message_box->insert( 'end', $message ); | ||
| 304 | $L_SU_project_selector->{_message_box_w}->insert( 'end', "\n \n" ); | ||
| 305 | |||
| 306 | $message_frame->pack( | ||
| 307 | -side => "top", | ||
| 308 | -fill => 'x', | ||
| 309 | ); | ||
| 310 | |||
| 311 | $work_frame->pack( | ||
| 312 | -side => "top", | ||
| 313 | -fill => "y", | ||
| 314 | ); | ||
| 315 | |||
| 316 | $buttons_frame->pack( | ||
| 317 | -side => "top", | ||
| 318 | -fill => "y", | ||
| 319 | ); | ||
| 320 | $message_box->pack( | ||
| 321 | -side => "top", | ||
| 322 | -fill => 'x', | ||
| 323 | ); | ||
| 324 | $save_button->pack( | ||
| 325 | -side => "left", | ||
| 326 | -fill => 'x', | ||
| 327 | ); | ||
| 328 | $ok_button->pack( | ||
| 329 | -side => "left", | ||
| 330 | -fill => 'x', | ||
| 331 | ); | ||
| 332 | $cancel_button->pack( | ||
| 333 | -side => "left", | ||
| 334 | -fill => 'x', | ||
| 335 | ); | ||
| 336 | $parameters_pane->pack( | ||
| 337 | -side => "left", | ||
| 338 | -fill => "y", | ||
| 339 | ); | ||
| 340 | $parameter_names_frame->pack( | ||
| 341 | -side => "left", | ||
| 342 | -fill => "y", | ||
| 343 | ); | ||
| 344 | $parameter_values_button_frame->pack( | ||
| 345 | -side => "left", | ||
| 346 | -fill => "y", | ||
| 347 | ); | ||
| 348 | $parameter_values_frame->pack( | ||
| 349 | -side => "top", | ||
| 350 | -fill => "x", | ||
| 351 | ); | ||
| 352 | |||
| 353 | # When the program first starts, the following is executed | ||
| 354 | |||
| 355 | # populate widgets IN PROJECT_SELECTOR MODULE | ||
| 356 | $L_SU_project_selector->{_values_w_aref} = $param_widgets->get_values_w_aref(); | ||
| 357 | $L_SU_project_selector->{_labels_w_aref} = $param_widgets->get_labels_w_aref(); | ||
| 358 | $L_SU_project_selector->{_check_buttons_w_aref} = $param_widgets->get_check_buttons_w_aref(); | ||
| 359 | |||
| 360 | $project_selector->set_hash_ref($L_SU_project_selector); | ||
| 361 | |||
| 362 | # pass the package reference to another package | ||
| 363 | # MUST be called before the first gui is started (i.e., set_gui) | ||
| 364 | # TODO See if the following lines are included already in the hash transger | ||
| 365 | # a few lines above | ||
| 366 | $project_selector->set_param_widgets_pkg( $L_SU_project_selector->{_param_widgets_pkg} ); | ||
| 367 | $project_selector->set_current_program_name( $L_SU_project_selector->{_prog_name} ); | ||
| 368 | $project_selector->set_message_box_w( $L_SU_project_selector->{_message_box_w} ); | ||
| 369 | $project_selector->set_create_new_button_w( $L_SU_project_selector->{_create_new_button} ); | ||
| 370 | |||
| 371 | # FINALLY call the starting gui | ||
| 372 | # automatically populate gui if one or more projects exist | ||
| 373 | # otherwise the gui will be blank | ||
| 374 | $project_selector->set_gui(); | ||
| 375 | |||
| 376 | MainLoop; | ||
| 377 | |||
| 378 | =head2 sub _project_selector | ||
| 379 | |||
| 380 | controls the following actions: | ||
| 381 | -create a new project ( always possible: if projects >=0 ) | ||
| 382 | -reset the active project ( always possible but only meaningful if # projects >1) | ||
| 383 | -cancel ( if projects >=0) | ||
| 384 | |||
| 385 | =cut | ||
| 386 | |||
| 387 | sub _project_selector { | ||
| 388 | my ( $set_method, $value ) = @_; | ||
| 389 | |||
| 390 | if ( length $set_method && length $value ) { | ||
| 391 | |||
| 392 | # print("L_SU_project_selector,method:$set_method, value:$value\n"); | ||
| 393 | |||
| 394 | $project_selector->$set_method($value); | ||
| 395 | # $project_selector->set_hash_ref($L_SU_project_selector); | ||
| 396 | |||
| 397 | } else { | ||
| 398 | print("_project_selector,no method: $set_method error 1,\n"); | ||
| 399 | } | ||
| 400 | |||
| 401 | return (); | ||
| 402 | } |