Skip to content

Commit

Permalink
* (bug fix) TkEntry#delete
Browse files Browse the repository at this point in the history
* (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
  • Loading branch information
nagai committed Aug 2, 2003
1 parent d7bdf5d commit 4c3328f
Show file tree
Hide file tree
Showing 33 changed files with 297 additions and 134 deletions.
1 change: 1 addition & 0 deletions ext/tk/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions ext/tk/lib/multi-tk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def initialize(ret=nil)
################################################
# methods for construction
class MultiTkIp
SLAVE_IP_ID = ['slave'.freeze, '0']
SLAVE_IP_ID = ['slave'.freeze, '0'].freeze

@@IP_TABLE = {}

Expand Down Expand Up @@ -234,7 +234,12 @@ class << subclass

######################################

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
Expand Down
18 changes: 12 additions & 6 deletions ext/tk/lib/tk.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#
# tk.rb - Tk interface module using tcltklib
# $Date$
# by Yukihiro Matsumoto <matz@netlab.jp>
Expand All @@ -17,7 +17,7 @@ def None.to_s

#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
Expand Down Expand Up @@ -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 }

Expand Down Expand Up @@ -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]")
Expand Down Expand Up @@ -1839,6 +1839,10 @@ def to_s
string(value).to_s
end

def to_sym
value.intern
end

def inspect
format "#<TkVariable: %s>", @id
end
Expand All @@ -1849,6 +1853,8 @@ def ==(other)
self.equal?(other)
when String
self.to_s == other
when Symbol
self.to_sym == other
when Integer
self.to_i == other
when Float
Expand Down Expand Up @@ -4630,7 +4636,7 @@ def see(index)
module TkTreatListItemFont
include TkTreatItemFont

ItemCMD = ['itemconfigure', TkComm::None]
ItemCMD = ['itemconfigure'.freeze, TkComm::None].freeze
def __conf_cmd(idx)
ItemCMD[idx]
end
Expand Down Expand Up @@ -4770,7 +4776,7 @@ def itemconfiginfo(index, key=nil)
module TkTreatMenuEntryFont
include TkTreatItemFont

ItemCMD = ['entryconfigure', TkComm::None]
ItemCMD = ['entryconfigure'.freeze, TkComm::None].freeze
def __conf_cmd(idx)
ItemCMD[idx]
end
Expand Down
18 changes: 17 additions & 1 deletion ext/tk/lib/tkafter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -311,6 +311,22 @@ def start(*init_args)
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 == []
Expand Down
8 changes: 4 additions & 4 deletions ext/tk/lib/tkcanvas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
module TkTreatCItemFont
include TkTreatItemFont

ItemCMD = ['itemconfigure', TkComm::None]
ItemCMD = ['itemconfigure'.freeze, TkComm::None].freeze
def __conf_cmd(idx)
ItemCMD[idx]
end
Expand Down Expand Up @@ -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 }

Expand Down Expand Up @@ -660,7 +660,7 @@ def initialize(parent)
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)
Expand Down Expand Up @@ -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 }

Expand Down
2 changes: 1 addition & 1 deletion ext/tk/lib/tkentry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def insert(pos,text)
self
end
def delete(first, last=None)
tk_send 'insert', first, last
tk_send 'delete', first, last
self
end
def mark(pos)
Expand Down
2 changes: 1 addition & 1 deletion ext/tk/lib/tkfont.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions ext/tk/lib/tktext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
module TkTreatTextTagFont
include TkTreatItemFont

ItemCMD = ['tag', 'configure']
ItemCMD = ['tag'.freeze, 'configure'.freeze].freeze
def __conf_cmd(idx)
ItemCMD[idx]
end
Expand All @@ -24,7 +24,7 @@ def __item_pathname(tagOrId)
end

class TkText<TkTextWin
ItemConfCMD = ['tag', 'configure']
ItemConfCMD = ['tag'.freeze, 'configure'.freeze].freeze
include TkTreatTextTagFont
include Scrollable

Expand Down Expand Up @@ -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 }

Expand Down Expand Up @@ -971,7 +971,7 @@ def self.new(parent, *args)

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 }

Expand Down
2 changes: 1 addition & 1 deletion ext/tk/lib/tkvirtevent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
23 changes: 13 additions & 10 deletions ext/tk/sample/demos-en/rmt
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}

Expand Down Expand Up @@ -247,13 +245,18 @@ class Rmt
rescue
end
TkWinfo.interps.sort.each{|ip|
if Tk.appsend(ip, false, 'info commands ruby') == ""
mode = 'Tcl'
else
mode = 'Ruby'
begin
if Tk.appsend(ip, false, 'info commands ruby') == ""
mode = 'Tcl'
else
mode = 'Ruby'
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("%s (#{mode}/Tk)", ip),
'command'=>proc{win.newApp ip, mode})
}
menu.add('command', 'label'=>format("local (Ruby/Tk)"),
'command'=>proc{win.newApp 'local', 'Ruby'})
Expand Down
8 changes: 4 additions & 4 deletions ext/tk/sample/demos-en/rolodex
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
9 changes: 4 additions & 5 deletions ext/tk/sample/demos-en/rolodex-j
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -318,7 +317,7 @@ Ctrl+S:
EOF

$helpTopics["バージョン情報"] = <<EOF
バージョンは 1.0 です。
バージョンは 1.0.1e です。
EOF

Tk.mainloop
11 changes: 9 additions & 2 deletions ext/tk/sample/demos-en/square
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@ require 'tkafter'

class TkSquare<TkWindow
def create_self
tk_call 'square', path
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)
Expand Down
Loading

0 comments on commit 4c3328f

Please sign in to comment.