* ext/tk/lib/tkextlib/tile/treeview.rb: Tk::Tile::Treeview#headingconfigure

is now working and more. [ruby-dev:26716]

* ext/tk/sample/tkextlib/tile/demo.rb: use Tk::Tile::Treeview#headingconfigure
  instead of direct Tk.tk_call.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8890 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ocean 2005-08-02 21:05:17 +00:00
parent a26cec27e1
commit 28c635fa9a
3 changed files with 146 additions and 86 deletions

View File

@ -1,4 +1,11 @@
2005-08-01 ocean <ocean@ruby-lang.org> 2005-08-03 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* lib/tkextlib/tile/treeview.rb: Tk::Tile::Treeview#headingconfigure
is now working and more. [ruby-dev:26716]
* sample/tkextlib/tile/demo.rb: use Tk::Tile::Treeview#headingconfigure instead of direct Tk.tk_call.
2005-08-02 ocean <ocean@ruby-lang.org>
* lib/tkextlib/tile/tprogressbar.rb: Tk::Tile::TProgressbar#start * lib/tkextlib/tile/tprogressbar.rb: Tk::Tile::TProgressbar#start
takes optional argument `interval'. takes optional argument `interval'.
@ -6,7 +13,7 @@
* sample/tkextlib/tile/demo.rb: emulate Tk::Tile::TProgressbar * sample/tkextlib/tile/demo.rb: emulate Tk::Tile::TProgressbar
with Tk::Tile::TProgress in tile 0.4. (repeating buttons demo) with Tk::Tile::TProgress in tile 0.4. (repeating buttons demo)
2005-08-01 ocean <ocean@ruby-lang.org> 2005-08-02 ocean <ocean@ruby-lang.org>
* sample/tkextlib/tile/demo.rb: added repeating buttons demo. * sample/tkextlib/tile/demo.rb: added repeating buttons demo.

View File

