Extensionless PHP Graphic User Interface library

Related tags

Imagery php-gui
Overview

php-gui

Extensionless PHP Graphic User Interface library

made with PHP S2

Build Status Latest Stable Version Software License Packagist

Table of Contents

Why

PHP can be more than a "Web Language", it's a fast language, with a cross platform interpreter and a good CLI. GUI is a natural step for completing this ecosystem.

For many years, GUI projects are being developed for PHP, like PHP-GTK, PHP-QT, wxPHP and so many others, but none of them became popular.

This project aims to solve the most common problems of existing "GUI Projects":

  • The need for installing an extension
  • Cross platform
  • No external dependencies
  • Easy to install (composer require php-gui) / Easy to use ($button = new Button)

Requirements

The following PHP versions are supported:

  • PHP 5.6
  • PHP 7
  • HHVM

And OS:

  • Linux x64
  • Windows x64
  • Mac OSX (tested on 10.10.x and 10.11.x)

Usage

Download the library using composer:

Stable version

$ composer require gabrielrcouto/php-gui

Latest version (development)

$ composer require gabrielrcouto/php-gui:dev-master

Now, you can build a GUI application. Let's do a Hello World!

Create the file 'myapp.php':


require 'vendor/autoload.php';

use Gui\Application;
use Gui\Components\Button;

$application = new Application();

$application->on('start', function() use ($application) {
    $button = (new Button())
        ->setLeft(40)
        ->setTop(100)
        ->setWidth(200)
        ->setValue('Look, I\'m a button!');

    $button->on('click', function() use ($button) {
        $button->setValue('Look, I\'m a clicked button!');
    });
});

$application->run();

Now, run it:

php myapp.php

Simple? 👏 You don't need to compile anything, just download the library via composer and use it! 😄

Documentation

We have a Documentation Page

But, if you want to see some examples, just follow the instructions below.

# clone the repository
git clone https://github.com/gabrielrcouto/php-gui.git
cd php-gui

# install dependencies
composer install

# run examples
php examples/01-basic/example.php
php examples/02-animation/example.php
php examples/03-window/example.php
php examples/04-multiple-windows/example.php
php examples/05-canvas/example.php
php examples/06-ping/example.php
php examples/07-php-internals/example.php
php examples/08-alert/example.php   
php examples/09-3d-perspective/example.php 

How it works

To create a GUI without the need for an extension, PHP executes a binary with proc_open and communicates with it using Stdin/Stdout Pipes--it's a fast and cross platform solution.

PHP <=> Stdin/Stdout Pipes <=> Lazarus Application <=> GUI

