Posted by paranomos Fri 9th Feb 2007 16:10 - Syntax is None/text - 330 views
Download | New Post | Modify | Hide line numbers
Description:
when description column is sorted and try to press the checkbox weired things
happen

  1.  
  2.  $window = new GtkWindow();
  3.  $window->connect_simple('destroy', array('Gtk','main_quit'));
  4.  $window->set_size_request(400, 200);
  5.  $window->add($vbox = new GtkVBox());
  6.  
  7.  // Set up a scroll window
  8.  $scrolled_win = &new GtkScrolledWindow();
  9.  $scrolled_win->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
  10.  $vbox->pack_start($scrolled_win);
  11.  
  12.  // the 2D table
  13.  $data = array(
  14.  array('row0', 'item 1',true, 2, 3.1),
  15.  array('row1', 'item 1',true, 20, 6.21),
  16.  array('row2', 'item 1',true, 8, 9.36),
  17.  array('row3', 'item 1',true, 11, 12.4),
  18.  array('row4', 'item 1',true, 5, 15.5),
  19.  array('row5', 'item 1',true, 17, 18.6),
  20.  array('row6', 'item 1',true, 20, 21.73));
  21.  
  22.  display_table ($scrolled_win, $data);
  23.  
  24.  $window->show_all();
  25.  Gtk::main();
  26.  
  27.  function display_table($scrolled_win, $data) {
  28.     global $model, $view;
  29.     $model = new GtkListStore(Gtk::TYPE_STRING, Gtk::TYPE_STRING, GTK::TYPE_BOOLEAN,
  30.                 Gtk::TYPE_LONG, Gtk::TYPE_DOUBLE);
  31.     $field_header = array('Row #','Description', 'check', 'Qty', 'Price');
  32.     $field_justification = array(0,0, 0, 0.5, 1);
  33.  
  34.     $modelsort = new GtkTreeModelSort($model);  // note 1
  35.    
  36.     $view = new GtkTreeView($modelsort); // note 3
  37.     $scrolled_win->add($view);
  38.  
  39.     // Creates the columns
  40.     for ($col=0; $col
  41.         if ($field_header[$col] == 'check') {
  42.          $render = new GtkCellRendererToggle();
  43.          $render->set_property('activatable', true);
  44.          $render->connect('toggled', 'on_toggle',$modelsort);
  45.          $column = new GtkTreeViewColumn($field_header[$col],$render,'active',$col);
  46.          $column->set_alignment($field_justification[$col]);
  47.         }else{
  48.          $cell_renderer = new GtkCellRendererText();
  49.          $cell_renderer->set_property("xalign", $field_justification[$col]);
  50.          $column = new GtkTreeViewColumn($field_header[$col], $cell_renderer, 'text', $col);
  51.          $column->set_alignment($field_justification[$col]);
  52.          $column->set_sort_column_id($col);
  53.         }
  54.  
  55.         $view->append_column($column);
  56.     }
  57.  
  58.     // pupulates the data
  59.     for ($row=0; $row
  60.         $values = array();
  61.         for ($col=0; $col
  62.             $values[] = $data[$row][$col];
  63.         }
  64.         $model->append($values);
  65.     }
  66.  
  67.  
  68.  
  69.  }
  70.  
  71.  //function for checkbox 
  72.   function on_toggle($renderer, $row, $modelsort) {
  73.    $sortiter = $modelsort->get_iter($row); 
  74.    $model = $modelsort -> get_model();
  75.    $iter = $modelsort -> convert_iter_to_child_iter($sortiter);
  76.    $model->set($iter, 2,!$model->get_value($iter, 2));
  77.   }

PermaLink to this entry https://pastebin.co.uk/10168
Posted by paranomos Fri 9th Feb 2007 16:10 - Syntax is None/text - 330 views
Download | New Post | Modify | Hide line numbers

 

Comments: 0