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 32

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

powered by: WebSVN 2.1.0

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