The binary is created using Lazarus (Free Pascal). After much research, I found a large advantage by using Lazarus over other desktop languages (like C#, Java...):

LCL graph, showing that LCL will use an interface for building the GUI according to the operation system

It doesn't have any dependencies (except for Linux, which needs GTK), has a good component library, is compiled, open source and has a nice slogan (Write Once, Compile Anywhere).

The communication (IPC) between PHP and Lazarus is performed using a protocol based on JSON RPC. You can view the specification here.

Contributors Guide

Components names

To be an easy to use library, this project will use HTML friendly names for the components, as PHP developers are more familiar with it.

Examples:

  • On Lazarus, the property "caption" is for the text of a button. On php-gui, the property name is "value".
  • On Lazarus, "Edit" is the component for text input, on php-gui, it's "InputText".

Compiling Lazarus App

On your Local Machine

First, you need to install Lazarus.

For compiling the lazarus binary:

lazbuild phpgui.lpr

Using Docker

If you are generating the Linux binary, you can use Docker:

lazarus/linux-docker.sh
cd lazarus/
lazbuild phpgui.lpr

Test

First install the dependencies, and after you can run:

bin/phing

TO-DO

The "Issues" page from this repository is being used for TO-DO management, just search for the "to-do" tag.

Credits

@gabrielrcouto

@reisraff

License

MIT License

Sponsor

Comments
  • Throw error on jsonDecode

    Throw error on jsonDecode

    Throw an exception on jsonDecode method in Receiver.php

    Maybe it would be usefull to create custom Exception class for components like ComponentException any feedbacks ?

    X-Ref : #35

    opened by Johann-S 12
  • New Components Implemented

    New Components Implemented

    Implementation to:

    TCalendar -> Calendar TDateEdit -> InputDate TTimeEdit -> InputTime TSpinEdit/TFloatSpinEdit -> InputNumber TEdit -> InputPassword

    opened by everton3x 11
  • Autofocus of window would be great

    Autofocus of window would be great

    Running examples I realize that the window php-gui opens are hidden behind other applications, I guess the issue is because of Autofocus not being used yet.

    to-do 
    opened by rogeriopradoj 7
  • CS fixes for source code, and added some good practices

    CS fixes for source code, and added some good practices

    The source code has some issues with IDE implementation, good practices and auto-completion sometimes.

    This PR fixes it.

    ping @gabrielrcouto @reisraff

    enhancement in-progress 
    opened by Pierstoval 6
  • Optionally pass the event loop into the Application constructor

    Optionally pass the event loop into the Application constructor

    In order to use other ReactPHP components within php-gui, you need to be able to share the event loop, since you can't have multiple event loops running at the same time.

    opened by davidwdan 6
  • Screen freezing

    Screen freezing

    Hello guys,

    I've been using Ubuntu for a while and I tried to run the code shown in README.md file but my screen just freeze when I run it.

    <?php
    require 'vendor/autoload.php';
    
    use Gui\Application;
    use Gui\Components\Button;
    
    $application = new Application();
    
    $application->on('start', function() use ($application) {
        $button = (new Button())
            ->setLeft(40)
            ->setTop(100)
            ->setWidth(200)
            ->setValue('Look, I\'m a button!');
    
        $button->on('click', function() use ($button) {
            $button->setValue('Look, I\'m a clicked button!');
        });
    });
    
    $application->run();
    

    My O.S : Ubuntu 14.04

    any ideas ?

    opened by marabesi 6
  • GetObjectProperty does not work for properties in collection format

    GetObjectProperty does not work for properties in collection format

    I am trying to implement TFileNameEdit and I encountered problems using the DialogFiles property to return the selected files, regardless of whether or not the ofAllowMultiSelect is used.

    TFileNameEdit.DialogFiles seems to return a string collection with the name of the selected files. The return type is TStrings.

    From what I saw in the source code in Lazarus, TIpcThread.GetObjectProperty always returns a string, but in the specific case the conversion done by VarToStr (propertyValue) is not returning anything.

    In addition could you tell me the way to fix this, since TFileNameEdit only provides that property to access all the selected files.

    opened by everton3x 5
  • Why would you use this over something like Electron?

    Why would you use this over something like Electron?

    Curious as to how php-gui compares. Both are targeted at builing cross platform apps, but surely php-gui is more a niche with it's own api (millions of devs already know HTML/CSS than a custom api to build a GUI).

    When would you choose php-gui over something like Electron?

    opened by garygreen 5
  • TOpenDialog method

    TOpenDialog method

    Hello! I rebuild the lazarus and I added the TOpenDialog. RegisterClass(TOpenDialog);

    And when I "Execute", its not working I'm calling like this: $this->call('execute', []);

    Where is my mistake? Sorry for my English!

    opened by HackMemory 5
  • Invalid argument supplied for foreach() in D:\paiva\geraCpf\vendor\gabrielrcouto\php-gui\src\Ipc\Receiver.php

    Invalid argument supplied for foreach() in D:\paiva\geraCpf\vendor\gabrielrcouto\php-gui\src\Ipc\Receiver.php

    Hello everbody.

    I'm facing a problem while executing an code with php-gui:

    Executing this code, when I click the $button, the error below appears and the event does not execute

    <?php
    require 'vendor/autoload.php';
    
    use Gui\Application;
    use Gui\Components\Button;
    
    $application = new Application();
    
    $application->on('start', function() use ($application) {
        $button = (new Button())
            ->setLeft(40)
            ->setTop(100)
            ->setWidth(200)
            ->setValue('Look, I\'m a button!');
    
        $button->on('click', function() use ($button) {
            $button->setValue('Look, I\'m a clicked button!');
        });
    });
    
    $application->run();
    
    ?[0mPHP Warning:  Invalid argument supplied for foreach() in D:\paiva\geraCpf\vendor\gabrielrcouto\php-gui\src\Ipc\Receiver.php on line 244
    PHP Stack trace:
    PHP   1. {main}() D:\paiva\geraCpf\issue.php:0
    PHP   2. Gui\Application->run() D:\paiva\geraCpf\issue.php:21
    PHP   3. React\EventLoop\StreamSelectLoop->run() D:\paiva\geraCpf\vendor\gabrielrcouto\php-gui\src\Application.php:351
    PHP   4. React\EventLoop\Timer\Timers->tick() D:\paiva\geraCpf\vendor\react\event-loop\src\StreamSelectLoop.php:177
    PHP   5. call_user_func:{D:\paiva\geraCpf\vendor\react\event-loop\src\Timer\Timers.php:90}() D:\paiva\geraCpf\vendor\react\event-loop\src\Timer\Timers.php:90
    PHP   6. Gui\Application->Gui\{closure}() D:\paiva\geraCpf\vendor\react\event-loop\src\Timer\Timers.php:90
    PHP   7. Gui\Ipc\Receiver->tick() D:\paiva\geraCpf\vendor\gabrielrcouto\php-gui\src\Application.php:347
    PHP   8. React\Stream\Stream->emit() D:\paiva\geraCpf\vendor\gabrielrcouto\php-gui\src\Ipc\Receiver.php:391
    PHP   9. Gui\Application->Gui\{closure}() D:\paiva\geraCpf\vendor\evenement\evenement\src\Evenement\EventEmitterTrait.php:70
    PHP  10. Gui\Ipc\Receiver->onData() D:\paiva\geraCpf\vendor\gabrielrcouto\php-gui\src\Application.php:324
    

    I was evaluating the values and I believe the problem might be in Receiver.php in line 176. Below is this class between lines 171 and 183:

          if ($fbrac < $fcurl || $fcurl === false) {
                // If '[' is before '{' use [].
                $fchar = '[';
                $lchar = ']';
                $start = $fbrac;
            } elseif ($fcurl > $fbrac || $fbrac === false) {
                // If '{' is before '[' use {}.
                $fchar = '{';
                $lchar = '}';
                $start = $fcurl;
            } else {
                return false;
            }
    

    The comparisons in the lines 171 and 176 are equals and will return the same result.

    I changed line 176 to } elseif ($fcurl > $fbrac || $fbrac === false) { and it worked well.

    Edit

    Obviously I didn't change to the code above and it worked. I changed to $fcurl < $fbrac!

    opened by paiva-thiago 4
  • New release plz

    New release plz

    A lot of issues were solved since the first release from 2016 😞, I'm thinking specially about issue #136. So, could you please launch a new release?, it could be v0.1.1 for example.

    Thanks a lot for your amazing job 👍

    opened by jawira 4
  • Escape JSON strings, add more supported OS versions (x32/x64)

    Escape JSON strings, add more supported OS versions (x32/x64)

    Lazarus: escape json strings, add cross-compile targets to project settings, re-compiled binaries for all supported systems. Add support for 64-bit MacOs, 32 bit Linux, 32 bit freeBSD, 32 bit Windows

    Php code: Application.php updated how lazarus binary is found, added assertion if binary exists.

    This fixes #191

    opened by DubbaThony 0
  • Quotes in text field generate JSON Exception

    Quotes in text field generate JSON Exception

    It looks like Lazarus has an issue with JSON encoding. For example if field contains exacly string [""], and its read, it gives an error:

    => Sent: {"id":100,"method":"callObjectMethod","params":[3,"lines.getAll",[]],"callback":null}
    JSON ERROR: {"id": 100, "result": "[""]"}
    

    The quotes weren't escaped to proper json.

    opened by DubbaThony 0
Releases(v0.1.1)
Owner
Gabriel Rodrigues Couto
PHP evangelist, open source lover, HTML5/JS developer and a guy that thinks everything has a solution.
Gabriel Rodrigues Couto
With the help of QR code technologies, digital entry passes can be created, which a user can show at the entry point to pass the door.

Navratri_Entry With the help of QR code technologies, digital entry passes can be created, which a user can show at the entry point to pass the door.

Kushang Shah 5 Aug 7, 2022
PHP Exif Library - library for reading and writing Exif headers in JPEG and TIFF files using PHP.

PEL: PHP Exif Library README file for PEL: PHP Exif Library. A library with support for reading and writing Exif headers in JPEG and TIFF images using

null 264 Dec 4, 2022
ImageWorkshop is a PHP5.3+ library that helps you to manage images based on GD library

================================ ImageWorkshop class ================================ Summary and features Really flexible and easy-to-use PHP class t

Clément Guillemain 853 Dec 27, 2022
Image optimization / compression library. This library is able to optimize png, jpg and gif files in very easy and handy way. It uses optipng, pngquant, pngcrush, pngout, gifsicle, jpegoptim and jpegtran tools.

Image Optimizer This library is handy and very easy to use optimizer for image files. It uses optipng, pngquant, jpegoptim, svgo and few more librarie

Piotr Śliwa 879 Dec 30, 2022
PHP 5.3 Object Oriented image manipulation library

Imagine Tweet about it using the #php_imagine hashtag. Image manipulation library for PHP 5.3 inspired by Python's PIL and other image libraries. Requ

Bulat Shakirzyanov 4.3k Jan 6, 2023
PHP Captcha library

Captcha Installation With composer : { ... "require": { "gregwar/captcha": "1.*" } } Usage You can create a captcha with the Captc

Grégoire Passault 1.6k Dec 25, 2022
This is a class of php QR Code, This library helps you generate QR codes in a jiffy.

This is a class of php QR Code, This library helps you generate QR codes in a jiffy.

null 59 Oct 5, 2022
A library using PHP to generate QRCode from https://www.qrcode-monkey.com free

PHP Class Generate Free QRCode ?? A library using PHP to generate QRCode from https://www.qrcode-monkey.com free ✋ NOTE: Do not generate too many QRCo

Nguyen Truong Nguyen 53 Dec 28, 2022
PHP library to resize, scale and crop images.

PHP library to resize, scale and crop images.

Gumlet 1.1k Jan 3, 2023
PHP library to easily edit image with GD extension. Resize, crop, merge, draw, and many more options !

PHP Image Editor PHP library to easily edit image with GD extension. Resize, crop, merge, draw, and many more options ! ✨ Supporting ⭐ Star this repos

Franck Alary 17 Nov 13, 2022
Goldbach Algorithms Mask is a PHP library developed for Symfony for apply a mask to strings.

Goldbach Algorithms Mask (fondly nicknamed GoldMask) is a PHP library developed for Symfony for apply a mask to strings.

Goldbach Algorithms 1 Oct 30, 2021
PEL: PHP Exif Library

PHP Exif Library - library for reading and writing Exif headers in JPEG and TIFF files using PHP.

null 264 Dec 4, 2022
PHP Thumb is a light-weight image manipulation library aimed at thumbnail generation

PHP Thumb NOTICE - This project was recently updated to 2.0 and is PSR-0 compliant and supports Composer integration. Some parts of the documentation

Ian Selby 985 Dec 4, 2022
PHP Library for generating SVG avatars based on React Avataaars

PHP library for Avataaars PHP Library for generating SVG avatars based on React Avataaars.

null 5 Apr 16, 2022
Wonderfully easy on-demand image manipulation library with an HTTP based API.

Glide Glide is a wonderfully easy on-demand image manipulation library written in PHP. Its straightforward API is exposed via HTTP, similar to cloud i

The League of Extraordinary Packages 2.4k Dec 19, 2022
Symfony Bundle to assist in imagine manipulation using the imagine library

LiipImagineBundle PHPUnit PHP-CS-Fixer Coverage Downloads Release This bundle provides an image manipulation abstraction toolkit for Symfony-based pro

Liip 1.6k Dec 30, 2022
PHPExif is a library which gives you easy access to the EXIF meta-data of an image

PHPExif v0.6.4 PHPExif is a library which gives you easy access to the EXIF meta-data of an image. PHPExif serves as a wrapper around some native or C

null 135 Dec 4, 2022
BaconQrCode is a port of QR code portion of the ZXing library

QR Code generator Introduction BaconQrCode is a port of QR code portion of the ZXing library. It currently only features the encoder part, but could l

Bacon 1.5k Jan 6, 2023
PHP Image Manipulation

Intervention Image Intervention Image is a PHP image handling and manipulation library providing an easier and expressive way to create, edit, and com

null 13k Jan 3, 2023