OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [perl_gui/] [lib/] [perl/] [widget.pl] - Blame information for rev 44

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 alirezamon
use Glib qw/TRUE FALSE/;
2
#use Gtk2 '-init';
3
use strict;
4
use warnings;
5
 
6 43 alirezamon
require "common.pl";
7 25 alirezamon
 
8 43 alirezamon
use FindBin;
9
use lib $FindBin::Bin;
10 25 alirezamon
 
11 43 alirezamon
use ColorButton;
12 38 alirezamon
 
13 16 alirezamon
use Gtk2::Pango;
14 25 alirezamon
#use Tk::Animation;
15 16 alirezamon
 
16 38 alirezamon
 
17
 
18 16 alirezamon
##############
19
# combo box
20
#############
21
sub gen_combo{
22
        my ($combo_list, $combo_active_pos)= @_;
23
        my $combo = Gtk2::ComboBox->new_text;
24
 
25
        combo_set_names($combo,$combo_list);
26 25 alirezamon
        $combo->set_active($combo_active_pos) if(defined $combo_active_pos);
27 16 alirezamon
 
28
        #my $font = Gtk2::Pango::FontDescription->from_string('Tahoma 5');
29
        #$combo->modify_font($font);
30
 
31
 
32
        return $combo;
33
}
34
 
35
 
36
sub combo_set_names {
37
        my ( $combo, $list_ref ) = @_;
38
        my @list=@{$list_ref};
39
        #print "$list[0]\n";
40
        for my $item (@list){$combo->append_text($item);}
41
}
42
 
43
 
44
sub gen_combo_help {
45
        my ($help, @combo_list, $pos)= @_;
46
        my $box = def_hbox(FALSE, 0);
47
        my $combo= gen_combo(@combo_list, $pos);
48
        my $button=def_image_button("icons/help.png");
49
 
50
        $button->signal_connect("clicked" => sub {message_dialog($help);});
51
 
52
        $box->pack_start( $combo, FALSE, FALSE, 3);
53
        $box->pack_start( $button, FALSE, FALSE, 3);
54
        $box->show_all;
55
 
56
        return ($box,$combo);
57
}
58
 
59
 
60
sub def_h_labeled_combo{
61
                my ($label_name,$combo_list,$combo_active_pos)=@_;
62
                my $box = def_hbox(TRUE,0);
63
                my $label= gen_label_in_left($label_name);
64
                my $combo= gen_combo($combo_list, $combo_active_pos);
65
                $box->pack_start( $label, FALSE, FALSE, 3);
66
                $box->pack_start( $combo, FALSE, TRUE, 3);
67
                return ($box,$combo);
68
}
69
 
70
sub def_h_labeled_combo_scaled{
71
                my ($label_name,$combo_list,$combo_active_pos,$lable_w,$comb_w)=@_;
72
                my $table= def_table(1,3,TRUE);
73
                my $label= gen_label_in_left($label_name);
74
                my $combo= gen_combo($combo_list, $combo_active_pos);
75
                $table->attach_defaults ($label, 0, $lable_w, 0, 1);
76
                $table->attach_defaults ($combo, 1, $lable_w+$comb_w, 0, 1);
77
 
78
 
79
 
80
 
81
                return ($table,$combo);
82
}
83
 
84
 
85
##############
86
# spin button
87
#############
88
sub gen_spin{
89
        my ($min,$max,$step)= @_;
90
        my $spin = Gtk2::SpinButton->new_with_range ($min, $max, $step);
91
        return $spin;
92
}
93
 
94
 
95
 
96
sub gen_spin_help {
97
        my ($help, $min,$max,$step)= @_;
98
        my $box = def_hbox(FALSE, 0);
99
        my $spin= gen_spin($min,$max,$step);
100
        my $button=def_image_button("icons/help.png");
101
 
102
        $button->signal_connect("clicked" => sub {message_dialog($help);});
103
 
104
        $box->pack_start( $spin, FALSE, FALSE, 3);
105
        $box->pack_start( $button, FALSE, FALSE, 3);
106
        $box->show_all;
107
 
108
        return ($box,$spin);
109
}
110
 
111
 
112
#############
113
#  entry
114
#############
115
sub gen_entry{
116
        my ($initial) = @_;
117
        my $entry = Gtk2::Entry->new;
118
        if(defined $initial){ $entry->set_text($initial)};
119
        return $entry;
120
}
121
 
122
 
123
sub gen_entry_help{
124
        my ($help, $init)= @_;
125
        my $box = def_hbox(FALSE, 0);
126
        my $entry= gen_entry ($init);
127
        my $button=def_image_button("icons/help.png");
128
 
129
        $button->signal_connect("clicked" => sub {message_dialog($help);});
130
 
131
        $box->pack_start( $entry, FALSE, FALSE, 3);
132
        $box->pack_start( $button, FALSE, FALSE, 3);
133
        $box->show_all;
134
 
135
        return ($box,$entry);
136
}
137
 
138
sub def_h_labeled_entry{
139
        my ($label_name,$initial)=@_;
140
        my $box = def_hbox(TRUE,0);
141
        my $label= gen_label_in_left($label_name);
142
        my $entry =gen_entry($initial);
143
        $box->pack_start( $label, FALSE, FALSE, 3);
144
        $box->pack_start( $entry, FALSE, FALSE, 3);
145
        return ($box,$entry);
146
 
147 24 alirezamon
}
148 16 alirezamon
 
149 24 alirezamon
sub def_h_labeled_entry_help{
150
        my ($help,$label_name,$initial)=@_;
151
        my $box = def_hbox(TRUE,0);
152
        my $label= gen_label_in_left($label_name);
153
        my ($b,$entry) =gen_entry_help($help,$initial);
154
        $box->pack_start( $label, FALSE, FALSE, 3);
155
        $box->pack_start( $b, FALSE, FALSE, 3);
156
        return ($box,$entry);
157
 
158
}
159
 
160 17 alirezamon
##############
161
# ComboBoxEntry
162
##############
163 16 alirezamon
 
164 17 alirezamon
sub gen_combo_entry{
165 25 alirezamon
        my ($list_ref,$pos)=@_;
166 17 alirezamon
        my @list=@{$list_ref};
167
 
168
        my $combo_box_entry = Gtk2::ComboBoxEntry->new_text;
169
        foreach my $p (@list){
170
                $combo_box_entry->append_text($p);
171
        }
172 25 alirezamon
        $pos=0 if(! defined $pos );
173
        $combo_box_entry->set_active($pos);
174 17 alirezamon
        return $combo_box_entry;
175
}
176
 
177 25 alirezamon
 
