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/] [drag_drop.pl] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 alirezamon
#! /usr/bin/perl -w
2
 
3
use strict;
4
use constant::boolean;
5
 
6
 
7
use FindBin;
8
use lib $FindBin::Bin;
9
require "widget.pl";
10
use POSIX qw(ceil floor);
11
 
12
 
13
#Declare our columns
14
use constant C_MARKUP               => 0;
15
use constant C_PIXBUF               => 1;
16
 
17
 
18
#Declare our IDENDTIFIER ID's
19
use constant ID_ICONVIEW            => 48;
20
 
21
 
22
 
23
 
24
 
25
 
26
sub drag_and_drop_page {
27
        my ($self,$tview,$name,$items_ref, $ctrl_box)=@_;
28
    my $vbox = def_vbox(FALSE,5);
29
        my $group_num=$self->object_get_attribute($name,'group_num');
30
        update_group_item_list($self,$group_num,$name,$items_ref);
31
        my $ref_source = $self->object_get_attribute("$name",'ungrouped');
32
    my $lb=$self->object_get_attribute($name,'lable');
33
    my ($win,$list_store)=create_iconview($self,"$lb",'NO', $ref_source,$name,'ungrouped',undef);
34
    my $table = def_table($group_num%8,$group_num/8,FALSE);
35
    my $dim_y = floor(sqrt($group_num));
36
        my $gname=$self->object_get_attribute("$name",'group_name_root');
37
        my $editable =$self->object_get_attribute("$name",'group_name_editble');
38
        my $limit=$self->object_get_attribute($name,'map_limit');
39
        for (my $i=0; $i<$group_num;$i++){
40
 
41
                        my $ref_grp = $self->object_get_attribute("$name","$gname($i)");
42
 
43
                my ($gwin,$list_store)=create_iconview($self,"$gname($i)",$editable,$ref_grp,$name,"$gname($i)",$limit );
44
                my $y= int($i/$dim_y);
45
                my $x= $i % $dim_y;
46
                $table->attach_defaults ($gwin, $x, $x+1 , $y, $y+1);
47
    }
48
   my $sw = add_widget_to_scrolled_win($table);
49
 
50
   my  $v_paned=gen_vpaned($win,.2,$sw);
51
   my  $h_paned= (defined $ctrl_box)? gen_hpaned_adj($self,$v_paned,.5,$ctrl_box, "drag.$name") : $v_paned;
52
 
53
$vbox->add($h_paned);
54
$vbox->show_all();
55
return $vbox;
56
}
57
 
58
sub get_item_group_name{
59
        my ($self,$name,$item)=@_;
60
        #print "($self,$name,$item)\n";
61
        my $group_num=$self->object_get_attribute("$name",'group_num');
62
        my $gname=$self->object_get_attribute("$name",'group_name_root');
63
        for(my $i=0;$i<$group_num;$i=$i+1){
64
                my $gref = $self->object_get_attribute("$name","$gname($i)");
65
                next if(! defined $gref);
66
                return $self->object_get_attribute("$name","$gname($i)".'_name') if( check_scolar_exist_in_array($item,$gref ));
67
        }
68
        return $item;
69
}
70
 
71
sub get_items_in_a_group{
72
        my ($self,$name,$group_name)=@_;
73
        my $group_num=$self->object_get_attribute("$name",'group_num');
74
        my $gname=$self->object_get_attribute("$name",'group_name_root');
75
        for(my $i=0;$i<$group_num;$i=$i+1){
76
                my $current_name= $self->object_get_attribute("$name","$gname($i)".'_name');
77
                return  $self->object_get_attribute("$name","$gname($i)") if($current_name eq $group_name );
78
        }
79
        return undef;
80
}
81
 
82
 
