Skip to content

Commit 28ca26e

Browse files
committed
Improve documentation and examples
1 parent e377ce1 commit 28ca26e

File tree

9 files changed

+59
-66
lines changed

9 files changed

+59
-66
lines changed

README.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# clue/reactphp-zenity
22

3-
[![CI status](https://github.com/clue/reactphp-zenity/workflows/CI/badge.svg)](https://github.com/clue/reactphp-zenity/actions)
3+
[![CI status](https://github.com/clue/reactphp-zenity/actions/workflows/ci.yml/badge.svg)](https://github.com/clue/reactphp-zenity/actions)
44
[![installs on Packagist](https://img.shields.io/packagist/dt/clue/zenity-react?color=blue&label=installs%20on%20Packagist)](https://packagist.org/packages/clue/zenity-react)
55

66
Zenity allows you to build graphical desktop (GUI) applications in PHP, built on top of [ReactPHP](https://reactphp.org/).
@@ -61,6 +61,10 @@ Once [installed](#install), you can use the following code to open a prompt
6161
asking the user for his name and presenting it in another info dialog.
6262

6363
```php
64+
<?php
65+
66+
require __DIR__ . '/vendor/autoload.php';
67+
6468
$launcher = new Clue\React\Zenity\Launcher();
6569

6670
$entry = new EntryDialog();
@@ -69,10 +73,12 @@ $entry->setEntryText(getenv('USER')); // prefill with current user
6973

7074
$launcher->launch($entry)->then(function ($name) use ($launcher) {
7175
$launcher->launch(new InfoDialog('Welcome to zenity-react, ' . $name .'!'));
76+
}, function (Exception $e) {
77+
echo 'Error: ' . $e->getMessage() . PHP_EOL;
7278
});
7379
```
7480

75-
Looking for more examples? Take a look at the [examples](examples) folder.
81+
Looking for more examples? Take a look at the [examples](examples/) folder.
7682

7783
## Usage
7884

@@ -152,6 +158,8 @@ Loop::addTimer(3.0, function () use ($zen) {
152158

153159
$zen->promise()->then(function ($result) {
154160
// dialog completed
161+
}, function (Exception $e) {
162+
echo 'Error: ' . $e->getMessage() . PHP_EOL;
155163
});
156164
```
157165

@@ -292,29 +300,29 @@ $builder->warning($text, $title = null);
292300

293301
## Install
294302

295-
The recommended way to install this library is [through Composer](https://getcomposer.org).
303+
The recommended way to install this library is [through Composer](https://getcomposer.org/).
296304
[New to Composer?](https://getcomposer.org/doc/00-intro.md)
297305

298306
This will install the latest supported version:
299307

300308
```bash
301-
$ composer require clue/zenity-react:^0.4.4
309+
composer require clue/zenity-react:^0.4.4
302310
```
303311

304312
See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.
305313

306314
This project aims to run on any platform and thus does not require any PHP
307315
extensions and supports running on legacy PHP 5.3 through current PHP 8+ and
308316
HHVM.
309-
It's *highly recommended to use PHP 7+* for this project.
317+
It's *highly recommended to use the latest supported PHP version* for this project.
310318

311319
Obviously, this library requires the Zenity binary itself.
312320
Zenity already ships with Ubuntu-based distributions and should not require any installation there.
313321
On Debian- and Ubuntu-based distributions you can make sure it's installed like this:
314322

315323
```bash
316324
# usually not required
317-
$ sudo apt-get install zenity
325+
sudo apt-get install zenity
318326
```
319327

320328
Otherwise you may have to install Zenity yourself (use your favorite search engine, download the appropriate release tarball or compile from source).
@@ -332,16 +340,16 @@ $launcher->setBin('/path/to/zenity');
332340
## Tests
333341

334342
To run the test suite, you first need to clone this repo and then install all
335-
dependencies [through Composer](https://getcomposer.org):
343+
dependencies [through Composer](https://getcomposer.org/):
336344

337345
```bash
338-
$ composer install
346+
composer install
339347
```
340348

341349
To run the test suite, go to the project root and run:
342350

343351
```bash
344-
$ php vendor/bin/phpunit
352+
vendor/bin/phpunit
345353
```
346354

347355
## License

examples/01-dialog.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
11
<?php
22

3-
use Clue\React\Zenity\Launcher;
4-
use Clue\React\Zenity\Dialog\InfoDialog;
5-
use Clue\React\Zenity\Dialog\QuestionDialog;
6-
use Clue\React\Zenity\Dialog\ErrorDialog;
7-
use Clue\React\Zenity\Dialog\EntryDialog;
8-
use Clue\React\Zenity\Dialog\WarningDialog;
9-
103
require __DIR__ . '/../vendor/autoload.php';
114

12-
$launcher = new Launcher();
5+
$launcher = new Clue\React\Zenity\Launcher();
136

14-
$q = new EntryDialog('What\'s your name?');
7+
$q = new Clue\React\Zenity\Dialog\EntryDialog('What\'s your name?');
158
$q->setEntryText(getenv('USER'));
169
$q->setTitle('Enter your name');
1710

1811
$launcher->launch($q)->then(function ($name) use ($launcher) {
19-
$launcher->launch(new InfoDialog('Welcome to the introduction of zenity, ' . $name))->then(function () use ($launcher) {
20-
$launcher->launch(new QuestionDialog('Do you want to quit?'))->then(function () use ($launcher) {
21-
$launcher->launch(new ErrorDialog('Oh noes!'));
12+
$launcher->launch(new Clue\React\Zenity\Dialog\InfoDialog('Welcome to the introduction of zenity, ' . $name))->then(function () use ($launcher) {
13+
$launcher->launch(new Clue\React\Zenity\Dialog\QuestionDialog('Do you want to quit?'))->then(function () use ($launcher) {
14+
$launcher->launch(new Clue\React\Zenity\Dialog\ErrorDialog('Oh noes!'));
2215
}, function() use ($launcher) {
23-
$launcher->launch(new WarningDialog('You should have selected yes!'));
16+
$launcher->launch(new Clue\React\Zenity\Dialog\WarningDialog('You should have selected yes!'));
2417
});
18+
}, function (Exception $e) {
19+
echo 'Error: ' . $e->getMessage() . PHP_EOL;
2520
});
2621
}, function () use ($launcher) {
27-
$launcher->launch(new WarningDialog('No name given'));
22+
$launcher->launch(new Clue\React\Zenity\Dialog\WarningDialog('No name given'));
2823
});

examples/02-file.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
<?php
22

3-
use Clue\React\Zenity\Launcher;
4-
use Clue\React\Zenity\Dialog\FileSelectionDialog;
5-
use Clue\React\Zenity\Builder;
6-
use Clue\React\Zenity\Dialog\InfoDialog;
7-
83
require __DIR__ . '/../vendor/autoload.php';
94

10-
$launcher = new Launcher();
11-
$builder = new Builder();
5+
$launcher = new Clue\React\Zenity\Launcher();
6+
$builder = new Clue\React\Zenity\Builder();
127

138
$launcher->launch($builder->fileSelection())->then(function (SplFileInfo $file) use ($launcher) {
149
var_dump($file);
1510

16-
$launcher->launch(new InfoDialog('Selected "' . $file->getFilename() . '". Re-opening dialog with same selection'))->then(function () use ($file, $launcher) {
17-
$selection = new FileSelectionDialog();
11+
$launcher->launch(new Clue\React\Zenity\Dialog\InfoDialog('Selected "' . $file->getFilename() . '". Re-opening dialog with same selection'))->then(function () use ($file, $launcher) {
12+
$selection = new Clue\React\Zenity\Dialog\FileSelectionDialog();
1813
$selection->setFilename($file);
1914
$selection->setTitle('Pretend we\'re overwriting the file');
2015
$selection->setConfirmOverwrite(true);
2116
$selection->setSave(true);
2217

2318
$launcher->launch($selection);
19+
}, function (Exception $e) {
20+
echo 'Error: ' . $e->getMessage() . PHP_EOL;
2421
});
22+
}, function (Exception $e) {
23+
echo 'Error: ' . $e->getMessage() . PHP_EOL;
2524
});

examples/03-progress-pulsate.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
<?php
22

3-
use Clue\React\Zenity\Launcher;
4-
use Clue\React\Zenity\Builder;
53
use React\EventLoop\Loop;
64

75
require __DIR__ . '/../vendor/autoload.php';
86

9-
$launcher = new Launcher();
10-
$builder = new Builder();
7+
$launcher = new Clue\React\Zenity\Launcher();
8+
$builder = new Clue\React\Zenity\Builder();
119

1210
$progress = $launcher->launchZen($builder->pulsate('Pseudo-processing...'));
1311

@@ -39,10 +37,14 @@
3937
$timer->cancel();
4038

4139
$launcher->launch($builder->info('Done'));
40+
}, function (Exception $e) {
41+
echo 'Error: ' . $e->getMessage() . PHP_EOL;
4242
});
4343

4444
$progress->promise()->then(null, function() use ($timer, $builder, $launcher) {
4545
$timer->cancel();
4646

4747
$launcher->launch($builder->error('Canceled'));
48+
}, function (Exception $e) {
49+
echo 'Error: ' . $e->getMessage() . PHP_EOL;
4850
});

examples/04-progress-random.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
<?php
22

3-
use Clue\React\Zenity\Launcher;
4-
use Clue\React\Zenity\Builder;
53
use React\EventLoop\Loop;
64

75
require __DIR__ . '/../vendor/autoload.php';
86

9-
$launcher = new Launcher();
10-
$builder = new Builder();
7+
$launcher = new Clue\React\Zenity\Launcher();
8+
$builder = new Clue\React\Zenity\Builder();
119

1210
$progress = $launcher->launchZen($builder->progress('Pseudo-processing...'));
1311

examples/05-form.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
<?php
22

3-
use Clue\React\Zenity\Launcher;
4-
use Clue\React\Zenity\Dialog\FormsDialog;
5-
63
require __DIR__ . '/../vendor/autoload.php';
74

8-
$launcher = new Launcher();
5+
$launcher = new Clue\React\Zenity\Launcher();
96

10-
$form = new FormsDialog();
7+
$form = new Clue\React\Zenity\Dialog\FormsDialog();
118
$form->setWindowIcon('info');
129
$form->setText('Enter user information');
1310

@@ -22,4 +19,6 @@
2219
var_dump('result', $result);
2320
}, function() {
2421
var_dump('form canceled');
22+
}, function (Exception $e) {
23+
echo 'Error: ' . $e->getMessage() . PHP_EOL;
2524
});

examples/06-menu.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
<?php
22

3-
use Clue\React\Zenity\Launcher;
4-
use Clue\React\Zenity\Builder;
5-
use Clue\React\Zenity\Dialog\InfoDialog;
6-
73
require __DIR__ . '/../vendor/autoload.php';
84

9-
$launcher = new Launcher();
10-
$builder = new Builder();
5+
$launcher = new Clue\React\Zenity\Launcher();
6+
$builder = new Clue\React\Zenity\Builder();
117

128
$main = function() use (&$main, $builder, $launcher) {
139
$menu = $builder->listMenu(array('Introduction', 'Tests', 'License', 'Bugs / Issues'), 'Main menu');
@@ -18,15 +14,15 @@
1814
if ($selected === '0') {
1915
// U+2212 MINUS SIGN for alignment
2016
$launcher->launch($builder->listRadio(array('+2', '+1', '±0', '−1', '−2'), 'Introduction Level', 2))->then(function ($level) use ($main, $launcher) {
21-
$launcher->launch(new InfoDialog('Level ' . var_export($level, true)))->then($main, $main);
17+
$launcher->launch(new Clue\React\Zenity\Dialog\InfoDialog('Level ' . var_export($level, true)))->then($main, $main);
2218
}, $main);
2319
} elseif ($selected === '1') {
2420
$launcher->launch($builder->listCheck(array('Unit', 'Functional', 'Acceptance (slow)'), 'Selected test suits to run', array(0, 1)))->then(function ($tests) use ($main, $launcher) {
25-
$launcher->launch(new InfoDialog('Tests: ' . var_export($tests, true)))->then($main, $main);
21+
$launcher->launch(new Clue\React\Zenity\Dialog\InfoDialog('Tests: ' . var_export($tests, true)))->then($main, $main);
2622
}, $main);
2723
} elseif ($selected === '2') {
2824
$launcher->launch($builder->confirmLicense(__DIR__ . '/../README.md', 'I have read the README.md file'))->then(function ($checked) use ($main, $launcher) {
29-
$launcher->launch(new InfoDialog('Clicked ' . var_export($checked, true)))->then($main, $main);
25+
$launcher->launch(new Clue\React\Zenity\Dialog\InfoDialog('Clicked ' . var_export($checked, true)))->then($main, $main);
3026
}, $main);
3127
} elseif ($selected === '3') {
3228
$launcher->launch($builder->table(
@@ -44,8 +40,10 @@
4440
$pulser->then($main, $main);
4541
}, $main);
4642
} else {
47-
$launcher->launch(new InfoDialog('Selected ' . var_export($selected, true)))->then($main, $main);
43+
$launcher->launch(new Clue\React\Zenity\Dialog\InfoDialog('Selected ' . var_export($selected, true)))->then($main, $main);
4844
}
45+
}, function (Exception $e) {
46+
echo 'Error: ' . $e->getMessage() . PHP_EOL;
4947
});
5048
};
5149

examples/10-notification.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
<?php
22

3-
use Clue\React\Zenity\Launcher;
4-
use Clue\React\Zenity\Builder;
53
use React\EventLoop\Loop;
64

75
require __DIR__ . '/../vendor/autoload.php';
86

9-
$launcher = new Launcher();
10-
$builder = new Builder();
7+
$launcher = new Clue\React\Zenity\Launcher();
8+
$builder = new Clue\React\Zenity\Builder();
119

1210
$notification = $builder->notifier();
1311
$zen = $launcher->launchZen($notification);

examples/20-blocking.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
<?php
22

3-
use Clue\React\Zenity\Launcher;
4-
use Clue\React\Zenity\Builder;
5-
use Clue\React\Zenity\Dialog\EntryDialog;
6-
73
require __DIR__ . '/../vendor/autoload.php';
84

9-
$launcher = new Launcher();
10-
$builder = new Builder();
5+
$launcher = new Clue\React\Zenity\Launcher();
6+
$builder = new Clue\React\Zenity\Builder();
117

12-
$name = $launcher->waitFor(new EntryDialog('Search package'));
8+
$name = $launcher->waitFor(new Clue\React\Zenity\Dialog\EntryDialog('Search package'));
139
if ($name === false) {
1410
exit;
1511
}

0 commit comments

Comments
 (0)