-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.gtk.php
executable file
·148 lines (130 loc) · 3.81 KB
/
index.gtk.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
include_once 'lib/adianti/util/TAdiantiLoader.class.php';
spl_autoload_register(array('TAdiantiLoader', 'autoload_gtk'));
/**
* TApplication Gtk Wrapper
*/
class TApplication extends GtkWindow
{
const APP_TITLE = 'Adianti Framework :: Samples';
static $inst;
private $content;
private $classname;
/**
* Constructor Method
*/
function __construct()
{
parent::__construct();
parent::set_size_request(840,640);
parent::set_position(GTK::WIN_POS_CENTER);
parent::connect_simple('delete-event', array($this, 'onClose'));
parent::connect_simple('destroy', array('Gtk', 'main_quit'));
parent::set_title(self::APP_TITLE);
parent::set_icon(GdkPixbuf::new_from_file('favicon.png'));
$gtk = GtkSettings::get_default();
$gtk->set_long_property("gtk-button-images", TRUE, 0);
$gtk->set_long_property("gtk-menu-images", TRUE, 0);
self::$inst = $this;
$ini = parse_ini_file('application.ini');
$lang = $ini['language'];
TAdiantiCoreTranslator::setLanguage($lang);
TApplicationTranslator::setLanguage($lang);
date_default_timezone_set($ini['timezone']);
$this->content = new GtkFixed;
$vbox = new GtkVBox;
parent::add($vbox);
$vbox->pack_start(GtkImage::new_from_file('app/images/pageheader-gtk.png'), false, false);
$MenuBar = TMenuBar::newFromXML('menu.xml');
$vbox->pack_start($MenuBar, false, false);
$vbox->pack_start($this->content, true, true);
parent::show_all();
}
/**
* Pack a class inside the application window
* @param $class class name
*/
function run($class)
{
if (class_exists($class))
{
$object = new $class;
if ($object instanceof TPage)
{
if ($children = $this->content->get_children())
{
foreach ($children as $child)
{
$this->content->remove($child);
}
}
$this->classname = $class;
$this->content->put($object, 5, 5);
$object->show();
return $object;
}
else
{
$object->show();
return $object;
}
}
}
/**
* Execute a specific method of a class with parameters
*
* @param $class class name
* @param $method method name
* @param $parameters array of parameters
*/
static public function executeMethod($class, $method, $parameters = NULL)
{
if (class_exists($class))
{
$inst = self::getInstance();
$object = $inst->run($class);
$object->$method($parameters);
}
}
/**
* on close the main window
*/
function onClose()
{
$dialog = new GtkMessageDialog(null, Gtk::DIALOG_MODAL, Gtk::MESSAGE_QUESTION,
Gtk::BUTTONS_YES_NO, 'Close the window ?');
$dialog->set_position(GTK::WIN_POS_CENTER);
$response = $dialog->run();
if ($response == Gtk::RESPONSE_YES)
{
$dialog->destroy();
return false;
}
else
{
$dialog->destroy();
return true;
}
}
/**
* Returns the application instance
*/
static function getInstance()
{
return self::$inst;
}
}
ini_set('php-gtk.codepage', 'UTF8');
$app = new TApplication;
try
{
Gtk::Main();
}
catch (Exception $e)
{
$app->destroy();
$ev=new TExceptionView($e);
$ev->show();
Gtk::main();
}
?>