* ext/tk/tcltklib.c: add TclTkIp#_create_console() method to create

a Tcl/Tk's console window.
* ext/tk/lib/multi-tk.rb: support TclTkIp#_create_console() method.
* ext/tk/lib/remote-tk.rb: ditto.
* ext/tk/lib/tk/console.rb: ditto.
* ext/tk/lib/tk.rb: update RELEASE_DATE
* ext/tk/sample/demo-*/check2.rb: use 'return' in the Proc object.
* ext/tk/sample/tkextlib/**: ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8212 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagai 2005-03-30 08:44:19 +00:00
parent a07bc1123a
commit 11974f26b3
17 changed files with 612 additions and 442 deletions

View File

@ -1,3 +1,20 @@
Wed Mar 30 17:41:48 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/tcltklib.c: add TclTkIp#_create_console() method to create
a Tcl/Tk's console window.
* ext/tk/lib/multi-tk.rb: support TclTkIp#_create_console() method.
* ext/tk/lib/remote-tk.rb: ditto.
* ext/tk/lib/tk/console.rb: ditto.
* ext/tk/lib/tk.rb: update RELEASE_DATE
* ext/tk/sample/demo-*/check2.rb: use 'return' in the Proc object.
* ext/tk/sample/tkextlib/**: ditto.
Tue Mar 29 22:20:49 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp> Tue Mar 29 22:20:49 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* test/rinda/test_rinda.rb: use DRbObject.new_with instead of reinit. * test/rinda/test_rinda.rb: use DRbObject.new_with instead of reinit.

View File

@ -1,3 +1,21 @@
2005-03-30 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* sample/tkextlib/bwidget/tree.rb: use 'return' in the Proc object.
* sample/tkextlib/tkHTML/hv.rb: ditto.
* sample/tkextlib/tkHTML/ss.rb: ditto.
* sample/tkextlib/tktable/basic.rb: ditto.
* sample/tkextlib/tktable/command.rb: ditto.
* sample/tkextlib/tktable/debug.rb: ditto.
* sample/tkextlib/tktable/maxsize.rb: ditto.
* sample/tkextlib/treectrl/demo.rb: ditto.
2005-03-29 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> 2005-03-29 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* lib/tkextlib/blt/component.rb: cannot create elements except * lib/tkextlib/blt/component.rb: cannot create elements except

View File

@ -1787,6 +1787,10 @@ class << MultiTkIp
def _conv_listelement(arg) def _conv_listelement(arg)
__getip._conv_listelement(arg) __getip._conv_listelement(arg)
end end
def _create_console
__getip._create_console
end
end end

View File

@ -400,6 +400,10 @@ class RemoteTkIp
@interp._conv_listelement(str) @interp._conv_listelement(str)
end end
def _create_console
fail RuntimeError, 'not support "_create_console" on the remote interpreter'
end
def mainloop def mainloop
fail RuntimeError, 'not support "mainloop" on the remote interpreter' fail RuntimeError, 'not support "mainloop" on the remote interpreter'
end end

View File

@ -4024,7 +4024,7 @@ end
#Tk.freeze #Tk.freeze
module Tk module Tk
RELEASE_DATE = '2005-03-26'.freeze RELEASE_DATE = '2005-03-30'.freeze
autoload :AUTO_PATH, 'tk/variable' autoload :AUTO_PATH, 'tk/variable'
autoload :TCL_PACKAGE_PATH, 'tk/variable' autoload :TCL_PACKAGE_PATH, 'tk/variable'

View File

@ -9,6 +9,9 @@ module TkConsole
TkCommandNames = ['console'.freeze].freeze TkCommandNames = ['console'.freeze].freeze
def self.create
TkCore::INTERP._create_console
end
def self.title(str=None) def self.title(str=None)
tk_call 'console', str tk_call 'console', str
end end

View File

@ -76,8 +76,7 @@ TkCheckButton.new($check2_demo, :text=>'Safety Check', :variable=>safety,
# tristate check # tristate check
in_check = false in_check = false
tristate_check = proc{|n1,n2,op| tristate_check = proc{|n1,n2,op|
return if in_check unless in_check
in_check = true in_check = true
begin begin
if n1 == safety if n1 == safety
@ -102,6 +101,7 @@ tristate_check = proc{|n1,n2,op|
ensure ensure
in_check = false in_check = false
end end
end
} }
[wipers, brakes, sober, safety].each{|v| v.trace('w', tristate_check)} [wipers, brakes, sober, safety].each{|v| v.trace('w', tristate_check)}

View File

@ -76,8 +76,7 @@ TkCheckButton.new($check2_demo, :text=>'
# tristate check # tristate check
in_check = false in_check = false
tristate_check = proc{|n1,n2,op| tristate_check = proc{|n1,n2,op|
return if in_check unless in_check
in_check = true in_check = true
begin begin
if n1 == safety if n1 == safety
@ -102,6 +101,7 @@ tristate_check = proc{|n1,n2,op|
ensure ensure
in_check = false in_check = false
end end
end
} }
[wipers, brakes, sober, safety].each{|v| v.trace('w', tristate_check)} [wipers, brakes, sober, safety].each{|v| v.trace('w', tristate_check)}

View File

@ -119,7 +119,7 @@ module DemoTree
Tk.root.bind_remove('Unmap') Tk.root.bind_remove('Unmap')
Tk.root.bind_remove('Map') Tk.root.bind_remove('Map')
Tk.root.bind_remove('Configure') Tk.root.bind_remove('Configure')
return true true
}) })
end end

View File

@ -78,28 +78,31 @@ big_imgs = {}
hotkey = {} hotkey = {}
move_big_image = proc{|b| move_big_image = proc{|b|
return unless big_imgs.key?(b) if big_imgs.key?(b)
b.copy(big_imgs[b]) b.copy(big_imgs[b])
big_imgs[b].delete big_imgs[b].delete
big_imgs.delete(b) big_imgs.delete(b)
Tk.update Tk.update
end
} }
image_cmd = proc{|*args| image_cmd = proc{|*args|
return smgray unless show_img.bool if show_img.bool
smgray
else
fn = args[0] fn = args[0]
if old_imgs.key?(fn) if old_imgs.key?(fn)
images[fn] = old_imgs[fn] images[fn] = old_imgs[fn]
old_imgs.delete(fn) old_imgs.delete(fn)
return images[fn] images[fn]
end
else
begin begin
img = TkPhotoImage.new(:file=>fn) img = TkPhotoImage.new(:file=>fn)
rescue rescue
return smgray smgray
end else
if img.width * img.height > 20000 if img.width * img.height > 20000
b = TkPhotoImage.new(:width=>img.width, :height=>img.height) b = TkPhotoImage.new(:width=>img.width, :height=>img.height)
big_imgs[b] = img big_imgs[b] = img
@ -108,8 +111,10 @@ image_cmd = proc{|*args|
end end
images[fn] = img images[fn] = img
img img
end
end
end
} }
# #
@ -183,12 +188,13 @@ clear_screen = proc{
# Load a file into the HTML widget # Load a file into the HTML widget
# #
load_file = proc{|name| load_file = proc{|name|
return unless (doc = read_file.call(name)) if (doc = read_file.call(name))
clear_screen.call clear_screen.call
last_file = name last_file = name
html.configure(:base=>name) html.configure(:base=>name)
html.parse(doc) html.parse(doc)
old_imgs.clear old_imgs.clear
end
} }
href_binding = proc{|x, y| href_binding = proc{|x, y|
@ -196,8 +202,8 @@ href_binding = proc{|x, y|
html.selection_clear html.selection_clear
priv['mark'] = "@#{x},#{y}" priv['mark'] = "@#{x},#{y}"
lst = html.href(x, y) lst = html.href(x, y)
return if lst.size.zero?
unless lst.size.zero?
lnk, target = lst lnk, target = lst
if lnk != "" if lnk != ""
@ -207,6 +213,7 @@ href_binding = proc{|x, y|
load_file.call(lnk) load_file.call(lnk)
end end
end end
end
} }
html.clipping_window.bind('1', href_binding, '%x %y') html.clipping_window.bind('1', href_binding, '%x %y')

View File

@ -6,111 +6,196 @@
require 'tk' require 'tk'
require 'tkextlib/tkHTML' require 'tkextlib/tkHTML'
root = TkRoot.new(:title=>'HTML File Viewer', :iconname=>'HV')
fswin = nil
html = nil
html_fs = nil
hotkey = {}
file = ARGV[0] file = ARGV[0]
class TkHTML_File_Viewer
include TkComm
# These are images to use with the actual image specified in a # These are images to use with the actual image specified in a
# "<img>" markup can't be found. # "<img>" markup can't be found.
# #
biggray = TkPhotoImage.new(:data=><<'EOD') @@biggray = TkPhotoImage.new(:data=><<'EOD')
R0lGODdhPAA+APAAALi4uAAAACwAAAAAPAA+AAACQISPqcvtD6OctNqLs968+w+G4kiW5omm R0lGODdhPAA+APAAALi4uAAAACwAAAAAPAA+AAACQISPqcvtD6OctNqLs968+w+G4kiW5omm
6sq27gvH8kzX9o3n+s73/g8MCofEovGITCqXzKbzCY1Kp9Sq9YrNFgsAO/// 6sq27gvH8kzX9o3n+s73/g8MCofEovGITCqXzKbzCY1Kp9Sq9YrNFgsAO///
EOD EOD
smgray = TkPhotoImage.new(:data=><<'EOD') @@smgray = TkPhotoImage.new(:data=><<'EOD')
R0lGODdhOAAYAPAAALi4uAAAACwAAAAAOAAYAAACI4SPqcvtD6OctNqLs968+w+G4kiW5omm R0lGODdhOAAYAPAAALi4uAAAACwAAAAAOAAYAAACI4SPqcvtD6OctNqLs968+w+G4kiW5omm
6sq27gvH8kzX9m0VADv/ 6sq27gvH8kzX9m0VADv/
EOD EOD
def initialize(file = nil)
@root = TkRoot.new(:title=>'HTML File Viewer', :iconname=>'HV')
@fswin = nil
@html = nil
@html_fs = nil
@hotkey = {}
@applet_arg = TkVarAccess.new_hash('AppletArg')
@images = {}
@old_imgs = {}
@big_imgs = {}
@last_dir = Dir.pwd
@last_file = ''
@key_block = false
Tk::HTML_Widget::ClippingWindow.bind('1',
proc{|w, ksym| key_press(w, ksym)},
'%W Down')
Tk::HTML_Widget::ClippingWindow.bind('3',
proc{|w, ksym| key_press(w, ksym)},
'%W Up')
Tk::HTML_Widget::ClippingWindow.bind('2',
proc{|w, ksym| key_press(w, ksym)},
'%W Down')
Tk::HTML_Widget::ClippingWindow.bind('KeyPress',
proc{|w, ksym| key_press(w, ksym)},
'%W %K')
############################################
#
# Build the half-size view of the page
#
menu_spec = [
[['File', 0],
['Open', proc{sel_load()}, 0],
['Full Screen', proc{fullscreen()}, 0],
['Refresh', proc{refresh()}, 0],
'---',
['Exit', proc{exit}, 1]]
]
mbar = @root.add_menubar(menu_spec)
@html = Tk::HTML_Widget.new(:width=>512, :height=>384,
:padx=>5, :pady=>9,
:formcommand=>proc{|*args| form_cmd(*args)},
:imagecommand=>proc{|*args|
image_cmd(1, *args)
},
:scriptcommand=>proc{|*args|
script_cmd(*args)
},
:appletcommand=>proc{|*args|
applet_cmd(*args)
},
:hyperlinkcommand=>proc{|*args|
hyper_cmd(*args)
},
:fontcommand=>proc{|*args|
pick_font(*args)
},
:appletcommand=>proc{|*args|
run_applet('small', *args)
},
:bg=>'white', :tablerelief=>:raised)
@html.token_handler('meta', proc{|*args| meta(@html, *args)})
vscr = @html.yscrollbar(TkScrollbar.new)
hscr = @html.xscrollbar(TkScrollbar.new)
Tk.grid(@html, vscr, :sticky=>:news)
Tk.grid(hscr, :sticky=>:ew)
@root.grid_columnconfigure(0, :weight=>1)
@root.grid_columnconfigure(1, :weight=>0)
@root.grid_rowconfigure(0, :weight=>1)
@root.grid_rowconfigure(1, :weight=>0)
############################################
@html.clipwin.focus
# If an arguent was specified, read it into the HTML widget.
#
Tk.update
if file && file != ""
load_file(file)
end
end
# #
# A font chooser routine. # A font chooser routine.
# #
# html[:fontcommand] = pick_font # html[:fontcommand] = pick_font
pick_font = proc{|size, attrs| def pick_font(size, attrs)
# puts "FontCmd: #{size} #{attrs}" # puts "FontCmd: #{size} #{attrs}"
[ ((attrs =~ /fixed/)? 'courier': 'charter'), [ ((attrs =~ /fixed/)? 'courier': 'charter'),
(12 * (1.2**(size.to_f - 4.0))).to_i, (12 * (1.2**(size.to_f - 4.0))).to_i,
((attrs =~ /italic/)? 'italic': 'roman'), ((attrs =~ /italic/)? 'italic': 'roman'),
((attrs =~ /bold/)? 'bold': 'normal') ].join(' ') ((attrs =~ /bold/)? 'bold': 'normal') ].join(' ')
} end
# This routine is called to pick fonts for the fullscreen view. # This routine is called to pick fonts for the fullscreen view.
# #
def pick_font_fs(size, attrs)
baseFontSize = 24 baseFontSize = 24
pick_font_fs = proc{|size, attrs|
# puts "FontCmd: #{size} #{attrs}" # puts "FontCmd: #{size} #{attrs}"
[ ((attrs =~ /fixed/)? 'courier': 'charter'), [ ((attrs =~ /fixed/)? 'courier': 'charter'),
(baseFontSize * (1.2**(size.to_f - 4.0))).to_i, (baseFontSize * (1.2**(size.to_f - 4.0))).to_i,
((attrs =~ /italic/)? 'italic': 'roman'), ((attrs =~ /italic/)? 'italic': 'roman'),
((attrs =~ /bold/)? 'bold': 'normal') ].join(' ') ((attrs =~ /bold/)? 'bold': 'normal') ].join(' ')
} end
# #
# #
hyper_cmd = proc{|*args| def hyper_cmd(*args)
puts "HyperlinkCommand: #{args.inspect}" puts "HyperlinkCommand: #{args.inspect}"
} end
# This routine is called to run an applet # This routine is called to run an applet
# #
applet_arg = TkVarAccess.new_hash('AppletArg') def run_applet(size, w, arglist)
run_applet = proc{|size, w, arglist|
applet_arg.value = Hash[*simplelist(arglist)] applet_arg.value = Hash[*simplelist(arglist)]
return unless applet_arg.key?('src') return unless @applet_arg.key?('src')
src = html.remove(applet_arg['src']) src = @html.remove(@applet_arg['src'])
applet_arg['window'] = w @applet_arg['window'] = w
applet_arg['fontsize'] = size @applet_arg['fontsize'] = size
begin begin
Tk.load_tclscript(src) Tk.load_tclscript(src)
rescue => e rescue => e
puts "Applet error: #{e.message}" puts "Applet error: #{e.message}"
end end
} end
# #
# #
form_cmd = proc{|n, cmd, *args| def form_cmd(n, cmd, *args)
} # p [n, cmd, *args]
end
# #
# #
images = {} def move_big_image(b)
old_imgs = {} return unless @big_imgs.key?(b)
big_imgs = {} b.copy(@big_imgs[b])
@big_imgs[b].delete
@big_imgs.delete(b)
end
# def image_cmd(hs, *args)
#
move_big_image = proc{|b|
return unless big_imgs.key?(b)
b.copy(big_imgs[b])
big_imgs[b].delete
big_imgs.delete(b)
}
image_cmd = proc{|hs, *args|
fn = args[0] fn = args[0]
if old_imgs.key?(fn) if @old_imgs.key?(fn)
return (images[fn] = old_imgs.delete(fn)) return (@images[fn] = @old_imgs.delete(fn))
end end
begin begin
img = TkPhotoImage.new(:file=>fn) img = TkPhotoImage.new(:file=>fn)
rescue rescue
return ((hs)? smallgray: biggray) return ((hs)? @@smallgray: @@biggray)
end end
if hs if hs
@ -122,77 +207,73 @@ image_cmd = proc{|hs, *args|
if img.width * img.height > 20000 if img.width * img.height > 20000
b = TkPhotoImage.new(:width=>img.width, :height=>img.height) b = TkPhotoImage.new(:width=>img.width, :height=>img.height)
big_imgs[b] = img @big_imgs[b] = img
img = b img = b
Tk.after_idle(proc{ move_big_image.call(b) }) Tk.after_idle(proc{ move_big_image(b) })
end end
images[fn] = img @images[fn] = img
img img
} end
# #
# This routine is called for every <SCRIPT> markup # This routine is called for every <SCRIPT> markup
# #
script_cmd = proc{|*args| def script_cmd(*args)
# puts "ScriptCmd: #{args.inspect}" # puts "ScriptCmd: #{args.inspect}"
} end
# This routine is called for every <APPLET> markup # This routine is called for every <APPLET> markup
# #
applet_cmd = proc{|w, arglist| def applet_cmd(w, arglist)
# puts "AppletCmd: w=#{w} arglist=#{arglist}" # puts "AppletCmd: w=#{w} arglist=#{arglist}"
#TkLabel.new(w, :text=>"The Applet #{w}", :bd=>2, :relief=>raised) #TkLabel.new(w, :text=>"The Applet #{w}", :bd=>2, :relief=>raised)
} end
# This binding fires when there is a click on a hyperlink # This binding fires when there is a click on a hyperlink
# #
href_binding = proc{|w, x, y| def href_binding(w, x, y)
lst = w.href(x, y) lst = w.href(x, y)
unless lst.empty? unless lst.empty?
process_url.call(lst) process_url(lst)
end
end end
}
# #
# #
last_dir = Dir.pwd def sel_load
load_file = nil
sel_load = proc{
filetypes = [ filetypes = [
['Html Files', ['.html', '.htm']], ['Html Files', ['.html', '.htm']],
['All Files', '*'] ['All Files', '*']
] ]
f = Tk.getOpenFile(:initialdir=>last_dir, :filetypes=>filetypes) f = Tk.getOpenFile(:initialdir=>@last_dir, :filetypes=>filetypes)
if f != '' if f != ''
load_file.call(f) load_file(f)
last_dir = File.dirname(f) @last_dir = File.dirname(f)
end
end end
}
# Clear the screen. # Clear the screen.
# #
clear_screen = proc{ def clear_screen
if html_fs && html_fs.exist? if @html_fs && @html_fs.exist?
w = html_fs w = @html_fs
else else
w = html w = @html
end end
w.clear w.clear
old_imgs.clear @old_imgs.clear
big_imgs.clear @big_imgs.clear
hotkey.clear @hotkey.clear
images.each{|k, v| old_imgs[k] = v } @images.each{|k, v| @old_imgs[k] = v }
images.clear @images.clear
} end
# Read a file # Read a file
# #
read_file = proc{|name| def read_file(name)
begin begin
fp = open(name, 'r') fp = open(name, 'r')
ret = fp.read(File.size(name)) ret = fp.read(File.size(name))
@ -205,202 +286,151 @@ read_file = proc{|name|
fp.close if fp fp.close if fp
end end
ret ret
} end
# Process the given URL # Process the given URL
# #
process_url = proc{|url| def process_url(url)
case url[0] case url[0]
when /^file:/ when /^file:/
load_file.call(url[0][5..-1]) load_file(url[0][5..-1])
when /^exec:/ when /^exec:/
Tk.ip_eval(url[0][5..-1].tr('\\', ' ')) Tk.ip_eval(url[0][5..-1].tr('\\', ' '))
else else
load_file.call(url[0]) load_file(url[0])
end
end end
}
# Load a file into the HTML widget # Load a file into the HTML widget
# #
last_file = '' def load_file(name)
return unless (doc = read_file(name))
load_file = proc{|name| clear_screen()
return unless (doc = read_file.call(name)) @last_file = name
clear_screen.call if @html_fs && @html_fs.exist?
last_file = name w = @html_fs
if html_fs && html_fs.exist?
w = html_fs
else else
w = html w = @html
end end
w.configure(:base=>name) w.configure(:base=>name)
w.parse(doc) w.parse(doc)
w.configure(:cursor=>'top_left_arrow') w.configure(:cursor=>'top_left_arrow')
old_imgs.clear @old_imgs.clear
} end
# Refresh the current file. # Refresh the current file.
# #
refresh = proc{|*args| def refresh(*args)
load_file.call(last_file) if last_file load_file(@last_file) if @last_file
} end
# This routine is called whenever a "<meta>" markup is seen. # This routine is called whenever a "<meta>" markup is seen.
# #
meta = proc{|w, tag, alist| def meta(w, tag, alist)
v = Hash[*simplelist(alist)] v = Hash[*simplelist(alist)]
if v.kye?('key') && v.key?('href') if v.key?('key') && v.key?('href')
hotkey[v['key']] = w.resolve(v['href']) @hotkey[v['key']] = w.resolve(v['href'])
end end
if v.kye?('next') if v.key?('next')
hotkey['Down'] =v['next'] @hotkey['Down'] =v['next']
end end
if v.kye?('prev') if v.key?('prev')
hotkey['Up'] =v['prev'] @hotkey['Up'] =v['prev']
end end
if v.kye?('other') if v.key?('other')
hotkey['o'] =v['other'] @hotkey['o'] =v['other']
end
end end
}
# Go from full-screen mode back to window mode. # Go from full-screen mode back to window mode.
# #
fullscreen_off = proc{ def fullscreen_off
fswin.destroy @fswin.destroy
root.deiconify @root.deiconify
Tk.update Tk.update
root.raise @root.raise
html.clipwin.focus @html.clipwin.focus
clear_screen.call clear_screen()
old_imgs.clear @old_imgs.clear
refresh.call refresh()
} end
# Go from window mode to full-screen mode. # Go from window mode to full-screen mode.
# #
fullscreen = proc{ def fullscreen
if fswin && fswin.exist? if @fswin && @fswin.exist?
fswin.deiconify @fswin.deiconify
Tk.update Tk.update
fswin.raise @fswin.raise
return return
end end
width = root.winfo_screenwidth width = @root.winfo_screenwidth
height = root.winfo_screenheight height = @root.winfo_screenheight
fswin = TkToplevel.new(:overrideredirect=>true, @fswin = TkToplevel.new(:overrideredirect=>true,
:geometry=>"#{width}x#{height}+0+0") :geometry=>"#{width}x#{height}+0+0")
html_fs = Tk::HTML_Widget.new(fswin, :padx=>5, :pady=>9, @html_fs = Tk::HTML_Widget.new(@fswin, :padx=>5, :pady=>9,
:formcommand=>form_cmd, :formcommand=>proc{|*args|
:imagecommand=>proc{image_cmd.call(0)}, form_cmd(*args)
:scriptcommand=>script_cmd, },
:appletcommand=>applet_cmd, :imagecommand=>proc{|*args|
:hyperlinkcommand=>hyper_cmd, image_cmd(0, *args)
:bg=>'white', :tablerelief=>:raised, },
:scriptcommand=>proc{|*args|
script_cmd(*args)
},
:appletcommand=>proc{|*args|
applet_cmd(*args)
},
:hyperlinkcommand=>proc{|*args|
hyper_cmd(*args)
},
:appletcommand=>proc{|*args| :appletcommand=>proc{|*args|
run_applet('big', *args) run_applet('big', *args)
}, },
:fontcommand=>pick_font_fs, :fontcommand=>proc{|*args|
pick_font_fs(*args)
},
:bg=>'white', :tablerelief=>:raised,
:cursor=>:tcross) { :cursor=>:tcross) {
pack(:fill=>:both, :expand=>true) pack(:fill=>:both, :expand=>true)
token_handler('meta', proc{|*args| meta.call(self, *args)}) token_handler('meta', proc{|*args| meta(self, *args)})
} }
clear_screen.call clear_screen()
old_imgs.clear @old_imgs.clear
refresh.call refresh()
Tk.update Tk.update
html_fs.clipwin.focus @html_fs.clipwin.focus
} end
# #
# #
key_block = false def key_press(w, keysym)
return if @key_block
@key_block = true
Tk.after(250, proc{@key_block = false})
key_press = proc{|w, keysym| if @hotkey.key?(keysym)
return if key_block process_url(@hotkey[keysym])
key_block = true
Tk.after(250, proc{key_block = false})
if hotkey.key?(keysym)
process_url.call(hotkey[keysym])
end end
case keysym case keysym
when 'Escape' when 'Escape'
if fswin && fswin.exist? if @fswin && @fswin.exist?
fullscreen_off.call fullscreen_off()
else else
fullscreen.call fullscreen()
end
end end
end end
}
Tk::HTML_Widget::ClippingWindow.bind('1', key_press, '%W Down')
Tk::HTML_Widget::ClippingWindow.bind('3', key_press, '%W Up')
Tk::HTML_Widget::ClippingWindow.bind('2', key_press, '%w Down')
Tk::HTML_Widget::ClippingWindow.bind('KeyPress', key_press, '%W %K')
############################################
#
# Build the half-size view of the page
#
menu_spec = [
[['File', 0],
['Open', sel_load, 0],
['Full Screen', fullscreen, 0],
['Refresh', refresh, 0],
'---',
['Exit', proc{exit}, 1]]
]
mbar = root.add_menubar(menu_spec)
html = Tk::HTML_Widget.new(:width=>512, :height=>384,
:padx=>5, :pady=>9,
:formcommand=>form_cmd,
:imagecommand=>proc{|*args|
image_cmd.call(1, *args)
},
:scriptcommand=>script_cmd,
:appletcommand=>applet_cmd,
:hyperlinkcommand=>hyper_cmd,
:fontcommand=>pick_font,
:appletcommand=>proc{|*args|
run_applet.call('small', *args)
},
:bg=>'white', :tablerelief=>:raised)
html.token_handler('meta', proc{|*args| meta.call(html, *args)})
vscr = html.yscrollbar(TkScrollbar.new)
hscr = html.xscrollbar(TkScrollbar.new)
Tk.grid(html, vscr, :sticky=>:news)
Tk.grid(hscr, :sticky=>:ew)
Tk.root.grid_columnconfigure(0, :weight=>1)
Tk.root.grid_columnconfigure(1, :weight=>0)
Tk.root.grid_rowconfigure(0, :weight=>1)
Tk.root.grid_rowconfigure(1, :weight=>0)
############################################
html.clipwin.focus
# If an arguent was specified, read it into the HTML widget.
#
Tk.update
if file && file != ""
load_file.call(file)
end end
############################################ ############################################
TkHTML_File_Viewer.new(file)
Tk.mainloop Tk.mainloop

View File

@ -29,11 +29,11 @@ table = Tk::TkTable.new(:rows=>rows, :cols=>cols, :variable=>ary,
:rowstretchmode=>:last, :colstretchmode=>:last, :rowstretchmode=>:last, :colstretchmode=>:last,
:rowtagcommand=>proc{|row| :rowtagcommand=>proc{|row|
row = Integer(row) row = Integer(row)
return 'OddRow' if row>0 && row%2 == 1 (row>0 && row%2 == 1)? 'OddRow': ''
}, },
:coltagcommand=>proc{|col| :coltagcommand=>proc{|col|
col = Integer(col) col = Integer(col)
return 'OddCol' if col>0 && col%2 == 1 (col>0 && col%2 == 1)? 'OddCol': ''
}, },
:selectmode=>:extended, :sparsearray=>false) :selectmode=>:extended, :sparsearray=>false)

View File

@ -45,11 +45,11 @@ table = Tk::TkTable.new(:rows=>rows, :cols=>cols,
:rowstretchmode=>:last, :colstretchmode=>:last, :rowstretchmode=>:last, :colstretchmode=>:last,
:rowtagcommand=>proc{|row| :rowtagcommand=>proc{|row|
row = Integer(row) row = Integer(row)
return 'OddRow' if row>0 && row%2 == 1 (row>0 && row%2 == 1)? 'OddRow': ''
}, },
:coltagcommand=>proc{|col| :coltagcommand=>proc{|col|
col = Integer(col) col = Integer(col)
return 'OddCol' if col>0 && col%2 == 1 (col>0 && col%2 == 1)? 'OddCol': ''
}, },
:selectmode=>:extended, :flashmode=>true, :selectmode=>:extended, :flashmode=>true,
:rowstretch=>:unset, :colstretch=>:unset, :rowstretch=>:unset, :colstretch=>:unset,

View File

@ -29,7 +29,7 @@ table = Tk::TkTable.new(:rows=>rows, :cols=>cols, :variable=>ary,
:roworigin=>-5, :colorigin=>-2, :roworigin=>-5, :colorigin=>-2,
:coltagcommand=>proc{|col| :coltagcommand=>proc{|col|
col = Integer(col) col = Integer(col)
return 'OddCol' if col>0 && col%2 == 1 (col>0 && col%2 == 1)? 'OddCol': ''
}, },
:selectmode=>:extended, :flashmode=>true, :selectmode=>:extended, :flashmode=>true,
:rowstretch=>:unset, :colstretch=>:unset, :rowstretch=>:unset, :colstretch=>:unset,

View File

@ -28,7 +28,7 @@ table = Tk::TkTable.new(:rows=>rows, :cols=>cols, :variable=>ary,
:titlerows=>1, :titlecols=>1, :titlerows=>1, :titlecols=>1,
:coltagcommand=>proc{|col| :coltagcommand=>proc{|col|
col = Integer(col) col = Integer(col)
return 'OddCol' if col>0 && col%2 == 1 (col>0 && col%2 == 1)? 'OddCol': ''
}, },
:selectmode=>:extended, :selectmode=>:extended,
:colstretch=>:unset, :rowstretch=>:unset, :colstretch=>:unset, :rowstretch=>:unset,

View File

@ -111,6 +111,7 @@ class TkTreeCtrl_demo
[['File']] [['File']]
] ]
if Tk::PLATFORM['platform'] != 'unix' if Tk::PLATFORM['platform'] != 'unix'
TkConsole.create
TkConsole.eval('.console conf -height 8') TkConsole.eval('.console conf -height 8')
menuspec[0] << ['Console', proc{ menuspec[0] << ['Console', proc{
if TkComm.bool(TkConsole.eval('winfo ismapped .')) if TkComm.bool(TkConsole.eval('winfo ismapped .'))

View File

@ -4,7 +4,7 @@
* Oct. 24, 1997 Y. Matsumoto * Oct. 24, 1997 Y. Matsumoto
*/ */
#define TCLTKLIB_RELEASE_DATE "2005-03-10" #define TCLTKLIB_RELEASE_DATE "2005-03-30"
#include "ruby.h" #include "ruby.h"
#include "rubysig.h" #include "rubysig.h"
@ -22,6 +22,12 @@
#include <tcl.h> #include <tcl.h>
#include <tk.h> #include <tk.h>
#ifndef TCL_ALPHA_RELEASE
#define TCL_ALPHA_RELEASE 0
#define TCL_BETA_RELEASE 1
#define TCL_FINAL_RELEASE 2
#endif
#ifdef __MACOS__ #ifdef __MACOS__
# include <tkMac.h> # include <tkMac.h>
# include <Quickdraw.h> # include <Quickdraw.h>
@ -4945,6 +4951,84 @@ ip_create_slave(argc, argv, self)
return retval; return retval;
} }
#if defined(MAC_TCL) || defined(__WIN32__)
#if TCL_MAJOR_VERSION < 8 \
|| (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0) \
|| (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 1 \
&& (TCL_RELEASE_LEVEL == TCL_ALPHA_RELEASE \
|| (TCL_RELEASE_LEVEL == TCL_BETA_RELEASE \
&& TCL_RELEASE_SERIAL < 2) ) )
EXTERN void TkConsoleCreate _((void));
#endif
#if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 1 \
&& ( (TCL_RELEASE_LEVEL == TCL_FINAL_RELEASE \
&& TCL_RELEASE_SERIAL == 0) \
|| (TCL_RELEASE_LEVEL == TCL_BETA_RELEASE \
&& TCL_RELEASE_SERIAL >= 2) )
EXTERN void TkConsoleCreate_ _((void));
#endif
#endif
static VALUE
ip_create_console_core(interp, argc, argv)
VALUE interp;
int argc; /* dummy */
VALUE *argv; /* dummy */
{
struct tcltkip *ptr = get_ip(interp);
if (Tcl_GetVar(ptr->ip,"tcl_interactive",TCL_GLOBAL_ONLY) == (char*)NULL) {
Tcl_SetVar(ptr->ip, "tcl_interactive", "0", TCL_GLOBAL_ONLY);
}
#if TCL_MAJOR_VERSION > 8 \
|| (TCL_MAJOR_VERSION == 8 \
&& (TCL_MINOR_VERSION > 1 \
|| (TCL_MINOR_VERSION == 1 \
&& TCL_RELEASE_LEVEL == TCL_FINAL_RELEASE \
&& TCL_RELEASE_SERIAL >= 1) ) )
Tk_InitConsoleChannels(ptr->ip);
if (Tk_CreateConsoleWindow(ptr->ip) != TCL_OK) {
rb_raise(rb_eRuntimeError, "fail to create console-window");
}
#else
#if defined(MAC_TCL) || defined(__WIN32__)
#if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 1 \
&& ( (TCL_RELEASE_LEVEL == TCL_FINAL_RELEASE && TCL_RELEASE_SERIAL == 0) \
|| (TCL_RELEASE_LEVEL == TCL_BETA_RELEASE && TCL_RELEASE_SERIAL >= 2) )
TkConsoleCreate_();
#else
TkConsoleCreate();
#endif
if (TkConsoleInit(ptr->ip) != TCL_OK) {
rb_raise(rb_eRuntimeError, "fail to create console-window");
}
#else
rb_notimplement();
#endif
#endif
return interp;
}
static VALUE
ip_create_console(self)
VALUE self;
{
struct tcltkip *ptr = get_ip(self);
/* ip is deleted? */
if (ptr == (struct tcltkip *)NULL || ptr->ip == (Tcl_Interp*)NULL
|| Tcl_InterpDeleted(ptr->ip)) {
DUMP1("ip is deleted");
rb_raise(rb_eRuntimeError, "interpreter is deleted");
}
return tk_funcall(ip_create_console_core, 0, (VALUE*)NULL, self);
}
/* make ip "safe" */ /* make ip "safe" */
static VALUE static VALUE
ip_make_safe_core(interp, argc, argv) ip_make_safe_core(interp, argc, argv)
@ -8349,6 +8433,8 @@ Init_tcltklib()
rb_define_method(ip, "_invoke", ip_invoke, -1); rb_define_method(ip, "_invoke", ip_invoke, -1);
rb_define_method(ip, "_return_value", ip_retval, 0); rb_define_method(ip, "_return_value", ip_retval, 0);
rb_define_method(ip, "_create_console", ip_create_console, 0);
/* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */
rb_define_method(ip, "_get_variable", ip_get_variable, 2); rb_define_method(ip, "_get_variable", ip_get_variable, 2);