svn: /gtk/php-gtk-doc/trunk/ examples/reference/gobject/register_type_properties.php examples/reference/gobject/register_type_signals.php manual/en/reference/gobject.xml

View: New views
1 Messages — Rating Filter:   Alert me  

svn: /gtk/php-gtk-doc/trunk/ examples/reference/gobject/register_type_properties.php examples/reference/gobject/register_type_signals.php manual/en/reference/gobject.xml

by auroraeosrose :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

auroraeosrose                            Mon, 05 Oct 2009 19:59:25 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=289232

Log:
Missing Gobject functions - and examples for custom signals and properties with gobject - note emit_stop_by_name is not documented - it's just an alias for stop_emission

Changed paths:
    A   gtk/php-gtk-doc/trunk/examples/reference/gobject/register_type_properties.php
    A   gtk/php-gtk-doc/trunk/examples/reference/gobject/register_type_signals.php
    U   gtk/php-gtk-doc/trunk/manual/en/reference/gobject.xml



Added: gtk/php-gtk-doc/trunk/examples/reference/gobject/register_type_properties.php
===================================================================
--- gtk/php-gtk-doc/trunk/examples/reference/gobject/register_type_properties.php                        (rev 0)
+++ gtk/php-gtk-doc/trunk/examples/reference/gobject/register_type_properties.php 2009-10-05 19:59:25 UTC (rev 289232)
@@ -0,0 +1,73 @@
+<?php
+/* Extend GObject or a child of GObject */
+class NewType extends GtkLabel {
+    /* Define our properties.  The format is property name => array(property type, nick name for the property,
+      description of the property, how the property can be accessed, default property value)
+      If you use default values, they must match the type assigned to the property
+    NOTE: this MUST be PUBLIC - after instatiation php-gtk will unset this property for you, so it will not exist
+    in your object after creation */
+    public $__gproperties = array(
+            'foo' => array(GObject::TYPE_STRING,  'foo property', 'new foo property', GObject::PARAM_READWRITE, 'default foo value'),
+            'bar' => array(GObject::TYPE_OBJECT,  'bar property', 'new bar property', GObject::PARAM_READWRITE),
+            'zoo' => array(GObject::TYPE_BOOLEAN, 'zoo property', 'new zoo property', GObject::PARAM_READABLE, 0),
+            );
+    private $foo;
+    private $bar;
+    private $zoo = 1;
+
+    function __construct()
+    {
+            parent::__construct();
+            $this->foo = 'abcdef';
+    }
+
+    function __get_gproperty($spec)
+    {
+            echo "__get_gproperty called for $spec\n";
+            if ($spec->name == 'foo') {
+                    return $this->foo;
+            } else if ($spec->name == 'bar') {
+                    return $this->bar;
+            } else if ($spec->name == 'zoo') {
+                    return $this->zoo;
+            } else {
+                    trigger_error('Unknown property');
+            }
+    }
+
+    function __set_gproperty($spec, $value)
+    {
+            echo "__set_gproperty called for $spec = $value\n";
+            if ($spec->name == 'foo') {
+                    $this->foo = $value;
+            } else if ($spec->name == 'bar') {
+                    $this->bar = $value;
+            } else {
+                    trigger_error('Unknown property');
+            }
+    }
+}
+
+GObject::register_type('NewType');
+echo $c, "\n";
+$c = new NewType;
+var_dump($c->get_property('foo'));
+var_dump($c->get_property('bar'));
+var_dump($c->get_property('zoo'));
+$c->set_property('bar', new GtkButton());
+echo $c->get_property('bar');
+echo "\n";
+
+/* Returns:
+__get_gproperty called for [GParamString 'foo']
+string(6) "abcdef"
+__get_gproperty called for [GParamObject 'bar']
+NULL
+__get_gproperty called for [GParamBoolean 'zoo']
+bool(true)
+__set_gproperty called for [GParamObject 'bar'] = [GtkButton object (GtkButton Gtk+ type)]
+__get_gproperty called for [GParamObject 'bar']
+[GtkButton object (GtkButton Gtk+ type)]
+
+*/
+?>
\ No newline at end of file


Property changes on: gtk/php-gtk-doc/trunk/examples/reference/gobject/register_type_properties.php
___________________________________________________________________
Added: svn:keywords
   + Id

