diff options
| author | polo <ordipolo@gmx.fr> | 2022-11-25 03:59:32 +0100 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2022-11-25 03:59:32 +0100 |
| commit | efe371fd6e883dde99ca6d90a7aae99eb4aeadea (patch) | |
| tree | 54b342e58e4e3908abf5f42c85680d32540dd7f3 /php/ZenityClasses.php | |
| download | AppliGestionPHP-efe371fd6e883dde99ca6d90a7aae99eb4aeadea.tar.gz AppliGestionPHP-efe371fd6e883dde99ca6d90a7aae99eb4aeadea.tar.bz2 AppliGestionPHP-efe371fd6e883dde99ca6d90a7aae99eb4aeadea.zip | |
première sauvegarde git
Diffstat (limited to 'php/ZenityClasses.php')
| -rw-r--r-- | php/ZenityClasses.php | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/php/ZenityClasses.php b/php/ZenityClasses.php new file mode 100644 index 0000000..c286d14 --- /dev/null +++ b/php/ZenityClasses.php | |||
| @@ -0,0 +1,111 @@ | |||
| 1 | <?php | ||
| 2 | // php/ZenityClasses.php | ||
| 3 | // | ||
| 4 | // commande système zenity | ||
| 5 | |||
| 6 | abstract class Zenity_cmd | ||
| 7 | { | ||
| 8 | protected $command = 'zenity'; | ||
| 9 | protected $command_type = ''; | ||
| 10 | protected $rows = []; | ||
| 11 | private $title = 'ORDIPOLO'; | ||
| 12 | private $text = ''; | ||
| 13 | protected $width = 300; | ||
| 14 | protected $height = 200; // recalculée en fonction du contenu, vaut au minimum 150 | ||
| 15 | |||
| 16 | |||
| 17 | protected function __construct($text, array $rows = []) // $rows est optionnel | ||
| 18 | { | ||
| 19 | $this->text = $text; | ||
| 20 | $this->rows= $rows; | ||
| 21 | $this->command .= $this->command_type; | ||
| 22 | $this->command .= ' --title="' . $this->title . '"'; | ||
| 23 | $this->command .= ' --text="' . $this->text . '"'; | ||
| 24 | } | ||
| 25 | |||
| 26 | public function get() | ||
| 27 | { | ||
| 28 | return($this->command); | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | |||
| 33 | class Zenity_list extends Zenity_cmd | ||
| 34 | { | ||
| 35 | public function __construct($text, array $rows) | ||
| 36 | { | ||
| 37 | $this->command_type = ' --list'; | ||
| 38 | parent::__construct($text, $rows); | ||
| 39 | $this->height = 80 + count($this->rows) * 25; | ||
| 40 | $this->command .= ' --width=' . $this->width; | ||
| 41 | $this->command .= ' --height=' . $this->height; | ||
| 42 | $this->command .= ' --hide-header'; // ligne inutile, il y a déjà le --text | ||
| 43 | self::one_column_zenity_list($this->rows); | ||
| 44 | } | ||
| 45 | |||
| 46 | public function set_entries($rows_set) // variable renseignée après la construction | ||
| 47 | { | ||
| 48 | $this->rows = $rows_set; | ||
| 49 | } | ||
| 50 | |||
| 51 | private function one_column_zenity_list($rows) | ||
| 52 | { | ||
| 53 | $output = ' --column=""'; | ||
| 54 | foreach($rows as $entry) | ||
| 55 | { | ||
| 56 | $output .= ' "' . $entry . '"'; // forme: ' "choix 1" "choix 2"' | ||
| 57 | } | ||
| 58 | $this->command .= $output; | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | class Zenity_question extends Zenity_cmd | ||
| 63 | { | ||
| 64 | public function __construct($text) | ||
| 65 | { | ||
| 66 | $this->command_type = ' --question'; | ||
| 67 | parent::__construct($text); | ||
| 68 | $this->command .= ' && echo $?'; | ||
| 69 | // la sortie de "zenity --question" est le statut de sortie "$?" | ||
| 70 | // $? vaut 0 pour oui, 1 pour non, à ceci près que pour non zenity ne renvoie rien | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | class Zenity_forms extends Zenity_cmd | ||
| 75 | { | ||
| 76 | public function __construct($text, array $rows) | ||
| 77 | { | ||
| 78 | $this->command_type = ' --forms'; | ||
| 79 | parent::__construct($text, $rows); | ||
| 80 | //$this->height = 80 + count($this->rows) * 25; // à tester, mais devrait produire le rendu attendu | ||
| 81 | self::entries_zenity_forms($this->rows); | ||
| 82 | } | ||
| 83 | |||
| 84 | private function entries_zenity_forms($entries) | ||
| 85 | { | ||
| 86 | $output = ''; | ||
| 87 | foreach($entries as $one_entry) | ||
| 88 | { | ||
| 89 | $output .= ' --add-entry="' . $one_entry . '"'; // forme: ' "choix 1" "choix 2"' | ||
| 90 | } | ||
| 91 | $this->command .= $output; | ||
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 95 | class Zenity_calendar extends Zenity_cmd | ||
| 96 | { | ||
| 97 | public function __construct($text) | ||
| 98 | { | ||
| 99 | $this->command_type = ' --calendar'; | ||
| 100 | parent::__construct($text); | ||
| 101 | } | ||
| 102 | } | ||
| 103 | |||
| 104 | class Zenity_entry extends Zenity_cmd | ||
| 105 | { | ||
| 106 | public function __construct($text) | ||
| 107 | { | ||
| 108 | $this->command_type = ' --entry'; | ||
| 109 | parent::__construct($text); | ||
| 110 | } | ||
| 111 | } | ||
