Esempio n. 1
0
function uprav_startovku()
{
    global $G, $model, $view;
    $dialog = new GtkDialog();
    // note 1
    $viewport1 = new GtkViewPort();
    $dialog->set_title('Úprava štartovnej listiny');
    $dialog->set_position(GTK::WIN_POS_CENTER);
    $dialog->set_default_size(1024, 420);
    /*
    kat,
    c.
    meno
    priezvisko
    klub
    meno psa
    plemeno
    pp
    krajina
    VZ
    */
    $model = new GtkListStore(Gobject::TYPE_STRING, Gobject::TYPE_STRING, Gobject::TYPE_STRING, Gobject::TYPE_STRING, Gobject::TYPE_STRING, Gobject::TYPE_STRING, Gobject::TYPE_STRING, Gobject::TYPE_BOOLEAN, Gobject::TYPE_STRING, Gobject::TYPE_STRING);
    $view = new GtkTreeView($model);
    #	$view->set_grid_lines(Gtk::TREE_VIEW_GRID_LINES_BOTH);
    $column1 = new GtkTreeViewColumn('Kat');
    $column2 = new GtkTreeViewColumn('Št.Č.');
    $column3 = new GtkTreeViewColumn('Meno');
    $column4 = new GtkTreeViewColumn('Priezvisko');
    $column5 = new GtkTreeViewColumn('Klub');
    $column6 = new GtkTreeViewColumn('Meno psa');
    $column7 = new GtkTreeViewColumn('Plemeno');
    $column8 = new GtkTreeViewColumn('PP');
    $column9 = new GtkTreeViewColumn('Krajina');
    $column10 = new GtkTreeViewColumn('Číslo VZ');
    $view->append_column($column1);
    $view->append_column($column2);
    $view->append_column($column3);
    $view->append_column($column4);
    $view->append_column($column5);
    $view->append_column($column6);
    $view->append_column($column7);
    $view->append_column($column8);
    $view->append_column($column9);
    $view->append_column($column10);
    $cell_renderer1 = new GtkCellRendererCombo();
    $cell_renderer2 = new GtkCellRendererText();
    $cell_renderer3 = new GtkCellRendererText();
    $cell_renderer4 = new GtkCellRendererText();
    $cell_renderer5 = new GtkCellRendererText();
    $cell_renderer6 = new GtkCellRendererText();
    $cell_renderer7 = new GtkCellRendererText();
    $cell_renderer8 = new GtkCellRendererToggle();
    $cell_renderer9 = new GtkCellRendererText();
    $cell_renderer10 = new GtkCellRendererText();
    $category = new GtkListStore(Gobject::TYPE_STRING);
    // note 2
    $list = array('SA0', 'SA1', 'SA2', 'SA3', 'MA0', 'MA1', 'MA2', 'MA3', 'LA0', 'LA1', 'LA2', 'LA3');
    foreach ($list as $choice) {
        $category->append(array($choice));
        //n4 note3
    }
    $cell_renderer1->set_property('model', $category);
    // note 4
    $cell_renderer1->set_property('text-column', 0);
    // note 5
    $cell_renderer1->set_property('editable', true);
    // note 6
    $cell_renderer1->set_property('has-entry', true);
    // note 7
    /*
    	$category = new GtkListStore(Gobject::TYPE_STRING); // note 2
    	$list = array('sk', 'cz', 'hu', 'si', 'cr', 'at', 'pl', 'ru');
    	foreach($list as $choice) {
    	    $category->append(array($choice)); //n4 note3
    	}
    	$cell_renderer9->set_property('model', $category); // note 4
    	$cell_renderer9->set_property('text-column', 0); // note 5
    	$cell_renderer9->set_property('editable', true); // note 6
    	$cell_renderer9->set_property('has-entry', true); // note 7 
    */
    $cell_renderer1->set_property('width', 50);
    $cell_renderer1->set_property('editable', true);
    $cell_renderer2->set_property('width', 30);
    $cell_renderer2->set_property('editable', true);
    $cell_renderer3->set_property('width', 110);
    $cell_renderer3->set_property('editable', true);
    $cell_renderer4->set_property('width', 110);
    $cell_renderer4->set_property('editable', true);
    $cell_renderer5->set_property('width', 120);
    $cell_renderer5->set_property('editable', true);
    $cell_renderer6->set_property('width', -1);
    $cell_renderer6->set_property('editable', true);
    $cell_renderer7->set_property('width', 100);
    $cell_renderer7->set_property('editable', true);
    $cell_renderer8->set_property('width', 40);
    $cell_renderer8->set_property('editable', true);
    $cell_renderer9->set_property('width', 50);
    $cell_renderer9->set_property('editable', true);
    $cell_renderer10->set_property('width', 50);
    $cell_renderer10->set_property('editable', true);
    $cell_renderer1->connect('edited', 'callback_start1');
    $cell_renderer2->connect('edited', 'callback_start2');
    $cell_renderer3->connect('edited', 'callback_start3');
    $cell_renderer4->connect('edited', 'callback_start4');
    $cell_renderer5->connect('edited', 'callback_start5');
    $cell_renderer6->connect('edited', 'callback_start6');
    $cell_renderer7->connect('edited', 'callback_start7');
    $cell_renderer8->connect('toggled', 'callback_start8');
    $cell_renderer9->connect('edited', 'callback_start9');
    $cell_renderer10->connect('edited', 'callback_start10');
    #$cell_renderer3->set_property('width', -1);
    $column1->pack_start($cell_renderer1, true);
    $column2->pack_start($cell_renderer2, true);
    $column3->pack_start($cell_renderer3, true);
    $column4->pack_start($cell_renderer4, true);
    $column5->pack_start($cell_renderer5, true);
    $column6->pack_start($cell_renderer6, true);
    $column7->pack_start($cell_renderer7, true);
    $column8->pack_start($cell_renderer8, true);
    $column9->pack_start($cell_renderer9, true);
    $column10->pack_start($cell_renderer10, true);
    $column1->set_attributes($cell_renderer1, 'text', 0);
    $column2->set_attributes($cell_renderer2, 'text', 1);
    $column3->set_attributes($cell_renderer3, 'text', 2);
    $column4->set_attributes($cell_renderer4, 'text', 3);
    $column5->set_attributes($cell_renderer5, 'text', 4);
    $column6->set_attributes($cell_renderer6, 'text', 5);
    $column7->set_attributes($cell_renderer7, 'text', 6);
    $column8->set_attributes($cell_renderer8, 'active', 7);
    $column9->set_attributes($cell_renderer9, 'text', 8);
    $column10->set_attributes($cell_renderer10, 'text', 9);
    #var_export($G["startovka"]);exit;
    #for($i=0;$i<count($G["startovka"]);$i++) {
    #	$model->append($G["startovka"][$i]);
    #	}
    foreach ($G["startovka"] as $r) {
        while (count($r) < 10) {
            $r[] = "";
        }
        for ($i = 0; $i < count($r); $i++) {
            $r[$i] = $r[$i];
        }
        $model->append($r);
    }
    $toolbar = new GtkHButtonBox();
    $addbutton = GtkButton::new_from_stock(Gtk::STOCK_ADD);
    $deletebutton = GtkButton::new_from_stock(Gtk::STOCK_DELETE);
    $loadbutton = GtkButton::new_from_stock(Gtk::STOCK_REFRESH);
    $savebutton = GtkButton::new_from_stock(Gtk::STOCK_SAVE);
    $savebutton->connect("pressed", "uloz_udaje");
    $addbutton->connect("pressed", "pridaj_riadok");
    $deletebutton->connect("pressed", "vymaz_riadok");
    $toolbar->add($addbutton);
    $toolbar->add($deletebutton);
    $toolbar->add($loadbutton);
    $toolbar->add($savebutton);
    $toolbar->set_size_request(0, 40);
    $sw = new GtkScrolledWindow();
    $sw->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
    $sw->add($view);
    $sw->set_size_request(-1, 560);
    $vbox = new GtkVBox();
    $vbox->add($toolbar);
    $vbox->add($sw);
    $dialog->vbox->pack_start($vbox);
    // note 3
    $dialog->show_all();
    // note 4
    $dialog->run();
    // note 5
    $dialog->destroy();
    // note 6
}
 public function treeviewLoadXML($file, $mainObject = NULL)
 {
     // Lê o XML
     // @since rev 1
     $xml = new SimpleXMLElement(file_get_contents($file));
     // Cria o frame, o scrool e o treeview
     // @since rev 1
     $treeviewName = (string) $xml['name'];
     $obj['treeview'] = new GtkTreeView();
     $scrolled = new GtkScrolledWindow();
     $scrolled->add($obj['treeview']);
     $obj['object'] = new GtkFrame();
     $obj['object']->add($scrolled);
     // Verifica o modo do scroll horizontal
     // @since rev 1
     switch (strtoupper((string) $xml['hscroll'])) {
         case "TRUE":
             $hscroll = Gtk::POLICY_ALWAYS;
             break;
         case "FALSE":
             $hscroll = Gtk::POLICY_NEVER;
             break;
         case "AUTO":
         default:
             $hscroll = Gtk::POLICY_AUTOMATIC;
             break;
     }
     // Verifica o modo do scroll vertical
     // @since rev 1
     switch (strtoupper((string) $xml['vscroll'])) {
         case "TRUE":
             $vscroll = Gtk::POLICY_ALWAYS;
             break;
         case "FALSE":
             $vscroll = Gtk::POLICY_NEVER;
             break;
         case "AUTO":
         default:
             $vscroll = Gtk::POLICY_AUTOMATIC;
             break;
     }
     // Configura os scrolls
     // @since rev 1
     $scrolled->set_policy($hscroll, $vscroll);
     // Configura o tamanho
     // @since rev 1
     $width = isset($xml['width']) ? (int) $xml['width'] : FALSE;
     $height = isset($xml['height']) ? (int) $xml['height'] : FALSE;
     $scrolled->set_size_request($width, $height);
     // Seta a coluna para a busca
     // @since rev 1
     $searchcolumn = isset($xml['searchcolumn']) ? (int) $xml['searchcolumn'] : 0;
     $obj['treeview']->set_search_column($searchcolumn);
     // Configura a visibilidade do header da coluna
     // @since rev 1
     switch (strtoupper((string) $xml['hvisible'])) {
         case "FALSE":
             $hvisible = FALSE;
             break;
         case "TRUE":
         default:
             $hvisible = TRUE;
             break;
     }
     $obj['treeview']->set_headers_visible($hvisible);
     // Verifica se existe evento button-press-event
     // @since rev 1
     $buttonpressevent = (string) $xml['buttonpressevent'];
     if (strlen($buttonpressevent) > 0) {
         // Verifica se é orientado à objeto
         // @since rev 1
         if ($mainObject != NULL) {
             $function = array($mainObject, $buttonpressevent);
         } else {
             $function = $buttonpressevent;
         }
         $obj['treeview']->connect("button-press-event", $function);
     }
     // Verifica se existe evento cursor-changed
     // @since rev 1
     $cursorchanged = (string) $xml['cursorchanged'];
     if (strlen($cursorchanged) > 0) {
         // Verifica se é orientado à objeto
         // @since rev 1
         if ($mainObject != NULL) {
             $function = array($mainObject, $cursorchanged);
         } else {
             $function = $cursorchanged;
         }
         $obj['treeview']->connect("cursor-changed", $function);
     }
     // Percorre as configurações
     // @since rev 1
     foreach ($xml as $configs) {
         // Verifica o tipo de configuração
         // @since rev 1
         if ($configs->getName() == "columns") {
             // Percorre as colunas
             // @since rev 1
             $counter = 0;
             $columnModel = array();
             foreach ($configs as $column) {
                 // Busca as configurações
                 $title = (string) $column['title'];
                 $visible = (string) $column['visible'];
                 // Cria a coluna
                 // @since rev 1
                 $modelType = Gobject::TYPE_STRING;
                 if (strtoupper($visible) != "FALSE") {
                     // Verifica o tipo e o render
                     // @since rev 1
                     switch (strtoupper((string) $column['type'])) {
                         // Toggle
                         // @since rev 1
                         case "TOGGLE":
                             // Cria o render
                             // @since rev 1
                             $render = new GtkCellRendererToggle();
                             $render->set_property("activatable", TRUE);
                             // Verifica se deve usar o autocheck
                             // @since rev 1
                             switch (strtoupper((string) $column['autocheck'])) {
                                 case "FALSE":
                                     break;
                                 case "TRUE":
                                 default:
                                     $render->connect("toggled", array("FTreeViews", "on_toggle"), $obj['treeview'], $counter);
                                     break;
                             }
                             // Verifica se existe evento onclick da coluna
                             // @since rev 1
                             $onclick = (string) $column['onclick'];
                             if (strlen($onclick) > 0) {
                                 // Verifica se é orientado à objeto
                                 // @since rev 1
                                 if ($mainObject != NULL) {
                                     $function = array($mainObject, $onclick);
                                 } else {
                                     $function = $onclick;
                                 }
                                 $render->connect("toggled", $function, $obj['treeview'], $counter);
                             }
                             // Armazena o atributo e o model
                             // @since rev 1
                             $attribute = "active";
                             $modelType = Gobject::TYPE_BOOLEAN;
                             break;
                             // Texto
                             // @since rev 1
                         // Texto
                         // @since rev 1
                         case "TEXT":
                         default:
                             $render = new GtkCellRendererText();
                             // Verifica se a coluna é editavel
                             // @since rev 1
                             switch (strtoupper((string) $column['editable'])) {
                                 case "TRUE":
                                     $render->set_property("editable", TRUE);
                                     break;
                                 case "FALSE":
                                 default:
                                     break;
                             }
                             // Verifica se existe sinal para edição
                             // @since rev 1
                             $onedited = (string) $column['onedited'];
                             if (strlen($onedited) > 0) {
                                 // Verifica se é orientado à objeto
                                 // @since rev 1
                                 if ($mainObject != NULL) {
                                     $function = array($mainObject, $onedited);
                                 } else {
                                     $function = $onedited;
                                 }
                                 $render->connect("edited", $function, $obj['treeview'], $counter);
                             }
                             $attribute = "text";
                             $modelType = Gobject::TYPE_STRING;
                     }
                     // Cria a coluna
                     // @since rev 1
                     $trvColumn = new GtkTreeViewColumn($title, $render, $attribute, $counter);
                     $obj['treeview']->append_column($trvColumn);
                     // Verifica se existe parametrização do tamanho
                     // @since rev 1
                     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) {
                             $function = array($mainObject, $onformat);
                         } else {
                             $function = $onformat;
                         }
                         $trvColumn->set_cell_data_func($render, $function, $counter);
                     }
                 }
                 // Armazena o model
                 // @since rev 1
                 $columnModel[$counter++] = $modelType;
             }
             // Seta o model
             // @since rev 1
             $model = new GtkTreeStore();
             $model->set_column_types($columnModel);
             $obj['treeview']->set_model($model);
         }
     }
     return $obj;
 }
Esempio n. 3
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);
					}
				}
			}
		}
	}
 /**
  * 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);
         }
     }
 }