} { Upload Photo } |
58 | | 0000 of 0000 |
59 | | www.theplantlist.org wikipedia.org |
60 | +-------------------------------------------+
61 | END
62 |
63 | my $backend=$ARGV[0]?$ARGV[0]:"tk";
64 | my $assist=$ARGV[1]?$ARGV[1]:"q";
65 | my $gui=GUIDeFATE->new($window,$backend,$assist);
66 | my $frame=$gui->getFrame()||$gui;
67 |
68 | loadGenera();
69 | searchGenera();
70 |
71 | $frame->setLabel("stattext1",$dateString);
72 |
73 | $gui->MainLoop();
74 |
75 | sub btn0 {#called using button with label Refresh Data
76 | createGeneraList();
77 | updateCounts();
78 | };
79 |
80 | sub btn2 {#called using button with label Search
81 | $currentSearch=$frame->getValue("textctrl3");
82 | searchGenera();
83 | };
84 |
85 | sub textctrl3 {#called using Text Control with default text '
86 | };
87 |
88 | sub btn4 {#called using button with label Angiosperms
89 | searchGenera("A");
90 | };
91 |
92 | sub btn5 {#called using button with label Gymnosperms
93 | searchGenera("G");
94 | };
95 |
96 | sub btn8 {#called using button with label Pteridophytes
97 | searchGenera("P");
98 | };
99 |
100 | sub btn9 {#called using button with label Bryophytes
101 | searchGenera("B");
102 | };
103 |
104 | sub btn18 {#called using button with label <
105 | prevItem();
106 | };
107 |
108 | sub btn19 {#called using button with label Explore
109 | if ($currentContext!~/Species/){
110 | createSpeciesList();
111 | }
112 | else {
113 | @results=@genusList;
114 | $currentItem=$currentGenus;
115 | $currentContext=$oldContext;
116 | updateView();
117 | }
118 | };
119 |
120 | sub btn20 {#called using button with label >
121 | nextItem();
122 | };
123 |
124 | sub btn21 {#called using button with label Wikipedia
125 |
126 | };
127 |
128 | sub createGeneraList{
129 | my $url='http://www.theplantlist.org/1.1/browse/-/-/';
130 | my $content = get $url;
131 | $dateString="Data from: $day/$month/$year";
132 | my @lines=split(/\n/, $content);
133 | @genera=();
134 | foreach my $line (@lines){
135 | if ($line=~/3){ push @genera, $line;}
139 | }
140 | }
141 | open my $fh, '>', "$dataFolder/genera.csv";
142 | print $fh $dateString."\n";
143 | print $fh join("\n",@genera);
144 | close $fh;
145 | }
146 |
147 | sub loadGenera{
148 | if (! -e "$dataFolder/genera.csv"){
149 | createGeneraList();
150 | }
151 | else {
152 | @genera=();
153 | open my $fh, "$dataFolder/genera.csv" or die "Couldn't open file: $!";
154 | $dateString = <$fh>;
155 | while (<$fh>){
156 | push @genera,$_;
157 | $groups{substr($_, 0, 1)}{filtered}++;
158 | }
159 | close $fh;
160 | chomp $dateString;
161 | }
162 | }
163 |
164 | sub createSpeciesList{
165 | my ($group,$family,$genus,$accepted)=split(',', $genera[$results[$currentItem]]);
166 | my $url="http://www.theplantlist.org/1.1/browse/$group/$family/$genus/";
167 |
168 | @genusList=@results;
169 | $currentGenus=$currentItem;
170 |
171 | @results=();
172 | @speciesList=();
173 | my $content = get $url;
174 | my @lines=split(/([^<]*); my $species=$1;
183 | $tmp=~/"authorship">([^<]*); my $authorship=$1;
184 | push @speciesList, join(',', ($group,$family,$genus,$species,$authorship,$record,$status))
185 | }
186 | }
187 | $currentContext="Species in genus $genus";
188 | $currentItem=0;
189 | @results=(0..$#speciesList);
190 | updateView();
191 | }
192 |
193 | sub nextItem{
194 | my $items=scalar @results;
195 | if ($currentItem<($items-1) ){
196 | $currentItem++;
197 | updateView();
198 | }
199 | }
200 |
201 | sub prevItem{
202 | my $items=scalar @results;
203 | if ($currentItem>(0) ){
204 | $currentItem--;
205 | updateView();
206 | }
207 | }
208 |
209 | sub searchGenera{
210 | my $grpFilter=shift; #search string
211 |
212 | $currentContext=((!$currentSearch ||($currentSearch eq ""))?"Unfiltered Search":"Filtered Search").
213 | ($grpFilter?" (".$groups{$grpFilter}{name}.")":'');
214 | $oldContext=$currentContext;
215 | @results=();
216 | foreach (qw/A B G P/){ # clear old counters
217 | $groups{$_}{filtered}=0;
218 | }
219 | for (my $c=0;$c<=$#genera;$c++){
220 | my ($group,$family,$genus,$accepted)=split(',', $genera[$c]);
221 | if ((!$currentSearch ||($currentSearch eq "")) || (($family =~/\Q$currentSearch\E/i)||($genus =~/\Q$currentSearch\E/i))){
222 | $groups{$group}{filtered}+=1;
223 | if (!$grpFilter || (($grpFilter)&&($group eq $grpFilter))){
224 | push @results,$c;
225 | }
226 | }
227 | }
228 | if (! scalar @results){
229 | @results=(0..$#genera);
230 | }
231 | $currentGenus=$results[0];
232 | $currentItem=0;
233 | updateCounts();
234 | updateView();
235 | }
236 |
237 | sub updateCounts{
238 | foreach (qw/A B G P/){
239 | $frame->setLabel($groups{$_}{widget},$groups{$_}{filtered});
240 | }
241 | }
242 |
243 | sub updateView{
244 | my ($view,$image);
245 | $frame->setLabel("stattext12",$currentContext);
246 | if ($currentContext =~/Species/){
247 | my ($group,$family,$genus,$species,$authorship,$record,$status)=split(',', $speciesList[$currentItem]);
248 | $view= "Group: - ".$groups{$group}{name} ."\n".
249 | "Family: - ".$family."\n".
250 | "Genus: - ".$genus."\n".
251 | "Species: - ".$species."\n".
252 | "Authorship:- ".$authorship."\n".
253 | "Record: - ".$record."\n".
254 | "Status: - ".(($status eq "A")?"Accepted":"Unresolved");
255 | $image=searchImage($status,$genus,$species)
256 |
257 | }
258 | else {
259 | my ($group,$family,$genus,$accepted)=split(',', $genera[$results[$currentItem]]) ;
260 | $view= "Group: - ".$groups{$group}{name} ."\n".
261 | "Family: - ".$family."\n".
262 | "Genus: - ".$genus."\n".
263 | "Status: - ".(($accepted eq "A")?"Accepted":"Unresolved");
264 | $image= searchImage($accepted,$genus,undef);
265 | }
266 |
267 | $frame->setImage("Image15",$image);
268 | $frame->setValue("TextCtrl14",$view);
269 | $frame->setLabel('stattext22',($currentItem+1) ." of ".($#results+1) );
270 | }
271 |
272 | sub searchImage{ # looks for an image for the particular viewed item
273 | my ($status,$genus,$species)=@_;
274 | my @files; my $image;
275 | if ($status eq "A"){ # if the iitem is accepted bother to look for picture
276 | if ($species){
277 | @files = glob( $imageFolder . "/$genus".'_'."$species.*" );
278 | $image= (scalar @files) ? $files[0] : downloadImageFromWiki($genus.'_'.$species);
279 | }
280 | else {
281 | @files = glob( $imageFolder . "/$genus.*" ); }
282 | $image= (scalar @files) ? $files[0] : downloadImageFromWiki($genus);
283 | }
284 | else {
285 | $image=$imageFolder . '/unresolved.png'; # otherwise show an unresolved picture
286 | }
287 |
288 | return $image;
289 |
290 | sub downloadImageFromWiki{
291 | my $pageName=shift;
292 | my $imagePath=$imageFolder."/noImage.png";
293 | my $url="https://en.wikipedia.org/wiki/$pageName";
294 | my $content = get $url;
295 | if ((defined $content)&&($content =~/]*>/, $content)[1];
297 | $infoTable=( split /<\/table/, $infoTable )[0];
298 | if ($infoTable=~/class="image">( ]*>)/){
299 | my $imgSrc=$1;
300 | $imgSrc=~/src="([^"]*\.(png|jpg|gif|bmp))"/;
301 | $imgSrc='http:'.$1;
302 | $imagePath=$imageFolder."/".$pageName.".$2";
303 | getstore($imgSrc, $imagePath);
304 | }
305 | }
306 | return $imagePath;
307 |
308 | }
309 | }
310 |
--------------------------------------------------------------------------------
/lib/GUIDeFATE/GFhtml.pm:
--------------------------------------------------------------------------------
1 | package GFhtml;
2 | use strict;
3 | use warnings;
4 |
5 | our $VERSION = '0.14';
6 |
7 | use Exporter 'import';
8 | our @EXPORT = qw;
9 | our $frame;
10 |
11 | our $winX=30;
12 | our $winY=30;
13 | our $winWidth;
14 | our $winHeight;
15 | our $winTitle="title";
16 | our $winScale=6.5;
17 |
18 | # these arrays will contain the widgets each as an arrayref of the parameters
19 | my @widgets=();
20 | my %iVars=(); #vars for interface operation (e.g.
21 | my %oVars=(); #vars for interface creation (e.g. list of options)
22 | my %styles;
23 |
24 | my $lastMenuLabel; #bug workaround in menu generator may be needed for submenus
25 |
26 | sub new
27 | {
28 | my $class = shift;
29 | my $self={};
30 | bless( $self, $class );
31 | $self->{header}=header();
32 | $self->{header}.="$winTitle $0 \n";
33 | $self->{content}="\n";
34 | setupContent($self,$self->{content});
35 |
36 | $self->{html}=$self->{header};
37 | $self->{html}.="\n\n\n".
38 | "\n".
39 | "\n\n";
40 | $self->{html}.=$self->{content};
41 | if ($self->{menubar}){ $self->{html}.= $self->{menubar} . "\n \n";}
42 | $self->{html}.= " \n\n |