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

Source for file VarDump.php

Documentation is available at VarDump.php

  1. <?php
  2. require_once 'Gtk2/VarDump/Pane.php';
  3.  
  4. /**
  5. *   Simple class for viewing PHP variables a var_dump() way
  6. *    in PHP-Gtk - reloaded for PHP-Gtk2.
  7. *
  8. *   It displays arrays and objects in a tree with all their
  9. *    children and subchildren and subsubchildren and ...
  10. *
  11. *   The class is memory-saving as it loads only the children
  12. *    which are currently visible. If the user expands a row,
  13. *    the next children will be loaded.
  14. *
  15. *   The tree has a small convenience feature: Left-click a row,
  16. *    and it will be expanded. Right-click it, and it collapses.
  17. *   Double-click or middle-click it, and all rows below the
  18. *    current one will be expanded. They will be expanded "all" only
  19. *    if they have been expanded before, as loading them recursively
  20. *    is very dangerous (if there are loops).
  21. *
  22. *   Note that Gtk2_VarDump::display() opens its own Gtk::main()-Loop,
  23. *    so your own program will stop executing until the VarDump window
  24. *    is closed.
  25. *
  26. *   Usage:
  27. *   require_once('Gtk2/VarDump.php');
  28. *   $ar = new array(1, 2, 3, 4, 'key' => array('this','is','cool');
  29. *   Gtk2_VarDump::display($ar);
  30. *
  31. *   Layout:
  32. *   +--[Window title]------------------------------------------------+
  33. *   |+--------------------------+/+---------------------------------+|
  34. *   || Node      | Type         ^\| Key    | Type      | Value      ^|
  35. *   ||                          |/|                                 ||
  36. *   || Left tree with objects   |\|  Right list with simple values  ||
  37. *   ||   and arrays             |/|     (int,float,string,...)      ||
  38. *   ||                          v\|                                 v|
  39. *   |+--------------------------+/+---------------------------------+|
  40. *   |                             [OK]                               |
  41. *   +----------------------------------------------------------------+
  42. *
  43. *   @author Christian Weiske <cweiske@php.net>
  44. */
  45. class Gtk2_VarDump extends GtkWindow
  46. {
  47.     /**
  48.     *   The tree on the left side of the window.
  49.     *   @var GtkTreeView 
  50.     */
  51.     protected $trTree    = null;
  52.  
  53.     /**
  54.     *   List on the right side of the window.
  55.     *   @var GtkTreeView 
  56.     */
  57.     protected $trValues  = null;
  58.  
  59.     /**
  60.     *   Model (data store) for the tree on the left.
  61.     *   @var GtkTreeStore 
  62.     */
  63.     protected $modTree   = null;
  64.  
  65.     /**
  66.     *   Model (data store) for the list on the right.
  67.     *   @var GtkListStore 
  68.     */
  69.     protected $modValues = null;
  70.  
  71.  
  72.  
  73.     /**
  74.     *   Create a new Gtk2_VarDump window.
  75.     *   When the window is closed, a main loop is stopped.
  76.     *
  77.     *   @param mixed    $variable   The variable to inspect
  78.     *   @param string   $title      The title for the window and the variable
  79.     */
  80.     public function __construct($variable$title 'Gtk2_VarDump')
  81.     {
  82.         parent::__construct();
  83.         $this->buildDialog($title);
  84.         $this->hpane->setVariable($variable$title);
  85.     }//public function __construct($variable, $title = 'Gtk2_VarDump')
  86.  
  87.  
  88.  
  89.     /**
  90.     *   Create a new Gtk2_VarDump window and keep it displayed
  91.     *   in its own Gtk::main()-loop.
  92.     *   This main loop is stopped as soon the window is closed
  93.     *
  94.     *   @param mixed    $variable   The variable to inspect
  95.     *   @param string   $title      The title for the window and the variable
  96.     */
  97.     public static function display($variable$title 'Gtk2_VarDump')
  98.     {
  99.         $vd = new Gtk2_VarDump($variable$title);
  100.         $vd->show_all();
  101.         Gtk::main();
  102.     }//public static function display($variable, $title = 'Gtk2_VarDump')
  103.  
  104.  
  105.  
  106.     /**
  107.     *   Creates the dialog content, loads the tree models and so
  108.     *
  109.     *   @param  string  $title  The title for the window
  110.     */
  111.     protected function buildDialog($title)
  112.     {
  113.         $this->set_title($title);
  114.         $this ->connect_simple('destroy'array($this'close'));
  115.  
  116.         $btnOk = GtkButton::new_from_stock(Gtk::STOCK_OK);
  117.         $btnOk->connect_simple('clicked'array($this'close'));
  118.  
  119.         $vboxMain    = new GtkVBox();
  120.         $this->hpane = new Gtk2_VarDump_Pane();
  121.  
  122.         $vboxMain->pack_start($this->hpanetrue true 0);
  123.         $vboxMain->pack_end(  $btnOk      falsefalse0);
  124.  
  125.         $this->add($vboxMain);
  126.  
  127.         $btnOk->set_flags($btnOk->flags(+ Gtk::CAN_DEFAULT);
  128.         $this->set_default($btnOk);
  129.         $this->set_default_size(600400);
  130.     }//protected function buildDialog($title)
  131.  
  132.  
  133.  
  134.     /**
  135.     *   Called when the user clicks "OK" or tries to close the window.
  136.     *   This function quits the main loop opened in the constructor.
  137.     */
  138.     public function close()
  139.     {
  140.         //quit our own main loop
  141.         $this->destroy();
  142.         Gtk::main_quit();
  143.     }//public function close()
  144.  
  145. }//class Gtk2_VarDump extends GtkWindow
  146. ?>

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