diff options
Diffstat (limited to 'ext/tk/lib/tkextlib/tcllib')
25 files changed, 2222 insertions, 69 deletions
diff --git a/ext/tk/lib/tkextlib/tcllib/calendar.rb b/ext/tk/lib/tkextlib/tcllib/calendar.rb new file mode 100644 index 0000000000..b6843df176 --- /dev/null +++ b/ext/tk/lib/tkextlib/tcllib/calendar.rb @@ -0,0 +1,55 @@ +# +# tkextlib/tcllib/calendar.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# +# * Part of tcllib extension +# * calendar widget +# + +require 'tk' +require 'tkextlib/tcllib.rb' + +# TkPackage.require('widget::calendar', '0.9') +TkPackage.require('widget::calendar') + +module Tk::Tcllib + module Widget + class Calendar < TkCanvas + PACKAGE_NAME = 'widget::calendar'.freeze + def self.package_name + PACKAGE_NAME + end + + def self.package_version + begin + TkPackage.require('widget::calendar') + rescue + '' + end + end + end + end +end + +class Tk::Tcllib::Widget::Calendar + TkCommandNames = ['::widget::calendar'.freeze].freeze + + def __boolval_optkeys + super() << 'showpast' + end + private :__boolval_optkeys + + def create_self(keys) + if keys and keys != None + tk_call_without_enc(self.class::TkCommandNames[0], @path, + *hash_kv(keys, true)) + else + tk_call_without_enc(self.class::TkCommandNames[0], @path) + end + end + private :create_self + + def get(what = 'all') + tk_send('get', what) + end +end diff --git a/ext/tk/lib/tkextlib/tcllib/canvas_sqmap.rb b/ext/tk/lib/tkextlib/tcllib/canvas_sqmap.rb new file mode 100644 index 0000000000..0bd59511c1 --- /dev/null +++ b/ext/tk/lib/tkextlib/tcllib/canvas_sqmap.rb @@ -0,0 +1,36 @@ +# +# tkextlib/tcllib/canvas.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# +# * Part of tcllib extension +# * +# + +require 'tk' +require 'tkextlib/tcllib.rb' + +# TkPackage.require('widget::canvas_sqmap', '0.2') +TkPackage.require('widget::canvas_sqmap') + +module Tk::Tcllib + module Widget + class Canvas_Sqmap < Canvas + TkCommandNames = ['::widget::canvas_sqmap'.freeze].freeze + + def image_set(cell, img) + tk_send('image', 'set', cell, img) + self + end + + def image_unset(cell) + tk_send('image', 'unset', cell) + self + end + + def flush + tk_send('flush') + self + end + end + end +end diff --git a/ext/tk/lib/tkextlib/tcllib/canvas_zoom.rb b/ext/tk/lib/tkextlib/tcllib/canvas_zoom.rb new file mode 100644 index 0000000000..e2a5061112 --- /dev/null +++ b/ext/tk/lib/tkextlib/tcllib/canvas_zoom.rb @@ -0,0 +1,21 @@ +# +# tkextlib/tcllib/canvas.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# +# * Part of tcllib extension +# * +# + +require 'tk' +require 'tkextlib/tcllib.rb' + +# TkPackage.require('widget::canvas_zoom', '0.1') +TkPackage.require('widget::canvas_zoom') + +module Tk::Tcllib + module Widget + class Canvas_Zoom < Canvas + TkCommandNames = ['::widget::canvas_zoom'.freeze].freeze + end + end +end diff --git a/ext/tk/lib/tkextlib/tcllib/chatwidget.rb b/ext/tk/lib/tkextlib/tcllib/chatwidget.rb new file mode 100644 index 0000000000..860b9e899b --- /dev/null +++ b/ext/tk/lib/tkextlib/tcllib/chatwidget.rb @@ -0,0 +1,151 @@ +# +# tkextlib/tcllib/chatwidget.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# +# * Part of tcllib extension +# * chatwidget - Provides a multi-paned view suitable for display of +# chat room or irc channel information +# + +require 'tk' +require 'tkextlib/tcllib.rb' + +# TkPackage.require('chatwidget', '1.1.0') +TkPackage.require('chatwidget') + +module Tk::Tcllib + class ChatWidget < TkText + PACKAGE_NAME = 'chatwidget'.freeze + def self.package_name + PACKAGE_NAME + end + + def self.package_version + begin + TkPackage.require('chatwidget') + rescue + '' + end + end + end +end + +class Tk::Tcllib::ChatWidget + TkCommandNames = ['::chatwidget::chatwidget'.freeze].freeze + + def show_topic + tk_send_without_enc('topic', 'show') + self + end + + def hide_topic + tk_send_without_enc('topic', 'hide') + self + end + + def set_topic(topic) + tk_send('topic', 'set', topic) + end + + def list_name + tk_split_simplelist(tk_send('name', 'list')) + end + + def list_name_full + tk_split_simplelist(tk_send('name', 'list')).map{|lst| + nick, *opts = tk_split_simplelist(lst) + h_opt = {} + opts.slice(2){|k, v| h_opt[k[1..-1]] = tk_tcl2ruby(v)} + [nick, h_opt] + } + end + + def add_name(nick, opts={}) + tk_send('name', 'add', nick, *(hash_kv(opts))) + end + + def delete_name(nick) + tk_send('name', 'delete', nick) + end + + def get_name(nick) + lst = tk_send('name', 'get', nick) + return nil if lst.empty? + nick, *opts = tk_split_simplelist(lst) + h_opt = {} + opts.slice(2){|k, v| h_opt[k[1..-1]] = tk_tcl2ruby(v)} + [nick, h_opt] + end + + def message(msg, opts={}) + tk_send('message', msg, *(hash_kv(opts))) + self + end + + def _parse_hook_list(lst) + tk_split_simplelist(lst).map{|hook| + cmd, prior = tk_split_simplelist(hook) + [procedure(cmd), number(prior)] + } + end + private :_parse_hook_list + + def hook_add(type, *args, &blk) # args -> [prior, cmd], [prior], [cmd] + #type -> 'message', 'post', 'names_group', 'names_nick', 'chatstate', 'url' + + if prior = args.shift + if !prior.kind_of?(Numeric) + cmd = prior + if (prior = args.shift) && !prior.kind_of?(Numeric) # error + args.unshift(prior) + end + args.unshift(cmd) + end + prior ||= 50 # default priority + end + + cmd = args.shift || blk + + fail ArgumentError, "invalid arguments" unless args.empty? + fail ArgumentError, "no callback is given" unless cmd + + _parse_hook_list(tk_send('hook', 'add', type, cmd, prior)) + end + + def hook_remove(type, cmd) + #type -> 'message', 'post', 'names_group', 'names_nick', 'chatstate', 'url' + _parse_hook_list(tk_send('hook', 'remove', type, cmd)) + end + + def hook_run(type, *cmd_args) + #type -> 'message', 'post', 'names_group', 'names_nick', 'chatstate', 'url' + tk_send('hook', 'run', type, *cmd_args) + end + + def hook_list(type) + #type -> 'message', 'post', 'names_group', 'names_nick', 'chatstate', 'url' + _parse_hook_list(tk_send('hook', 'list', type)) + end + + def show_names + tk_send('names', 'show') + self + end + + def hide_names + tk_send('names', 'hide') + self + end + + def names_widget + window(tk_send('names')) + end + + def entry_widget + window(tk_send('entry')) + end + + def chat_widget + window(tk_send('chat')) + end +end diff --git a/ext/tk/lib/tkextlib/tcllib/crosshair.rb b/ext/tk/lib/tkextlib/tcllib/crosshair.rb new file mode 100644 index 0000000000..49b5361e4f --- /dev/null +++ b/ext/tk/lib/tkextlib/tcllib/crosshair.rb @@ -0,0 +1,117 @@ +# +# tkextlib/tcllib/crosshair.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# +# * Part of tcllib extension +# * Crosshairs for Tk canvas +# + +require 'tk' +require 'tkextlib/tcllib.rb' + +# TkPackage.require('crosshair', '1.0.2') +TkPackage.require('crosshair') + +module Tk::Tcllib + module Crosshair + PACKAGE_NAME = 'crosshair'.freeze + def self.package_name + PACKAGE_NAME + end + + def self.package_version + begin + TkPackage.require('crosshair') + rescue + '' + end + end + end +end + +module Tk::Tcllib::Crosshair + include TkCore + TkCommandNames = ['::crosshair::crosshair'.freeze].freeze + + def self.crosshair(w, keys={}) + Tk.tk_call('::crosshair::crosshair', w, *hash_kv(keys)) + w + end + def self.on(w, keys={}) + self.crosshair(w, keys) + end + + def self.off(w) + Tk.tk_call('::crosshair::off', w) + w + end + + def self.track_on(w, &b) + Tk.tk_call('::crosshair::track_on', w, b) + w + end + + def self.track_off(w) + Tk.tk_call('::crosshair::track_off', w) + w + end +end + +class << Tk::Tcllib::Crosshair + include TkComm + include TkCanvasItemConfig + + def __item_methodcall_optkeys(id) + {} + end + private :__item_methodcall_optkeys + + def __item_config_cmd(id) + # maybe need to override + ['::crosshair::configure', id] + end + private :__item_config_cmd + + private :itemcget_tkstring, :itemcget, :itemcget_strict + private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo + + def confugure(w, slot, value=None) + itemconfigure(w, slot, value) + end + def confuginfo(w, slot = nil) + itemconfiginfo(w, slot) + end + def current_configinfo(w, slot = nil) + current_itemconfiginfo(w, slot) + end + def cget(w, slot) + current_itemconfiginfo(w, slot).values[0] + end +end + +module Tk::Tcllib::Crosshair + def crosshair_on(keys={}) + Tk::Tcllib::Crosshair.on(self, keys) + end + def crosshair_off + Tk::Tcllib::Crosshair.off(self) + end + def crosshair_track_on(&b) + Tk::Tcllib::Crosshair.track_on(self, &b) + end + def crosshair_track_off + Tk::Tcllib::Crosshair.track_off(self) + end + def crosshair_configure(*args) + Tk::Tcllib::Crosshair.configure(self, *args) + end + def crosshair_configinfo(slot = nil) + Tk::Tcllib::Crosshair.configinfo(self, slot) + end + def crosshair_current_configinfo(slot = nil) + Tk::Tcllib::Crosshair.current_configinfo(self, slot) + end + def crosshair_cget(slot) + Tk::Tcllib::Crosshair.cget(self, slot) + end +end diff --git a/ext/tk/lib/tkextlib/tcllib/ctext.rb b/ext/tk/lib/tkextlib/tcllib/ctext.rb index 21d6438b48..308847c233 100644 --- a/ext/tk/lib/tkextlib/tcllib/ctext.rb +++ b/ext/tk/lib/tkextlib/tcllib/ctext.rb @@ -35,7 +35,7 @@ end class Tk::Tcllib::CText TkCommandNames = ['ctext'.freeze].freeze WidgetClassName = 'Ctext'.freeze - WidgetClassNames[WidgetClassName] = self + WidgetClassNames[WidgetClassName] ||= self def create_self(keys) if keys and keys != None diff --git a/ext/tk/lib/tkextlib/tcllib/dateentry.rb b/ext/tk/lib/tkextlib/tcllib/dateentry.rb new file mode 100644 index 0000000000..77038d95bc --- /dev/null +++ b/ext/tk/lib/tkextlib/tcllib/dateentry.rb @@ -0,0 +1,62 @@ +# +# tkextlib/tcllib/dateentry.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# +# * Part of tcllib extension +# * dateentry widget +# + +require 'tk' +require 'tkextlib/tcllib.rb' + +# TkPackage.require('widget::dateentry', '0.91') +TkPackage.require('widget::dateentry') + +module Tk::Tcllib + module Widget + class Dateentry < Tk::Tile::TEntry + PACKAGE_NAME = 'widget::dateentry'.freeze + def self.package_name + PACKAGE_NAME + end + + def self.package_version + begin + TkPackage.require('widget::dateentry') + rescue + '' + end + end + end + DateEntry = Dateentry + end +end + +class Tk::Tcllib::Widget::Dateentry + TkCommandNames = ['::widget::dateentry'.freeze].freeze + + def __strval_optkeys + super() << ['dateformat'] + end + private :__strval_optkeys + + def create_self(keys) + if keys and keys != None + tk_call_without_enc(self.class::TkCommandNames[0], @path, + *hash_kv(keys, true)) + else + tk_call_without_enc(self.class::TkCommandNames[0], @path) + end + end + private :create_self + + def post + tk_send('post') + self + end + + def unpost + tk_send('unpost') + self + end +end diff --git a/ext/tk/lib/tkextlib/tcllib/diagrams.rb b/ext/tk/lib/tkextlib/tcllib/diagrams.rb new file mode 100644 index 0000000000..d24ba9d232 --- /dev/null +++ b/ext/tk/lib/tkextlib/tcllib/diagrams.rb @@ -0,0 +1,224 @@ +# +# tkextlib/tcllib/diagrams.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# +# * Part of tcllib extension +# * Draw diagrams +# + +require 'tk' +require 'tkextlib/tcllib.rb' + +# TkPackage.require('Diagrams', '0.3') +TkPackage.require('Diagrams') + +module Tk::Tcllib + module Diagrams + PACKAGE_NAME = 'Diagrams'.freeze + def self.package_name + PACKAGE_NAME + end + + def self.package_version + begin + TkPackage.require('Diagrams') + rescue + '' + end + end + end +end + +class << Tk::Tcllib::Diagrams + include TkCore + + def drawin(canvas) + tk_call('::Diagrams::drawin', canvas) + canvas + end + alias draw_in drawin + + def saveps(filename) + tk_call('::Diagrams::saveps', filename) + filename + end + alias save_ps saveps + + def direction(dir) + tk_call('::Diagrams::direction', dir) + dir + end + + def currentpos(pos) + list(tk_call('::Diagrams::currentpos', pos)) + end + alias current_pos currentpos + alias currentpos= currentpos + alias current_pos= currentpos + + def getpos(anchor, obj) + list(tk_call('::Diagrams::getpos', anchor, obj)) + end + alias get_pos getpos + + def position(x, y) + list(tk_call('::Diagrams::position', x, y)) + end + + def box(text, width=nil, height=nil) + if width || height + width = '' unless width + height = '' unless height + list(tk_call('::Diagrams::box', text, width, height)) + else + list(tk_call('::Diagrams::box', text)) + end + end + + def plaintext(text, width=nil, height=nil) + if width || height + width = '' unless width + height = '' unless height + list(tk_call('::Diagrams::plaintext', text, width, height)) + else + list(tk_call('::Diagrams::plaintext', text)) + end + end + + def circle(text, radius=nil) + if radius + list(tk_call('::Diagrams::circle', text, radius)) + else + list(tk_call('::Diagrams::circle', text)) + end + end + + def slanted(text, width=nil, height=nil, angle=nil) + if width || height || angle + width = '' unless width + height = '' unless height + if angle + list(tk_call('::Diagrams::slanted', text, width, height, angle)) + else + list(tk_call('::Diagrams::slanted', text, width, height)) + end + else + list(tk_call('::Diagrams::slanted', text)) + end + end + + def diamond(text, width=nil, height=nil) + if width || height + width = '' unless width + height = '' unless height + list(tk_call('::Diagrams::diamond', text, width, height)) + else + list(tk_call('::Diagrams::diamond', text)) + end + end + + def drum(text, width=nil, height=nil) + if width || height + width = '' unless width + height = '' unless height + list(tk_call('::Diagrams::drum', text, width, height)) + else + list(tk_call('::Diagrams::drum', text)) + end + end + + def arrow(text=nil, length=nil, head=nil) + if length || head + text = '' unless text + length = '' unless length + list(tk_call('::Diagrams::arrow', text, length, head)) + else + if text + list(tk_call('::Diagrams::arrow', text)) + else + list(tk_call('::Diagrams::arrow')) + end + end + end + + def line(*args) + ary = [] + args.each{|arg| + if arg.kind_of?(Array) && arg.length == 2 # [length, angle] + ary.concat arg + else # ["POSITION", x, y] or length or angle + ary << arg + end + } + list(tk_call('::Diagrams::line', *ary)) + end + + def bracket(dir, dist, from_pos, to_pos) + list(tk_call('::Diagrams::bracket', dir, dist, from_pos, to_pos)) + end + + def attach(anchor=None) + tk_call('::Diagrams::attach', anchor) + end + + def color(name=None) + tk_call('::Diagrams::color', name) + end + + def fillcolor(name=None) + tk_call('::Diagrams::fillcolor', name) + end + + def textcolor(name=None) + tk_call('::Diagrams::textcolor', name) + end + + def usegap(mode=None) + bool(tk_call('::Diagrams::usegap', mode)) + end + alias use_gap usegap + + def xgap(val=None) + number(tk_call('::Diagrams::xgap', val)) + end + + def ygap(val=None) + number(tk_call('::Diagrams::ygap', val)) + end + + def textfont(fnt=None) + tk_call('::Diagrams::textfont', fnt) + end + + def linewidth(pixels=None) + number(tk_call('::Diagrams::linewidth', pixels)) + end + + def linestyle(style=None) + tk_call('::Diagrams::linestyle', style) + end + + def pushstate + tk_call('::Diagrams::pushstate') + end + alias push_state pushstate + + def popstate + tk_call('::Diagrams::popstate') + end + alias pop_state popstate + + def computepos + list(tk_call('::Diagrams::computepos')) + end + alias compute_pos computepos + + def boxcoords(x1, y1, x2, y2) + list(tk_call('::Diagrams::boxcoords', x1, y1, x2, y2)) + end + + def moveobject(obj) + list(tk_call('::Diagrams::moveobject', obj)) + end + alias move_object moveobject +end diff --git a/ext/tk/lib/tkextlib/tcllib/getstring.rb b/ext/tk/lib/tkextlib/tcllib/getstring.rb index ab45c9b1ea..48711d3b66 100644 --- a/ext/tk/lib/tkextlib/tcllib/getstring.rb +++ b/ext/tk/lib/tkextlib/tcllib/getstring.rb @@ -34,7 +34,7 @@ end class Tk::Tcllib::GetString_Dialog TkCommandNames = ['::getstring::tk_getString'.freeze].freeze WidgetClassName = 'TkSDialog'.freeze - WidgetClassNames[WidgetClassName] = self + WidgetClassNames[WidgetClassName] ||= self def self.show(*args) dialog = self.new(*args) diff --git a/ext/tk/lib/tkextlib/tcllib/ico.rb b/ext/tk/lib/tkextlib/tcllib/ico.rb index 538f7b5408..36a32c6b09 100644 --- a/ext/tk/lib/tkextlib/tcllib/ico.rb +++ b/ext/tk/lib/tkextlib/tcllib/ico.rb @@ -8,7 +8,7 @@ require 'tk' require 'tk/image' -require 'tkextlib/tcllib.rb' +#require 'tkextlib/tcllib.rb' # TkPackage.require('ico', '0.3') TkPackage.require('ico') @@ -38,9 +38,39 @@ class Tk::Tcllib::ICO *hash_kv(keys, true))) end + def self.icons(file, keys=nil) + tk_split_simplelist(tk_call_without_enc('::ico::icons', file, + *hash_kv(keys, true))).map{|elem| + num_or_str(elem) + } + end + + def self.get_members(file, name, keys=nil) + tk_split_simplelist(tk_call_without_enc('::ico::getMembers', file, name, + *hash_kv(keys, true))).map{|elem| + name, width, height, bpp = tk_split_simplelist(elem) + [name, number(width), number(height), number(bpp)] + } + end + def self.get(file, index, keys=nil) tk_call_without_enc('::ico::getIcon', file, index, *hash_kv(keys, true)) end + def self.get_icon(*args) + get(*args) + end + + def self.get_by_name(file, name, keys=nil) + tk_call_without_enc('::ico::getIconByName', file, name, + *hash_kv(keys, true)) + end + def self.get_icon_by_name(*args) + get_by_name(*args) + end + + def self.get_fileicon(file, keys=nil) + tk_call_without_enc('::ico::getFileIcon', file, *hash_kv(keys, true)) + end def self.get_image(file, index, keys={}) keys = _symbolkey2str(keys) diff --git a/ext/tk/lib/tkextlib/tcllib/ip_entry.rb b/ext/tk/lib/tkextlib/tcllib/ip_entry.rb index a8a33f1cad..e5e0f8d42d 100644 --- a/ext/tk/lib/tkextlib/tcllib/ip_entry.rb +++ b/ext/tk/lib/tkextlib/tcllib/ip_entry.rb @@ -33,13 +33,18 @@ module Tk end end IPEntry = IP_Entry + + class IP_Entry6 < IP_Entry + end + IPEntry6 = IP_Entry6 + IP6_Entry = IP_Entry6 end end class Tk::Tcllib::IP_Entry TkCommandNames = ['::ipentry::ipentry'.freeze].freeze WidgetClassName = 'IPEntry'.freeze - WidgetClassNames[WidgetClassName] = self + WidgetClassNames[WidgetClassName] ||= self def create_self(keys) if keys and keys != None @@ -64,3 +69,7 @@ class Tk::Tcllib::IP_Entry tk_send_without_enc('insert', array2tk_list(ip.flatten)) end end + +class Tk::Tcllib::IP_Entry6 < Tk::Tcllib::IP_Entry + TkCommandNames = ['::ipentry::ipentry6'.freeze].freeze +end diff --git a/ext/tk/lib/tkextlib/tcllib/khim.rb b/ext/tk/lib/tkextlib/tcllib/khim.rb new file mode 100644 index 0000000000..00acff91d9 --- /dev/null +++ b/ext/tk/lib/tkextlib/tcllib/khim.rb @@ -0,0 +1,68 @@ +# +# tkextlib/tcllib/khim.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# +# * Part of tcllib extension +# * Kevin's Hacky Input Method +# + +require 'tk' +require 'tkextlib/tcllib.rb' + +# TkPackage.require('khim', '1.0') +TkPackage.require('khim') + +module Tk::Tcllib + class KHIM < TkToplevel + PACKAGE_NAME = 'khim'.freeze + def self.package_name + PACKAGE_NAME + end + + def self.package_version + begin + TkPackage.require('khim') + rescue + '' + end + end + end +end + +class Tk::Tcllib::KHIM + TkCommandNames = ['::khim::getOptions'.freeze].freeze + + def self.get_options(parent='') + path = parent + '.tcllib_widget_khim_dialog' + self.new(:widgetname => path) + end + + def self.get_config #=> cmd_string + Tk.tk_call_without_enc('::khim::getConfig') + end + + def self.set_config(*args) + if args.length == 1 + # cmd_string generated by + #Tk.ip_eval_without_enc(cmd_string) + Tk.ip_eval(cmd_string) + else + # args for setConfig command + #Tk.tk_call_without_enc('::khim::setConfig', *args) + Tk.tk_call('::khim::setConfig', *args) + end + end + + def self.showHelp + Tk::Tcllib::KHIM::Help.new + end + + def create_self(keys=None) + @db_class = @classname = nil + super(None) # ignore keys + end +end + +class Tk::Tcllib::KHIM::Help < TkToplevel + TkCommandNames = ['::khim::showHelp'.freeze].freeze +end diff --git a/ext/tk/lib/tkextlib/tcllib/menuentry.rb b/ext/tk/lib/tkextlib/tcllib/menuentry.rb new file mode 100644 index 0000000000..f1eb2f295c --- /dev/null +++ b/ext/tk/lib/tkextlib/tcllib/menuentry.rb @@ -0,0 +1,47 @@ +# +# tkextlib/tcllib/menuentry.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# +# * Part of tcllib extension +# * menuentry widget +# + +require 'tk' +require 'tkextlib/tcllib.rb' + +# TkPackage.require('widget::menuentry', '1.0') +TkPackage.require('widget::menuentry') + +module Tk::Tcllib + module Widget + class Menuentry < Tk::Tile::TEntry + PACKAGE_NAME = 'widget::menuentry'.freeze + def self.package_name + PACKAGE_NAME + end + + def self.package_version + begin + TkPackage.require('widget::menuentry') + rescue + '' + end + end + end + MenuEntry = Menuentry + end +end + +class Tk::Tcllib::Widget::Menuentry + TkCommandNames = ['::widget::menuentry'.freeze].freeze + + def create_self(keys) + if keys and keys != None + tk_call_without_enc(self.class::TkCommandNames[0], @path, + *hash_kv(keys, true)) + else + tk_call_without_enc(self.class::TkCommandNames[0], @path) + end + end + private :create_self +end diff --git a/ext/tk/lib/tkextlib/tcllib/ntext.rb b/ext/tk/lib/tkextlib/tcllib/ntext.rb new file mode 100644 index 0000000000..7888ed4871 --- /dev/null +++ b/ext/tk/lib/tkextlib/tcllib/ntext.rb @@ -0,0 +1,146 @@ +# +# tkextlib/tcllib/ntext.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# +# * Part of tcllib extension +# * Ntext bindtag +# + +require 'tk' +require 'tkextlib/tcllib.rb' + +# TkPackage.require('ntext', '0.81') +TkPackage.require('ntext') + +module Tk::Tcllib + Ntext = TkBindTag.new_by_name('Ntext') +end + +# variables +Tk::Tcllib::Ntext.instance_eval{ + # boolean + @classicAnchor = TkVarAccess.new('::ntext::classicAnchor') + @classicExtras = TkVarAccess.new('::ntext::classicExtras') + @classicMouseSelect = TkVarAccess.new('::ntext::classicMouseSelect') + @classicWordBreak = TkVarAccess.new('::ntext::classicWordBreak') + @classicWrap = TkVarAccess.new('::ntext::classicWrap') + @overwrite = TkVarAccess.new('::ntext::overwrite') + + # regexp + @newWrapRegexp = TkVarAccess.new('::ntext::newWrapRegexp') + + # variables (advanced use) + @tcl_match_wordBreakAfter = TkVarAccess.new('::ntext::tcl_match_wordBreakAfter') + @tcl_match_wordBreakBefore = TkVarAccess.new('::ntext::tcl_match_wordBreakBefore') + @tcl_match_endOfWord = TkVarAccess.new('::ntext::tcl_match_endOfWord') + @tcl_match_startOfNextWord = TkVarAccess.new('::ntext::tcl_match_startOfNextWord') + @tcl_match_startOfPreviousWord = TkVarAccess.new('::ntext::tcl_match_startOfPreviousWord') +} + +class << Tk::Tcllib::Ntext + def wrapIndent(txt, *args) + TK.tk_call('::next::wrapIndent', txt, *args) + end + + def initializeMatchPatterns + TK.tk_call('::next::initializeMatchPatterns') + self + end + + def createMatchPatterns(*args) + TK.tk_call('::next::createMatchPatterns', *args) + self + end + + # functions (advanced use) + #ntext::new_wordBreakAfter + #ntext::new_wordBreakBefore + #ntext::new_endOfWord + #ntext::new_startOfNextWord + #ntext::new_startOfPreviousWord + + # accessor + def classicAnchor + @classicAnchor.bool + end + def classicAnchor=(mode) + @classicAnchor.bool = mode + end + + def classicExtras + @classicExtras.bool + end + def classicExtras=(mode) + @classicExtras.bool = mode + end + + def classicMouseSelect + @classicMouseSelect.bool + end + def classicMouseSelect=(mode) + @classicMouseSelect.bool = mode + end + + def classicWordBreak + @classicWordBreak.bool + end + def classicWordBreak=(mode) + @classicWordBreak.bool = mode + end + + def classicWrap + @classicWrap.bool + end + def classicWrap=(mode) + @classicWrap.bool = mode + end + + def overwrite + @overwrite.bool + end + def overwrite=(mode) + @classic.bool = mode + end + + def newWrapRegexp + @newWrapRegexp.value + end + def newWrapRegexp=(val) + @newWrapRegexp.value = val + end + + def tcl_match_wordBreakAfter + @tcl_match_wordBreakAfter.value + end + def tcl_match_wordBreakAfter=(val) + @tcl_match_wordBreakAfter.value = val + end + + def tcl_match_wordBreakBefore + @tcl_match_wordBreakBefore.value + end + def tcl_match_wordBreakBefore=(val) + @tcl_match_wordBreakBefore.value = val + end + + def tcl_match_endOfWord + @tcl_match_endOfWord.value + end + def tcl_match_endOfWord=(val) + @tcl_match_endOfWord.value = val + end + + def tcl_match_startOfNextWord + @tcl_match_startOfNextWord.value + end + def tcl_match_startOfNextWord=(val) + @tcl_match_startOfNextWord.value = val + end + + def tcl_match_startOfPreviousWord + @tcl_match_startOfPreviousWord.value + end + def tcl_match_startOfPreviousWord=(val) + @tcl_match_startOfPreviousWord.value = val + end +end diff --git a/ext/tk/lib/tkextlib/tcllib/panelframe.rb b/ext/tk/lib/tkextlib/tcllib/panelframe.rb index 9086ad78d2..020c51cbd1 100644 --- a/ext/tk/lib/tkextlib/tcllib/panelframe.rb +++ b/ext/tk/lib/tkextlib/tcllib/panelframe.rb @@ -60,11 +60,17 @@ class Tk::Tcllib::Widget::PanelFrame def remove(*wins) tk_send('remove', *wins) + self end def remove_destroy(*wins) tk_send('remove', '-destroy', *wins) + self + end + + def delete(*wins) + tk_send('delete', *wins) + self end - alias delete remove_destroy def items simplelist(tk_send('items')).collect!{|w| window(w)} diff --git a/ext/tk/lib/tkextlib/tcllib/plotchart.rb b/ext/tk/lib/tkextlib/tcllib/plotchart.rb index 25a574efbc..6b7a526b75 100644 --- a/ext/tk/lib/tkextlib/tcllib/plotchart.rb +++ b/ext/tk/lib/tkextlib/tcllib/plotchart.rb @@ -62,6 +62,7 @@ require 'tkextlib/tcllib.rb' # TkPackage.require('Plotchart', '0.9') # TkPackage.require('Plotchart', '1.1') +# TkPackage.require('Plotchart', '1.6.3') TkPackage.require('Plotchart') module Tk @@ -109,6 +110,29 @@ module Tk::Tcllib::Plotchart list(tk_call_without_enc('::Plotchart::coords3DToPixel', w.path, x, y, z)) end + def self.plotconfig(*args) + case args.length + when 0, 1, 2 + # 0: (no args) --> list of chat types + # 1: charttype --> list of components + # 2: charttype, component --> list of properties + simplelist(tk_call('::Plotchart::plotconfig', *args)) + when 3 + # 3: charttype, component, property --> current value + tk_call('::Plotchart::plotconfig', *args) + else + # 4: charttype, component, property, value : set new value + # 5+: Error on Tcl/Tk + tk_call('::Plotchart::plotconfig', *args) + nil + end + end + + def self.plotpack(w, dir, *plots) + tk_call_without_enc('::Plotchart::plotpack', w.path, dir, *plots) + w + end + def self.polar_coordinates(w, radmax) tk_call_without_enc('::Plotchart::polarCoordinates', w.path, radmax) end @@ -157,8 +181,7 @@ module Tk::Tcllib::Plotchart if key.kind_of?(Hash) tk_call_without_enc(@chart, 'xconfig', *hash_kv(key, true)) else - tk_call_without_enc(@chart, 'xconfig', - "-#{key}", _get_eval_enc_str(value)) + tk_call(@chart, 'xconfig', "-#{key}",value) end self end @@ -167,13 +190,86 @@ module Tk::Tcllib::Plotchart if key.kind_of?(Hash) tk_call_without_enc(@chart, 'yconfig', *hash_kv(key, true)) else - tk_call_without_enc(@chart, 'yconfig', - "-#{key}", _get_eval_enc_str(value)) + tk_call(@chart, 'yconfig', "-#{key}", value) + end + self + end + + def background(part, color_or_image, dir) + tk_call_without_enc(@chart, 'background', + part, color_or_image, dir) + self + end + + def xticklines(color=None) + tk_call(@chart, 'xticklines', color) + self + end + + def yticklines(color=None) + tk_call(@chart, 'yticklines', color) + self + end + + def legendconfig(key, value=None) + if key.kind_of?(Hash) + tk_call_without_enc(@chart, 'legendconfig', *hash_kv(key, true)) + else + tk_call(@chart, 'legendconfig', "-#{key}", value) + end + self + end + + def legend(series, text) + tk_call_without_enc(@chart, 'legend', + _get_eval_enc_str(series), _get_eval_enc_str(text)) + self + end + + def balloon(*args) # args => (x, y, text, dir) or ([x, y], text, dir) + if args[0].kind_of?(Array) + # args => ([x, y], text, dir) + x, y = args.shift + else + # args => (x, y, text, dir) + x = args.shift + y = args.shift end + + text, dir = args + + tk_call_without_enc(@chart, 'balloon', x, y, + _get_eval_enc_str(text), dir) + self + end + + def balloonconfig(key, value=None) + if key.kind_of?(Hash) + tk_call_without_enc(@chart, 'balloonconfig', *hash_kv(key, true)) + else + tk_call(@chart, 'balloonconfig', "-#{key}", value) + end + end + + def plaintext(*args) # args => (x, y, text, dir) or ([x, y], text, dir) + if args[0].kind_of?(Array) + # args => ([x, y], text, dir) + x, y = args.shift + else + # args => (x, y, text, dir) + x = args.shift + y = args.shift + end + + text, dir = args + + tk_call_without_enc(@chart, 'plaintext', x, y, + _get_eval_enc_str(text), dir) self end ############################ + def view_port(*args) # args := pxmin, pymin, pxmax, pymax tk_call_without_enc('::Plotchart::viewPort', @path, *(args.flatten)) self @@ -200,6 +296,11 @@ module Tk::Tcllib::Plotchart list(tk_call_without_enc('::Plotchart::coords3DToPixel', @path, x, y, z)) end + def plotpack(dir, *plots) + tk_call_without_enc('::Plotchart::plotpack', @path, dir, *plots) + self + end + def polar_coordinates(radmax) tk_call_without_enc('::Plotchart::polarCoordinates', @path, radmax) self @@ -281,27 +382,27 @@ module Tk::Tcllib::Plotchart vals = array2tk_list(vals) if vals.kind_of?(Array) clss = array2tk_list(clss) if clss.kind_of?(Array) - tk_call_without_enc(@chart, 'contourlines', xcrd, ycrd, vals, clss) + tk_call(@chart, 'contourlines', xcrd, ycrd, vals, clss) self end - def contourfill(xcrd, ycrd, vals, klasses=None) + def contourfill(xcrd, ycrd, vals, clss=None) xcrd = array2tk_list(xcrd) if xcrd.kind_of?(Array) ycrd = array2tk_list(ycrd) if ycrd.kind_of?(Array) vals = array2tk_list(vals) if vals.kind_of?(Array) clss = array2tk_list(clss) if clss.kind_of?(Array) - tk_call_without_enc(@chart, 'contourfill', xcrd, ycrd, vals, clss) + tk_call(@chart, 'contourfill', xcrd, ycrd, vals, clss) self end - def contourbox(xcrd, ycrd, vals, klasses=None) + def contourbox(xcrd, ycrd, vals, clss=None) xcrd = array2tk_list(xcrd) if xcrd.kind_of?(Array) ycrd = array2tk_list(ycrd) if ycrd.kind_of?(Array) vals = array2tk_list(vals) if vals.kind_of?(Array) clss = array2tk_list(clss) if clss.kind_of?(Array) - tk_call_without_enc(@chart, 'contourbox', xcrd, ycrd, vals, clss) + tk_call(@chart, 'contourbox', xcrd, ycrd, vals, clss) self end @@ -324,10 +425,70 @@ module Tk::Tcllib::Plotchart if key.kind_of?(Hash) tk_call_without_enc(@chart, 'dataconfig', series, *hash_kv(key, true)) else - tk_call_without_enc(@chart, 'dataconfig', series, - "-#{key}", _get_eval_enc_str(value)) + tk_call(@chart, 'dataconfig', series, "-#{key}", value) end end + + def rescale(xscale, yscale) # xscale|yscale => [newmin, newmax, newstep] + tk_call_without_enc(@chart, 'rescale', xscale, yscale) + self + end + + def trend(series, xcrd, ycrd) + tk_call_without_enc(@chart, 'trend', + _get_eval_enc_str(series), xcrd, ycrd) + self + end + + def rchart(series, xcrd, ycrd) + tk_call_without_enc(@chart, 'rchart', + _get_eval_enc_str(series), xcrd, ycrd) + self + end + + def interval(series, xcrd, ymin, ymax, ycenter=None) + tk_call(@chart, 'interval', series, xcrd, ymin, ymax, ycenter) + self + end + + def box_and_whiskers(series, xcrd, ycrd) + tk_call_without_enc(@chart, 'box-and-whiskers', + _get_eval_enc_str(series), xcrd, ycrd) + self + end + alias box_whiskers box_and_whiskers + + def vectorconfig(series, key, value=None) + if key.kind_of?(Hash) + tk_call_without_enc(@chart, 'vectorconfig', + _get_eval_enc_str(series), *hash_kv(key, true)) + else + tk_call(@chart, 'vectorconfig', series, "-#{key}", value) + end + self + end + + def vector(series, xcrd, ycrd, ucmp, vcmp) + tk_call_without_enc(@chart, 'vector', _get_eval_enc_str(series), + xcrd, ycrd, ucmp, vcmp) + self + end + + def dotconfig(series, key, value=None) + if key.kind_of?(Hash) + tk_call_without_enc(@chart, 'dotconfig', + _get_eval_enc_str(series), *hash_kv(key, true)) + else + tk_call(@chart, 'dotconfig', series, "-#{key}", value) + end + self + end + + def dot(series, xcrd, ycrd, value) + tk_call_without_enc(@chart, 'dot', _get_eval_enc_str(series), + xcrd, ycrd, value) + self + end end ############################ @@ -339,6 +500,30 @@ module Tk::Tcllib::Plotchart end ############################ + class TXPlot < XYPlot + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::createTXPlot'.freeze + ].freeze + end + + ############################ + class XLogYPlot < XYPlot + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::createXLogYPlot'.freeze + ].freeze + end + + ############################ + class Histogram < XYPlot + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::createHistgram'.freeze + ].freeze + end + + ############################ class PolarPlot < Tk::Canvas include ChartMethod @@ -389,10 +574,10 @@ module Tk::Tcllib::Plotchart def dataconfig(series, key, value=None) if key.kind_of?(Hash) - tk_call_without_enc(@chart, 'dataconfig', series, *hash_kv(key, true)) + tk_call_without_enc(@chart, 'dataconfig', _get_eval_enc_str(series), + *hash_kv(key, true)) else - tk_call_without_enc(@chart, 'dataconfig', series, - "-#{key}", _get_eval_enc_str(value)) + tk_call(@chart, 'dataconfig', series, "-#{key}", value) end end end @@ -541,6 +726,15 @@ module Tk::Tcllib::Plotchart self end + def plot_line(dat, color) + # dat has to be provided as a 2 level array. + # 1st level contains rows, drawn in y-direction, + # and each row is an array whose elements are drawn in x-direction, + # for the columns. + tk_call_without_enc(@chart, 'plotline', dat, color) + self + end + def plot_data(dat) # dat has to be provided as a 2 level array. # 1st level contains rows, drawn in y-direction, @@ -550,6 +744,15 @@ module Tk::Tcllib::Plotchart self end + def zconfig(key, value=None) + if key.kind_of?(Hash) + tk_call_without_enc(@chart, 'zconfig', *hash_kv(key, true)) + else + tk_call(@chart, 'zconfig', "-#{key}", value) + end + self + end + def colour(fill, border) # configure the colours to use for polygon borders and inner area tk_call_without_enc(@chart, 'colour', fill, border) @@ -561,6 +764,132 @@ module Tk::Tcllib::Plotchart end ############################ + class Barchart3D < Tk::Canvas + include ChartMethod + + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::create3DBarchart'.freeze + ].freeze + + def initialize(*args) # args := ([parent,] yaxis, nobars [, keys]) + # yaxis := Array of [minimum, maximum, stepsize] + # nobars := number of bars + if args[0].kind_of?(Array) + @yaxis = args.shift + @nobars = args.shift + + super(*args) # create canvas widget + else + parent = args.shift + + @yaxis = args.shift + @nobars = args.shift + + if parent.kind_of?(Tk::Canvas) + @path = parent.path + else + super(parent, *args) # create canvas widget + end + end + + @chart = _create_chart + end + + def _create_chart + p self.class::TkCommandNames[1] if $DEBUG + tk_call_without_enc(self.class::TkCommandNames[1], @path, + array2tk_list(@yaxis), @nobars) + end + private :_create_chart + + def plot(label, yvalue, color) + tk_call_without_enc(@chart, 'plot', _get_eval_enc_str(label), + _get_eval_enc_str(yvalue), color) + self + end + + def config(key, value=None) + if key.kind_of?(Hash) + tk_call_without_enc(@chart, 'config', *hash_kv(key, true)) + else + tk_call(@chart, 'config', "-#{key}", value) + end + self + end + end + + ############################ + class RibbonChart3D < Tk::Canvas + include ChartMethod + + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::create3DRibbonChart'.freeze + ].freeze + + def initialize(*args) # args := ([parent,] names, yaxis, zaxis [, keys]) + # names := Array of the series + # yaxis := Array of [minimum, maximum, stepsize] + # zaxis := Array of [minimum, maximum, stepsize] + if args[0].kind_of?(Array) + @names = args.shift + @yaxis = args.shift + @zaxis = args.shift + + super(*args) # create canvas widget + else + parent = args.shift + + @names = args.shift + @yaxis = args.shift + @zaxis = args.shift + + if parent.kind_of?(Tk::Canvas) + @path = parent.path + else + super(parent, *args) # create canvas widget + end + end + + @chart = _create_chart + end + + def _create_chart + p self.class::TkCommandNames[1] if $DEBUG + tk_call_without_enc(self.class::TkCommandNames[1], @path, + array2tk_list(@names), + array2tk_list(@yaxis), + array2tk_list(@zaxis)) + end + private :_create_chart + + def line(*args) # xypairs, color + color = args.pop # last argument is a color + xypairs = TkComm.slice_ary(args.flatten, 2) # regenerate xypairs + tk_call_without_enc(@chart, 'line', xypairs, color) + self + end + + def area(*args) # xypairs, color + color = args.pop # last argument is a color + xypairs = TkComm.slice_ary(args.flatten, 2) # regenerate xypairs + tk_call_without_enc(@chart, 'area', xypairs, color) + self + end + + def zconfig(key, value=None) + if key.kind_of?(Hash) + tk_call_without_enc(@chart, 'zconfig', *hash_kv(key, true)) + else + tk_call(@chart, 'zconfig',"-#{key}", value) + end + self + end + end + + + ############################ class Piechart < Tk::Canvas include ChartMethod @@ -586,9 +915,76 @@ module Tk::Tcllib::Plotchart private :_create_chart def plot(*dat) # argument is a list of [label, value] - tk_call_without_enc(@chart, 'plot', dat.flatten) + tk_call(@chart, 'plot', dat.flatten) + self + end + + def colours(*list) + tk_call_without_enc(@chart, 'colours', *list) self end + alias colors colours + end + + + ############################ + class Radialchart < Tk::Canvas + include ChartMethod + + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::createRadialchart'.freeze + ].freeze + + def initialize(*args) # args := ([parent,] names, scale, style [, keys]) + # radius_data := Array of [maximum_radius, stepsize] + if args[0].kind_of?(Array) + @names = args.shift + @scale = args.shift + @style = args.shift + + super(*args) # create canvas widget + else + parent = args.shift + + @names = args.shift + @scale = args.shift + @style = args.shift + + if parent.kind_of?(Tk::Canvas) + @path = parent.path + else + super(parent, *args) # create canvas widget + end + end + + @chart = _create_chart + end + + def _create_chart + p self.class::TkCommandNames[1] if $DEBUG + tk_call_without_enc(self.class::TkCommandNames[1], @path, + array2tk_list(@names), @scale, @style) + end + private :_create_chart + + def __destroy_hook__ + Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.mutex.synchronize{ + Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.delete(@path) + } + end + + def plot(data, color, thickness) + tk_call_without_enc(@chart, 'plot', _get_eval_enc_str(data), + color, thickness) + self + end + + def colours(*list) + tk_call_without_enc(@chart, 'colours', *list) + self + end + alias colors colours end ############################ @@ -655,13 +1051,13 @@ module Tk::Tcllib::Plotchart end def plot(series, dat, col=None) - tk_call_without_enc(@chart, 'plot', series, dat, col) + tk_call(@chart, 'plot', series, dat, col) self end def colours(*cols) # set the colours to be used - tk_call_without_enc(@chart, 'colours', *cols) + tk_call(@chart, 'colours', *cols) self end alias colour colours @@ -678,6 +1074,102 @@ module Tk::Tcllib::Plotchart end ############################ + class Boxplot < Tk::Canvas + include ChartMethod + + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::createBoxplot'.freeze + ].freeze + + def initialize(*args) # args := ([parent,] xaxis, ylabels [, keys]) + # xaxis := Array of [minimum, maximum, stepsize] + # yaxis := List of labels for the y-axis + if args[0].kind_of?(Array) + @xaxis = args.shift + @ylabels = args.shift + + super(*args) # create canvas widget + else + parent = args.shift + + @xaxis = args.shift + @ylabels = args.shift + + if parent.kind_of?(Tk::Canvas) + @path = parent.path + else + super(parent, *args) # create canvas widget + end + end + + @chart = _create_chart + end + + def _create_chart + p self.class::TkCommandNames[1] if $DEBUG + tk_call_without_enc(self.class::TkCommandNames[1], @path, + array2tk_list(@xaxis), array2tk_list(@ylabels)) + end + private :_create_chart + + def __destroy_hook__ + Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.mutex.synchronize{ + Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.delete(@path) + } + end + + def plot(label, *values) + tk_call(@chart, 'plot', label, values.flatten) + self + end + end + + ############################ + class RightAxis < Tk::Canvas + include ChartMethod + + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::createRightAxis'.freeze + ].freeze + + def initialize(*args) # args := ([parent,] yaxis [, keys]) + # yaxis := Array of [minimum, maximum, stepsize] + if args[0].kind_of?(Array) + @yaxis = args.shift + + super(*args) # create canvas widget + else + parent = args.shift + + @yaxis = args.shift + + if parent.kind_of?(Tk::Canvas) + @path = parent.path + else + super(parent, *args) # create canvas widget + end + end + + @chart = _create_chart + end + + def _create_chart + p self.class::TkCommandNames[1] if $DEBUG + tk_call_without_enc(self.class::TkCommandNames[1], @path, + array2tk_list(@yaxis)) + end + private :_create_chart + + def __destroy_hook__ + Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.mutex.synchronize{ + Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.delete(@path) + } + end + end + + ############################ class Timechart < Tk::Canvas include ChartMethod @@ -723,46 +1215,60 @@ module Tk::Tcllib::Plotchart private :_create_chart def period(txt, time_begin, time_end, col=None) - tk_call_without_enc(@chart, 'period', txt, time_begin, time_end, col) + tk_call(@chart, 'period', txt, time_begin, time_end, col) self end def milestone(txt, time, col=None) - tk_call_without_enc(@chart, 'milestone', txt, time, col) + tk_call(@chart, 'milestone', txt, time, col) self end def vertline(txt, time) - tk_call_without_enc(@chart, 'vertline', txt, time) + tk_call(@chart, 'vertline', txt, time) + self + end + + def hscroll=(scr) + tk_call_without_enc(@chart, 'hscroll', scr) + scr + end + def hscroll(scr) + tk_call_without_enc(@chart, 'hscroll', scr) + self + end + + def vscroll=(scr) + tk_call_without_enc(@chart, 'vscroll', scr) + scr + end + def vscroll(scr) + tk_call_without_enc(@chart, 'vscroll', scr) self end end ############################ - class Gnattchart < Tk::Canvas + class Ganttchart < Tk::Canvas include ChartMethod TkCommandNames = [ 'canvas'.freeze, - '::Plotchart::createGnattchart'.freeze + '::Plotchart::createGanttchart'.freeze ].freeze def initialize(*args) # args := ([parent,] time_begin, time_end, items [, text_width] [, keys]) # time_begin := String of time format (e.g. "1 january 2004") # time_end := String of time format (e.g. "1 january 2004") - # items := Expected/maximum number of items - # ( This determines the vertical spacing. ) + # args := Expected/maximum number of items + # ( This determines the vertical spacing. ), + # Expected/maximum width of items, + # Option Hash ( { key=>value, ... } ) if args[0].kind_of?(String) @time_begin = args.shift @time_end = args.shift - @items = args.shift - - if args[0].kind_of?(Fixnum) - @text_width = args.shift - else - @text_width = None - end + @args = args super(*args) # create canvas widget else @@ -770,13 +1276,7 @@ module Tk::Tcllib::Plotchart @time_begin = args.shift @time_end = args.shift - @items = args.shift - - if args[0].kind_of?(Fixnum) - @text_width = args.shift - else - @text_width = None - end + @args = args if parent.kind_of?(Tk::Canvas) @path = parent.path @@ -790,25 +1290,25 @@ module Tk::Tcllib::Plotchart def _create_chart p self.class::TkCommandNames[1] if $DEBUG - tk_call_without_enc(self.class::TkCommandNames[1], @path, - @time_begin, @time_end, @items, @text_width) + tk_call(self.class::TkCommandNames[1], @path, + @time_begin, @time_end, *args) end private :_create_chart def task(txt, time_begin, time_end, completed=0.0) - list(tk_call_without_enc(@chart, 'task', txt, time_begin, time_end, - completed)).collect!{|id| + list(tk_call(@chart, 'task', txt, time_begin, time_end, + completed)).collect!{|id| TkcItem.id2obj(self, id) } end def milestone(txt, time, col=None) - tk_call_without_enc(@chart, 'milestone', txt, time, col) + tk_call(@chart, 'milestone', txt, time, col) self end def vertline(txt, time) - tk_call_without_enc(@chart, 'vertline', txt, time) + tk_call(@chart, 'vertline', txt, time) self end @@ -816,23 +1316,41 @@ module Tk::Tcllib::Plotchart from_task = array2tk_list(from_task) if from_task.kind_of?(Array) to_task = array2tk_list(to_task) if to_task.kind_of?(Array) - tk_call_without_enc(@chart, 'connect', from_task, to_task) + tk_call(@chart, 'connect', from_task, to_task) self end def summary(txt, tasks) tasks = array2tk_list(tasks) if tasks.kind_of?(Array) - tk_call_without_enc(@chart, 'summary', tasks) + tk_call(@chart, 'summary', tasks) self end def color_of_part(keyword, newcolor) - tk_call_without_enc(@chart, 'color', keyword, newcolor) + tk_call(@chart, 'color', keyword, newcolor) self end def font_of_part(keyword, newfont) - tk_call_without_enc(@chart, 'font', keyword, newfont) + tk_call(@chart, 'font', keyword, newfont) + self + end + + def hscroll=(scr) + tk_call_without_enc(@chart, 'hscroll', scr) + scr + end + def hscroll(scr) + tk_call_without_enc(@chart, 'hscroll', scr) + self + end + + def vscroll=(scr) + tk_call_without_enc(@chart, 'vscroll', scr) + scr + end + def vscroll(scr) + tk_call_without_enc(@chart, 'vscroll', scr) self end end @@ -841,7 +1359,7 @@ module Tk::Tcllib::Plotchart class PlotSeries < TkObject SeriesID_TBL = TkCore::INTERP.create_table - (Series_ID = ['series'.freeze, '00000'.taint]).instance_eval{ + (Series_ID = ['series'.freeze, TkUtil.untrust('00000')]).instance_eval{ @mutex = Mutex.new def mutex; @mutex; end freeze diff --git a/ext/tk/lib/tkextlib/tcllib/scrolledwindow.rb b/ext/tk/lib/tkextlib/tcllib/scrolledwindow.rb new file mode 100644 index 0000000000..c9488b4686 --- /dev/null +++ b/ext/tk/lib/tkextlib/tcllib/scrolledwindow.rb @@ -0,0 +1,57 @@ +# +# tkextlib/tcllib/scrolledwindow.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# +# * Part of tcllib extension +# * scrolledwindow widget +# + +require 'tk' +require 'tkextlib/tcllib.rb' + +# TkPackage.require('widget::scrolledwindow', '1.2') +TkPackage.require('widget::scrolledwindow') + +module Tk::Tcllib + module Widget + class Scrolledwindow < Tk::Tile::TFrame + PACKAGE_NAME = 'widget::scrolledwindow'.freeze + def self.package_name + PACKAGE_NAME + end + + def self.package_version + begin + TkPackage.require('widget::scrolledwindow') + rescue + '' + end + end + end + ScrolledWindow = Scrolledwindow + end +end + +class Tk::Tcllib::Widget::ScrolledWindow + TkCommandNames = ['::widget::scrolledwindow'.freeze].freeze + + def create_self(keys) + if keys and keys != None + tk_call_without_enc(self.class::TkCommandNames[0], @path, + *hash_kv(keys, true)) + else + tk_call_without_enc(self.class::TkCommandNames[0], @path) + end + end + private :create_self + + def getframe + window(tk_send_without_enc('getframe')) + end + alias get_frame getframe + + def setwidget(w) + window(tk_send_without_enc('setwidget', w)) + end + alias set_widget setwidget +end diff --git a/ext/tk/lib/tkextlib/tcllib/statusbar.rb b/ext/tk/lib/tkextlib/tcllib/statusbar.rb new file mode 100644 index 0000000000..46a4b9d8b6 --- /dev/null +++ b/ext/tk/lib/tkextlib/tcllib/statusbar.rb @@ -0,0 +1,79 @@ +# +# tkextlib/tcllib/statusbar.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# +# * Part of tcllib extension +# * statusbar widget +# + +require 'tk' +require 'tkextlib/tcllib.rb' + +# TkPackage.require('widget::statusbar', '1.2') +TkPackage.require('widget::statusbar') + +module Tk::Tcllib + module Widget + class Statusbar < Tk::Tile::TFrame + PACKAGE_NAME = 'widget::statusbar'.freeze + def self.package_name + PACKAGE_NAME + end + + def self.package_version + begin + TkPackage.require('widget::statusbar') + rescue + '' + end + end + end + end +end + +class Tk::Tcllib::Widget::Statusbar + TkCommandNames = ['::widget::statusbar'.freeze].freeze + + def __boolval_optkeys + super() << 'separator' << 'resize' << 'resizeseparator' + end + private :__boolval_optkeys + + def create_self(keys) + if keys and keys != None + tk_call_without_enc(self.class::TkCommandNames[0], @path, + *hash_kv(keys, true)) + else + tk_call_without_enc(self.class::TkCommandNames[0], @path) + end + end + private :create_self + + def getframe + window(tk_send_without_enc('getframe')) + end + alias get_frame getframe + + def add(w, keys={}) + window(tk_send_without_enc('setwidget', *(hash_kv(keys)))) + end + + def remove(*wins) + tk_send_without_enc('remove', *wins) + self + end + + def remove_with_destroy(*wins) + tk_send_without_enc('remove', '-destroy', *wins) + self + end + + def delete(*wins) + tk_send_without_enc('delete', *wins) + self + end + + def items(pat=None) + tk_split_list(tk_send('items', pat)) + end +end diff --git a/ext/tk/lib/tkextlib/tcllib/swaplist.rb b/ext/tk/lib/tkextlib/tcllib/swaplist.rb index bb4c71cd5f..7698640534 100644 --- a/ext/tk/lib/tkextlib/tcllib/swaplist.rb +++ b/ext/tk/lib/tkextlib/tcllib/swaplist.rb @@ -33,7 +33,7 @@ end class Tk::Tcllib::Swaplist_Dialog TkCommandNames = ['::swaplist::swaplist'.freeze].freeze WidgetClassName = 'Swaplist'.freeze - WidgetClassNames[WidgetClassName] = self + WidgetClassNames[WidgetClassName] ||= self def self.show(*args) dialog = self.new(*args) diff --git a/ext/tk/lib/tkextlib/tcllib/tablelist.rb b/ext/tk/lib/tkextlib/tcllib/tablelist.rb index efeb8fbbac..b40f7a5b8b 100644 --- a/ext/tk/lib/tkextlib/tcllib/tablelist.rb +++ b/ext/tk/lib/tkextlib/tcllib/tablelist.rb @@ -10,7 +10,8 @@ require 'tkextlib/tcllib.rb' # check Tile extension :: If already loaded, use tablelist_tile. unless defined? Tk::Tcllib::Tablelist_usingTile - Tk::Tcllib::Tablelist_usingTile = TkPackage.provide('tile') + Tk::Tcllib::Tablelist_usingTile = + TkPackage.provide('tile') || TkPackage.provide('Ttk') end if Tk::Tcllib::Tablelist_usingTile @@ -20,8 +21,8 @@ if Tk::Tcllib::Tablelist_usingTile else # without Tile - # TkPackage.require('Tablelist', '4.2') - TkPackage.require('Tablelist') + # TkPackage.require('tablelist', '4.2') + TkPackage.require('tablelist') require 'tkextlib/tcllib/tablelist_core' end diff --git a/ext/tk/lib/tkextlib/tcllib/tablelist_core.rb b/ext/tk/lib/tkextlib/tcllib/tablelist_core.rb index c99f62f2dc..850e75d845 100644 --- a/ext/tk/lib/tkextlib/tcllib/tablelist_core.rb +++ b/ext/tk/lib/tkextlib/tcllib/tablelist_core.rb @@ -67,6 +67,9 @@ module Tk::Tcllib::TablelistItemConfig [self.path, mixed_id[0] + 'configure', _to_idx(mixed_id[1])] end + def cell_cget_tkstring(tagOrId, option) + itemcget_tkstring(['cell', tagOrId], option) + end def cell_cget(tagOrId, option) itemcget(['cell', tagOrId], option) end @@ -82,12 +85,16 @@ module Tk::Tcllib::TablelistItemConfig def current_cell_configinfo(tagOrId, slot=nil) current_itemconfiginfo(['cell', tagOrId], slot) end + alias cellcget_tkstring cell_cget_tkstring alias cellcget cell_cget alias cellcget_strict cell_cget_strict alias cellconfigure cell_configure alias cellconfiginfo cell_configinfo alias current_cellconfiginfo current_cell_configinfo + def column_cget_tkstring(tagOrId, option) + itemcget_tkstring(['column', tagOrId], option) + end def column_cget(tagOrId, option) itemcget(['column', tagOrId], option) end @@ -103,12 +110,16 @@ module Tk::Tcllib::TablelistItemConfig def current_column_configinfo(tagOrId, slot=nil) current_itemconfiginfo(['column', tagOrId], slot) end + alias columncget_tkstring column_cget_tkstring alias columncget column_cget alias columncget_strict column_cget_strict alias columnconfigure column_configure alias columnconfiginfo column_configinfo alias current_columnconfiginfo current_column_configinfo + def row_cget_tkstring(tagOrId, option) + itemcget_tkstring(['row', tagOrId], option) + end def row_cget(tagOrId, option) itemcget(['row', tagOrId], option) end @@ -124,13 +135,14 @@ module Tk::Tcllib::TablelistItemConfig def current_row_configinfo(tagOrId, slot=nil) current_itemconfiginfo(['row', tagOrId], slot) end + alias rowcget_tkstring row_cget_tkstring alias rowcget row_cget alias rowcget_strict row_cget_strict alias rowconfigure row_configure alias rowconfiginfo row_configinfo alias current_rowconfiginfo current_row_configinfo - private :itemcget, :itemcget_strict + private :itemcget_tkstring, :itemcget, :itemcget_strict private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo end @@ -140,7 +152,7 @@ class Tk::Tcllib::Tablelist TkCommandNames = ['::tablelist::tablelist'.freeze].freeze WidgetClassName = 'Tablelist'.freeze - WidgetClassNames[WidgetClassName] = self + WidgetClassNames[WidgetClassName] ||= self def create_self(keys) if keys and keys != None @@ -165,16 +177,16 @@ class Tk::Tcllib::Tablelist private :__strval_optkeys def __boolval_optkeys - super() + [ + super() - ['takefocus'] + [ 'forceeditendcommand', 'movablecolumns', 'movablerows', - 'protecttitlecolumns', 'resizablecolumns', + 'protecttitlecolumns', 'resizablecolumns', 'setfocus', 'showarrow', 'showlabels', 'showseparators' ] end private :__boolval_optkeys def __listval_optkeys - super() + ['columns'] + super() + ['columns', 'columntitles'] end private :__listval_optkeys @@ -186,7 +198,21 @@ class Tk::Tcllib::Tablelist def __val2ruby_optkeys # { key=>proc, ... } # The method is used to convert a opt-value to a ruby's object. # When get the value of the option "key", "proc.call(value)" is called. - super().update('stretch'=>proc{|v| (v == 'all')? v: simplelist(v)}) + super().update('stretch'=>proc{|v| + (v == 'all')? v: simplelist(v) + }, + 'takefocus'=>proc{|v| + case v + when '1' + true + when '0' + false + when '' + nil + else # cmd + tk_tcl2ruby(cmd) + end + }) end private :__val2ruby_optkeys @@ -196,6 +222,18 @@ class Tk::Tcllib::Tablelist # That is, "-#{key} #{proc.call(value)}". super().update('stretch'=>proc{|v| (v.kind_of?(Array))? v.collect{|e| _to_idx(e)}: v + }, + 'takefocus'=>proc{|v| + case v + when true + '1' + when false + '0' + when nil + '' + else + _get_eval_string(v) + end }) end private :__ruby2val_optkeys @@ -211,14 +249,15 @@ class Tk::Tcllib::Tablelist if id[0] == 'cell' super(id) + ['title'] else - super(id) - ['text'] + ['title'] + super(id) - ['text'] + ['title', 'name'] end end private :__item_strval_optkeys def __item_boolval_optkeys(id) super(id) + [ - 'editable', 'hide', 'resizable', 'showarrow', 'stretchable', + 'changesnipside', 'editable', 'hide', 'resizable', 'selectable', + 'showarrow', 'showlinenumbers', 'stretchable', 'stretchwindow', 'wrap' ] end private :__item_boolval_optkeys @@ -286,6 +325,23 @@ class Tk::Tcllib::Tablelist end alias cancelediting cancel_editing + def get_cellattrib(name=nil) + if name && name != None + tk_send('cellattrib', name) + else + ret = [] + lst = simplelist(tk_send('cellattrib')) + until lst.empty? + ret << ( [lst.shift] << lst.shift ) + end + ret + end + end + def set_cellattrib(*args) + tk_send('cellattrib', *(args.flatten)) + self + end + def cellindex(idx) _from_idx(tk_send('cellindex', _to_idx(idx))) end @@ -321,6 +377,23 @@ class Tk::Tcllib::Tablelist self end + def get_columnattrib(name=nil) + if name && name != None + tk_send('columnattrib', name) + else + ret = [] + lst = simplelist(tk_send('columnattrib')) + until lst.empty? + ret << ( [lst.shift] << lst.shift ) + end + ret + end + end + def set_columnattrib(*args) + tk_send('columnattrib', *(args.flatten)) + self + end + def columncount number(tk_send('columncount')) end @@ -329,6 +402,83 @@ class Tk::Tcllib::Tablelist number(tk_send('columnindex', _to_idx(idx))) end + def columnwidth(idx, opt=nil) + if opt + number(tk_send('columnwidth', _to_idx(idx), "-#{opt}")) + else + number(tk_send('columnwidth', _to_idx(idx))) + end + end + def requested_columnwidth(idx) + columnwidth(idx, 'requested') + end + def stretched_columnwidth(idx) + columnwidth(idx, 'stretched') + end + def total_columnwidth(idx) + columnwidth(idx, 'total') + end + + def configcelllist(lst) # lst ==> [idx, opt, val, idx, opt, val, ...] + ary = [] + lst.slice(3){|idx, opt, val| + ary << _to_idx(idx) << "-#{opt}" << val + } + tk_send('configcelllist', ary) + self + end + alias config_celllist configcelllist + + def configcells(*args) # args ==> idx, opt, val, idx, opt, val, ... + ary = [] + args.slice(3){|idx, opt, val| + ary << _to_idx(idx) << "-#{opt}" << val + } + tk_send('configcells', *ary) + self + end + alias config_cells configcells + + def configcolumnlist(lst) # lst ==> [idx, opt, val, idx, opt, val, ...] + ary = [] + lst.slice(3){|idx, opt, val| + ary << _to_idx(idx) << "-#{opt}" << val + } + tk_send('configcolumnlist', ary) + self + end + alias config_columnlist configcolumnlist + + def configcolumns(*args) # args ==> idx, opt, val, idx, opt, val, ... + ary = [] + args.slice(3){|idx, opt, val| + ary << _to_idx(idx) << "-#{opt}" << val + } + tk_send('configcolumns', *ary) + self + end + alias config_columns configcolumns + + def configrowlist(lst) # lst ==> [idx, opt, val, idx, opt, val, ...] + ary = [] + lst.slice(3){|idx, opt, val| + ary << _to_idx(idx) << "-#{opt}" << val + } + tk_send('configrowlist', ary) + self + end + alias config_rowlist configrowlist + + def configrows(*args) # args ==> idx, opt, val, idx, opt, val, ... + ary = [] + args.slice(3){|idx, opt, val| + ary << _to_idx(idx) << "-#{opt}" << val + } + tk_send('configrows', *ary) + self + end + alias config_rows configrows + def containing(y) idx = num_or_str(tk_send('containing', y)) (idx.kind_of?(Fixnum) && idx < 0)? nil: idx @@ -392,6 +542,10 @@ class Tk::Tcllib::Tablelist end alias editcell edit_cell + def editwintag + TkBindTag.new_by_name(tk_send('editwintag')) + end + def editwinpath window(tk_send('editwinpath')) end @@ -412,6 +566,11 @@ class Tk::Tcllib::Tablelist end alias finishediting finish_editing + def formatinfo + key, row, col = simplelist(tk_send('formatinfo')) + [key, number(row), number(col)] + end + def get(first, last=nil) if first.kind_of?(Array) simplelist(tk_send('get', first.collect{|idx| _to_idx(idx)})).collect!{|elem| simplelist(elem) } @@ -455,6 +614,22 @@ class Tk::Tcllib::Tablelist end alias getkeys get_keys + def has_attrib?(name) + bool(tk_send('hasattrib', name)) + end + + def has_cellattrib?(idx, name) + bool(tk_send('hascellattrib', _to_idx(idx), name)) + end + + def has_columnattrib?(idx, name) + bool(tk_send('hascolumnattrib', _to_idx(idx), name)) + end + + def has_rowattrib?(idx, name) + bool(tk_send('hasrowattrib', _to_idx(idx), name)) + end + def imagelabelpath(idx) window(tk_send('imagelabelpath', _to_idx(idx))) end @@ -486,6 +661,16 @@ class Tk::Tcllib::Tablelist end alias insertlist insert_list + def is_elem_snipped?(cellidx, tkvar) + bool(tk_send('iselemsnipped', _to_idx(cellidx), tkvar)) + end + alias elem_snipped? is_elem_snipped? + + def is_title_snipped?(colidx, tkvar) + bool(tk_send('istitlesnipped', _to_idx(colidx), tkvar)) + end + alias title_snipped? is_title_snipped? + def itemlistvar TkVarAccess.new(tk_send('itemlistvar')) end @@ -498,6 +683,10 @@ class Tk::Tcllib::Tablelist simplelist(tk_send('labels')) end + def labeltag + TkBindTag.new_by_name(tk_send('labeltag')) + end + def move(src, target) tk_send('move', _to_idx(src), _to_idx(target)) self @@ -535,6 +724,23 @@ class Tk::Tcllib::Tablelist end alias resetsortinfo reset_sortinfo + def get_rowattrib(name=nil) + if name && name != None + tk_send('rowattrib', name) + else + ret = [] + lst = simplelist(tk_send('rowattrib')) + until lst.empty? + ret << ( [lst.shift] << lst.shift ) + end + ret + end + end + def set_rowattrib(*args) + tk_send('rowattrib', *(args.flatten)) + self + end + def scan_mark(x, y) tk_send('scan', 'mark', x, y) self @@ -633,7 +839,22 @@ class Tk::Tcllib::Tablelist self end - DEFAULT_sortByColumn_cmd = '::tablelist::sortByColumn' + + # default of 'labelcommand' option + DEFAULT_labelcommand_value = + DEFAULT_sortByColumn_cmd = '::tablelist::sortByColumn' + + # default of 'labelcommand2' option + DEFAULT_labelcommand2_value = + DEFAULT_addToSortColumns_cmd = '::tablelist::addToSortColumns' + + def sortByColumn_with_event_generate(idx) + tk_call('::tablelist::sortByColumn', @path, _to_idx(idx)) + end + + def addToSortColumns_with_event_generate(idx) + tk_call('::tablelist::addToSortColumns', @path, _to_idx(idx)) + end def sort_by_column(idx, order=nil) if order @@ -659,15 +880,49 @@ class Tk::Tcllib::Tablelist self end + def sort_by_columnlist(idxlist, orderlist=None) + # orderlist :: list of 'increasing' or 'decreasing' + tk_send('sortbycolumnlist', idxlist.map{|idx| _to_idx(idx)}, orderlist) + self + end + def sortcolumn idx = num_or_str(tk_send('sortcolum')) (idx.kind_of?(Fixnum) && idx < 0)? nil: idx end + def sortcolumnlist + simplelist(tk_send('sortcolumlist')).map{|col| num_or_str(col)} + end + def sortorder tk_send('sortorder') end + def sortorderlist + simplelist(tk_send('sortorderlist')) + end + + def toggle_columnhide(first, last=nil) + if first.kind_of?(Array) + tk_send('togglecolumnhide', first.collect{|idx| _to_idx(idx)}) + else + first = _to_idx(first) + last = (last)? _to_idx(last): first + tk_send('togglecolumnhide', first, last) + end + end + + def toggle_rowhide(first, last=nil) + if first.kind_of?(Array) + tk_send('togglerowhide', first.collect{|idx| _to_idx(idx)}) + else + first = _to_idx(first) + last = (last)? _to_idx(last): first + tk_send('togglerowhide', first, last) + end + end + def toggle_visibility(first, last=nil) if first.kind_of?(Array) tk_send('togglevisibility', first.collect{|idx| _to_idx(idx)}) @@ -680,6 +935,26 @@ class Tk::Tcllib::Tablelist end alias togglevisibility toggle_visibility + def unset_attrib(name) + tk_send('unsetattrib', name) + self + end + + def unset_cellattrib(idx, name) + tk_send('unsetcellattrib', _to_idx(idx), name) + self + end + + def unset_columnattrib(idx, name) + tk_send('unsetcolumnattrib', _to_idx(idx), name) + self + end + + def unset_rowattrib(idx, name) + tk_send('unsetrowattrib', _to_idx(idx), name) + self + end + def windowpath(idx) window(tk_send('windowpath', _to_idx(idx))) end @@ -692,6 +967,11 @@ class << Tk::Tcllib::Tablelist window(Tk.tk_call('::tablelist::getTablelistPath', descendant)) end + def getTablelistColumn(descendant) + num_or_str(Tk.tk_call('::tablelist::getTablelistColumn', headerlabel)) + end + + def convEventFields(descendant, x, y) window(Tk.tk_call('::tablelist::convEventFields', descendant, x, y)) end @@ -767,6 +1047,16 @@ class << Tk::Tcllib::Tablelist Tk.tk_call('::tablelist::addTimeMentry', format, separator, gmt, name) end + def addDateTimeMentry(format, date_sep, time_sep, gmt=false, name=None) + if gmt && gmt != None + gmt = '-gmt' + else + gmt = None + end + Tk.tk_call('::tablelist::addDateTimeMentry', + format, date_sep, time_sep, gmt, name) + end + def addFixedPointMentry(count1, count2, comma=false, name=None) if comma && comma != None comma = '-comma' diff --git a/ext/tk/lib/tkextlib/tcllib/tablelist_tile.rb b/ext/tk/lib/tkextlib/tcllib/tablelist_tile.rb index 0cb4eb735d..0a1458415e 100644 --- a/ext/tk/lib/tkextlib/tcllib/tablelist_tile.rb +++ b/ext/tk/lib/tkextlib/tcllib/tablelist_tile.rb @@ -9,7 +9,7 @@ require 'tk' require 'tkextlib/tcllib.rb' # TkPackage.require('tablelist_tile', '4.2') -TkPackage.require('Tablelist_tile') +TkPackage.require('tablelist_tile') unless defined? Tk::Tcllib::Tablelist_usingTile Tk::Tcllib::Tablelist_usingTile = true @@ -19,6 +19,24 @@ requrie 'tkextlib/tcllib/tablelist_core' module Tk module Tcllib + class Tablelist + # commands related to tile Themems + def self.set_theme(theme) + Tk.tk_call('::tablelist::setTheme', theme) + end + + def self.get_current_theme + Tk.tk_call('::tablelist::getCurrentTheme') + end + + def self.get_theme_list + TkComm.simplelist(Tk.tk_call('::tablelist::getThemes')) + end + def self.set_theme_defaults + Tk.tk_call('::tablelist::setThemeDefaults') + end + end + Tablelist_Tile = Tablelist TableList_Tile = Tablelist end diff --git a/ext/tk/lib/tkextlib/tcllib/toolbar.rb b/ext/tk/lib/tkextlib/tcllib/toolbar.rb new file mode 100644 index 0000000000..6eae4eb3e1 --- /dev/null +++ b/ext/tk/lib/tkextlib/tcllib/toolbar.rb @@ -0,0 +1,175 @@ +# +# tkextlib/tcllib/toolbar.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# +# * Part of tcllib extension +# * toolbar widget +# + +require 'tk' +require 'tkextlib/tcllib.rb' + +# TkPackage.require('widget::toolbar', '1.2') +TkPackage.require('widget::toolbar') + +module Tk::Tcllib + module Widget + class Toolbar < TkWindow + PACKAGE_NAME = 'widget::toolbar'.freeze + def self.package_name + PACKAGE_NAME + end + + def self.package_version + begin + TkPackage.require('widget::toolbar') + rescue + '' + end + end + end + + module ToolbarItemConfig + include TkItemConfigMethod + end + end +end + + +class Tk::Tcllib::Widget::ToolbarItem < TkObject + include TkTreatTagFont + + ToolbarItemID_TBL = TkCore::INTERP.create_table + + TkCore::INTERP.init_ip_env{ + TTagID_TBL.mutex.synchronize{ TTagID_TBL.clear } + } + + def ToolbarItem.id2obj(tbar, id) + tpath = tbar.path + ToolbarItemID_TBL.mutex.synchronize{ + if ToolbarItemID_TBL[tpath] + ToolbarItemID_TBL[tpath][id]? ToolbarItemID_TBL[tpath][id]: id + else + id + end + } + end + + def initaialize(parent, *args) + @parent = @t = parent + @tpath = parent.path + + @path = @id = @t.tk_send('add', *args) + # A same id is rejected by the Tcl function. + + ToolbarItemID_TBL.mutex.synchronize{ + ToolbarItemID_TBL[@id] = self + ToolbarItemID_TBL[@tpath] = {} unless ToolbarItemID_TBL[@tpath] + ToolbarItemID_TBL[@tpath][@id] = self + } + end + + def [](key) + cget key + end + + def []=(key,val) + configure key, val + val + end + + def cget_tkstring(option) + @t.itemcget_tkstring(@id, option) + end + def cget(option) + @t.itemcget(@id, option) + end + def cget_strict(option) + @t.itemcget_strict(@id, option) + end + + def configure(key, value=None) + @t.itemconfigure(@id, key, value) + self + end + + def configinfo(key=nil) + @t.itemconfiginfo(@id, key) + end + + def current_configinfo(key=nil) + @t.current_itemconfiginfo(@id, key) + end + + def delete + @t.delete(@id) + end + + def itemid + @t.itemid(@id) + end + + def remove + @t.remove(@id) + end + def remove_with_destroy + @t.remove_with_destroy(@id) + end +end + +class Tk::Tcllib::Widget::Toolbar + include Tk::Tcllib::Widget::ToolbarItemConfig + + TkCommandNames = ['::widget::toolbar'.freeze].freeze + + def __destroy_hook__ + Tk::Tcllib::Widget::ToolbarItem::ToolbarItemID_TBL.mutex.synchronize{ + Tk::Tcllib::Widget::ToolbarItem::ToolbarItemID_TBL.delete(@path) + } + end + + def create_self(keys) + if keys and keys != None + tk_call_without_enc(self.class::TkCommandNames[0], @path, + *hash_kv(keys, true)) + else + tk_call_without_enc(self.class::TkCommandNames[0], @path) + end + end + private :create_self + + def getframe + window(tk_send('getframe')) + end + alias get_frame getframe + + def add(*args) + Tk::Tcllib::Widget::Toolbar.new(self, *args) + end + + def itemid(item) + window(tk_send('itemid')) + end + + def items(pattern) + tk_split_simplelist(tk_send('items', pattern)).map{|id| + Tk::Tcllib::Widget::ToolbarItem.id2obj(self, id) + } + end + + def remove(*items) + tk_send('remove', *items) + self + end + + def remove_with_destroy(*items) + tk_send('remove', '-destroy', *items) + self + end + + def delete(*items) + tk_send('delete', *items) + self + end +end diff --git a/ext/tk/lib/tkextlib/tcllib/tooltip.rb b/ext/tk/lib/tkextlib/tcllib/tooltip.rb index 73b7df0c22..070e63a7b5 100644 --- a/ext/tk/lib/tkextlib/tcllib/tooltip.rb +++ b/ext/tk/lib/tkextlib/tcllib/tooltip.rb @@ -34,6 +34,8 @@ module Tk::Tcllib::Tooltip extend TkCore WidgetClassName = 'Tooltip'.freeze + WidgetClassNames[WidgetClassName] ||= self + def self.database_classname self::WidgetClassName end @@ -64,6 +66,13 @@ module Tk::Tcllib::Tooltip self.delay(millisecs) end + def self.fade? + bool(tk_call_without_enc('::tooltip::tooltip', 'fade')) + end + def self.fade(mode) + tk_call_without_enc('::tooltip::tooltip', 'fade', mode) + end + def self.disable tk_call_without_enc('::tooltip::tooltip', 'disable') false @@ -86,7 +95,7 @@ module Tk::Tcllib::Tooltip else args = msg end - tk_call_without_enc('::tooltip::tooltip', widget.path, *args) + tk_call('::tooltip::tooltip', widget.path, *args) end def self.erase(widget) diff --git a/ext/tk/lib/tkextlib/tcllib/widget.rb b/ext/tk/lib/tkextlib/tcllib/widget.rb index ed69f67ce6..57fdf7a575 100644 --- a/ext/tk/lib/tkextlib/tcllib/widget.rb +++ b/ext/tk/lib/tkextlib/tcllib/widget.rb @@ -26,10 +26,41 @@ module Tk::Tcllib '' end end + + #--- followings may be private functions of tklib + def self.isa(compare_as, *args) + begin + return Tk.tk_call('::widget::isa', compare_as, *args) + rescue => e + if TkComm.bool(Tk.tk_call('info','command','::widget::isa')) || + ! TkComm.bool(Tk.tk_call('info','command','::widget::validate')) + fail e + end + end + Tk.tk_call('::widget::validate', compare_as, *args) + end + def self.validate(compare_as, *args) + begin + return Tk.tk_call('::widget::validate', compare_as, *args) + rescue => e + if TkComm.bool(Tk.tk_call('info','command','::widget::validate')) || + ! TkComm.bool(Tk.tk_call('info','command','::widget::isa')) + fail e + end + end + Tk.tk_call('::widget::isa', compare_as, *args) + end end end module Tk::Tcllib::Widget + TkComm::TkExtlibAutoloadModule.unshift(self) + + autoload :Calendar, 'tkextlib/tcllib/calendar' + + autoload :Canvas_Sqmap, 'tkextlib/tcllib/canvas_sqmap' + autoload :Canvas_Zoom, 'tkextlib/tcllib/canvas_zoom' + autoload :Dialog, 'tkextlib/tcllib/dialog' autoload :Panelframe, 'tkextlib/tcllib/panelframe' @@ -45,4 +76,7 @@ module Tk::Tcllib::Widget autoload :Superframe, 'tkextlib/tcllib/superframe' autoload :SuperFrame, 'tkextlib/tcllib/superframe' + + autoload :Toolbar, 'tkextlib/tcllib/toolbar' + autoload :ToolbarItem, 'tkextlib/tcllib/toolbar' end |