get()); abstract class ZenityCmd { protected string $command = 'zenity'; protected string $command_type; protected array $rows; protected string $text; protected int $width = 300; protected int $height = 200; // recalculée en fonction du contenu, vaut au minimum 150 protected function __construct(string $text, array $rows = []) // $rows est optionnel { $this->text = $text; $this->rows= $rows; $this->command .= $this->command_type; $this->command .= ' --title="' . Config::$business_name . '"'; $this->command .= ' --text="' . $this->text . '"'; } public function get(): string { //echo $this->command . "\n"; return($this->command); } } class ZenityList extends ZenityCmd { private $columns = 1; // tableau simple ou multidimensionnel? public function __construct(string $text, array $rows = []) { $this->command_type = ' --list'; parent::__construct($text, $rows); //$this->columns = 1; $this->command .= ' --hide-header'; // ligne inutile, il y a déjà le --text if($this->rows !== []) { $this->command .= ' --width=' . (string)$this->width; $this->height = 80 + count($this->rows) * 25; $this->command .= ' --height=' . $this->height; $this->fillZenityList(); } } // cas ou $this->rows n'est pas renseignée dans le constructeur // la valeur de $columns n'est plus nécessairement celle par défaut public function setListRows(array $rows, int $columns, float $widen = 1) { // si 1 colonne, $rows = tableau à une dimension // si 2 colonnes ou plus, $rows = tableau à deux dimensions $this->rows = $rows; $this->columns = $columns; $this->width = $this->columns * 120 * $widen; $this->height = 91 + count($this->rows) * 25; // inclut les lignes et la barre de défilement horizontale $this->command .= ' --width=' . (string)$this->width; $this->command .= ' --height=' . (string)$this->height; $this->fillZenityList(); } // noter que la syntaxe de zenity --list est déroutante! // le remplissage est horizontal et le nombre de colonne dépend du nombre d'occurence de --column="" public function fillZenityList() { $output = ''; if($this->columns === 1) // $this->rows doit être un tableau { $output .= ' --column=""'; // remplissage vertical foreach($this->rows as $one_row) { $output .= ' "' . $one_row . '"'; // forme: ' "choix 1" "choix 2"' } } elseif($this->columns >= 2) // $this->rows doit être un tableau à deux dimensions // marche quelque soit le nombre de colonnes { for($i = 0; $i < $this->columns; $i++) { $output .= ' --column=""'; } // remplissage horizontal, un sous-tableau = une ligne foreach($this->rows as $one_row) { foreach($one_row as $one_field) { $output .= ' "' . $one_field . '"'; } } } $this->command .= $output; } /*public function cleanCommand() { $this->command = 'zenity'; $this->__construct($this->text); }*/ } class ZenityQuestion extends ZenityCmd { public function __construct(string $text) { $this->command_type = ' --question'; parent::__construct($text); $this->command .= ' && echo $?'; // la sortie de "zenity --question" est le statut de sortie "$?" // $? vaut 0 pour oui, 1 pour non, à ceci près que pour non zenity ne renvoie rien } } // note: le formulaire renvoie une chaine avec des pipes | entre les zones de texte (qui peuvent être vides) // si on clique sur 'Annuler', renvoie une chaine vide class ZenityForms extends ZenityCmd { public function __construct(string $text, array $rows) { $this->command_type = ' --forms'; parent::__construct($text, $rows); //$this->height = 80 + count($this->rows) * 25; // à tester, mais devrait produire le rendu attendu $this->entriesZenityForms($this->rows); } private function entriesZenityForms(array $input) { $output = ''; foreach($input as $one_question) { $output .= ' --add-entry="' . $one_question . '"'; // forme: ' "choix 1" "choix 2"' } $this->command .= $output; } } class ZenityCalendar extends ZenityCmd { public function __construct(string $text) { $this->command_type = ' --calendar'; parent::__construct($text); } } class ZenityEntry extends ZenityCmd { public function __construct(string $text) { $this->command_type = ' --entry'; parent::__construct($text); } }