178
sub def_h_labeled_combo_entry_help{
179
        my ($help,$label_name,$list_ref,$initial)=@_;
180
        my $box = def_hbox(TRUE,0);
181
        my $label= gen_label_in_left($list_ref);
182
        my ($b,$entry) =gen_combo_entry($help,$initial);
183
        $box->pack_start( $label, FALSE, FALSE, 3);
184
        $box->pack_start( $b, FALSE, FALSE, 3);
185
        return ($box,$entry);
186
 
187
}
188
 
189 24 alirezamon
###########
190 43 alirezamon
# checkbutton
191 24 alirezamon
###########
192
 
193
sub def_h_labeled_checkbutton{
194
        my ($label_name,$status)=@_;
195
        my $box = def_hbox(TRUE,0);
196
        my $label= gen_label_in_left($label_name);
197
        my $check= Gtk2::CheckButton->new;
198
        #if($status==1) $check->
199
        $box->pack_start( $label, FALSE, FALSE, 3);
200
        $box->pack_start( $check, FALSE, FALSE, 3);
201
        return ($box,$check);
202
 
203
}
204
 
205
 
206
 
207
 
208 16 alirezamon
#############
209
#  label
210
############
211
 
212
sub gen_label_in_left{
213
        my ($data)=@_;
214
        my $label   = Gtk2::Label->new($data);
215
        $label->set_alignment( 0, 0.5 );
216
        #my $font = Gtk2::Pango::FontDescription->from_string('Tahoma 5');
217
        #$label->modify_font($font);
218
        return $label;
219
}
220
 
221
 
222
sub gen_label_in_center{
223
        my ($data)=@_;
224
        my $label   = Gtk2::Label->new($data);
225
        return $label;
226
}
227
 
228
sub def_label{
229
        my @data=@_;
230
        my $label   = Gtk2::Label->new(@data);
231
        $label->set_alignment( 0, 0.5 );
232
        return $label;
233
 
234
}
235
 
236
 
237
sub box_label{
238
        my( $homogeneous, $spacing, $name)=@_;
239
        my $box=def_hbox($homogeneous, $spacing);
240
        my $label= def_label($name);
241
        $box->pack_start( $label, FALSE, FALSE, 3);
242
        return $box;
243
}
244
 
245
 
246
sub def_title_box{
247
        my( $homogeneous, $spacing, @labels)=@_;
248
        my $box=def_hbox($homogeneous, $spacing);
249
        foreach my $label (@labels){
250
                my $labelbox=box_label($homogeneous, $spacing, $label);
251
                $box->pack_start( $labelbox, FALSE, FALSE, 3);
252
 
253
        }
254
        return $box;
255
}
256
 
257
 
258
sub gen_label_help {
259
        my ($help, $label_name)= @_;
260
        my $box = def_hbox(FALSE, 0);
261
        my $label= gen_label_in_left($label_name);
262
        my $button=def_image_button("icons/help.png");
263
 
264
        $button->signal_connect("clicked" => sub {message_dialog($help);});
265
 
266
        $box->pack_start( $label, FALSE, FALSE, 0);
267
        $box->pack_start( $button, FALSE, FALSE, 0);
268
        $box->set_spacing (0);
269
        $box->show_all;
270
 
271
        return $box;
272
 
273
 
274
}
275
 
276
 
277
 
278
 
279
##############
280
# button
281
#############
282
 
283
 
284
sub button_box{
285
# create a new button
286
        my @label=@_;
287
        my $button = Gtk2::Button->new_from_stock(@label);
288
        my $box=def_hbox(TRUE,5);
289
        $box->pack_start($button,   FALSE, FALSE,0);
290
 
291
        return ($box,$button);
292
 
293
}
294
 
295
 
296 34 alirezamon
sub def_icon{
297 16 alirezamon
        my $image_file=shift;
298 25 alirezamon
        my $font_size=get_defualt_font_size();
299 16 alirezamon
        my $size=($font_size==10)? 25:
300
                     ($font_size==9 )? 22:
301
                         ($font_size==8 )? 18:
302
                         ($font_size==7 )? 15:12 ;
303
        my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file_at_scale($image_file,$size,$size,FALSE);
304
 
305
 
306
        my $image = Gtk2::Image->new_from_pixbuf($pixbuf);
307
        return $image;
308
 
309
}
310
 
311
 
312 34 alirezamon
sub open_image{
313
        my ($image_file,$x,$y,$unit)=@_;
314
        if(defined $unit){
315
                my($width,$hight)=max_win_size();
316
                if($unit eq 'percent'){
317
                        $x= ($x * $width)/100;
318
                        $y= ($y * $hight)/100;
319
                } # else its pixels
320
 
321
        }
322
        my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file_at_scale($image_file,$x,$y,TRUE);
323
        my $image = Gtk2::Image->new_from_pixbuf($pixbuf);
324
        return $image;
325 43 alirezamon
}
326 16 alirezamon
 
327 43 alirezamon
sub open_inline_image{
328
        my ($image_string,$x,$y,$unit)=@_;
329
        if(defined $unit){
330
                my($width,$hight)=max_win_size();
331
                if($unit eq 'percent'){
332
                        $x= ($x * $width)/100;
333
                        $y= ($y * $hight)/100;
334
                } # else its pixels
335
 
336
        }
337
        my $pixbuf = do {
338
        my $loader = Gtk2::Gdk::PixbufLoader->new();
339
        $loader->set_size(  $x,$y );
340
        $loader->write(  $image_string );
341
        $loader->close();
342
        $loader->get_pixbuf();
343
    };
344
 
345
 
346
        my $image = Gtk2::Image->new_from_pixbuf($pixbuf);
347
 
348
        return $image;
349 34 alirezamon
}
350
 
351
 
352
 
353 16 alirezamon
sub def_image_button{
354 43 alirezamon
        my ($image_file, $label_text, $homogeneous, $mnemonic)=@_;
355 16 alirezamon
        # create box for image and label 
356 25 alirezamon
        $homogeneous = FALSE if(!defined $homogeneous);
357
        my $box = def_hbox($homogeneous,0);
358 34 alirezamon
        my $image = def_icon($image_file) if(-f $image_file);
359 16 alirezamon
 
360
 
361
        # now on to the image stuff
362
        #my $image = Gtk2::Image->new_from_file($image_file);
363 34 alirezamon
        $box->pack_start($image, FALSE, FALSE, 0) if(-f $image_file);
364 16 alirezamon
        $box->set_border_width(0);
365
        $box->set_spacing (0);
366
        # Create a label for the button
367
        if(defined $label_text ) {
368 43 alirezamon
                my $label;
369
                $label = Gtk2::Label->new("  $label_text") unless (defined $mnemonic);
370
                $label = Gtk2::Label->new_with_mnemonic (" $label_text") if (defined $mnemonic);
371 16 alirezamon
                $box->pack_start($label, FALSE, FALSE, 0);
372 44 alirezamon
        }
373 16 alirezamon
 
374
        my $button = Gtk2::Button->new();
375
        $button->add($box);
376
        $button->set_border_width(0);
377
        $button->show_all;
378
        return $button;
379
}
380
 
