Skip to content

Commit

Permalink
New components by everton3x (gabrielrcouto#117)
Browse files Browse the repository at this point in the history
* TDirectoryEdit implemented as DirectoryField.

DirectoryField provides a one-button text field for directory selection.

* TDirectoryEdit implemented as DirectoryField.

DirectoryField provides a one-button text field for directory selection.

Fixed bug with windows directories firing JSON Syntax exception

* Code settings for Travis-CI

* Line breaks to Unix

* Line breaks to Unix, aff

* Line breaks to Unix, aff, aff, Travis, you make me crazy.

* DirectoryField::getBaseDir(): return the dialog title - bug fixed

* Code format to DirectoryField a.k.a Travis

* Implementation of TFileNameEdit

* PSR2 refactor, and letting pascal return a list of files

* Implementation of TFileNameEdit

* DirectoryField renamed for compatibility with project naming (a.k.a InputText)

* FileField renamed for compatibility with project naming (a.k.a InputText)

* Implementation of @reisraff suggestions:

OptionMgr and OpenOptions inserted in InputFile;

Improved PSR2 formatting.

* InputPassor Implementation.

* InputNumber Implementation.

Minor adjusts in examples.

* InputDate Implementation.

Minor adjusts in examples.

* InputTime Implementation.

Minor adjusts and code format.

* Calendar Implementation.

Minor adjusts and code format.

* Gallery sample

* Travis-CI: Line exceeds 120 characters; contains 136 characters - fixed

* Travis-CI: Line exceeds 120 characters; contains 136 characters - fixed

* Travis-CI: Line exceeds 120 characters; contains 136 characters - fixed

* Travis-CI: Line exceeds 120 characters; contains 136 characters - fixed

* Notes reviewed gabrielrcouto#113

* Adding duplicated code to a trait
  • Loading branch information
reisraff authored May 8, 2017
1 parent b08b3f4 commit 8221222
Show file tree
Hide file tree
Showing 23 changed files with 921 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ bin/*
!bin/generatedoc
phpunit.xml
doc/
/nbproject
11 changes: 6 additions & 5 deletions examples/11-forms/01-example.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
$application->on('start', function() use ($application) {
$field = (new InputDirectory())
->setLeft(10)
->setTop(80)
->setTitle('PHP-GUI Dialog Input Example');
->setTop(50)
->setWidth(300)
->setTitle('PHP-GUI Dialog Input Example')
;

$field->on('change', function() use ($field) {
echo "Directory selected:\n";
echo "\t{$field->getValue()}\n";
$field->on('change', function() use ($field, $application) {
$application->alert('Directory Chosen: ' . PHP_EOL . $field->getValue(), 'Directory Chosen');
});
});

Expand Down
9 changes: 4 additions & 5 deletions examples/11-forms/02-example.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
$application->on('start', function() use ($application) {
$field = (new InputFile())
->setLeft(10)
->setTop(80)
->setWidth(200)
->setAutoSize(true)
->setBaseDir('C:\Users\Arthur\Documents\NetBeansProjects\php-gui')
->setTop(50)
->setWidth(300)
->setBaseDir(realpath(__DIR__.'/../..'))
->setDialogOptions(InputFile::ALLOW_MULTI_SELECT)
;

$field->on('change', function() use ($application, $field) {
$application->alert(implode(', ', $field->getValue()), 'Files');
$application->alert('Files: ' . PHP_EOL . implode(PHP_EOL, $field->getValue()), 'Files');
});
});

Expand Down
43 changes: 43 additions & 0 deletions examples/11-forms/03-example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/*
* Password Input Example
*/
require __DIR__ . '/../../vendor/autoload.php';

use Gui\Application;
use Gui\Components\Label;
use Gui\Components\Button;
use Gui\Components\InputPassword;

$application = new Application();

$application->on('start', function() use ($application) {
$label = (new Label())
->setFontSize(12)
->setLeft(10)
->setText('Password:')
->setTop(20);

$field = (new InputPassword())
->setLeft(90)
->setTop(16)
->setWidth(200)
;

$button = (new Button())
->setCounter(1)
->setLeft(10)
->setTop(50)
->setValue('Click me, or Return/Enter in the above field')
->setWidth(300);

$func = function() use ($application, $field) {
$application->alert('Password: ' . $field->getValue(), 'Password');
};

$button->on('click', $func);

$field->on('EditingDone', $func);
});

$application->run();
47 changes: 47 additions & 0 deletions examples/11-forms/04-example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/*
* Number Input Example
*/
require __DIR__ . '/../../vendor/autoload.php';

use Gui\Application;
use Gui\Components\Label;
use Gui\Components\InputNumber;

$application = new Application();

$application->on('start', function() use ($application) {
$label1 = (new Label())
->setFontSize(12)
->setLeft(10)
->setText('Integer')
->setTop(80);

$field1 = (new InputNumber())
->setLeft(100)
->setTop(80)
->setWidth(200)
->setIncrement(2)
->setMax(10)
->setMin(-10)
->setValue(-4)
;

$label2 = (new Label())
->setFontSize(12)
->setLeft(10)
->setText('Float')
->setTop(120);

$field2 = (new InputNumber(true))
->setLeft(100)
->setTop(120)
->setWidth(200)
->setIncrement(0.25)
->setValue(1.25)
->setDecimals(4)
;

});

$application->run();
31 changes: 31 additions & 0 deletions examples/11-forms/05-example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/*
* Date Input Example
*/
require __DIR__ . '/../../vendor/autoload.php';

use Gui\Application;
use Gui\Components\Label;
use Gui\Components\InputDate;

$application = new Application();

$application->on('start', function() use ($application) {
$label = (new Label())
->setFontSize(12)
->setLeft(10)
->setText('Date')
->setTop(20);

$field = (new InputDate())
->setLeft(90)
->setTop(16)
->setWidth(200)
;

$field->on('change', function() use ($application, $field) {
$application->alert('Date selected: ' . $field->getValue(), 'Date selected');
});
});

$application->run();
33 changes: 33 additions & 0 deletions examples/11-forms/06-example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/*
* Date Input Example
*/
require __DIR__ . '/../../vendor/autoload.php';

use Gui\Application;
use Gui\Components\Label;
use Gui\Components\InputTime;

$application = new Application();

$application->on('start', function() use ($application) {
$label = (new Label())
->setFontSize(12)
->setLeft(10)
->setText('Time')
->setTop(20);

$field = (new InputTime())
->setLeft(100)
->setTop(16)
->setWidth(200)
->setAcceptInput(false)
->setButtonOnlyWhenFocused(true)
;

$field->on('change', function() use ($application, $field) {
$application->alert('Time selected: ' . $field->getValue(), 'Time selected');
});
});

$application->run();
25 changes: 25 additions & 0 deletions examples/11-forms/07-example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/*
* Calendar Example
*/
require __DIR__ . '/../../vendor/autoload.php';

use Gui\Application;
use Gui\Components\Calendar;

$application = new Application();

$application->on('start', function() use ($application) {
$field = (new Calendar())
->setLeft(20)
->setTop(20)
->setValue('01/02/2017')
;

// {on}change events is also fired with the getValue() and then causes a infinite loop
$field->on('mouseUp', function() use ($application, $field) {
$application->alert('Date selected: ' . $field->getValue(), 'Date selected');
});
});

$application->run();
113 changes: 113 additions & 0 deletions examples/11-forms/gallery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php

/*
* Components Gallery
*/
require __DIR__ . '/../../vendor/autoload.php';

use Gui\Application;
use Gui\Components\Button;
use Gui\Components\Calendar;
use Gui\Components\Checkbox;
use Gui\Components\InputDate;
use Gui\Components\InputDirectory;
use Gui\Components\InputFile;
use Gui\Components\InputNumber;
use Gui\Components\InputPassword;
use Gui\Components\InputText;
use Gui\Components\InputTime;
use Gui\Components\Label;
use Gui\Components\Option;
use Gui\Components\ProgressBar;
use Gui\Components\Radio;
use Gui\Components\Select;
use Gui\Components\TextArea;

$application = new Application();

$application->on('start', function() use ($application) {
$application->getWindow()->setTitle('PHP-GUI Components Gallery');
$application->getWindow()->setWindowState('maximized');

$button = (new Button())
->setValue('Click')
->setTop(10)
->setLeft(10);

$calendar = (new Calendar())
->setTop(50)
->setLeft(10);

$checkbox = (new Checkbox())
->setTop(10)
->setLeft(300);

$label = (new Label())
->setText('Checkbox')
->setTop(11)
->setLeft(320);

$radio = (new Radio())
->setTop(30)
->setLeft(300)
->setOptions([
new Option('Radio 1', 1),
new Option('Radio 2', 2),
new Option('Radio 3', 3)
]);

$date = (new InputDate())
->setTop(250)
->setLeft(10);

$directory = (new InputDirectory())
->setTop(300)
->setLeft(10);

$file = (new InputFile())
->setTop(350)
->setLeft(10);

$integer= (new InputNumber())
->setTop(400)
->setLeft(10);

$float= (new InputNumber(true))
->setTop(450)
->setLeft(10);

$password = (new InputPassword())
->setTop(250)
->setLeft(250);

$text = (new InputText())
->setTop(300)
->setLeft(250);

$time = (new InputTime())
->setTop(350)
->setLeft(250);

$progress = (new ProgressBar())
->setTop(500)
->setLeft(10)
->setMin(0)
->setMax(100)
->setPosition(75);

$select = (new Select())
->setTop(10)
->setLeft(190)
->setOptions([
new Option('Option 1', 1),
new Option('Option 2', 2),
new Option('Option 3', 3)
]);

$textarea = (new TextArea())
->setTop(500)
->setLeft(500)
->setValue('Text area sample');
});

$application->run();
Binary file added lazarus/lib/x86_64-linux/phpgui.o
Binary file not shown.
Binary file added lazarus/lib/x86_64-linux/phpgui.or
Binary file not shown.
Binary file added lazarus/lib/x86_64-linux/unit1.ppu
Binary file not shown.
Binary file added lazarus/lib/x86_64-linux/unitipcthread.o
Binary file not shown.
Binary file added lazarus/lib/x86_64-linux/unitipcthread.ppu
Binary file not shown.
Binary file modified lazarus/phpgui-x86_64-linux
Binary file not shown.
12 changes: 10 additions & 2 deletions lazarus/unitipcthread.pas
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface

uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, Pipes,
fpjson, jsonparser, unit1, typinfo, ExtCtrls, Variants, ComCtrls, EditBtn;
fpjson, jsonparser, unit1, typinfo, ExtCtrls, Variants, ComCtrls, EditBtn, Spin, Calendar;

type

Expand Down Expand Up @@ -159,6 +159,11 @@ procedure TIpcThread.Execute;
RegisterClass(TProgressBar);
RegisterClass(TDirectoryEdit);
RegisterClass(TFileNameEdit);
RegisterClass(TSpinEdit);
RegisterClass(TFloatSpinEdit);
RegisterClass(TDateEdit);
RegisterClass(TTimeEdit);
RegisterClass(TCalendar);

// Initializes the input pipe (Stdin)
StdinStream := TInputPipeStream.Create(StdInputHandle);
Expand Down Expand Up @@ -531,7 +536,11 @@ procedure TIpcThread.GetObjectProperty;
// Get file list from TFileNameEdit
return := (objArray[objId] as TFileNameEdit).DialogFiles.Text;
return := StringReplace(return, '\', '\\', [rfReplaceAll]);

// windows suport
return := StringReplace(return, #13#10, ';', [rfReplaceAll]);
// Linux suport
return := StringReplace(return, #10, ';', [rfReplaceAll]);


messageId := jData.FindPath('id').AsInteger;
Expand Down Expand Up @@ -560,7 +569,6 @@ procedure TIpcThread.GetObjectProperty;

messageId := jData.FindPath('id').AsInteger;
return := StringReplace(return, '\', '\\', [rfReplaceAll]);
return := StringReplace(return, '"', '\"', [rfReplaceAll]);
Output('{"id": ' + IntToStr(messageId) + ',"result": ' + return + '}');
end;
end;
Expand Down
Loading

0 comments on commit 8221222

Please sign in to comment.