83
sub update_group_item_list{
84
        my ($self,$group_num,$name,$items_ref)=@_;
85
        #get the list of current items
86
        my @items = (defined $items_ref) ? @{$items_ref}:();
87
        my @items_grouped;
88
        my $gname=$self->object_get_attribute("$name",'group_name_root');
89
        #update groaped_list
90
        for(my $i=0;$i<$group_num;$i=$i+1){
91
                my $gref = $self->object_get_attribute("$name","$gname($i)");
92
                next if(! defined $gref);
93
                my @grouped =  @{$gref};
94
                @grouped=get_common_array(\@grouped,\@items);
95
                $self->object_add_attribute("$name","$gname($i)",\@grouped);
96
                push (@items_grouped,@grouped);
97
        }
98
        #@items_ungroaped= @items - @items_groaped
99
        my @items_ungrouped= get_diff_array(\@items ,\@items_grouped);
100
        $self->object_add_attribute("$name",'ungrouped',\@items_ungrouped);
101
}
102
 
103
 
104
 
105
 
106
sub create_iconview {
107
#---------------------------------------------------
108
#Creates an Iconview in a ScrolledWindow. This -----
109
#Iconview has the ability to drag items off it  -----
110
#---------------------------------------------------
111
        my ($self,$label,$editable,$ref,$name,$param,$limit)=@_;
112
    my $icon_string= undef;
113
    my $tree_model = create_iconview_model($self,$name,$ref);
114
 
115
    my $icon_view = gen_iconview($tree_model,C_MARKUP,C_PIXBUF);
116
 
117
    #Enable the IconView as a drag source
118
 
119
    add_drag_source($icon_view,'STRING',[],ID_ICONVIEW);
120
    add_drop_source($icon_view,$tree_model,$name,$param,$self,$limit);
121
 
122
    #This is a nice to have. It changes the drag icon to that of the
123
    #icon which are now selected and dragged (single selection mode)
124
        my $saved;
125
 
126
    $icon_view->signal_connect('drag-begin' => sub {
127
        $icon_view->selected_foreach ( sub{
128
                my $iter =$tree_model->get_iter($_[1]);
129
                                $saved=$iter;
130
                #set the text and pixbuf
131
                my $icon_pixbuf = $tree_model->get_value($iter,C_PIXBUF);
132
                                drag_set_icon_pixbuf($icon_view,$icon_pixbuf);
133
                                $icon_view->show_all();
134
        } );
135
    });
136
 
137
    #set up the data which needs to be fed to the drag destination (drop)
138
    $icon_view->signal_connect ('drag-data-get' => sub {
139
                return if(! defined $saved);
140
                $icon_string = $tree_model->get_value($saved,C_MARKUP);
141
                #print "\$icon_string=$icon_string\n";
142
                my $no_markup = $icon_string;
143
        $no_markup =~ s/<[^>]*>//g;
144
 
145
 
146
                my $gref = $self->object_get_attribute("$name",$param);
147
                $tree_model->remove($saved);
148
                source_drag_data_get(@_,$icon_string);
149
                my @array=remove_scolar_from_array($gref,$no_markup );
150
                $self->object_add_attribute("$name",$param,\@array);
151
                set_gui_status($self,"drag-data-get",0);
152
 
153
        } );
154
 
155
    #Standard scrolledwindow to allow growth
156
    my $sw = add_widget_to_scrolled_win($icon_view);
157
    $sw->set_policy('never','automatic');
158
    $sw->set_border_width(6);
159
    my($width,$hight)=max_win_size();
160
        $sw->set_size_request($width/10,$hight/10);
161
 
162
 
163
    my $frame = gen_frame();
164
        $frame->set_shadow_type ('in');
165
        # Animation
166
        $frame->add ($sw);
167
        #$align->add ($frame);
168
 
169
 
170
 
171
        my $entry=gen_entry_object($self,$name,$param."_name",$label);
172
        $frame->set_label_widget ($entry) if($editable eq 'YES');
173
        $frame->set_label_widget (gen_label_in_center($label)) unless($editable eq 'YES');
174
 
175
 
176
    return ($frame,$tree_model);
177
}
178
 
179
 
180
 
181
 
182
 