381 44 alirezamon
sub def_button{
382
        my ($label_text)=@_;
383
        my $label = Gtk2::Label->new("$label_text");
384
        my $button= Gtk2::Button->new();
385
        $button->add($label);
386
        return $button;
387
}
388 16 alirezamon
 
389 44 alirezamon
 
390 16 alirezamon
sub def_image_label{
391 43 alirezamon
        my ($image_file, $label_text,$mnemonic)=@_;
392 16 alirezamon
        # create box for image and label 
393
        my $box = def_hbox(FALSE,1);
394
        # now on to the image stuff
395 34 alirezamon
        my $image = def_icon($image_file);
396 16 alirezamon
        $box->pack_start($image, TRUE, FALSE, 0);
397
        # Create a label for the button
398
        if(defined $label_text ) {
399 43 alirezamon
                my $label;
400
                $label = Gtk2::Label->new("  $label_text") unless (defined $mnemonic);
401
                $label = Gtk2::Label->new_with_mnemonic (" $label_text") if (defined $mnemonic);
402 16 alirezamon
                $box->pack_start($label, TRUE, FALSE, 0);
403
        }
404
 
405
        return $box;
406
 
407
}
408
 
409
 
410
sub gen_button_message {
411
        my ($help, $image_file,$label_name)= @_;
412
        my $box = def_hbox(FALSE, 0);
413
        my $label= gen_label_in_center($label_name) if(defined $label_name);
414
        my $button=def_image_button($image_file);
415
 
416
        if(defined $help ){$button->signal_connect("clicked" => sub {message_dialog($help);});}
417
 
418
        $box->pack_start( $label, FALSE, FALSE, 0) if(defined $label_name);
419
        $box->pack_start( $button, FALSE, FALSE, 0);
420
        $box->set_border_width(0);
421
        $box->set_spacing (0);
422
        $box->show_all;
423
 
424
        return $box;
425
 
426
 
427
}
428
 
429
 
430
sub def_colored_button{
431
        my ($label_text,$color_num)=@_;
432
        # create box for image and label 
433
        my $box = def_hbox(FALSE,0);
434 25 alirezamon
        my $font_size=get_defualt_font_size();
435 16 alirezamon
 
436 43 alirezamon
        my ($red,$green,$blue) = get_color($color_num);
437
        my $button = ColorButton->new (red => $red, green => $green, blue => $blue, label=>"$label_text");
438
 
439 16 alirezamon
        $button->set_border_width(0);
440
        $button->show_all;
441
        return $button;
442
 
443
}
444
 
445
 
446 25 alirezamon
sub show_gif{
447
        my $gif = shift;
448
        my $vbox = Gtk2::HBox->new (TRUE, 8);
449
    my $filename;
450
      eval {
451
          $filename = main::demo_find_file ($gif);
452
      };
453 43 alirezamon
    my $image = Gtk2::Image->new_from_file ($gif);
454
    $vbox->set_border_width (4);
455
    my   $align = Gtk2::Alignment->new (0.5, 0.5, 0, 0);
456 25 alirezamon
        my $frame = Gtk2::Frame->new;
457
        $frame->set_shadow_type ('in');
458 43 alirezamon
    # Animation
459
    $frame->add ($image);
460
    $align->add ($frame);
461
        $vbox->pack_start ($align, FALSE, FALSE, 0);
462
        return $vbox;
463 25 alirezamon
}
464
 
465 16 alirezamon
############
466
#       message_dialog
467
############
468
 
469
sub message_dialog {
470 34 alirezamon
  my ($message,$type)=@_;
471
  $type = 'info' if (!defined $type);
472 16 alirezamon
  my $window;
473
  my $dialog = Gtk2::MessageDialog->new ($window,
474
                                   [qw/modal destroy-with-parent/],
475 34 alirezamon
                                   $type,
476 16 alirezamon
                                   'ok',
477 34 alirezamon
                                    $message);
478 16 alirezamon
  $dialog->run;
479
  $dialog->destroy;
480
 
481
}
482
 
483
 
484 38 alirezamon
 
485
sub set_tip{
486
        my ($widget,$tip)=@_;
487
        my $tooltips = Gtk2::Tooltips->new;
488
        $tooltips->set_tip($widget,$tip);
489
 
490
 
491
}
492
 
493
 
494 16 alirezamon
############
495
# window
496
###########
497
 
498
sub def_win {
499
        my @titel=shift;
500
        my $window = Gtk2::Window->new('toplevel');
501
        $window->set_title(@titel);
502
        $window->set_position("center");
503
        $window->set_default_size(100, 100);
504
        $window->set_border_width(20);
505
        $window->signal_connect (delete_event => sub { Gtk2->main_quit });
506
        return $window;
507
 
508
}
509
 
510
 
511
sub def_win_size {
512
        my $x=shift;
513
        my $y=shift;
514
        my @titel=shift;
515
        my $window = Gtk2::Window->new('toplevel');
516
        $window->set_title(@titel);
517
        $window->set_position("center");
518
        $window->set_default_size($x, $y);
519
        $window->set_border_width(20);
520
        $window->signal_connect (delete_event => sub { Gtk2->main_quit });
521
        return $window;
522
 
523
}
524
 
525
 
526
sub def_popwin_size {
527 34 alirezamon
        my ($x,$y,$titel,$unit)=@_;
528
        if(defined $unit){
529
                my($width,$hight)=max_win_size();
530
                if($unit eq 'percent'){
531
                        $x= ($x * $width)/100;
532
                        $y= ($y * $hight)/100;
533
                } # else its pixels
534
 
535
        }
536 16 alirezamon
        #my $window = Gtk2::Window->new('popup');
537
        my $window = Gtk2::Window->new('toplevel');
538 34 alirezamon
        $window->set_title($titel);
539 16 alirezamon
        $window->set_position("center");
540
        $window->set_default_size($x, $y);
541
        $window->set_border_width(20);
542
        $window->signal_connect (delete_event => sub { $window->destroy });
543
        return $window;
544
 
545
}
546
 
547
 
548 25 alirezamon
 
549
 
550
 
551 16 alirezamon
sub def_scrolled_window_box{
552
 
553
        my $window =  def_popwin_size(@_);
554
        my $box=def_vbox(TRUE,5);
555
        my $scrolled_window = new Gtk2::ScrolledWindow (undef, undef);
556
        $scrolled_window->set_policy( "automatic", "automatic" );
557
        $scrolled_window->add_with_viewport($box);
558
        $window->add($scrolled_window);
559
        $window->show_all;
560
        $box->show_all;
561
        return ($box,$window);
562
 
563
}
564
 
