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] - Diff between revs 24 and 25

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 24 Rev 25
Line 1... Line 1...
use Glib qw/TRUE FALSE/;
use Glib qw/TRUE FALSE/;
#use Gtk2 '-init';
#use Gtk2 '-init';
use strict;
use strict;
use warnings;
use warnings;
 
 
use Gtk2::Pango;
 
 
 
 
 
 
use Gtk2::Pango;
 
#use Tk::Animation;
 
 
##############
##############
# combo box
# combo box
#############
#############
sub gen_combo{
sub gen_combo{
        my ($combo_list, $combo_active_pos)= @_;
        my ($combo_list, $combo_active_pos)= @_;
        my $combo = Gtk2::ComboBox->new_text;
        my $combo = Gtk2::ComboBox->new_text;
 
 
        combo_set_names($combo,$combo_list);
        combo_set_names($combo,$combo_list);
        $combo->set_active($combo_active_pos);
        $combo->set_active($combo_active_pos) if(defined $combo_active_pos);
 
 
        #my $font = Gtk2::Pango::FontDescription->from_string('Tahoma 5');
        #my $font = Gtk2::Pango::FontDescription->from_string('Tahoma 5');
        #$combo->modify_font($font);
        #$combo->modify_font($font);
 
 
 
 
Line 151... Line 153...
##############
##############
# ComboBoxEntry
# ComboBoxEntry
##############
##############
 
 
sub gen_combo_entry{
sub gen_combo_entry{
        my $list_ref=shift;
        my ($list_ref,$pos)=@_;
        my @list=@{$list_ref};
        my @list=@{$list_ref};
 
 
        my $combo_box_entry = Gtk2::ComboBoxEntry->new_text;
        my $combo_box_entry = Gtk2::ComboBoxEntry->new_text;
        foreach my $p (@list){
        foreach my $p (@list){
                $combo_box_entry->append_text($p);
                $combo_box_entry->append_text($p);
        }
        }
        $combo_box_entry->set_active(0);
        $pos=0 if(! defined $pos );
 
        $combo_box_entry->set_active($pos);
        return $combo_box_entry;
        return $combo_box_entry;
}
}
 
 
 
 
 
sub def_h_labeled_combo_entry_help{
 
        my ($help,$label_name,$list_ref,$initial)=@_;
 
        my $box = def_hbox(TRUE,0);
 
        my $label= gen_label_in_left($list_ref);
 
        my ($b,$entry) =gen_combo_entry($help,$initial);
 
        $box->pack_start( $label, FALSE, FALSE, 3);
 
        $box->pack_start( $b, FALSE, FALSE, 3);
 
        return ($box,$entry);
 
 
 
}
 
 
###########
###########
#
#
###########
###########
 
 
sub def_h_labeled_checkbutton{
sub def_h_labeled_checkbutton{
Line 271... Line 286...
}
}
 
 
 
 
sub def_image{
sub def_image{
        my $image_file=shift;
        my $image_file=shift;
        my $font_size=get_deafualt_font_size();
        my $font_size=get_defualt_font_size();
        my $size=($font_size==10)? 25:
        my $size=($font_size==10)? 25:
                     ($font_size==9 )? 22:
                     ($font_size==9 )? 22:
                         ($font_size==8 )? 18:
                         ($font_size==8 )? 18:
                         ($font_size==7 )? 15:12 ;
                         ($font_size==7 )? 15:12 ;
        my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file_at_scale($image_file,$size,$size,FALSE);
        my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file_at_scale($image_file,$size,$size,FALSE);
Line 287... Line 302...
}
}
 
 
 
 
 
 
sub def_image_button{
sub def_image_button{
        my ($image_file, $label_text)=@_;
        my ($image_file, $label_text, $homogeneous)=@_;
        # create box for image and label 
        # create box for image and label 
        my $box = def_hbox(FALSE,0);
        $homogeneous = FALSE if(!defined $homogeneous);
 
        my $box = def_hbox($homogeneous,0);
        my $image = def_image($image_file);
        my $image = def_image($image_file);
 
 
 
 
        # now on to the image stuff
        # now on to the image stuff
        #my $image = Gtk2::Image->new_from_file($image_file);
        #my $image = Gtk2::Image->new_from_file($image_file);
Line 356... Line 372...
 
 
sub def_colored_button{
sub def_colored_button{
        my ($label_text,$color_num)=@_;
        my ($label_text,$color_num)=@_;
        # create box for image and label 
        # create box for image and label 
        my $box = def_hbox(FALSE,0);
        my $box = def_hbox(FALSE,0);
        my $font_size=get_deafualt_font_size();
        my $font_size=get_defualt_font_size();
        my $size=($font_size==10)? 25:
        my $size=($font_size==10)? 25:
                     ($font_size==9 )? 22:
                     ($font_size==9 )? 22:
                         ($font_size==8 )? 18:
                         ($font_size==8 )? 18:
                         ($font_size==7 )? 15:12 ;
                         ($font_size==7 )? 15:12 ;
        $box->set_border_width(0);
        $box->set_border_width(0);
Line 383... Line 399...
}
}
 
 
 
 
 
 
 
 
 
sub show_gif{
 
 
 
        my $gif = shift;
 
        #my $mw=def_popwin_size(400,200,'hey');
 
        my $vbox = Gtk2::HBox->new (TRUE, 8);
 
    my $filename;
 
      eval {
 
##          $filename = demo_find_file ("floppybuddy.gif");
 
          $filename = main::demo_find_file ($gif);
 
      };
 
 
 
 
 
      my $image = Gtk2::Image->new_from_file ($gif);
 
 
 
     $vbox->set_border_width (4);
 
     my   $align = Gtk2::Alignment->new (0.5, 0.5, 0, 0);
 
 
 
        my $frame = Gtk2::Frame->new;
 
        $frame->set_shadow_type ('in');
 
 
 
 
 
 
 
 
 
      # Animation
 
     $frame->add ($image);
 
      $align->add ($frame);
 
 
 
 
 
 
 
 
 
     $vbox->pack_start ($align, FALSE, FALSE, 0);
 
 
 
      # $mw->add ($vbox);
 
 
 
 
 
      # Progressive
 
 
 
 
 
 
 
 
 
        #$mw->show_all();
 
  return $vbox;
 
 
 
 
 
 
 
 
 
}
 
 
############
############
#       message_dialog
#       message_dialog
############
############
 
 
sub message_dialog {
sub message_dialog {
Line 452... Line 513...
        return $window;
        return $window;
 
 
}
}
 
 
 
 
 
 
 
 
 
 
sub def_scrolled_window_box{
sub def_scrolled_window_box{
 
 
        my $window =  def_popwin_size(@_);
        my $window =  def_popwin_size(@_);
        my $box=def_vbox(TRUE,5);
        my $box=def_vbox(TRUE,5);
        my $scrolled_window = new Gtk2::ScrolledWindow (undef, undef);
        my $scrolled_window = new Gtk2::ScrolledWindow (undef, undef);
Line 478... Line 542...
        my $width = $screen->get_width();
        my $width = $screen->get_width();
        return ($width,$hight);
        return ($width,$hight);
}
}
 
 
 
 
sub get_deafualt_font_size{
sub get_defualt_font_size{
        my($width,$hight)=max_win_size();
        my($width,$hight)=max_win_size();
        #print "($width,$hight)\n";
        #print "($width,$hight)\n";
        my $font_size=($width>=1600)? 10:
        my $font_size=($width>=1600)? 10:
                              ($width>=1400)? 9:
                              ($width>=1400)? 9:
                                  ($width>=1200)? 8:
                                  ($width>=1200)? 8:
                                  ($width>=1000)? 7:6;
                                  ($width>=1000)? 7:6;
 
        #print "$font_size\n";  
        return $font_size;
        return $font_size;
}
}
 
 
 
 
sub set_deafualt_font_size{
sub set_defualt_font_size{
        my $font_size=get_deafualt_font_size();
        my $font_size=get_defualt_font_size();
        if($font_size==10){
 
                Gtk2::Rc->parse_string(<<__);
 
                        style "normal" {
 
                                font_name ="Verdana 10"
 
                        }
 
                        widget "*" style "normal"
 
__
 
 
 
        }
 
        elsif ($font_size==9){
 
                $font_size=9;
 
                Gtk2::Rc->parse_string(<<__);
 
                style "normal" {
 
                                font_name ="Verdana 9"
 
                        }
 
                        widget "*" style "normal"
 
__
 
 
 
        }
 
        elsif ($font_size==8){
 
                $font_size=8;
 
                Gtk2::Rc->parse_string(<<__);
 
                style "normal" {
 
                                font_name ="Verdana 8"
 
                        }
 
                        widget "*" style "normal"
 
__
 
 
 
        }
 
        elsif ($font_size==7){
 
            $font_size=7;
 
                Gtk2::Rc->parse_string(<<__);
 
                style "normal" {
 
                                font_name ="Verdana 7"
 
                        }
 
                        widget "*" style "normal"
 
__
 
 
 
        }
 
        else{
 
                Gtk2::Rc->parse_string(<<__);
                Gtk2::Rc->parse_string(<<__);
                style "normal" {
                style "normal" {
                                font_name ="Verdana 6"
                                font_name ="Verdana $font_size"
                        }
                        }
                        widget "*" style "normal"
                        widget "*" style "normal"
__
__
 
 
        }
        }
 
 
 
 
 
 
}
 
 
 
 
 
##############
##############
#       box
#       box
#############
#############
 
 
sub def_hbox {
sub def_hbox {
Line 626... Line 648...
        my @state= ($entry,$timeout);
        my @state= ($entry,$timeout);
        return \@state
        return \@state
 
 
}
}
 
 
sub set_state{
 
        my ($state,$initial,$timeout)=@_;
 
        my ($entry,$time_out)=@{$state};
 
        $entry->set_text($initial);
 
        @{$state}[1]=$timeout;
 
 
 
}
 
 
 
 
 
sub get_state{
 
        my ($state)=@_;
sub set_gui_status{
        my ($entry,$time_out)=@{$state};
        my ($object,$status,$timeout)=@_;
        my $st;
        $object->object_add_attribute('gui_status','status',$status);
        $st=$entry->get_text();
        $object->object_add_attribute('gui_status','timeout',$timeout);
        return ($st,$time_out);
 
}
}
 
 
 
 
 
sub get_gui_status{
 
        my ($object)=@_;
 
        my $status= $object->object_get_attribute('gui_status','status');
 
        my $timeout=$object->object_get_attribute('gui_status','timeout');
 
        return ($status,$timeout);
 
}
 
 
 
 
 
 
##################
##################
#       show_info
#       show_info
##################
##################
Line 655... Line 677...
        my ($textview_ref,$info)=@_;
        my ($textview_ref,$info)=@_;
        my $buffer = $$textview_ref->get_buffer();
        my $buffer = $$textview_ref->get_buffer();
        $buffer->set_text($info);
        $buffer->set_text($info);
}
}
 
 
 
sub add_info{
 
        my ($textview_ref,$info)=@_;
 
        my $buffer = $$textview_ref->get_buffer();
 
        my $textiter = $buffer->get_end_iter();
 
        #Insert some text into the buffer
 
        $buffer->insert($textiter,$info);
 
 
 
}
 
 
 
 
 
 
####################
####################
#       read verilog file
#       read verilog file
##################
##################
Line 683... Line 714...
        }
        }
 
 
        return $vdb;
        return $vdb;
}
}
 
 
 