@ -10,93 +10,124 @@ module Tk
class Treeview < TkWindow class Treeview < TkWindow
end end
module TreeviewItemConfig module TreeviewConfig
include TkItemConfigMethod include TkItemConfigMethod
def __item_cget_cmd(id) def __item_cget_cmd(id)
[self.path, 'item', id] [self.path, id[0], id[1]]
end end
private :__item_cget_cmd private :__item_cget_cmd
def __item_config_cmd(id) def __item_config_cmd(id)
[self.path, 'item', id] [self.path, id[0], id[1]]
end end
private :__item_config_cmd private :__item_config_cmd
def __item_numstrval_optkeys(id) def __item_numstrval_optkeys(id)
['width'] case id[0]
when :item, 'item'
['width']
when :column, 'column'
super(id[1])
when :heading, 'heading'
super(id[1])
end
end end
private :__item_numstrval_optkeys private :__item_numstrval_optkeys
def __item_strval_optkeys(id) def __item_strval_optkeys(id)
# maybe need to override case id[0]
super(id) + ['id'] when :item, 'item'
super(id) + ['id']
when :column, 'column'
super(id[1])
when :heading, 'heading'
super(id[1])
end
end end
private :__item_strval_optkeys private :__item_strval_optkeys
def __item_boolval_optkeys(id) def __item_boolval_optkeys(id)
['open'] case id[0]
when :item, 'item'
['open']
when :column, 'column'
super(id[1])
when :heading, 'heading'
super(id[1])
end
end end
private :__item_boolval_optkeys private :__item_boolval_optkeys
def __item_listval_optkeys(id) def __item_listval_optkeys(id)
['values'] case id[0]
end when :item, 'item'
private :__item_listval_optkeys ['values']
end when :column, 'column'
[]
module TreeviewColumnConfig when :heading, 'heading'
include TkItemConfigMethod []
end
def __item_cget_cmd(id)
[self.path, 'column', id]
end
private :__item_cget_cmd
def __item_config_cmd(id)
[self.path, 'column', id]
end
private :__item_config_cmd
def __item_listval_optkeys(id)
[]
end end
private :__item_listval_optkeys private :__item_listval_optkeys
alias columncget itemcget alias __itemcget itemcget
alias columnconfigure itemconfigure alias __itemconfigure itemconfigure
alias columnconfiginfo itemconfiginfo alias __itemconfiginfo itemconfiginfo
alias current_columnconfiginfo current_itemconfiginfo alias __current_itemconfiginfo current_itemconfiginfo
private :itemcget, :itemconfigure private :__itemcget, :__itemconfigure
private :itemconfiginfo, :current_itemconfiginfo private :__itemconfiginfo, :__current_itemconfiginfo
end
module TreeviewHeadingConfig # Treeview Item
include TkItemConfigMethod def itemcget(tagOrId, option)
__itemcget([:item, tagOrId], option)
def __item_cget_cmd(id)
[self.path, 'heading', id]
end end
private :__item_cget_cmd def itemconfigure(tagOrId, slot, value=None)
__itemconfigure([:item, tagOrId], slot, value)
def __item_config_cmd(id)
[self.path, 'heading', id]
end end
private :__item_config_cmd def itemconfiginfo(tagOrId, slot=nil)
__itemconfiginfo([:item, tagOrId], slot)
def __item_listval_optkeys(id) end
[] def current_itemconfiginfo(tagOrId, slot=nil)
__current_itemconfiginfo([:item, tagOrId], slot)
end end
private :__item_listval_optkeys
alias headingcget itemcget # Treeview Column
alias headingconfigure itemconfigure def columncget(tagOrId, option)
alias headingconfiginfo itemconfiginfo __itemcget([:column, tagOrId], option)
alias current_headingconfiginfo current_itemconfiginfo end
def columnconfigure(tagOrId, slot, value=None)
__itemconfigure([:column, tagOrId], slot, value)
end
def columnconfiginfo(tagOrId, slot=nil)
__itemconfiginfo([:column, tagOrId], slot)
end
def current_columnconfiginfo(tagOrId, slot=nil)
__current_itemconfiginfo([:column, tagOrId], slot)
end
alias column_cget columncget
alias column_configure columnconfigure
alias column_configinfo columnconfiginfo
alias current_column_configinfo current_columnconfiginfo
private :itemcget, :itemconfigure # Treeview Heading
private :itemconfiginfo, :current_itemconfiginfo def headingcget(tagOrId, option)
__itemcget([:heading, tagOrId], option)
end
def headingconfigure(tagOrId, slot, value=None)
__itemconfigure([:heading, tagOrId], slot, value)
end
def headingconfiginfo(tagOrId, slot=nil)
__itemconfiginfo([:heading, tagOrId], slot)
end
def current_headingconfiginfo(tagOrId, slot=nil)
__current_itemconfiginfo([:heading, tagOrId], slot)
end
alias heading_cget headingcget
alias heading_configure headingconfigure
alias heading_configinfo headingconfiginfo
alias current_heading_configinfo current_headingconfiginfo
end end
end end
end end
@ -105,9 +136,7 @@ class Tk::Tile::Treeview < TkWindow
include Tk::Tile::TileWidget include Tk::Tile::TileWidget
include Scrollable include Scrollable
include Tk::Tile::TreeviewColumnConfig include Tk::Tile::TreeviewConfig
include Tk::Tile::TreeviewHeadingConfig
include Tk::Tile::TreeviewItemConfig
if Tk::Tile::USE_TTK_NAMESPACE if Tk::Tile::USE_TTK_NAMESPACE
TkCommandNames = ['::ttk::treeview'.freeze].freeze TkCommandNames = ['::ttk::treeview'.freeze].freeze
@ -122,98 +151,119 @@ class Tk::Tile::Treeview < TkWindow
end end
def tagid(id) def tagid(id)
_get_eval_string(id) if id.kind_of?(Array)
[id[0], _get_eval_string(id[1])]
else
_get_eval_string(id)
end
end end
def children(item) def children(item)
list(tk_send_without_enc('children', item)) simplelist(tk_send_without_enc('children', item))
end end
def children=(item, *items) def set_children(item, *items)
tk_send_without_enc('children', item, *items) tk_send_without_enc('children', item,
items array2tk_list(items.flatten, true))
self
end end
def delete(*items) def delete(*items)
tk_send_without_enc('delete', *items) tk_send_without_enc('delete', array2tk_list(items.flatten, true))
self self
end end
def detach(*items) def detach(*items)
tk_send_without_enc('detach', *items) tk_send_without_enc('detach', array2tk_list(items.flatten, true))
self self
end end
def exist?(item) def exist?(item)
bool(tk_send_without_enc('exists', item)) bool(tk_send_without_enc('exists', _get_eval_enc_str(item)))
end end
def focus_item(item = None) def focus_item(item = None)
tk_send_without_enc('focus', item) tk_send('focus', item)
end end
def identify(x, y) def identify(x, y)
tk_send_without_enc('identify', x, y) ret = simplelist(tk_send('identify', x, y))
case ret[0]
when 'heading', 'separator', 'cell'
ret[-1] = num_or_str(ret[-1])
end
end end
def index(item) def index(item)
number(tk_send_without_enc('index', item)) number(tk_send('index', item))
end end
def insert(parent, idx, keys={}) def insert(parent, idx, keys={})
keys = _symbolkey2str(keys) keys = _symbolkey2str(keys)
id = keys.delete('id') id = keys.delete('id')
if id if id
tk_send_without_enc('insert', parent, idx, '-id', id, *hash_kv(keys)) tk_send('insert', parent, idx, '-id', id, *hash_kv(keys))
else else
tk_send_without_enc('insert', parent, idx, *hash_kv(keys)) tk_send('insert', parent, idx, *hash_kv(keys))
end end
self self
end end
def instate(spec, cmd=Proc.new)
tk_send('instate', spec, cmd)
end
def state(spec=None)
tk_send('state', spec)
end
def move(item, parent, idx) def move(item, parent, idx)
tk_send_without_enc('move', item, parent, idx) tk_send('move', item, parent, idx)
self self
end end
def next(item) def next(item)
tk_send_without_enc('next', item) tk_send('next', item)
end end
def parent(item) def parent(item)
tk_send_without_enc('parent', item) tk_send('parent', item)
end end
def prev(item) def prev(item)
tk_send_without_enc('prev', item) tk_send('prev', item)
end end
def see(item) def see(item)
tk_send_without_enc('see', item) tk_send('see', item)
self self
end end
def selection
simplelist(tk_send('selection'))
end
alias selection_get selection
def selection_add(*items) def selection_add(*items)
tk_send_without_enc('selection', 'add', *items) tk_send('selection', 'add', array2tk_list(items.flatten, true))
self self
end end
def selection_remove(*items) def selection_remove(*items)
tk_send_without_enc('selection', 'remove', *items) tk_send('selection', 'remove', array2tk_list(items.flatten, true))
self self
end end
def selection_set(*items) def selection_set(*items)
tk_send_without_enc('selection', 'set', *items) tk_send('selection', 'set', array2tk_list(items.flatten, true))
self self
end end
def selection_toggle(*items) def selection_toggle(*items)
tk_send_without_enc('selection', 'toggle', *items) tk_send('selection', 'toggle', array2tk_list(items.flatten, true))
self self
end end
def get(item, col) def get(item, col)
tk_send_without_enc('set', item, col) tk_send('set', item, col)
end end
def set(item, col, value) def set(item, col, value)
tk_send_without_enc('set', item, col, value) tk_send('set', item, col, value)
self self
end end
end end

