예제 #1
0
 /**
  * Construct treeview
  */
 function __construct()
 {
     parent::__construct();
     parent::set_headers_visible(FALSE);
     $this->model = new GtkTreeStore(GObject::TYPE_OBJECT, GObject::TYPE_STRING, GObject::TYPE_PHP_VALUE, GObject::TYPE_STRING);
     parent::set_model($this->model);
     parent::connect('row-activated', array($this, 'onClick'));
     $column1 = new GtkTreeViewColumn();
     $cell_renderer1 = new GtkCellRendererPixbuf();
     $cell_renderer2 = new GtkCellRendererText();
     $column1->pack_start($cell_renderer1, false);
     $column1->pack_start($cell_renderer2, false);
     $column1->set_attributes($cell_renderer1, 'pixbuf', 0);
     $column1->set_attributes($cell_renderer2, 'text', 1);
     parent::append_column($column1);
 }
예제 #2
0
	/**
	 * Add a column (or more columns if you give it an array instead of a string) to a GtkTreeView(). Saves code.
	 * @param GtkTreeView $treeview The treeview which the function should add columns to.
	 * @param mixed $arrcolumn As a string, this would be the title of the one column added. As an array, this should be all the titles which should be added to the treeview as strings in the array.
	*/
	function treeview_addColumn(GtkTreeView $treeview, $arrcolumn){
		if (is_array($arrcolumn) && !$arrcolumn["type"] && !$arrcolumn["title"]){
			//Adding a liststore to the treeview.
			$eval = "\$ls = new GtkListStore(";
			$first = true;
			foreach($arrcolumn AS $column){
				if ($first == true){
					$first = false;
				}else{
					$eval .= ", ";
				}
				
				if (!is_array($column)){
					$type = "text";
				}else{
					$type = $column["type"];
				}
				
				if ($type == "text"){
					$eval .= "_TYPE_STRING";
				}elseif($type == "active"){
					$eval .= "_TYPE_BOOLEAN";
				}elseif($type == "int"){
					$eval .= "_TYPE_LONG";
				}else{
					throw new Exception("Invalid type: " . $type);
				}
				
				$count++;
			}
			$eval .= ");";
			eval($eval);
			
			$treeview->set_model($ls);
			$treeview->set_enable_search(true);
			
			//Add columns to the treeview.
			foreach($arrcolumn AS $value){
				treeview_addColumn($treeview, $value);
			}
		}else{
			$number = count($treeview->get_columns());
			
			if (is_array($arrcolumn)){
				$type = $arrcolumn["type"];
				$title = $arrcolumn["title"];
			}else{
				$title = $arrcolumn;
				$type = "text";
			}
			
			if ($type == "text" || $type == "int"){
				$render = new GtkCellRendererText();
				$type = "text";
			}elseif($type == "active"){
				$render = new GtkCellRendererToggle();
				$render->set_property("activatable", true);
			}else{
				throw new Exception("Invalid type: " . $type);
			}
			
			if (is_array($arrcolumn["connect"])){
				foreach($arrcolumn["connect"] AS $key => $value){
					$render->connect_after($key, $value);
				}
			}
			
			$column = new GtkTreeViewColumn($title, $render, $type, $number);
			$column->set_reorderable(true);
			$column->set_resizable(true);
			$column->set_clickable(true);
			$column->set_sort_column_id($number);
			$treeview->append_column($column);
			
			if (is_array($arrcolumn)){
				if ($arrcolumn["hidden"] == true){
					$column->set_visible(false);
				}
				
				if ($arrcolumn["searchcol"] == true){
					$treeview->set_search_column($number);
				}
				
				if ($arrcolumn["sortcol"] == true){
					if ($arrcolumn["sort"] == "desc"){
						$treeview->get_model()->set_sort_column_id($number, Gtk::SORT_DESCENDING);
					}else{
						$treeview->get_model()->set_sort_column_id($number, Gtk::SORT_ASCENDING);
					}
				}
			}
		}
	}