sub add_color_to_gd{
 
        foreach (my $i=0;$i<32;$i++ ) {
 
                my ($red,$green,$blue)=get_color($i);
 
 
 
 
 
                add_colour("my_color$i"=>[$red>>8,$green>>8,$blue>>8]);
 
 
 
 
 
        }
 
 
 
 
 
 
 
}
 
 
 
 
 
 
sub get_color {
sub get_color {
        my $num=shift;
        my $num=shift;
 
 
        my @colors=(
        my @colors=(
Line 718... Line 764...
        0xDC143C,#Crimson       
        0xDC143C,#Crimson       
        0x9932CC,#Dark Orchid
        0x9932CC,#Dark Orchid
        0x800000,#marron
        0x800000,#marron
        0x800080,#Purple
        0x800080,#Purple
        0x4B0082,#Indigo
        0x4B0082,#Indigo
        0xFFFFFF #white                 
        0xFFFFFF,#white 
 
        0x000000 #Black         
                );
                );
 
 
        my $color=      ($num< scalar (@colors))? $colors[$num]: 0xFFFFFF;
        my $color=      ($num< scalar (@colors))? $colors[$num]: 0xFFFFFF;
        my $red=        ($color & 0xFF0000) >> 8;
        my $red=        ($color & 0xFF0000) >> 8;
        my $green=      ($color & 0x00FF00);
        my $green=      ($color & 0x00FF00);
Line 796... Line 843...
                }#if    
                }#if    
        }#p
        }#p
}#sub   
}#sub   
 
 
 
 
 
