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 43

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
        }
373
 
374
 
375
        my $button = Gtk2::Button->new();
376
        $button->add($box);
377
        $button->set_border_width(0);
378
        $button->show_all;
379
        return $button;
380
 
381
}
382
 
383
 
384
sub def_image_label{
385 43 alirezamon
        my ($image_file, $label_text,$mnemonic)=@_;
386 16 alirezamon
        # create box for image and label 
387
        my $box = def_hbox(FALSE,1);
388
        # now on to the image stuff
389 34 alirezamon
        my $image = def_icon($image_file);
390 16 alirezamon
        $box->pack_start($image, TRUE, FALSE, 0);
391
        # Create a label for the button
392
        if(defined $label_text ) {
393 43 alirezamon
                my $label;
394
                $label = Gtk2::Label->new("  $label_text") unless (defined $mnemonic);
395
                $label = Gtk2::Label->new_with_mnemonic (" $label_text") if (defined $mnemonic);
396 16 alirezamon
                $box->pack_start($label, TRUE, FALSE, 0);
397
        }
398
 
399
        return $box;
400
 
401
}
402
 
403
 
404
sub gen_button_message {
405
        my ($help, $image_file,$label_name)= @_;
406
        my $box = def_hbox(FALSE, 0);
407
        my $label= gen_label_in_center($label_name) if(defined $label_name);
408
        my $button=def_image_button($image_file);
409
 
410
        if(defined $help ){$button->signal_connect("clicked" => sub {message_dialog($help);});}
411
 
412
        $box->pack_start( $label, FALSE, FALSE, 0) if(defined $label_name);
413
        $box->pack_start( $button, FALSE, FALSE, 0);
414
        $box->set_border_width(0);
415
        $box->set_spacing (0);
416
        $box->show_all;
417
 
418
        return $box;
419
 
420
 
421
}
422
 
423
 
424
sub def_colored_button{
425
        my ($label_text,$color_num)=@_;
426
        # create box for image and label 
427
        my $box = def_hbox(FALSE,0);
428 25 alirezamon
        my $font_size=get_defualt_font_size();
429 16 alirezamon
 
430 43 alirezamon
        my ($red,$green,$blue) = get_color($color_num);
431
        my $button = ColorButton->new (red => $red, green => $green, blue => $blue, label=>"$label_text");
432
 
433 16 alirezamon
        $button->set_border_width(0);
434
        $button->show_all;
435
        return $button;
436
 
437
}
438
 
439
 
440 25 alirezamon
sub show_gif{
441
        my $gif = shift;
442
        my $vbox = Gtk2::HBox->new (TRUE, 8);
443
    my $filename;
444
      eval {
445
          $filename = main::demo_find_file ($gif);
446
      };
447 43 alirezamon
    my $image = Gtk2::Image->new_from_file ($gif);
448
    $vbox->set_border_width (4);
449
    my   $align = Gtk2::Alignment->new (0.5, 0.5, 0, 0);
450 25 alirezamon
        my $frame = Gtk2::Frame->new;
451
        $frame->set_shadow_type ('in');
452 43 alirezamon
    # Animation
453
    $frame->add ($image);
454
    $align->add ($frame);
455
        $vbox->pack_start ($align, FALSE, FALSE, 0);
456
        return $vbox;
457 25 alirezamon
}
458
 
459 16 alirezamon
############
460
#       message_dialog
461
############
462
 
463
sub message_dialog {
464 34 alirezamon
  my ($message,$type)=@_;
465
  $type = 'info' if (!defined $type);
466 16 alirezamon
  my $window;
467
  my $dialog = Gtk2::MessageDialog->new ($window,
468
                                   [qw/modal destroy-with-parent/],
469 34 alirezamon
                                   $type,
470 16 alirezamon
                                   'ok',
471 34 alirezamon
                                    $message);
472 16 alirezamon
  $dialog->run;
473
  $dialog->destroy;
474
 
475
}
476
 
477
 
478 38 alirezamon
 
479
sub set_tip{
480
        my ($widget,$tip)=@_;
481
        my $tooltips = Gtk2::Tooltips->new;
482
        $tooltips->set_tip($widget,$tip);
483
 
484
 
485
}
486
 
487
 
488 16 alirezamon
############
489
# window
490
###########
491
 
492
sub def_win {
493
        my @titel=shift;
494
        my $window = Gtk2::Window->new('toplevel');
495
        $window->set_title(@titel);
496
        $window->set_position("center");
497
        $window->set_default_size(100, 100);
498
        $window->set_border_width(20);
499
        $window->signal_connect (delete_event => sub { Gtk2->main_quit });
500
        return $window;
501
 
502
}
503
 
504
 
505
sub def_win_size {
506
        my $x=shift;
507
        my $y=shift;
508
        my @titel=shift;
509
        my $window = Gtk2::Window->new('toplevel');
510
        $window->set_title(@titel);
511
        $window->set_position("center");
512
        $window->set_default_size($x, $y);
513
        $window->set_border_width(20);
514
        $window->signal_connect (delete_event => sub { Gtk2->main_quit });
515
        return $window;
516
 
517
}
518
 
