#!ruby -Ku # -*- mode: ruby; coding: utf-8 -*- # Last updated: <2016/10/13 06:21:04 +0900> # # Ruby/Tk + tkDND でファイルのドロップを受け付けるかテスト # Tk拡張を導入していないと動作しない。 # Windows10 x64 + Ruby 2.2.5 p319 + Ruby/Tk + TkDND 2.8 で動作確認 # # 参考ページ # # [ruby-list:49771] TkDND での日本語名の扱い # http://ruby-list.ruby-lang.narkive.com/lx7VFWDo/ruby-list-49771-tkdnd # # DebianでRubyからTcl/TkのTkDNDを利用してドラッグアンドドロップを実装する -- ぺけみさお # https://www.xmisao.com/2013/07/25/ruby-tkdnd-linux.html require 'tk' require "tkextlib/tkDND" require 'nkf' Tk::TkDND::DND label = TkLabel.new { text "Please File Drop" pack } txt = TkText.new(nil) { dnd_bindtarget('text/uri-list','', "%D") { |d| d.each { |s| # 日本語ファイル名を渡した時におかしくなるので変換処理をする u8str = s.encode("iso-8859-1","utf-8").encode("iso-8859-1","utf-8") u8str.encode!('cp932', 'utf-8') puts u8str insert('end',u8str) insert('end',"\n") } } pack } TkButton.new { text "Exit" command "exit" pack } Tk.mainloop