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

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