예제 #3
0
 protected function setup_treeview(GtkTreeView $view)
 {
     $this->store = new GtkTreeStore(Gobject::TYPE_STRING, Gobject::TYPE_STRING);
     $view->set_model($this->store);
     // Build Header
     $view->append_column(new GtkTreeViewColumn('4Chan Section', new GtkCellRendererText(), 'text', 0));
     $view->append_column(new GtkTreeViewColumn('Photo Count', new GtkCellRendererText(), 'text', 1));
     // Build Sections
     $root = $this->store->append(null, array('/w/ - Anime/Wallpapers', '0'));
     $root2 = $this->store->append(null, array('/wg/ - Wallpapers/General', '0'));
     // Build Threads
     $child1 = $this->store->append($root, array('Thread 23897346', '0'));
     $child2 = $this->store->append($root, array('Thread 23897347', '0'));
     $child3 = $this->store->append($root2, array('Thread 23897348', '0'));
     $child4 = $this->store->append($root2, array('Thread 23897349', '0'));
 }
$iter = $listStore->insert(2, array('Crisscott Pencils', 18, 0.99));
// Comment the above line and uncomment these two to test.
//$tmp = array('Crisscott Pencils', 18, .99);
//$iter = $listStore->insert(2, $tmp);
/**
 * Weird issue 2:
 * If insert is called twice, weird issue 1 is not a problem.
 * Uncomment the two following lines to test. 
 * Make sure weird issue 1 is commented just to isolate the
 * issue.
 */
