Source for file Gtk.php
Documentation is available at Gtk.php
+----------------------------------------------------------------------+
+----------------------------------------------------------------------+
| Copyright (c) 1997-2003 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 2.02 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available at through the world-wide-web at |
| http://www.php.net/license/2_02.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Alan Knowles <alan@akbkhome.com> |
+----------------------------------------------------------------------+
$Id: Gtk.php,v 1.20 2005/03/14 07:20:36 alan_k Exp $
require_once "PEAR/Frontend.php";
require_once "PEAR/Frontend/Gtk/Packages.php";
require_once "PEAR/Frontend/Gtk/Summary.php";
require_once "PEAR/Frontend/Gtk/Install.php";
require_once "PEAR/Frontend/Gtk/Config.php";
require_once "PEAR/Frontend/Gtk/DirSelect.php";
require_once "PEAR/Frontend/Gtk/Info.php";
require_once "PEAR/Frontend/Gtk/Documentation.php";
* Core Gtk Frontend Class
* All the real work is done in the child classes (Gtk/*.php)
* @author Alan Knowles <alan@akbkhome.com>
class PEAR_Frontend_Gtk extends PEAR_Frontend
* What type of user interface this frontend is for.
* current config? - is this really neccessay - just use Config::singleton?
* @var object PEAR_Config
var $config; // object PEAR_Config
* Gtk Frontend Constructor
* Makes calls to load the glade file, and connect signals.
function PEAR_Frontend_Gtk ()
dl('php_gtk.' . (OS_WINDOWS ? 'dll' : 'so'));
function setConfig (&$config)
$this->config = &$config;
$this->_summary = &new PEAR_Frontend_Gtk_Summary ($this);
$this->_install = &new PEAR_Frontend_Gtk_Install ($this);
$this->_packages = &new PEAR_Frontend_Gtk_Packages ($this);
$this->_config = &new PEAR_Frontend_Gtk_Config ($this);
$this->_dirselect = &new PEAR_Frontend_Gtk_DirSelect ($this);
$this->_info = &new PEAR_Frontend_Gtk_Info ($this);
$this->_documentation= &new PEAR_Frontend_Gtk_Documentation ($this);
* Load the Glade file (and automake widget vars and connect signals)
* Loads the glade file and also maps all widgets 'NAME' in glade file
* Straight maps all handles to 'this object'
* #TODO - base the widgets on 'documented/defined widgets in this file' rather than
* grepping the glade file...
$file = dirname(__FILE__ ). '/Gtk/installer.glade';
return PEAR ::raiseError ('Glade is currently required for the installer to work, please see php GTK install instructions for more information',null ,PEAR_ERROR_DIE );
$this->_glade = &new GladeXML ($file);
foreach ($items[1 ] as $widgetname) {
if (preg_match('/^(_install|_packages|_summary|_config|_dirselect|_info|_documentation)_(.*)$/',$widgetname,$args)) {
//echo "ASSIGN $obj $varname to $widgetname\n";
$this->$obj->$varname = $this->_glade->get_widget ($widgetname);
$varname = "_widget_". $widgetname;
$this->$varname = $this->_glade->get_widget ($widgetname);
foreach ($items[1 ] as $handler) {
if (preg_match('/^(_install|_packages|_summary|_config|_dirselect|_info|_documentation)_(.*)$/',$handler,$args)) {
//echo "CONNECT $obj $method to $handler\n";
exit; // programming error!
$this->_glade->signal_connect ($handler ,array (&$this->$obj,$method));
$this->_glade->signal_connect ( $handler ,array (&$this,$handler));
* the class that manages the class list
* @var object PEAR_Frontend_Gtk_Packages
* the class that manages the Package summary
* @var object PEAR_Frontend_Gtk_Summray
* the class manages package installation
* @var object PEAR_Frontend_Gtk_Install
* the class manages directory selection
* @var object PEAR_Frontend_Gtk_DirSelect
* the class manages simple info prompts
* @var object PEAR_Frontend_Gtk_Info
* Load and initialize the sub modules
function _initInterface () {
// must be a better way - still needs to read -c -C optss
// initialize child objects
$this->_widget_window->connect_after ('realize',array (&$this,'_callbackWindowConfigure'));
$this->_widget_window->connect_after ('configure_event',array (&$this,'_callbackWindowConfigure'));
$this->_widget_details_area->hide ();
$this->_widget_window->show ();
* has the window been configured (eg. pixmaps loaded etc.)
var $_windowConfiguredFlag = FALSE;
* Set up images, styles etc.
* @param object gtkwindow
function _callbackWindowConfigure ($window) {
// must be a better way - still needs to read -c -C optss
$this->_initPixmaps ($window);
if ($this->_windowConfiguredFlag) return;
$this->_windowConfiguredFlag = TRUE;
/* main package selection tab */
$this->_setStyle ('nav_bar','','#7b7d7a',FALSE );
$this->_setStyle ('pear_installer_button','#000000','#7b7d7a');
$this->_setStyle ('config_button','#000000','#7b7d7a');
$this->_setStyle ('documentation_button','#000000','#7b7d7a');
$this->_packages->loadPackageList ();
$this->_setStyle ('black_bg1','#FFFFFF','#000000',FALSE );
$this->_setStyle ('black_bg2','#FFFFFF','#000000',FALSE );
$this->_setStyle ('black_bg3','#FFFFFF','#000000',FALSE );
$this->_setStyle ('black_bg4','#FFFFFF','#000000',TRUE );
//$this->_setStyle('download_list','#000000','#FFFFFF',TRUE);
//$this->_widget_close_details->set_style($newstyle);
$this->_setStyle ('close_details','#FFFFFF','#000000',FALSE );
$this->_loadButton ('close_details' , 'black_close_icon.xpm',TRUE );
$this->_setStyle ('summary' ,'#FFFFFF','#000000',TRUE );
$this->_setFont ('summary','-*-helvetica-bold-r-normal-*-*-80-*-*-p-*-iso8859-1');
$this->_setStyle ('black_msg1','#FFFFFF','#000000',FALSE );
$newstyle = &new GtkStyle ();
$this->_widget_packages_install->set_style ($newstyle);
$this->_loadButton ('pear_installer_button' ,'nav_installer.xpm');
$this->_loadButton ('config_button' , 'nav_configuration.xpm');
$this->_loadButton ('documentation_button' , 'nav_documentation.xpm');
//$this->_setStyleWidget($pixmap,'#000000','#339900',FALSE);
$this->_setStyle ('package_logo','#000000','#339900',TRUE );
$this->_setStyle ('package_logo_text','#FFFFFF','#339900');
$this->_setFont ('package_logo_text','-*-helvetica-bold-r-normal-*-*-100-*-*-p-*-iso8859-1');
$package_logo = &new GtkPixmap (
$this->_pixmaps['pear.xpm'][0 ],
$this->_pixmaps['pear.xpm'][1 ]);
$this->_widget_package_logo->put ($package_logo,0 ,0 );
$this->_setStyle ('white_bg1','#000000','#FFFFFF',TRUE );
$download_icon = &new GtkPixmap (
$this->_pixmaps['downloading_image.xpm'][0 ],
$this->_pixmaps['downloading_image.xpm'][1 ]);
$this->_widget_white_bg1->put ($download_icon,0 ,0 );
$this->_setStyle ('downloading_logo','#000000','#339900',TRUE );
$this->_setStyle ('downloading_logo_text','#FFFFFF','#339900');
$this->_setFont ('downloading_logo_text','-*-helvetica-bold-r-normal-*-*-100-*-*-p-*-iso8859-1');
$this->_widget_downloading_logo_text->set_justify ( GTK_JUSTIFY_LEFT );
$installer_logo = &new GtkPixmap (
$this->_pixmaps['pear.xpm'][0 ],
$this->_pixmaps['pear.xpm'][1 ]);
$this->_widget_downloading_logo->put ($installer_logo,0 ,0 );
/* configuration loading */
$this->_config->loadConfig ();
$this->_setStyle ('config_logo','#000000','#339900',TRUE );
$this->_setStyle ('config_logo_text','#FFFFFF','#339900');
$this->_setFont ('config_logo_text','-*-helvetica-bold-r-normal-*-*-100-*-*-p-*-iso8859-1');
$config_logo = &new GtkPixmap (
$this->_pixmaps['pear.xpm'][0 ],
$this->_pixmaps['pear.xpm'][1 ]);
$this->_widget_config_logo->put ($config_logo,0 ,0 );
/* documentation loading */
$this->_setStyle ('documentation_logo','#000000','#339900',TRUE );
$this->_setStyle ('documentation_logo_text','#FFFFFF','#339900');
$this->_setFont ('documentation_logo_text','-*-helvetica-bold-r-normal-*-*-100-*-*-p-*-iso8859-1');
$documentation_logo = &new GtkPixmap (
$this->_pixmaps['pear.xpm'][0 ],
$this->_pixmaps['pear.xpm'][1 ]);
$this->_widget_documentation_logo->put ($documentation_logo,0 ,0 );
$documentation_logo->show ();
$this->_documentation->init ();
$this->_setStyle ('documentation_view_label' ,'#FFFFFF','#000000',TRUE );
$this->_setFont ('documentation_view_label','-*-helvetica-bold-r-normal-*-*-80-*-*-p-*-iso8859-1');
$this->_setStyle ('documentation_package_label' ,'#FFFFFF','#000000',TRUE );
$this->_setFont ('documentation_package_label','-*-helvetica-bold-r-normal-*-*-80-*-*-p-*-iso8859-1');
* Set up images, styles etc.
* Load an image into a button as glade does not support this!
* @param string widget name
* @param string icon name
* @param boolean relief - the left menu is FALSE, other buttons are TRUE
function &_loadButton ($widgetname, $icon, $relief=FALSE ) {
$widget_fullname = "_widget_". $widgetname;
$widget = &$this->$widget_fullname;
// if (get_class($child) == "GtkVBox") return;
$widget->set_relief (GTK_RELIEF_NONE );
//$widget->set_usize(150,100);
// this stuff only gets done once
$pixmap = &new GtkPixmap ($this->_pixmaps[$icon][0 ],$this->_pixmaps[$icon][1 ]);
$vbox->pack_start ( $pixmap, true , true , 2 );
$vbox->pack_end ($child,true ,true ,2 );
//$widget->set_usize(150,100);
* Funky routine to set the style(colours) of Gtkwidgets
* @param string widget name
* @param string foreground color
* @param string background color
* @param booloean Base style of (TRUE)existing or create a new style(FALSE)
function _setStyle ($widgetname,$fgcolor= '',$bgcolor= '',$copy=FALSE ) {
//echo "SET: $widgetname: $fgcolor/$bgcolor ". ((int) $copy) . "\n";
$widget_fullname = "_widget_". $widgetname;
$this->_setStyleWidget ($this->$widget_fullname,$fgcolor,$bgcolor,$copy) ;
function _setStyleWidget (&$widget,$fgcolor= '',$bgcolor= '',$copy=FALSE ) {
$oldstyle = $widget->get_style ();
$newstyle = $oldstyle->copy ();
$newstyle = &new GtkStyle ();
if ($fgcolor) { // set foreground color
$fg = &new GdkColor ($fgcolor);
$newstyle->fg [GTK_STATE_PRELIGHT ] = $fg;
$newstyle->fg [GTK_STATE_NORMAL ] = $fg;
$newstyle->fg [GTK_STATE_ACTIVE ] = $fg;
$newstyle->fg [GTK_STATE_SELECTED ] = $fg;
$newstyle->fg [GTK_STATE_INSENSITIVE ] = $fg;
//$newstyle->bg_pixmap=NULL;
if ($bgcolor) { // set background color
$bg = &new GdkColor ($bgcolor);
$newstyle->bg [GTK_STATE_PRELIGHT ] = $bg;
$newstyle->bg [GTK_STATE_NORMAL ] = $bg;
$newstyle->bg [GTK_STATE_ACTIVE ] = $bg;
$newstyle->bg [GTK_STATE_SELECTED ] = $bg;
$newstyle->bg [GTK_STATE_INSENSITIVE ] = $bg;
//$newstyle->bg_pixmap=NULL;
$widget->set_style ($newstyle);
function _setFont ($widgetname,$fontname) {
$font = gdk ::font_load ($fontname);
$widget_fullname = "_widget_". $widgetname;
$widget = &$this->$widget_fullname;
$oldstyle = $widget->get_style ();
$newstyle = $oldstyle->copy ();
$widget->set_style ($newstyle);
* All the pixmaps from the xpm directory
var $_pixmaps = array (); // associative array of filename -> pixmaps|mask array objects used by application
* initialize the pixmaps - load the into $this->_pixmaps[name][0|1]
* @param object gtkwindow the window from the realize event.
function _initPixmaps (&$window) {
if ($this->_pixmaps) return;
$dir = dirname(__FILE__ ). '/Gtk/xpm';
while (($file = readdir($dh)) !== FALSE ) {
if (@$file{0 } == '.') continue;
//echo "loading {$dir}/{$file}";
Gdk ::pixmap_create_from_xpm ($window->window , NULL , "{ $dir}/{ $file}" );
* Menu Callback - Exit/Quit
* Left button callback - goto installer
function _callbackShowInstaller () {
$this->_widget_pages->set_page (0 );
* Left button callback - goto config page
function _callbackShowConfig () {
$this->_widget_pages->set_page (2 );
/*-------------------------------------Downloading --------------------------------*/
* PEAR_Command Callback - used by downloader
* @param string message type
* @param string message data
function _downloadCallback ($msg, $params) {
$this->_install->_downloadCallback ($msg, $params);
/*---------------- Dir Seleciton stuff -----------------------*/
//-------------------------- BASE Installer methods --------------------------
* Callback from command API, that sends data back from config-show
* @param mixed data requeted by another part of this program
* @param string the command that was sent to result in this
function outputData ($data,$command= ''){
$this->_config->buildConfig ($data['data']);
$this->_install->uninstallOutputData ($data);
$this->_info->show ($data['data']);
//echo "COMMAND : $command\n";
//echo "DATA: ".print_r($data,true)."\n";
function log ($msg,$command= '') {
return $this->_info->show (" LOG: $msg: $command" );
function displayLine ($msg,$args)
return $this->_info->show (" DISPLAYLINE: $msg: $args" );
function display ($text,$command= '')
return $this->_info->show (" TEXT: $text: $command" );
// {{{ displayError(eobj)
function displayError ($eobj)
//echo "ERROR: ".$eobj->getMessage();
return $this->_info->show ("ERROR: ". $eobj->getMessage ());
// {{{ displayFatalError(eobj)
function displayFatalError ($eobj)
echo "FATAL ERROR: ". $eobj->getMessage ();
return $this->_info->show ("FATAL ERROR: ". $eobj->getMessage ());
// {{{ displayHeading(title)
function displayHeading ($title)
// {{{ userDialog(prompt, [type], [default])
function userDialog ($prompt, $type = 'text', $default = '')
echo "Dialog?" . $prompt;
// {{{ userConfirm(prompt, [default])
function userConfirm ($prompt, $default = 'yes')
echo "\nConfirm?" . $prompt;
// {{{ startTable([params])
function startTable ($params = array ())
// {{{ tableRow(columns, [rowparams], [colparams])
function tableRow ($columns, $rowparams = array (), $colparams = array ())
echo "\nBOLD?" . $prompt;
Documentation generated on Mon, 11 Mar 2019 14:28:56 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|