[Solved] supressing gtk warning messages

Post

Posted
Rating:
#1 (In Topic #719)
Guru
BruceSteers is in the usergroup ‘Guru’
Anyone know of a way to suppress the gtk warning messages?

The best answer i have so far is this "hack"…
Uses gb.args

if the arg -q or –quiet is given then before the app loads it launches itself with any and all args plus "2>/dev/null" to redirect the error output and an additional arg -s.

when the 2nd run instance quits the 1st one that launched the second one also quits before it's even done anything.

the check works earliest in the _new() method. in _init() gb.args does not work.

PS. as it runs it's own exe you will need to "Make Executable" before it can work

Code (gambas)

  1.  
  2. Public Sub _new()
  3.  
  4.   Args.Begin()
  5.   Dim bQuiet As Boolean = Args.Has("q", "quiet", "supress gtk error messages")
  6.   If bQuiet Then bQuiet = (Args.Has("s", "supressed", "supressed gtk error warnings") == False)
  7.   Args.End()
  8.  
  9.   If bQuiet And File.In.IsTerm Then  ' if we are not run from a terminal then no need for any of this
  10.     Dim sRestOfargs As String[] = Args.All.Copy()
  11.  
  12.     ' the next 2 lines just handle if being run from the IDE and make Arg[0] be executable name.
  13.     If Not InStr(sRestOfargs[0], "/") Then sRestOfargs[0] = Application.Path &/ Application.Name
  14.     If File.Ext(sRestOfargs[0]) <> "gambas" Then sRestOfargs[0] &= ".gambas"  
  15.  
  16.     sRestOfargs.Insert(["-s", "2>/dev/null"])
  17.     Shell sRestOfargs.Join(" ")
  18.     Me.Close
  19.     Return
  20.  
  21.  

Attached is a simple test app
It's a form with a tiny little TextArea in it, so small it produces warnings on my system when i move the mouse around the window…
(Test:79673): Gdk-CRITICAL **: 20:26:58.775: gdk_window_is_visible: assertion 'GDK_IS_WINDOW (window)' failed

Run with -q and all is quiet.
./Test.gambas -q

Of course this method will suppress ANY error messages ,
shell commands can be fixed by adding '>2&1'
Shell "/run/mycommand 2>&1"
that redirects error output to stdout and stdout is still showing

Please somebody tell me there's a better way…
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’

BruceSteers said


PS. as it runs it's own exe you will need to "Make Executable" before it can work

or do this i guess if you want to add something like this to your own projects …
(see additional commented routine at line 15 to compile exe if run from IDE)

Note: i also did away with the -s arg and made it just remove the -q or –quiet arg on relaunch

Code (gambas)

  1. Public Sub _new()
  2.  
  3.   Dim sRestOfargs As String[] = Args.All.Copy()
  4.  
  5.   Args.Begin()
  6.     Dim bQuiet As Boolean = Args.Has("q", "quiet", "supress gtk error messages")
  7.   Args.End()
  8.  
  9.   If bQuiet And File.In.IsTerm Then
  10.     If Not InStr(sRestOfargs[0], "/") Then sRestOfargs[0] = Application.Path &/ Application.Name
  11.     If File.Ext(sRestOfargs[0]) <> "gambas" Then sRestOfargs[0] &= ".gambas"
  12.  
  13. ' With this command the project is compiled before it's relaunched (If run from the IDE Arg[0] has no path).
  14.    If Not InStr(Args[0], "/") Then
  15.      Shell "cd '" & File.Dir(sRestOfargs[0]) & "'\ngbc3 -xawg\ngba3\necho 'Compiling complete'" Wait
  16.    Endif
  17.  
  18.     If sRestOfargs.Exist("-q") Then sRestOfargs.Remove(sRestOfargs.Find("-q"))
  19.     If sRestOfargs.Exist("--quiet") Then sRestOfargs.Remove(sRestOfargs.Find("--quiet"))
  20.  
  21.     sRestOfargs.Add("2>/dev/null")
  22.  
  23.     Shell sRestOfargs.Join(" ")
  24.     Me.Close
  25.     Return
  26.  
  27.  
  28.  

Making the exe compile itself first before relaunching helps when developing as in the IDE you can just hit the run button without having to compile first.
You have to compile before test running the app in the IDE and using the -q arg to suppress the gtk garbage as the app will be relaunching itself if you do not "make exe" then the relaunch runs the old exe.
So the addition above will make the project compile a new exe (with your changes) before relaunch.

Note: DO NOT APPEND -q to other args.  Ie. if you have other args say -V and -s you CANNOT use -qVs  or -Vsq etc you MUST use something like '-Vs -q'
Any of the other args can be appended and be okay but the -q MUST be on it's own to be removed or the app will just cycle relaunching.
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
Thanks to BrianG on the gambas m/l for his help, I now have this solution.

The code below will divert outgoing Error/Debug messages through the File_Read() event where i check for Gtk- and Gdk- messages and Print the error if not.

the downside is that your program will only output to StdOut with Print  (not really much of a downside)


Code (gambas)

  1.  
  2. ' Gambas class file
  3.  
  4. Extern dup2(OldFD As Integer, newfd As Integer) In "libc:6"
  5. Private Writer As File
  6. Private Reader As File
  7. Private restore As File
  8.  
  9. Public Sub _new()
  10.   Writer = Open Pipe "/tmp/testpipeout" For Write
  11.   restore = File.Err
  12.   dup2(Writer.handle, 2)
  13.   Reader = Open Pipe "/tmp/testpipeout" For Read Watch
  14.  
  15. Public Sub File_read()
  16.  
  17.   Dim buffer As String
  18.  
  19.   buffer = Read #Last, -Lof(Last)
  20.   For Each sLine As String In Split(buffer, "\n")
  21.     If Not sLine Then Continue
  22.     If sLine Like "(" & Application.Name & ":*): G*k-*" Then Continue
  23.     Print sLine
  24.   Next
  25.  
  26.  
  27. Public Sub Form_Close()
  28.   If Writer Then Writer.Close()
  29.   If Reader Then Reader.Close()
  30.   dup2(restore.handle, 2)
  31.  
  32. ' This is a test button
  33. Public Sub ButtonTest_Click()
  34.  
  35.   Print "Print Something"
  36.   Debug "Debug Something"
  37.  
  38.  
Online now: No Back to the top
1 guest and 0 members have just viewed this.