Added: gtk/php-gtk-doc/trunk/examples/reference/gobject/register_type_signals.php
===================================================================
--- gtk/php-gtk-doc/trunk/examples/reference/gobject/register_type_signals.php                        (rev 0)
+++ gtk/php-gtk-doc/trunk/examples/reference/gobject/register_type_signals.php 2009-10-05 19:59:25 UTC (rev 289232)
@@ -0,0 +1,43 @@
+<?php
+/* Extend GObject or a child of GObject */
+class NewType extends GtkButton {
+    /* Define our signals.  The format is signal name => array(when to run, return type, array(parameters required))
+    NOTE: this MUST be PUBLIC - after instatiation php-gtk will unset this property for you, so it will not exist
+    in your object after creation */
+    public $__gsignals = array(
+            /* override means we are overwriting the default handler provided by gtk for gtkbutton */
+            'clicked' => 'override',
+            'mashed'  => array(GObject::SIGNAL_RUN_LAST, GObject::TYPE_BOOLEAN, array(GObject::TYPE_LONG, GtkRequisition::gtype)),
+            );
+
+    /* any method named ___do_{$signalname} will be considered the default handler for a signal */
+    public function __do_clicked() {
+        echo "do_clicked called\n";
+    }
+
+    function __do_mashed($arg, $arg2) {
+            echo "NewType: class closure for `mashed` called with arguments {$arg}, ", get_class($arg2), "\n";
+    }
+}
+
+/* handler to attach to our new signal */
+function my_handler($obj, $arg, $arg2, $ex) {
+    echo "my_handler called with args {$arg}, ", get_class($arg2), " and extra {$ex}\n";
+    /* This stops bubbling */
+    return true;
+}
+
+GObject::register_type('NewType');
+$c = new NewType;
+$r = $c->size_request();
+$c->connect('mashed', 'my_handler', 99);
+$c->emit('clicked');
+var_dump($c->emit('mashed', 42, $r));
+
+/* Returns:
+do_clicked called
+my_handler called with args 42, GtkRequisition and extra 99
+NewType: class closure for `mashed` called with arguments 42, GtkRequisition
+bool(false)
+*/
+?>
\ No newline at end of file


Property changes on: gtk/php-gtk-doc/trunk/examples/reference/gobject/register_type_signals.php
___________________________________________________________________
Added: svn:keywords
   + Id

Modified: gtk/php-gtk-doc/trunk/manual/en/reference/gobject.xml
===================================================================
--- gtk/php-gtk-doc/trunk/manual/en/reference/gobject.xml 2009-10-05 19:33:21 UTC (rev 289231)
+++ gtk/php-gtk-doc/trunk/manual/en/reference/gobject.xml 2009-10-05 19:59:25 UTC (rev 289232)
@@ -15,7 +15,54 @@
   </desc>
  </classmeta>

+ <constructors>
+
+  <constructor id="gobject.constructor">
+   <funcsynopsis>
+    <funcprototype>
+    <funcdef> <function>GObject</function></funcdef>
+    <paramdef>
+     <parameter>
+      <optional>
+       <paramdef><enumname>string</enumname> <parameter>gtype</parameter></paramdef>
+       <paramdef><enumname>array</enumname> <parameter>properties</parameter></paramdef>
+      </optional>
+     </parameter>
+    </paramdef>
+    </funcprototype>
+   </funcsynopsis>
+   <shortdesc>
+    Creates a new GObject instance.
+   </shortdesc>
+   <desc>
+    <para>
+     Creates a new instance of Gobject, or optionally of type <parameter>gtype</parameter>.
+     The properties parameter should contain an associative array of Gobject properties
+     to set for the new instance.
+    </para>
+   </desc>
+  </constructor>
+
+ </constructors>
+
  <methods>
+  <method id="gobject.method.__tostring">
+   <funcsynopsis>
+    <funcprototype>
+     <funcdef>string<function>__toString</function></funcdef>
+    </funcprototype>
+   </funcsynopsis>
+   <shortdesc>
+    Creates a string representation of a GObject
+   </shortdesc>
+   <desc>
+    <para>
+     Returns a string representation of an object, including the PHP name and the
+     GType associated with the object.
+    </para>
+   </desc>
+  </method>
+
   <method id="gobject.method.block">
    <funcsynopsis>
     <funcprototype>
@@ -273,6 +320,59 @@
    </desc>
   </method>

+  <method id="gobject.method.emit">
+   <funcsynopsis>
+    <funcprototype>
+     <funcdef>void <function>emit</function></funcdef>
+     <paramdef>string <parameter>signal_name</parameter></paramdef>
+    </funcprototype>
+   </funcsynopsis>
+   <shortdesc>
+    Emits a signal on an object.  Additional values may be passed with the emit
+    call, these values will then be sent to any connected handlers.
+   </shortdesc>
+   <desc>
+    <para>
+     Emits a signal on an object, calling any connected handlers and passing any
+     user supplied data to the connected handlers.  Only signals registered for
+     the particular object can be emitted.  If a singal requires parameters in
+     the definition, then the required number of parameters must be sent to the
+     emit method.
+    </para>
+    <para>
+     &seealso;
+     <function class="GObject">connect</function>
+    </para>
+   </desc>
+  </method>
+
+  <method id="gobject.method.freeze_notify">
+   <funcsynopsis>
+    <funcprototype>
+     <funcdef>void <function>freeze_notify</function></funcdef>
+    </funcprototype>
+   </funcsynopsis>
+   <shortdesc>
+    Increments the freeze notify count
+   </shortdesc>
+   <desc>
+    <para>
+     Increases the freeze count on object. If the freeze count is non-zero, the
+     emission of "notify" signals on object is stopped. The signals are queued until
+     the freeze count is decreased to zero.
+    </para>
+    <para>
+     This is necessary for accessors that modify multiple properties to prevent
+     premature notification while the object is still being modified.
+    </para>
+    <para>
+     &seealso;
+     <function class="GObject">notify</function>,
+     <function class="GObject">thaw_notify</function>
+    </para>
+   </desc>
+  </method>
+
   <method id="gobject.method.get_data">
    <funcsynopsis>
     <funcprototype>
