本文介绍了错误:无法读取服务器:远程使用ltk时没有这样的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在修改ltk,因为它提供了运行远程图形用户界面的选项。但是,在尝试使用远程图形用户界面时,我遇到了在本地运行ltk时没有遇到的问题:(in-package :ltk-user)
(defun add-current-investigation-frame (master)
(let* ((frame (make-instance 'frame :master master :width 100 :height 100))
(topic-label (make-instance 'label :text "Current Investigation" :master frame))
(project-label (make-instance 'entry :text "N/A" :master frame))
(action-button (make-instance 'button
:master frame
:text "new investigation")))
(setf (command action-button) (lambda ()
(format t "test~%")
(let ((next-project (nth (random 3) '("A" "B" "N/A"))))
(setf (text project-label) next-project))))
(pack frame)
(pack topic-label :side :top)
(pack project-label :side :top)
(pack action-button :side :top)))
(defun create-main-view ()
(let ((wrapper-frame (make-instance 'frame :master nil)))
(pack wrapper-frame)
(add-current-investigation-frame wrapper-frame)))
(defun create-remote-view (&optional (port 8888))
(Ltk:with-remote-ltk port ()
(create-main-view)))
(defun create-local-view ()
(with-ltk ()
(create-main-view)))
运行(create-local-view)
时,一切正常,Entry小工具的内容随机更改。
运行(create-remote-view)
时,收到错误消息can't read server: no such variable
。发生此错误的原因以及如何修复此错误?
我使用的是由Quicklisp部署的remote.tcl
:
#!/usr/bin/wish
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
wm withdraw .
set host localhost
if {[llength $argv] == 2} {
set host [lindex $argv 0]
set port [lindex $argv 1]} else {
set port [lindex $argv 0]}
#puts "connecting to $host $port"
set server [socket $host $port]
set wi [open "|wish" RDWR]
fconfigure $server -blocking 0
fconfigure $wi -blocking 0
fileevent $server readable {set txt [read $server];puts $wi "$txt";flush $wi}
fileevent $wi readable {
if {[eof $wi]} {
close $wi
exit} else {
set txt [read $wi]; puts -nonewline $server $txt;flush $server}}
推荐答案
这是一个初步答案,因为我不能完全确定此修复程序是否不会破坏任何东西。我将在将来更新此答案,以报告遇到的问题。但就目前而言,这解决了问题。
在ltk.lisp
中有一个名为init-wish
的函数,它需要额外的行(send-wish "set server stdout")
(defun init-wish ()
(send-lazy
;; print string readable, escaping all " and
;; proc esc {s} {puts ""[regsub {"} [regsub {\} $s {\\}] {"}]""}
;(send-wish "proc esc {s} {puts "\"[regsub -all {"} [regsub -all {\\} $s {\\\\}] {\"}]\""} ")
;(send-wish "proc escape {s} {return [regsub -all {"} [regsub -all {\\} $s {\\\\}] {\"}]} ")
(send-wish "package require Tk")
;;; PUT MISSING LINE HERE
(send-wish "set server stdout")
;;; PUT MISSING LINE HERE
(flush-wish)
#+:tk84
(send-wish "catch {package require Ttk}")
#-:tk84
(send-wish "if {[catch {package require Ttk} err]} {tk_messageBox -icon error -type ok -message "$err"}")
(send-wish "proc debug { msg } {
global server
puts $server "(:debug \"[escape $msg]\")"
flush $server
} ")
; more code ....
))
说明:该功能似乎设置了愿望界面和动作(在remote.tcl
中插入打印确认)。然而,正如我们所看到的,server
在所有过程中都被引用,但是如果我们认为所有这些声明都在它们自己的命名空间中,那么它永远不会被声明。因此,必须定义缺失的服务器。由于所有输出都由fileevent $wi ...
读取,然后进一步传递,因此将server
定义为stdout
似乎是最明智的。
它似乎起作用了,但我不知道这是否会损坏其他东西
这篇关于错误:无法读取服务器:远程使用ltk时没有这样的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!