diff options
author | Mifpasoti <mifpasoti@outlook.com> | 2019-02-03 15:16:22 -0500 |
---|---|---|
committer | Mifpasoti <mifpasoti@outlook.com> | 2019-02-03 15:16:22 -0500 |
commit | d4404d51dea2891821a80091e0c4bf2ce84c5e67 (patch) | |
tree | a5c2aa16c02ea860c8f51db615583a4baf57ae70 | |
parent | 15cbbb1a853019910e6928427113c9ee6b0fcfba (diff) | |
download | gtk-demos-d4404d51dea2891821a80091e0c4bf2ce84c5e67.tar.gz gtk-demos-d4404d51dea2891821a80091e0c4bf2ce84c5e67.tar.bz2 gtk-demos-d4404d51dea2891821a80091e0c4bf2ce84c5e67.zip |
See the hotnews file.
-rw-r--r-- | README.md | 12 | ||||
-rwxr-xr-x[-rw-r--r--] | demo1 | 40 | ||||
-rwxr-xr-x[-rw-r--r--] | demo2 | 42 | ||||
-rwxr-xr-x[-rw-r--r--] | demo3 | 32 | ||||
-rwxr-xr-x[-rw-r--r--] | demo4 | 28 | ||||
-rwxr-xr-x | demo5 | 7 | ||||
-rwxr-xr-x | demo6 | 7 | ||||
-rwxr-xr-x | demo7 | 7 | ||||
-rwxr-xr-x | demo8 | 7 | ||||
-rwxr-xr-x | demo9 | 7 | ||||
-rwxr-xr-x | demos | 16 | ||||
-rw-r--r-- | demostuff | 104 | ||||
-rw-r--r-- | hotnews | 86 | ||||
-rw-r--r-- | intro | 26 | ||||
-rwxr-xr-x | makesans | 12 | ||||
-rwxr-xr-x | menu | 19 | ||||
-rwxr-xr-x | sanssbcl | bin | 0 -> 39493272 bytes |
17 files changed, 265 insertions, 187 deletions
@@ -1,13 +1,7 @@ # Gtk-Demos -Brief demos of using Gtk user interface from a high level language without any C or makefiles. - -See the intro file for explanation/description. - -No need to compile anything. The demos are scripts, ready to run. +Brief demos of using Gtk user interface from a high level language without any C or makefiles. Installation of sbcl is no longer required. See the hotnews file. It has details and explanation/description of the demos, and notes about this version. To run the demos: - -chmod +x demo[1-4] - -./demo4 +chmod +x demos +./demos @@ -1,28 +1,16 @@ -#!/bin/bash -sbcl --script << 'EOF' 2> >(sed '/^Backtrace/,$d;/^; /d') - ; Refer to the demostuff file for definitions and descriptions. -(load "demostuff") - -(defun main () - (gapp demo1 - (window win demo1 "Four Button Demo" 300 150) - (box h outerbox win) - (box v mainbox outerbox) - (box h buttons mainbox) - (box h numbox mainbox) - (box v leftbuttons buttons) - (box v rightbuttons buttons) - (text thenum "Zero" numbox) - (button button1 "1" leftbuttons (xtext thenum "One")) - (button button2 "2" leftbuttons (xtext thenum "Two")) - (button button3 "3" rightbuttons (xtext thenum "Three")) - (button button4 "4" rightbuttons (xtext thenum "Four")) - (gtk_widget_show_all win)) - (g_application_run demo1 0 nil) - (g_object_unref demo1)) - -(main) - -EOF +(defun demo1 () + (window demo1 demos "Four Button Demo" 300 150) + (box h outerbox1 demo1) + (box v mainbox1 outerbox1) + (box h buttons1 mainbox1) + (box h numbox1 mainbox1) + (box v leftbuttons1 buttons1) + (box v rightbuttons1 buttons1) + (text num1 "Zero" numbox1) + (button b1nw "1" leftbuttons1 (xtext num1 "One")) + (button b1sw "2" leftbuttons1 (xtext num1 "Two")) + (button b1ne "3" rightbuttons1 (xtext num1 "Three")) + (button b1se "4" rightbuttons1 (xtext num1 "Four")) + (gtk_widget_show_all demo1)) @@ -1,26 +1,18 @@ -#!/bin/bash -sbcl --script << 'EOF' 2> >(sed '/^Backtrace/,$d;/^; /d') - ; Refer to the demostuff file for definitions and descriptions. -(load "demostuff") - -(defun main () - (gapp demo2 - (window win demo2 "Numerals Demo" 250 250) - (box h outerbox win) - (box v mainbox outerbox) - (box h numbox mainbox) - (button but1 (bnt 1) mainbox (xnum (bn 1))) - (button but2 (bnt 2) mainbox (xnum (bn 2))) - (button but3 (bnt 3) mainbox (xnum (bn 3))) - (button but4 (bnt 4) mainbox (xnum (bn 4))) - (button but5 (bnt 5) mainbox (xnum (bn 5))) - (button numeralbutton "Numerals" mainbox (togglenumar)) - (text thenum "zero" numbox) - (gtk_widget_show_all win)) - (g_application_run demo2 0 nil) - (g_object_unref demo2)) +(defun demo2 () + (window demo2 demos "Numerals Demo" 250 250) + (box h outerbox2 demo2) + (box v mainbox2 outerbox2) + (box h numbox2 mainbox2) + (button b21 (bnt 1) mainbox2 (xnum (bn 1))) + (button b22 (bnt 2) mainbox2 (xnum (bn 2))) + (button b23 (bnt 3) mainbox2 (xnum (bn 3))) + (button b24 (bnt 4) mainbox2 (xnum (bn 4))) + (button b25 (bnt 5) mainbox2 (xnum (bn 5))) + (button numeralbutton2 "Numerals" mainbox2 (togglenumar)) + (text num2 "zero" numbox2) + (gtk_widget_show_all demo2)) (defparameter numar 'a) ; 'r = I II II IV V. 'a = 1 2 3 4 5. @@ -30,12 +22,8 @@ sbcl --script << 'EOF' 2> >(sed '/^Backtrace/,$d;/^; /d') (defun togglenumar () (setq numar (if (eq numar 'a) 'r 'a)) - (loop as button in (list but1 but2 but3 but4 but5) + (loop as button in (list b21 b22 b23 b24 b25) as n from 1 to 5 do (xlabel button (bnt n)))) -(defun xnum (n) (xtext thenum (format nil "~R" n))) - -(main) - -EOF +(defun xnum (n) (xtext num2 (format nil "~R" n))) @@ -1,30 +1,18 @@ -#!/bin/bash -sbcl --script << 'EOF' 2> >(sed '/^Backtrace/,$d;/^; /d') - ; Refer to the demostuff file for definitions and descriptions. -(load "demostuff") - -(defun main () - (gapp demo3 - (window win demo3 "Dates Demo" 300 200) - (box h outerbox win) - (box v mainbox outerbox) - (button button1 "1066" mainbox (relabel button1 1066)) - (button button2 "1415" mainbox (relabel button2 1415)) - (button button3 "1492" mainbox (relabel button3 1492)) - (button button4 "1620" mainbox (relabel button4 1620)) - (button button5 "1776" mainbox (relabel button5 1776)) - (gtk_widget_show_all win)) - (g_application_run demo3 0 nil) - (g_object_unref demo3)) +(defun demo3 () + (window demo3 demos "Dates Demo" 300 200) + (box h outerbox3 demo3) + (box v mainbox3 outerbox3) + (button date1 "1066" mainbox3 (relabel date1 1066)) + (button date2 "1415" mainbox3 (relabel date2 1415)) + (button date3 "1492" mainbox3 (relabel date3 1492)) + (button date4 "1620" mainbox3 (relabel date4 1620)) + (button date5 "1776" mainbox3 (relabel date5 1776)) + (gtk_widget_show_all demo3)) (defun relabel (button number) (let* ((old (gtk_button_get_label button)) (isdigits (<= 0 (- (char-int (aref old 0)) (char-int #\0)) 9)) (new (format nil (if isdigits "~@R" "~d") number))) (xlabel button new))) - -(main) - -EOF @@ -1,25 +1,7 @@ -#!/bin/bash -sbcl --script << 'EOF' 2> >(sed '/^Backtrace/,$d;/^; /d') - ; Refer to the demostuff file for definitions and descriptions. -(load "demostuff") - -(defun main () - (gapp demo4 - (window win demo4 "Demos Menu" 300 200) - (box h outerbox win) - (box v mainbox outerbox) - (mbutton button1 "Four Button Demo" mainbox (dodemo 1)) - (mbutton button2 "Numerals Demo" mainbox (dodemo 2)) - (mbutton button3 "Dates Demo" mainbox (dodemo 3)) - (gtk_widget_show_all win)) - (g_application_run demo4 0 nil) - (g_object_unref demo4)) - -(defun dodemo (which) - (sb-ext:run-program (format nil "demo~d" which) nil)) - -(main) - -EOF +(defun demo4 () + (window demo4 demos "de minimis" 300 150) + (box v deminimisbox4 demo4) + (text deminimismsg4 "This demo is not yet defined." deminimisbox4) + (gtk_widget_show_all demo4)) @@ -0,0 +1,7 @@ +; Refer to the demostuff file for definitions and descriptions. + +(defun demo5 () + (window demo5 demos "de minimis" 300 150) + (box v deminimisbox5 demo5) + (text deminimismsg5 "This demo is not yet defined." deminimisbox5) + (gtk_widget_show_all demo5)) @@ -0,0 +1,7 @@ +; Refer to the demostuff file for definitions and descriptions. + +(defun demo6 () + (window demo6 demos "de minimis" 300 150) + (box v deminimisbox6 demo6) + (text deminimismsg6 "This demo is not yet defined." deminimisbox6) + (gtk_widget_show_all demo6)) @@ -0,0 +1,7 @@ +; Refer to the demostuff file for definitions and descriptions. + +(defun demo7 () + (window demo7 demos "de minimis" 300 150) + (box v deminimisbox7 demo7) + (text deminimismsg7 "This demo is not yet defined." deminimisbox7) + (gtk_widget_show_all demo7)) @@ -0,0 +1,7 @@ +; Refer to the demostuff file for definitions and descriptions. + +(defun demo8 () + (window demo8 demos "de minimis" 300 150) + (box v deminimisbox8 demo8) + (text deminimismsg8 "This demo is not yet defined." deminimisbox8) + (gtk_widget_show_all demo8)) @@ -0,0 +1,7 @@ +; Refer to the demostuff file for definitions and descriptions. + +(defun demo9 () + (window demo9 demos "de minimis" 300 150) + (box v deminimisbox9 demo9) + (text deminimismsg9 "This demo is not yet defined." deminimisbox9) + (gtk_widget_show_all demo9)) @@ -0,0 +1,16 @@ +#!/bin/bash +./sanssbcl 2> >(sed '/^Backtrace/,$d;/^; /d;/^$/d') + +# This script, demos, uses sanssbcl to run the demos, with or without +# sbcl installed. +# +# sanssbcl has to be present with this script and the demo scripts. +# To make the demos executable do this: chmod +x demos +# To invoke the demos, do this: ./demos +# +# If you want to make sanssbcl, it can be made on a Linux PC that +# has sbcl installed by using the makesans script. To make +# sanssbcl there, do this: chmod +x makesans +# ./makesans +# Then you can copy sanssbcl to another Linux PC, whether it has +# sbcl installed or not. @@ -40,60 +40,54 @@ and defines gapp, window, box, button, text, xtext, and xlabel. ; of them default to having it not be an error. (sb-int:set-floating-point-modes :traps '(:overflow :invalid)) -; gfunc makes a prototype for a gtk function. -(defmacro gfunc (gtkname &rest types) - `(define-alien-routine ,gtkname ,(car types) - ,@(loop as argname in '(a b c d e f g h i j k l m) - as argtype in (cdr types) - collect (list argname argtype)))) -; gfunc above vs x_x etc below: gfunc is more general, but more -; verbose. x_x etc are for specific combinations of argument types. +; Gtk function prototypes: each has a code, such as xx or vxs. The +; first letter of the code is the return value type, and the rest are +; the argument types: +; v = void +; x = void* +; i = int +; l = long +; f = float +; d = double +; s = c-string +; y = vxx function +(loop as (gfunc xx) in + '((gtk_application_window_new xx) + (gtk_window_set_title vxs) + (gtk_window_set_default_size vxii) + (gtk_button_box_new xi) + (gtk_size_group_new xi) + (gtk_bin_get_child xx) + (gtk_label_set_xalign vxf) + (gtk_container_add vxx) + (gtk_label_new xs) + (gtk_label_set_text vxs) + (gtk_button_set_label vxs) + (gtk_button_get_label sx) + (gtk_button_new_with_label xs) + (gtk_widget_destroy xx) + (gtk_application_new xsi) + (g_application_run ixix) + (g_object_unref vx) + (gtk_widget_show_all vx) + (g_signal_connect_data lxsyxxi)) + as types = (loop as x across (string xx) + collect (ecase (char-downcase x) + (#\v 'void) + (#\x '(* t)) + (#\i 'int) + (#\l 'long) + (#\f 'float) + (#\d 'double) + (#\s 'c-string) + (#\y '(function void (* t) (* t))))) + as rv = (car types) + as args = (loop as argname in '(a b c d e f g h i j k l m) + as argtype in (cdr types) + collect (list argname argtype)) + do (eval `(define-alien-routine ,gfunc ,rv ,@args))) -; x_x, v_xs, etc use gfunc to make prototypes for gtk functions. -; The name, such as x_x, includes an underline, to indicate it's -; for a gtk function, because underlines are practically a -; trademark of gtk function names. The letter before the underline -; is the return value type, and the other letters are the argument -; types: -; v for void -; x for void* -; s for c-string -; i for int -; In the following, the g argument is the name of the gtk function. -(defmacro x_x (g) `(gfunc ,g (* t) (* t))) -(defmacro v_x (g) `(gfunc ,g void (* t))) -(defmacro v_xx (g) `(gfunc ,g void (* t) (* t))) -(defmacro x_i (g) `(gfunc ,g (* t) int)) -(defmacro v_xii (g) `(gfunc ,g void (* t) int int)) -(defmacro v_xs (g) `(gfunc ,g void (* t) c-string)) -(defmacro x_s (g) `(gfunc ,g (* t) c-string)) -(defmacro s_x (g) `(gfunc ,g c-string (* t))) -(defmacro i_xix (g) `(gfunc ,g int (* t) int (* t))) -(defmacro x_si (g) `(gfunc ,g (* t) c-string int)) -(defmacro v_xf (g) `(gfunc ,g void (* t) float)) - -; These make the prototypes for the gtk functions. See above. -(x_x gtk_application_window_new) -(v_xs gtk_window_set_title) -(v_xii gtk_window_set_default_size) -(x_i gtk_button_box_new) -(x_i gtk_size_group_new) -(x_x gtk_bin_get_child) -(v_xf gtk_label_set_xalign) -(v_xx gtk_container_add) -(x_s gtk_label_new) -(v_xs gtk_label_set_text) -(v_xs gtk_button_set_label) -(s_x gtk_button_get_label) -(x_s gtk_button_new_with_label) -(x_x gtk_widget_destroy) -(x_si gtk_application_new) -(i_xix g_application_run) -(v_x g_object_unref) -(v_x gtk_widget_show_all) -(gfunc g_signal_connect_data long - (* t) c-string (function void (* t) (* t)) (* t) (* t) int) ; callbackname makes a callback name from an object name. ; The eval-when makes it usable during macro expansions. @@ -131,7 +125,8 @@ and defines gapp, window, box, button, text, xtext, and xlabel. (eval `(defparameter ,abutton nil)) (let ((cb (callbackname abutton))) (eval `(sb-alien::define-alien-callback - ,cb void ((a (* t)) (u (* t))) + ,cb void ((a (* t)) (b (* t))) + (declare (ignore a b)) ,@body)) `(progn (setf ,abutton (gtk_button_new_with_label ,buttonlabel)) @@ -172,7 +167,8 @@ and defines gapp, window, box, button, text, xtext, and xlabel. (eval `(defparameter ,theapp nil)) (let ((cb (callbackname theapp))) (eval `(sb-alien::define-alien-callback - ,cb void ((a (* t)) (u (* t))) + ,cb void ((a (* t)) (b (* t))) + (declare (ignore a b)) ,@body)) `(progn (setf ,theapp (gtk_application_new nil 0)) @@ -0,0 +1,86 @@ +See "Introduction" below. + +The most recent version of the Gtk Demos scripts is an update of the +January 17 version. The following changes have been made since January 17: + + +It's no longer necessary to install sbcl to run the scripts. They're +invoked by a new script named demos. A file named sanssbcl has to be +with the scripts. See "Info about sanssbcl" below. + +The demo scripts have minor changes whose purpose is for them to be +invoked differently than before. See "Invoke the demo scripts" below. + +Some of the object names in the demos have been changed to make them +unique, because all the demos now get loaded into one name space. + +The menu was demo4, but is now named menu. All the demos have been +combined into one Gtk application, which is established by the gapp in +menu. + +Six de minimis demos have been added, so you can easily make your own +demos by editing de minimis demos. The de minimis demos are demo4 through +demo9. You should also edit the menu to give your demos appropriate +names. The button name doesn't matter, and only has to be unique. +The label text is what will show as the button label. Also change the +window title in your demo, to no longer indicate it's a de minimis demo. + +The syntax of the Gtk function prototypes has been changed again, to make +them shorter and neater. If you need more Gtk functions than are presently +in the list, simply add them to the list, using the same syntax. + + +The demos are here: https://github.com/mifpasoti/Gtk-Demos + + +Invoke the demo scripts: + +If the script named demos is not executable, do this: chmod +x demos +To invoke the demo scripts, do this: ./demos + + +Info about sanssbcl: + +If sbcl is not installed, and you don't want to install it, you can copy +or download sanssbcl. Put it in the same directory with the demo scripts. + +If sbcl is installed, you can make sanssbcl by running the makesans script. + +The makesans script is short and easy to understand. And sanssbcl is easy +to understand, by understanding makesans. + + +The January 17 version of the demos had the following changes from the +original version: + +Added a menu of the other demos. It was demo4 in the January 17 version, +but is now named menu. + +The syntax for the list of Gtk function prototypes in demostuff was +changed, but has been changed again. + +Loading the Gtk shared object file by name only, without specifying +the path, but using SBCL's built-in path logic, to be compatible +with more Linux distros. + + +Introduction + +These demos demonstrate using Gtk directly from a higher level language. +None of the demos have any low level code in them. There is no need for +any makefiles, C compilers, or any other low level stuff. There is +probably no need to install Gtk, because it's probably already used by +your Linux. + +You don't need to install sbcl if you have the sanssbcl file. But, if you +want to install sbcl, you can usually install it via the Linux distro. In +the rare circumstance that a particular Linux distro doesn't have sbcl, you +could install, via sbcl.org, either a binary version, or the sources to +compile. + +To use a different high level language for these demos, it is of course +necessary to edit them to change the language. But they aren't very long +and that might not take very long. It's strongly advised to run the +present demos first, and make some minor changes to them, to see the +differences, to make sure to understand how they work, before starting to +change them to a different language. @@ -1,26 +0,0 @@ -These demos demonstrate using Gtk directly from a higher level language. -None of the demos have any low level code in them. There is no need for -any makefiles, C compilers, or any other low level stuff. There is -probably no need to install Gtk, because it's probably already used by -your Linux. - -To use a different high level language for these demos, it is of course -necessary to edit them to change the language. But they aren't very long -and that might not take very long. It's strongly advised to run the -present demos first, and make some minor changes to them, to see the -differences, to make sure to understand how they work, before starting to -change them to a different language. - -When a demo script gets invoked, the code gets compiled into memory, with -a very fast compiler, so there will be no object files, executable binaries, -etc., unless those are desired. The only requirement is to download or copy -and paste the demos and demostuff and make each demo executable with -"chmod +x demo[1-4]". Then run the demos with "./demo4". - -If there are error messages about not finding sbcl, it might be necessary -to install that, or to add it to the path. Installing sbcl is easy, usually -via the Linux distro. - -In the rare circumstance that a particular Linux distro doesn't have sbcl, -you could install, via sbcl.org, either a binary version, or the sources to -compile. diff --git a/makesans b/makesans new file mode 100755 index 0000000..a33c8de --- /dev/null +++ b/makesans @@ -0,0 +1,12 @@ +#!/usr/local/bin/sbcl --script + +; This script, makesans, uses sbcl to make sanssbcl, which can then +; be copied to a Linux PC that doesn't have sbcl. + +(defun load-and-go () + (load "demostuff") + (load "menu") + (loop as n from 1 to 9 do (load (format nil "demo~d" n))) + (menu)) + +(save-lisp-and-die "sanssbcl" :executable t :toplevel #'load-and-go) @@ -0,0 +1,19 @@ +; Refer to the demostuff file for definitions and descriptions. + +(defun menu () + (gapp demos + (window win demos "Demos Menu" 300 350) + (box h outerbox win) + (box v mainbox outerbox) + (mbutton dodemo1 "Four Button Demo" mainbox (demo1)) + (mbutton dodemo2 "Numerals Demo" mainbox (demo2)) + (mbutton dodemo3 "Dates Demo" mainbox (demo3)) + (mbutton dodemo4 "de minimis" mainbox (demo4)) + (mbutton dodemo5 "de minimis" mainbox (demo5)) + (mbutton dodemo6 "de minimis" mainbox (demo6)) + (mbutton dodemo7 "de minimis" mainbox (demo7)) + (mbutton dodemo8 "de minimis" mainbox (demo8)) + (mbutton dodemo9 "de minimis" mainbox (demo9)) + (gtk_widget_show_all win)) + (g_application_run demos 0 nil) + (g_object_unref demos)) diff --git a/sanssbcl b/sanssbcl Binary files differnew file mode 100755 index 0000000..71a7f6d --- /dev/null +++ b/sanssbcl |