get-file関数でファイル名入力ダイアログを利用できます.戻り値はパスまたは#fです.
オブジェクト指向風にファイル名入力用テキストフィールド+ボタンをまとめたクラスを作成してみます.
#lang racket
(require racket/gui/base)
(define file-input-pane%
(class vertical-pane%
(init-field button-label)
(init-field parent)
(init-field [label #f])
(super-new [parent parent]
[stretchable-height #f]
[stretchable-width #f])
(when label
(new message% [label label]
[stretchable-width #t]
[parent this]))
(define horizontal-pane
(new horizontal-pane% [parent this]
[stretchable-height #f]
[stretchable-width #f]))
(define file-name-field
(new text-field%
[label ""] [parent horizontal-pane]))
(define file-name-button
(new button%
[label button-label]
[parent horizontal-pane]
[callback
(lambda (btn evt)
(let ((fpath (get-file)))
(when fpath
(send file-name-field set-value
(path->string fpath)))))]))
(define/public (get-value)
(send file-name-field get-value))
(define/public (set-value value)
(send file-name-field set-value value))))
;; test
(define frame (new frame% [label "example"]
[width 300]
[height 200]))
(new file-input-pane% [parent frame]
[label "hello"]
[button-label "file"])
(send frame show #t)
0 件のコメント:
コメントを投稿