#!/usr/bin/env ksh # # Demonstration on how to create a GTK GUI using Psalm with KSH. # # Run as follows (sockets): # socat EXEC:./psalm EXEC:./demo.ksh # # Or using socat with pipes: # socat EXEC:./psalm,pipes EXEC:./demo.ksh,pipes # # Or using dpipe from VDE2: # dpipe ./psalm = ./demo.ksh # # Or using pipexec: # pipexec [ A ./psalm ] [ B ./demo.ksh ] "{A:1>B:0}" "{B:1>A:0}" # # Or native Linux: # : | { ./psalm | ./demo.ksh; } > /dev/fd/0 # # November 22, 2022 by Peter van Eerten. #------------------------------------------------------------------------------------ function comm { print ${@} 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 long gtk_button_new_with_label char*" comm "DEF libgtk-3.so.0 long gtk_fixed_new void" comm "DEF libgtk-3.so.0 long gtk_fixed_put long long int int" comm "DEF libgtk-3.so.0 long gtk_calendar_new void" 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 libgtk-3.so.0 void gtk_container_add long long" comm "DEF libgobject-2.0.so.0 long g_signal_connect_data int char* address void* void* int" # Design GUI comm "EXE gtk_init 0 0" comm "EXE gtk_window_new 0"; win=${answer} comm "EXE gtk_window_set_title ${win} \"Hello Calendar\"" comm "EXE gtk_widget_set_size_request ${win} 300 300" comm "EXE gtk_fixed_new"; fixed=${answer} comm "EXE gtk_container_add ${win} ${fixed}" comm "EXE gtk_button_new_with_label \"Press Me\""; button=${answer} comm "EXE gtk_widget_set_size_request ${button} 100 30" comm "EXE gtk_fixed_put ${fixed} ${button} 190 260" comm "EXE gtk_calendar_new"; calendar=${answer} comm "EXE gtk_widget_set_size_request ${calendar} 200 200" comm "EXE gtk_fixed_put ${fixed} ${calendar} 10 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 ${button} clicked callback NULL NULL 0" # Mainloop while [[ $cb -ne $button && $cb -ne $win ]] do comm "EXE gtk_main_iteration" comm "CALLBACK 1"; cb=${answer} done comm "EXIT"
Return to PSALM