[Jprogramming] A dialogue form to view tacit sentences interactively
Oleg Kobchenko
olegykj at yahoo.com
Sat May 2 17:13:57 HKT 2009
(Oops... correction of the last post)
> From: bob therriault <bobtherriault at mac.com>
> Sent: Monday, April 27, 2009 1:20:09 PM
>
>>> http://www.jsoftware.com/pipermail/programming/2009-April/014508.html
>
> Recently I posted the following script to the chat forum, as my
> previous post to this forum was unsuccessful ( resubscribing seemed to
> fix this). It is meant to allow a tacit expression to be viewed in a
> number of formats. It is not complex, but did allow me to stretch my
> abilities with the form editor (my first version displayed in an
> isigraph, until I realized that listboxes would automatically include
> trackbars for oversized displays).
>
> My questions.
>
> 1. Any comments on my approach and style are welcome. I seek guidance.
> 2. I would like to allow a flexible resizing to this form (including
> repositioning of of the form objects), but I am looking for which
> event is triggered by a resize. The gl2 lab shows what can be done
> with isigraph, but not so much for the resizing of the form itself.
> Any input is appreciated.
> 3. Is there a value to tools like this for J users (especially
> beginners)? I am thinking of working a more interactive version that
> could allow the user to examine the intermediate results of the
> different entities. (Apple's conduit approach to Quartz Composer
> http://en.wikipedia.org/wiki/Quartz_Composer
> mixed with Roger Stokes EVM script is the basis of my vision).
> From: "Sherlock, Ric" <R.G.Sherlock at massey.ac.nz>
> Sent: Tuesday, April 28, 2009 4:09:40 PM
>
>>> http://www.jsoftware.com/pipermail/programming/2009-April/014542.html
>
> Here is a slightly different take on your script. The biggest differences:
>
> * the display verb takes a right argument
> * It uses the Unicode box drawing chars if specified by the user's session.
> wd 'set tdisp *', ,LF,~"1 utf8 at ucpboxdraw_jijs_"1 ":STYLE <'ZZZ'
> * It simplifies the event handlers for the radiobuttons by reading which one is
> selected in the update verb.
Here's the script taken from Ric with "a few" changes.
There are two stages in APL/J programming: solve the problem
and then rewrite the code until it cannot be any shorter. :)
* no comments unless absolutely unnecessary or revise code
* show your intention with code and naming, see "display=: ..."
* use first indent instead of flower boxing
* /!\ different verbs for different APIs: cannot use the same
for user API and event handling
* in general, streamline call flow: trace display..update paths
* initialize control names in form locale when calling a handler
verb outside event, such as when form is created ("syschild" and "box")
* no need for "Close" button, window frame already has one
* "Cancel" key is for child dialogs, in main form, use Cmd+W or Alt+F4
* use array of control names to assign event handlers programmatically
* typical use exemplified, as in: display '+/ % #'
* employ "once and only once", see how syschild assigned and next line
* clear traces of globals to avoid error on first use
* "display" name is too generic, should be in style of "disprep" or so
* finally: (note to self) test ad lib changes before sending :)
========================================================= [cut] ===
NB. display - displays tacit sentences in selected format
coerase<'rgtVisual' NB. debug - clear traces of globals
coclass 'rgtVisual'
style=: 5!:
DISPLAY=: 0 : 0
pc display dialog;
xywh 9 156 216 22;cc box edit topmove rightmove bottommove;
xywh 248 24 60 11;cc rbFormatBox radiobutton leftmove rightmove;cn "Box Format";
xywh 248 40 60 11;cc rbFormatLinear radiobutton leftmove rightmove group;cn "Linear Format";
xywh 248 55 60 11;cc rbFormatTree radiobutton leftmove rightmove group;cn "Tree Format";
xywh 248 72 60 11;cc rbFormatParen radiobutton leftmove rightmove group;cn "Paren Format";
xywh 240 11 95 80;cc format groupbox leftmove rightmove;cn "Display Style";
xywh 0 0 225 150;cc tdisp listbox ws_hscroll ws_vscroll lbs_multiplesel rightmove bottommove;
pas 6 6;pcenter;
rem form end;
)
RBFORMAT=: ;:'Box Tree Linear Paren'
display_run=: 3 : 0
wd DISPLAY
wd 'set box *',y
wd 'setfont box ',FIXFONT,';setfocus box;'
wd 'setfont tdisp ',FIXFONT,'; setenable tdisp 1;'
syschild=: 'rbFormat',0{::RBFORMAT
wd 'set ',syschild,' 1;'
box=: y
update ''
wd 'pshow;'
)
display_resume=: 3 : 0
wd 'psel display'
wd 'set box *',box=: y
update''
)
update=: 3 : 0
try.
sidx=. {. 2 4 5 6 2 {~ RBFORMAT i.<8}.syschild
".'ZZZ=. ' , box NB. ZZZ is a global dummy that holds the tacit entry
wd 'set tdisp *', ,LF,~"1 utf8 at ucpboxdraw_jijs_"1 ": sidx style <'ZZZ'
catch.
wd 'set tdisp *',13!:12 ''
end.
)
display_close=: 3 : 0
wd'pclose'
)
display_box_button=: update
((<'display_rbFormat'),each RBFORMAT,each<'_button')=: update
display=: display_run`display_resume at .((<'display') e. {."1 at wdforms)
display_z_=: display_rgtVisual_
display '+/ % #'
========================================================= [cut] ===
More information about the Programming
mailing list