[Gambas-user] Gambas GUI server - bash example
Peter Bauer
pebauer68 at gmail.com
Sun May 24 18:07:36 CEST 2020
Hello,
I tried to make Gambas GUI controls usable for bash scripts via TCP/IP
sockets
Somehow it works ! Bash scripts need socat to talk to Gambas sockets.
Simple example App:
https://www.bitkistl.com/2020/05/gambas3-gui-server-bash.html
https://gambas.one/gambasfarm/?id=823&action=search
GUI controls/objects/properties can be queried from a bash script the
following way:
by classname - eg: textbox
by classname.object, instance number and property name - eg:
textbox1.text
#!/bin/bash
gambas() { socat -t 1 tcp:localhost:9090 -; } # connect to gambas GUI
while :
do
var=$(gambas) # wait for gambas event
if [ $? -eq 1 ]; then echo "Cannot connect to Gambas App"; exit; fi
echo "Event: " $var
if [ -z "$var" ]; then echo "Disonnected"; break; fi
if [ $var = "Button1_clicked" ]; then
var=$(echo "textbox1.text" | gambas ) # read property value
echo "Age: " $var
if
fi
done
Introspection of Gambas Controls,Classes, and Object instances work fine
now.
Public Sub full_instrospect(clsname As String)
Dim cls As Class
Dim count, pos As Integer
Dim oo As Object
Dim string$, result As String
Dim propname, objname, clsn, instance_num As String
Print "clsname: "; clsname
pos = InStr(clsname, ".")
If pos > 0 Then
clsn = Left$(clsname, pos - 1) '
button1.foreground\n
propname = Trim$(Right$(clsname, Len(clsname) - pos)) ' foreground
objname = clsn
clsname = Left$(clsn, -1) 'remove number ' button1
Else
clsname = Trim$(clsname)
If IsNumber(Right$(clsname)) Then
instance_num = Right$(clsname)
clsname = Left$(clsname, -1) 'remove number ' button1
Endif
Endif
Try cls = Class.Load(clsname)
If Error Then
Print "full_instrospect() "; Error.Text
Print #rsock, "full_instrospect() "; Error.Text
Return
Endif
If instance_num Then clsname = clsname & instance_num ' button1
Print "Controls: "; Me.Controls.Count ' number of
controls
For Each oo In Me.Controls
If Not propname Then Print #rsock, " "; Trim$(oo.name)
If UCase$(oo.name) = UCase$(clsname) ' can we find a
class or an instance of a class ?
Print "Found cls object: "; clsname
Break
Else If UCase$(oo.name) = UCase$(objname)
Print "Found cls.object object: "; clsname; " "; objname
Try result = Object.GetProperty(oo, propname)
If Error Then
Print #rsock, "full_instrospect() "; Error.Text
Return
Endif
Print #rsock, result
Return
Else
Endif
Next
Print oo
Print oo.Name; ":"
count = 0
For Each string$ In cls.Symbols 'iterate over all symbols
Print string$; ",";
Print #rsock, string$; ",";
count += 1
Next
Print "\nSymbols found: "; count; "\n"
Print #rsock, "\nSymbols found: "; count; "\n"
count = 0
For Each string$ In cls.Symbols
Print "\nTRY: "; clsname; " "; count; " ";
If Not objname Then Print #rsock, "\nTRY: "; clsname; " "; count;
" ";
Try result = Object.GetProperty(oo, string$)
If result Not Begins ":" 'is an event !
Print "Symbol: "; string$; " Value: "; result; "";
If Not objname Then Print #rsock, "Symbol: "; string$;
" Value: "; result; "";
Endif
If Error Then
Print " Error: "; Error.code; " "; Error.Text; " ";
Print #rsock, " Error: "; Error.code; " "; Error.Text; " ";
Endif
count += 1
Next
Print #rsock, "\n"
End
BR,
Peter
https://www.bitkistl.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20200524/bab0f12a/attachment.html>
More information about the User
mailing list