"){
$all_menus{$name}{'menu'}=$menu;
$all_menus{$name}{'num'}=0;
}}
}
if(defined $key){
$menuitem->add_accelerator('activate',$accel_group,Gtk3::accelerator_parse($key),'visible');
}
if(defined $func){
$menuitem->signal_connect('activate' => \&$func);
}
#print "$name,$key,$func,$u,$type\n";
$menuitem->show();
}
my $box = Gtk3::Box->new( 'vertical', 0 );
$box->pack_start( $menubar, FALSE, TRUE, 0 );
$menubar->show();
return $box;
}
sub creating_detachable_toolbar{
my @attachments=@_;
return def_pack_hbox('FALSE', 0, @_);
#The handle box helps in creating a detachable toolbar
my $hb = Gtk3::HandleBox->new;
#create a toolbar, and do some initial settings
my $toolbar = Gtk3::Toolbar->new;
$toolbar->set_icon_size ('small-toolbar');
$toolbar->set_show_arrow (FALSE);
foreach my $p (@attachments){
$toolbar->insert($p,-1);
}
$hb->add($toolbar);
return $hb;
}
sub gui_quite{
Gtk3->main_quit;
}
sub gtk_gui_run{
my ($main)=@_;
Gtk3->init;
&$main;
Gtk3->main();
return 1;
}
sub refresh_gui{
while (Gtk3::events_pending) {
Gtk3::main_iteration;
}
Gtk3::Gdk::flush;
}
sub about {
my $version=shift;
my $about = Gtk3::AboutDialog->new;
my @authors=("Alireza Monemi", "Email: alirezamonemi\@opencores.org");
$about->set_authors(\@authors);
$about->set_version( $version );
$about->set_website('http://opencores.org/project,an-fpga-implementation-of-low-latency-noc-based-mpsoc');
$about->set_comments('NoC based MPSoC generator.');
$about->set_program_name('ProNoC');
my $pixbuf = Gtk3::Gdk::Pixbuf->new_from_file_at_scale("icons/ProNoC.png",50,50,FALSE);
$about->set_logo($pixbuf);
$about->set_license(
"This program is free software; you can redistribute it\n"
. "and/or modify it under the terms of the GNU General \n"
. "Public License as published by the Free Software \n"
. "Foundation; either version 1, or (at your option)\n"
. "any later version.\n\n"
);
# Add the Hide action to the 'Close' button in the AboutDialog():
$about->signal_connect('response' => sub { $about->hide; });
$about->set_transient_for (Gtk3::Window->new('toplevel'));#just to get rid of transient warning
$about->run;
$about->destroy;
return;
}
############
# list_store
###########
sub gen_list_store {
my ($dref,$clmn_type_ref, $clmn_lables_ref)=@_;
# my @data = (
# {0 => "Average distance", 1 =>"$avg"},
# {0 => "Max distance", 1 =>"$max" },
# {0 => "Min distance",1 => "$min"},
# {0 => "Normlized data per hop", 1 =>"$norm" }
# );
# my @clmn_type = (#'Glib::Boolean', # => G_TYPE_BOOLEAN
# #'Glib::Uint', # => G_TYPE_UINT
# 'Glib::String', # => G_TYPE_STRING
# 'Glib::String'); # you get the idea
my @data = @{$dref};
my @clmn_type = @{$clmn_type_ref};
my @clmn_lables= @{$clmn_lables_ref};
# create list store
my $store = Gtk3::ListStore->new ( @clmn_type);
# add data to the list store
foreach my $d (@data) {
my $iter = $store->append;
my @clmns = sort keys %{$d};
my @a=($iter);
foreach my $c (@clmns){
push (@a,($c,$d->{$c}));
}
$store->set (@a);
}
my $treeview = Gtk3::TreeView->new ($store);
$treeview->set_rules_hint (TRUE);
$treeview->set_search_column (1);
#my $renderer = Gtk3::CellRendererToggle->new;
#$renderer->signal_connect (toggled => \&fixed_toggled, $store);
# column for severities
my $c=0;
foreach my $l (@clmn_lables){
my $renderer = Gtk3::CellRendererText->new;
my $column = Gtk3::TreeViewColumn->new_with_attributes ("$l",
$renderer,
text => $c );
$column->set_sort_column_id ($c );
$treeview->append_column ($column);
$c++;
}
return $treeview;
}
##############
# create tree
##############
sub create_tree_model_network_maker{
my $model = Gtk3::TreeStore->new ('Glib::String', 'Glib::String', 'Glib::Scalar', 'Glib::Boolean');
my $tree_view = Gtk3::TreeView->new;
$tree_view->set_model ($model);
my $selection = $tree_view->get_selection;
$selection->set_mode ("single");
my $cell = Gtk3::CellRendererText->new;
$cell->set ('style' => 'italic');
my $column = Gtk3::TreeViewColumn->new_with_attributes ("select", $cell, 'text' => 0, 'style_set' => 3);
return ($model,$tree_view,$column);
}
sub treemodel_next_iter{
my ($child , $tree_model)=@_;
$tree_model->iter_next ($child);
return $child;
}
# clean names for column numbers.
use constant DISPLAY_COLUMN => 0;
use constant CATRGORY_COLUMN => 1;
use constant MODULE_COLUMN => 2;
use constant ITALIC_COLUMN => 3;
use constant NUM_COLUMNS => 4;
sub create_tree {
my ($self,$label,$info,$tree_ref,$row_selected_func,$row_activated_func)=@_;
my %tree_in = %{$tree_ref};
my $model = Gtk3::TreeStore->new ('Glib::String', 'Glib::String', 'Glib::Scalar', 'Glib::Boolean');
my $tree_view = Gtk3::TreeView->new;
$tree_view->set_model ($model);
my $selection = $tree_view->get_selection;
$selection->set_mode ('browse');
foreach my $p (sort keys %tree_in)
{
my @modules= @{$tree_in{$p}};
#my @dev_entry= @{$tree_entry{$p}};
my $iter = $model->append (undef);
$model->set ($iter,
DISPLAY_COLUMN, $p,
CATRGORY_COLUMN, $p || '',
MODULE_COLUMN, 0 || '',
ITALIC_COLUMN, FALSE);
next unless @modules;
foreach my $v ( @modules){
my $child_iter = $model->append ($iter);
my $entry= '';
$model->set ($child_iter,
DISPLAY_COLUMN, $v,
CATRGORY_COLUMN, $p|| '',
MODULE_COLUMN, $v || '',
ITALIC_COLUMN, FALSE);
}
}
my $cell = Gtk3::CellRendererText->new;
$cell->set ('style' => 'italic');
my $column = Gtk3::TreeViewColumn->new_with_attributes
("$label",
$cell,
'text' => DISPLAY_COLUMN,
'style_set' => ITALIC_COLUMN);
$tree_view->append_column ($column);
my @ll=($model,$info);
#row selected
$selection->signal_connect (changed =>sub {
my ($selection, $ref) = @_;
my ($model,$info)=@{$ref};
my $iter = $selection->get_selected;
return unless defined $iter;
my ($category) = $model->get ($iter, CATRGORY_COLUMN);
my ($module) = $model->get ($iter,MODULE_COLUMN );
$row_selected_func->($self,$category,$module,$info) if(defined $row_selected_func);
}, \@ll);
# row_activated
$tree_view->signal_connect (row_activated => sub{
my ($tree_view, $path, $column) = @_;
my $model = $tree_view->get_model;
my $iter = $model->get_iter ($path);
my ($category) = $model->get ($iter, CATRGORY_COLUMN);
my ($module) = $model->get ($iter,MODULE_COLUMN );
if($module){
#print "$module is selected via row activaton!\n";
$row_activated_func->($self,$category,$module,$info) if(defined $row_activated_func);
#add_module_to_soc($soc,$ip,$category,$module,$info);
}
}, \@ll);
#$tree_view->expand_all;
my $scrolled_window = Gtk3::ScrolledWindow->new;
$scrolled_window->set_policy ('automatic', 'automatic');
$scrolled_window->set_shadow_type ('in');
$scrolled_window->add($tree_view);
my $hbox = Gtk3::HBox->new (FALSE, 0);
$hbox->pack_start ( $scrolled_window, TRUE, TRUE, 0);
return $hbox;
}
sub row_activated_cb{
my ($tree_view, $path, $column) = @_;
my $model = $tree_view->get_model;
my $iter = $model->get_iter ($path);
my ($category) = $model->get ($iter, DISPLAY_COLUMN);
my ($module) = $model->get ($iter, CATRGORY_COLUMN);
}
sub file_edit_tree {
my $model = Gtk3::TreeStore->new('Glib::String', 'Glib::String');
my $tree_view = Gtk3::TreeView->new;
$tree_view->set_model ($model);
my $selection = $tree_view->get_selection;
$selection->set_mode ("single");
my $cell = Gtk3::CellRendererText->new;
$cell->set ('style' => 'italic');
my $column = Gtk3::TreeViewColumn->new_with_attributes('Double-click to open',$cell, text => "0");
$tree_view->append_column($column);
$tree_view->set_headers_visible(TRUE);
return ($model,$tree_view);
}
# my $column = Gtk3::TreeViewColumn->new_with_attributes ("select", $cell, 'text' => 0, 'style_set' => 3);
##########
# run external commands
##########
sub run_cmd_in_back_ground
{
my $command = shift;
#print "\t$command\n";
### Start running the Background Job:
my $proc = Proc::Background->new($command);
my $PID = $proc->pid;
my $start_time = $proc->start_time;
my $alive = $proc->alive;
### While $alive is NOT '0', then keep checking till it is...
# *When $alive is '0', it has finished executing.
while($alive ne 0)
{
$alive = $proc->alive;
# This while loop will cause Gtk3 to continue processing events, if
# there are events pending... *which there are...
while (Gtk3::events_pending) {
Gtk3::main_iteration;
}
Gtk3::Gdk::flush;
usleep(1000);
}
my $end_time = $proc->end_time;
# print "*Command Completed at $end_time, with PID = $PID\n\n";
# Since the while loop has exited, the BG job has finished running:
# so close the pop-up window...
# $popup_window->hide;
# Get the RETCODE from the Background Job using the 'wait' method
my $retcode = $proc->wait;
$retcode /= 256;
#print "\t*RETCODE == $retcode\n\n";
Gtk3::Gdk::flush;
### Check if the RETCODE returned with an Error:
if ($retcode ne 0) {
print "Error: The Background Job ($command) returned with an Error...!\n";
return 1;
} else {
#print "Success: The Background Job Completed Successfully...!\n";
return 0;
}
}
sub run_cmd_in_back_ground_get_stdout
{
my $cmd=shift;
my $exit;
my ($stdout, $stderr);
open(OLDERR, ">&STDERR");
open(STDERR, ">>/tmp/tmp.spderr") or die "Can't dup stdout";
select(STDOUT); $| = 1; # make unbuffered
print OLDERR ""; #this fixed an error about OLDERR not being used
## do my stuff here.
capture { $exit=run_cmd_in_back_ground($cmd) } \$stdout, \$stderr;
close(STDERR);
open(STDERR, ">&OLDERR");
return ($stdout,$exit,$stderr);
}
sub run_cmd_message_dialog_errors{
my ($cmd)=@_;
my ($stdout,$exit,$stderr)=run_cmd_in_back_ground_get_stdout($cmd);
if(length $stderr>1){
message_dialog("$stderr\n",'error');
return 1;
}if($exit){
message_dialog("Error $cmd failed: $stdout\n",'error');
return 1;
}
return 0;
}
sub run_cmd_textview_errors{
my ($cmd,$tview)=@_;
my ($stdout,$exit,$stderr)=run_cmd_in_back_ground_get_stdout($cmd);
if(length $stderr>1){
add_colored_info($tview,"Error: $stderr\n",'red');
add_colored_info($tview,"$cmd did not run successfully!\n",'red');
return undef;
}
if($exit){
add_colored_info($tview,"Error:$stdout\n",'red');
add_colored_info($tview,"$cmd did not run successfully!\n",'red');
return undef;
}
$stdout = "" if (!defined $stdout);
return $stdout
}
sub create_iconview_model {
#----------------------------------------------------
#The Iconview needs a Gtk3::Treemodel implementation-
#containing at least a Glib::String and -------------
#Gtk3::Gdk::Pixbuf type. The first is used for the --
#text of the icon, and the last for the icon self----
#Gtk3::ListStore is ideal for this ------------------
#----------------------------------------------------
my ($self,$name,$ref)=@_;
my @sources= (defined $ref)? @{$ref}:();
my $list_store = Gtk3::ListStore->new(qw/Glib::String Gtk3::Gdk::Pixbuf Glib::String/);
#******************************************************
#we populate the Gtk3::ListStore with Gtk3::Stock icons
#******************************************************
foreach my $val(@sources){
#get the iconset from the icon_factory
#my $iconset = $icon_factory->lookup_default($val);
#try and extract the icon from it
add_icon_to_tree($self,$name,$list_store,$val);
}
return $list_store;
}
####################
# SourceView
####################
sub gen_SourceView_with_buffer{
return Gtk3::SourceView::View->new_with_buffer(@_);
}
sub create_SourceView_buffer {
my $self = shift;
my $tags = Gtk3::TextTagTable->new();
add_tag_to_SourceView($tags, search => {
background => 'yellow',
});
add_tag_to_SourceView($tags, goto_line => {
'paragraph-background' => 'orange',
});
my $buffer = Gtk3::SourceView::Buffer->new($tags);
$buffer->signal_connect('notify::cursor-position' => sub {
$self->clear_highlighted();
});
return $buffer;
}
sub add_tag_to_SourceView {
my ($tags, $name, $properties) = @_;
my $tag = Gtk3::TextTag->new($name);
$tag->set(%{ $properties });
$tags->add($tag);
}
sub detect_language {
my $self = shift;
my ($filename) = @_;
# Guess the programming language of the file
my $manager = Gtk3::SourceView::LanguageManager->get_default;
my $language = $manager->guess_language($filename);
$self->buffer->set_language($language);
}
sub get_pressed_key{
my $event=shift;
my $key = Gtk3::Gdk::keyval_name( $event->keyval );
return $key;
}
1
Error running this command: diff -w -U 5 "" "/tmp/7ciADY"
diff: : No such file or directory