Write text viewer with PHP-GTK

Source: Internet
Author: User
A simple study of a few examples of PHP-GTK, flip the instructions, with handwriting such a little thing to play. Click load to open the dialog box and select a file. The content of the selected file is displayed in the text box. You are too lazy to adjust the location and size, so the interface is very ugly. Show two images first, followed Program .

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 ?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.