cvs: pear /Gtk2_EntryDialog package.xml /Gtk2_EntryDialog/Gtk2 EntryDialog.php /Gtk2_EntryDialog/examples normal.php simple.php verysimple.php

From: Date: Mon, 20 Mar 2006 08:21:34 +0000
Subject: cvs: pear /Gtk2_EntryDialog package.xml /Gtk2_EntryDialog/Gtk2 EntryDialog.php /Gtk2_EntryDialog/examples normal.php simple.php verysimple.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-39200@lists.php.net to get a copy of this message
cweiske Mon Mar 20 08:21:34 2006 UTC Added files: /pear/Gtk2_EntryDialog package.xml /pear/Gtk2_EntryDialog/Gtk2 EntryDialog.php /pear/Gtk2_EntryDialog/examples normal.php simple.php verysimple.php Log: Initial import

http://cvs.php.net/viewcvs.cgi/pear/Gtk2_EntryDialog/package.xml?view=markup&rev=1.1 Index: pear/Gtk2_EntryDialog/package.xml +++ pear/Gtk2_EntryDialog/package.xml <?xml version="1.0"?> <package version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd"> <name>Gtk2_EntryDialog</name> <channel>pear.php.net</channel> <summary>Message box with text entry field</summary> <description> Gtk2 message box with additional text entry field. </description> <lead> <name>Christian Weiske</name> <user>cweiske</user> <email>cweiske@php.net</email> <active>yes</active> </lead> <date>2006-03-11</date> <version> <release>0.0.3</release> <api>0.0.3</api> </version> <stability> <release>beta</release> <api>beta</api> </stability> <license uri="http://www.gnu.org/licenses/lgpl.html">LGPL</license> <notes> - Added camelCase pear-compatible method aliases - get() returns false if the user cancelled </notes> <contents> <dir name="/" baseinstalldir="/"> <dir name="Gtk2"> <file name="EntryDialog.php" role="php"/> </dir> <dir name="examples"> <file name="normal.php" role="doc"/> <file name="simple.php" role="doc"/> <file name="verysimple.php" role="doc"/> </dir> </dir> </contents> <dependencies> <required> <php> <min>5.1</min> <max>6.0.0</max> </php> <pearinstaller> <min>1.4.1</min> </pearinstaller> <extension> <name>php-gtk</name> <min>2.0.0dev</min> </extension> </required> </dependencies> <phprelease/> <changelog> <release> <version> <release>0.0.3</release> <api>0.0.3</api> </version> <stability> <release>beta</release> <api>beta</api> </stability> <date>2006-03-11</date> <license uri="http://www.gnu.org/licenses/lgpl.html">LGPL</license> <notes> - Added camelCase pear-compatible method aliases - get() returns false if the user cancelled </notes> </release> <release> <version> <release>0.0.2</release> <api>0.0.2</api> </version> <stability> <release>beta</release> <api>beta</api> </stability> <date>2006-03-04</date> <license uri="http://www.gnu.org/licenses/lgpl.html">LGPL</license> <notes> Added two convenience methods. </notes> </release> <release> <version> <release>0.0.1</release> <api>0.0.1</api> </version> <stability> <release>beta</release> <api>beta</api> </stability> <date>2006-03-03</date> <license uri="http://www.gnu.org/licenses/lgpl.html">LGPL</license> <notes> Initial release. </notes> </release> </changelog> </package> http://cvs.php.net/viewcvs.cgi/pear/Gtk2_EntryDialog/Gtk2/EntryDialog.php?view=markup&rev=1.1 Index: pear/Gtk2_EntryDialog/Gtk2/EntryDialog.php +++ pear/Gtk2_EntryDialog/Gtk2/EntryDialog.php <?php /** * Dialog message box with text entry field. * * There are three modes to use it: * - Normal constructor with (somewhat complicated) parameters * as known from GtkMessageDialog. * - new_simple() static method constructor with only one required * parameter. * - Static get() method that just returns the inputted text instead * of the dialog itself. This is the most convenient and code-saving * method to get an input. * * Even when the dialog has an OK button only, the user can cancel it * by closing the window. * * @category Gtk2 * @package Gtk2_EntryDialog * @author Christian Weiske <cweiske@php.net> * @license LGPL * @version CVS: $Id: EntryDialog.php,v 1.1 2006/03/20 08:21:34 cweiske Exp $ */ class Gtk2_EntryDialog extends GtkMessageDialog { /** * The entry box * @var GtkEntry */ protected $entry; /** * The response id that is used as default * @var int */ protected $nDefaultResponseId = null; /** * Normal constructor. * Parameters are the same as for GtkMessageDialog. * * @param GtkWindow $parent Parent window (can be null) * @param GtkDialogFlags $flags Dialog flags (use 0 as default) * @param GtkMessageType $type Message type (e.g. Gtk::MESSAGE_QUESTION) * @param GtkButtonsType $buttons Buttons to show (e.g. Gtk::BUTTONS_OK) * @param string $message Message to display * @param string $default Default text for the entry */ public function __construct($parent, $flags, $type, $buttons, $message, $default = null) { parent::__construct($parent, $flags, $type, $buttons, $message); $this->entry = new GtkEntry(); $this->entry->connect_simple('activate', array($this, 'onActivateEntry')); $this->vbox->pack_end($this->entry); if ($default !== null) { $this->entry->set_text($default); } switch ($buttons) { case Gtk::BUTTONS_OK: case Gtk::BUTTONS_OK_CANCEL: $this->nDefaultResponseId = Gtk::RESPONSE_OK; break; case Gtk::BUTTONS_YESNO: $this->nDefaultResponseId = Gtk::RESPONSE_YES; break; case Gtk::BUTTONS_CLOSE: $this->nDefaultResponseId = Gtk::RESPONSE_CLOSE; break; } }//public function __construct($parent, $flags, $type, $buttons, $message, $default = null) /** * Simplified constructor with not so much parameters. * Message type is Gtk::MESSAGE_QUESTION, the flags will be * Gtk::DIALOG_MODAL if the parent is set. Only one OK button * will be visible. * * @param string $message Message/question to display * @param string $default Default entry text * @param GtkWidget $parent Parent widget if any * * @return Gtk2_EntryDialog Entry dialog instance */ public static function new_simple($message, $default = null, $parent = null) { $flags = $parent === null ? 0 : Gtk::DIALOG_MODAL; return new Gtk2_EntryDialog( $parent, $flags, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_OK, $message, $default ); }//public static function new_simple($message, $default = null, $parent = null) /** * Creates a dialog with the given parameters (@see new_simple), * runs it, and returns the text set. * If the user cancelled the dialog, this method returns FALSE. * In any other case (even when the text is empty), the a string * with the text is returned. * * @param string $message Message/question to display * @param string $default Default entry text * @param GtkWidget $parent Parent widget if any * * @return string Text input by the user */ public static function get($message, $default, $parent = null) { $dialog = self::new_simple($message, $default, $parent); $answer = $dialog->run(); if ($answer == Gtk::RESPONSE_OK) { $text = $dialog->get_text(); } else { //cancelled $text = false; } $dialog->destroy(); return $text; }//public static function get($message, $default, $parent = null) /** * Show the dialog and block until a button has been pressed. * * @return int The response id of the pressed button. */ public function run() { //Make sure that the entry is visible $this->show_all(); return parent::run(); }//public function run() /** * Sets the text for the entry * * @param string $text The text to set */ public function set_text($text) { $this->entry->set_text($text); }//public function set_text($text) /** * Retrieves the text from the entry * * @return string The input from the user */ public function get_text() { return $this->entry->get_text(); }//public function get_text() /** * Set the default response. * The button with the id will be the default one, * allowing you to just press return to activate it * * @param int $response_id Response code */ public function set_default_response($response_id) { parent::set_default_response($response_id); $this->nDefaultResponseId = $response_id; }//public function set_default_response($response_id) /** * Callback for the entry text. * Activates the default button. */ public function onActivateEntry() { if ($this->nDefaultResponseId !== null) { $this->response($this->nDefaultResponseId); } }//public function onActivateEntry() /* * PEAR-style camelCase method aliases */ /** * Alias for set_default_response() * * @param int $response_id Response code */ public function setRefaultResponse($response_id) { $this->set_default_response($response_id); }//public function setRefaultResponse($response_id) /** * Alias for set_text(). * * @param string $text The text to set */ public function setText($text) { $this->set_text($text); }//public function setText($text) /** * Alias for get_text(). * * @return string The input from the user */ public function getText() { return $this->get_text(); }//public function getText() }//class Gtk2_EntryDialog extends GtkMessageDialog ?> http://cvs.php.net/viewcvs.cgi/pear/Gtk2_EntryDialog/examples/normal.php?view=markup&rev=1.1 Index: pear/Gtk2_EntryDialog/examples/normal.php +++ pear/Gtk2_EntryDialog/examples/normal.php <?php /** * Normal Gtk2_EntryDialog example * * @author Christian Weiske <cweiske@php.net> */ require_once 'Gtk2/EntryDialog.php'; $id = new Gtk2_EntryDialog( null, //parent window 0, //flags (GtkDialogFlags) Gtk::MESSAGE_QUESTION, //type of message Gtk::BUTTONS_OK_CANCEL, //which buttons shall be there 'What\'s your name?', //the message 'Don\'t know' //The default text ); $answer = $id->run(); $id->destroy(); if ($answer == Gtk::RESPONSE_OK) { echo 'The name is: '; var_dump($id->get_text()); } else { echo "You cancelled\r\n"; } ?> http://cvs.php.net/viewcvs.cgi/pear/Gtk2_EntryDialog/examples/simple.php?view=markup&rev=1.1 Index: pear/Gtk2_EntryDialog/examples/simple.php +++ pear/Gtk2_EntryDialog/examples/simple.php <?php /** * Simple Gtk2_EntryDialog example * * @author Christian Weiske <cweiske@php.net> */ require_once 'Gtk2/EntryDialog.php'; $id = Gtk2_EntryDialog::new_simple( 'What\'s your name?', //the message 'Don\'t know' //The default text ); $answer = $id->run(); $id->destroy(); if ($answer == Gtk::RESPONSE_OK) { echo 'The name is: '; var_dump($id->get_text()); } else { echo "You cancelled\r\n"; } ?> http://cvs.php.net/viewcvs.cgi/pear/Gtk2_EntryDialog/examples/verysimple.php?view=markup&rev=1.1 Index: pear/Gtk2_EntryDialog/examples/verysimple.php +++ pear/Gtk2_EntryDialog/examples/verysimple.php <?php /** * Very simple Gtk2_EntryDialog example * * @author Christian Weiske <cweiske@php.net> */ require_once 'Gtk2/EntryDialog.php'; $text = Gtk2_EntryDialog::get( 'What\'s your name?', //the message 'Don\'t know' //The default text ); if ($text !== false) { echo 'The name is: '; var_dump($text); } else { echo "You cancelled\r\n"; } ?>
« previous php.pear.cvs (#39200) next »