Native desktop applications with PHP

Overview

php-gui

php-gui allows you to build desktop ui applications with PHP only. It leverages FFI extension and Tcl/Tk for that, thus you don't need to compile or install any external extensions.

Requirements

  • PHP >= 7.4
  • ffi extension must be enabled
  • Tcl/Tk >= 8.6

Getting started

Make sure that Tcl/Tk is installed in your OS. For Debian/Ubuntu based distros you may install it with apt:

sudo apt install tcl tk

Clone this repository and try out demos:

git clone https://github.com/skoro/php-gui.git php-gui
cd php-gui
php demos/buttons.php

Options

You may enable some application features like:

  • debug mode
  • appearance

Copy the provided .env.example into .env and customize the options.

Debug mode allows you to find out which commands execute by Tcl engine. To enable the debug mode set:

DEBUG=true
DEBUG_LOG=php://stdout

All the debug messages will go to the console. You may specify a file name instead of console.

To change the application appearance comment out THEME option and set one of: clam, alt, default, classic. Additional themes for Windows: winnative, xpnative, vista. By default, auto is used, setting a theme depending on OS:

THEME=auto

Windows

You need to install Tcl/Tk binary distribution and set path to dlls in .env file like this:

WINDOWS_LIB_TCL=c:\\tcltk\\bin\\tcl86t.dll
WINDOWS_LIB_TK=c:\\tcltk\\bin\\tk86t.dll
Comments
  • Adding a 'setIcon' method to allow the Window's icon to be changed

    Adding a 'setIcon' method to allow the Window's icon to be changed

    Currently the only way to set the icon is to call directly the protected method setWm. If we don't want to follow the approach of extending MainWindow we should still be able to set its icon.

    This PR addresses that concern, making public a setIcon method that receives the path for the icon bitmap file. As it was added to the docblock, / should be used as directory separator even on Windows. When trying to use \ I received the following error:

    image

    PHP Fatal error:  Uncaught Tkui\TclTk\Exceptions\EvalException: Eval: bitmap "C:WindowsSystem32OneDrive.ico" not defined in C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\Tcl.php:63
    Stack trace:
    #0 C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\Interp.php(54): Tkui\TclTk\Tcl->eval(Object(Tkui\TclTk\Interp), 'wm iconbitmap ....')
    #1 C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\TkApplication.php(86): Tkui\TclTk\Interp->eval('wm iconbitmap ....')
    #2 C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\TkWindowManager.php(209): Tkui\TclTk\TkApplication->tclEval('wm', 'iconbitmap', '.', 'C:\\Windows\\Syst...')
    #3 C:\Users\carlo\Documents\code\untitled\index.php(38): Tkui\TclTk\TkWindowManager->setWm('iconbitmap', 'C:\\Windows\\Syst...')
    #4 {main}
      thrown in C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\Tcl.php on line 63
    
    Fatal error: Uncaught Tkui\TclTk\Exceptions\EvalException: Eval: bitmap "C:WindowsSystem32OneDrive.ico" not defined in C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\Tcl.php on line 63
    
    Tkui\TclTk\Exceptions\EvalException: Eval: bitmap "C:WindowsSystem32OneDrive.ico" not defined in C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\Tcl.php on line 63
    
    Call Stack:
        0.0002     412616   1. {main}() C:\Users\carlo\Documents\code\untitled\index.php:0
        0.1035     887664   2. Tkui\TclTk\TkWindowManager->setWm($command = 'iconbitmap', ...$value = variadic('C:\\Windows\\System32\\OneDrive.ico')) C:\Users\carlo\Documents\code\untitled\index.php:38
        0.1035     888040   3. Tkui\TclTk\TkApplication->tclEval(...$args = variadic('wm', 'iconbitmap', '.', 'C:\\Windows\\System32\\OneDrive.ico')) C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\TkWindowManager.php:209
        0.1035     888496   4. Tkui\TclTk\Interp->eval($script = 'wm iconbitmap . C:\\Windows\\System32\\OneDrive.ico') C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\TkApplication.php:86
        0.1035     888496   5. Tkui\TclTk\Tcl->eval($interp = class Tkui\TclTk\Interp { private Tkui\TclTk\Tcl $tcl = class Tkui\TclTk\Tcl { private FFI $ffi = class FFI { ... } }; private FFI\CData $interp = class FFI\CData { public $0 = class FFI\CData { ... } }; private ?Psr\Log\LoggerInterface $logger = NULL }, $script = 'wm iconbitmap . C:\\Windows\\System32\\OneDrive.ico') C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\Interp.php:54
    
    opened by CViniciusSDias 4
  • No application name in Gnome

    No application name in Gnome

    Instead of the application name there is only Tk in Gnome desktop environment: image

    In Gnome DE the application class name should be used. It can be checked by running wish with -name parameter like this:

    wish some-script.tcl
    wish -name ScriptApp some-script.tcl
    

    Also, digging into tk sources there is toplevel initialization with -class option (tkWindow.c:3314-3322):

        /*
         * Create an argument list for creating the top-level window, using the
         * information parsed from argv, if any.
         */
    
        cmd = Tcl_NewStringObj("toplevel . -class", -1);
    
        Tcl_ListObjAppendElement(NULL, cmd, classObj);
        classObj = NULL;
    

    Since the root toplevel is created by Tk initialization routine we need to provide name through Tcl argv global variable.

    bug 
    opened by skoro 1
  • Unable to override .env parameter via command line

    Unable to override .env parameter via command line

    Now an application name or class can be used in some desktop environments like Gnome where the app name is shown in the Dash to Dock and the top panel but window title in the application switcher. There is also an option to override the app name via .env and APP_NAME parameter but it cannot be overridden like this:

    APP_NAME=SomeApp php demos/buttons.php
    

    This is due to usage m1/env package which is cannot read the os environment. As a solution, transition to dotenv could fix that.

    PS: not the app name can be overridden but any .env parameter, it will let to override an app theme from the command like this: THEME=dark php app.php

    opened by skoro 0
  • Adding Tcl list variables

    Adding Tcl list variables

    This PR adds Tcl list variables. It supports adding, getting values and get count of elements. Usage is following:

    $argv = $interp->createListVariable('argv');
    $argv->append('-name', 'value1');
    
    enhancement 
    opened by skoro 0
  • Fix php74 errors

    Fix php74 errors

    buttons, menu, text, treeview demos are not working with PHP 7.4 which is minimal requirement in composer.json. This PR removes all the PHP 8 new feature to be compatible with 7.4 Mentioned here: https://github.com/skoro/php-tkui/issues/4#issuecomment-1294352704

    bug 
    opened by skoro 0
  • transition to tkui package

    transition to tkui package

    Since php-gui is already existing this package could be treated as a fork of it but it's not so. This transition changes the package name to tkui and namespaces. The repository should also be renamed.

    opened by skoro 0
  • feat: include tcltk distribution into the package

    feat: include tcltk distribution into the package

    This is especially actual for Windows users who needs to install TclTk separately by using one of available distribution. Including tcltk will be much simpler for getting started with the package.

    What should be done:

    • make tcltk compilation script (I manually tried msys2 for compiling and it works but it should be automated)
    • strip unneeded files from tcltk to reduce distribution size (demo, help, etc)
    • make os detection before app bootstrapping to pickup the included distribution depending on os

    Disadvantages:

    • the package size will be increased (+ ~10mb)
    opened by skoro 0
  • Setting an application icon via APP_ICON

    Setting an application icon via APP_ICON

    APP_ICON in .env could be used for overriding the application icon.

    Use cases: ?

    Problems:

    • how to add more than one icon for different resolutions ?
    question 
    opened by skoro 0
  • php8 only ?

    php8 only ?

    Using PHP8 gives the following improvements:

    • nullsafe operator ?-> (HasLogger)
    • constructor property promotions
    • using Enums instead of consts
    • union types: array|Options in widget constructors
    opened by skoro 4
