 |
| View previous topic :: View next topic |
| Author |
Message |
leon_pegg
Joined: 12 Jun 2006 Posts: 113 Location: hemel / UK
|
Posted: Tue Sep 05, 2006 11:57 am Post subject: GTKDEBUG Component |
|
|
I Quickly wrote this its not very advanced but with som work it could be very useful.
| Code: |
class GtkComponent{
protected $signals;
private $connections;
private $connections_after;
public function __construct(){
}
public function connect($signal, $function){
if (isset($this->signals[$signal])) {
if (function_exists($function)) {
$this->connections[$signal][] = $function;
} else {
trigger_error("Invalid Callback",E_USER_WARNING);
}
} else {
trigger_error("$signal is not a valid signal",E_USER_WARNING);
}
}
public function connect_after($signal, $function){
if (isset($this->signals[$signal])) {
$this->connections_after[$signal][] = $function;
}
}
protected function trigger_signal($signal,$parmeter = null){
if (isset($this->connections[$signal])) {
foreach ($this->connections[$signal] as $call){
call_user_func($call,$parmeter);
}
}
}
protected function trigger_signal_after($signal,$parmeter = null){
if (isset($this->connections_after[$signal])) {
foreach ($this->connections_after[$signal] as $call){
call_user_func($call,$parmeter);
}
}
}
}
class error{
public $type;
public $msg;
public $file;
public $line;
public $context;
public function __construct($error_type, $error_msg, $error_file, $error_line, $error_context){
$this->type = $error_type;
$this->msg = $error_msg;
$this->file = $error_file;
$this->line = $error_line;
$this->context = $error_context;
}
}
class GtkDebug extends GtkComponent {
private $listStore;
private $window;
public function __construct(){
$this->signals["ANY-ERROR"] = "ANY-ERROR";
$this->signals["ERROR"] = "ERROR";
$this->signals["NOTICE"] = "NOTICE";
$this->signals["WARNING"] = "WARNING";
set_error_handler(array(&$this, "ERROR_HANDLER"));
// INITIALIZATION
$column0 = 0;
// WIDGET HIERARCHY
$this->window = new GtkWindow();
$scrolledWindow = new GtkScrolledWindow();
$treeView = new GtkTreeView(); // start building the treeview
$this->listStore = new GtkListStore(Gtk::TYPE_STRING); // text
$textRenderer = new GtkCellRendererText();
$textColumn = new GtkTreeViewColumn("Error Message", $textRenderer,
"text", $column0);
// SETTINGS
$this->window->set_title("Debug");
$this->window->set_position(Gtk::WIN_POS_CENTER);
$this->window->set_default_size(330, 500);
$this->window->set_border_width(8);
$treeView->set_model($this->listStore);
// CONNECTIONS
$this->window->connect_simple("destroy", array($this->window, "hide_all"));
$this->window->add($scrolledWindow);
$scrolledWindow->add($treeView);
$treeView->append_column($textColumn);
//$this->window->show_all();
}
function ERROR_HANDLER($error_type, $error_msg, $error_file, $error_line, $error_context)
{
$error_object = new error($error_type,$error_msg,$error_file,$error_line,$error_context);
$this->trigger_signal("ANY-ERROR",$error_object);
switch( $error_type )
{
case E_ERROR:
case E_USER_ERROR:
$this->trigger_signal("ERROR",$error_object);
$this->listStore->append(array('ERROR : ' . $error_msg));
//print_r( 'ERROR : ' . $error_msg . ' (error type ' . $error_type . ' in ' . $error_file . ' on line ' . $error_line . ")\n");
$this->trigger_signal_after("ERROR",$error_object);
break;
case E_WARNING:
case E_USER_WARNING:
$this->trigger_signal("WARNING",$error_object);
$this->listStore->append(array('WARNING : ' . $error_msg));
//print_r( 'WARNING : ' . $error_msg . ' (error type ' . $error_type . ' in ' . $error_file . ' on line ' . $error_line . ")\n");
$this->trigger_signal_after("WARNING",$error_object);
break;
case E_NOTICE:
case E_USER_NOTICE:
$this->trigger_signal("NOTICE",$error_object);
$this->listStore->append(array('NOTICE : ' . $error_msg));
//print_r( 'NOTICE : ' . $error_msg . ' (error type ' . $error_type . ' in ' . $error_file . ' on line ' . $error_line . ")\n");
$this->trigger_signal_after("NOTICE",$error_object);
break;
case 'MY_CUSTOM_TYPE':
echo 'an error has occured. Do something! Quick!',chr(10);
break;
}
$this->trigger_signal_after("ANY-ERROR",$error_object);
return true;
} //END OF ERROR_HANDLER()
public function show_all(){
$this->window->show_all();
}
public function show(){
$this->window->show();
}
public function hide_all(){
$this->window->hide_all();
}
public function hide(){
$this->window->hide();
}
} |
tell me what you think. |
|
| Back to top |
|
 |
cweiske
Joined: 08 Dec 2005 Posts: 454 Location: Leipzig/Germany
|
|
| Back to top |
|
 |
leon_pegg
Joined: 12 Jun 2006 Posts: 113 Location: hemel / UK
|
Posted: Tue Sep 05, 2006 1:03 pm Post subject: |
|
|
no i had not. much more advanced than mine.
gess ill go back t thinking of thinking of something else. |
|
| Back to top |
|
 |
cweiske
Joined: 08 Dec 2005 Posts: 454 Location: Leipzig/Germany
|
Posted: Tue Sep 05, 2006 1:26 pm Post subject: |
|
|
You could create a bug reporting dialog that allows the user to write a feedback, attach a bug report and uses Gtk2_ExceptionDump internally (the class allows this). With a nice "Send" button that can be configured to
a) Send a mail to the author
b) Post the bug report via POST to a HTTP-URL
c) Don't know what more |
|
| Back to top |
|
 |
leon_pegg
Joined: 12 Jun 2006 Posts: 113 Location: hemel / UK
|
Posted: Tue Sep 05, 2006 1:33 pm Post subject: |
|
|
| thats a good idea think i may have go at that. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
 |