565
sub max_win_size{
566
        my $screen =Gtk2::Gdk::Screen->get_default();
567
        my $hight = $screen->get_height();
568
        my $width = $screen->get_width();
569
        return ($width,$hight);
570
}
571
 
572
 
573 25 alirezamon
sub get_defualt_font_size{
574 16 alirezamon
        my($width,$hight)=max_win_size();
575
        #print "($width,$hight)\n";
576
        my $font_size=($width>=1600)? 10:
577
                              ($width>=1400)? 9:
578 34 alirezamon
                                  ($width>=1200)? 9:
579 16 alirezamon
                                  ($width>=1000)? 7:6;
580 25 alirezamon
        #print "$font_size\n";  
581 16 alirezamon
        return $font_size;
582
}
583
 
584
 
585 25 alirezamon
sub set_defualt_font_size{
586
        my $font_size=get_defualt_font_size();
587
 
588 16 alirezamon
                Gtk2::Rc->parse_string(<<__);
589
                        style "normal" {
590 25 alirezamon
                                font_name ="Verdana $font_size"
591 16 alirezamon
                        }
592
                        widget "*" style "normal"
593
__
594
 
595
}
596
 
597 38 alirezamon
sub gen_scr_win_with_adjst {
598
        my ($self,$name)=@_;
599
        my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
600
        $scrolled_win->set_policy( "automatic", "automatic" );
601
        $scrolled_win->signal_connect("destroy"=> sub{
602
                save_scrolled_win_adj($self,$scrolled_win, $name);
603
 
604
         });
605
         my $adjast=0;
606
         $scrolled_win->signal_connect("size-allocate"=> sub{
607
                if($adjast==0){
608
                        load_scrolled_win_adj($self,$scrolled_win, $name);
609
                        $adjast=1;
610
                }
611
 
612
         });
613
        return $scrolled_win;
614
}
615 16 alirezamon
 
616 38 alirezamon
 
617
sub save_scrolled_win_adj {
618
        my ($self,$scrolled_win,$name)=@_;
619
        my $ha= $scrolled_win->get_hadjustment();
620
    my $va =$scrolled_win->get_vadjustment();
621
    return if(!defined $ha);
622
    return if(!defined $va);
623
    save_adj ($self,$ha,$name,"ha");
624
        save_adj ($self,$va,$name,"va");
625
}
626
 
627
 
628
sub load_scrolled_win_adj {
629
        my ($self,$scrolled_win,$name)=@_;
630
        my $ha= $scrolled_win->get_hadjustment();
631
    my $va =$scrolled_win->get_vadjustment();
632
        my $h=load_adj ($self,$ha,$name,"ha");
633
        my $v=load_adj ($self,$va,$name,"va");
634
        #$ha->set_value($h) if(defined $h);
635
    #$va->set_value($v) if(defined $v);    
636
}
637
 
638
 
639
 
640
 
641
sub save_adj {
642
        my ($self,$adjustment,$at1,$at2)=@_;
643
        my $value = $adjustment->value;
644
        $self->object_add_attribute($at1,$at2,$value);
645
}
646
 
647
 
648
sub load_adj {
649
        my ($self,$adjustment,$at1,$at2)=@_;
650
        return if(!defined $at1);
651
    my $value=  $self->object_get_attribute($at1,$at2);
652
    return if(!defined $value);
653
    my $lower =  $adjustment->lower;
654
    my $upper = $adjustment->upper - $adjustment->page_size;
655
    $value=  ($value < $lower || $value > $upper ) ? 0 : $value;
656
 
657
    $adjustment->set_value($value);
658
}
659
 
660
 
661 16 alirezamon
##############
662
#       box
663
#############
664
 
665
sub def_hbox {
666
        my( $homogeneous, $spacing)=@_;
667
        my $box = Gtk2::HBox->new($homogeneous, $spacing);
668
        $box->set_border_width(2);
669
        return $box;
670
}
671
 
672
sub def_vbox {
673
        my $box = Gtk2::VBox->new(FALSE, 0);
674
        $box->set_border_width(2);
675
        return $box;
676
}
677
 
678
sub def_pack_hbox{
679
        my( $homogeneous, $spacing , @box_list)=@_;
680
        my $box=def_hbox($homogeneous, $spacing);
681
        foreach my $subbox (@box_list){
682
                $box->pack_start( $subbox, FALSE, FALSE, 3);
683
        }
684
        return $box;
685
 
686
 
687
}
688
 
689 34 alirezamon
sub def_pack_vbox{
690
        my( $homogeneous, $spacing , @box_list)=@_;
691
        my $box=def_vbox($homogeneous, $spacing);
692
        foreach my $subbox (@box_list){
693
                $box->pack_start( $subbox, FALSE, FALSE, 3);
694
        }
695
        return $box;
696 16 alirezamon
 
697 34 alirezamon
}
698 16 alirezamon
 
699 34 alirezamon
 
700
##########
701
# Paned
702
#########
703
 
704
 
705
sub gen_vpaned {
706
        my ($w1,$loc,$w2) = @_;
707
        my $vpaned = Gtk2::VPaned -> new;
708
        my($width,$hight)=max_win_size();
709
 
710
 
711
        $vpaned -> pack1($w1, TRUE, TRUE);
712
        $vpaned -> set_position ($hight*$loc);
713
        $vpaned -> pack2($w2, TRUE, TRUE);
714
 
715
        return $vpaned;
716
}
717
 
718
 
719
sub gen_hpaned {
720
        my ($w1,$loc,$w2) = @_;
721
        my $hpaned = Gtk2::HPaned -> new;
722
        my($width,$hight)=max_win_size();
723
 
724
 
725
        $hpaned -> pack1($w1, TRUE, TRUE);
726
        $hpaned -> set_position ($width*$loc);
727
        $hpaned -> pack2($w2, TRUE, TRUE);
728
 
729
        return $hpaned;
730
}
731
 
732 16 alirezamon
#############
733
# text_view 
734
############
735
 
736
sub create_text {
737
  my $scrolled_window = Gtk2::ScrolledWindow->new;
738
  $scrolled_window->set_policy ('automatic', 'automatic');
739
  $scrolled_window->set_shadow_type ('in');
740
  my $tview = Gtk2::TextView->new();
741
  $scrolled_window->add ($tview);
742
  $tview->show_all;
743
  # Make it a bit nicer for text.
744
  $tview->set_wrap_mode ('word');
745
  $tview->set_pixels_above_lines (2);
746
  $tview->set_pixels_below_lines (2);
747 38 alirezamon
 # $scrolled_window->set_placement('bottom_left' );
748 43 alirezamon
 add_colors_to_textview($tview);
749 16 alirezamon
  return ($scrolled_window,$tview);
750
}
751
 