Releases(v0.2.1)
Owner
Alexei Skorobogatko
Alexei Skorobogatko
This is a Native PHP MVC. If you will build your own PHP project in MVC with router, you can clone this ready to use MVC pattern repo.

Welcome to PHP-Native-MVC-Pattern ?? If you will build your own PHP project in MVC with router, you can clone this ready to use MVC pattern repo. Work

null 2 Jun 6, 2022
Here is the top 100 PHP functions: it is the list of the most often used PHP native functions

Here is the top 100 PHP functions: it is the list of the most often used PHP native functions. If you are a PHP developer, you must know the Top 100 PHP Functions deeply.

Max Base 16 Dec 11, 2022
YogsMAP adalah GIS(Geographic Information System) yang dibangun dengan PHP Native, MapBox API dan Boostrap

YogsMAP adalah GIS(Geographic Information System) yang dibangun dengan PHP Native, MapBox API dan Boostrap. Website ini menampilkan data pada area di yogyakarta, serta bisa menampilkan lokasi-lokasi yang diinginkan.

Krisna Dewa 3 Nov 18, 2022
A simple, standalone, modern PHP class inspector and mapper library, wrapping PHPs native reflection in a fluent interface

A simple, standalone, modern PHP class inspector and mapper library, wrapping PHPs native reflection in a fluent interface.

