Arthur W Cater | 5 Sep 13:16
Favicon

y-or-n-dialog contribution

Here's a y-or-n-dialog function using cocoa calls. Maybe there was something like it already but I failed to find it.

Suggested improvements most welcome: I am just learning ...

(in-package :easygui)

(defun y-or-n-dialog (message)
  (let* (dialog content
         (app (#/sharedApplication ns:ns-application))
         (yes (make-instance 'ns:ns-button))
         (no (make-instance 'ns:ns-button))
         (query (make-instance 'ns:ns-text-field)))
    (flet ((buttonize (button text x action)
             (dcc (#/setTitle: button text))
             (dcc (#/setBezelStyle: button #$NSRoundedBezelStyle))
             (dcc (#/sizeToFit button))
             (if (< x 0)
               (let ((left (- 0 x (ns:ns-rect-width (dcc (#/bounds button))))))
                 (dcc (#/setFrameOrigin: button (ns:make-ns-point left 9))))
               (dcc (#/setFrameOrigin: button (ns:make-ns-point x 9))))
             (dcc (#/addSubview: content button))
             (dcc (#/setTarget: button app))
             (dcc (#/setAction: button action))))
      (dcc (#/setStringValue: query message))
      (dcc (#/setFrameOrigin: query (ns:make-ns-point 9 48)))
      (dcc (#/sizeToFit query))
      (let* ((querybounds (dcc (#/bounds query)))
             (width (max 100.0 (+ 18.0 (ns:ns-rect-width querybounds))))
             (rect (ns:make-ns-rect
                    *window-position-default-x*
                    *window-position-default-y*
                    width
                    (max 90.0 (+ 57.0 (ns:ns-rect-height querybounds))))))
        (setf dialog (make-instance 'ns:ns-window
                       :with-content-rect rect
                       :style-mask (logior #$NSBorderlessWindowMask #$NSTexturedBackgroundWindowMask)
                       :backing #$NSBackingStoreBuffered ; TODO? Copied from ccl:examples/cocoa/easygui/views.lisp
                       :defer nil)
              content (#/contentView dialog))
        (buttonize yes "Yes" 9 ( <at> selector #/stopModal))
        (buttonize no "No" (- 9 width) ( <at> selector #/abortModal)))
      (dcc (#/addSubview: content query))
      (prog1
          (eq #$NSRunStoppedResponse (dcc (#/runModalForWindow: app dialog)))
          (#/close dialog)))))
_______________________________________________
Openmcl-devel mailing list
Openmcl-devel <at> clozure.com
http://clozure.com/mailman/listinfo/openmcl-devel
Gary Byers | 5 Sep 15:35

Re: y-or-n-dialog contribution

Thanks.

As a reminder, if anyone wants write access to the SVN repository, just
ask (me, for the time being.)  There's a little bit of setup involved
(on the server end and on your end), but there seem to be several
advantages to doing it this way.

Those advantages include:

1) no two email clients/servers/whatever seem able to agree on which
    of the many standards (if any ...) to follow when wrapping lines
    in email messages, but all seem to agree that lisp source code
    sent in the body of a message should have line breaks inserted
    at unfortunate points, and it takes some small effort and occasional
    guesswork to repair that damage (and sometimes raises lingering doubts
    that nothing's been lost in translation.)
2) as I've gotten older, my attention span and ability to shift focus
    and multitask have all declined.  It may not take any longer to
    deal with small issues like (1), but my ability to get back to
    what I was doing and pick up where I left off has definitely
    declined.  (Of course, so has my long-term memory, so perhaps
    I'm not remembering that correctly ...)  In any case, interrupt
    latency isn't what it could be, and focus (and gears ...) don't
    get shifted as quickly as they could and should.  Whether it's
    due to the ravages of time or other factors, I think that the
    same sort of thing applies to other people who have SVN write
    access.

    Increasing the number of people who have SVN write access seems
    like a good approach here.

Hmm.  That reads more like "me whining" than "an enumeration of the
advantages of encouraging the notion that contributions be made via
SVN".

There are lots of advantages to all concerned if anyone who's
interested in doing so can easily contribute (examples, enhancements,
bug fixes, ...) to CCL, and I hope that I'm right in thinking that
using SVN (rather than ad hoc email) to do that will scale better
and generally work better for everyone (whether senility is
rapidly approaching or still a ways off.)

On Fri, 5 Sep 2008, Arthur W Cater wrote:

> Here's a y-or-n-dialog function using cocoa calls. Maybe there was something like it already but I failed
to find it.
> Suggested improvements most welcome: I am just learning ...
>
> (in-package :easygui)
>
> (defun y-or-n-dialog (message)
>   (let* (dialog content
>          (app (#/sharedApplication ns:ns-application))
>          (yes (make-instance 'ns:ns-button))
>          (no (make-instance 'ns:ns-button))
>          (query (make-instance 'ns:ns-text-field)))
>     (flet ((buttonize (button text x action)
>              (dcc (#/setTitle: button text))
>              (dcc (#/setBezelStyle: button #$NSRoundedBezelStyle))
>              (dcc (#/sizeToFit button))
>              (if (< x 0)
>                (let ((left (- 0 x (ns:ns-rect-width (dcc (#/bounds button))))))
>                  (dcc (#/setFrameOrigin: button (ns:make-ns-point left 9))))
>                (dcc (#/setFrameOrigin: button (ns:make-ns-point x 9))))
>              (dcc (#/addSubview: content button))
>              (dcc (#/setTarget: button app))
>              (dcc (#/setAction: button action))))
>       (dcc (#/setStringValue: query message))
>       (dcc (#/setFrameOrigin: query (ns:make-ns-point 9 48)))
>       (dcc (#/sizeToFit query))
>       (let* ((querybounds (dcc (#/bounds query)))
>              (width (max 100.0 (+ 18.0 (ns:ns-rect-width querybounds))))
>              (rect (ns:make-ns-rect
>                     *window-position-default-x*
>                     *window-position-default-y*
>                     width
>                     (max 90.0 (+ 57.0 (ns:ns-rect-height querybounds))))))
>         (setf dialog (make-instance 'ns:ns-window
>                        :with-content-rect rect
>                        :style-mask (logior #$NSBorderlessWindowMask #$NSTexturedBackgroundWindowMask)
>                        :backing #$NSBackingStoreBuffered ; TODO? Copied from ccl:examples/cocoa/easygui/views.lisp
>                        :defer nil)
>               content (#/contentView dialog))
>         (buttonize yes "Yes" 9 (@selector #/stopModal))
>         (buttonize no "No" (- 9 width) (@selector #/abortModal)))
>       (dcc (#/addSubview: content query))
>       (prog1
>           (eq #$NSRunStoppedResponse (dcc (#/runModalForWindow: app dialog)))
>           (#/close dialog)))))
>
_______________________________________________
Openmcl-devel mailing list
Openmcl-devel <at> clozure.com
http://clozure.com/mailman/listinfo/openmcl-devel
Arthur W Cater | 5 Sep 15:58
Favicon

Re: y-or-n-dialog contribution

Sorry that I didn't think to attach the file instead of pasting into message body.

I certainly didn't mean to cause anybody any extra editing work!
I'm attaching my original file to this message.

Sign me up for SVN write access please; then I'll have to learn how to use it.
As a newbie, very conscious of the enormous amount of both ccl and cocoa
that I don't know, I'm rather scared of contributing buggy code, so I hope that
folk intending to use it will look over it and criticise it. For example in the present
case, I don't know if I should be using some autorelease-pool stuff (I'm not) because
my study hasn't gone there yet. So many FMs to R!

Arthur 

Attachment (y-or-n.lisp): application/octet-stream, 2046 bytes
_______________________________________________
Openmcl-devel mailing list
Openmcl-devel <at> clozure.com
http://clozure.com/mailman/listinfo/openmcl-devel
Favicon

Re: y-or-n-dialog contribution

I do not want to sound unappreciative, or start some flamewar, but given that Clozure CL is in its early stage I think it is important to seed the GUI example pool with samples that are Apple Human Interface Guidelines compliant (http://developer.apple.com/documentation/UserExperience/Conceptual/AppleHIGuidelines/  look for Alert)

We had similar kinds of discussions with MCL for quite some time. It took a long time to finally replace the hand made dialogs (which broke over time) with HIG compliant ones based on high level tool box code. Apple makes this pretty easy actually. I think I even saw some CCL sample code somewhere to just use NSAlert (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSAlert_Class/Reference/Reference.html).

I am all for including a couple of essential dialogs into CCL similar to MCL. y-or-n-dialog, choose-file/folder *... come to mind. These should not even be examples. They should be built in.

all the best,  Alex




On Sep 5, 2008, at 7:58 AM, Arthur W Cater wrote:

Sorry that I didn't think to attach the file instead of pasting into message body.
I certainly didn't mean to cause anybody any extra editing work!
I'm attaching my original file to this message.

Sign me up for SVN write access please; then I'll have to learn how to use it.
As a newbie, very conscious of the enormous amount of both ccl and cocoa
that I don't know, I'm rather scared of contributing buggy code, so I hope that
folk intending to use it will look over it and criticise it. For example in the present
case, I don't know if I should be using some autorelease-pool stuff (I'm not) because
my study hasn't gone there yet. So many FMs to R!

Arthur 

<y-or-n.lisp>_______________________________________________
Openmcl-devel mailing list
Openmcl-devel <at> clozure.com
http://clozure.com/mailman/listinfo/openmcl-devel

Prof. Alexander Repenning


University of Colorado

Computer Science Department

Boulder, CO 80309-430


vCard: http://www.cs.colorado.edu/~ralex/AlexanderRepenning.vcf



_______________________________________________
Openmcl-devel mailing list
Openmcl-devel <at> clozure.com
http://clozure.com/mailman/listinfo/openmcl-devel
Arthur W Cater | 5 Sep 19:29
Favicon

Re: y-or-n-dialog contribution

Alex said:

> I do not want to sound unappreciative, or start some flamewar, but ... <snip>

I said I welcome criticism, and I meant it. Thank you!
My "mission" is to get my own program running under clozurecl, and for me all this
cocoa programming is something I'd rather not be doing at all. Maybe my contribution
will provoke somebody who knows what they're doing - wrt HIG and whatever else -
to do that y-or-n-dialog job properly and replace my attempt. If so, great. Same applies
to menu code I contributed several weeks ago.

Arthur
_______________________________________________
Openmcl-devel mailing list
Openmcl-devel <at> clozure.com
http://clozure.com/mailman/listinfo/openmcl-devel

Gmane