summaryrefslogtreecommitdiff
path: root/php/Zenity.php
diff options
context:
space:
mode:
Diffstat (limited to 'php/Zenity.php')
-rw-r--r--php/Zenity.php110
1 files changed, 110 insertions, 0 deletions
diff --git a/php/Zenity.php b/php/Zenity.php
new file mode 100644
index 0000000..a04b794
--- /dev/null
+++ b/php/Zenity.php
@@ -0,0 +1,110 @@
1<?php
2// php/Zenity.php
3//
4// commande système zenity
5
6abstract class ZenityCmd
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 protected function __construct($text, array $rows = []) // $rows est optionnel
17 {
18 $this->text = $text;
19 $this->rows= $rows;
20 $this->command .= $this->command_type;
21 $this->command .= ' --title="' . $this->title . '"';
22 $this->command .= ' --text="' . $this->text . '"';
23 }
24
25 public function get()
26 {
27 return($this->command);
28 }
29}
30
31
32class ZenityList extends ZenityCmd
33{
34 public function __construct($text, array $rows)
35 {
36 $this->command_type = ' --list';
37 parent::__construct($text, $rows);
38 $this->height = 80 + count($this->rows) * 25;
39 $this->command .= ' --width=' . $this->width;
40 $this->command .= ' --height=' . $this->height;
41 $this->command .= ' --hide-header'; // ligne inutile, il y a déjà le --text
42 self::one_column_zenity_list($this->rows);
43 }
44
45 public function set_entries($rows_set) // variable renseignée après la construction
46 {
47 $this->rows = $rows_set;
48 }
49
50 private function one_column_zenity_list($rows)
51 {
52 $output = ' --column=""';
53 foreach($rows as $entry)
54 {
55 $output .= ' "' . $entry . '"'; // forme: ' "choix 1" "choix 2"'
56 }
57 $this->command .= $output;
58 }
59}
60
61class ZenityQuestion extends ZenityCmd
62{
63 public function __construct($text)
64 {
65 $this->command_type = ' --question';
66 parent::__construct($text);
67 $this->command .= ' && echo $?';
68 // la sortie de "zenity --question" est le statut de sortie "$?"
69 // $? vaut 0 pour oui, 1 pour non, à ceci près que pour non zenity ne renvoie rien
70 }
71}
72
73class ZenityForms extends ZenityCmd
74{
75 public function __construct($text, array $rows)
76 {
77 $this->command_type = ' --forms';
78 parent::__construct($text, $rows);
79 //$this->height = 80 + count($this->rows) * 25; // à tester, mais devrait produire le rendu attendu
80 self::entries_zenity_forms($this->rows);
81 }
82
83 private function entries_zenity_forms($entries)
84 {
85 $output = '';
86 foreach($entries as $one_entry)
87 {
88 $output .= ' --add-entry="' . $one_entry . '"'; // forme: ' "choix 1" "choix 2"'
89 }
90 $this->command .= $output;
91 }
92}
93
94class ZenityCalendar extends ZenityCmd
95{
96 public function __construct($text)
97 {
98 $this->command_type = ' --calendar';
99 parent::__construct($text);
100 }
101}
102
103class ZenityEntry extends ZenityCmd
104{
105 public function __construct($text)
106 {
107 $this->command_type = ' --entry';
108 parent::__construct($text);
109 }
110}