519
 
520
sub def_popwin_size {
521 34 alirezamon
        my ($x,$y,$titel,$unit)=@_;
522
        if(defined $unit){
523
                my($width,$hight)=max_win_size();
524
                if($unit eq 'percent'){
525
                        $x= ($x * $width)/100;
526
                        $y= ($y * $hight)/100;
527
                } # else its pixels
528
 
529
        }
530 16 alirezamon
        #my $window = Gtk2::Window->new('popup');
531
        my $window = Gtk2::Window->new('toplevel');
532 34 alirezamon
        $window->set_title($titel);
533 16 alirezamon
        $window->set_position("center");
534
        $window->set_default_size($x, $y);
535
        $window->set_border_width(20);
536
        $window->signal_connect (delete_event => sub { $window->destroy });
537
        return $window;
538
 
539
}
540
 
541
 
542 25 alirezamon
 
543
 
544
 
545 16 alirezamon
sub def_scrolled_window_box{
546
 
547
        my $window =  def_popwin_size(@_);
548
        my $box=def_vbox(TRUE,5);
549
        my $scrolled_window = new Gtk2::ScrolledWindow (undef, undef);
550
        $scrolled_window->set_policy( "automatic", "automatic" );
551
        $scrolled_window->add_with_viewport($box);
552
        $window->add($scrolled_window);
553
        $window->show_all;
554
        $box->show_all;
555
        return ($box,$window);
556
 
557
}
558
 
559
sub max_win_size{
560
        my $screen =Gtk2::Gdk::Screen->get_default();
561
        my $hight = $screen->get_height();
562
        my $width = $screen->get_width();
563
        return ($width,$hight);
564
}
565
 
566
 
567 25 alirezamon
sub get_defualt_font_size{
568 16 alirezamon
        my($width,$hight)=max_win_size();
569
        #print "($width,$hight)\n";
570
        my $font_size=($width>=1600)? 10:
571
                              ($width>=1400)? 9:
572 34 alirezamon
                                  ($width>=1200)? 9:
573 16 alirezamon
                                  ($width>=1000)? 7:6;
574 25 alirezamon
        #print "$font_size\n";  
575 16 alirezamon
        return $font_size;
576
}
577
 
578
 
579 25 alirezamon
sub set_defualt_font_size{
580
        my $font_size=get_defualt_font_size();
581
 
582 16 alirezamon
                Gtk2::Rc->parse_string(<<__);
583
                        style "normal" {
584 25 alirezamon
                                font_name ="Verdana $font_size"
585 16 alirezamon
                        }
586
                        widget "*" style "normal"
587
__
588
 
589
}
590
 
591 38 alirezamon
sub gen_scr_win_with_adjst {
592
        my ($self,$name)=@_;
593
        my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
594
        $scrolled_win->set_policy( "automatic", "automatic" );
595
        $scrolled_win->signal_connect("destroy"=> sub{
596
                save_scrolled_win_adj($self,$scrolled_win, $name);
597
 
598
         });
599
         my $adjast=0;
600
         $scrolled_win->signal_connect("size-allocate"=> sub{
601
                if($adjast==0){
602
                        load_scrolled_win_adj($self,$scrolled_win, $name);
603
                        $adjast=1;
604
                }
605
 
606
         });
607
        return $scrolled_win;
608
}
609 16 alirezamon
 
610 38 alirezamon
 
611
sub save_scrolled_win_adj {
612
        my ($self,$scrolled_win,$name)=@_;
613
        my $ha= $scrolled_win->get_hadjustment();
614
    my $va =$scrolled_win->get_vadjustment();
615
    return if(!defined $ha);
616
    return if(!defined $va);
617
    save_adj ($self,$ha,$name,"ha");
618
        save_adj ($self,$va,$name,"va");
619
}
620
 
621
 
622
sub load_scrolled_win_adj {
623
        my ($self,$scrolled_win,$name)=@_;
624
        my $ha= $scrolled_win->get_hadjustment();
625
    my $va =$scrolled_win->get_vadjustment();
626
        my $h=load_adj ($self,$ha,$name,"ha");
627
        my $v=load_adj ($self,$va,$name,"va");
628
        #$ha->set_value($h) if(defined $h);
629
    #$va->set_value($v) if(defined $v);    
630
}
631
 
632
 
633
 
634
 
635
sub save_adj {
636
        my ($self,$adjustment,$at1,$at2)=@_;
637
        my $value = $adjustment->value;
638
        $self->object_add_attribute($at1,$at2,$value);
639
}
640
 
641
 
642
sub load_adj {
643
        my ($self,$adjustment,$at1,$at2)=@_;
644
        return if(!defined $at1);
645
    my $value=  $self->object_get_attribute($at1,$at2);
646
    return if(!defined $value);
647
    my $lower =  $adjustment->lower;
648
    my $upper = $adjustment->upper - $adjustment->page_size;
649
    $value=  ($value < $lower || $value > $upper ) ? 0 : $value;
650
 
651
    $adjustment->set_value($value);
652
}
653
 