############
 
#       get file folder list
 
###########
 
 
 
sub get_directory_name {
 
        my ($object,$title,$entry,$attribute1,$attribute2,$status,$timeout)= @_;
 
        my $browse= def_image_button("icons/browse.png");
 
 
 
        $browse->signal_connect("clicked"=> sub{
 
                my $entry_ref=$_[1];
 
                my $file;
 
                $title ='select directory' if(!defined $title);
 
                my $dialog = Gtk2::FileChooserDialog->new(
 
                        $title, undef,
 
                        #               'open',
 
                        'select-folder',
 
                        'gtk-cancel' => 'cancel',
 
                        'gtk-ok'     => 'ok',
 
                        );
 
 
 
 
 
                        if ( "ok" eq $dialog->run ) {
 
                        $file = $dialog->get_filename;
 
                                $$entry_ref->set_text($file);
 
                                $object->object_add_attribute($attribute1,$attribute2,$file);
 
                                set_gui_status($object,$status,$timeout) if(defined $status);
 
                                #check_input_file($file,$socgen,$soc_state,$info);
 
                                #print "file = $file\n";
 
                         }
 
                        $dialog->destroy;
 
 
 
 
 
 
 
                } , \$entry);
 
 
 
        return $browse;
 
 
 
}
 
 
 
 
 
