scorninpc / php-gtk3

GTK3 extension for PHP
https://andor.com.br/
GNU Lesser General Public License v3.0
113 stars 10 forks source link

Catch Gdk-WARNING #51

Closed apss-pohl closed 1 year ago

apss-pohl commented 1 year ago

Hi,

we get a warning when using https://docs.gtk.org/gtk3/method.Menu.popup_at_pointer.html


(php.exe:3064): Gdk-WARNING **: 11:47:21.235: Event with type 4 not holding a GdkSeat. It is most likely synthesized outside Gdk/GTK+

(php.exe:3064): Gdk-WARNING **: 11:47:21.236: Event with type 4 not holding a GdkSeat. It is most likely synthesized outside Gdk/GTK+

I think it is not critical but maybe it can be catched?

scorninpc commented 1 year ago

And this causing any problem? can you send me a working code to test?

apss-pohl commented 1 year ago

Not a problem afaik. More a cosmetic thing to get rid of the warning. Here is some code to reproduce. Right click on try icon will cause the warning.

<?php
function check_menu()
{
    $menu = new GtkMenu();

    $menu->append(new GtkSeparatorMenuItem());
    $quit = GtkMenuItem::new_with_label('Quit');
    $quit->connect('activate', function () {
        var_dump('Quit');
    });

    $menu->append($quit);

    $menu->show_all();
    return $menu;
}

Gtk::init();

defined("APPLICATION_PATH") || define("APPLICATION_PATH", dirname(__FILE__));

$tray = GtkStatusIcon::new_from_file(dirname(realpath(__FILE__)) . "/logo.png");
$tray->set_tooltip_text($tooltip);
$tray->connect("button_press_event", function ($widget, $event = null) {
    if ($event->button->button == 3) {
        // Right click
        $menu = check_menu();
        $menu->popup_at_pointer($event);
        $menu->show_all();
    } 
});

$tray->set_visible(true);

$entry = new GtkEntry();
$entry->set_text('32132133');

// Window
$window = new GtkWindow();
$window->connect("destroy", function () {
    Gtk::main_quit();
});
$window->add($entry);
$window->set_default_size(300, 200);
$window->show_all();

Gtk::main();
scorninpc commented 1 year ago

i've tested, but everything works fine. Warning is a common thing on GTK, due the versions of systems, themes, etc. So will close for now, but any problem, please reopen

apss-pohl commented 1 year ago

Hi Bruno, we are running more often into issues where such a Critical is thrown but we can't catch those in PHP. It there a way you can catch them and trow a PHP Error instead?

(php.exe:15616): GLib-GObject-WARNING **: 21:15:33.575: invalid uninstantiatable type '(NULL)' in cast to 'GtkDialog' 
(php.exe:15616): Gtk-CRITICAL **: 21:15:33.575: gtk_dialog_response: assertion 'GTK_IS_DIALOG (dialog)' failed

This would be very helpful.

scorninpc commented 1 year ago

No you cannot, since this is a internal GTK problem. But its easy to find this problem, as it say GTK_IS_DIALOG

You passing some var to some function that need to be a GtkDialog. This is not a simple message, this is a problem of your code. Show me a piece of code

apss-pohl commented 1 year ago

To find the issue is not the problem, it is already fixed, but to have the ability to writ such into a log file would help because we don't have an open console with our customer. So the errors are invisible to us as the app crashed silently. We need to think of anything else to record them.

scorninpc commented 1 year ago

I need to know the code to think about that. But, if the param is a GtkDialog and you are passing GtkEntry, for example, this is not the extension problem, understand? maybe you can validate the type of variable before call this methods

apss-pohl commented 1 year ago

Forget about this issue, it is fixed already :-) But take it as an example what kind of messages we would like to be able to catch.

scorninpc commented 1 year ago

Forget about this issue, it is fixed already :-)

ok, but i dont think i'm influenced by the title of this issue, or if we are talking about different thinks

The issue is about warning messages, this will not break your code!

your problem is a critical message, that is logical code problem, not binding problem.

I understand that we can handle a exception for errors, but in some cases, GTK not will throw a exception, so we need to verify manualy, or in CPP code, or in PHP code.

Is a nice convension that you may need do some verifications before use. like this https://github.com/scorninpc/php-gtk-cookbook/blob/680771178651ac2998a13c6be8c88c60d64b260f/00024.php#L46 (sorry for exemple, i dont have another one)

apss-pohl commented 1 year ago

Yes, sorry, if i hijacked this thread. Topic may be misleading, indeed. Basically the question is: Can we somehow add functionality to CPP code to "catch and convert" GTK / GDK output (minimum critical, best any type of message to improve code) to PHP messages and/or writ them to a logfile. This might not be the solution for all issues but it would help a lot.

If this is not possible, then it it what is is :-)

scorninpc commented 1 year ago

Can we somehow add functionality to CPP code to "catch and convert" GTK / GDK output (minimum critical, best any type of message to improve code) to PHP messages and/or writ them to a logfile

i dont know any method to do that. As i know, you need to verify manualy and throw a php exception, like this:

looking parameters count https://github.com/scorninpc/php-gtk3/blob/b43a78cce8d8d86f4aa745c161a53d8794188b51/src/Gtk/GtkInfoBar.cpp#L24

verify the param type https://github.com/scorninpc/php-gtk3/blob/65b758e51fb4c3b42d2a187f6012c7d6699ac285/src/Gtk/GtkTreeView.cpp#L42

or verify return https://github.com/scorninpc/php-gtk3/blob/ebd7d7e7cc02a93565d75557b3c88fa752dd4dc8/src/G/GObject.cpp#L337

is the best scenario, but this will increase considerable the code size, and logic needed, causing more bugs

apss-pohl commented 1 year ago

That would be the most sophisticated solution for sure but i agree - it`s an overkill. I was hoping a less intense solution but might not be possible at all..

scorninpc commented 1 year ago

i'm working on a new php-gtk version, that will be auto generated! This will works in the right way https://github.com/scorninpc/php8-gtk4-tests

scorninpc commented 1 year ago

Sven, this is the thing you may need to know

https://github.com/scorninpc/php-gtk3/pull/57/files#diff-f858f6a50e29bac657d97a796a7a0e7363bbfbae854e1fc50bb927d3aee57330

The gtk_tree_path_new_from_string doesn't return boolean when path is empty. This return NULL if the path is invalid

So why the same method on PHP works diferent?

This is a thing you need to verify on PHP, not on PHP, understand?