[Gambas-user] "The program received an X Window System error"... and more problems
Benoît Minisini
gambas at ...1...
Tue Jun 17 01:48:37 CEST 2014
Le 17/06/2014 01:27, Ru Vuott a écrit :
> Hello,
>
> well, I have this code to run a extern program from a Terminal:
>
> ****************************************
> Public Sub Button1_Click()
>
> ' Opens the Terminal:
> Desktop.OpenTerminal
>
> End
>
>
> Public Sub Button2_Click()
>
> Dim c As Integer[]
>
> ' Finds the ID of Terminal window before open:
> c = Desktop.FindWindow("Terminal")
>
> ' Gives the "Focus" to Terminal window:
> Desktop.ActiveWindow = c[c.Max]
>
> ' Runs "Gedit" program:
> Desktop.SendKeys("{gedit\n}")
>
> End
> *********************************************
>
> I have some problems:
>
> 1) If I activate only "gb.desktop", but not also "gb.desktop.x11", I obtain an error at line:
> c = Desktop.FindWindow("Terminal"):
> " cannot load class x11: Unable to load class file"
>
> My question: ok, but why does "gb.desktop" component have the function ".FindWindow()" ?
Because it had it in Gambas 3.5. Now the bug is that Desktop.FindWindow
should automatically load "gb.desktop.x11" behind the scene.
And in the future, when we will get Wayland, we can imagine a
gb.desktop.wayland component, and a gb.desktop component that will
choose between gb.desktop.x11 and gb.desktop.wayland according to the
context.
But your code won't change, it will continue to call Desktop.FindWindow().
>
>
> 2) Well, so I activate also
> I run my program, and press Button1: In console I obtain this notice:
> "(gnome-terminal:21625): GLib-GIO-CRITICAL **: g_settings_get: the format string may not contain '&' (key 'monospace-font-name' from schema 'org.gnome.desktop.interface').
> This call will probably stop working with a future version of glib."
>
> My question: What's that ?
The output console is for your running program *and* all children
processes run by it. You see "gnome-terminal" at the beginning of the
message? Guess what, this is the responsible.
>
>
> 3) By pressing Button1, a Terminal window open. Well, so I press Button2... but I obtain this error:
> " The program 'my_program'
> received an X Window System error.
> This probably reflects a bug in the program.
> The error was 'BadWindow (invalid Window parameter)'.
> (Details: serial 2363 error_code 3 request_code 20 minor_code 0)
> (Note to programmers: normally, X errors are reported asynchronously;
> that is, you will receive the error a while after causing it.
> To debug your program, run it with the --sync command line
> option to change this behavior. You can then get a meaningful
> backtrace from your debugger if you break on the gdk_x_error() function.) "
>
> My question: What's that ?
An X11 error message. X11 is asynchronous by default: nothing ensures
that the terminal is launched when you call Desktop.FindWindow(). You
must retry periodically until you find the window.
>
>
> 4) Now I repeat procedure, but I do not close last Terminal. I run my_program, press Button1: now obviously I have 2 Terminals.
> So, now I press Button2 and I do not receive error or notices.
> Gedit opens.
>
> My question: ...Why does my program runs perfect only with 2 or more Terminals ?
If you understood the previous point, you should now why.
By the way, read carefully the documentation of Desktop.SendKeys(). You
should not put your string beetween braces.
Regards,
--
Benoît Minisini
More information about the User
mailing list