752
 
753 44 alirezamon
 
754
 
755
 
756 16 alirezamon
#################
757
#       table
758
################
759
 
760
sub def_table{
761
        my ($row,$col,$homogeneous)=@_;
762
        my $table = Gtk2::Table->new ($row, $col, $homogeneous);
763
        $table->set_row_spacings (0);
764
        $table->set_col_spacings (0);
765
        return $table;
766
 
767
}
768
 
769 38 alirezamon
sub attach_widget_to_table {
770
        my ($table,$row,$label,$inf_bt,$widget,$column)=@_;
771
        $column = 0 if(!defined $column);
772
        $column *=4;
773
        #my $tmp=gen_label_in_left(" "); 
774
        if(defined $label)  {$table->attach  ($label , $column, $column+1,  $row,$row+1,'fill','shrink',2,2);$column++;}
775
        if(defined $inf_bt) {$table->attach  ($inf_bt , $column, $column+1, $row,$row+1,'fill','shrink',2,2);$column++;}
776
        if(defined $widget) {$table->attach  ($widget , $column, $column+1, $row,$row+1,'fill','shrink',2,2);$column++;}
777
        #$table->attach  ($tmp , $column+3, $column+4, $row,$row+1,'fill','shrink',2,2);
778
}
779 16 alirezamon
 
780
 
781
 
782
##################
783
#       show_info
784
##################
785
sub show_info{
786
        my ($textview_ref,$info)=@_;
787
        my $buffer = $$textview_ref->get_buffer();
788
        $buffer->set_text($info);
789
}
790
 
791 25 alirezamon
sub add_info{
792
        my ($textview_ref,$info)=@_;
793
        my $buffer = $$textview_ref->get_buffer();
794
        my $textiter = $buffer->get_end_iter();
795
        #Insert some text into the buffer
796
        $buffer->insert($textiter,$info);
797
 
798
}
799 16 alirezamon
 
800 38 alirezamon
 
801
sub new_on_textview{
802
        my ($textview,$info)=@_;
803
        my $buffer = $textview->get_buffer();
804
        $buffer->set_text($info);
805
}
806
 
807
sub append_to_textview{
808
        my ($textview,$info)=@_;
809
        my $buffer = $textview->get_buffer();
810
        my $textiter = $buffer->get_end_iter();
811
        #Insert some text into the buffer
812
        $buffer->insert($textiter,$info);
813
 
814
 
815
}
816
 
817
 
818 34 alirezamon
sub show_colored_info{
819
        my ($textview_ref,$info,$color)=@_;
820
        my $buffer = $$textview_ref->get_buffer();
821
        #$buffer->set_text($info);
822
        my $textiter = $buffer->get_start_iter();
823
        $buffer->insert_with_tags_by_name ($textiter, "$info", "${color}_tag");
824
}
825 16 alirezamon
 
826 34 alirezamon
sub add_colored_info{
827
        my ($textview_ref,$info,$color)=@_;
828
        my $buffer = $$textview_ref->get_buffer();
829
        my $textiter = $buffer->get_end_iter();
830
        #Insert some text into the buffer
831
        #$buffer->insert($textiter,$info);
832
        $buffer->insert_with_tags_by_name ($textiter, "$info", "${color}_tag");
833
 
834
}
835 25 alirezamon
 
836 38 alirezamon
sub add_colors_to_textview{
837
        my $tview= shift;
838
        add_colored_tag($tview,'red');
839
        add_colored_tag($tview,'blue');
840
        add_colored_tag($tview,'green');
841
}
842
 
843
 
844 34 alirezamon
sub add_colored_tag{
845
        my ($textview_ref,$color)=@_;
846
        my $buffer = $textview_ref->get_buffer();
847
        $buffer->create_tag ("${color}_tag", foreground => $color);
848
}
849
 
850 25 alirezamon
sub add_color_to_gd{
851
        foreach (my $i=0;$i<32;$i++ ) {
852 34 alirezamon
                my ($red,$green,$blue)=get_color($i);
853
                add_colour("my_color$i"=>[$red>>8,$green>>8,$blue>>8]);
854 25 alirezamon
 
855 34 alirezamon
        }
856
}
857
 
858
 
859
 
860 25 alirezamon
############
861
#       get file folder list
862
###########
863
 
864 43 alirezamon
sub get_directory_name_widget {
865 25 alirezamon
        my ($object,$title,$entry,$attribute1,$attribute2,$status,$timeout)= @_;
866
        my $browse= def_image_button("icons/browse.png");
867
 
868
        $browse->signal_connect("clicked"=> sub{
869
                my $entry_ref=$_[1];
870
                my $file;
871
                $title ='select directory' if(!defined $title);
872
                my $dialog = Gtk2::FileChooserDialog->new(
873
                        $title, undef,
874
                        #               'open',
875
                        'select-folder',
876
                        'gtk-cancel' => 'cancel',
877
                        'gtk-ok'     => 'ok',
878
                        );
879
 
880
 
881
                        if ( "ok" eq $dialog->run ) {
882
                        $file = $dialog->get_filename;
883
                                $$entry_ref->set_text($file);
884
                                $object->object_add_attribute($attribute1,$attribute2,$file);
885
                                set_gui_status($object,$status,$timeout) if(defined $status);
886
                                #check_input_file($file,$socgen,$soc_state,$info);
887
                                #print "file = $file\n";
888
                         }
889
                        $dialog->destroy;
890
 
891
 
892
 
893
                } , \$entry);
894
 
895
        return $browse;
896
 
897
}
898
 
899 43 alirezamon
 
900
sub get_dir_name {
901
        my ($object,$title,$attribute1,$attribute2,$open_in,$status,$timeout)= @_;
902
        my $dir;
903
        $title ='select directory' if(!defined $title);
904
        my $dialog = Gtk2::FileChooserDialog->new(
905
                $title, undef,
906
                #               'open',
907
                'select-folder',
908
                'gtk-cancel' => 'cancel',
909
                'gtk-ok'     => 'ok',
910
        );
911
        if(defined  $open_in){
912
                $dialog->set_current_folder ($open_in);
913
        }
914
 
915
        if ( "ok" eq $dialog->run ) {
916
                        $dir = $dialog->get_filename;
917
                                $object->object_add_attribute($attribute1,$attribute2,$dir);
918
                                set_gui_status($object,$status,$timeout) if(defined $status);
919
                                $dialog->destroy;
920
        }
921 41 alirezamon
}
922
 
923
 
924 25 alirezamon
 