183
sub target_drag_data_received {
184
#---------------------------------------------------
185
#Extract the data which was set up during the  -----
186
#'drag-data-get' event which fired just before -----
187
#the 'drag-data-received' event. Also checks which--
188
#source supplied the data, and handle accordingly----
189
#---------------------------------------------------
190
 
191
    my ($widget, $context, $x, $y, $data, $info, $time,$ref) = @_;
192
 
193
        my ($target,$name,$param,$self,$limit) = @{$ref};
194
    my @array;
195
        my $icon=$self->object_get_attribute($name,'trace_icon');
196
        my $pixbuf = get_icon_pixbuff ($icon );
197
 
198
 
199
 
200
 
201
        my $no_markup = $data->get_text;
202
                #print Dumper ($widget, $context, $x, $y, $data, $info, $time,$no_markup);
203
 
204
        $no_markup =~ s/<[^>]*>//g;
205
 
206
 
207
 
208
 
209
        add_icon_to_tree($self,$name,$target,$no_markup) ;
210
        my $r=$self->object_get_attribute("$name","$param");
211
 
212
        @array = defined ($r)? @{$r}:();
213
        push (@array ,$no_markup);
214
        $self->object_add_attribute("$name","$param",\@array);
215
 
216
 
217
 
218
 
219
 
220
# check if the maximum number of dropped item is received
221
$limit =655350 if(!defined $limit);
222
if( scalar @array >= $limit){
223
    stop_drag_dest( $widget);
224
}
225
 
226
        call_gtk_drag_finish($context, 0, 0, $time);
227
   # $context->finish (0, 0, $time);
228
}
229
 
230
sub source_drag_data_get {
231
#---------------------------------------------------
232
#This sets up the data of the drag source. It is ---
233
#required before the 'drag-data-received' event ----
234
#fires which can be used to extract this data ------
235
#---------------------------------------------------
236
 
237
    my ($widget, $context, $data, $info, $time,$string) = @_;
238
 
239
    $data->set_text($string,-1) if defined $string;
240
    $data->set_text("Unknown-event-name",-1) unless defined $string;
241
 
242
 
243
 
244
}
245
 
246
 
247
 
248
 
249
sub add_icon_to_tree{
250
        my ($self,$name,$list_store,$val)=@_;
251
 
252
    my $icon=$self->object_get_attribute($name,'trace_icon');
253
        my $pixbuf = get_icon_pixbuff ($icon );
254
 
255
 
256
        #if there was a valid icon in the iconset, add it
257
        if( defined $pixbuf ){
258
 
259
            my $iter = $list_store->append;
260
            $list_store->set (
261
                        $iter,
262
                        C_MARKUP, "<b>$val</b>",
263
                        C_PIXBUF, $pixbuf,
264
             );
265
 
266
        }
267
 
268
}
269
 
270
 
271
 
272
 
273
sub stop_drag_dest {
274
        my $widget=shift;
275
        $widget->drag_dest_unset ();
276
}
277
 
278
 
279
sub add_drop_source {
280
        my ($widget,$target,$name,$param,$self,$limit)=@_;
281
 
282
        #Create a target table to receive drops
283
        add_drag_dest_set($widget, 'STRING',[],ID_ICONVIEW);
284
 
285
    #make this the drag destination (drop) for various drag sources
286
    my $r=$self->object_get_attribute("$name","$param");
287
    my    @array = defined ($r)? @{$r}:();
288
 
289
    # check if the maximum number of dropped item is received
290
        $limit =655350 if(!defined $limit);
291
        if( scalar @array >= $limit){
292
            stop_drag_dest( $widget);
293
        }
294
 
295
 
296
    #do a callback as soon as drag data is received
297
    my @params=($target,$name,$param,$self,$limit);
298
    $widget->signal_connect ('drag-data-received' => \&target_drag_data_received,\@params );
299
    $widget->signal_connect ('drag-data-get' => sub {
300
                add_drag_dest_set($widget, 'STRING',[],ID_ICONVIEW);
301
    });
302
 
303
}

powered by: WebSVN 2.1.0

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