sub get_file_name {
 
        my ($object,$title,$entry,$attribute1,$attribute2,$extension,$lable,$open_in)= @_;
 
        my $browse= def_image_button("icons/browse.png");
 
 
 
        $browse->signal_connect("clicked"=> sub{
 
                my $entry_ref=$_[1];
 
                my $file;
 
                $title ='select directory' if(!defined $title);
 
                my $dialog = Gtk2::FileChooserDialog->new(
 
                'Select a File', undef,
 
                'open',
 
                'gtk-cancel' => 'cancel',
 
                'gtk-ok'     => 'ok',
 
                );
 
         if(defined $extension){
 
                my $filter = Gtk2::FileFilter->new();
 
                $filter->set_name($extension);
 
                $filter->add_pattern("*.$extension");
 
                $dialog->add_filter ($filter);
 
         }
 
          if(defined  $open_in){
 
                $dialog->set_current_folder ($open_in);
 
                # print "$open_in\n";
 
 
 
        }
 
 
 
                        if ( "ok" eq $dialog->run ) {
 
                        $file = $dialog->get_filename;
 
                                $$entry_ref->set_text($file);
 
                                $object->object_add_attribute($attribute1,$attribute2,$file);
 
                                my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
 
                                $lable->set_markup("<span  foreground= 'black' ><b>$name$suffix</b></span>");
 
                                $lable->show;
 
 
 
                                #check_input_file($file,$socgen,$soc_state,$info);
 
                                #print "file = $file\n";
 
                         }
 
                        $dialog->destroy;
 
 
 
 
 
 
 
                } , \$entry);
 
 
 
        return $browse;
 
 
 
}
 
 
 
 
 
#################
 
#       widget update object
 
#################
 
 
 
