diff options
| author | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-05-01 16:09:54 +0000 |
|---|---|---|
| committer | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-05-01 16:09:54 +0000 |
| commit | 72e35a71aa4b38d661ee20895fc1e39a1ec6905c (patch) | |
| tree | dfeb96c4772df8caba4e01e749c8f3e1262f8fe0 /ext/tk/sample/binstr_usage.rb | |
| parent | 2045cc0e0b4391ed856ce8bcb885e80668e07842 (diff) | |
| download | ruby-72e35a71aa4b38d661ee20895fc1e39a1ec6905c.tar.gz ruby-72e35a71aa4b38d661ee20895fc1e39a1ec6905c.tar.xz ruby-72e35a71aa4b38d661ee20895fc1e39a1ec6905c.zip | |
* renewal Ruby/Tk
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@6237 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/sample/binstr_usage.rb')
| -rw-r--r-- | ext/tk/sample/binstr_usage.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/ext/tk/sample/binstr_usage.rb b/ext/tk/sample/binstr_usage.rb new file mode 100644 index 000000000..91692856f --- /dev/null +++ b/ext/tk/sample/binstr_usage.rb @@ -0,0 +1,39 @@ +#!/usr/bin/env ruby + +require "tk" + +TkMessage.new(:width=>360, :text=><<EOM).pack +This sample shows how to use a binary sequence between Ruby and Tk. \ +This reads the image data from the file as the binary sequence. + +To treat the difference of encodings between on Ruby and on Tk seamlessly, \ +Ruby/Tk converts the encoding of string arguments automatically. \ +I think it is comfortable for users on almost all situations. \ +However, when treats a binary sequence, the convert process makes troubles. + +Tk::BinaryString class (subclass of Tk::EncodedString class) is the class \ +to avoid such troubles. Please see the source code of this sample. \ +A Tk::BinaryString instance is used to create the image for the center button. +EOM + +ImgFile=['images','tcllogo.gif'].join(File::Separator) + +ph1 = TkPhotoImage.new(:file=>ImgFile) +p ph1.configinfo + +b_str = Tk::BinaryString(IO.read(ImgFile)) +p [b_str, b_str.encoding] + +ph2 = TkPhotoImage.new(:data=>b_str) +p ph2.configinfo +p ph2.data(:grayscale=>true) + +ph3 = TkPhotoImage.new() +ph3.put(ph2.data(:grayscale=>true)) + +f = TkFrame.new.pack +TkButton.new(:parent=>f, :image=>ph1, :command=>proc{exit}).pack(:side=>:left) +TkButton.new(:parent=>f, :image=>ph2, :command=>proc{exit}).pack(:side=>:left) +TkButton.new(:parent=>f, :image=>ph3, :command=>proc{exit}).pack(:side=>:left) + +Tk.mainloop |