654
 
655 16 alirezamon
##############
656
#       box
657
#############
658
 
659
sub def_hbox {
660
        my( $homogeneous, $spacing)=@_;
661
        my $box = Gtk2::HBox->new($homogeneous, $spacing);
662
        $box->set_border_width(2);
663
        return $box;
664
}
665
 
666
sub def_vbox {
667
        my $box = Gtk2::VBox->new(FALSE, 0);
668
        $box->set_border_width(2);
669
        return $box;
670
}
671
 
672
sub def_pack_hbox{
673
        my( $homogeneous, $spacing , @box_list)=@_;
674
        my $box=def_hbox($homogeneous, $spacing);
675
        foreach my $subbox (@box_list){
676
                $box->pack_start( $subbox, FALSE, FALSE, 3);
677
        }
678
        return $box;
679
 
680
 
681
}
682
 
683 34 alirezamon
sub def_pack_vbox{
684
        my( $homogeneous, $spacing , @box_list)=@_;
685
        my $box=def_vbox($homogeneous, $spacing);
686
        foreach my $subbox (@box_list){
687
                $box->pack_start( $subbox, FALSE, FALSE, 3);
688
        }
689
        return $box;
690 16 alirezamon
 
691 34 alirezamon
}
692 16 alirezamon
 
693 34 alirezamon
 
694
##########
695
# Paned
696
#########
697
 
698
 
699
sub gen_vpaned {
700
        my ($w1,$loc,$w2) = @_;
701
        my $vpaned = Gtk2::VPaned -> new;
702
        my($width,$hight)=max_win_size();
703
 
704
 
705
        $vpaned -> pack1($w1, TRUE, TRUE);
706
        $vpaned -> set_position ($hight*$loc);
707
        $vpaned -> pack2($w2, TRUE, TRUE);
708
 
709
        return $vpaned;
710
}
711
 
712
 
713
sub gen_hpaned {
714
        my ($w1,$loc,$w2) = @_;
715
        my $hpaned = Gtk2::HPaned -> new;
716
        my($width,$hight)=max_win_size();
717
 
718
 
719
        $hpaned -> pack1($w1, TRUE, TRUE);
720
        $hpaned -> set_position ($width*$loc);
721
        $hpaned -> pack2($w2, TRUE, TRUE);
722
 
723
        return $hpaned;
724
}
725
 
726 16 alirezamon
#############
727
# text_view 
728
############
729
 
730
sub create_text {
731
  my $scrolled_window = Gtk2::ScrolledWindow->new;
732
  $scrolled_window->set_policy ('automatic', 'automatic');
733
  $scrolled_window->set_shadow_type ('in');
734
  my $tview = Gtk2::TextView->new();
735
  $scrolled_window->add ($tview);
736
  $tview->show_all;
737
  # Make it a bit nicer for text.
738
  $tview->set_wrap_mode ('word');
739
  $tview->set_pixels_above_lines (2);
740
  $tview->set_pixels_below_lines (2);
741 38 alirezamon
 # $scrolled_window->set_placement('bottom_left' );
742 43 alirezamon
 add_colors_to_textview($tview);
743 16 alirezamon
  return ($scrolled_window,$tview);
744
}
745
 
746
 
747
#################
748
#       table
749
################
750
 
751
sub def_table{
752
        my ($row,$col,$homogeneous)=@_;
753
        my $table = Gtk2::Table->new ($row, $col, $homogeneous);
754
        $table->set_row_spacings (0);
755
        $table->set_col_spacings (0);
756
        return $table;
757
 
758
}
759
 
760 38 alirezamon
sub attach_widget_to_table {
761
        my ($table,$row,$label,$inf_bt,$widget,$column)=@_;
762
        $column = 0 if(!defined $column);
763
        $column *=4;
764
        #my $tmp=gen_label_in_left(" "); 
765
        if(defined $label)  {$table->attach  ($label , $column, $column+1,  $row,$row+1,'fill','shrink',2,2);$column++;}
766
        if(defined $inf_bt) {$table->attach  ($inf_bt , $column, $column+1, $row,$row+1,'fill','shrink',2,2);$column++;}
767
        if(defined $widget) {$table->attach  ($widget , $column, $column+1, $row,$row+1,'fill','shrink',2,2);$column++;}
768
        #$table->attach  ($tmp , $column+3, $column+4, $row,$row+1,'fill','shrink',2,2);
769
}
770 16 alirezamon
 
771
 
772
 
773
##################
774
#       show_info
775
##################
776
sub show_info{
777
        my ($textview_ref,$info)=@_;
778
        my $buffer = $$textview_ref->get_buffer();
779
        $buffer->set_text($info);
780
}
781
 
782 25 alirezamon
sub add_info{
783
        my ($textview_ref,$info)=@_;
784
        my $buffer = $$textview_ref->get_buffer();
785
        my $textiter = $buffer->get_end_iter();
786
        #Insert some text into the buffer
787
        $buffer->insert($textiter,$info);
788
 
789
}
790 16 alirezamon
 
791 38 alirezamon
 
