We will introduce this article to you.
Php gtk text viewer code example:
- <? Php
- Require_once ('file. php ');
- If (! Class_exists ('gtk ')){
- If (strtoupper (substr (PHP_ OS, 0, 3) = 'win '))
- Dl ('php _ gtk. dll ');
- Else
- Dl ('php _ gtk. so ');
- 10}
- Function delete_event ()
- {
- Return false;
- }
- Function shutdown ()
- {
- Print ("Shutting down ");
- Gtk: main_quit ();
- }
- Function ButtonLoad_clicked ()
- {
- SelectFile ();
- }
- Function ButtonClose_clicked ()
- {
- Global $ window;
- $ Window->Close ();
- }
- Function fs_ OK ($ button, $ fs)
- {
- Global $ TextBox;
- $ TextBox->Insert_text
(File: readAll ($ fs->Get_filename (), 0 );
- Return true;
- }
- Function fs_Cancel ()
- {
- Return false;
- }
- Function SelectFile ()
- {
- $ Fs = & new GtkFileSelection
('Please select the file ');
- $ OK _button = $ fs->OK _button;
- $ OK _button->Connect ('clicked', 'fs _ OK ', $ fs );
- $ OK _button->Connect_object
('Clicked', array ($ fs, 'deststroy '));
- $ Cancel_button = $ fs->Cancel_button;
- $ Cancel_button->Connect
('Clicked', 'fs _ Cancel ');
- $ Cancel_button->Connect_object
('Clicked', array ($ fs, 'deststroy '));
- $ Fs->Show ();
- }
- $ Window = & new GtkWindow ();
- $ Window->Connect (
'Deststroy', 'shutdown ');
- $ Window->Connect ('delete-event'
, 'Delete _ event ');
- $ Window->Set_border_width (0 );
- $ TextBox = & new GtkText ();
- $ TextBox->Set_editable (true );
- $ ButtonLoad = & new GtkButton ('load ');
- $ ButtonLoad->Connect ('clicked ',
'Buttonload _ clicked ');
- $ ButtonClose = & new GtkButton ('close ');
- $ ButtonClose->Connect ('clicked ',
'Buttonclose _ clicked ');
- $ VBox = & new GtkVBox (false, 10 );
- $ VBox->Pack_start ($ ButtonLoad );
- $ VBox->Pack_start ($ ButtonClose );
- $ HBox = & new GtkHBox (false, 10 );
- $ HBox->Pack_start ($ TextBox );
- $ HBox->Pack_start ($ VBox );
- $ Window->Add ($ HBox );
- $ Window->Show_all ();
- Gtk: main ();
- ?>
The above Code describes how to write a text viewer using php gtk.