![phppad1.JPG](https://i-blog.csdnimg.cn/blog_migrate/5410162c36b239545d8a05bfdd44e92f.jpeg)
![phppad2.JPG](https://i-blog.csdnimg.cn/blog_migrate/3c1d95db82735164fa6dd5667eb70d1a.jpeg)
1
<?
php
2
3 require_once( ' File.php ' );
4
5 if ( ! class_exists( ' gtk ' )) {
6 if (strtoupper(substr(PHP_OS, 0 , 3 ) == ' WIN ' ))
7 dl( ' php_gtk.dll ' );
8 else
9 dl( ' php_gtk.so ' );
10 }
11
12 function delete_event()
13 {
14 return false ;
15 }
16
17 function shutdown()
18 {
19 print( " Shutting down " );
20 gtk::main_quit();
21 }
22
23 function ButtonLoad_clicked()
24 {
25 SelectFile();
26 }
27
28 function ButtonClose_clicked()
29 {
30 global $window;
31 $window -> close();
32 }
33
34 function fs_OK($button, $fs)
35 {
36 global $TextBox;
37 $TextBox -> insert_text(File::readAll($fs -> get_filename()), 0 );
38 return true ;
39 }
40
41 function fs_Cancel()
42 {
43 return false ;
44 }
45
46 function SelectFile()
47 {
48 $fs = & new GtkFileSelection( ' Please select the file ' );
49 $ok_button = $fs -> ok_button;
50 $ok_button -> connect( ' clicked ' , ' fs_OK ' , $fs);
51 $ok_button -> connect_object( ' clicked ' , array($fs, ' destroy ' ));
52 $cancel_button = $fs -> cancel_button;
53 $cancel_button -> connect( ' clicked ' , ' fs_Cancel ' );
54 $cancel_button -> connect_object( ' clicked ' , array($fs, ' destroy ' ));
55 $fs -> show();
56 }
57 $window = & new GtkWindow();
58 $window -> connect( ' destroy ' , ' shutdown ' );
59 $window -> connect( ' delete-event ' , ' delete_event ' );
60 $window -> set_border_width( 0 );
61
62 $TextBox = & new GtkText();
63 $TextBox -> set_editable( true );
64
65 $ButtonLoad = & new GtkButton( ' Load ' );
66 $ButtonLoad -> connect( ' clicked ' , ' ButtonLoad_clicked ' );
67
68 $ButtonClose = & new GtkButton( ' Close ' );
69 $ButtonClose -> connect( ' clicked ' , ' ButtonClose_clicked ' );
70
71 $VBox = & new GtkVBox( false , 10 );
72 $VBox -> pack_start($ButtonLoad);
73 $VBox -> pack_start($ButtonClose);
74
75 $HBox = & new GtkHBox( false , 10 );
76 $HBox -> pack_start($TextBox);
77 $HBox -> pack_start($VBox);
78
79 $window -> add($HBox);
80
81 $window -> show_all();
82
83 gtk::main();
84
85 ?>
2
3 require_once( ' File.php ' );
4
5 if ( ! class_exists( ' gtk ' )) {
6 if (strtoupper(substr(PHP_OS, 0 , 3 ) == ' WIN ' ))
7 dl( ' php_gtk.dll ' );
8 else
9 dl( ' php_gtk.so ' );
10 }
11
12 function delete_event()
13 {
14 return false ;
15 }
16
17 function shutdown()
18 {
19 print( " Shutting down " );
20 gtk::main_quit();
21 }
22
23 function ButtonLoad_clicked()
24 {
25 SelectFile();
26 }
27
28 function ButtonClose_clicked()
29 {
30 global $window;
31 $window -> close();
32 }
33
34 function fs_OK($button, $fs)
35 {
36 global $TextBox;
37 $TextBox -> insert_text(File::readAll($fs -> get_filename()), 0 );
38 return true ;
39 }
40
41 function fs_Cancel()
42 {
43 return false ;
44 }
45
46 function SelectFile()
47 {
48 $fs = & new GtkFileSelection( ' Please select the file ' );
49 $ok_button = $fs -> ok_button;
50 $ok_button -> connect( ' clicked ' , ' fs_OK ' , $fs);
51 $ok_button -> connect_object( ' clicked ' , array($fs, ' destroy ' ));
52 $cancel_button = $fs -> cancel_button;
53 $cancel_button -> connect( ' clicked ' , ' fs_Cancel ' );
54 $cancel_button -> connect_object( ' clicked ' , array($fs, ' destroy ' ));
55 $fs -> show();
56 }
57 $window = & new GtkWindow();
58 $window -> connect( ' destroy ' , ' shutdown ' );
59 $window -> connect( ' delete-event ' , ' delete_event ' );
60 $window -> set_border_width( 0 );
61
62 $TextBox = & new GtkText();
63 $TextBox -> set_editable( true );
64
65 $ButtonLoad = & new GtkButton( ' Load ' );
66 $ButtonLoad -> connect( ' clicked ' , ' ButtonLoad_clicked ' );
67
68 $ButtonClose = & new GtkButton( ' Close ' );
69 $ButtonClose -> connect( ' clicked ' , ' ButtonClose_clicked ' );
70
71 $VBox = & new GtkVBox( false , 10 );
72 $VBox -> pack_start($ButtonLoad);
73 $VBox -> pack_start($ButtonClose);
74
75 $HBox = & new GtkHBox( false , 10 );
76 $HBox -> pack_start($TextBox);
77 $HBox -> pack_start($VBox);
78
79 $window -> add($HBox);
80
81 $window -> show_all();
82
83 gtk::main();
84
85 ?>