用PHP-GTK寫文本查看器

來源:互聯網
上載者:User
簡單研究了幾個PHP-GTK的例子、翻了翻說明,隨手寫這麼個小玩意玩玩。點LOAD開啟對話方塊選擇檔案,則被選擇檔案的內容就會顯示在文字框中。懶得去調整位置和大小,所以介面醜陋無比,大家將就。先SHOW兩張圖,後面是程式。

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.