ruby-changes:4787
From: ko1@a...
Date: Sat, 3 May 2008 22:52:58 +0900 (JST)
Subject: [ruby-changes:4787] nagai - Ruby:r16281 (ruby_1_8): * ext/tk/lib/tkextlib/tile.rb, ext/tk/lib/tkextlib/tile/style.rb,
nagai 2008-05-03 22:52:47 +0900 (Sat, 03 May 2008)
New Revision: 16281
Modified files:
branches/ruby_1_8/ext/tk/lib/tkextlib/tile/style.rb
branches/ruby_1_8/ext/tk/lib/tkextlib/tile.rb
branches/ruby_1_8/ext/tk/lib/tkextlib/version.rb
branches/ruby_1_8/ext/tk/sample/ttk_wrapper.rb
Log:
* ext/tk/lib/tkextlib/tile.rb, ext/tk/lib/tkextlib/tile/style.rb,
ext/tk/sample/ttk_wrapper.rb: improve treating and control themes.
add Tk::Tile.themes and Tk::Tile.set_theme(theme).
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ext/tk/lib/tkextlib/tile/style.rb?r1=16281&r2=16280&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ext/tk/lib/tkextlib/tile.rb?r1=16281&r2=16280&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ext/tk/lib/tkextlib/version.rb?r1=16281&r2=16280&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ext/tk/sample/ttk_wrapper.rb?r1=16281&r2=16280&diff_format=u
Index: ruby_1_8/ext/tk/sample/ttk_wrapper.rb
===================================================================
--- ruby_1_8/ext/tk/sample/ttk_wrapper.rb (revision 16280)
+++ ruby_1_8/ext/tk/sample/ttk_wrapper.rb (revision 16281)
@@ -4,7 +4,7 @@
#
# by Hidetoshi NAGAI (nagai@a...)
#
-version = '0.1.1'
+version = '0.1.2'
#
##########################################################################
# parse commandline arguments
@@ -108,37 +108,15 @@
##########################################################################
-# define utility method
-##########################################################################
-def setTheme(theme)
- unless Tk::Tile::Style.theme_names.find{|n| n == theme}
- if (pkg = TkPackage.names.find{|n| n =~ /(tile|ttk)::theme::#{theme}/})
- TkPackage.require(pkg)
- end
- end
- Tk::Tile::Style.theme_use(theme)
-end
-
-
-##########################################################################
-# make theme name list
-##########################################################################
-ThemesList = Tk::Tile::Style.theme_names
-TkPackage.names.find_all{|n| n =~ /^(tile|ttk)::theme::/}.each{|pkg|
- ThemesList << pkg.split('::')[-1]
-}
-ThemesList.uniq!
-
-
-##########################################################################
# set theme of widget style
##########################################################################
if OPTS[:list] || OPTS[:verbose]
- print "supported theme names: #{ThemesList.inspect}\n"
+ print "supported theme names: #{Tk::Tile.themes.inspect}\n"
exit if OPTS[:list] && ARGV.empty?
end
print "use theme: \"#{OPTS[:theme]}\"\n" if OPTS[:theme] && OPTS[:verbose]
-setTheme(OPTS[:theme]) if OPTS[:theme]
+#setTheme(OPTS[:theme]) if OPTS[:theme]
+Tk::Tile.set_theme(OPTS[:theme]) if OPTS[:theme]
##########################################################################
Index: ruby_1_8/ext/tk/lib/tkextlib/version.rb
===================================================================
--- ruby_1_8/ext/tk/lib/tkextlib/version.rb (revision 16280)
+++ ruby_1_8/ext/tk/lib/tkextlib/version.rb (revision 16281)
@@ -2,5 +2,5 @@
# release date of tkextlib
#
module Tk
- Tkextlib_RELEASE_DATE = '2008-04-18'.freeze
+ Tkextlib_RELEASE_DATE = '2008-05-03'.freeze
end
Index: ruby_1_8/ext/tk/lib/tkextlib/tile/style.rb
===================================================================
--- ruby_1_8/ext/tk/lib/tkextlib/tile/style.rb (revision 16280)
+++ ruby_1_8/ext/tk/lib/tkextlib/tile/style.rb (revision 16281)
@@ -33,6 +33,8 @@
# conflict with some definitions on Tcl/Tk scripts.
if Tk::Tile::TILE_SPEC_VERSION_ID < 7
def __define_wrapper_proc_for_compatibility__!
+ __define_themes_and_setTheme_proc__!
+
unless Tk.info(:commands, '::ttk::style').empty?
# fail RuntimeError,
# "can't define '::ttk::style' command (already exist)"
@@ -59,6 +61,8 @@
end
else ### TILE_SPEC_VERSION_ID == 7
def __define_wrapper_proc_for_compatibility__!
+ __define_themes_and_setTheme_proc__!
+
unless Tk.info(:commands, '::ttk::style').empty?
# fail RuntimeError,
# "can't define '::ttk::style' command (already exist)"
@@ -91,6 +95,8 @@
TkCommandNames = ['::ttk::style'.freeze].freeze
def __define_wrapper_proc_for_compatibility__!
+ __define_themes_and_setTheme_proc__!
+
unless Tk.info(:commands, '::style').empty?
# fail RuntimeError, "can't define '::style' command (already exist)"
@@ -120,6 +126,36 @@
end
end
+ def __define_themes_and_setTheme_proc__!
+ TkCore::INTERP.add_tk_procs('::ttk::themes', '{ptn *}', <<-'EOS')
+ #set themes [list]
+ set themes [::ttk::style theme names]
+ foreach pkg [lsearch -inline -all -glob [package names] ttk::theme::$ptn] {
+ set theme [namespace tail $pkg]
+ if {[lsearch -exact $themes $theme] < 0} {
+ lappend themes $theme
+ }
+ }
+ foreach pkg [lsearch -inline -all -glob [package names] tile::theme::$ptn] {
+ set theme [namespace tail $pkg]
+ if {[lsearch -exact $themes $theme] < 0} {
+ lappend themes $theme
+ }
+ }
+ return $themes
+ EOS
+ #########################
+ TkCore::INTERP.add_tk_procs('::ttk::setTheme', 'theme', <<-'EOS')
+ variable currentTheme
+ if {[lsearch -exact [::ttk::style theme names] $theme] < 0} {
+ package require [lsearch -inline -regexp [package names] (ttk|tile)::theme::$theme]
+ }
+ ::ttk::style theme use $theme
+ set currentTheme $theme
+ EOS
+ end
+ private :__define_themes_and_setTheme_proc__!
+
def configure(style=nil, keys=nil)
if style.kind_of?(Hash)
keys = style
Index: ruby_1_8/ext/tk/lib/tkextlib/tile.rb
===================================================================
--- ruby_1_8/ext/tk/lib/tkextlib/tile.rb (revision 16280)
+++ ruby_1_8/ext/tk/lib/tkextlib/tile.rb (revision 16281)
@@ -201,6 +201,38 @@
args.map!{|arg| TkComm._get_eval_string(arg)}.join('.')
end
+ def self.themes(glob_ptn = nil)
+ if TILE_SPEC_VERSION_ID < 8 && Tk.info(:commands, '::ttk::themes').empty?
+ fail RuntimeError, 'not support glob option' if glob_ptn
+ cmd = ['::tile::availableThemes']
+ else
+ glob_ptn = '*' unless glob_ptn
+ cmd = ['::ttk::themes', glob_ptn]
+ end
+
+ begin
+ TkComm.simplelist(Tk.tk_call_without_enc(*cmd))
+ rescue
+ TkComm.simplelist(Tk.tk_call('lsearch', '-all', '-inline',
+ Tk::Tile::Style.theme_names,
+ glob_ptn))
+ end
+ end
+
+ def self.set_theme(theme)
+ if TILE_SPEC_VERSION_ID < 8 && Tk.info(:commands, '::ttk::setTheme').empty?
+ cmd = '::tile::setTheme'
+ else
+ cmd = '::ttk::setTheme'
+ end
+
+ begin
+ Tk.tk_call_without_enc(cmd, theme)
+ rescue
+ Tk::Tile::Style.theme_use(theme)
+ end
+ end
+
module KeyNav
if Tk::Tile::TILE_SPEC_VERSION_ID < 8
def self.enableMnemonics(w)
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/