Changes between Version 4 and Version 5 of waue/2010/0510


Ignore:
Timestamp:
May 10, 2010, 6:23:52 PM (14 years ago)
Author:
waue
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • waue/2010/0510

    v4 v5  
    1414
    1515 = 心得 =
     16 * pygtk+ 的程式架構為 程式邏輯 與 圖形介面 分成兩個不同的檔
     17   * 程式邏輯 : python檔 (xx.py)
     18   * 圖形介面 : 可藉由 glade3輔助來產生圖形layout 的xml格式檔,共可分兩種
     19     *  xx.glade = 使用 libglade 函式庫
     20     *  xx.xml =  使用 gtkbuilder 函式庫
     21 == glade3 畫面 ==
     22 [[Image(http://www.micahcarrick.com/mc_images/gtk-glade-tutorial/glade-3-tutorial-1.jpg,width=600)]]
     23 * inspector 展現 editor 端完整的階層架構
     24 * properties 所展現的'''XXX'''元件屬性可以到 http://www.pygtk.org/docs/pygtk/class-'''XXX'''.html 看更詳細的說明
     25   * 如 button 按鈕元件的properties所列出可以設定的值,可到 http://www.pygtk.org/docs/pygtk/class-gtkbutton.html 來看
     26 == gtk 手冊導讀 ==
     27 http://www.pygtk.org/docs/pygtk/ 中 class-'''XXX'''.html 說明
    1628
    17  [[Image(http://www.micahcarrick.com/mc_images/gtk-glade-tutorial/glade-3-tutorial-1.jpg)]]
     29   * Synopsis & Methods : Synopsis 列出此 XXX 物件可用的 Methods,而這些function 則是透過 py 檔,用來改變屬性值或驅動動作的方法
     30   * Ancestry :類別的繼承關係
     31   * Properties & Style Properties :glade 中 properties 部份的 前三個tag 所定義的屬性
     32   * Signals & Signal Prototypes: 驅動訊號,此部份的說明等同於glade 中 "properties  -> 訊號 "  的地方。
    1833
     34 =  Exam 1 =
     35
     36 http://www.pygtk.org/docs/pygtk/class-gtkbutton.html
     37
     38{{{
     39#!python
     40
     41#!/usr/bin/env python
     42import gtk
     43import gtk.glade
     44class calc:
     45    def __init__(self):
     46        # 在 py 檔中 導入glade
     47        self.glade_file = "calc.glade" 
     48        self.main_window = gtk.glade.XML(self.glade_file)
     49        self.window = self.main_window.get_widget ("calc_window")
     50        # 建立處理訊號常數的字典
     51        events_dic = {
     52                      "haha":self.handle_haha_show,
     53                      "yaya":self.handle_yaya_show,
     54                      "on_button4_clicked":self.handle_4_clicked,
     55                      }
     56        # 連接圖形介面與訊號常數
     57        self.main_window.signal_autoconnect(events_dic)
     58
     59        # 取得 widget 視窗的元件
     60        self.entry1 = self.main_window.get_widget("entry1") # entry1 為計算機鍵盤下方的元件名稱
     61        self.entry_res = self.main_window.get_widget("entry_result") # entry_res 為計算機鍵盤上方的元件名稱
     62       
     63        # 顯示
     64        self.window.show()              # 顯示圖形
     65       
     66    # 定義按鈕驅動函數
     67       
     68    def handle_haha_show(self, widget):
     69       self.entry1.set_text('yaya')
     70       self.entry1.set_text('yaya')
     71    def handle_yaya_show(self, widget):
     72       self.entry1.set_text('haha')
     73       self.entry1.set_text('haha')
     74    def on_button4_clicked(self, widget):
     75       self.entry_res.set_text('4')
     76
     77if __name__ == '__main__':
     78    calc()                   
     79    gtk.main()               
     80
     81}}}
    1982
    2083= 好用連結 =