792
sub new_on_textview{
793
        my ($textview,$info)=@_;
794
        my $buffer = $textview->get_buffer();
795
        $buffer->set_text($info);
796
}
797
 
798
sub append_to_textview{
799
        my ($textview,$info)=@_;
800
        my $buffer = $textview->get_buffer();
801
        my $textiter = $buffer->get_end_iter();
802
        #Insert some text into the buffer
803
        $buffer->insert($textiter,$info);
804
 
805
 
806
}
807
 
808
 
809 34 alirezamon
sub show_colored_info{
810
        my ($textview_ref,$info,$color)=@_;
811
        my $buffer = $$textview_ref->get_buffer();
812
        #$buffer->set_text($info);
813
        my $textiter = $buffer->get_start_iter();
814
        $buffer->insert_with_tags_by_name ($textiter, "$info", "${color}_tag");
815
}
816 16 alirezamon
 
817 34 alirezamon
sub add_colored_info{
818
        my ($textview_ref,$info,$color)=@_;
819
        my $buffer = $$textview_ref->get_buffer();
820
        my $textiter = $buffer->get_end_iter();
821
        #Insert some text into the buffer
822
        #$buffer->insert($textiter,$info);
823
        $buffer->insert_with_tags_by_name ($textiter, "$info", "${color}_tag");
824
 
825
}
826 25 alirezamon
 
827 38 alirezamon
sub add_colors_to_textview{
828
        my $tview= shift;
829
        add_colored_tag($tview,'red');
830
        add_colored_tag($tview,'blue');
831
        add_colored_tag($tview,'green');
832
}
833
 
834
 
835 34 alirezamon
sub add_colored_tag{
836
        my ($textview_ref,$color)=@_;
837
        my $buffer = $textview_ref->get_buffer();
838
        $buffer->create_tag ("${color}_tag", foreground => $color);
839
}
840
 
841 25 alirezamon
sub add_color_to_gd{
842
        foreach (my $i=0;$i<32;$i++ ) {
843 34 alirezamon
                my ($red,$green,$blue)=get_color($i);
844
                add_colour("my_color$i"=>[$red>>8,$green>>8,$blue>>8]);
845 25 alirezamon
 
846 34 alirezamon
        }
847
}
848
 
849
 
850
 
851 25 alirezamon
############
852
#       get file folder list
853
###########
854
 
855 43 alirezamon
sub get_directory_name_widget {
856 25 alirezamon
        my ($object,$title,$entry,$attribute1,$attribute2,$status,$timeout)= @_;
857
        my $browse= def_image_button("icons/browse.png");
858
 
859
        $browse->signal_connect("clicked"=> sub{
860
                my $entry_ref=$_[1];
861
                my $file;
862
                $title ='select directory' if(!defined $title);
863
                my $dialog = Gtk2::FileChooserDialog->new(
864
                        $title, undef,
865
                        #               'open',
866
                        'select-folder',
867
                        'gtk-cancel' => 'cancel',
868
                        'gtk-ok'     => 'ok',
869
                        );
870
 
871
 
872
                        if ( "ok" eq $dialog->run ) {
873
                        $file = $dialog->get_filename;
874
                                $$entry_ref->set_text($file);
875
                                $object->object_add_attribute($attribute1,$attribute2,$file);
876
                                set_gui_status($object,$status,$timeout) if(defined $status);
877
                                #check_input_file($file,$socgen,$soc_state,$info);
878
                                #print "file = $file\n";
879
                         }
880
                        $dialog->destroy;
881
 
882
 
883
 
884
                } , \$entry);
885
 
886
        return $browse;
887
 
888
}
889
 
890 43 alirezamon
 
891
sub get_dir_name {
892
        my ($object,$title,$attribute1,$attribute2,$open_in,$status,$timeout)= @_;
893
        my $dir;
894
        $title ='select directory' if(!defined $title);
895
        my $dialog = Gtk2::FileChooserDialog->new(
896
                $title, undef,
897
                #               'open',
898
                'select-folder',
899
                'gtk-cancel' => 'cancel',
900
                'gtk-ok'     => 'ok',
901
        );
902
        if(defined  $open_in){
903
                $dialog->set_current_folder ($open_in);
904
        }
905
 
906
        if ( "ok" eq $dialog->run ) {
907
                        $dir = $dialog->get_filename;
908
                                $object->object_add_attribute($attribute1,$attribute2,$dir);
909
                                set_gui_status($object,$status,$timeout) if(defined $status);
910
                                $dialog->destroy;
911
        }
912 41 alirezamon
}
913
 
914
 
915 25 alirezamon
 
