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

# Communication function
proc comm str {

    puts $str
    flush stdout
    return [gets stdin]
}

# 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_label_new char*"
comm "DEF libgtk-3.so.0 void gtk_table_attach_defaults long long int int int int"
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"

# Build GUI
comm "EXE gtk_init NULL NULL"
set win [comm "EXE gtk_window_new 0"]
comm "EXE gtk_window_set_title $win \"Tcl PSALM demo\""
comm "EXE gtk_widget_set_size_request $win 300 200"
comm "EXE gtk_window_set_position $win 1"
set table [comm "EXE gtk_table_new 20 20 1"]
comm "EXE gtk_container_add $win $table"
set buttn [comm "EXE gtk_button_new_with_label \"Click to Quit\""]
comm "EXE gtk_table_attach_defaults $table $buttn 12 19 12 19"
set labl [comm "EXE gtk_label_new \"Plain Shell Access to Library Modules for Tcl!\""]
comm "EXE gtk_table_attach_defaults $table $labl 1 15 1 10"
comm "EXE gtk_widget_show_all $win"

# Connect signals
comm "EXE g_signal_connect_data ${win} delete-event callback NULL NULL 0"
comm "EXE g_signal_connect_data ${buttn} clicked callback NULL NULL 0"

# Initialize
set event 0

# Mainloop
while { $event != $buttn & $event != $win} {
    comm "EXE gtk_main_iteration"
    set event [comm "CALLBACK 1"]
}

# Exit Psalm
comm "EXIT"

Return to PSALM