sub gen_entry_object {
 
        my ($object,$attribute1,$attribute2,$default,$status,$timeout)=@_;
 
        my $old=$object->object_get_attribute($attribute1,$attribute2);
 
        my $widget;
 
        if(defined $old ){
 
                $widget=gen_entry($old);
 
        }
 
        else
 
        {
 
                $widget=gen_entry($default);
 
                $object->object_add_attribute($attribute1,$attribute2,$default);
 
        }
 
        $widget-> signal_connect("changed" => sub{
 
                my $new_param_value=$widget->get_text();
 
                $object->object_add_attribute($attribute1,$attribute2,$new_param_value);
 
                set_gui_status($object,$status,$timeout) if (defined $status);
 
        });
 
        return $widget;
 
}
 
 
 
 
 
sub gen_combobox_object {
 
        my ($object,$attribute1,$attribute2,$content,$default,$status,$timeout)=@_;
 
        my @combo_list=split(",",$content);
 
        my $value=$object->object_get_attribute($attribute1,$attribute2);
 
        my $pos;
 
        $pos=get_pos($value, @combo_list) if (defined $value);
 
        if(!defined $pos && defined $default){
 
                $object->object_add_attribute($attribute1,$attribute2,$default);
 
                $pos=get_item_pos($default, @combo_list);
 
        }
 
        #print " my $pos=get_item_pos($value, @combo_list);\n";
 
        my $widget=gen_combo(\@combo_list, $pos);
 
        $widget-> signal_connect("changed" => sub{
 
                my $new_param_value=$widget->get_active_text();
 
                $object->object_add_attribute($attribute1,$attribute2,$new_param_value);
 
                set_gui_status($object,$status,$timeout) if (defined $status);
 
         });
 
        return $widget;
 
 
 
 
 
}
 
 
 
 
 
sub gen_comboentry_object {
 
        my ($object,$attribute1,$attribute2,$content,$default,$status,$timeout)=@_;
 
        my @combo_list=split(",",$content);
 
        my $value=$object->object_get_attribute($attribute1,$attribute2);
 
        my $pos;
 
        $pos=get_pos($value, @combo_list) if (defined $value);
 
        if(!defined $pos && defined $default){
 
                $object->object_add_attribute($attribute1,$attribute2,$default);
 
                $pos=get_item_pos($default, @combo_list);
 
        }
 
        #print " my $pos=get_item_pos($value, @combo_list);\n";
 
        my $widget=gen_combo_entry(\@combo_list, $pos);
 
        ($widget->child)->signal_connect('changed' => sub {
 
                my ($entry) = @_;
 
                my $new_param_value=$entry->get_text();
 
                $object->object_add_attribute($attribute1,$attribute2,$new_param_value);
 
                set_gui_status($object,$status,$timeout) if (defined $status);
 
         });
 
        return $widget;
 
 
 
}
 
 
 
 
 
 
 
sub gen_spin_object {
 
        my ($object,$attribute1,$attribute2,$content, $default,$status,$timeout)=@_;
 
        my $value=$object->object_get_attribute($attribute1,$attribute2);
 
        my ($min,$max,$step)=split(",",$content);
 
        if(!defined $value){
 
                $value=$default;
 
                $object->object_add_attribute($attribute1,$attribute2,$value);
 
        }
 
        $value=~ s/\D//g;
 
        $min=~ s/\D//g;
 
        $max=~ s/\D//g;
 
        $step=~ s/\D//g;
 
        my $widget=gen_spin($min,$max,$step);
 
        $widget->set_value($value);
 
        $widget-> signal_connect("value_changed" => sub{
 
                my $new_param_value=$widget->get_value_as_int();
 
                $object->object_add_attribute($attribute1,$attribute2,$new_param_value);
 
                set_gui_status($object,$status,$timeout) if (defined $status);
 
        });
 
        return $widget;
 
}
 
 
 
 
 