916
sub get_file_name {
917
        my ($object,$title,$entry,$attribute1,$attribute2,$extension,$lable,$open_in)= @_;
918
        my $browse= def_image_button("icons/browse.png");
919 38 alirezamon
 
920 25 alirezamon
        $browse->signal_connect("clicked"=> sub{
921
                my $entry_ref=$_[1];
922
                my $file;
923
                $title ='select directory' if(!defined $title);
924
                my $dialog = Gtk2::FileChooserDialog->new(
925
                'Select a File', undef,
926
                'open',
927
                'gtk-cancel' => 'cancel',
928
                'gtk-ok'     => 'ok',
929
                );
930
         if(defined $extension){
931
                my $filter = Gtk2::FileFilter->new();
932
                $filter->set_name($extension);
933
                $filter->add_pattern("*.$extension");
934
                $dialog->add_filter ($filter);
935
         }
936
          if(defined  $open_in){
937
                $dialog->set_current_folder ($open_in);
938
                # print "$open_in\n";
939
 
940
        }
941
 
942
                        if ( "ok" eq $dialog->run ) {
943 38 alirezamon
                        $file = $dialog->get_filename;
944 34 alirezamon
                                #remove $project_dir form beginig of each file
945 38 alirezamon
                $file =remove_project_dir_from_addr($file);
946 25 alirezamon
                                $$entry_ref->set_text($file);
947 34 alirezamon
                                $object->object_add_attribute($attribute1,$attribute2,$file) if(defined $object);
948 25 alirezamon
                                my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
949 34 alirezamon
                                if(defined $lable){
950
                                        $lable->set_markup("<span  foreground= 'black' ><b>$name$suffix</b></span>");
951
                                        $lable->show;
952
                                }
953 25 alirezamon
 
954
                                #check_input_file($file,$socgen,$soc_state,$info);
955
                                #print "file = $file\n";
956
                         }
957
                        $dialog->destroy;
958
 
959
 
960
 
961
                } , \$entry);
962
 
963
        return $browse;
964
 
965
}
966
 
967
 
968
#################
969
#       widget update object
970
#################
971
 
972
sub gen_entry_object {
973
        my ($object,$attribute1,$attribute2,$default,$status,$timeout)=@_;
974
        my $old=$object->object_get_attribute($attribute1,$attribute2);
975
        my $widget;
976
        if(defined $old ){
977
                $widget=gen_entry($old);
978
        }
979
        else
980
        {
981
                $widget=gen_entry($default);
982
                $object->object_add_attribute($attribute1,$attribute2,$default);
983
        }
984
        $widget-> signal_connect("changed" => sub{
985
                my $new_param_value=$widget->get_text();
986
                $object->object_add_attribute($attribute1,$attribute2,$new_param_value);
987
                set_gui_status($object,$status,$timeout) if (defined $status);
988
        });
989
        return $widget;
990
}
991
 
992
 
993
sub gen_combobox_object {
994
        my ($object,$attribute1,$attribute2,$content,$default,$status,$timeout)=@_;
995
        my @combo_list=split(",",$content);
996
        my $value=$object->object_get_attribute($attribute1,$attribute2);
997
        my $pos;
998
        $pos=get_pos($value, @combo_list) if (defined $value);
999
        if(!defined $pos && defined $default){
1000
                $object->object_add_attribute($attribute1,$attribute2,$default);
1001
                $pos=get_item_pos($default, @combo_list);
1002
        }
1003
        #print " my $pos=get_item_pos($value, @combo_list);\n";
1004
        my $widget=gen_combo(\@combo_list, $pos);
1005
        $widget-> signal_connect("changed" => sub{
1006
                my $new_param_value=$widget->get_active_text();
1007
                $object->object_add_attribute($attribute1,$attribute2,$new_param_value);
1008
                set_gui_status($object,$status,$timeout) if (defined $status);
1009
         });
1010
        return $widget;
1011
 
1012
 
1013
}
1014
 
1015
 
1016
sub gen_comboentry_object {
1017
        my ($object,$attribute1,$attribute2,$content,$default,$status,$timeout)=@_;
1018
        my @combo_list=split(",",$content);
1019
        my $value=$object->object_get_attribute($attribute1,$attribute2);
1020
        my $pos;
1021
        $pos=get_pos($value, @combo_list) if (defined $value);
1022
        if(!defined $pos && defined $default){
1023
                $object->object_add_attribute($attribute1,$attribute2,$default);
1024
                $pos=get_item_pos($default, @combo_list);
1025
        }
1026
        #print " my $pos=get_item_pos($value, @combo_list);\n";
1027
        my $widget=gen_combo_entry(\@combo_list, $pos);
1028
        ($widget->child)->signal_connect('changed' => sub {
1029
                my ($entry) = @_;
1030
                my $new_param_value=$entry->get_text();
1031
                $object->object_add_attribute($attribute1,$attribute2,$new_param_value);
1032
                set_gui_status($object,$status,$timeout) if (defined $status);
1033
         });
1034
        return $widget;
1035
 
1036
}
1037
 
1038
 
1039
 
