public function __construct()
 {
     $this->frame = new GtkFrame();
     $frameBox = new GtkVBox(false, 10);
     $frameBox->set_border_width(10);
     $titleBox = new GtkHBox(false, 10);
     $titleLabel = new GtkLabel("Users");
     $titleLabel->set_markup("<span weight='bold'>Users</span>");
     $titleLabel->set_alignment(0, 0.5);
     $this->statusLabel = new GtkLabel("");
     $this->statusLabel->set_alignment(1, 0.5);
     $titleBox->pack_start($titleLabel, true, true, 0);
     $titleBox->pack_end($this->statusLabel, true, true, 0);
     $frameBox->pack_start($titleBox, false, false, 0);
     $this->frame->add($frameBox);
     $this->userListStore = new GtkRefListStore(Gobject::TYPE_STRING, Gobject::TYPE_STRING, Gobject::TYPE_STRING, Gobject::TYPE_STRING, Gobject::TYPE_STRING);
     $this->userListTree = new GtkRefTreeView($this->userListStore);
     $this->userListTree->set_rules_hint(true);
     $usersWindow = new GtkScrolledWindow();
     $usersWindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
     $usersWindow->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
     $usersWindow->add($this->userListTree);
     $frameBox->pack_start($usersWindow, true, true, 0);
     $cols = array('Username', 'First Name', 'Last Name', 'Email', 'Department');
     foreach ($cols as $num => $item) {
         $renderer = new GtkCellRendererText();
         $renderer->set_property("editable", false);
         $column = new GtkTreeViewColumn($item, $renderer, "text", $num);
         $column->set_sort_column_id($num);
         $column->set_expand(true);
         $column->set_resizable(true);
         $this->userListTree->append_column($column);
     }
     $userSelection = $this->userListTree->get_selection();
     $userSelection->set_mode(Gtk::SELECTION_SINGLE);
     $userSelection->connect('changed', array($this, 'isSelected'));
     $this->newButton = new GtkButton("New");
     $this->newButton->connect('clicked', array($this, 'deSelect'));
     $this->delButton = new GtkButton("Delete");
     $this->delButton->set_sensitive(false);
     $this->delButton->connect('clicked', array($this, 'confirmDeletion'));
     $buttonBox = new GtkHBox(false, 8);
     $buttonBox->pack_end($this->newButton, false, false, 0);
     $buttonBox->pack_end($this->delButton, false, false, 0);
     $frameBox->pack_end($buttonBox, false, false, 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);
					}
				}
			}
		}
	}
Exemple #3
0
 function new_column($label, $cell_type, $index)
 {
     //check cell type
     if ($cell_type == 'text') {
         $this->celulas[$index] = new GtkCellRendererText();
     } elseif ($cell_type == 'active') {
         $this->celulas[$index] = new GtkCellRendererToggle();
         $this->celulas[$index]->connect('toggled', array($this, 'sel_toggled'));
     } elseif ($cell_type == 'pixbuf') {
         $this->celulas[$index] = new GtkCellRendererPixbuf();
     }
     $column = new GtkTreeViewColumn($label, $this->celulas[$index], $cell_type, $index);
     $column->set_reorderable(true);
     $column->set_sort_column_id($index);
     $column->set_resizable(true);
     $column->connect('clicked', array($this, 'column_clicked'));
     $this->treeview->append_column($column);
     return $column;
 }