PSALM - demo.yash
Not logged in
#!/usr/bin/env yash
#
# Demonstration on how to create a GTK GUI using Psalm with YASH.
#
# Run as follows within YASH:
#   { ./psalm | ./demo.yash; } >>|0
#
# Or using socat:
#   socat EXEC:./psalm EXEC:./demo.yash
# 
# Or using socat with pipes:
#   socat EXEC:./psalm,pipes EXEC:./demo.yash,pipes
#
# Or using dpipe from VDE2:
#   dpipe ./psalm = ./demo.yash
#
# Or using pipexec:
#   pipexec [ A ./psalm ] [ B ./demo.yash ] "{A:1>B:0}" "{B:1>A:0}"
#
# Or native Linux:
#   : | { ./psalm | ./demo.yash; } > /dev/fd/0
#
# November 22, 2022 by Peter van Eerten.
#------------------------------------------------------------------------------------

function comm()
{
    echo "${@}"
    read answer
}

# Send definitions first
comm "DEF libgtk-3.so.0 void gtk_init int int"
comm "DEF libgtk-3.so.0 long gtk_window_new int"
comm "DEF libgtk-3.so.0 void gtk_window_set_title int char*"
comm "DEF libgtk-3.so.0 void gtk_window_set_position long int"
comm "DEF libgtk-3.so.0 long gtk_button_new_with_label char*"
comm "DEF libgtk-3.so.0 long gtk_table_new int int int"
comm "DEF libgtk-3.so.0 void gtk_container_add long long"
comm "DEF libgtk-3.so.0 long gtk_button_new_with_label char*"
comm "DEF libgtk-3.so.0 long gtk_check_button_new_with_label char*"
comm "DEF libgtk-3.so.0 void gtk_table_attach_defaults long long int int int int"
comm "DEF libgtk-3.so.0 long gtk_entry_new void"
comm "DEF libgtk-3.so.0 char* gtk_entry_get_text long"
comm "DEF libgtk-3.so.0 void gtk_main_iteration void"
comm "DEF libgtk-3.so.0 void gtk_widget_show_all int"
comm "DEF libgtk-3.so.0 void gtk_widget_set_size_request long int int"
comm "DEF libgobject-2.0.so.0 long g_signal_connect_data int char* address void* void* int"

# Design GUI
comm "EXE gtk_init NULL NULL"
comm "EXE gtk_window_new 0"; window=${answer}
comm "EXE gtk_window_set_title ${window} \"This is a title for YASH\""
comm "EXE gtk_window_set_position ${window} 1"
comm "EXE gtk_widget_set_size_request ${window} 300 300"
comm "EXE gtk_table_new 10 10 1"; table=${answer}
comm "EXE gtk_container_add ${window} ${table}"
comm "EXE gtk_button_new_with_label \"Click here\""; button=${answer}
comm "EXE gtk_table_attach_defaults ${table} ${button} 5 9 7 9"
comm "EXE gtk_check_button_new_with_label \"Check this out!\""; check=${answer}
comm "EXE gtk_table_attach_defaults ${table} ${check} 1 6 1 2"
comm "EXE gtk_entry_new"; entry=${answer}
comm "EXE gtk_table_attach_defaults ${table} ${entry} 1 6 3 4"
comm "EXE gtk_widget_show_all ${window}"

# Connect signals
comm "EXE g_signal_connect_data ${window} delete-event callback NULL NULL 0"
comm "EXE g_signal_connect_data ${button} clicked callback NULL NULL 0"
comm "EXE g_signal_connect_data ${entry} activate callback NULL NULL 0"

# Mainloop
while [[ ${event} != ${button} && ${event} != ${window} ]]
do
    comm "EXE gtk_main_iteration"
    comm "CALLBACK 1"; event=${answer}

    if [[ ${event} == ${entry} ]]
    then
        comm "EXE gtk_entry_get_text ${entry}"
        echo "${answer}" >&2
    fi
done

comm "EXIT"

Return to PSALM