Posted by Anonymous Fri 9th Feb 2007 15:33 - Syntax is PHP - 110 views
Modification of posting from dimitris Fri 9th Feb 2007 15:21Run this post in the PHP shell
Download | New Post | Modify | Diff | Hide line numbers
PHP parser reported no syntax errors in this post!
  1. $window = new GtkWindow();
  2. $window->set_size_request(400, 312);
  3. $window->connect_simple('destroy', array('Gtk','main_quit'));
  4. $window->add($vbox = new GtkVBox());
  5. $accel_group = new GtkAccelGroup();
  6. $window->add_accel_group($accel_group);
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13. // Set up a scroll window
  14. $scrolled_win = &new GtkScrolledWindow();
  15. $scrolled_win->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
  16. $vbox->pack_start($scrolled_win);
  17.  
  18. // the 2D table
  19. $data = array(
  20. array('row0', 'item 19',true, 2, 3.1),
  21. array('row1', 'item 16',true, 20, 6.21),
  22. array('row2', 'item 13',true, 8, 9.36),
  23. array('row3', 'item 10',true, 11, 12.4),
  24. array('row4', 'item 7',true, 5, 15.5),
  25. array('row5', 'item 4',true, 17, 18.6),
  26. array('row6', 'item 3',true, 20, 21.73));
  27.  
  28. display_table ($scrolled_win, $data);
  29.  
  30. $window->show_all();
  31. Gtk::main();
  32.  
  33. function display_table($scrolled_win, $data) {
  34.     // Creates the list store
  35.     global $model, $view;
  36.     $model = new GtkListStore(Gtk::TYPE_STRING, Gtk::TYPE_STRING, GTK::TYPE_BOOLEAN,
  37.                 Gtk::TYPE_LONG, Gtk::TYPE_DOUBLE);
  38.     $field_header = array('Row #','Description', 'check', 'Qty', 'Price');
  39.     $field_justification = array(0,0, 0, 0.5, 1);
  40.  
  41.     // setup GtkTreeModelSort
  42.     $modelsort = new GtkTreeModelSort($model)// note 1
  43.    
  44.     // Creates the view to display the list store
  45.     $view = new GtkTreeView($modelsort); // note 3
  46.     $scrolled_win->add($view);
  47.  
  48.     // Creates the columns
  49.     for ($col=0; $col($field_header); ++$col) {
  50.         echo $col;
  51.         if ($field_header[$col] == 'check') {
  52.          $render = new GtkCellRendererToggle();
  53.          $render->set_property('activatable', true);
  54.          $render->connect('toggled', 'on_toggle',$modelsort);
  55.          $column = new GtkTreeViewColumn($field_header[$col],$render,'active',$col);
  56.          $column->set_alignment($field_justification[$col]);
  57.         }else{
  58.          $cell_renderer = new GtkCellRendererText();
  59.          $cell_renderer->set_property("xalign", $field_justification[$col]);
  60.          $column = new GtkTreeViewColumn($field_header[$col], $cell_renderer, 'text', $col);
  61.          $column->set_alignment($field_justification[$col]);
  62.          $column->set_sort_column_id($col);
  63.         }
  64.  
  65.         /* // set the header font and color
  66.         $label = new GtkLabel($field_header[$col]);
  67.         $label->modify_font(new PangoFontDescription("Arial Bold"));
  68.         $label->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000FF"));
  69.         $column->set_widget($label);
  70.         $label->show(); */
  71.  
  72.         // setup self-defined function to display alternate row color
  73.         $view->append_column($column);
  74.     }
  75.  
  76.     // pupulates the data
  77.     for ($row=0; $row($data); ++$row) {
  78.         $values = array();
  79.         for ($col=0; $col($data[$row]); ++$col) {
  80.             $values[] = $data[$row][$col];
  81.         }
  82.         $model->append($values);
  83.     }
  84.  
  85.  
  86.  
  87. }
  88.  
  89.  //function for checkbox 
  90.   function on_toggle($renderer, $row, $modelsort) {
  91.    $sortiter = $modelsort->get_iter($row)
  92.    $model = $modelsort -> get_model();
  93.    $iter = $modelsort -> convert_iter_to_child_iter($sortiter);
  94.     $model->set($iter, 2,!$model->get_value($iter, 2));
  95.   }

PermaLink to this entry https://pastebin.co.uk/10167
Posted by Anonymous Fri 9th Feb 2007 15:33 - Syntax is PHP - 110 views
Modification of posting from dimitris Fri 9th Feb 2007 15:21Run this post in the PHP shell
Download | New Post | Modify | Diff | Hide line numbers

 

Comments: 0