@@ -340,6 +440,38 @@
    </desc>
   </method>

+  <method id="gobject.method.list_properties">
+   <funcsynopsis>
+    <funcprototype>
+     <funcdef>array <function>list_properties</function></funcdef>
+     <paramdef>int <parameter>gtype</parameter></paramdef>
+    </funcprototype>
+   </funcsynopsis>
+   <shortdesc>
+    Lists all properties of a given class.
+   </shortdesc>
+   <desc>
+    <para>
+     Lists all properties in any class descended from gobject or registered as a
+     gtype.  Property information is returned in the same format as
+     <function class="GObject">get_property</function>.
+    </para>
+    <note>
+     <simpara>This method is static.</simpara>
+    </note>
+    <para>
+     The <parameter>gtype</parameter> parameter is an integer
+     unique to all classes/interfaces. You can acquire the gtype
+     of a class by using <literal>ClassName::gtype</literal>.
+    </para>
+    <para>
+     &seealso;
+     <function class="GObject">get_property</function>,
+     <function class="GObject">set_property</function>
+    </para>
+   </desc>
+  </method>
+
   <method id="gobject.method.notify">
    <funcsynopsis>
     <funcprototype>
@@ -357,6 +489,50 @@
    </desc>
   </method>

+  <method id="gobject.method.register_type">
+   <funcsynopsis>
+    <funcprototype>
+     <funcdef>bool<function>register_type</function></funcdef>
+     <paramdef>string<parameter>classname</parameter></paramdef>
+    </funcprototype>
+   </funcsynopsis>
+   <shortdesc>
+    Register a custom Gtype
+   </shortdesc>
+   <desc>
+    <para>
+     Allows custom signals and properties to be used in PHP classes.
+    </para>
+    <para>
+     You must call this method before attempting to instantiate any classes
+     that use custom signals and properties.
+    </para>
+    <note>
+     <simpara>This method is static.</simpara>
+    </note>
+    <example>
+     <title>Creating Custom Signals</title>
+     <programlisting role="php">
+      <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
+       href="&directory.examples;/reference/gobject/register_type_signals.php"
+       parse="text">
+       <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
+      </xi:include>
+     </programlisting>
+    </example>
+    <example>
+     <title>Creating Custom Properties</title>
+     <programlisting role="php">
+      <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
+       href="&directory.examples;/reference/gobject/register_type_properties.php"
+       parse="text">
+       <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
+      </xi:include>
+     </programlisting>
+    </example>
+   </desc>
+  </method>
+
   <method id="gobject.method.set_data">
    <funcsynopsis>
     <funcprototype>
@@ -542,6 +718,59 @@
    </desc>
   </method>

+  <method id="gobject.method.stop_emission">
+   <funcsynopsis>
+    <funcprototype>
+     <funcdef>void <function>stop_emission</function></funcdef>
+    </funcprototype>
+   </funcsynopsis>
+   <shortdesc>
+    Stops emission of a signal that is currently being emitted
+   </shortdesc>
+   <desc>
+    <para>
+     Stops a signal's current emission for the object this is called on.
+    </para>
+    <para>
+     This will prevent the default method from running, if the signal was
+     G_SIGNAL_RUN_LAST and you connected normally (i.e. without the "after" flag).
+     Prints a warning if used on a signal which isn't being emitted.
+    </para>
+    <para>
+     &seealso;
+     <function class="GObject">emit</function>,
+    </para>
+   </desc>
+  </method>
+
+  <method id="gobject.method.thaw_notify">
+   <funcsynopsis>
+    <funcprototype>
+     <funcdef>void <function>thaw_notify</function></funcdef>
+    </funcprototype>
+   </funcsynopsis>
+   <shortdesc>
+    Decrements the freeze notify count
+   </shortdesc>
+   <desc>
+    <para>
+     Reverts the effect of a previous call to <function
+     class="GObject">freeze_notify</function>. The freeze count is decreased on
+     object and when it reaches zero, all queued "notify" signals are emitted.
+     It is an error to call this function when the freeze count is zero
+    </para>
+    <para>
+     If multiple calls to <function class="GObject">freeze_notify</function>
+     were made, and equal number of calls must be made to unfreeze.
+    </para>
+    <para>
+     &seealso;
+     <function class="GObject">notify</function>,
+     <function class="GObject">freeze_notify</function>
+    </para>
+   </desc>
+  </method>
+
   <method id="gobject.method.unblock">
    <funcsynopsis>
     <funcprototype>


--
PHP-GTK Documentation Mailing List (http://gtk.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php