925
sub get_file_name {
926
        my ($object,$title,$entry,$attribute1,$attribute2,$extension,$lable,$open_in)= @_;
927
        my $browse= def_image_button("icons/browse.png");
928 38 alirezamon
 
929 25 alirezamon
        $browse->signal_connect("clicked"=> sub{
930
                my $entry_ref=$_[1];
931
                my $file;
932
                $title ='select directory' if(!defined $title);
933
                my $dialog = Gtk2::FileChooserDialog->new(
934
                'Select a File', undef,
935
                'open',
936
                'gtk-cancel' => 'cancel',
937
                'gtk-ok'     => 'ok',
938
                );
939
         if(defined $extension){
940
                my $filter = Gtk2::FileFilter->new();
941
                $filter->set_name($extension);
942
                $filter->add_pattern("*.$extension");
943
                $dialog->add_filter ($filter);
944
         }
945
          if(defined  $open_in){
946
                $dialog->set_current_folder ($open_in);
947
                # print "$open_in\n";
948
 
949
        }
950
 
951
                        if ( "ok" eq $dialog->run ) {
952 38 alirezamon
                        $file = $dialog->get_filename;
953 34 alirezamon
                                #remove $project_dir form beginig of each file
954 38 alirezamon
                $file =remove_project_dir_from_addr($file);
955 25 alirezamon
                                $$entry_ref->set_text($file);
956 34 alirezamon
                                $object->object_add_attribute($attribute1,$attribute2,$file) if(defined $object);
957 25 alirezamon
                                my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
958 34 alirezamon
                                if(defined $lable){
959
                                        $lable->set_markup("<span  foreground= 'black' ><b>$name$suffix</b></span>");
960
                                        $lable->show;
961
                                }
962 25 alirezamon
 
963
                                #check_input_file($file,$socgen,$soc_state,$info);
964
                                #print "file = $file\n";
965
                         }
966
                        $dialog->destroy;
967
 
968
 
969
 
970
                } , \$entry);
971
 
972
        return $browse;
973
 
974
}
975
 
976
 
977
#################
978
#       widget update object
979
#################
980
 
981
sub gen_entry_object {
982
        my ($object,$attribute1,$attribute2,$default,$status,$timeout)=@_;
983
        my $old=$object->object_get_attribute($attribute1,$attribute2);
984
        my $widget;
985
        if(defined $old ){
986
                $widget=gen_entry($old);
987
        }
988
        else
989
        {
990
                $widget=gen_entry($default);
991
                $object->object_add_attribute($attribute1,$attribute2,$default);
992
        }
993
        $widget-> signal_connect("changed" => sub{
994
                my $new_param_value=$widget->get_text();
995
                $object->object_add_attribute($attribute1,$attribute2,$new_param_value);
996
                set_gui_status($object,$status,$timeout) if (defined $status);
997
        });
998
        return $widget;
999
}
1000
 
1001
 
1002
sub gen_combobox_object {
1003
        my ($object,$attribute1,$attribute2,$content,$default,$status,$timeout)=@_;
1004
        my @combo_list=split(",",$content);
1005
        my $value=$object->object_get_attribute($attribute1,$attribute2);
1006
        my $pos;
1007
        $pos=get_pos($value, @combo_list) if (defined $value);
1008
        if(!defined $pos && defined $default){
1009
                $object->object_add_attribute($attribute1,$attribute2,$default);
1010
                $pos=get_item_pos($default, @combo_list);
1011
        }
1012
        #print " my $pos=get_item_pos($value, @combo_list);\n";
1013
        my $widget=gen_combo(\@combo_list, $pos);
1014
        $widget-> signal_connect("changed" => sub{
1015
                my $new_param_value=$widget->get_active_text();
1016
                $object->object_add_attribute($attribute1,$attribute2,$new_param_value);
1017
                set_gui_status($object,$status,$timeout) if (defined $status);
1018
         });
1019
        return $widget;
1020
 
1021
 
1022
}
1023
 
1024
 
1025
sub gen_comboentry_object {
1026
        my ($object,$attribute1,$attribute2,$content,$default,$status,$timeout)=@_;
1027
        my @combo_list=split(",",$content);
1028
        my $value=$object->object_get_attribute($attribute1,$attribute2);
1029
        my $pos;
1030
        $pos=get_pos($value, @combo_list) if (defined $value);
1031
        if(!defined $pos && defined $default){
1032
                $object->object_add_attribute($attribute1,$attribute2,$default);
1033
                $pos=get_item_pos($default, @combo_list);
1034
        }
1035
        #print " my $pos=get_item_pos($value, @combo_list);\n";
1036
        my $widget=gen_combo_entry(\@combo_list, $pos);
1037
        ($widget->child)->signal_connect('changed' => sub {
1038
                my ($entry) = @_;
1039
                my $new_param_value=$entry->get_text();
1040
                $object->object_add_attribute($attribute1,$attribute2,$new_param_value);
1041
                set_gui_status($object,$status,$timeout) if (defined $status);
1042
         });
1043
        return $widget;
1044
 
1045
}
1046
 
1047
 
1048
 
1049
sub gen_spin_object {
1050
        my ($object,$attribute1,$attribute2,$content, $default,$status,$timeout)=@_;
1051
        my $value=$object->object_get_attribute($attribute1,$attribute2);
1052
        my ($min,$max,$step)=split(",",$content);
1053
        if(!defined $value){
1054
                $value=$default;
1055
                $object->object_add_attribute($attribute1,$attribute2,$value);
1056
        }
1057 38 alirezamon
 
1058
        $value=~ s/[^0-9.]//g;
1059
        $min=~   s/[^0-9.]//g;
1060
        $max=~   s/[^0-9.]//g;
1061
        $step=~  s/[^0-9.]//g;
1062
 
1063
 
1064 25 alirezamon
        my $widget=gen_spin($min,$max,$step);
1065
        $widget->set_value($value);
1066
        $widget-> signal_connect("value_changed" => sub{
1067 38 alirezamon
                my $new_param_value=$widget->get_value();
1068 25 alirezamon
                $object->object_add_attribute($attribute1,$attribute2,$new_param_value);
1069
                set_gui_status($object,$status,$timeout) if (defined $status);
1070
        });
1071
        return $widget;
1072
}
1073
 
1074
 
