This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

LTK: listbox

4 posts · 3836 views

LTK users here? :)

I've come across certain issues concerning the listbox widget.

First of all, evidently there's no `activate' method.

Suppose I create a listbox with three items and select the second (i. e. the middle) one at the initialization:
(with-ltk ()
  (let ((l (make-instance 'listbox)))
    (listbox-append l '("foo" "bar" "baz"))
    (listbox-select l 1)
    (pack l)
    (focus l)))
Naturally when the user presses arrow keys, it's desirable that the selected item should be active. However, it's the last one that is active in the example above. As a way out one could use the activate method, but it hasn't apparently been implemented. Actually the implementation isn't hard at all:
(defgeneric listbox-activate (l index))
(defmethod listbox-activate ((l listbox) index)
  (format-wish "~a activate ~a" (widget-path l) index) 
  l)
However, I'm afraid I may be missing some point...

On a related note: the listbox widget has the listvariable option. However, I failed to produce a working example. Any suggestions? (BTW, I greatly appreciate LTK's design in the way that it keeps all the StringVar mess under the hood, unlike Python. It would be nice to have the VALUE method for listboxes as well. Yet I don't know how to retrieve listbox items if not implementing listbox-get, which is also missing and perhaps obsolete.)

I've found the LTK mailing list, but something must be wrong with mailing lists on common-lisp.net, the links are broken for the most part.

Re: LTK: listbox

I'm afraid I can't help you with LTK, but your problem with the mailing list is because common-lisp.net is going through a very horrible transition, apparently the maintainer was forced to switch hosting provider at short notice and the mailing lists were a casualty because the new host doesn't support the same mail manager.

Re: LTK: listbox

Thanks, pjstirling, I didn't know that.

Re: LTK: listbox

As for the listvariable, there's obviously no way to use it:
http://permalink.gmane.org/gmane.lisp.ltk.user/494

However, it's not hard to implement mutatis mutandis:
(defclass tklistvariable ()) 

(defmethod initialize-instance :around ((v tklistvariable) &key)
  (call-next-method)
  (format-wish "~a configure -listvariable ~a ; global ~a ; set ~a {}" (widget-path v) (name v) (name v) (name v)))

(defmethod value ((v tklistvariable))
  (format-wish "global ~a; senddatastrings $~a" (name v) (name v))
  (read-data))

(defmethod (setf value) (val (v tklistvariable))
  (format-wish "global ~a; set ~a [list ~{ \{~a\}~}]" (name v) (name v) val)
  val)

(defwrapper listbox (widget tklistvariable)
  ((xscroll :accessor xscroll :initarg :xscroll :initform nil)
   (yscroll :accessor yscroll :initarg :yscroll :initform nil))
  "listbox")
In the meanwhile I'm pondering why we need the option setter configure if we already have the getter cget and setf. Then there wouldn't be problems like this:
http://thread.gmane.org/gmane.lisp.ltk. ... /focus=502
setfing could be implemented in just few lines. :?