#!/usr/bin/newlisp # # Demo to show colored widgets - documentation code snippet # The principle should work with *any* interpreted language # # Tested with newLisp 8.9.9 on Slackware 10.1 # # Nov 29, 2006 - Peter van Eerten #------------------------------------------------------- Embedded GTK (if (= (last (sys-info)) 6) (begin (import "gtk-server.dll" "gtk") (set 'cfgfile (open "C:\\GTK-server\\gtk-server.cfg" "read"))) (begin (import "libgtk-server.so" "gtk") (set 'cfgfile (open "/etc/gtk-server.cfg" "read")))) (cond ((not cfgfile)(println "No GTK-server configfile found! Exiting...")(exit))) (while (read-line cfgfile) (if (starts-with (current-line) "FUNCTION_NAME") (begin (set 'func (chop ((parse (current-line) " ") 2))) (set 'lb (append {(lambda()(setq s "} func {")(dolist (x (args))(setq s (string s " " x)))(get-string (gtk s)))})) (constant (global (sym func)) (eval-string lb)) ) ) ) (close cfgfile) (constant (global 'NULL) "NULL") #------------------------------------------------------- The actual program # Window (gtk_init NULL NULL) (set 'win (gtk_window_new 0)) (gtk_window_set_title win {"Colored buttons"}) (gtk_window_set_position win 1) (gtk_widget_set_size_request win 300 75) (gtk_window_set_resizable win 0) # Buttons (set 'yes_button (gtk_button_new_with_label "Yes")) (set 'no_button (gtk_button_new_with_label "No")) (set 'maybe_button (gtk_button_new_with_label "Maybe")) # Exit button (set 'exit_button (gtk_button_new_with_label "Exit")) # Now arrange widgets on window using boxes (set 'hbox (gtk_hbox_new 0 0)) (gtk_box_pack_start hbox yes_button 1 1 1) (gtk_box_pack_start hbox no_button 1 1 1) (gtk_box_pack_start hbox maybe_button 1 1 1) (gtk_box_pack_start hbox exit_button 1 1 1) (gtk_container_add win hbox) # Now, for the widgets to color, setup names for each of them (gtk_widget_set_name yes_button "yes_button") (gtk_widget_set_name no_button "no_button") (gtk_widget_set_name maybe_button "maybe_button") # Save the current settings (set 'settings (gtk_settings_get_default)) # Parse colors for YES button (gtk_rc_parse_string "\"style \\\"yes_style\\\" { bg[PRELIGHT] = {65535, 0, 0} }\"") (gtk_rc_parse_string "\"style \\\"yes_style\\\" { bg[ACTIVE] = {40000, 0, 0} }\"") (gtk_rc_parse_string "\"style \\\"yes_style\\\" { bg[NORMAL] = {32768, 0, 0} }\"") (gtk_rc_parse_string "\"style \\\"yes_style\\\" { fg[NORMAL] = {65535, 65535, 65535} }\"") (gtk_rc_parse_string "\"widget \\\"*.*.yes_button*\\\" style \\\"yes_style\\\"\"") # Parse colors for NO button (gtk_rc_parse_string "\"style \\\"no_style\\\" { bg[PRELIGHT] = {0, 65535, 0} }\"") (gtk_rc_parse_string "\"style \\\"no_style\\\" { bg[ACTIVE] = {0, 40000, 0} }\"") (gtk_rc_parse_string "\"style \\\"no_style\\\" { bg[NORMAL] = {0, 32768, 0} }\"") (gtk_rc_parse_string "\"style \\\"no_style\\\" { fg[PRELIGHT] = {0, 0, 65535} }\"") (gtk_rc_parse_string "\"style \\\"no_style\\\" { fg[NORMAL] = {65535, 0, 0} }\"") (gtk_rc_parse_string "\"widget \\\"*.*.no_button*\\\" style \\\"no_style\\\"\"") # Parse colors for MAYBE button (gtk_rc_parse_string "\"style \\\"maybe_style\\\" { bg[PRELIGHT] = {0, 0, 65535} }\"") (gtk_rc_parse_string "\"style \\\"maybe_style\\\" { bg[ACTIVE] = {0, 0, 40000} }\"") (gtk_rc_parse_string "\"style \\\"maybe_style\\\" { bg[NORMAL] = {0, 0, 32768} }\"") (gtk_rc_parse_string "\"style \\\"maybe_style\\\" { fg[NORMAL] = {65535, 65535, 0} }\"") (gtk_rc_parse_string "\"widget \\\"*.*.maybe_button*\\\" style \\\"maybe_style\\\"\"") # Let GTK refresh the colors (gtk_rc_reset_styles settings) # Show all widgets (gtk_widget_show_all win) # Mainloop (do-until (or (= event win)(= event exit_button)) # Get event (set 'event (gtk_server_callback "wait")) ) # Exit GUI (exit)