1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* (bug fix) TkEntry#delete

* (bug fix) some widget demos
* support <TkVariable object> == <Symbol>
  ( "coerce TkVariable" add to the TODO list :-) )
* freeze some object for security reason


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4282 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagai 2003-08-02 05:04:30 +00:00
parent d7bdf5df56
commit 4c3328f547
33 changed files with 297 additions and 134 deletions

View file

@ -35,6 +35,7 @@ sample/resource.ja
sample/resource.en
sample/tktimer.rb
sample/tktimer2.rb
sample/tktimer3.rb
sample/demos-en/ChangeLog
sample/demos-en/ChangeLog.prev
sample/demos-en/README

View file

@ -33,7 +33,7 @@ MultiTkIp_OK.freeze
################################################
# methods for construction
class MultiTkIp
SLAVE_IP_ID = ['slave'.freeze, '0']
SLAVE_IP_ID = ['slave'.freeze, '0'].freeze
@@IP_TABLE = {}
@ -234,7 +234,12 @@ class MultiTkIp
######################################
SAFE_OPT_LIST = ['accessPath', 'statics', 'nested', 'deleteHook']
SAFE_OPT_LIST = [
'accessPath'.freeze,
'statics'.freeze,
'nested'.freeze,
'deleteHook'.freeze
].freeze
def _parse_slaveopts(keys)
name = nil
safe = false

View file

@ -1,4 +1,4 @@
#
# tk.rb - Tk interface module using tcltklib
# $Date$
# by Yukihiro Matsumoto <matz@netlab.jp>
@ -17,7 +17,7 @@ module TkComm
#Tk_CMDTBL = {}
#Tk_WINDOWS = {}
Tk_IDs = ["00000", "00000"] # [0]-cmdid, [1]-winid
Tk_IDs = ["00000", "00000"].freeze # [0]-cmdid, [1]-winid
# for backward compatibility
Tk_CMDTBL = Object.new
@ -1651,7 +1651,7 @@ class TkBindTag
#BTagID_TBL = {}
BTagID_TBL = TkCore::INTERP.create_table
Tk_BINDTAG_ID = ["btag".freeze, "00000"]
Tk_BINDTAG_ID = ["btag".freeze, "00000"].freeze
TkCore::INTERP.init_ip_env{ BTagID_TBL.clear }
@ -1726,7 +1726,7 @@ class TkVariable
#TkVar_ID_TBL = {}
TkVar_CB_TBL = TkCore::INTERP.create_table
TkVar_ID_TBL = TkCore::INTERP.create_table
Tk_VARIABLE_ID = ["v".freeze, "00000"]
Tk_VARIABLE_ID = ["v".freeze, "00000"].freeze
TkCore::INTERP.add_tk_procs('rb_var', 'args',
"ruby [format \"TkVariable.callback %%Q!%s!\" $args]")
@ -1839,6 +1839,10 @@ class TkVariable
string(value).to_s
end
def to_sym
value.intern
end
def inspect
format "#<TkVariable: %s>", @id
end
@ -1849,6 +1853,8 @@ class TkVariable
self.equal?(other)
when String
self.to_s == other
when Symbol
self.to_sym == other
when Integer
self.to_i == other
when Float
@ -4630,7 +4636,7 @@ end
module TkTreatListItemFont
include TkTreatItemFont
ItemCMD = ['itemconfigure', TkComm::None]
ItemCMD = ['itemconfigure'.freeze, TkComm::None].freeze
def __conf_cmd(idx)
ItemCMD[idx]
end
@ -4770,7 +4776,7 @@ end
module TkTreatMenuEntryFont
include TkTreatItemFont
ItemCMD = ['entryconfigure', TkComm::None]
ItemCMD = ['entryconfigure'.freeze, TkComm::None].freeze
def __conf_cmd(idx)
ItemCMD[idx]
end

View file

@ -11,7 +11,7 @@ class TkTimer
TkCommandNames = ['after'.freeze].freeze
Tk_CBID = ['a'.freeze, '00000']
Tk_CBID = ['a'.freeze, '00000'].freeze
Tk_CBTBL = {}
TkCore::INTERP.add_tk_procs('rb_after', 'id', <<-'EOL')
@ -311,6 +311,22 @@ class TkTimer
self
end
def reset(*reset_args)
restart() if @running
if @init_proc
@return_value = @init_proc.call(self)
else
@return_value = nil
end
@current_pos = 0
@current_args = @init_args
@set_next = false if @in_callback
self
end
def restart(*restart_args)
cancel if @running
if restart_args == []

