Lisp HUG Maillist Archive

Initial focus in a dialog box

I have a dialog defined as follows:

------

(capi:define-interface dialog-1 ()
  ()
  (:panes
   (pane-1
    capi:radio-button-panel
    :layout-class 'capi:column-layout
    :title "Buttons"
    :items '("Item 1"
             "Item 2"))
   (buttons
    capi:push-button-panel
    :accessor dialog-1-buttons
    :items '("OK" "Cancel")
    :layout-args '(:x-uniform-size-p t)
    :callback-type :interface
    :callbacks '(capi:exit-dialog capi:abort-dialog)))
  (:layouts
   (main-layout
    capi:column-layout
    '(pane-1 buttons)
    :x-adjust :centre))
  (:default-initargs
   :layout 'main-layout))

(capi:display-dialog (make-instance 'dialog-1))

------

That works fine, but now I want the "OK" button to have the initial
focus.

If add the following to the default initargs ...

   :create-callback
   #'(lambda (interface)
       (capi:set-pane-focus 
        (first
         (capi:layout-description
          (capi:pane-layout
           (dialog-1-buttons interface))))))

.... then things are as I want.

But is there a simpler way?

I tried defining the "OK" and "Cancel" buttons separately and
using :INITIAL-FOCUS in the interface's default initargs. That
works, but the "OK" button is smaller than the "Cancel" button
and I couldn't find a way to get the buttons to be the same
size.

Simon



Re: Initial focus in a dialog box

Hello Simon,

| I have a dialog defined as follows:
|...snip...|
| That works fine, but now I want the "OK" button to have the initial
| focus.
|...snip...| 
| I tried defining the "OK" and "Cancel" buttons separately and
| using :INITIAL-FOCUS in the interface's default initargs. That
| works, but the "OK" button is smaller than the "Cancel" button
| and I couldn't find a way to get the buttons to be the same
| size.

Have you tried the :focus argument of capi:display-dialog?
--
Sincerely,
Dmitriy Ivanov
lisp.ystok.ru


RE: Initial focus in a dialog box

> From: Dmitriy Ivanov [mailto:divanov@aha.ru] 
> 
> Hello Simon,

Hi Dmitriy,

> | I have a dialog defined as follows:
> |...snip...|
> | That works fine, but now I want the "OK" button to have the
initial
> | focus.
> |...snip...| 
> | I tried defining the "OK" and "Cancel" buttons separately and
> | using :INITIAL-FOCUS in the interface's default initargs. That
> | works, but the "OK" button is smaller than the "Cancel" button
> | and I couldn't find a way to get the buttons to be the same
> | size.
> 
> Have you tried the :focus argument of capi:display-dialog?

Ummm, are you really suggesting that will affect the size of the
"Open" button?

Simon



Re: Initial focus in a dialog box

"Simon Katz" <sk@nomistech.com> wrote:

|> From: Dmitriy Ivanov [mailto:divanov@aha.ru]
| 
| Hi Dmitriy,
| 
|> 
|> Have you tried the :focus argument of capi:display-dialog?
| 
| Ummm, are you really suggesting that will affect the size of the
| "Open" button?

No. And :uniform-size-p does not work here. You have to create each button
by hand, e.g.

(capi:define-interface dialog-1 ()
()
(:panes
   (pane-1
    capi:radio-button-panel
    :layout-class 'capi:column-layout
    :title "Buttons"
    :items '("Item 1"  "Item 2"))
  (ok-button  capi:push-button  :text "OK"
   :default-p t
   :visible-min-width #1='(:character 10)
   :callback 'capi:exit-dialog  :callback-type :interface)
  (cancel-button  capi:push-button  :text "Cancel"
   :cancel-p t
   :visible-min-width #1#
   :callback 'capi:abort-dialog  :callback-type :interface)
  (apply-button  capi:push-button  :text "Apply"
   :reader apply-button :enabled t
   :visible-min-width #1#
   :callback '%apply-settings  :callback-type :interface)
)
(:layouts
  (main-layout capi:column-layout '(pane-1 buttons) :x-adjust :center)
  (buttons  capi:row-layout '(ok-button cancel-button apply-button)
   :gap 10))    ;:uniform-size-p t - does not work
(:default-initargs
  :layout 'main-layout))

(let ((dialog (make-instance 'dialog-1)))
  (capi:display-dialog dialog :focus (apply-button dialog)))

--
Sincerely,
Dmitriy Ivanov
lisp.ystok.ru


Re: Initial focus in a dialog box

you can try something like this :

(defvar *ok-button* nil)
 
> (capi:define-interface dialog-1 ()
> ()
> (:panes
>  (pane-1
>   capi:radio-button-panel
>   :layout-class 'capi:column-layout
>   :title "Buttons"
>   :items '("Item 1"
>            "Item 2"))
>  (buttons
>   capi:push-button-panel
>   :accessor dialog-1-buttons
>   :items (list (setf *ok-button* (make-instance 'push-button
                                    :default T :visible-min-size 60
                                    :text "OK"))
                 (make-instance 'push-button :visible-min-size 60
                                :text "Cancel")
>   :layout-args '(:x-uniform-size-p t)
>   :callback-type :interface
>   :callbacks '(capi:exit-dialog capi:abort-dialog)))
> (:layouts
>  (main-layout
>   capi:column-layout
>   '(pane-1 buttons)
>   :x-adjust :centre))
> (:default-initargs
>  :layout 'main-layout))
> 
> (capi:display-dialog (make-instance 'dialog-1) :initial-focus *ok-button*)

best

Denis


> 
> ------
> 
> That works fine, but now I want the "OK" button to have the initial
> focus.
> 
> If add the following to the default initargs ...
> 
>  :create-callback
>  #'(lambda (interface)
>      (capi:set-pane-focus
>       (first
>        (capi:layout-description
>         (capi:pane-layout
>          (dialog-1-buttons interface))))))
> 
> ... then things are as I want.
> 
> But is there a simpler way?
> 
> I tried defining the "OK" and "Cancel" buttons separately and
> using :INITIAL-FOCUS in the interface's default initargs. That
> works, but the "OK" button is smaller than the "Cancel" button
> and I couldn't find a way to get the buttons to be the same
> size.
> 
> Simon
> 
> 
> 



----------------------------------------------------
Denis Pousseur
6 clos du Drossart
1180 Bruxelles, Belgique

Mail :  denis.pousseur@compositeurs.be
Website : http://compositeurs.be
----------------------------------------------------



RE: Initial focus in a dialog box

I wrote:
> I have a dialog defined as follows:
> 
> ------
> 
> (capi:define-interface dialog-1 ()
>   ()
>   (:panes
>    (pane-1
>     capi:radio-button-panel
>     :layout-class 'capi:column-layout
>     :title "Buttons"
>     :items '("Item 1"
>              "Item 2"))
>    (buttons
>     capi:push-button-panel
>     :accessor dialog-1-buttons
>     :items '("OK" "Cancel")
>     :layout-args '(:x-uniform-size-p t)
>     :callback-type :interface
>     :callbacks '(capi:exit-dialog capi:abort-dialog)))
>   (:layouts
>    (main-layout
>     capi:column-layout
>     '(pane-1 buttons)
>     :x-adjust :centre))
>   (:default-initargs
>    :layout 'main-layout))
> 
> (capi:display-dialog (make-instance 'dialog-1))
> 
> ------
> 
> That works fine, but now I want the "OK" button to have the initial
> focus.


Thanks for the suggestions.

I hadn't previously known there were default buttons -- I had thought
that pressing the return key had to apply to the item with focus.

I can get something better than I was asking for by having the
following for the capi:push-button-panel:

    :items '(:ok :cancel)
    :default-button :ok
    :cancel-button :cancel
    :print-function #'(lambda (x)
                        (ecase x (:ok "OK") (:cancel "Cancel")))
    :layout-args '(:uniform-size-p t)

Simon



Updated at: 2020-12-10 08:48 UTC