sub gen_check_box_object {
 
                my ($object,$attribute1,$attribute2,$content,$value,$default,$status,$timeout)=@_;
 
                my $widget = def_hbox(FALSE,0);
 
                my @check;
 
                for (my $i=0;$i<$content;$i++){
 
                        $check[$i]= Gtk2::CheckButton->new;
 
                }
 
                for (my $i=0;$i<$content;$i++){
 
                        $widget->pack_end(  $check[$i], FALSE, FALSE, 0);
 
 
 
                        my @chars = split("",$value);
 
                        #check if saved value match the size of check box
 
                        if($chars[0] ne $content ) {
 
                                $object->object_add_attribute($attribute1,$attribute2,$default);
 
                                $value=$default;
 
                                @chars = split("",$value);
 
                        }
 
                        #set initial value
 
 
 
                        #print "\@chars=@chars\n";
 
                        for (my $i=0;$i<$content;$i++){
 
                                my $loc= (scalar @chars) -($i+1);
 
                                        if( $chars[$loc] eq '1') {$check[$i]->set_active(TRUE);}
 
                                        else {$check[$i]->set_active(FALSE);}
 
                        }
 
 
 
 
 
                        #get new value
 
                        $check[$i]-> signal_connect("toggled" => sub{
 
                                my $new_val="$content\'b";
 
 
 
                                for (my $i=$content-1; $i >= 0; $i--){
 
                                        if($check[$i]->get_active()) {$new_val="${new_val}1" ;}
 
                                        else {$new_val="${new_val}0" ;}
 
                                }
 
                                $object->object_add_attribute($attribute1,$attribute2,$new_val);
 
                                #print "\$new_val=$new_val\n";
 
                                set_gui_status($object,$status,$timeout) if (defined $status);
 
                        });
 
        }
 
        return $widget;
 
 
 
}
 
 
 
 
 
 
 
sub get_dir_in_object {
 
        my ($object,$attribute1,$attribute2,$content,$status,$timeout)=@_;
 
        my $widget = def_hbox(FALSE,0);
 
        my $value=$object->object_get_attribute($attribute1,$attribute2);
 
        my $entry=gen_entry($value);
 
        $entry-> signal_connect("changed" => sub{
 
                my $new_param_value=$entry->get_text();
 
                $object->object_add_attribute($attribute1,$attribute2,$new_param_value);
 
                set_gui_status($object,$status,$timeout) if (defined $status);
 
        });
 
        my $browse= get_directory_name($object,undef,$entry,$attribute1,$attribute2,$status,$timeout);
 
        $widget->pack_start( $entry, FALSE, FALSE, 0);
 
        $widget->pack_start( $browse, FALSE, FALSE, 0);
 
        return $widget;
 
}
 
 
 
 
 
 
 
 
 
sub get_file_name_object {
 
        my ($object,$attribute1,$attribute2,$extension,$open_in)=@_;
 
        my $widget = def_hbox(FALSE,0);
 
        my $value=$object->object_get_attribute($attribute1,$attribute2);
 
        my $lable;
 
        if(defined $value){
 
                my ($name,$path,$suffix) = fileparse("$value",qr"\..[^.]*$");
 
                $lable=gen_label_in_center($name.$suffix);
 
 
 
        } else {
 
                        $lable=gen_label_in_center("Selecet a $extension file");
 
                        $lable->set_markup("<span  foreground= 'red' ><b>Selecet a sof file</b></span>");
 
        }
 
        my $entry=gen_entry();
 
        my $browse= get_file_name($object,undef,$entry,$attribute1,$attribute2,$extension,$lable,$open_in);
 
        $widget->pack_start( $lable, FALSE, FALSE, 0);
 
        $widget->pack_start( $browse, FALSE, FALSE, 0);
 
        return $widget;
 
}
 
 
 
################
 
# ADD info and label to widget
 
################
 
 
 
 
 
sub labele_widget_info{
 
        my ($label_name,$widget,$info)=@_;
 
        my $box = def_hbox(FALSE,0);
 
        #label
 
        if(defined $label_name){
 
                my $label= gen_label_in_left($label_name);
 
                $box->pack_start( $label, FALSE, FALSE, 3);
 
        }
 
        $box->pack_start( $widget, FALSE, FALSE, 3);
 
        #info   
 
        if(defined $info){
 
                my $button=def_image_button("icons/help.png");
 
                $button->signal_connect("clicked" => sub {message_dialog($info);});
 
                $box->pack_start( $button, FALSE, FALSE, 3);
 
        }
 
        $box->show_all;
 
        return $box;
 
}
 
 
 
 
 
 
 
 
################
################
#       general
#       general
#################
#################
 
 
 
 

powered by: WebSVN 2.1.0

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