1040
sub gen_spin_object {
1041
        my ($object,$attribute1,$attribute2,$content, $default,$status,$timeout)=@_;
1042
        my $value=$object->object_get_attribute($attribute1,$attribute2);
1043
        my ($min,$max,$step)=split(",",$content);
1044
        if(!defined $value){
1045
                $value=$default;
1046
                $object->object_add_attribute($attribute1,$attribute2,$value);
1047
        }
1048 38 alirezamon
 
1049
        $value=~ s/[^0-9.]//g;
1050
        $min=~   s/[^0-9.]//g;
1051
        $max=~   s/[^0-9.]//g;
1052
        $step=~  s/[^0-9.]//g;
1053
 
1054
 
1055 25 alirezamon
        my $widget=gen_spin($min,$max,$step);
1056
        $widget->set_value($value);
1057
        $widget-> signal_connect("value_changed" => sub{
1058 38 alirezamon
                my $new_param_value=$widget->get_value();
1059 25 alirezamon
                $object->object_add_attribute($attribute1,$attribute2,$new_param_value);
1060
                set_gui_status($object,$status,$timeout) if (defined $status);
1061
        });
1062
        return $widget;
1063
}
1064
 
1065
 
1066 34 alirezamon
sub gen_check_box_object_array {
1067
                my ($object,$attribute1,$attribute2,$content,$default,$status,$timeout)=@_;
1068
                my $value=$object->object_get_attribute($attribute1,$attribute2);
1069
                $value = $default if (!defined $value);
1070 25 alirezamon
                my $widget = def_hbox(FALSE,0);
1071
                my @check;
1072
                for (my $i=0;$i<$content;$i++){
1073
                        $check[$i]= Gtk2::CheckButton->new;
1074
                }
1075
                for (my $i=0;$i<$content;$i++){
1076
                        $widget->pack_end(  $check[$i], FALSE, FALSE, 0);
1077
 
1078
                        my @chars = split("",$value);
1079
                        #check if saved value match the size of check box
1080
                        if($chars[0] ne $content ) {
1081
                                $object->object_add_attribute($attribute1,$attribute2,$default);
1082
                                $value=$default;
1083
                                @chars = split("",$value);
1084
                        }
1085
                        #set initial value
1086
 
1087
                        #print "\@chars=@chars\n";
1088
                        for (my $i=0;$i<$content;$i++){
1089
                                my $loc= (scalar @chars) -($i+1);
1090
                                        if( $chars[$loc] eq '1') {$check[$i]->set_active(TRUE);}
1091
                                        else {$check[$i]->set_active(FALSE);}
1092
                        }
1093
 
1094
 
1095
                        #get new value
1096
                        $check[$i]-> signal_connect("toggled" => sub{
1097
                                my $new_val="$content\'b";
1098
 
1099
                                for (my $i=$content-1; $i >= 0; $i--){
1100
                                        if($check[$i]->get_active()) {$new_val="${new_val}1" ;}
1101
                                        else {$new_val="${new_val}0" ;}
1102
                                }
1103
                                $object->object_add_attribute($attribute1,$attribute2,$new_val);
1104
                                #print "\$new_val=$new_val\n";
1105
                                set_gui_status($object,$status,$timeout) if (defined $status);
1106
                        });
1107
        }
1108
        return $widget;
1109
 
1110
}
1111
 
1112
 
1113
 
1114 34 alirezamon
 
1115
 
1116
sub gen_check_box_object {
1117
                my ($object,$attribute1,$attribute2,$default,$status,$timeout)=@_;
1118
                my $value=$object->object_get_attribute($attribute1,$attribute2);
1119
                if (!defined $value){
1120
                        #set initial value
1121
                        $object->object_add_attribute($attribute1,$attribute2,$default);
1122
                        $value = $default
1123
                }
1124
                my $widget = Gtk2::CheckButton->new;
1125
                if($value == 1) {$widget->set_active(TRUE);}
1126
                else {$widget->set_active(FALSE);}
1127
 
1128
                #get new value
1129
                $widget-> signal_connect("toggled" => sub{
1130
                        my $new_val;
1131
                        if($widget->get_active()) {$new_val=1;}
1132
                        else {$new_val=0;}
1133
                        $object->object_add_attribute($attribute1,$attribute2,$new_val);
1134
                        #print "\$new_val=$new_val\n";
1135
                        set_gui_status($object,$status,$timeout) if (defined $status);
1136
                });
1137
 
1138
        return $widget;
1139
 
1140
}
1141
 
1142
 
1143
 
1144
 
1145
 
1146
 