1075 34 alirezamon
sub gen_check_box_object_array {
1076
                my ($object,$attribute1,$attribute2,$content,$default,$status,$timeout)=@_;
1077
                my $value=$object->object_get_attribute($attribute1,$attribute2);
1078
                $value = $default if (!defined $value);
1079 25 alirezamon
                my $widget = def_hbox(FALSE,0);
1080
                my @check;
1081
                for (my $i=0;$i<$content;$i++){
1082
                        $check[$i]= Gtk2::CheckButton->new;
1083
                }
1084
                for (my $i=0;$i<$content;$i++){
1085
                        $widget->pack_end(  $check[$i], FALSE, FALSE, 0);
1086
 
1087
                        my @chars = split("",$value);
1088
                        #check if saved value match the size of check box
1089
                        if($chars[0] ne $content ) {
1090
                                $object->object_add_attribute($attribute1,$attribute2,$default);
1091
                                $value=$default;
1092
                                @chars = split("",$value);
1093
                        }
1094
                        #set initial value
1095
 
1096
                        #print "\@chars=@chars\n";
1097
                        for (my $i=0;$i<$content;$i++){
1098
                                my $loc= (scalar @chars) -($i+1);
1099
                                        if( $chars[$loc] eq '1') {$check[$i]->set_active(TRUE);}
1100
                                        else {$check[$i]->set_active(FALSE);}
1101
                        }
1102
 
1103
 
1104
                        #get new value
1105
                        $check[$i]-> signal_connect("toggled" => sub{
1106
                                my $new_val="$content\'b";
1107
 
1108
                                for (my $i=$content-1; $i >= 0; $i--){
1109
                                        if($check[$i]->get_active()) {$new_val="${new_val}1" ;}
1110
                                        else {$new_val="${new_val}0" ;}
1111
                                }
1112
                                $object->object_add_attribute($attribute1,$attribute2,$new_val);
1113
                                #print "\$new_val=$new_val\n";
1114
                                set_gui_status($object,$status,$timeout) if (defined $status);
1115
                        });
1116
        }
1117
        return $widget;
1118
 
1119
}
1120
 
1121
 
1122
 
1123 34 alirezamon
 
1124
 
1125
sub gen_check_box_object {
1126
                my ($object,$attribute1,$attribute2,$default,$status,$timeout)=@_;
1127
                my $value=$object->object_get_attribute($attribute1,$attribute2);
1128
                if (!defined $value){
1129
                        #set initial value
1130
                        $object->object_add_attribute($attribute1,$attribute2,$default);
1131
                        $value = $default
1132
                }
1133
                my $widget = Gtk2::CheckButton->new;
1134
                if($value == 1) {$widget->set_active(TRUE);}
1135
                else {$widget->set_active(FALSE);}
1136
 
1137
                #get new value
1138
                $widget-> signal_connect("toggled" => sub{
1139
                        my $new_val;
1140
                        if($widget->get_active()) {$new_val=1;}
1141
                        else {$new_val=0;}
1142
                        $object->object_add_attribute($attribute1,$attribute2,$new_val);
1143
                        #print "\$new_val=$new_val\n";
1144
                        set_gui_status($object,$status,$timeout) if (defined $status);
1145
                });
1146
 
1147
        return $widget;
1148
 
1149
}
1150
 
1151
 
1152
 
1153
 
1154
 
1155
 
1156 25 alirezamon
sub get_dir_in_object {
1157 38 alirezamon
        my ($object,$attribute1,$attribute2,$content,$status,$timeout,$default)=@_;
1158 25 alirezamon
        my $widget = def_hbox(FALSE,0);
1159
        my $value=$object->object_get_attribute($attribute1,$attribute2);
1160 38 alirezamon
        $object->object_add_attribute($attribute1,$attribute2,  $default) if (!defined $value );
1161
        $value = $default if (!defined $value );
1162 43 alirezamon
        if (defined $default){
1163
                $object->object_add_attribute($attribute1,$attribute2,  $default) if  !(-d $value );
1164
                $value = $default  if !(-d $value );
1165
        };
1166
 
1167
        my $warning;
1168
 
1169 25 alirezamon
        my $entry=gen_entry($value);
1170
        $entry-> signal_connect("changed" => sub{
1171
                my $new_param_value=$entry->get_text();
1172
                $object->object_add_attribute($attribute1,$attribute2,$new_param_value);
1173
                set_gui_status($object,$status,$timeout) if (defined $status);
1174 43 alirezamon
                unless (-d $new_param_value ){
1175
                        if (!defined $warning){
1176
                                $warning = def_icon("icons/warning.png");
1177
                                $widget->pack_start( $warning, FALSE, FALSE, 0);
1178
                                set_tip($warning,"$new_param_value is not a valid directory");
1179
                                $widget->show_all;
1180
                        }
1181
 
1182
                }else{
1183
                        $warning->destroy if (defined $warning);
1184
                        undef $warning;
1185
 
1186
                }
1187
 
1188 25 alirezamon
        });
1189 43 alirezamon
        my $browse= get_directory_name_widget($object,undef,$entry,$attribute1,$attribute2,$status,$timeout);
1190
 
1191 25 alirezamon
        $widget->pack_start( $entry, FALSE, FALSE, 0);
1192
        $widget->pack_start( $browse, FALSE, FALSE, 0);
1193 43 alirezamon
 
1194
         if(defined $value){
1195
                unless (-d $value ){
1196
                        $warning= def_icon("icons/warning.png");
1197
                        $widget->pack_start( $warning, FALSE, FALSE, 0);
1198
                        set_tip($warning,"$value is not a valid directory path");
1199
                }
1200
        }
1201 25 alirezamon
        return $widget;
1202
}
1203
 
1204
 
1205
 
1206
 
1207
sub get_file_name_object {
1208
        my ($object,$attribute1,$attribute2,$extension,$open_in)=@_;
1209
        my $widget = def_hbox(FALSE,0);
1210
        my $value=$object->object_get_attribute($attribute1,$attribute2);
1211
        my $lable;
1212
        if(defined $value){
1213
                my ($name,$path,$suffix) = fileparse("$value",qr"\..[^.]*$");
1214
                $lable=gen_label_in_center($name.$suffix);
1215
 
1216
        } else {
1217 34 alirezamon
                        $lable=gen_label_in_center("Selecet a file");
1218 32 alirezamon
                        $lable->set_markup("<span  foreground= 'red' ><b>No file has been selected yet</b></span>");
1219 25 alirezamon
        }
1220
        my $entry=gen_entry();
1221
        my $browse= get_file_name($object,undef,$entry,$attribute1,$attribute2,$extension,$lable,$open_in);
1222
        $widget->pack_start( $lable, FALSE, FALSE, 0);
1223
        $widget->pack_start( $browse, FALSE, FALSE, 0);
1224
        return $widget;
1225
}
1226
 
1227 38 alirezamon
 
1228
 
