Alan Knowles - Background
- Teletext editor (6502 assembler in early 80's)
- C & Autolisp (early 90's)
- VBCCE - ccmail (late 90's)
- contributor to TWIG (php webmail application)
- set up a Linux Consulting company during dotcom boom
- contributor to Midgard (C Mysql php extension)
- Large scale php application user interface to midgard
The Need
- Dreamweaver Quality HTML editor on linux
- Midgard interface (Content managment)
- Editor that access files using scp/ssh
- Learn and expand knowledge of PHP
Advantages
- Open Source :)
- simple powerfull object orientated language
- large user base = lots of potential contributors
- easy to build extensions
- cross platform - works on windows (well sometimes)
- scripting -> compiled -> run = fast at runtime, negligable startup penalty
Disadvantages
- threading
- forking and sockets available though
- incomplete widgets
- gnome etc. - not available on windows anyway.
Initial efforts and PHPIDE
Initial Efforts
- initial efforts where hacking moleskine (added file tree to moleskine)
- python object model not as intuative
- at the same time Andrei released php-gtkscintilla in cvs
- Original PHPMole very much a straight port of moleskine into PHP
- Only major change was not doing this as it was confusing to read.
class phpinterface extends scintilla {PHPIDE
- Aims
- Modular enviroment
- PEAR based (with PEAR standards)
- Problems
- Project lacked resources
- Ideas good.
- first effort at phpmole
- already allowed editing documents
- but not very modular.
Modulizing the mole
Display Modules (modules)
- Scintilla
- Now has : Gtkhtml (WYSIWYG html editor), plain text, database,xml and forms/midgard
Transport Modules (transports)
- File
- Scp
- Midgard (HTTP + Curl)
- Database
Parser/Language Modules (languages)
- XML,
- HTML/PHP
Extensions (plugin extras)
- Help Viewer, Directory/Image tools, dictionary client, simple and full debugger, phppresents
Extending PHP-GTK - adding GTKHTML
GtkHTML = gtk widget
- Browing Web pages
- Editing Web pages in a WYSIWYG manner
- Understanding the design of GtkHTML
Limitations
- Strips HTML!
- Not very cross platform (cschtml? or gtkhtml2 or gtk2 text widget)
Writing a PHP & PHP-GTK Extension
Principle :
- Auto generated C code - try not to do the hard work
php-gtk/generator/generator.phpDefs file
- The defs file generator (/php-gtk/generator/h2defs.py)
- .h files converted to 'scheme/lisp format'
(object HTML (in-module Gtk) (parent Layout (Gtk)) (c-name GtkHTML) )
Writing a PHP & PHP-GTK Extension
Overrides file
- The C code that can not be generated
Makefiles and config files
- Like all PHP modules - Makefile.in, config.m4
Zend/PHP API
- Alot of C Macros
- php functions/methods become short and simple C functions
GTKHTML - the source
PHP_FUNCTION(gtk_html_get_paragraph_style) { long php_retval; NOT_STATIC_METHOD(); if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "")) return; php_retval = gtk_html_get_paragraph_style( GTK_HTML(PHP_GTK_GET(this_ptr))); RETURN_LONG(php_retval); }
GTKHTML - the widget
Creating the widget
- must be inside a scrolled window!
$scrolly = &new gtkscrolledwindow() $gtkhtml = &new gtkhtml(); $scrolly->add($gtkhtml);Loading the html data
$stream = $gtkhtml->begin(); $gtkhtml->write($stream,$data,strlen($data)); $gtkhtml->end($stream,GTK_HTML_STREAM_OK);
GTKHTML - the widget
Connect the callbacks
$gtkhtml->connect(""link_clicked","callback_link_clicked"); $this->gtkhtml->connect_url_request("callback_url_request");Callback functions
- all callbacks call function with widget, then other variables eg.
function callback_url_request($widget,$stream) { $data = .....get image...... $widget->write($stream, $data, $size_of_data); }Saving the data
$gtkhtml->save(array(&$this,"mymethod"));
Phpmole Modules
Developing modulized class based desktop apps.
- module manager
- responsible for relaying messages to modules
- no single module could expect another one to be there
- all messages must be sent to module manager.
- extensive use of
call_user_function(array(&$something,"method"),$args)
PHP-GTK Tips & Tricks
the & sign
- essential to create and use references of classes
- useful for sharing data between different classes - eg. the transports and editors.
- avoid copying data as this is slower!
$object = &$other_object; // reference $object = $other_object; // copy
- If you copy a gtk object - it will break
$widget->connect("clicked",array(&$this,"some_method"));
- Call backs on classes should use &$this, otherwise you will end up with referencing a copy of the object at the time the 'connect' was called
while (gtk::events_pending) gtk::main_iteration();
- php is multitasking not threaded
- if your program is busy - you can use this to let the interface have control breifly
- most applications do not require threading - it also introduces other issues - like locking
- re-entrant methods - what happens when methods are called inside themselves.
signal connecting
- avoid accidently connecting twice.
$widget->connect("clicked",array(&$this,"some_method")); $widget->connect("clicked",array(&$this,"some_method"));
- will call some_method twice
- fix:
$ref = $widget->connect("clicked",array(&$this,"some_method")); $widget->connect("clicked",array(&$this,"some_method")); $widget->connect($ref);
PHP-GTK Tips & Tricks
use glade - the gtk interface builder
- saves time developing interfaces
- you can load parts of a glade file and merge it with your interface
- simple phplibglade layer in phpmole to get arround win32 libglade bugs
- phpmole uses configuration dialogs
- automatically map config vars to widget names
- adding config options involves
- modifying the glade file.
- adding config names to default config file
PHP-GTK Tips & Tricks
extending gtk objects
- common trick is to use $this->widget to refer to managed widget
- make code clearer (loses some benifits of object extending)
- reuse of classes like scintilla...
class mywidget extends gtknotebook { function mywidget() { //initialize the widget $this->set_sensitive(FALSE); } } //or this may be clearer, however more typing! class mywidget { var $widget; function mywidget() { //initialize the widget $this->widget = &new GtkNotebook(); $this->widget->set_sensitive(FALSE); } }
PHP-GTK Tips & Tricks
storing extra information on widgets
- lists, trees and notebooks it is usefull to store extra data with a widget
$widget->set_data("key","value") $widget->connect("pressed","some_function"); function some_function($w){ echo $w->get_data("key"); }
PHP-GTK Tips & Tricks
Drawing areas (Drawing Graphics- lines, text etc.)
- most complex part of gtk1.2 (although gtk2 has gtktextview as competition)
- useful for displaying images, or doing drawing diagrams, pdfs..... etc.
- off screen pixmap, painted on to screen using expose_event callbacks
- configure_event callback sets up the pixmap
- pixmap can be drawn to seperatly from displaying it.
- explicity tell display to draw pixmap. (or part of pixmap) on drawing area
Look at tests/scribble.php for more details
PHP-GTK Tips & Tricks
Drag and Drop
- very difficult to do in web enviroment ( php's origin )
- does not work on php-gtk for windows (as of 0.5.0)
- not usefull for non-mouse driven displays
source widget
$widget->drag_source_set( GDK_BUTTON1_MASK|GDK_BUTTON3_MASK, array(array('text/plain', 0, -1)), GDK_ACTION_COPY); $widget->connect('drag_data_get', array(&$this,'dnd_drag_data_get'));destination widget
$widget->drag_dest_set(GTK_DEST_DEFAULT_ALL, array(array('text/plain', 0, -1)) , GDK_ACTION_COPY); $widget->connect('drag_data_received', array(&$this,"drop_recieved"));see tests/test.php for more details
Content Management - Web Services
Midgard Integration (Web Services)
- Midgard is CMS engine - managed C API interface to mysql
- phpmole uses a simplified XML transport layer to get send data to midgard server
- can be used as an abstract form eding layer - eg. sourceforge, bugtracker etc.
- in the future it will use XMLRPC
![]()
Phpmole the Future
Other plans
- real php debugger : APD - added socket support - PROTOTYPE WORKING!
- real builder/executer/runner - PROTOTYPE WORKING!
- start make
- more parsers C, C++..
- replace Gtkhtml? - PROTOTYPE STARTED!
Conclusion
Developing on php-gtk is FAST!