diff options
author | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-10-19 08:38:35 +0000 |
---|---|---|
committer | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-10-19 08:38:35 +0000 |
commit | bf0e2520d7103948427adc520047335f55038907 (patch) | |
tree | b099d3f9e39b6d13d5e240505efda430896ab693 /ext/tk/lib | |
parent | 281bfbd9cd5f72d08a4dd550f92cf51b8a6f656f (diff) | |
download | ruby-bf0e2520d7103948427adc520047335f55038907.tar.gz |
* ext/tk/tcltklib.c: support Tcl/Tk8.6.
* ext/tk/lib/tk.rb: ditto.
* ext/tk/extconf.rb: ditto.
* ext/tk/lib/tk_mac.rb: add new features of Tcl/Tk8.6.
* ext/tk/lib/tkextlib/tile/treeview.rb: ditto.
* ext/tk/lib/tkextlib/tile/fontchooser.rb: add an alias.
* ext/tk/lib/tk/autoload.rb: ditto.
* ext/tk/lib/tkextlib/tcllib/validator.rb: add a new feature of tklib extension.
* ext/tk/lib/tkextlib/tkimg/dted.rb: a new supported format of Img extension.
* ext/tk/lib/tkextlib/tkimg/raw.rb: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48018 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/lib')
-rw-r--r-- | ext/tk/lib/tk.rb | 22 | ||||
-rw-r--r-- | ext/tk/lib/tk/autoload.rb | 2 | ||||
-rw-r--r-- | ext/tk/lib/tk/fontchooser.rb | 4 | ||||
-rw-r--r-- | ext/tk/lib/tk/tk_mac.rb | 158 | ||||
-rw-r--r-- | ext/tk/lib/tkextlib/tcllib/validator.rb | 65 | ||||
-rw-r--r-- | ext/tk/lib/tkextlib/tile/treeview.rb | 30 | ||||
-rw-r--r-- | ext/tk/lib/tkextlib/tkimg/dted.rb | 33 | ||||
-rw-r--r-- | ext/tk/lib/tkextlib/tkimg/raw.rb | 33 |
8 files changed, 343 insertions, 4 deletions
diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index 5bac92e47c..45f86a9253 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -1309,8 +1309,12 @@ EOS end unless interp.deleted? - #Thread.current[:status].value = TclTkLib.mainloop(false) - Thread.current[:status].value = interp.mainloop(false) + begin + #Thread.current[:status].value = TclTkLib.mainloop(false) + Thread.current[:status].value = interp.mainloop(false) + rescue Exception=>e + puts "ignore exception on interp: #{e.inspect}\n" if $DEBUG + end end ensure @@ -1569,7 +1573,15 @@ EOS EOL =end - at_exit{ INTERP.remove_tk_procs(TclTkLib::FINALIZE_PROC_NAME) } + if !WITH_RUBY_VM || RUN_EVENTLOOP_ON_MAIN_THREAD ### check Ruby 1.9 !!!!!!! + at_exit{ INTERP.remove_tk_procs(TclTkLib::FINALIZE_PROC_NAME) } + else + at_exit{ + Tk.root.destroy + INTERP.remove_tk_procs(TclTkLib::FINALIZE_PROC_NAME) + INTERP_THREAD.kill.join + } + end EventFlag = TclTkLib::EventFlag @@ -5197,6 +5209,8 @@ class TkWindow<TkObject TkWinfo.exist?(self) end + alias subcommand tk_send + def bind_class @db_class || self.class() end @@ -5742,7 +5756,7 @@ TkWidget = TkWindow #Tk.freeze module Tk - RELEASE_DATE = '2010-06-03'.freeze + RELEASE_DATE = '2014-10-19'.freeze autoload :AUTO_PATH, 'tk/variable' autoload :TCL_PACKAGE_PATH, 'tk/variable' diff --git a/ext/tk/lib/tk/autoload.rb b/ext/tk/lib/tk/autoload.rb index f6ca261da9..451922c7d3 100644 --- a/ext/tk/lib/tk/autoload.rb +++ b/ext/tk/lib/tk/autoload.rb @@ -94,6 +94,8 @@ module Tk autoload :Y_Scrollable, 'tk/scrollable' autoload :Scrollable, 'tk/scrollable' + autoload :Fontchooser, 'tk/fontchooser' + autoload :Wm, 'tk/wm' autoload :Wm_for_General, 'tk/wm' diff --git a/ext/tk/lib/tk/fontchooser.rb b/ext/tk/lib/tk/fontchooser.rb index 694c58a607..22d70f9c0a 100644 --- a/ext/tk/lib/tk/fontchooser.rb +++ b/ext/tk/lib/tk/fontchooser.rb @@ -8,6 +8,10 @@ module TkFont::Chooser extend TkCore end +module Tk + Fontchooser = TkFont::Chooser +end + class << TkFont::Chooser def method_missing(id, *args) name = id.id2name diff --git a/ext/tk/lib/tk/tk_mac.rb b/ext/tk/lib/tk/tk_mac.rb new file mode 100644 index 0000000000..77bb2349cc --- /dev/null +++ b/ext/tk/lib/tk/tk_mac.rb @@ -0,0 +1,158 @@ +# +# tk/tk_mac.rb : Access Mac-Specific functionality on OS X from Tk +# (supported by Tk8.6 or later) +# +# ATTENTION !! +# This is NOT TESTED. Because I have no test-environment. +# +require 'tk' + +module Tk + module Mac + end +end + +module Tk::Mac + extend TkCore + + # event handler callbacks + def self.def_ShowPreferences(cmd=Proc.new) + ip_eval("proc ::tk::mac::ShowPreferences {} { #{install_cmd(cmd)} }") + nil + end + + def self.def_OpenApplication(cmd=Proc.new) + ip_eval("proc ::tk::mac::OpenApplication {} { #{install_cmd(cmd)} }") + nil + end + + def self.def_ReopenApplication(cmd=Proc.new) + ip_eval("proc ::tk::mac::ReopenApplication {} { #{install_cmd(cmd)} }") + nil + end + + def self.def_OpenDocument(cmd=Proc.new) + ip_eval("proc ::tk::mac::OpenDocument {args} { eval #{install_cmd(cmd)} $args }") + nil + end + + def self.def_PrintDocument(cmd=Proc.new) + ip_eval("proc ::tk::mac::PrintDocument {args} { eval #{install_cmd(cmd)} $args }") + nil + end + + def self.def_Quit(cmd=Proc.new) + ip_eval("proc ::tk::mac::Quit {} { #{install_cmd(cmd)} }") + nil + end + + def self.def_OnHide(cmd=Proc.new) + ip_eval("proc ::tk::mac::OnHide {} { #{install_cmd(cmd)} }") + nil + end + + def self.def_OnShow(cmd=Proc.new) + ip_eval("proc ::tk::mac::OnShow {} { #{install_cmd(cmd)} }") + nil + end + + def self.def_ShowHelp(cmd=Proc.new) + ip_eval("proc ::tk::mac::ShowHelp {} { #{install_cmd(cmd)} }") + nil + end + + + # additional dialogs + def self.standardAboutPanel + tk_call('::tk::mac::standardAboutPanel') + nil + end + + + # system configuration + def self.useCompatibilityMetrics(mode) + tk_call('::tk::mac::useCompatibilityMetrics', mode) + nil + end + + def self.CGAntialiasLimit(limit) + tk_call('::tk::mac::CGAntialiasLimit', limit) + nil + end + + def self.antialiasedtext(num) + tk_call('::tk::mac::antialiasedtext', num) + nil + end + + def self.useThemedToplevel(mode) + tk_call('::tk::mac::useThemedToplevel', mode) + nil + end + +end + +class Tk::Mac::IconBitmap < TkImage + TkCommandNames = ['::tk::mac::iconBitmap'].freeze + + def self.new(width, height, keys) + if keys.kind_of?(Hash) + name = nil + if keys.key?(:imagename) + name = keys[:imagename] + elsif keys.key?('imagename') + name = keys['imagename'] + end + if name + if name.kind_of?(TkImage) + obj = name + else + name = _get_eval_string(name) + obj = nil + Tk_IMGTBL.mutex.synchronize{ + obj = Tk_IMGTBL[name] + } + end + if obj + if !(keys[:without_creating] || keys['without_creating']) + keys = _symbolkey2str(keys) + keys.delete('imagename') + keys.delete('without_creating') + obj.instance_eval{ + tk_call_without_enc('::tk::mac::iconBitmap', + @path, width, height, *hash_kv(keys, true)) + } + end + return obj + end + end + end + (obj = self.allocate).instance_eval{ + Tk_IMGTBL.mutex.synchronize{ + initialize(width, height, keys) + Tk_IMGTBL[@path] = self + } + } + obj + end + + def initialize(width, height, keys) + @path = nil + without_creating = false + if keys.kind_of?(Hash) + keys = _symbolkey2str(keys) + @path = keys.delete('imagename') + without_creating = keys.delete('without_creating') + end + unless @path + Tk_Image_ID.mutex.synchronize{ + @path = Tk_Image_ID.join(TkCore::INTERP._ip_id_) + Tk_Image_ID[1].succ! + } + end + unless without_creating + tk_call_without_enc('::tk::mac::iconBitmap', + @path, width, height, *hash_kv(keys, true)) + end + end +end diff --git a/ext/tk/lib/tkextlib/tcllib/validator.rb b/ext/tk/lib/tkextlib/tcllib/validator.rb new file mode 100644 index 0000000000..3a71960afa --- /dev/null +++ b/ext/tk/lib/tkextlib/tcllib/validator.rb @@ -0,0 +1,65 @@ +# +# tkextlib/tcllib/validator.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# +# * Part of tcllib extension +# * Provides a unified validation API +# + +require 'tk' +require 'tkextlib/tcllib.rb' + +# TkPackage.require('widget::validator', '0.1') +TkPackage.require('widget::validator') + +module Tk::Tcllib + module Validator + PACKAGE_NAME = 'widget::validator'.freeze + def self.package_name + PACKAGE_NAME + end + + def self.package_version + begin + TkPackage.require('widget::validator') + rescue + '' + end + end + end +end + +module Tk::Tcllib::Validator + extend TkCore + + def self.attach(widget, color, cmd=Proc.new) + tk_call_without_enc('::widget::validator', 'attach', widget, color, cmd) + nil + end + + def self.detach(widget) + tk_call_without_enc('::widget::validator', 'detach', widget) + nil + end + + def self.validate(widget) + tk_call_without_enc('::widget::validator', 'validate', widget) + nil + end + + def attach_validator(color, cmd=Proc.new) + tk_call_without_enc('::widget::validator', 'attach', @path, color, cmd) + self + end + + def detach_validator(color, cmd=Proc.new) + tk_call_without_enc('::widget::validator', 'detach', @path) + self + end + + def invoke_validator(color, cmd=Proc.new) + tk_call_without_enc('::widget::validator', 'validate', @path) + self + end + alias validate_validator invoke_validator +end diff --git a/ext/tk/lib/tkextlib/tile/treeview.rb b/ext/tk/lib/tkextlib/tile/treeview.rb index 70db3d6d78..ed8e875d96 100644 --- a/ext/tk/lib/tkextlib/tile/treeview.rb +++ b/ext/tk/lib/tkextlib/tile/treeview.rb @@ -986,6 +986,18 @@ class Tk::Tile::Treeview::Tag < TkObject end alias added? tag_has? + def tag_has + @t.tag_has(@id) + end + + def add(*items) + @t.tag_add(@id, *items)) + end + + def remove(*items) + @t.tag_remove(@id, *items)) + end + def bind(seq, *args) if TkComm._callback_entry?(args[0]) || !block_given? cmd = args.shift @@ -1299,6 +1311,24 @@ class Tk::Tile::Treeview < TkWindow _bindinfo([@path, 'tag', 'bind', tag], context) end alias tagbindinfo tag_bindinfo + + def tag_names + tk_split_simplelist(tk_send('tag', 'names')).collect{|id| + Tk::Tile::Treeview::Tag.id2obj(self, id) + } + end + + def tag_add(tag, *items) + fail ArgumentError, "no target items" if items.empty? + tk_send('tag', 'add', tagid(tag), *(items.collect{|item| tagid(item)})) + self + end + + def tag_remove(tag, *items) + tk_send('tag', 'remove', tagid(tag), *(items.collect{|item| tagid(item)})) + self + end + end #Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Treeview, :TkTreeview) diff --git a/ext/tk/lib/tkextlib/tkimg/dted.rb b/ext/tk/lib/tkextlib/tkimg/dted.rb new file mode 100644 index 0000000000..cae833664c --- /dev/null +++ b/ext/tk/lib/tkextlib/tkimg/dted.rb @@ -0,0 +1,33 @@ +# +# TkImg - format 'DTED' +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# +require 'tk' + +# call setup script for general 'tkextlib' libraries +require 'tkextlib/setup.rb' + +# call setup script +require 'tkextlib/tkimg/setup.rb' + +# TkPackage.require('img::dted', '1.4') +TkPackage.require('img::dted') + +module Tk + module Img + module DTED + PACKAGE_NAME = 'img::dted'.freeze + def self.package_name + PACKAGE_NAME + end + + def self.package_version + begin + TkPackage.require('img::dted') + rescue + '' + end + end + end + end +end diff --git a/ext/tk/lib/tkextlib/tkimg/raw.rb b/ext/tk/lib/tkextlib/tkimg/raw.rb new file mode 100644 index 0000000000..5f1cdcaac0 --- /dev/null +++ b/ext/tk/lib/tkextlib/tkimg/raw.rb @@ -0,0 +1,33 @@ +# +# TkImg - format 'Raw Data' +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# +require 'tk' + +# call setup script for general 'tkextlib' libraries +require 'tkextlib/setup.rb' + +# call setup script +require 'tkextlib/tkimg/setup.rb' + +# TkPackage.require('img::raw', '1.4') +TkPackage.require('img::raw') + +module Tk + module Img + module Raw + PACKAGE_NAME = 'img::raw'.freeze + def self.package_name + PACKAGE_NAME + end + + def self.package_version + begin + TkPackage.require('img::raw') + rescue + '' + end + end + end + end +end |