View file

@ -11,7 +11,7 @@ require 'tkfont'
module TkTreatCItemFont
include TkTreatItemFont
ItemCMD = ['itemconfigure', TkComm::None]
ItemCMD = ['itemconfigure'.freeze, TkComm::None].freeze
def __conf_cmd(idx)
ItemCMD[idx]
end
@ -529,7 +529,7 @@ class TkcTag<TkObject
include TkcTagAccess
CTagID_TBL = TkCore::INTERP.create_table
Tk_CanvasTag_ID = ['ctag', '00000']
Tk_CanvasTag_ID = ['ctag'.freeze, '00000'].freeze
TkCore::INTERP.init_ip_env{ CTagID_TBL.clear }
@ -660,7 +660,7 @@ class TkcTagCurrent<TkcTag
end
class TkcGroup<TkcTag
Tk_cGroup_ID = ['tkcg', '00000']
Tk_cGroup_ID = ['tkcg'.freeze, '00000'].freeze
def create_self(parent, *args)
if not parent.kind_of?(TkCanvas)
fail format("%s need to be TkCanvas", parent.inspect)
@ -823,7 +823,7 @@ class TkImage<TkObject
TkCommandNames = ['image'.freeze].freeze
Tk_IMGTBL = TkCore::INTERP.create_table
Tk_Image_ID = ['i', '00000']
Tk_Image_ID = ['i'.freeze, '00000'].freeze
TkCore::INTERP.init_ip_env{ Tk_IMGTBL.clear }

View file

@ -158,7 +158,7 @@ class TkEntry<TkLabel
self
end
def delete(first, last=None)
tk_send 'insert', first, last
tk_send 'delete', first, last
self
end
def mark(pos)

View file

@ -11,7 +11,7 @@ class TkFont
TkCommandNames = ['font'.freeze].freeze
Tk_FontID = ["@font".freeze, "00000"]
Tk_FontID = ["@font".freeze, "00000"].freeze
Tk_FontNameTBL = TkCore::INTERP.create_table
Tk_FontUseTBL = TkCore::INTERP.create_table

View file

@ -9,7 +9,7 @@ require 'tkfont'
module TkTreatTextTagFont
include TkTreatItemFont
ItemCMD = ['tag', 'configure']
ItemCMD = ['tag'.freeze, 'configure'.freeze].freeze
def __conf_cmd(idx)
ItemCMD[idx]
end
@ -24,7 +24,7 @@ module TkTreatTextTagFont
end
class TkText<TkTextWin
ItemConfCMD = ['tag', 'configure']
ItemConfCMD = ['tag'.freeze, 'configure'.freeze].freeze
include TkTreatTextTagFont
include Scrollable
@ -767,7 +767,7 @@ class TkTextTag<TkObject
include TkTreatTagFont
TTagID_TBL = TkCore::INTERP.create_table
Tk_TextTag_ID = ['tag', '00000']
Tk_TextTag_ID = ['tag'.freeze, '00000'].freeze
TkCore::INTERP.init_ip_env{ TTagID_TBL.clear }
@ -971,7 +971,7 @@ end
class TkTextMark<TkObject
TMarkID_TBL = TkCore::INTERP.create_table
Tk_TextMark_ID = ['mark', '00000']
Tk_TextMark_ID = ['mark'.freeze, '00000'].freeze
TkCore::INTERP.init_ip_env{ TMarkID_TBL.clear }

View file

@ -9,7 +9,7 @@ class TkVirtualEvent<TkObject
TkCommandNames = ['event'.freeze].freeze
TkVirtualEventID = ["<VirtEvent".freeze, "00000", ">".freeze]
TkVirtualEventID = ["<VirtEvent".freeze, "00000", ">".freeze].freeze
TkVirtualEventTBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{ TkVirtualEventTBL.clear }

View file

