Glade_Window.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. *
  4. */
  5. /**
  6. * Auto-loading Glade window
  7. */
  8. class Glade_Window
  9. {
  10. /**
  11. * The top widget. It does not have to be
  12. * a top-level object if this is loaded
  13. * within another UI
  14. *
  15. * @var GtkWidget
  16. */
  17. public $top;
  18. /**
  19. * @var GladeXML
  20. */
  21. protected $glade;
  22. /**
  23. * Load the fixed structure for the actual class invoking the constructor
  24. *
  25. * @param void
  26. * @return void
  27. */
  28. public function __construct($topName = 'top')
  29. {
  30. $uiDescriptionFileName = get_class($this) . '.glade';
  31. try
  32. {
  33. $this->glade = new GladeXML($uiDescriptionFileName);
  34. $this->glade->signal_autoconnect_instance($this);
  35. $this->top = $this->glade->get_widget($topName);
  36. }
  37. catch (Exception $e)
  38. {
  39. echo "Glade_Windows/__construct(): " . $e->getMessage();
  40. die();
  41. }
  42. }
  43. /**
  44. * callback wrapper around Gtk::main_quit() for Glade
  45. */
  46. public function quit()
  47. {
  48. Gtk::main_quit();
  49. }
  50. /**
  51. * A utility callback for views inherited from this class: it
  52. * enables automatic alternate row colors
  53. *
  54. * @param GtkCellLayout $cell_layout
  55. * @param GtkCellRenderer $cell
  56. * @param GtkTreeModel $tree_model
  57. * @param GtkTreeIter $iter
  58. * @return void
  59. */
  60. static public function zebraTreeViewCallback(GtkCellLayout $cell_layout, GtkCellRenderer $cell, GtkTreeModel $tree_model, GtkTreeIter $iter /* [, user_data] */)
  61. {
  62. $path = $tree_model->get_path($iter);
  63. $cell->set_property('cell-background', ($path[0] % 2) ?'#d0d0d0' : '#ffffff');
  64. }
  65. }