1147 25 alirezamon
sub get_dir_in_object {
1148 38 alirezamon
        my ($object,$attribute1,$attribute2,$content,$status,$timeout,$default)=@_;
1149 25 alirezamon
        my $widget = def_hbox(FALSE,0);
1150
        my $value=$object->object_get_attribute($attribute1,$attribute2);
1151 38 alirezamon
        $object->object_add_attribute($attribute1,$attribute2,  $default) if (!defined $value );
1152
        $value = $default if (!defined $value );
1153 43 alirezamon
        if (defined $default){
1154
                $object->object_add_attribute($attribute1,$attribute2,  $default) if  !(-d $value );
1155
                $value = $default  if !(-d $value );
1156
        };
1157
 
1158
        my $warning;
1159
 
1160 25 alirezamon
        my $entry=gen_entry($value);
1161
        $entry-> signal_connect("changed" => sub{
1162
                my $new_param_value=$entry->get_text();
1163
                $object->object_add_attribute($attribute1,$attribute2,$new_param_value);
1164
                set_gui_status($object,$status,$timeout) if (defined $status);
1165 43 alirezamon
                unless (-d $new_param_value ){
1166
                        if (!defined $warning){
1167
                                $warning = def_icon("icons/warning.png");
1168
                                $widget->pack_start( $warning, FALSE, FALSE, 0);
1169
                                set_tip($warning,"$new_param_value is not a valid directory");
1170
                                $widget->show_all;
1171
                        }
1172
 
1173
                }else{
1174
                        $warning->destroy if (defined $warning);
1175
                        undef $warning;
1176
 
1177
                }
1178
 
1179 25 alirezamon
        });
1180 43 alirezamon
        my $browse= get_directory_name_widget($object,undef,$entry,$attribute1,$attribute2,$status,$timeout);
1181
 
1182 25 alirezamon
        $widget->pack_start( $entry, FALSE, FALSE, 0);
1183
        $widget->pack_start( $browse, FALSE, FALSE, 0);
1184 43 alirezamon
 
1185
         if(defined $value){
1186
                unless (-d $value ){
1187
                        $warning= def_icon("icons/warning.png");
1188
                        $widget->pack_start( $warning, FALSE, FALSE, 0);
1189
                        set_tip($warning,"$value is not a valid directory path");
1190
                }
1191
        }
1192 25 alirezamon
        return $widget;
1193
}
1194
 
1195
 
1196
 
1197
 
1198
sub get_file_name_object {
1199
        my ($object,$attribute1,$attribute2,$extension,$open_in)=@_;
1200
        my $widget = def_hbox(FALSE,0);
1201
        my $value=$object->object_get_attribute($attribute1,$attribute2);
1202
        my $lable;
1203
        if(defined $value){
1204
                my ($name,$path,$suffix) = fileparse("$value",qr"\..[^.]*$");
1205
                $lable=gen_label_in_center($name.$suffix);
1206
 
1207
        } else {
1208 34 alirezamon
                        $lable=gen_label_in_center("Selecet a file");
1209 32 alirezamon
                        $lable->set_markup("<span  foreground= 'red' ><b>No file has been selected yet</b></span>");
1210 25 alirezamon
        }
1211
        my $entry=gen_entry();
1212
        my $browse= get_file_name($object,undef,$entry,$attribute1,$attribute2,$extension,$lable,$open_in);
1213
        $widget->pack_start( $lable, FALSE, FALSE, 0);
1214
        $widget->pack_start( $browse, FALSE, FALSE, 0);
1215
        return $widget;
1216
}
1217
 
1218 38 alirezamon
 
1219
 
