Gtk2_ExceptionDump
[ class tree: Gtk2_ExceptionDump ] [ index: Gtk2_ExceptionDump ] [ all elements ]

Source for file InfoBox.php

Documentation is available at InfoBox.php

  1. <?php
  2. /**
  3. * Information box with icon and the exception message.
  4. *
  5. @category Gtk2
  6. @package  Gtk2_ExceptionDump
  7. @author   Christian Weiske <cweiske@php.net>
  8. @license  http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  9. @version  CVS: $Id$
  10. @link     http://pear.php.net/package/Gtk2_ExceptionDump
  11. */
  12. class Gtk2_ExceptionDump_InfoBox extends GtkHBox
  13. {
  14.     /**
  15.     * Creates a new InfoBox and sets the exception.
  16.     *
  17.     * @param mixed $exception Exception or PEAR_Error
  18.     */
  19.     public function __construct($exception = null)
  20.     {
  21.         parent::__construct();
  22.         $this->build();
  23.         if ($exception !== null{
  24.             $this->setException($exception);
  25.         }
  26.     }//public function __construct($exception = null)
  27.  
  28.  
  29.  
  30.     /**
  31.     * Sets up the child widgets.
  32.     */
  33.     protected function build()
  34.     {
  35.         $stockalign = new GtkAlignment(0000);
  36.         $stockalign->add(
  37.             GtkImage::new_from_stock(
  38.                 Gtk::STOCK_DIALOG_ERRORGtk::ICON_SIZE_DIALOG
  39.             )
  40.         );
  41.         $this->pack_start($stockalignfalsetrue);
  42.  
  43.  
  44.         $this->expander = new GtkExpander('');
  45.  
  46.         $this->message = new GtkLabel();
  47.         $this->expander->set_label_widget($this->message);
  48.         $this->message->set_selectable(true);
  49.         $this->message->set_line_wrap(true);
  50.  
  51.         $this->userinfo = new GtkLabel();
  52.         $this->userinfo->set_selectable(true);
  53.         $this->userinfo->set_line_wrap(true);
  54.         //FIXME: add scrolled window
  55.         $this->expander->add($this->userinfo);
  56.  
  57.         $this->pack_start($this->expander);
  58.     }//protected function build()
  59.  
  60.  
  61.  
  62.     /**
  63.     * Sets and displays the exception.
  64.     *
  65.     * @param mixed $exception Exception or PEAR_Error
  66.     */
  67.     public function setException($exception)
  68.     {
  69.         //works on PEAR_Error and Exception
  70.         $code $exception->getCode();
  71.         if ($code !== null{
  72.             $code ' (Code #' $code ')';
  73.         }
  74.  
  75.         $this->message->set_label($exception->getMessage($code);
  76.         if ($exception instanceof PEAR_Error{
  77.             $this->userinfo->set_label($exception->getUserInfo());
  78.         else {
  79.             $this->userinfo->set_label('');
  80.         }
  81.     }//public function setException($exception)
  82.  
  83.  
  84.  
  85.     /**
  86.     * Explicitely sets a message to display, not an exception.
  87.     * Can be used to tell the user that no exception occured,
  88.     * but a normal variable has been passed.
  89.     *
  90.     * @param string $message  The message to display
  91.     * @param string $userinfo User information text that is display
  92.     *                          when expanding the label.
  93.     */
  94.     public function setMessage($message$userinfo '')
  95.     {
  96.         $this->message->set_label($message);
  97.         $this->userinfo->set_label($userinfo);
  98.     }//public function setMessage($message, $userinfo = '')
  99.  
  100. }//class Gtk2_ExceptionDump_InfoBox extends GtkHBox
  101. ?>

Documentation generated on Mon, 11 Mar 2019 15:55:05 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.