Has anyone a clue how postcommand in combobox is supposed to be used?
I want to construct the values of a combobox according to the state of a device just when klicking on the widget.
I can construct a combobox:
(defun combo-1 () (ltk:with-ltk () (let ((c (make-instance 'combobox :text "Values:" :values '(1 2 3)))) (ltk:pack c :side :left :padx 2))))
and change the values outside the constructor:
(defun combo-values () "Change :values of combobox outside the constructor" (ltk:with-ltk () (let ((c (make-instance 'combobox :text "Values:"))) (ltk:pack c :side :left :padx 2) (setf (options c) '(1 2 3))))) ; changes field :values
Even if I think it would have been better if this would have worked instead: (setf (values c) '(1 2 3))
But fail when I try to use postcommand. This doesn't work:
(defun combo-postcommand-1 () "Use of postcommand in combobox." (ltk:with-ltk () (let ((c (make-instance 'combobox :text "Values:" :postcommand (lambda () (set (options c) '(1 2 3)))))) (ltk:pack c :side :left :padx 2))))
(I understand that c is not defined when the lambda command is read but don't see a correct solution.)
I can not even run a simple function as postcommand, because this doesn't work either:
(defun combo-postcommand-2 () (ltk:with-ltk () (let ((c (make-instance 'combobox :text "Values:" :postcommand (lambda () (format t "Run postcommand~%"))))) (ltk:pack c :side :left :padx 2))))
???
On Mon, Jun 25, 2018 at 03:27:46PM +0200, Volker wrote:
hello!
Has anyone a clue how postcommand in combobox is supposed to be used?
[...]
I can not even run a simple function as postcommand, because this doesn't work either:
(defun combo-postcommand-2 () (ltk:with-ltk () (let ((c (make-instance 'combobox :text "Values:" :postcommand (lambda () (format t "Run postcommand~%"))))) (ltk:pack c :side :left :padx 2))))
Looking at the ltk source¹ seems to me that "postcommand" is not a slot of the ltk:combobox (and neither of the parents too).
If I can understand correctly the value (converted to string) is passed straight to wish. Have you tried to pass tcl code instead?
Bye! C.
¹ https://github.com/herth/ltk/blob/master/ltk/ltk.lisp#L2149
If I can understand correctly the value (converted to string) is passed straight to wish. Have you tried to pass tcl code instead?
I can pass a valid tcl command without arguments:
(let ((c (make-instance 'combobox :text "Values:" :postcommand "pwd"))) ...
but I don't know how to use this to change the values list, unfortunately my knowledge in Tcl is rather limiteted.
Have to read a little bit more, I suspect.
/Volker
Maybe someone is interested in a workaround for the postcommand in combobox issue:
(postcommand is a script which will be called right before displaying the pop-down list of choices. This can be used to more dynamically set the list of choices, via the values option. Source: https://tkdocs.com/widgets/combobox.html)
Not really elegant but it solves my problem:
(defun combo-values-when-entering () "Combobox updating values when the mouse enters the widget." (ltk:with-ltk () (let* ((f (make-instance 'ltk:frame)) (outconsole (make-instance 'ltk:scrolled-text :borderwidth 2 :relief :raised :master f)) (c (make-instance 'ltk:combobox :master f :text "Values:"))) (ltk:pack f) (ltk:pack outconsole) (ltk:pack c :side :left :padx 2) (ltk:append-text outconsole "Line 1 (Add more lines here and use the combobox widget thereafter)") (ltk:bind c "<Enter>" (lambda (evt) (declare (ignore evt)) (setf (options c) (cl-ppcre:split #\newline (text outconsole))))))))
(The reading from the textwidget is just an example. In my application I want to read the state of some ports when using the combobox.)
/Volker
On Wed, Jun 27, 2018 at 04:24:11PM +0200, Volker wrote:
Maybe someone is interested in a workaround for the postcommand in combobox issue:
I am interested, thank you!
(postcommand is a script which will be called right before displaying the pop-down list of choices. This can be used to more dynamically set the list of choices, via the values option. Source: https://tkdocs.com/widgets/combobox.html)
So you got rid of the postcommand entirely, right? Interesting.
Sometimes i think could be useful to collect all this snippets for LTK in a wiki or something like that.
Bye! C.
Sometimes i think could be useful to collect all this snippets for LTK in a wiki or something like that.
Hello cage, I really like this idea! Is there some way to realize it? I probably don't know enough to set up a wiki but I would like to help with some content. For sure there are some more people struggling with the same problems and coming to better solutions.
/Volker
Hi Volker,
now that you mention it, there is a wiki, which just waits to be filled :). I never made an official announcement, as I didn't do any code changes recently, but the LTk repository has moved to https://github.com/herth/ltk. There is a wiki - any registered github user should be able to post there. I would be very happy about any contributions!
Peter
On Tue, Jul 3, 2018 at 5:03 PM, Volker vos@lundinova.se wrote:
Sometimes i think could be useful to collect all this snippets for LTK in a wiki or something like that.
Hello cage, I really like this idea! Is there some way to realize it? I probably don't know enough to set up a wiki but I would like to help with some content. For sure there are some more people struggling with the same problems and coming to better solutions.
/Volker
On 07/03/18 17:19, Peter Herth wrote:
now that you mention it, there is a wiki, which just waits to be filled :). I never made an official announcement, as I didn't do any code changes recently, but the LTk repository has moved to https://github.com/herth/ltk. There is a wiki - any registered github user should be able to post there. I would be very happy about any contributions!
It seems that the wiki is not editable for non-collaborators, you probably have to change the permissions, see
https://help.github.com/articles/changing-access-permissions-for-wikis/
(An alternative would be to use pull-requests but I don't know if this would be convenient. I haven't done this yet.)
/Volker
On Tue, Jul 03, 2018 at 05:03:09PM +0200, Volker wrote:
Sometimes i think could be useful to collect all this snippets for LTK in a wiki or something like that.
Hello cage, I really like this idea! Is there some way to realize it? I probably don't know enough to set up a wiki but I would like to help with some content. For sure there are some more people struggling with the same problems and coming to better solutions.
Hi Peter and Volker!
I would like to collaborate to the wiki even if my english is bad; in principle i am ok with a separated wiki on github but i'd like to suggest that you may consider cl-cookbook too.
anyway, count me in! :)
Bye! C.