#!/usr/bin/env rc # # Demonstration on how to create a GTK GUI using Psalm with rc (the Plan 9 Shell) # # Run as follows (sockets): # socat EXEC:./psalm EXEC:./demo.rc # # Or using socat with pipes: # socat EXEC:./psalm,pipes EXEC:./demo.rc,pipes # # Or using dpipe from VDE2: # dpipe ./psalm = ./demo.rc # # Or using pipexec: # pipexec [ A ./psalm ] [ B ./demo.rc ] "{A:1>B:0}" "{B:1>A:0}" # # Or native Linux: # : | { ./psalm | ./demo.rc; } > /dev/fd/0 # # November 28, 2022 by Peter van Eerten. #------------------------------------------------------------------------------------ fn read { $1=`{/usr/bin/awk '{print;exit}'} } fn 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 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 "Calendar App" 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 to Exit"; 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 cb=0 while (test $cb != $win -a $cb != $button) { comm EXE gtk_main_iteration comm CALLBACK 1; cb=$answer } comm EXIT
Return to PSALM