phpgtk__legacy/wiki1/wiki.d/CodeSnippets.FastStartingWithGlade2

21 lines
17 KiB
XML

version=pmwiki-1.0.5
newline=²
text=!!! PhpGtk2 Glade sample code²²a working example for Gtk2 ; there is an auto-signal connecting system based on name of method. See App class example. You must name method like this : ²²[[include:Main/CodeTable]]² # 3 possibilities² function on_object_signal(){}² function on_object_name_signal(){}²² # the last but the best one : ² function on_object_name__complex_signal_name()² # complex_signal_name is converted to complex-signal-name for GTK toolkit²²²[[include:Main/CodeTableEnd]]²²here is complet code ; you should separate 2 classes.²²[[include:Main/CodeTable]]²<?php²²error_reporting(E_ALL);²²# library²class GladeApp {²² function load_glade($file) {² $this->wnd=&new GladeXML($file);² $list_of_methods=get_class_methods($this);² for ($i=0;$i<sizeof($list_of_methods);$i++) {² if (strstr($list_of_methods[$i],"on_")) {²² if(preg_match('/on_(.+?)__(.+)$/', $list_of_methods[$i], $values)){² $widget = $this->get_widget($values[1]);² $signal = $values[2];² $signal = str_replace('_', '-', $signal);² $widget->connect_simple($signal, array($this, $list_of_methods[$i]));² }² elseif(preg_match('/on_(.+?_.+)_(.+)$/', $list_of_methods[$i], $values)){² $widget = $this->get_widget($values[1]);² $widget->connect_simple($values[2], array($this, $list_of_methods[$i]));² }²² elseif(preg_match('/on_(.+?)_(.+?)$/', $list_of_methods[$i], $values)){² $widget = $this->get_widget($values[1]);² $widget->connect_simple($values[2], array($this, $list_of_methods[$i]));² }² }² }² }²² function get_widget($widget) {² return $this->wnd->get_widget($widget);² }²}²²# your class application²class App extends GladeApp {²² function quit() {² gtk::main_quit();² }² function on_button_quit_clicked(){² echo "application terminating ...\n";² $this->quit();² }²² function on_button_print_clicked(){² $entry = $this->get_widget('entry');² $txt = $entry->get_text();² if($txt != '')² echo "$txt\n";² else{² $label2 = $this->get_widget('label2');² $label2->set_text('please type some text before');² }² }²² function on_button_delete_clicked(){² $entry = $this->get_widget('entry');² $entry->set_text('');² }²² function on_entry__key_press_event(){² echo "entry : key pressed\n";² }²²}²²$a=new App();²$a->load_glade("test.glade");²gtk::main();²²?>²[[include:Main/CodeTableEnd]]²²below, this is test.glade file in XML format working with App class.²²²[[include:Main/CodeTable]]²<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->²<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">²²<glade-interface>²²<widget class="GtkWindow" id="window">² <property name="visible">True</property>² <property name="title" translatable="yes">window1</property>² <property name="type">GTK_WINDOW_TOPLEVEL</property>² <property name="window_position">GTK_WIN_POS_NONE</property>² <property name="modal">False</property>² <property name="resizable">True</property>² <property name="destroy_with_parent">False</property>² <property name="decorated">True</property>² <property name="skip_taskbar_hint">False</property>² <property name="skip_pager_hint">False</property>² <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>² <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>² <property name="focus_on_map">True</property>²² <child>² <widget class="GtkFixed" id="fixed1">² <property name="visible">True</property>²² <child>² <widget class="GtkEntry" id="entry">² <property name="width_request">216</property>² <property name="height_request">32</property>² <property name="visible">True</property>² <property name="can_focus">True</property>² <property name="editable">True</property>² <property name="visibility">True</property>² <property name="max_length">0</property>² <property name="text" translatable="yes"></property>² <property name="has_frame">True</property>² <property name="invisible_char">*</property>² <property name="activates_default">False</property>² </widget>² <packing>² <property name="x">152</property>² <property name="y">112</property>² </packing>² </child>²² <child>² <widget class="GtkButton" id="button_print">² <property name="width_request">58</property>² <property name="height_request">27</property>² <property name="visible">True</property>² <property name="can_focus">True</property>² <property name="label" translatable="yes">Print</property>² <property name="use_underline">True</property>² <property name="relief">GTK_RELIEF_NORMAL</property>² <property name="focus_on_click">True</property>² </widget>² <packing>² <property name="x">40</property>² <property name="y">96</property>² </packing>² </child>²² <child>² <widget class="GtkLabel" id="label1">² <property name="width_request">224</property>² <property name="height_request">40</property>² <property name="visible">True</property>² <property name="label" translatable="yes">write some text here²and press a button²</property>² <property name="use_underline">False</property>² <property name="use_markup">False</property>² <property name="justify">GTK_JUSTIFY_LEFT</property>² <property name="wrap">False</property>² <property name="selectable">False</property>² <property name="xalign">0.5</property>² <property name="yalign">0.5</property>² <property name="xpad">0</property>² <property name="ypad">0</property>² <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>² <property name="width_chars">-1</property>² <property name="single_line_mode">False</property>² <property name="angle">0</property>² </widget>² <packing>² <property name="x">152</property>² <property name="y">64</property>² </packing>² </child>²² <child>² <widget class="GtkButton" id="button_delete">² <property name="width_request">58</property>² <property name="height_request">27</property>² <property name="visible">True</property>² <property name="can_focus">True</property>² <property name="label" translatable="yes">Delete</property>² <property name="use_underline">True</property>² <property name="relief">GTK_RELIEF_NORMAL</property>² <property name="focus_on_click">True</property>² </widget>² <packing>² <property name="x">40</property>² <property name="y">128</property>² </packing>² </child>²² <child>² <widget class="GtkButton" id="button_quit">² <property name="width_request">58</property>² <property name="height_request">27</property>² <property name="visible">True</property>² <property name="can_focus">True</property>² <property name="label" translatable="yes">Quit</property>² <property name="use_underline">True</property>² <property name="relief">GTK_RELIEF_NORMAL</property>² <property name="focus_on_click">True</property>² </widget>² <packing>² <property name="x">40</property>² <property name="y">200</property>² </packing>² </child>²² <child>² <widget class="GtkLabel" id="label2">² <property name="width_request">216</property>² <property name="height_request">136</property>² <property name="visible">True</property>² <property name="label" translatable="yes">label2</property>² <property name="use_underline">False</property>² <property name="use_markup">False</property>² <property name="justify">GTK_JUSTIFY_LEFT</property>² <property name="wrap">False</property>² <property name="selectable">False</property>² <property name="xalign">0.5</property>² <property name="yalign">0.5</property>² <property name="xpad">0</property>² <property name="ypad">0</property>² <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>² <property name="width_chars">-1</property>² <property name="single_line_mode">False</property>² <property name="angle">0</property>² </widget>² <packing>² <property name="x">152</property>² <property name="y">160</property>² </packing>² </child>² </widget>² </child>²</widget>²²</glade-interface>²[[include:Main/CodeTableEnd]]²
time=1157658648
diff:1157630961:1157630961:=1,253c1²< ²< !!! PhpGtk2 Glade sample code²< ²< a working example for Gtk2 ; there is an auto-signal connecting system based on name of method. You must name method like this : ²< ²< [[include:Main/CodeTable]]²< # 3 possibilities²< function on_object_signal(){}²< function on_object_name_signal(){}²< ²< # the last but the best one : ²< function on_object_name__complex_signal_name()²< # complex_signal_name is converted to complex-signal-name for GTK toolkit²< ²< ²< [[include:Main/CodeTableEnd]]²< ²< here is complet code ; you should separate 2 classes.²< ²< [[include:Main/CodeTable]]²< <?php²< ²< error_reporting(E_ALL);²< ²< class App {²< ²< function load_glade($file) {²< $this->wnd=&new GladeXML($file);²< $list_of_methods=get_class_methods($this);²< for ($i=0;$i<sizeof($list_of_methods);$i++) {²< if (strstr($list_of_methods[$i],"on_")) {²< ²< if(preg_match('/on_(.+?)__(.+)$/', $list_of_methods[$i], $values)){²< $widget = $this->get_widget($values[1]);²< $signal = $values[2];²< $signal = str_replace('_', '-', $signal);²< $widget->connect_simple($signal, array($this, $list_of_methods[$i]));²<< elseif(preg_match('/on_(.+?_.+)_(.+)$/', $list_of_methods[$i], $values)){²< $widget = $this->get_widget($values[1]);²< $widget->connect_simple($values[2], array($this, $list_of_methods[$i]));²<< ²< elseif(preg_match('/on_(.+?)_(.+?)$/', $list_of_methods[$i], $values)){²< $widget = $this->get_widget($values[1]);²< $widget->connect_simple($values[2], array($this, $list_of_methods[$i]));²<<<<< ²< function get_widget($widget) {²< return $this->wnd->get_widget($widget);²<<< ²< class App1 extends App {²< ²< function quit() {²< gtk::main_quit();²< }²< function on_button_quit_clicked(){²< echo "application terminating ...\n";²< $this->quit();²<< ²< function on_button_print_clicked(){²< $entry = $this->get_widget('entry');²< $txt = $entry->get_text();²< if($txt != '')²< echo "$txt\n";²< else{²< $label2 = $this->get_widget('label2');²< $label2->set_text('please type some text before');²<<< ²< function on_button_delete_clicked(){²< $entry = $this->get_widget('entry');²< $entry->set_text('');²<< ²< function on_entry__key_press_event(){²< echo "entry : key pressed\n";²< }²< ²< }²< ²< $a=new App1();²< $a->load_glade("test.glade");²< gtk::main();²< ²< ?>²< [[include:Main/CodeTableEnd]]²< ²< below, this is test.glade file in XML format working with App1 class.²< ²< ²< [[include:Main/CodeTable]]²< <?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->²< <!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">²< ²< <glade-interface>²< ²< <widget class="GtkWindow" id="window">²< <property name="visible">True</property>²< <property name="title" translatable="yes">window1</property>²< <property name="type">GTK_WINDOW_TOPLEVEL</property>²< <property name="window_position">GTK_WIN_POS_NONE</property>²< <property name="modal">False</property>²< <property name="resizable">True</property>²< <property name="destroy_with_parent">False</property>²< <property name="decorated">True</property>²< <property name="skip_taskbar_hint">False</property>²< <property name="skip_pager_hint">False</property>²< <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>²< <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>²< <property name="focus_on_map">True</property>²< ²< <child>²< <widget class="GtkFixed" id="fixed1">²< <property name="visible">True</property>²< ²< <child>²< <widget class="GtkEntry" id="entry">²< <property name="width_request">216</property>²< <property name="height_request">32</property>²< <property name="visible">True</property>²< <property name="can_focus">True</property>²< <property name="editable">True</property>²< <property name="visibility">True</property>²< <property name="max_length">0</property>²< <property name="text" translatable="yes"></property>²< <property name="has_frame">True</property>²< <property name="invisible_char">*</property>²< <property name="activates_default">False</property>²< </widget>²< <packing>²< <property name="x">152</property>²< <property name="y">112</property>²< </packing>²< </child>²< ²< <child>²< <widget class="GtkButton" id="button_print">²< <property name="width_request">58</property>²< <property name="height_request">27</property>²< <property name="visible">True</property>²< <property name="can_focus">True</property>²< <property name="label" translatable="yes">Print</property>²< <property name="use_underline">True</property>²< <property name="relief">GTK_RELIEF_NORMAL</property>²< <property name="focus_on_click">True</property>²< </widget>²< <packing>²< <property name="x">40</property>²< <property name="y">96</property>²< </packing>²< </child>²< ²< <child>²< <widget class="GtkLabel" id="label1">²< <property name="width_request">224</property>²< <property name="height_request">40</property>²< <property name="visible">True</property>²< <property name="label" translatable="yes">write some text here²< and press a button²< </property>²< <property name="use_underline">False</property>²< <property name="use_markup">False</property>²< <property name="justify">GTK_JUSTIFY_LEFT</property>²< <property name="wrap">False</property>²< <property name="selectable">False</property>²< <property name="xalign">0.5</property>²< <property name="yalign">0.5</property>²< <property name="xpad">0</property>²< <property name="ypad">0</property>²< <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>²< <property name="width_chars">-1</property>²< <property name="single_line_mode">False</property>²< <property name="angle">0</property>²< </widget>²< <packing>²< <property name="x">152</property>²< <property name="y">64</property>²< </packing>²< </child>²< ²< <child>²< <widget class="GtkButton" id="button_delete">²< <property name="width_request">58</property>²< <property name="height_request">27</property>²< <property name="visible">True</property>²< <property name="can_focus">True</property>²< <property name="label" translatable="yes">Delete</property>²< <property name="use_underline">True</property>²< <property name="relief">GTK_RELIEF_NORMAL</property>²< <property name="focus_on_click">True</property>²< </widget>²< <packing>²< <property name="x">40</property>²< <property name="y">128</property>²< </packing>²< </child>²< ²< <child>²< <widget class="GtkButton" id="button_quit">²< <property name="width_request">58</property>²< <property name="height_request">27</property>²< <property name="visible">True</property>²< <property name="can_focus">True</property>²< <property name="label" translatable="yes">Quit</property>²< <property name="use_underline">True</property>²< <property name="relief">GTK_RELIEF_NORMAL</property>²< <property name="focus_on_click">True</property>²< </widget>²< <packing>²< <property name="x">40</property>²< <property name="y">200</property>²< </packing>²< </child>²< ²< <child>²< <widget class="GtkLabel" id="label2">²< <property name="width_request">216</property>²< <property name="height_request">136</property>²< <property name="visible">True</property>²< <property name="label" translatable="yes">label2</property>²< <property name="use_underline">False</property>²< <property name="use_markup">False</property>²< <property name="justify">GTK_JUSTIFY_LEFT</property>²< <property name="wrap">False</property>²< <property name="selectable">False</property>²< <property name="xalign">0.5</property>²< <property name="yalign">0.5</property>²< <property name="xpad">0</property>²< <property name="ypad">0</property>²< <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>²< <property name="width_chars">-1</property>²< <property name="single_line_mode">False</property>²< <property name="angle">0</property>²< </widget>²< <packing>²< <property name="x">152</property>²< <property name="y">160</property>²< </packing>²< </child>²< </widget>²< </child>²< </widget>²< ²< </glade-interface>²< [[include:Main/CodeTableEnd]]²---²> Describe FastStartingWithGlade2 here.²\ No newline at end of file²
author=Marc Quinton
author:1157630961=Marc Quinton
host:1157630961=143.196.162.107
name=CodeSnippets.FastStartingWithGlade2
host=82.234.62.122
agent=Mozilla/5.0 (X11; U; Linux i686; fr-FR; rv:1.7.12) Gecko/20060216 Debian/1.7.12-1.1ubuntu2
rev=4
diff:1157631078:1157630961:=0a1²> ²3c4²< a working example for Gtk2 ; there is an auto-signal connecting system based on name of method. See App class example. You must name method like this : ²---²> a working example for Gtk2 ; there is an auto-signal connecting system based on name of method. You must name method like this : ²24c25²< class GladeApp {²---²> class App {²56c57²< class App extends GladeApp {²---²> class App1 extends App {²95c96²< below, this is test.glade file in XML format working with App class.²---²> below, this is test.glade file in XML format working with App1 class.²
author:1157631078=Marc Quinton
host:1157631078=143.196.162.107
diff:1157658352:1157631078:=88c88²< $a=new App();²---²> $a=new App1();²
author:1157658352=Marc Quinton
host:1157658352=82.234.62.122
diff:1157658648:1157658352:=24d23²< # library²57d55²< # your class application²
author:1157658648=Marc Quinton
host:1157658648=82.234.62.122