用PHP-GTK写文本查看器

简单研究了几个PHP-GTK的例子、翻了翻说明,随手写这么个小玩意玩玩。点LOAD打开对话框选择文件,则被选择文件的内容就会显示在文本框中。懒得去调整位置和大小,所以界面丑陋无比,大家将就。先SHOW两张图,后面是程序。
phppad1.JPG

phppad2.JPG
 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  ?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值