Skip to content

Commit 1ee8e37

Browse files
committed
Improve documentation and examples
1 parent e377ce1 commit 1ee8e37

File tree

9 files changed

+55
-66
lines changed

9 files changed

+55
-66
lines changed

README.md

Lines changed: 13 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/).
@@ -69,10 +69,12 @@ $entry->setEntryText(getenv('USER')); // prefill with current user
6969

7070
$launcher->launch($entry)->then(function ($name) use ($launcher) {
7171
$launcher->launch(new InfoDialog('Welcome to zenity-react, ' . $name .'!'));
72+
}, function (Exception $e) {
73+
echo 'Error: ' . $e->getMessage() . PHP_EOL;
7274
});
7375
```
7476

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

7779
## Usage
7880

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

153155
$zen->promise()->then(function ($result) {
154156
// dialog completed
157+
}, function (Exception $e) {
158+
echo 'Error: ' . $e->getMessage() . PHP_EOL;
155159
});
156160
```
157161

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

293297
## Install
294298

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

298302
This will install the latest supported version:
299303

300304
```bash
301-
$ composer require clue/zenity-react:^0.4.4
305+
composer require clue/zenity-react:^0.4.4
302306
```
303307

304308
See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.
305309

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

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

315319
```bash
316320
# usually not required
317-
$ sudo apt-get install zenity
321+
sudo apt-get install zenity
318322
```
319323

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

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

337341
```bash
338-
$ composer install
342+
composer install
339343
```
340344

341345
To run the test suite, go to the project root and run:
342346

343347
```bash
344-
$ php vendor/bin/phpunit
348+
vendor/bin/phpunit
345349
```
346350

347351
## 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)