Transvision Detrication for Quarks

The SkriptX Interface

SkriptX is an interface which allows the user to quickly create and display simple graphical elements (windows, popup menu items, etc) on-the-fly using simple Scheme procedures. These are particularly useful in scripts where one wishes to display data or get input from the user.

SkriptX is till in early development and there is no guarantee that it will not crash without any provocation.

Currently, the following is possible:

  1. creation of windows (called text boxes) where data can be continuously displayed and changed until the window is destroyed.
  2. creation of windows which optionally may contain widgets for getting different types of input (checkbuttons, font specs, colour specs, strings, etc) from the user. These are called SkriptX dialogs.
  3. creation of Script-Fu-like menu items.

Contents:

  1. Textboxes
  2. Getting input from the user
  3. SX Items

1. Text Boxes TB


A text box is used for diplaying information in a widget whose contents may be changed programmatically. The textbox may contain many different widgets, but there is one widget that is always created and whose contents may be changed. The widget is either a text widget (for displaying text) or a clist (for displaying info in a multi-columned list). The former is a text textbox (ttb); the latter, a clist textbox (ctb). The following
image shows a textbox created to display current DCC status.

1. Creating a textbox

(sx-text-new w h [proc | FALSE] [SX_items])
(sx-clist-new w h ncolumns [proc | FALSE] [SX_items])
(sx-sclist-new w h ncolumns [proc | #f] [SX_items])

sx-text-new creates and displays a new text window.
sx-clist-new creates and displays a textbox which contains a clist as main widget.
sx-sclist-new is similar to sx-clist-new except that only one row may be selected from the multi-columned list.
All procedures return the id of the new textbox.
w and h are the initial width and height of the box. Use negative values if you want a value to be set automagically.

If an optional procedure proc is given, it will be called when the user destroys the window, for example by clicking on the cancel or close button of the textbox. proc is either FALSE (then nothing will happen), or a Scheme procedure that takes one argument: the id of the textbox.

SX_items is a definition of other widgets that should be in the textbox (title, pixmaps, labels, etc). The only items that make sense here are SX_BUTTON, SX_TITLE, SX_LABEL, SX_PIXMAP, SX_BROWSE and SX_CANCEL.

Examples
Type the following examples at the console and see what happens. Set verbose_return on.

(gs-set! 'verbose_return #t)
(define ttb (sx-text-new 300 200 (lambda(id)(set! ttb -1))
    SX_BUTTON "Clear" (lambda(id data)(sx-text-clear id)) #f -1))
(define ctb (sx-clist-new 300 200 3 (lambda(id)(set! ctb -1))
    SX_BUTTON "Clear" (lambda(id data)(sx-clist-clear id)) #f -1))

The title, label, and other properties of a textbox may be set using the following procedure:

(sx-tb-set! id str_prop str_val)
This sets a particular property str_prop to the specified value str_val. str_prop can be 'label, 'title, "bg-pixmap", 'bg-colour, "fg-colour" or maybe something else. When setting a colour, str_val should be a valid colour specification (e.g. "blue" or "rgb:0/0/ffff" or "rgbi:0/0/1") as described by X(3X).

Example:

(sx-tb-set! ttb "title" "A text textbox")
(sx-tb-set! ttb "bg-pixmap" "pixmaps/weird.xpm")
(sx-tb-set! ctb "title" "A clist textbox")

Manipulating a text textbox ttb

(sx-text-add-text id str)
Appends str to the text already in the text TB which has the ID id. Colour and font codes in str are interpreted.

Example:

(sx-text-add-text ttb "@iHello @C1World!\n")

(sx-text-add-file id filename)
Append the contents of a file to the text in the textbox.

Example:

(sx-text-add-file ttb "/etc/passwd")
Our example ttb up to this point has the appearance shown on the
image.A text textbox

(sx-text-retrieve id)
Returns the contents of a text textbox or "" if textbox is empty.

(sx-text-clear id)
Clear a textbox.

(sx-text-destroy id)
Destroy a textbox.

Manipulating a clist textbox ctb


(All procedures return #f on failure and #t if successful.)

(sx-clist-title! id column new_title)
(sx-clist-column-width! id column width)
Change the title and width of the given column.

Example

(sx-clist-titles-show ctb)
(sx-clist-title! ctb 0 "Whatever")
(sx-clist-title! ctb 1 "1st. Value")
(sx-clist-title! ctb 2 "2nd. Value")
(sx-clist-column-width! ctb 0 80)
(sx-clist-column-width! ctb 1 80)

(sx-clist-titles-hide id)
(sx-clist-titles-show id)
Hide or show column titles.

(sx-clist-add-rows id items)
Appends rows to the list. The data for each row is in a list, each item of which contains the text for a particular cell (the length of each list should normally be equal to the number of columns in the clist). items is therefore a list of lists. Note that cell data must be a string.

Example:
Add 2 rows:
(sx-clist-add-rows ctb (list '("fruits" "apples" "oranges") '("non-fruit" "deer" "lion" "zebra")))

(sx-get-selected-rows id)
Returns a list of selected rows.

(sx-get-selected-text id)
Returns the contents of all selected rows. The result is a list of lists where each list contains the data from a selected row:
(row0 row1 row2 ...) where row0 ::= '(column_00 column_01 ...) etc.

(sx-delete-selected-rows id)
Deletes all selected rows.

(sx-delete-rows id rows)
Takes a list of rows and removes them.

(sx-clist-clear id) removes all rows.

Setting row and cell colour and font
(sx-clist-cell-style! id row column style)
(sx-clist-row-style! id row style)

These set the font, fore- and background colours of a cell or of a row.
style is a string containing any combination of format characters @f, @C, @D, @i, etc, as are normally used when specifying the style in which text should be drawn. Example: "@C4@i" for blue and italics.

Example

(sx-clist-row-style! ctb 0 "@D9@C5")
(sx-clist-cell-style! ctb 1 1 "@b@i@C1")
Our ctb thus far can be seen in the following
image.
A clist textbox

(sx-clist-destroy id) destroys the textbox.

2. Getting input from the user: popup windows and menus


(sx-dialog-new user_data ok_cb|#f cancel_cb|#f [SX_items])
(sx-submit-new console? path_str proc_str [SX_items])

sx-dialog-new immediately creates and displays a window containing many different widgets as specified by the user.
sx-submit-new creates a menu item using the specified path; a dialog window will be displayed later when the user selects the menu item. console? is either TRUE or FALSE. If it is TRUE, an item will be created for the console menu. Otherwise, we want to create one for channel windows.
sx-submit is sx-submit-new with console? set to FALSE.
sx-console-submit is sx-submit-new with console? set to TRUE.

Both ok_cb and cancel_cb, if not #f, are called with user_data as first argument. user_data is returned unmodified.

When the user clicks on the Ok button, the procedure ok_cb is called (provided it was not #f) with user input as remaining arguments . If you are not interested in ok_cb, use FALSE instead. If the operation was cancelled, or if the window was destroyed, cancel_cb is called if it is not #f.
If the dialog window was displayed as a result of a menu item being selected, the procedure proc_str is called with the window number as first actual parameter, the menu path as second argument, and the user input as remaining actual parameters. The window number for the console is -1. Note that proc is a procedure, while proc_str is a string containing the name of a procedure.

proc should take user_data as first argument and as many other arguments as there are SX input items.

proc_str should take a number as first argument, a menu path as second, and as many other arguments as there are SX input items. The number is a window number.

Input items are SX items where the user was expected to choose or to specify something. SX_BUTTONs and SX_PIXMAPs are not input items.

Some simple examples:

(sx-dialog-new
#f
(lambda(d)(say "ok ok ok!"))
#f
SX_TITLE "Hello world"
SX_PIXMAP "pixmaps/oliy.xpm"
SX_BROWSE "Hello @lLarge, @C4Blue World!" 250 -1)
Resulting dialog Menu item definition
example_window_props (sx-submit
  "/Mad man's stuff/Properties/Upper window"
  "_upperwindow_props"
  SX_TITLE "Change font and colour for top window"
  SX_COLOUR "Background colour:" ""
  SX_COLOUR "Foreground colour:" ""
  SX_FONT "Text font:"
  "-*-abadi mt condensed light-medium-r-normal-*-*-130-*-*-*-*-*-*"
  SX_FILE "Background pixmap" "")

The menu action:
(define (_upperwindow_props w path bg fg font xpm)
  (gs-set-window-bg-colour bg w)
  (gs-set-window-fg-colour fg w)
  (if(and(not(string-null? font))(not(gs-set-window-text-font font w)))
    (_say2 w "Can't set font " font))
  (gs-set-window-bg-pixmap xpm w))

sx-submit: signoff dialog (sx-submit
  "/My Box/Server/Signoff"
  "_signoff"
 SX_TITLE "SPX II: Quit IRC"
  SX_STR "Signoff\nmessage:" "$X signing off")

The menu action:
(define (_signoff w path msg)
 (gs-execute w "/quit " msg))

sx-submit: change topic (sx-submit "/My Box/Channel/change topic" "_topic"
  SX_TITLE (string-append (gs-client-name) ": Channel topic")
  SX_STRING "Channel " "*"
  SX_STRING "New topic " "")
The action:

(define (_topic w channel path new_topic)
  (if(null? (gs-window-server2 w))
    (gs-bell -50)
    (begin
      (if(string-null? channel)
        (set! channel (gs-current-channel w)))
      (if channel
        (gs-execute w "/TOPIC " channel " " new_topic)))))

window popup: change modes (sx-submit "/My Box/User modes" "_my_mode"
  SX_TOGGLE "Invisible"       TRUE
  SX_TOGGLE "Server messages" FALSE
  SX_TOGGLE "Restricted"      TRUE
  SX_TOGGLE "Receive wallops"  FALSE
  SX_TOGGLE "IRC Oper"         FALSE)

The menu action:
(define (_my_mode win path i s r w o)
  (let((mode ""))
    (set! mode (string-append mode (if i "+i" "-i")))
    (set! mode (string-append mode (if s "+s" "-s")))
    (set! mode (string-append mode (if r "+r" "-r")))
    (set! mode (string-append mode (if i "+w" "-w")))
    (set! mode (string-append mode (if o "+o" "-o")))
    (gs-execute win "/eval /mode $N " mode)))

3. SX Items


You specify what widgets have to be displayed on a textbox or in a dialogue by using the optional SX_items argument:

SX_item::= empty line | type [arguments] [SX_item]

type is any of the following:

SX_TOGGLE        a checkbutton
SX_NUMBER        input field for a whole number
SX_FLOAT
SX_STRING        input field for a string
SX_FILE          input field for a pathname
SX_FONT          input field for a font name
SX_COLOUR        input field to get a colour specification
SX_TEXT          input field for multiple line text (editor)
SX_CLIST         multicolum list
SX_SLIST         single column list; only 1 item can be selected
SX_MLIST         single column list box; multiple selections are allowed
SX_PIXMAP        display a pixamp
SX_LABEL         display static text
SX_BROWSE        display text in a text widget
SX_FILELOAD      display a file in text widget
SX_TITLE         set the title of the window
SX_BUTTON        just a button. It may have a callback.
SX_OK            the label of the OK button
SX_CANCEL        the label of the Cancel buttons
The following summarizes what else to specify after the type. NA means 'not required'.

Type 1st arg 2nd arg 3rd arg 4th arg
SX_PIXMAP image file name NA NA NA
SX_LABEL label text NA NA NA
SX_TITLE title text NA NA NA
SX_OK label of the 'Ok' button NA NA NA
SX_CANCEL label of the 'Cancel' button NA NA NA
SX_BUTTON label of the button callback procedure user data -1
SX_NUMBER
SX_FLOAT
label string default numeric value NA NA
SX_STRING
SX_FILE
SX_FONT
SX_COLOUR
label string default string value NA NA
SX_TOGGLE label string default value:
TRUE or FALSE
NA NA
SX_TEXT label string default text widget width widget height
SX_FILELOAD file to load widget width widget height NA
SX_BROWSE text to display widget width widget height NA
SX_SLIST
SX_MLIST
label string a list of choices, all strings widget width widget height
SX_CLIST see Textboxes      

For type SX_PIXMAP, if the specified image cant be read, some icon is displayed.

For type SX_BUTTON, the number of parameters for the callback procedure that is bound to the button depends on where the button is being used. If the button is in a textbox, the procedure takes two (2) arguments: the id of the textbox and user_data. Otherwise, it takes just one (1) argument: user_data.

Where a width or a height is required, negative values may given to automatically set the height or width.
Please see $LIBDIR/scripts as well as the directory sample_scripts for examples.


That's all for now about SkriptX.


The following does not belong here.
Adding items to the channel user popup menu

(gs-add-pup str_name str_proc [bool_is_scm_proc])

  str_name: the name of the pop-up item as you want it displayed in the menu
  str_proc: the name of the command that is to be bound to the pup item.
   bool_is_scm_proc can be anything. If it is not given, str_proc is considered to be the name of a Scheme procedure. In that case, when the menu item is activated, str_proc will be called as if the user had typed the following:

      /(str_proc window_number channel nick user@host)

    If bool_is_scm_proc is not given, proc wil be called as if the user had actually typed it:

      /str_proc

    In the latter case, however, certain characters in "str_proc" will be expanded
    before "/str_proc" is executed. Some of the available format chars are:
      $C  - channel name
      $N  - selected nickname (str_proc is called for each selected nick)
      $U  - user@host of selected nick
      $I  - the current contents of the input line
-----------