Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Apress
committed
Oct 7, 2016
0 parents
commit eb4e956
Showing
167 changed files
with
19,151 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* A simple Object Oriented example. | ||
*/ | ||
class Ralph { | ||
|
||
public $name = 'Ralph'; | ||
protected $suffix = 'Sr'; | ||
|
||
public function __construct() | ||
{ | ||
echo 'My name is ' . $this->name . ' ' . $this->suffix . ".\n"; | ||
} | ||
|
||
public function giveBirth() | ||
{ | ||
echo "It's a boy!\n"; | ||
return new Ralph_Jr(); | ||
} | ||
} | ||
|
||
class Ralph_Jr extends Ralph { | ||
|
||
protected $suffix = 'Jr'; | ||
|
||
public function giveBirth() | ||
{ | ||
throw new Exception('Ralph Jr. can\'t have kids!'); | ||
} | ||
} | ||
|
||
$senior = new Ralph(); | ||
$junior = $senior->giveBirth(); | ||
|
||
try { | ||
$junior->giveBirth(); | ||
} catch (Exception $e) { | ||
echo $e->getMessage() . "\n"; | ||
} | ||
/* | ||
* Local variables: | ||
* tab-width: 4 | ||
* c-basic-offset: 4 | ||
* End: | ||
*/ | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
$window = new GtkWindow(); | ||
$window->connect_object('destroy', array('Gtk', 'main_quit')); | ||
|
||
$dateTime = new GtkLabel(date('Y-m-d H:i:s')); | ||
|
||
$window->add($dateTime); | ||
$window->show_all(); | ||
Gtk::main(); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
/** | ||
* A really simple PHP-GTK application. | ||
*/ | ||
$window = new GtkWindow(); | ||
$window->connect_object('destroy', array('Gtk', 'main_quit')); | ||
$window->show(); | ||
Gtk::main(); | ||
/* | ||
* Local variables: | ||
* tab-width: 4 | ||
* c-basic-offset: 4 | ||
* End: | ||
*/ | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import javax.swing.*; | ||
|
||
public class listing1_4 { | ||
|
||
public static void createAndShowGUI() { | ||
JFrame frame = new JFrame(); | ||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
frame.setVisible(true); | ||
} | ||
|
||
public static void main(String[] args) { | ||
javax.swing.SwingUtilities.invokeLater( | ||
createAndShowGUI(); | ||
); | ||
createAndShowGUI(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/** | ||
* A PHP implementation of GtkObject. | ||
*/ | ||
class GtkObject { | ||
|
||
private $flags; | ||
private $refCounter; | ||
|
||
public function destroy() | ||
{ | ||
unset($this); | ||
} | ||
|
||
public function flags() | ||
{ | ||
return $this->flags; | ||
} | ||
|
||
public function set_flags($flags) | ||
{ | ||
$this->flags = $this->flags | $flags; | ||
} | ||
|
||
public function sink() | ||
{ | ||
if (--$this->refCounter < 1) { | ||
$this->destroy(); | ||
} | ||
} | ||
|
||
public function unset_flags($flags) | ||
{ | ||
$this->flags = $this->flags & ~$flags; | ||
} | ||
} | ||
/* | ||
* Local variables: | ||
* tab-width: 4 | ||
* c-basic-offset: 4 | ||
* End: | ||
*/ | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/** | ||
* An example to show the various states of a widget. | ||
*/ | ||
$widget = new GtkWindow(); | ||
|
||
// If you try to grab the window before realizing | ||
// the object you will get nothing. | ||
var_dump($widget->window); | ||
var_dump($widget->flags()); | ||
|
||
$widget->realize(); | ||
|
||
// Now that the widget is realized, we can grab | ||
// the window property. | ||
var_dump($widget->window); | ||
var_dump($widget->flags()); | ||
|
||
$widget->show(); | ||
|
||
// Showing and hiding a widget changes the value | ||
// of its flags. | ||
var_dump($widget->flags()); | ||
|
||
$widget->hide(); | ||
|
||
var_dump($widget->flags()); | ||
|
||
$widget->unrealize(); | ||
|
||
// Now that the widget is realized, we can grab | ||
// the window property. | ||
var_dump($widget->window); | ||
var_dump($widget->flags()); | ||
/* | ||
* Local variables: | ||
* tab-width: 4 | ||
* c-basic-offset: 4 | ||
* End: | ||
*/ | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
/** | ||
* An example to what happens when you try to add a widget to two containers. | ||
*/ | ||
$window = new GtkWindow(); | ||
$frame = new GtkFrame(); | ||
$button = new GtkButton("I'm a button"); | ||
|
||
$window->add($button); | ||
$frame->add($button); | ||
|
||
/* | ||
Spits out this message: | ||
(listing-3.php:1870): Gtk-WARNING **: Attempting to add a widget with type GtkButton to a container of type GtkFrame, but the widget is already inside a container of type GtkWindow, the GTK+ FAQ at http://www.gtk.org/faq/ explains how to reparent a widget. | ||
*/ | ||
|
||
/* | ||
* Local variables: | ||
* tab-width: 4 | ||
* c-basic-offset: 4 | ||
* End: | ||
*/ | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/** | ||
* Getting, setting and changing a widgets parent. | ||
*/ | ||
function testForParent($widget) | ||
{ | ||
$parent = $widget->get_parent(); | ||
|
||
echo 'The ' . get_class($widget) . ' has '; | ||
if (isset($parent)) { | ||
echo 'a ' . get_class($parent); | ||
} else { | ||
echo 'no'; | ||
} | ||
echo " parent.\n"; | ||
} | ||
|
||
// Start with three widgets. | ||
$window = new GtkWindow(); | ||
$frame = new GtkFrame('I am a frame'); | ||
$button = new GtkButton("I'm a button"); | ||
|
||
testForParent($button); | ||
|
||
$button->set_parent($frame); | ||
testForParent($button); | ||
|
||
// What if we want the button to be added directly to | ||
// the window? | ||
$button->unparent(); | ||
$button->set_parent($window); | ||
testForParent($button); | ||
$button->unparent(); | ||
testForParent($button); | ||
/* | ||
* Local variables: | ||
* tab-width: 4 | ||
* c-basic-offset: 4 | ||
* End: | ||
*/ | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/** | ||
* Getting, setting and changing a widgets parent. | ||
*/ | ||
function testForParent($widget) | ||
{ | ||
$parent = $widget->get_parent(); | ||
|
||
echo 'The ' . get_class($widget) . ' has '; | ||
if (isset($parent)) { | ||
echo 'a ' . get_class($parent); | ||
} else { | ||
echo 'no'; | ||
} | ||
echo " parent.\n"; | ||
} | ||
|
||
// Start with three widgets. | ||
$window = new GtkWindow(); | ||
$frame = new GtkFrame('I am a frame'); | ||
$button = new GtkButton("I'm a button"); | ||
|
||
testForParent($button); | ||
|
||
$frame->add($button); | ||
testForParent($button); | ||
|
||
// What if we want the button to be added directly to | ||
// the window? | ||
$frame->remove($button); | ||
$window->add($button); | ||
testForParent($button); | ||
|
||
// No switch it back to the frame. | ||
$button->reparent($frame); | ||
testForParent($button); | ||
/* | ||
* Local variables: | ||
* tab-width: 4 | ||
* c-basic-offset: 4 | ||
* End: | ||
*/ | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
/** | ||
* Reacting to events. | ||
*/ | ||
function setParentFunction($widget) | ||
{ | ||
$parent = $widget->get_parent(); | ||
|
||
echo 'The ' . get_class($widget) . ' has '; | ||
if (isset($parent)) { | ||
echo 'a ' . get_class($parent); | ||
} else { | ||
echo 'no'; | ||
} | ||
echo " parent.\n"; | ||
} | ||
|
||
// Start with three widgets. | ||
$window = new GtkWindow(); | ||
$frame = new GtkFrame('I am a frame'); | ||
$button = new GtkButton("I'm a button"); | ||
|
||
// Connect the event to our test function | ||
$button->connect('parent-set', 'setParentFunction'); | ||
|
||
// Now set some parents. | ||
$button->set_parent($window); | ||
$button->unparent(); | ||
$frame->add($button); | ||
|
||
$button->reparent($window); | ||
/* | ||
* Local variables: | ||
* tab-width: 4 | ||
* c-basic-offset: 4 | ||
* End: | ||
*/ | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* Reacting to events. | ||
*/ | ||
class ExtendedButton extends GtkButton { | ||
|
||
public function __construct($label) | ||
{ | ||
parent::__construct($label); | ||
|
||
$this->connect('parent-set', array($this, 'printParentSet')); | ||
} | ||
|
||
public function printParentSet($widget) | ||
{ | ||
$parent = $widget->get_parent(); | ||
|
||
echo 'The ' . get_class($widget) . ' has '; | ||
if (isset($parent)) { | ||
echo 'a ' . get_class($parent); | ||
} else { | ||
echo 'no'; | ||
} | ||
echo " parent.\n"; | ||
} | ||
} | ||
|
||
// Start with three widgets. | ||
$window = new GtkWindow(); | ||
$frame = new GtkFrame('I am a frame'); | ||
$button = new ExtendedButton("I'm a button"); | ||
|
||
// Now set some parents. | ||
$button->set_parent($window); | ||
$button->unparent(); | ||
$frame->add($button); | ||
|
||
$frame->connect('parent-set', array('ExtendedButton', 'printParentSet')); | ||
$window->add($frame); | ||
/* | ||
* Local variables: | ||
* tab-width: 4 | ||
* c-basic-offset: 4 | ||
* End: | ||
*/ | ||
?> |
Oops, something went wrong.