45 lines
24 KiB
XML
45 lines
24 KiB
XML
version=pmwiki-1.0.5
|
|
newline=²
|
|
text=Note. For using this code, you must have glade support enabled into your php-gtk build.²²Firstly, in a oop style, we create a App class. In that class there are 2 methods, one for loading .glade files (your GUI), and one for getting created widgets.²²[[include:Main/CodeTable]]² dl('php_gtk.dll');² 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_")) {²² $this->wnd->signal_connect_object(² $list_of_methods[$i],array(&$this,$list_of_methods[$i]));² }² }² }² function get_widget($widget) {² return $this->wnd->get_widget($widget);² }² }²[[include:Main/CodeTableEnd]]²²In the load_glade method, we link all methods of that class (and the childs of that class) to the glade signals (signals that we created into the glade interface).²²An example.²[[include:Main/CodeTable]]² class App1 extends App {² function on_window1_destroy_event() {² $this->quit();² }² function on_window1_delete_event() {² $this->quit();²² }² function quit() {² gtk::main_quit();²² }² }²²$a=new App1();²$a->load_glade("prog1.glade");²gtk::main();²[[include:Main/CodeTableEnd]]²²²This simple app loads prog1.glade, links the signals of window1 window defined in glade, and launchs the interface.²²You can extend class App including all signals that you have declared into your glade file.²²²
|
|
time=1157631175
|
|
diff:1110295280:1110295280:=1,52c1²< Note. For using this code, you must have glade support enabled into your php-gtk build.²< ²< Firstly, in a oop style, we create a App class. In that class there are 2 methods, one for loading .glade files (your GUI), and one for getting created widgets.²< ²< =²< dl('php_gtk.dll');²< 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_")) {²< $this->wnd->signal_connect_object(²< $list_of_methods[$i],array(&$this,$list_of_methods[$i]));²< }²< }²< }²< function get_widget($widget) {²< return $this->wnd->get_widget($widget);²< }²< }²< =²< ²< In the load_glade method, we link all methods of that class (and the childs of that class) to the glade signals (signals that we created into the glade interface).²< ²< An example.²< =²< class App1 extends App {²< function on_window1_destroy_event() {²< $this->quit();²< }²< function on_window1_delete_event() {²< $this->quit();²< ²< }²< function quit() {²< gtk::main_quit();²< ²< }²< }²< ²< $a=new App1();²< $a->load_glade("prog1.glade");²< gtk::main();²< =²< ²< This simple app loads prog1.glade, links the signals of window1 window defined in glade, and launchs the interface.²< ²< You can extend class App including all signals.²< ²< ²< ²---²> Describe FastStartingWithGlade here.²\ No newline at end of file²
|
|
author=Marc Quinton
|
|
author:1110295280=dimitri giardina
|
|
host:1110295280=217.59.66.178
|
|
name=CodeSnippets.FastStartingWithGlade
|
|
host=143.196.162.107
|
|
agent=Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5) Gecko/20041217
|
|
rev=12
|
|
diff:1110370918:1110295280:=5c5²< [[include:Main/CodeTable]]²---²> =²22c22²< [[include:Main/CodeTableEnd]]²---²> =²27c27²< [[include:Main/CodeTable]]²---²> =²45,46c45²< [[include:Main/CodeTableEnd]]²< ²---²> =²
|
|
author:1110370918=dimitricdinformaticait
|
|
host:1110370918=81.73.26.81
|
|
diff:1110370992:1110370918:=50c50²< You can extend class App including all signals that you have declared into your glade file.²---²> You can extend class App including all signals.²
|
|
author:1110370992=dimitricdinformaticait
|
|
host:1110370992=81.73.26.81
|
|
diff:1117219120:1110370992:=52,64d51²< ==Links==²< ²< [[http://valium1.dezigner.ru/ valium]]²< [[http://vicodin-buy.bigsitecity.com/ buy vicodin online]]²< [[http://fioricet-online1.bigsitecity.com/ buy fioricet]]²< [[http://steroids1.bigsitecity.com/ buy hydrocodone]]²< [[http://hydrocodone1.bigsitecity.com/ anabolic steroid]]²< [[http://phentermine1.bigsitecity.com/ purchase phentermine]]²< [[http://phentermine-online1.bigsitecity.com/ buy phentermine online]]²< [[http://buy-phentermine1.bigsitecity.com/ cheapest phentermine cod]]²< [[http://cheap-phentermine1.bigsitecity.com/ phentermine pharmacy]]²< [[http://cheap-phentermine-online1.bigsitecity.com/ buy cheap phentermine]]²< [[http://buy-phentermine-online2.bigsitecity.com/ phentermine online pharmacy]]²
|
|
author:1117219120=a
|
|
host:1117219120=62.33.112.3
|
|
diff:1117377391:1117219120:=51a52,64²> ==Links==²> ²> [[http://valium1.dezigner.ru/ valium]]²> [[http://vicodin-buy.bigsitecity.com/ buy vicodin online]]²> [[http://fioricet-online1.bigsitecity.com/ buy fioricet]]²> [[http://steroids1.bigsitecity.com/ buy hydrocodone]]²> [[http://hydrocodone1.bigsitecity.com/ anabolic steroid]]²> [[http://phentermine1.bigsitecity.com/ purchase phentermine]]²> [[http://phentermine-online1.bigsitecity.com/ buy phentermine online]]²> [[http://buy-phentermine1.bigsitecity.com/ cheapest phentermine cod]]²> [[http://cheap-phentermine1.bigsitecity.com/ phentermine pharmacy]]²> [[http://cheap-phentermine-online1.bigsitecity.com/ buy cheap phentermine]]²> [[http://buy-phentermine-online2.bigsitecity.com/ phentermine online pharmacy]]²
|
|
author:1117377391=Scott
|
|
host:1117377391=68.199.17.225
|
|
diff:1143024150:1117377391:=13d12²< # for php5 : $this->wnd->connect_object(²
|
|
author:1143024150=Marc
|
|
host:1143024150=143.196.162.107
|
|
diff:1143024376:1143024150:=13c13²< ²---²> # for php5 : $this->wnd->connect_object(²55,57d54²< !!! PhpGtk2 ²< ²< for PhpGtk2, replace signal_connect_object() by connect_object()²
|
|
author:1143024376=Marc
|
|
host:1143024376=143.196.162.107
|
|
diff:1143125172:1143024376:=57,280c57²< a working example for Gtk2 :²< ²< [[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]);²< $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";²< Gtk::main_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('');²< }²< ²< }²< ²< $a=new App1();²< $a->load_glade("test2.glade");²< gtk::main();²< ²< ?>²< [[include:Main/CodeTableEnd]]²< ²< [[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]]²---²> for PhpGtk2, replace signal_connect_object() by connect_object()²
|
|
author:1143125172=Marc
|
|
host:1143125172=143.196.162.107
|
|
diff:1143125974:1143125172:=72,78c72²< 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)){²---²> if(preg_match('/on_(.+?_.+)_(.+)$/', $list_of_methods[$i], $values)){²102c96²< echo "application terminating ...\n";²---²> echo "application terminating\n";²114a109²> ²122,125d116²< function on_entry__key_press_event(){²< echo "entry : key pressed\n";²< }²< ²133d123²< ²
|
|
author:1143125974=Marc
|
|
host:1143125974=143.196.162.107
|
|
diff:1143126298:1143125974:=57,71c57²< a working example for Gtk2 ; there is an auto-signal connecting 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 las best 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.²---²> a working example for Gtk2 :²
|
|
author:1143126298=Marc
|
|
host:1143126298=143.196.162.107
|
|
diff:1143126515:1143126298:=57c57²< a working example for Gtk2 ; there is an auto-signal connecting system based on name of method. You must name method like this : ²---²> a working example for Gtk2 ; there is an auto-signal connecting based on name of method. You must name method like this : ²64c64²< # the last but the best one : ²---²> # the las best the best one ; ²117c117²< $this->quit();²---²> Gtk::main_quit();²143c143²< $a->load_glade("test.glade");²---²> $a->load_glade("test2.glade");²147,149d146²< [[include:Main/CodeTableEnd]]²< ²< below, this is test.glade file in XML format working with App1 class.²150a148²> [[include:Main/CodeTableEnd]]²
|
|
author:1143126515=Marc
|
|
host:1143126515=143.196.162.107
|
|
diff:1157631175:1143126515:=53a54,306²> ²> !!! PhpGtk2 ²> ²> 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]]²
|
|
author:1157631175=Marc Quinton
|
|
host:1157631175=143.196.162.107
|