1229
sub add_param_widget {
1230 43 alirezamon
         my ($self,$name,$param, $default,$type,$content,$info, $table,$row,$column,$show,$attribut1,$ref_delay,$new_status,$loc)=@_;
1231 38 alirezamon
         my $label;
1232
         $label =gen_label_in_left(" $name") if(defined $name);
1233
         my $widget;
1234 43 alirezamon
         my $value=$self->object_get_attribute($attribut1,$param);
1235 38 alirezamon
         if(! defined $value) {
1236 43 alirezamon
                        $self->object_add_attribute($attribut1,$param,$default);
1237
                        $self->object_add_attribute_order($attribut1,$param);
1238 38 alirezamon
                        $value=$default;
1239
         }
1240
         if(! defined $new_status){
1241
                $new_status='ref';
1242
         }
1243 43 alirezamon
         if (! defined $loc){
1244
                 $loc = "vertical";
1245
         }
1246 38 alirezamon
         if ($type eq "Entry"){
1247
                $widget=gen_entry($value);
1248
                $widget-> signal_connect("changed" => sub{
1249
                        my $new_param_value=$widget->get_text();
1250 43 alirezamon
                        $self->object_add_attribute($attribut1,$param,$new_param_value);
1251
                        set_gui_status($self,$new_status,$ref_delay) if(defined $ref_delay);
1252
                });
1253 38 alirezamon
         }
1254
         elsif ($type eq "Combo-box"){
1255
                 my @combo_list=split(",",$content);
1256
                 my $pos=get_pos($value, @combo_list) if(defined $value);
1257
                 if(!defined $pos){
1258 43 alirezamon
                        $self->object_add_attribute($attribut1,$param,$default);
1259 38 alirezamon
                        $pos=get_item_pos($default, @combo_list) if (defined $default);
1260
 
1261
                 }
1262
                #print " my $pos=get_item_pos($value, @combo_list);\n";
1263
                 $widget=gen_combo(\@combo_list, $pos);
1264
                 $widget-> signal_connect("changed" => sub{
1265
                 my $new_param_value=$widget->get_active_text();
1266 43 alirezamon
                 $self->object_add_attribute($attribut1,$param,$new_param_value);
1267
                 set_gui_status($self,$new_status,$ref_delay) if(defined $ref_delay);
1268 38 alirezamon
                 });
1269
 
1270
         }
1271
         elsif  ($type eq "Spin-button"){
1272
                  my ($min,$max,$step)=split(",",$content);
1273
                  $value=~ s/\D//g;
1274
                  $min=~ s/\D//g;
1275
                  $max=~ s/\D//g;
1276
                  $step=~ s/\D//g;
1277
                  $widget=gen_spin($min,$max,$step);
1278
                  $widget->set_value($value);
1279
                  $widget-> signal_connect("value_changed" => sub{
1280
                  my $new_param_value=$widget->get_value_as_int();
1281 43 alirezamon
                  $self->object_add_attribute($attribut1,$param,$new_param_value);
1282
                  set_gui_status($self,$new_status,$ref_delay) if(defined $ref_delay);
1283
              });
1284 38 alirezamon
 
1285
                 # $box=def_label_spin_help_box ($param,$info, $value,$min,$max,$step, 2);
1286
         }
1287
 
1288
        elsif ( $type eq "Check-box"){
1289
                $widget = def_hbox(FALSE,0);
1290
                my @check;
1291
                for (my $i=0;$i<$content;$i++){
1292
                        $check[$i]= Gtk2::CheckButton->new;
1293
                }
1294
                for (my $i=0;$i<$content;$i++){
1295
                        $widget->pack_end(  $check[$i], FALSE, FALSE, 0);
1296
 
1297
                        my @chars = split("",$value);
1298
                        #check if saved value match the size of check box
1299
                        if($chars[0] ne $content ) {
1300 43 alirezamon
                                $self->object_add_attribute($attribut1,$param,$default);
1301 38 alirezamon
                                $value=$default;
1302
                                @chars = split("",$value);
1303
                        }
1304
                        #set initial value
1305
 
1306
                        #print "\@chars=@chars\n";
1307
                        for (my $i=0;$i<$content;$i++){
1308
                                my $loc= (scalar @chars) -($i+1);
1309
                                        if( $chars[$loc] eq '1') {$check[$i]->set_active(TRUE);}
1310
                                        else {$check[$i]->set_active(FALSE);}
1311
                        }
1312
 
1313
 
1314
                        #get new value
1315
                        $check[$i]-> signal_connect("toggled" => sub{
1316
                                my $new_val="$content\'b";
1317
 
1318
                                for (my $i=$content-1; $i >= 0; $i--){
1319
                                        if($check[$i]->get_active()) {$new_val="${new_val}1" ;}
1320
                                        else {$new_val="${new_val}0" ;}
1321
                                }
1322 43 alirezamon
                                $self->object_add_attribute($attribut1,$param,$new_val);
1323 38 alirezamon
                                #print "\$new_val=$new_val\n";
1324 43 alirezamon
                                set_gui_status($self,$new_status,$ref_delay) if(defined $ref_delay);
1325 38 alirezamon
                        });
1326
                }
1327
 
1328
        }
1329
        elsif ( $type eq "DIR_path"){
1330 43 alirezamon
                        $widget =get_dir_in_object ($self,$attribut1,$param,$value,'ref',10,$default);
1331
                        set_gui_status($self,$new_status,$ref_delay) if(defined $ref_delay);
1332 38 alirezamon
        }
1333
        elsif ( $type eq "FILE_path"){ # use $content as extention
1334 43 alirezamon
                        $widget =get_file_name_object ($self,$attribut1,$param,$content,undef);
1335
                        set_gui_status($self,$new_status,$ref_delay) if(defined $ref_delay);
1336 38 alirezamon
        }
1337
 
1338
        else {
1339
                 $widget =gen_label_in_left("unsuported widget type!");
1340
        }
1341
 
1342
        my $inf_bt= (defined $info)? gen_button_message ($info,"icons/help.png"):gen_label_in_left(" ");
1343
        if($show==1){
1344
                attach_widget_to_table ($table,$row,$label,$inf_bt,$widget,$column);
1345
                if ($loc eq "vertical"){
1346
                        #print "$loc\n";
1347
                         $row ++;}
1348
                else {
1349
                        $column+=4;
1350
                }
1351
        }
1352
    return ($row,$column);
1353
}
1354
 
1355
 
1356
 
1357
 
1358 16 alirezamon
################
1359 25 alirezamon
# ADD info and label to widget
1360
################
1361
 
1362
 
1363
sub labele_widget_info{
1364
        my ($label_name,$widget,$info)=@_;
1365
        my $box = def_hbox(FALSE,0);
1366
        #label
1367
        if(defined $label_name){
1368
                my $label= gen_label_in_left($label_name);
1369
                $box->pack_start( $label, FALSE, FALSE, 3);
1370
        }
1371
        $box->pack_start( $widget, FALSE, FALSE, 3);
1372
        #info   
1373
        if(defined $info){
1374
                my $button=def_image_button("icons/help.png");
1375
                $button->signal_connect("clicked" => sub {message_dialog($info);});
1376
                $box->pack_start( $button, FALSE, FALSE, 3);
1377
        }
1378
        $box->show_all;
1379
        return $box;
1380
}
1381
 
1382
 
1383
 
1384
 
1385 16 alirezamon
 
1386
1

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.