View File

@ -14,7 +14,10 @@ Tk.load_tclscript(File.join(demodir, 'repeater.tcl'))
# This forces an update of the available packages list. It's required # This forces an update of the available packages list. It's required
# for package names to find the themes in demos/themes/*.tcl # for package names to find the themes in demos/themes/*.tcl
Tk.tk_call(TkPackage.unknown_proc, 'Tcl', TkPackage.provide('Tcl')) ## Tk.tk_call(TkPackage.unknown_proc, 'Tcl', TkPackage.provide('Tcl'))
## --> This doesn't work.
## Because, unknown_proc may be "command + some arguments".
Tk.ip_eval("#{TkPackage.unknown_proc} Tcl #{TkPackage.provide('Tcl')}")
TkRoot.new{ TkRoot.new{
title 'Tile demo' title 'Tile demo'
@ -574,8 +577,8 @@ if TkPackage.vcompare(Tk::Tile.package_version, '0.5') >= 0
# Later nodes will be added in <<TreeviewOpen>> binding. # Later nodes will be added in <<TreeviewOpen>> binding.
treeview.insert('', 0, :id=>'.', :text=>'Main Window', :open=>false, treeview.insert('', 0, :id=>'.', :text=>'Main Window', :open=>false,
:values=>[TkWinfo.classname('.')]) :values=>[TkWinfo.classname('.')])
Tk.tk_call(treeview, 'heading', '#0', :text=>'Widget') treeview.headingconfigure('#0', :text=>'Widget')
Tk.tk_call(treeview, 'heading', 'Class', :text=>'Class') treeview.headingconfigure('Class', :text=>'Class')
treeview.bind('<TreeviewOpen>', proc{fillTree(treeview)}) treeview.bind('<TreeviewOpen>', proc{fillTree(treeview)})
def fillTree(treeview) def fillTree(treeview)