Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Number input dialog-item

2 views
Skip to first unread message

Peter Paine

unread,
Sep 18, 1998, 3:00:00 AM9/18/98
to
Is there a custom editable-text-dialog-item to accept only number input (a
la CLIM (accept 'number))?
There needs to be interception of paste operations to restrict pasting
non-numeric input. I anticipated writing a custom view-key-event-handler
and window-do-operation (or perhaps the "right" thing to do is contextually
swap the Edit menu Paste menu-item, though I'm not sure if this is
appropriate per dialog-item interaction than per window), but don't want to
reinvent wheels.

PS. Thanks for the postings re. command key input, it never crossed my mind
that the code handles would be catagorized as "window operation"s.

Richard Lynch

unread,
Sep 21, 1998, 3:00:00 AM9/21/98
to
At 12:08 AM 9/19/98, Alice Hartley wrote:
>>>>>
>>Is there a custom editable-text-dialog-item to accept only number input (a
>>la CLIM (accept 'number))?

>(defmethod view-key-event-handler ((thing geo) char)
> (if (alpha-char-p char) (ed-beep) (call-next-method)))
>
>else you can't delete anything or do ctrl-f etc.

Alas, even that doesn't cut it, since (I think) there are a whole mess of
non-digit non-alpha characters that can get in there...

I did something like this once upon a time, and ended up checking for
specific characters (arrows, delete, backspace, etc), because Lisp didn't
have any built-in charset that matched what I wanted.

I dunno where I did this, or I'd send on the source. Sorry.

--
--
-- "TANSTAAFL" Rich ly...@lscorp.com

Alan Ruttenberg

unread,
Sep 22, 1998, 3:00:00 AM9/22/98
to
Hope this helps,
Alan

;-*- Mode: Lisp; Package: CCL -*-
;; ****************************************************************
;;
;; Author: Alan Ruttenberg, MIT Media Lab
;; email: al...@media.mit.edu
;;
;; Created: Thursday September 19,1991
;;
;; ****************************************************************
(in-package :ccl)

(defclass number-editable-text-dialog-item (editable-text-dialog-item)
((return/tab-action :initarg :return/tab-action :initform nil :accessor
return/tab-action)))

(defmethod view-key-event-handler ((v number-editable-text-dialog-item) char)
(let ((buffer-position (buffer-position (fred-buffer v))))
(cond ((or (char= char #\return) (char= char #\tab))
(funcall (or (return/tab-action v) 'not) v)
(change-key-handler (view-window v)))
;; allow digits, #\. #\-, but no other printable characters
((not (or (digit-char-p char) (char= char #\.) (char= char #\-)
(not (graphic-char-p char))
(any-modifier-keys-p)))
(ed-beep))
;; no more than one #\.
((and (char= char #\.) (find #\. (dialog-item-text v)))
(ed-beep))
;; no more than one #\-, and only at start
((and (char= char #\-)
(or (char= #\- (char (dialog-item-text v) 0))
(not (zerop buffer-position))))
(ed-beep))
;; insert 0 with 1 at lead of buffer
((and (char= char #\.) (zerop buffer-position))
(view-key-event-handler v #\0)
(call-next-method))
;; otherwise handle key as usual
(t (call-next-method)))))

(defmethod item-value ((v number-editable-text-dialog-item))
(read-from-string (dialog-item-text v)))

(defmethod set-item-value ((v number-editable-text-dialog-item) value)
(set-dialog-item-text v (prin1-to-string value)))

(defmethod paste ((v number-editable-text-dialog-item))
(let ((scrap (get-scrap :fred)))
(when scrap
(let ((string (car scrap)))
(loop for char across string do (view-key-event-handler v char))))))


You wrote:
Is there a custom editable-text-dialog-item to accept only number input (a
la CLIM (accept 'number))?

Alan Ruttenberg

unread,
Sep 22, 1998, 3:00:00 AM9/22/98
to
Alice points out that this code doesn't handle scientific notation. If someone extends it to handle this or other cases do please send the revised version back.

-Alan

0 new messages