//$iter = $listStore->insert(2, array('Crisscott Pencils', 18, .99));
//$iter = $listStore->insert(3, array('Crisscott Pens', 18, .99));
// Create a veiw to show the list.
$view = new GtkTreeView();
$view->set_model($listStore);
// Create columns for each type of data.
$column = new GtkTreeViewColumn();
$column->set_title('Product Name');
$view->insert_column($column, 0);
// Create a renderer for the column.
$cell_renderer = new GtkCellRendererText();
$column->pack_start($cell_renderer, true);
$column->set_attributes($cell_renderer, 'text', 0);
// Create columns for each type of data.
$column = new GtkTreeViewColumn();
$column->set_title('Inventory');
$view->insert_column($column, 1);
// Create a renderer for the column.
$cell_renderer = new GtkCellRendererText();
$column->pack_start($cell_renderer, true);
 /**
  * Cria o treeview apartir de um XML
  * 
  * @name treeviewLoadXML
  * @param string $file Caminho do arquivo XML com as definições do treeview
  * @param object $mainObject Objeto onde está os métodos callback do treeview 
  */
 public function treeviewLoadXML($file, $mainObject = NULL)
 {
     // Lê o XML
     $xml = new SimpleXMLElement(file_get_contents($file));
     // Seta a coluna para a busca
     $searchcolumn = isset($xml['searchcolumn']) ? (int) $xml['searchcolumn'] : 0;
     parent::set_search_column($searchcolumn);
     // Configura a visibilidade do header da coluna
     switch (strtoupper((string) $xml['hvisible'])) {
         case "FALSE":
             $hvisible = FALSE;
             break;
         case "TRUE":
         default:
             $hvisible = TRUE;
             break;
     }
     parent::set_headers_visible($hvisible);
     // Verifica se existe evento button-press-event
     $buttonpressevent = (string) $xml['buttonpressevent'];
     if (strlen($buttonpressevent) > 0) {
         // Verifica se é orientado à objeto
         if ($mainObject != NULL) {
             // Cria o método callback
             $function = array($mainObject, $buttonpressevent);
         } else {
             // Cria a função callback
             $function = $buttonpressevent;
         }
         parent::connect("button-press-event", $function);
     }
     // Verifica se existe evento cursor-changed
     $cursorchanged = (string) $xml['cursorchanged'];
     if (strlen($cursorchanged) > 0) {
         // Verifica se é orientado à objeto
         if ($mainObject != NULL) {
             // Cria o método callback
             $function = array($mainObject, $cursorchanged);
         } else {
             // Cria a função callback
             $function = $cursorchanged;
         }
         parent::connect("cursor-changed", $function);
     }
     // Percorre as configurações
     foreach ($xml as $configs) {
         // Verifica se são as configurações das colunas
         if ($configs->getName() == "columns") {
             // Percorre as colunas
             $counter = 0;
             $columnModel = array();
             foreach ($configs as $column) {
                 // Busca as configurações
                 $title = (string) $column['title'];
                 $visible = (string) $column['visible'];
                 // Cria a coluna
                 $modelType = Gobject::TYPE_STRING;
                 if (strtoupper($visible) != "FALSE") {
                     // Verifica o tipo e o render
                     switch (strtoupper((string) $column['type'])) {
                         // Toggle
                         case "TOGGLE":
                             // Cria o render
                             $render = new GtkCellRendererToggle();
                             $render->set_property("activatable", TRUE);
                             // Verifica se deve usar o autocheck
                             switch (strtoupper((string) $column['autocheck'])) {
                                 case "FALSE":
                                     break;
                                 case "TRUE":
                                 default:
                                     $render->connect("toggled", array($this, "__onToggle"), $counter);
                                     break;
                             }
                             // Verifica se existe evento onclick da coluna
                             $onclick = (string) $column['onclick'];
                             if (strlen($onclick) > 0) {
                                 // Verifica se é orientado à objeto
                                 if ($mainObject != NULL) {
                                     // Cria o método callback
                                     $function = array($mainObject, $onclick);
                                 } else {
                                     // Cria a função callback
                                     $function = $onclick;
                                 }
                                 // Conecta o callback de check
                                 $render->connect("toggled", $function, $counter);
                             }
                             // Armazena o atributo e o model
                             $attribute = "active";
                             $modelType = Gobject::TYPE_BOOLEAN;
                             break;
                             // Texto
                         // Texto
                         case "TEXT":
                         default:
                             $render = new GtkCellRendererText();
                             // Verifica se a coluna é editavel
                             switch (strtoupper((string) $column['editable'])) {
                                 case "TRUE":
                                     $render->set_property("editable", TRUE);
                                     break;
                                 case "FALSE":
                                 default:
                                     break;
                             }
                             // Verifica se existe sinal para edição
                             $onedited = (string) $column['onedited'];
                             if (strlen($onedited) > 0) {
                                 // Verifica se é orientado à objeto
                                 if ($mainObject != NULL) {
                                     // Cria o método callback
                                     $function = array($mainObject, $onedited);
                                 } else {
                                     // Cria a função callback
                                     $function = $onedited;
                                 }
                                 // Conecta a coluna ao callback
                                 $render->connect("edited", $function, $this, $counter);
                             }
                             // Armazena os atributos
                             $attribute = "text";
                             $modelType = Gobject::TYPE_STRING;
                     }
                     // Cria a coluna com as configurações
                     $trvColumn = new GtkTreeViewColumn($title, $render, $attribute, $counter);
                     parent::append_column($trvColumn);
                     // Verifica se existe parametrização do tamanho da coluna
                     if (isset($column['width'])) {
                         $trvColumn->set_fixed_width((int) $column['width']);
                         $trvColumn->set_sizing(Gtk::TREE_VIEW_COLUMN_FIXED);
                     }
                     // Verifica se existe parametrização da formatação
                     if (isset($column['onformat'])) {
                         $onformat = (string) $column['onformat'];
                         // Verifica se é orientado à objeto
                         if ($mainObject != NULL) {
                             // Cria o método callback
                             $function = array($mainObject, $onformat);
                         } else {
                             // Cria a função callback
                             $function = $onformat;
                         }
                         // Conecta o callback de renderização
                         $trvColumn->set_cell_data_func($render, $function, $counter);
                     }
                 }
                 // Armazena o model
                 $columnModel[$counter++] = $modelType;
             }
             // Seta o model
             $model = new GtkTreeStore();
             $model->set_column_types($columnModel);
             parent::set_model($model);
         }
     }
 }