Thread FileChooserButton (2 answers)
Opened by Andreas at 2012-03-05 22:28

topeg
 2012-03-05 23:16
#156644 #156644
User since
2006-07-10
2611 articles
BenutzerIn

user image
Gtk2::FileChooserButton implementiert das Interface FileChooser und kann damit auch alle Methoden.

Beispiel:
test.glade
more (2.4kb):
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?xml version="1.0"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkWindow" id="mainwin">
<signal name="destroy" handler="on_exit"/>
<signal name="destroy_event" handler="on_exit"/>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkFileChooserButton" id="My_File_Choose">
<property name="visible">True</property>
<signal name="file_set" handler="on_file_set"/>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="b_test">
<property name="label" translatable="yes">TEST</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_test"/>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/perl
use strict;
use warnings;
use Gtk2 '-init';
use Data::Dumper;
use FindBin '$Bin';

my $glade_file=$Bin.'/test.glade';

my $builder=Gtk2::Builder->new();
$builder->add_from_file($glade_file);
$builder->connect_signals();
chooser_button()->set_current_folder($Bin);

$builder->get_object('mainwin')->show_all();
Gtk2->main();

########################################################################
########################################################################

sub chooser_button { return $builder->get_object('My_File_Choose'); }

sub on_exit { Gtk2->main_quit; }

sub on_test { print chooser_button()->get_filename()."\n"; }

sub on_file_set
{
  my $chooser=shift;
  my $name=$chooser->get_filename();
  print "Choosen $name\n";
}

View full thread FileChooserButton