smpl 9 Sep 1, 2022
This library provides a collection of native enum utilities (traits) which you almost always need in every PHP project.

This library provides a collection of native enum utilities (traits) which you almost always need in every PHP project.

DIVE 20 Nov 11, 2022
Converts any PocketMine-MP 3.0 extended blocks into PM4 native blocks!

ExtendedBlocksConverter Converts any PocketMine-MP 3.0 extended blocks into PM4 native blocks! Yes, you heard right, this plugin can convert any lefto

Covered123 6 Jun 4, 2022
Magento React Native Community

Magento React Native Community New version of the https://github.com/troublediehard/magento-react-native based on GraphQL api. Which will be covered w

Dima Portenko 52 Dec 21, 2022
React Native mobile app for Magento 2.x

Open source React Native mobile app for Magento 2 Magento React Native is a fully functional eCommerce App for your Magento 2 website. It uses Magento

Dima Portenko 290 Dec 1, 2022
Mage2click toolset to create and manage the Magento Docker development environment with mutagen.io file-sync for macOS and native filesystem mounts on Linux.

Mage2click - Magento Docker Toolset Mage2click toolset is a system-wide command-line tool for creating and managing simultaneously running Magento Doc

Mage2click 69 Nov 28, 2022
QuCheng cloud-native application delivery platform

开源轻量级应用交付平台 渠成云原生应用交付平台 是 北京渠成软件有限公司自主设计、研发的开源轻量级应用交付平台。它底层基于容器和Kubernetes技术,通过Helm进行应用的封装,提供了渠成云原生应用市场、服务管理、服务监控与告警、日志管理与审计、集群管理等平台功能,是一款使用简单,功能完备的云原

EasySoft 14 Dec 17, 2022
Lightweight PHP wrapper for OVH APIs. That's the easiest way to use OVH.com APIs in your PHP applications.

This PHP package is a lightweight wrapper for OVH APIs. That's the easiest way to use OVH.com APIs in your PHP applications.

OVHcloud 263 Dec 14, 2022
PPM is a process manager, supercharger and load balancer for modern PHP applications.

PPM - PHP Process Manager PHP-PM is a process manager, supercharger and load balancer for PHP applications. It's based on ReactPHP and works best with

PPM - PHP Process Manager 6.5k Jan 3, 2023
A library for create network applications with PHP.

SocketServer A library for create network applications with PHP. Installation. $ composer require thenlabs/socket-server Usage. The below code show a

ThenLabs 3 Apr 11, 2022
Advanced algorithmic PHP applications I've made

Advanced algorithmic PHP applications I've made

Deniz Uku 1 Nov 2, 2021
Demo serverless applications, examples code snippets and resources for PHP

The Serverless LAMP stack Examples Code example Description AWS blog link 0.1-SimplePhpFunction A very simple implementation of a PHP Lambda function.

AWS Samples 303 Dec 20, 2022
Samsui is a factory library for building PHP objects useful for setting up test data in your applications.

#Samsui Samsui is a factory library for building PHP objects useful for setting up test data in your applications. It is mainly inspired by Rosie for

Sam Yong 31 Nov 11, 2020
This pacakge provides an easy connection to the Open Brewery DB project for PHP and Laravel applications.

Laravel Openbrewerydb API This pacakge provides an easy connection to the Open Brewery DB project for PHP and Laravel applications. About Open Brewery

Alex Justesen 1 Oct 4, 2022
ShurjoPay payment gateway integration for PHP applications.

ShurjoPay PHP Library Using this library you can integrate ShurjoPay payment gateway into your PHP applications. If you face any problem then create i

Raziul Islam 6 Jun 17, 2022
High performance view templating API for PHP applications using tags & expressions inspired by Java JSTL and C compiler

View Language API Table of contents: About Expressions Tags Configuration Compilation Installation Unit Tests Examples Reference Guide About This API

Lucian Gabriel Popescu 0 Jan 9, 2022