@ -53,10 +53,8 @@ class Rmt
# Create text window and scrollbar.
@txt = TkText.new(root, 'relief'=>'sunken', 'bd'=>2, 'setgrid'=>true) {|t|
TkScrollbar.new(root, 'command'=>proc{|*args| t.yview *args}) {
pack('side'=>'right', 'fill'=>'both')
}
@txt = TkText.new(root, 'relief'=>'sunken', 'bd'=>2, 'setgrid'=>true) {
yscrollbar(TkScrollbar.new(root){pack('side'=>'right', 'fill'=>'y')})
pack('side'=>'left')
}
@ -247,6 +245,7 @@ class Rmt
rescue
end
TkWinfo.interps.sort.each{|ip|
begin
if Tk.appsend(ip, false, 'info commands ruby') == ""
mode = 'Tcl'
else
@ -254,6 +253,10 @@ class Rmt
end
menu.add('command', 'label'=>format("%s (#{mode}/Tk)", ip),
'command'=>proc{win.newApp ip, mode})
rescue
menu.add('command', 'label'=>format("%s (unknown Tk)", ip),
'command'=>proc{win.newApp ip, mode}, 'state'=>'disabled')
end
}
menu.add('command', 'label'=>format("local (Ruby/Tk)"),
'command'=>proc{win.newApp 'local', 'Ruby'})

View file

@ -4,7 +4,7 @@
# This script is a part of Tom LaStrange's rolodex
#
# Copyright (C) 1998 by Takaaki Tateishi <ttate@jaist.ac.jp>
# Time-stamp: "98/07/20 12:00:02 ttate"
# Time-stamp: "03/08/02 06:23:06 nagai"
#
require "tk"
@ -176,8 +176,8 @@ end
class Rolodex < TkRoot
attr_reader :frame, :buttons, :menu
def initialize
super
def initialize(*args)
super(*args)
@frame = RolodexFrame.new(self)
@frame.pack("side"=>"top",
"fill"=>"y",
@ -314,7 +314,7 @@ Ctrl+S: Search (dummy operation)
EOF
$helpTopics["version"] = <<EOF
This is version 1.0.
This is version 1.0.1.
EOF
Tk.mainloop

View file

@ -4,11 +4,10 @@
# このスクリプトは Tom LaStrange の rolodex の一部です。
#
# Copyright (C) 1998 by Takaaki Tateishi <ttate@jaist.ac.jp>
# Time-stamp: "98/07/20 12:00:36 ttate"
# Time-stamp: "03/08/02 14:02:04 nagai"
#
require "tk"
require 'tkencoding'
Tk.encoding = "euc-jp"
$font = TkFont.new('k14')
@ -198,8 +197,8 @@ end
class Rolodex < TkRoot
attr_reader :frame, :buttons, :menu
def initialize
super
def initialize(*args)
super(*args)
@frame = RolodexFrame.new(self)
@frame.pack("side"=>"top",
"fill"=>"y",
@ -318,7 +317,7 @@ Ctrl+S:
EOF
$helpTopics["バージョン情報"] = <<EOF
バージョンは 1.0 です。
バージョンは 1.0.1e です。
EOF
Tk.mainloop

View file

@ -15,13 +15,20 @@ require 'tkafter'
class TkSquare<TkWindow
def create_self
begin
tk_call 'square', path
rescue
STDERR.print "\nSorry. Your Tk interpreter does not contain " +
'a "square" demonstration widget.' +
"\n ( See documents included the Tcl/Tk source archive. )\n\n"
exit
end
end
def size(amount=nil)
if amount
tk_send 'size', amount
else
number(tk_send 'size')
number(tk_send('size'))
end
end
def position(x,y)

View file

@ -30,6 +30,12 @@ $label2 = TkVariable.new("label2")
$label3 = TkVariable.new("label3")
# setup the entry of the resourc database
if (TkVarAccess.new('tcl_platform')['platform'] == 'unix')
TkOptionDB.add('*Entry.background', 'white')
end
# 各イベント用のメソッド
def rgbToHsv(red,green,blue)
@ -132,7 +138,7 @@ def tc_scaleChanged
scale2 = $root.middle.middle.scale2
scale3 = $root.middle.middle.scale3
case $colorSpace.to_i
case $colorSpace.value.intern
when :rgb
$red = (scale1.get * 65.535).to_i
$green = (scale2.get * 65.535).to_i
@ -167,7 +173,7 @@ def tc_setScales
scale2 = $root.middle.middle.scale2
scale3 = $root.middle.middle.scale3
case $colorSpace.to_i
case $colorSpace.value.intern
when :rgb
scale1.set($red / 65.535)
scale2.set($green / 65.535)
@ -289,7 +295,7 @@ class TkColorMenuFrame<TkFrame
"command" => proc{changeColorSpace(:hsb)}
add "separator"
add "radio",
"label" => "Qutomatic updates",
"label" => "Automatic updates",
"variable" => $autoUpdate,
"value" => "1",
"underline" => "0"
@ -367,7 +373,7 @@ class TkColorMiddleLeftFrame<TkFrame
"relief"=>"sunken",
"borderwidth"=>"2",
"exportselection"=>"false")
@scroll.command(proc{|*args| @names.yview *args})
@scroll.command(proc{|*args| @names.yview(*args)})
@names.bind("Double-1",proc{
tc_loadNamedColor(@names.get(@names.curselection))})
@names.pack("side"=>"left")
@ -490,8 +496,8 @@ end
class TkColor<TkRoot
attr_reader :menu, :bottom, :middle
def initialize
super
def initialize(*args)
super(*args)
@menu = TkColorMenuFrame.new(self)
@menu.pack("side"=>"top", "fill"=>"x")

View file

@ -80,12 +80,28 @@ end
class ButtonFrame < TkFrame
def initialize(parent=nil,keys=nil)
super(parent,keys)
=begin
@stop = TkButton.new(self,
'text'=>'Stop',
'command'=>proc{timer_stop})
@start = TkButton.new(self,
'text'=>'Start',
'command'=>proc{timer_start})
=end
@stop = TkButton.new(self, :text=>'Stop', :state=>:disabled)
@start = TkButton.new(self, :text=>'Start', :state=>:normal)
@stop.command proc{
timer_stop
@start.state(:normal)
@stop.state(:disabled)
}
@start.command proc{
timer_start
@stop.state(:normal)
@start.state(:disabled)
}
@reset = TkButton.new(self,
'text'=>'Reset',
'command'=>proc{timer_reset})
@ -99,8 +115,8 @@ end
class Timer < TkRoot
attr_reader :countframe
def initialize
super
def initialize(*args)
super(*args)
@countframe = CountFrame.new(self)
@buttonframe = ButtonFrame.new(self)
for f in [@buttonframe,@countframe]

View file

@ -1,4 +1,4 @@
#!/usr/local/bin/ruby
#!/usr/bin/env ruby
# browse --
# This script generates a directory browser, which lists the working

View file

@ -1,4 +1,4 @@
#!/usr/local/bin/ruby
#!/usr/bin/env ruby
# browse --
# This script generates a directory browser, which lists the working

View file

@ -1,4 +1,4 @@
#!/usr/local/bin/ruby
#!/usr/bin/env ruby
require 'tk'
TkButton.new(nil,

View file

@ -1,4 +1,4 @@
#!/usr/local/bin/ruby
#!/usr/bin/env ruby
# ixset --
# A nice interface to "xset" to change X server settings

View file

@ -1,4 +1,4 @@
#!/usr/local/bin/ruby
#!/usr/bin/env ruby
# rmt --
# This script implements a simple remote-control mechanism for
@ -53,10 +53,8 @@ class Rmt
# Create text window and scrollbar.
@txt = TkText.new(root, 'relief'=>'sunken', 'bd'=>2, 'setgrid'=>true) {|t|
TkScrollbar.new(root, 'command'=>proc{|*args| t.yview *args}) {
pack('side'=>'right', 'fill'=>'both')
}
@txt = TkText.new(root, 'relief'=>'sunken', 'bd'=>2, 'setgrid'=>true) {
yscrollbar(TkScrollbar.new(root){pack('side'=>'right', 'fill'=>'y')})
pack('side'=>'left')
}
@ -247,6 +245,7 @@ class Rmt
rescue
end
TkWinfo.interps.sort.each{|ip|
begin
if Tk.appsend(ip, false, 'info commands ruby') == ""
mode = 'Tcl'
else
@ -254,6 +253,10 @@ class Rmt
end
menu.add('command', 'label'=>format("%s (#{mode}/Tk)", ip),
'command'=>proc{win.newApp ip, mode})
rescue
menu.add('command', 'label'=>format("%s (unknown Tk)", ip),
'command'=>proc{win.newApp ip, mode}, 'state'=>'disabled')
end
}
menu.add('command', 'label'=>format("local (Ruby/Tk)"),
'command'=>proc{win.newApp 'local', 'Ruby'})

View file

@ -1,10 +1,10 @@
#!/usr/local/bin/ruby
#!/usr/bin/env ruby
#
# rolodex --
# This script is a part of Tom LaStrange's rolodex
#
# Copyright (C) 1998 by Takaaki Tateishi <ttate@jaist.ac.jp>
# Time-stamp: "98/07/20 12:00:02 ttate"
# Time-stamp: "03/08/02 12:45:21 nagai"
#
require "tk"
@ -176,8 +176,8 @@ end
class Rolodex < TkRoot
attr_reader :frame, :buttons, :menu
def initialize
super
def initialize(*args)
super(*args)
@frame = RolodexFrame.new(self)
@frame.pack("side"=>"top",
"fill"=>"y",
@ -314,7 +314,7 @@ Ctrl+S: Search (dummy operation)
EOF
$helpTopics["version"] = <<EOF
This is version 1.0.
This is version 1.0.1.
EOF
Tk.mainloop

View file

@ -1,21 +1,14 @@
#!/usr/local/bin/ruby
#!/usr/bin/env ruby
#
# rolodex --
# このスクリプトは Tom LaStrange の rolodex の一部です。
#
# Copyright (C) 1998 by Takaaki Tateishi <ttate@jaist.ac.jp>
# Time-stamp: "98/07/20 12:00:36 ttate"
# Time-stamp: "03/08/02 14:01:54 nagai"
#
require "tk"
# UTF8への変換を行なう。
$encoding = "euc-jp"
def j(str)
Tk.toUTF8(str,$encoding)
end
Tk.encoding = "euc-jp"
def show_help(topic,x=0,y=0)
if( topic.is_a?(TkWindow) )
@ -33,17 +26,17 @@ def show_help(topic,x=0,y=0)
msg = "このトピックについてのヘルプはまだ使用できません"
end
TkDialog.new("title"=>"Rolodex Help",
"message"=>j("「#{topic}」\n\n#{msg}"),
"message"=>"「#{topic}」\n\n#{msg}",
"default_button"=>0,
"buttons"=>["OK"])
end
def fillCard
clearAction
$root.frame.entry[1].insert(0,j("立石 孝彰"))
$root.frame.entry[2].insert(0,j("923-1292 石川県"))
$root.frame.entry[3].insert(0,j("辰口町 旭台 1-1"))
$root.frame.entry[4].insert(0,j("北陸先端科学技術大学院大学"))
$root.frame.entry[1].insert(0, "立石 孝彰")
$root.frame.entry[2].insert(0, "923-1292 石川県")
$root.frame.entry[3].insert(0, "辰口町 旭台 1-1")
$root.frame.entry[4].insert(0, "北陸先端科学技術大学院大学")
$root.frame.entry[5].insert(0,"private")
$root.frame.entry[6].insert(0,"***-***-****")
$root.frame.entry[7].insert(0,"***-***-****")
@ -53,7 +46,7 @@ def addAction
for i in 1..7
STDERR.print format("%-12s %s\n",
RolodexFrame::LABEL[i],
Tk.fromUTF8($root.frame.entry[i].value,$encoding))
$root.frame.entry[i].value)
end
end
@ -65,7 +58,7 @@ end
def fileAction
TkDialog.new("title"=>"File Selection",
"message"=>j("これはファイル選択ダイアログのダミーです。\n"),
"message"=>"これはファイル選択ダイアログのダミーです。\n",
"default_button"=>0,
"buttons"=>["OK"])
STDERR.print "dummy file name\n"
@ -73,9 +66,9 @@ end
def deleteAction
result = TkDialog.new("title"=>"Confirm Action",
"message"=>j("よろしいですか?"),
"message"=>"よろしいですか?",
"default_button"=>0,
"buttons"=>[j("キャンセル")])
"buttons"=>["キャンセル"])
if( result.value == 0 )
clearAction
end
@ -90,7 +83,6 @@ class RolodexFrame < TkFrame
def initialize(parent=nil,keys=nil)
super(parent,keys)
self["relief"] = "flat"
@i = []
@label = []
@entry = []
@ -100,7 +92,7 @@ class RolodexFrame < TkFrame
"pady"=>2,
"anchor"=>"e")
@label[i] = TkLabel.new(@i[i],
"text"=>j(LABEL[i]),
"text"=>LABEL[i],
"anchor"=>"e")
@entry[i] = TkEntry.new(@i[i],
"width"=>30,
@ -116,14 +108,10 @@ class RolodexButtons < TkFrame
def initialize(parent,keys=nil)
super(parent,keys)
@clear = TkButton.new(self,
"text" => j("クリアー"))
@add = TkButton.new(self,
"text" => j("追加"))
@search = TkButton.new(self,
"text" => j("検索"))
@delete = TkButton.new(self,
"text" => j("消去"))
@clear = TkButton.new(self,"text" => "クリアー")
@add = TkButton.new(self, "text" => "追加")
@search = TkButton.new(self, "text" => "検索")
@delete = TkButton.new(self, "text" => "消去")
for w in [@clear,@add,@search,@delete]
w.pack("side"=>"left", "padx"=>2)
end
@ -139,42 +127,42 @@ class RolodexMenuFrame < TkFrame
"borderwidth"=>1)
@file = TkMenubutton.new(self,
"text"=>j("ファイル"),
"text"=> "ファイル",
"underline"=>0)
@file_menu = TkMenu.new(@file)
@file_menu.add("command",
"label" => j("読み込み ..."),
"label" => "読み込み ...",
"command" => proc{fileAction},
"underline" => 0)
@file_menu.add("command",
"label" => j("終了"),
"label" => "終了",
"command" => proc{$root.destroy},
"underline" => 0)
@file.menu(@file_menu)
@file.pack("side"=>"left")
@help = TkMenubutton.new(self,
"text"=>j("ヘルプ"),
"text"=> "ヘルプ",
"underline"=>0)
@help_menu = TkMenu.new(@help)
@help_menu.add("command",
"label"=>j("コンテキストについて"),
"label"=> "コンテキストについて",
"command"=>proc{show_help("コンテキスト")},
"underline"=>3)
@help_menu.add("command",
"label"=>j("ヘルプについて"),
"label"=> "ヘルプについて",
"command"=>proc{show_help("ヘルプ")},
"underline"=>3)
@help_menu.add("command",
"label"=>j("ウィンドウについて"),
"label"=> "ウィンドウについて",
"command"=>proc{show_help("ウィンドウ")},
"underline"=>3)
@help_menu.add("command",
"label"=>j("キー操作について"),
"label"=> "キー操作について",
"command"=>proc{show_help("キー操作")},
"underline"=>3)
@help_menu.add("command",
"label"=>j("バージョン情報"),
"label"=> "バージョン情報",
"command"=>proc{show_help("バージョン情報")},
"underline"=>3)
@help.menu(@help_menu)
@ -185,8 +173,8 @@ end
class Rolodex < TkRoot
attr_reader :frame, :buttons, :menu
def initialize
super
def initialize(*args)
super(*args)
@frame = RolodexFrame.new(self)
@frame.pack("side"=>"top",
"fill"=>"y",
@ -209,16 +197,16 @@ $root.buttons.add.configure("command"=>proc{addAction})
$root.buttons.clear.configure("command"=>proc{clearAction})
$root.buttons.search.configure("command"=>proc{addAction; fillCard})
$root.buttons.clear.configure("text"=>j("クリアー Ctrl+C"))
$root.buttons.clear.configure("text"=> "クリアー Ctrl+C")
$root.bind("Control-c",proc{clearAction})
$root.buttons.add.configure("text"=>j("追加 Ctrl+A"))
$root.buttons.add.configure("text"=> "追加 Ctrl+A")
$root.bind("Control-a",proc{addAction})
$root.buttons.search.configure("text"=>j("検索 Ctrl+S"))
$root.buttons.search.configure("text"=> "検索 Ctrl+S")
$root.bind("Control-s",proc{addAction; fillCard})
$root.buttons.delete.configure("text"=>j("消去 Ctrl+D"))
$root.buttons.delete.configure("text"=> "消去 Ctrl+D")
$root.bind("Control-d",proc{deleteAction})
$root.menu.file_menu.entryconfigure(1, "accel"=>"Ctrl+F")
@ -305,7 +293,7 @@ Ctrl+S:
EOF
$helpTopics["バージョン情報"] = <<EOF
バージョンは 1.0 です。
バージョンは 1.0.1j です。
EOF
Tk.mainloop

View file

@ -1,4 +1,4 @@
#!/usr/local/bin/ruby
#!/usr/bin/env ruby
# square --
# This script generates a demo application containing only
@ -15,13 +15,20 @@ require 'tkafter'
class TkSquare<TkWindow
def create_self
begin
tk_call 'square', path
rescue
STDERR.print "\nSorry. Your Tk interpreter does not contain " +
'a "square" demonstration widget.' +
"\n ( See documents included the Tcl/Tk source archive. )\n\n"
exit
end
end
def size(amount=nil)
if amount
tk_send 'size', amount
else
number(tk_send 'size')
number(tk_send('size'))
end
end
def position(x,y)

View file

@ -1,4 +1,4 @@
#!/usr/local/bin/ruby
#!/usr/bin/env ruby
#
# tcolor --
# このスクリプトはRGB,HSB,CYM形式をサポートする
@ -30,6 +30,12 @@ $label2 = TkVariable.new("label2")
$label3 = TkVariable.new("label3")
# リソースデータベースの設定
if (TkVarAccess.new('tcl_platform')['platform'] == 'unix')
TkOptionDB.add('*Entry.background', 'white')
end
# 各イベント用のメソッド
def rgbToHsv(red,green,blue)
@ -132,7 +138,7 @@ def tc_scaleChanged
scale2 = $root.middle.middle.scale2
scale3 = $root.middle.middle.scale3
case $colorSpace.to_i
case $colorSpace.value.intern
when :rgb
$red = (scale1.get * 65.535).to_i
$green = (scale2.get * 65.535).to_i
@ -167,7 +173,7 @@ def tc_setScales
scale2 = $root.middle.middle.scale2
scale3 = $root.middle.middle.scale3
case $colorSpace.to_i
case $colorSpace.value.intern
when :rgb
scale1.set($red / 65.535)
scale2.set($green / 65.535)
@ -289,7 +295,7 @@ class TkColorMenuFrame<TkFrame
"command" => proc{changeColorSpace(:hsb)}
add "separator"
add "radio",
"label" => "Qutomatic updates",
"label" => "Automatic updates",
"variable" => $autoUpdate,
"value" => "1",
"underline" => "0"
@ -367,7 +373,7 @@ class TkColorMiddleLeftFrame<TkFrame
"relief"=>"sunken",
"borderwidth"=>"2",
"exportselection"=>"false")
@scroll.command(proc{|*args| @names.yview *args})
@scroll.command(proc{|*args| @names.yview(*args)})
@names.bind("Double-1",proc{
tc_loadNamedColor(@names.get(@names.curselection))})
@names.pack("side"=>"left")
@ -490,8 +496,8 @@ end
class TkColor<TkRoot
attr_reader :menu, :bottom, :middle
def initialize
super
def initialize(*args)
super(*args)
@menu = TkColorMenuFrame.new(self)
@menu.pack("side"=>"top", "fill"=>"x")

View file

@ -1,4 +1,4 @@
#!/usr/local/bin/ruby
#!/usr/bin/env ruby
#
# timer --
# This script generates a counter with start,stop and reset buttons.
@ -80,12 +80,28 @@ end
class ButtonFrame < TkFrame
def initialize(parent=nil,keys=nil)
super(parent,keys)
=begin
@stop = TkButton.new(self,
'text'=>'Stop',
'command'=>proc{timer_stop})
@start = TkButton.new(self,
'text'=>'Start',
'command'=>proc{timer_start})
=end
@stop = TkButton.new(self, :text=>'Stop', :state=>:disabled)
@start = TkButton.new(self, :text=>'Start', :state=>:normal)
@stop.command proc{
timer_stop
@start.state(:normal)
@stop.state(:disabled)
}
@start.command proc{
timer_start
@stop.state(:normal)
@start.state(:disabled)
}
@reset = TkButton.new(self,
'text'=>'Reset',
'command'=>proc{timer_reset})
@ -99,8 +115,8 @@ end
class Timer < TkRoot
attr_reader :countframe
def initialize
super
def initialize(*args)
super(*args)
@countframe = CountFrame.new(self)
@buttonframe = ButtonFrame.new(self)
for f in [@buttonframe,@countframe]

View file

@ -1,4 +1,4 @@
#!/usr/local/bin/ruby
#!/usr/bin/env ruby
# tk 関係ライブラリの読み込み
require 'tk'

View file

@ -32,6 +32,7 @@ cmd = Proc.new{|txt|
timer = TkTimer.new(50, -1, tick).start(0, proc{ label.text('0.00'); 0 })
=begin
TkButton.new(:text=>'Start') {
command proc{ timer.continue unless timer.running? }
pack(:side=>:left, :fill=>:both, :expand=>true)
@ -44,6 +45,30 @@ cmd = Proc.new{|txt|
command proc{ timer.stop if timer.running? }
pack('side'=>'right','fill'=>'both','expand'=>'yes')
}
=end
b_start = TkButton.new(:text=>'Start', :state=>:disabled) {
pack(:side=>:left, :fill=>:both, :expand=>true)
}
b_stop = TkButton.new(:text=>'Stop', :state=>:normal) {
pack('side'=>'left', 'fill'=>'both', 'expand'=>'yes')
}
b_start.command {
timer.continue
b_stop.state(:normal)
b_start.state(:disabled)
}
b_stop.command {
timer.stop
b_start.state(:normal)
b_stop.state(:disabled)
}
TkButton.new(:text=>'Reset', :state=>:normal) {
command { timer.reset }
pack('side'=>'right', 'fill'=>'both', 'expand'=>'yes')
}
ev_quit = TkVirtualEvent.new('Control-c', 'Control-q')
Tk.root.bind(ev_quit, proc{Tk.exit}).focus

View file

@ -1,4 +1,4 @@
#! /usr/local/bin/ruby
#!/usr/bin/env ruby
if ARGV[0] != '-d'
unless $DEBUG

View file

@ -1,4 +1,4 @@
#!/usr/local/bin/ruby
#!/usr/bin/env ruby
#
# This script generates a directory browser, which lists the working
# directory and allows you to open files or subdirectories by

View file

@ -1,4 +1,4 @@
#! /usr/local/bin/ruby
#!/usr/bin/env ruby
require "tk"
root = TkFrame.new

View file

@ -1,4 +1,4 @@
#! /usr/local/bin/ruby
#!/usr/bin/env ruby
require "parsedate"
require "base64"

View file

@ -1,4 +1,4 @@
#!/usr/local/bin/ruby
#!/usr/bin/env ruby
# This script generates a counter with start and stop buttons.
require "tk"

59
ext/tk/sample/tktimer3.rb Normal file
View file

@ -0,0 +1,59 @@
#!/usr/bin/env ruby
# This script is a re-implementation of tktimer.rb with TkTimer(TkAfter) class.
require "tk"
# new notation :
# * symbols are acceptable as keys or values of the option hash
# * the parent widget can be given by :parent key on the option hash
root = TkRoot.new(:title=>'timer sample')
label = TkLabel.new(:parent=>root, :relief=>:raised, :width=>10) \
.pack(:side=>:bottom, :fill=>:both)
# define the procedure repeated by the TkTimer object
tick = proc{|aobj| #<== TkTimer object
cnt = aobj.return_value + 5 # return_value keeps a result of the last proc
label.text format("%d.%02d", *(cnt.divmod(100)))
cnt #==> return value is kept by TkTimer object
# (so, can be send to the next repeat-proc)
}
timer = TkTimer.new(50, -1, tick).start(0, proc{ label.text('0.00'); 0 })
# ==> repeat-interval : (about) 50 ms,
# repeat : infinite (-1) times,
# repeat-procedure : tick (only one, in this case)
#
# ==> wait-before-call-init-proc : 0 ms,
# init_proc : proc{ label.text('0.00'); 0 }
#
# (0ms)-> init_proc ->(50ms)-> tick ->(50ms)-> tick ->....
b_start = TkButton.new(:text=>'Start', :state=>:disabled) {
pack(:side=>:left, :fill=>:both, :expand=>true)
}
b_stop = TkButton.new(:text=>'Stop', :state=>:normal) {
pack('side'=>'left', 'fill'=>'both', 'expand'=>'yes')
}
b_start.command {
timer.continue
b_stop.state(:normal)
b_start.state(:disabled)
}
b_stop.command {
timer.stop
b_start.state(:normal)
b_stop.state(:disabled)
}
TkButton.new(:text=>'Reset', :state=>:normal) {
command { timer.reset }
pack(:side=>:right, :fill=>:both, :expand=>:yes)
}
ev_quit = TkVirtualEvent.new('Control-c', 'Control-q')
Tk.root.bind(ev_quit, proc{Tk.exit}).focus
Tk.mainloop