1220
sub add_param_widget {
1221 43 alirezamon
         my ($self,$name,$param, $default,$type,$content,$info, $table,$row,$column,$show,$attribut1,$ref_delay,$new_status,$loc)=@_;
1222 38 alirezamon
         my $label;
1223
         $label =gen_label_in_left(" $name") if(defined $name);
1224
         my $widget;
1225 43 alirezamon
         my $value=$self->object_get_attribute($attribut1,$param);
1226 38 alirezamon
         if(! defined $value) {
1227 43 alirezamon
                        $self->object_add_attribute($attribut1,$param,$default);
1228
                        $self->object_add_attribute_order($attribut1,$param);
1229 38 alirezamon
                        $value=$default;
1230
         }
1231
         if(! defined $new_status){
1232
                $new_status='ref';
1233
         }
1234 43 alirezamon
         if (! defined $loc){
1235
                 $loc = "vertical";
1236
         }
1237 38 alirezamon
         if ($type eq "Entry"){
1238
                $widget=gen_entry($value);
1239
                $widget-> signal_connect("changed" => sub{
1240
                        my $new_param_value=$widget->get_text();
1241 43 alirezamon
                        $self->object_add_attribute($attribut1,$param,$new_param_value);
1242
                        set_gui_status($self,$new_status,$ref_delay) if(defined $ref_delay);
1243
                });
1244 38 alirezamon
         }
1245
         elsif ($type eq "Combo-box"){
1246
                 my @combo_list=split(",",$content);
1247
                 my $pos=get_pos($value, @combo_list) if(defined $value);
1248
                 if(!defined $pos){
1249 43 alirezamon
                        $self->object_add_attribute($attribut1,$param,$default);
1250 38 alirezamon
                        $pos=get_item_pos($default, @combo_list) if (defined $default);
1251
 
1252
                 }
1253
                #print " my $pos=get_item_pos($value, @combo_list);\n";
1254
                 $widget=gen_combo(\@combo_list, $pos);
1255
                 $widget-> signal_connect("changed" => sub{
1256
                 my $new_param_value=$widget->get_active_text();
1257 43 alirezamon
                 $self->object_add_attribute($attribut1,$param,$new_param_value);
1258
                 set_gui_status($self,$new_status,$ref_delay) if(defined $ref_delay);
1259 38 alirezamon
                 });
1260
 
1261
         }
1262
         elsif  ($type eq "Spin-button"){
1263
                  my ($min,$max,$step)=split(",",$content);
1264
                  $value=~ s/\D//g;
1265
                  $min=~ s/\D//g;
1266
                  $max=~ s/\D//g;
1267
                  $step=~ s/\D//g;
1268
                  $widget=gen_spin($min,$max,$step);
1269
                  $widget->set_value($value);
1270
                  $widget-> signal_connect("value_changed" => sub{
1271
                  my $new_param_value=$widget->get_value_as_int();
1272 43 alirezamon
                  $self->object_add_attribute($attribut1,$param,$new_param_value);
1273
                  set_gui_status($self,$new_status,$ref_delay) if(defined $ref_delay);
1274
              });
1275 38 alirezamon
 
1276
                 # $box=def_label_spin_help_box ($param,$info, $value,$min,$max,$step, 2);
1277
         }
1278
 
1279
        elsif ( $type eq "Check-box"){
1280
                $widget = def_hbox(FALSE,0);
1281
                my @check;
1282
                for (my $i=0;$i<$content;$i++){
1283
                        $check[$i]= Gtk2::CheckButton->new;
1284
                }
1285
                for (my $i=0;$i<$content;$i++){
1286
                        $widget->pack_end(  $check[$i], FALSE, FALSE, 0);
1287
 
1288
                        my @chars = split("",$value);
1289
                        #check if saved value match the size of check box
1290
                        if($chars[0] ne $content ) {
1291 43 alirezamon
                                $self->object_add_attribute($attribut1,$param,$default);
1292 38 alirezamon
                                $value=$default;
1293
                                @chars = split("",$value);
1294
                        }
1295
                        #set initial value
1296
 
1297
                        #print "\@chars=@chars\n";
1298
                        for (my $i=0;$i<$content;$i++){
1299
                                my $loc= (scalar @chars) -($i+1);
1300
                                        if( $chars[$loc] eq '1') {$check[$i]->set_active(TRUE);}
1301
                                        else {$check[$i]->set_active(FALSE);}
1302
                        }
1303
 
1304
 
1305
                        #get new value
1306
                        $check[$i]-> signal_connect("toggled" => sub{
1307
                                my $new_val="$content\'b";
1308
 
1309
                                for (my $i=$content-1; $i >= 0; $i--){
1310
                                        if($check[$i]->get_active()) {$new_val="${new_val}1" ;}
1311
                                        else {$new_val="${new_val}0" ;}
1312
                                }
1313 43 alirezamon
                                $self->object_add_attribute($attribut1,$param,$new_val);
1314 38 alirezamon
                                #print "\$new_val=$new_val\n";
1315 43 alirezamon
                                set_gui_status($self,$new_status,$ref_delay) if(defined $ref_delay);
1316 38 alirezamon
                        });
1317
                }
1318
 
1319
        }
1320
        elsif ( $type eq "DIR_path"){
1321 43 alirezamon
                        $widget =get_dir_in_object ($self,$attribut1,$param,$value,'ref',10,$default);
1322
                        set_gui_status($self,$new_status,$ref_delay) if(defined $ref_delay);
1323 38 alirezamon
        }
1324
        elsif ( $type eq "FILE_path"){ # use $content as extention
1325 43 alirezamon
                        $widget =get_file_name_object ($self,$attribut1,$param,$content,undef);
1326
                        set_gui_status($self,$new_status,$ref_delay) if(defined $ref_delay);
1327 38 alirezamon
        }
1328
 
1329
        else {
1330
                 $widget =gen_label_in_left("unsuported widget type!");
1331
        }
1332
 
1333
        my $inf_bt= (defined $info)? gen_button_message ($info,"icons/help.png"):gen_label_in_left(" ");
1334
        if($show==1){
1335
                attach_widget_to_table ($table,$row,$label,$inf_bt,$widget,$column);
1336
                if ($loc eq "vertical"){
1337
                        #print "$loc\n";
1338
                         $row ++;}
1339
                else {
1340
                        $column+=4;
1341
                }
1342
        }
1343
    return ($row,$column);
1344
}
1345
 
1346
 
1347
 
1348
 
1349 16 alirezamon
################
1350 25 alirezamon
# ADD info and label to widget
1351
################
1352
 
1353
 
1354
sub labele_widget_info{
1355
        my ($label_name,$widget,$info)=@_;
1356
        my $box = def_hbox(FALSE,0);
1357
        #label
1358
        if(defined $label_name){
1359
                my $label= gen_label_in_left($label_name);
1360
                $box->pack_start( $label, FALSE, FALSE, 3);
1361
        }
1362
        $box->pack_start( $widget, FALSE, FALSE, 3);
1363
        #info   
1364
        if(defined $info){
1365
                my $button=def_image_button("icons/help.png");
1366
                $button->signal_connect("clicked" => sub {message_dialog($info);});
1367
                $box->pack_start( $button, FALSE, FALSE, 3);
1368
        }
1369
        $box->show_all;
1370
        return $box;
1371
}
1372
 
1373
 
1374
 
1375
 
1376 16 alirezamon
 
1377
1

powered by: WebSVN 2.1.0

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