PHP, GTK, PHP-GTK look ma, no webserver. http://joind.in/2980
May 28, 2015
PHP, GTK, PHP-GTK
look ma, no webserver.
http://joind.in/2980
WHAT IS PHP?For the sake of completeness
WHAT IS GTK?Boxes, buttons, and sliders, oh my!
GTK was... GTK is...
• Original UI toolkit for GIMP.– GIMP Tool Kit
• Now the basis of GNOME and lots of software.– GNOME Tool Kit. (sarcastic groan)
• C Library. Bindings in almost any language ever– C++, D, ...– Java, Python, Perl, ...– Oh, and PHP
GTK Applications
• GIMP• GNOME anything.• Transmission• Banshee• Pidgin• Apps roll custom UI kits for GTK or QT purists– Firefox, The suite formerly known as OpenOffice.
SO WHY NOT PHP AND GTK^_^
PHP-GTK is...
• A client side application library.– Will not run in a
webserver. In fact your webserver will catch fire.
– I have seen it happen twice.
• NOT for building webpages. Remember: fire.
PHP-GTK Pros
• PHP is easy fun.• PHP Object Orientation fits well with a widget
toolkit mindset.• Linux systems probably already have PHP CLI
accessible.• Multiplatform.– Download unzip and go on Windows.– Package manager + some compiling on Linux.– MacOS is not fun to setup. But it can happen.
PHP-GTK Cons
• PHP is “slow”• PHP is kind of single thread mostly.• Windows users are like “lolwut?”
– The concept of an exe binary does not exist.• Actually it does, but it is the official position of the devs to not even
attempt to support blendering.
– Perfectly reasonable way around this• MacOS is a pain to setup.
– 4:39:15 PM Greg: So let me see, you used Linux software to run the Windows binaries of Linux libraries through a web programming language on Mac... so that you could use a text editor?
– 4:39:34 PM Bob: yeah :D
Quick peek at some PHP-GTKs
<?php
//. FAR from a proper app,//. but will “work”.
$window = new GtkWindow;$window->add(new GtkLabel( ‘Hello World’));$window->set_title(‘Hurr Durr’);$window->show_all();Gtk::main();
?>
WHAT CAN WE DO WITH PHP-GTK?The right answer is almost anything.
PGID3, An MP3 Tag Editor
Ambst, Ambient Star Trek >_>
Prana, Removable Media Launcher
HOW ABOUT SOME HEAVY LIFTINGNice tiny apps but...
LiveCD Installer?
Package Management?
Repository Management?
Network Configuration?
QUICK PRE-DEMO POINTERSlets see some code already.
Desktop App Requirements
• Applications must know how to initialize themselves.– Loading, caching, building UI, handling input.
• Applications must know how to terminate themselves cleanly.– SEGFAULT is not a valid choice, though humorous.– Clean up files, swaps, connections, last second
saves, etc.
How it works...
• Execute PHP application• PHP app loads whatever config, init whatever
UI, and exposes itself to you• PHP app hits the main loop– Gtk::main();– This keeps your script alive in the GTK loop so that
it can answer to things like mouse clicks.• PHP app breaks the loop when done.– Gtk::main_quit();
BOB GO SHOW THEM SOME CODESRSLY, CODE... NAO
Some Widgets
• Windows. GtkWindow, GtkDialog• Buttons. GtkButton• Text Labels. GtkLabel• Text Entry. GtkEntry, GtkTextView• Dropdown Menus: GtkComboBox• Radio Buttons: GtkRadioButton• Progress Bars: GtkProgressBar
The power comes from EXTENDS
• GtkWindow is boring.• bobWindow extends GtkWindow– Sets default title, icon, builds internal UI.– This is how apps are made.
Resources
• PHP-GTK Manual, http://gtk.php.net• Bob’s PHP-GTK Archive– http://oops.opsat.net– http://squirrelshaterobots.com
• PHP-GTK Community Site– apps, tips, sort-of-not-active-forum– http://php-gtk.eu
Contact and More Info
• Bob Majdak Jr• twitter: @bobmajdakjr• irc: #php-gtk, #dallasphp on Freenode• dev blog: http://squirrelshaterobots.com• this talk: http://joind.in/2980