mirror of
https://github.com/ruby/ruby.git
synced 2025-09-17 17:43:59 +02:00
* 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). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16281 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7542aa5b39
commit
8f5ddf723f
4 changed files with 73 additions and 27 deletions
|
@ -201,6 +201,38 @@ module Tk
|
|||
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)
|
||||
|
|
|
@ -33,6 +33,8 @@ class << Tk::Tile::Style
|
|||
# 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 @@ class << Tk::Tile::Style
|
|||
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 @@ class << Tk::Tile::Style
|
|||
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 @@ class << Tk::Tile::Style
|
|||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#
|
||||
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
|
||||
#
|
||||
version = '0.1.1'
|
||||
version = '0.1.2'
|
||||
#
|
||||
##########################################################################
|
||||
# parse commandline arguments
|
||||
|
@ -107,38 +107,16 @@ TkConfigMethod.__set_IGNORE_UNKNOWN_CONFIGURE_OPTION__! true
|
|||
TkItemConfigMethod.__set_IGNORE_UNKNOWN_CONFIGURE_OPTION__! true
|
||||
|
||||
|
||||
##########################################################################
|
||||
# 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]
|
||||
|
||||
|
||||
##########################################################################
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue