blob: a04b794952f788526fa5e299129b853df856fd12 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
<?php
// php/Zenity.php
//
// commande système zenity
abstract class ZenityCmd
{
protected $command = 'zenity';
protected $command_type = '';
protected $rows = [];
private $title = 'ORDIPOLO';
private $text = '';
protected $width = 300;
protected $height = 200; // recalculée en fonction du contenu, vaut au minimum 150
protected function __construct($text, array $rows = []) // $rows est optionnel
{
$this->text = $text;
$this->rows= $rows;
$this->command .= $this->command_type;
$this->command .= ' --title="' . $this->title . '"';
$this->command .= ' --text="' . $this->text . '"';
}
public function get()
{
return($this->command);
}
}
class ZenityList extends ZenityCmd
{
public function __construct($text, array $rows)
{
$this->command_type = ' --list';
parent::__construct($text, $rows);
$this->height = 80 + count($this->rows) * 25;
$this->command .= ' --width=' . $this->width;
$this->command .= ' --height=' . $this->height;
$this->command .= ' --hide-header'; // ligne inutile, il y a déjà le --text
self::one_column_zenity_list($this->rows);
}
public function set_entries($rows_set) // variable renseignée après la construction
{
$this->rows = $rows_set;
}
private function one_column_zenity_list($rows)
{
$output = ' --column=""';
foreach($rows as $entry)
{
$output .= ' "' . $entry . '"'; // forme: ' "choix 1" "choix 2"'
}
$this->command .= $output;
}
}
class ZenityQuestion extends ZenityCmd
{
public function __construct($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
}
}
class ZenityForms extends ZenityCmd
{
public function __construct($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
self::entries_zenity_forms($this->rows);
}
private function entries_zenity_forms($entries)
{
$output = '';
foreach($entries as $one_entry)
{
$output .= ' --add-entry="' . $one_entry . '"'; // forme: ' "choix 1" "choix 2"'
}
$this->command .= $output;
}
}
class ZenityCalendar extends ZenityCmd
{
public function __construct($text)
{
$this->command_type = ' --calendar';
parent::__construct($text);
}
}
class ZenityEntry extends ZenityCmd
{
public function __construct($text)
{
$this->command_type = ' --entry';
parent::__construct($text);
}
}
|