From ef5afcf8a010fedef0b6aed91d2dabccacab2bc5 Mon Sep 17 00:00:00 2001 From: nagai Date: Tue, 29 Mar 2005 10:27:32 +0000 Subject: [PATCH] * lib/tkextlib/blt/component.rb: cannot create elements except default type of element. * lib/tkextlib/blt/barchart.rb: ditto. * lib/tkextlib/blt/graph.rb: ditto. * lib/tkextlib/blt/stripchart.rb: ditto. * lib/tkextlib/blt/component.rb: axis command option gets proper object type of arguments. * sample/tkextlib/blt/calendar.rb: new sample. * sample/tkextlib/blt/pareto.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8208 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/ChangeLog.tkextlib | 30 +- ext/tk/lib/tkextlib/blt/barchart.rb | 2 + ext/tk/lib/tkextlib/blt/component.rb | 342 +++++++++++++++++--- ext/tk/lib/tkextlib/blt/graph.rb | 2 + ext/tk/lib/tkextlib/blt/stripchart.rb | 2 + ext/tk/sample/tkextlib/blt/calendar.rb | 117 +++++++ ext/tk/sample/tkextlib/blt/images/chalk.gif | Bin 0 -> 4378 bytes ext/tk/sample/tkextlib/blt/images/rain.gif | Bin 0 -> 3785 bytes ext/tk/sample/tkextlib/blt/pareto.rb | 90 ++++++ 9 files changed, 537 insertions(+), 48 deletions(-) create mode 100644 ext/tk/sample/tkextlib/blt/calendar.rb create mode 100644 ext/tk/sample/tkextlib/blt/images/chalk.gif create mode 100644 ext/tk/sample/tkextlib/blt/images/rain.gif create mode 100644 ext/tk/sample/tkextlib/blt/pareto.rb diff --git a/ext/tk/ChangeLog.tkextlib b/ext/tk/ChangeLog.tkextlib index 85fd938e3a..9c9f2bf368 100644 --- a/ext/tk/ChangeLog.tkextlib +++ b/ext/tk/ChangeLog.tkextlib @@ -1,3 +1,21 @@ +2005-03-29 Hidetoshi NAGAI + + * lib/tkextlib/blt/component.rb: cannot create elements except + default type of element. + + * lib/tkextlib/blt/barchart.rb: ditto. + + * lib/tkextlib/blt/graph.rb: ditto. + + * lib/tkextlib/blt/stripchart.rb: ditto. + + * lib/tkextlib/blt/component.rb: axis command option gets + proper object type of arguments. + + * sample/tkextlib/blt/calendar.rb: new sample. + + * sample/tkextlib/blt/pareto.rb: ditto. + 2005-03-26 Hidetoshi NAGAI * lib/tkextlib/blt.rb: add commands for zooming. @@ -16,19 +34,19 @@ * lib/tkextlib/blt/htext.rb: add TkVariable object to access special Tcl variables. - * ext/tk/lib/tkextlib/treectrl/tktreectrl.rb: typo fix. + * lib/tkextlib/treectrl/tktreectrl.rb: typo fix. - * ext/tk/lib/tkextlib/treectrl/tktreectrl.rb: proper treatment + * lib/tkextlib/treectrl/tktreectrl.rb: proper treatment of 'font' option of element_configure. - * ext/tk/lib/tkextlib/treectrl/tktreectrl.rb: bug fix on item_sort. + * lib/tkextlib/treectrl/tktreectrl.rb: bug fix on item_sort. - * ext/tk/lib/tkextlib/treectrl/tktreectrl.rb: add methods to + * lib/tkextlib/treectrl/tktreectrl.rb: add methods to call TreeCtrl commands for bindings. - * ext/tk/sample/tkextlib/blt/*: add some sample scripts. + * sample/tkextlib/blt/*: add some sample scripts. - * ext/tk/sample/tkextlib/treectrl/*: add some sample scripts. + * sample/tkextlib/treectrl/*: add some sample scripts. 2005-03-18 Hidetoshi NAGAI diff --git a/ext/tk/lib/tkextlib/blt/barchart.rb b/ext/tk/lib/tkextlib/blt/barchart.rb index d8ecad834f..c253194582 100644 --- a/ext/tk/lib/tkextlib/blt/barchart.rb +++ b/ext/tk/lib/tkextlib/blt/barchart.rb @@ -26,6 +26,7 @@ module Tk::BLT end private :__strval_optkeys +=begin BarElement_ID = ['blt_barchart_bar'.freeze, '00000'.taint].freeze def bar(elem=nil, keys={}) @@ -40,6 +41,7 @@ module Tk::BLT tk_send('bar', elem, keys) Element.new(self, elem, :without_creating=>true) end +=end def extents(item) num_or_str(tk_send_without_enc('extents', item)) diff --git a/ext/tk/lib/tkextlib/blt/component.rb b/ext/tk/lib/tkextlib/blt/component.rb index c5152ddab4..a42c39d0eb 100644 --- a/ext/tk/lib/tkextlib/blt/component.rb +++ b/ext/tk/lib/tkextlib/blt/component.rb @@ -78,6 +78,19 @@ module Tk::BLT ret = itemcget(['axis', id], option) end def axis_configure(id, slot, value=None) + if slot.kind_of?(Hash) + slot = _symbolkey2str(slot) + if cmd = slot.delete('command') + slot['command'] = proc{|w, tick| + cmd.call(TkComm.window(w), TkComm.num_or_str(tick)) + } + end + elsif slot == :command || slot == 'command' + cmd = value + value = proc{|w, tick| + cmd.call(TkComm.window(w), TkComm.num_or_str(tick)) + } + end itemconfigure(['axis', id], slot, value) end def axis_configinfo(id, slot=nil) @@ -113,6 +126,32 @@ module Tk::BLT current_itemconfiginfo(['element', id], slot) end + def bar_cget(id, option) + itemcget(['bar', id], option) + end + def bar_configure(id, slot, value=None) + itemconfigure(['bar', id], slot, value) + end + def bar_configinfo(id, slot=nil) + itemconfiginfo(['bar', id], slot) + end + def current_bar_configinfo(id, slot=nil) + current_itemconfiginfo(['bar', id], slot) + end + + def line_cget(id, option) + itemcget(['line', id], option) + end + def line_configure(id, slot, value=None) + itemconfigure(['line', id], slot, value) + end + def line_configinfo(id, slot=nil) + itemconfiginfo(['line', id], slot) + end + def current_line_configinfo(id, slot=nil) + current_itemconfiginfo(['line', id], slot) + end + def gridline_cget(option) itemcget('grid', option) end @@ -294,6 +333,16 @@ module Tk::BLT @chart.current_axis_configinfo(@id, key) end + def command(cmd=nil, &b) + if cmd + configure('command', cmd) + elsif b + configure('command', Proc.new(&b)) + else + cget('command') + end + end + def delete @chart.axis_delete(@id) self @@ -385,10 +434,26 @@ module Tk::BLT ################# class Element < TkObject + extend Tk + extend TkItemFontOptkeys + extend TkItemConfigOptkeys + + extend Tk::BLT::PlotComponent::OptKeys + + ElementTypeName = 'element' + ElementTypeToClass = { ElementTypeName=>self } + ElementID_TBL = TkCore::INTERP.create_table + + TkCore::INTERP.init_ip_env{ ElementID_TBL.clear } + OBJ_ID = ['blt_chart_element'.freeze, '00000'.taint].freeze OBJ_TBL={} - def self.id2obj(chart, id) + def Element.type2class(type) + ElementTypeToClass[type] + end + + def Element.id2obj(chart, id) cpath = chart.path return id unless OBJ_TBL[cpath] OBJ_TBL[cpath][id]? OBJ_TBL[cpath][id]: id @@ -419,11 +484,12 @@ module Tk::BLT end @parent = @chart = chart @cpath = @chart.path + @typename = self.class::ElementTypeName Element::OBJ_TBL[@cpath][@element] = self keys = _symbolkey2str(keys) unless keys.delete('without_creating') # @chart.element_create(@element, keys) - tk_call(@chart, 'element', 'create', @element, keys) + tk_call(@chart, @typename, 'create', @element, keys) end end @@ -436,17 +502,21 @@ module Tk::BLT end def cget(option) - @chart.element_cget(@id, option) + # @chart.element_cget(@id, option) + @chart.__send__(@typename + '_cget', @id, option) end def configure(key, value=None) - @chart.element_configure(@id, key, value) + # @chart.element_configure(@id, key, value) + @chart.__send__(@typename + '_configure', @id, key, value) self end def configinfo(key=nil) - @chart.element_configinfo(@id, key) + # @chart.element_configinfo(@id, key) + @chart.__send__(@typename + '_configinfo', @id, key) end def current_configinfo(key=nil) - @chart.current_element_configinfo(@id, key) + # @chart.current_element_configinfo(@id, key) + @chart.__send__('current_' << @typename << '_configinfo', @id, key) end def activate(*args) @@ -455,7 +525,8 @@ module Tk::BLT end def closest(x, y, var, keys={}) - @chart.element_closest(x, y, var, @id, keys) + # @chart.element_closest(x, y, var, @id, keys) + @chart.__send__(@typename + '_closest', x, y, var, @id, keys) end def deactivate @@ -481,6 +552,15 @@ module Tk::BLT end end + class Bar < Element + ElementTypeName = 'bar'.freeze + ElementTypeToClass[ElementTypeName] = self + end + class Line < Element + ElementTypeName = 'line'.freeze + ElementTypeToClass[ElementTypeName] = self + end + ################# class GridLine < TkObject @@ -781,7 +861,7 @@ module Tk::BLT fail RuntimeError, "#{self} is an abstract class" end args, fontkeys = _parse_create_args(keys) - idnum = tk_call_without_enc(chart.path, 'create', + idnum = tk_call_without_enc(chart.path, 'marker', 'create', self::MarkerTypeName, *args) chart.marker_configure(idnum, fontkeys) unless fontkeys.empty? idnum.to_i # 'item id' is an integer number @@ -789,7 +869,8 @@ module Tk::BLT def self.create_type(chart, type, keys={}) args, fontkeys = _parse_create_args(keys) - idnum = tk_call_without_enc(chart.path, 'create', type, *args) + idnum = tk_call_without_enc(chart.path, 'marker', 'create', + type, *args) chart.marker_configure(idnum, fontkeys) unless fontkeys.empty? id = idnum.to_i # 'item id' is an integer number obj = self.allocate @@ -797,10 +878,10 @@ module Tk::BLT @parent = @chart = chart @path = chart.path @id = id - unless Tk::BLT::PlotComponent::MarkerID_TBL[@path] - Tk::BLT::PlotComponent::MarkerID_TBL[@path] = {} + unless Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@path] + Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@path] = {} end - Tk::BLT::PlotComponent::MarkerID_TBL[@path][@id] = self + Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@path][@id] = self } obj end @@ -810,10 +891,10 @@ module Tk::BLT @path = parent.path @id = create_self(*args) # an integer number as 'item id' - unless Tk::BLT::PlotComponent::MarkerID_TBL[@path] - Tk::BLT::PlotComponent::MarkerID_TBL[@path] = {} + unless Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@path] + Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@path] = {} end - Tk::BLT::PlotComponent::MarkerID_TBL[@path][@id] = self + Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@path][@id] = self end def create_self(*args) self.class.create(@chart, *args) # return an integer as 'item id' @@ -973,6 +1054,32 @@ module Tk::BLT _component_bindinfo('element', tag, context) end + def bar_bind(tag, context, *args) + _component_bind('bar', tag, context, *args) + end + def bar_bind_append(tag, context, *args) + _component_bind_append('bar', tag, context, *args) + end + def bar_bind_remove(tag, context) + _component_bind_remove('bar', tag, context) + end + def bar_bindinfo(tag, context=nil) + _component_bindinfo('bar', tag, context) + end + + def line_bind(tag, context, *args) + _component_bind('line', tag, context, *args) + end + def line_bind_append(tag, context, *args) + _component_bind_append('line', tag, context, *args) + end + def line_bind_remove(tag, context) + _component_bind_remove('line', tag, context) + end + def line_bindinfo(tag, context=nil) + _component_bindinfo('line', tag, context) + end + def legend_bind(tag, context, *args) _component_bind('legend', tag, context, *args) end @@ -1017,7 +1124,7 @@ module Tk::BLT end def axis_names(*pats) simplelist(tk_send('axis', 'names', *pats)).collect{|axis| - Axis.id2obj(self, axis) + Tk::BLT::PlotComponent::Axis.id2obj(self, axis) } end def axis_transform(id, val) @@ -1029,9 +1136,12 @@ module Tk::BLT end def axis_use(id, target=nil) if target - Axis.id2obj(self, tk_send('axis', 'use', tagid(id), tagid(target))) + Tk::BLT::PlotComponent::Axis.id2obj(self, + tk_send('axis', 'use', + tagid(id), tagid(target))) else - Axis.id2obj(self, tk_send('axis', 'use', tagid(id))) + Tk::BLT::PlotComponent::Axis.id2obj(self, + tk_send('axis', 'use', tagid(id))) end end @@ -1082,7 +1192,7 @@ module Tk::BLT end def element_names(*pats) simplelist(tk_send('element', 'names', *pats)).collect{|elem| - Element.id2obj(self, elem) + Tk::BLT::PlotComponent::Element.id2obj(self, elem) } end def element_show(*names) @@ -1099,6 +1209,102 @@ module Tk::BLT ################### + def bar_create(id=nil, keys={}) + # tk_send('bar', 'create', tagid(id), keys) + Tk::BLT::PlotComponent::Bar.new(self, id, keys) + end + alias bar bar_create + def bar_activate(id, *indices) + tk_send('bar', 'activate', tagid(id), *indices) + self + end + def bar_closest(x, y, var, *args) + if args[-1].kind_of?(Hash) + keys = args.pop + bool(tk_send('bar', 'activate', x, y, var, + *(hash_kv(keys).concat(args)))) + else + bool(tk_send('bar', 'activate', x, y, var, *args)) + end + end + def bar_deactivate(*ids) + tk_send('bar', 'deactivate', *(ids.collect{|id| tagid(id)})) + self + end + def bar_delete(*ids) + tk_send('bar', 'delete', *(ids.collect{|id| tagid(id)})) + self + end + def bar_exist?(id) + bool(tk_send('bar', 'exists', tagid(id))) + end + def bar_names(*pats) + simplelist(tk_send('bar', 'names', *pats)).collect{|elem| + Tk::BLT::PlotComponent::Element.id2obj(self, elem) + } + end + def bar_show(*names) + if names.empty? + simplelist(tk_send('bar', 'show')) + else + tk_send('bar', 'show', *names) + self + end + end + def bar_type(id) + tk_send('bar', 'type', tagid(id)) + end + + ################### + + def line_create(id=nil, keys={}) + # tk_send('line', 'create', tagid(id), keys) + Tk::BLT::PlotComponent::Line.new(self, id, keys) + end + alias bar line_create + def line_activate(id, *indices) + tk_send('line', 'activate', tagid(id), *indices) + self + end + def line_closest(x, y, var, *args) + if args[-1].kind_of?(Hash) + keys = args.pop + bool(tk_send('line', 'activate', x, y, var, + *(hash_kv(keys).concat(args)))) + else + bool(tk_send('line', 'activate', x, y, var, *args)) + end + end + def line_deactivate(*ids) + tk_send('line', 'deactivate', *(ids.collect{|id| tagid(id)})) + self + end + def line_delete(*ids) + tk_send('line', 'delete', *(ids.collect{|id| tagid(id)})) + self + end + def line_exist?(id) + bool(tk_send('line', 'exists', tagid(id))) + end + def line_names(*pats) + simplelist(tk_send('line', 'names', *pats)).collect{|elem| + Tk::BLT::PlotComponent::Element.id2obj(self, elem) + } + end + def line_show(*names) + if names.empty? + simplelist(tk_send('line', 'show')) + else + tk_send('line', 'show', *names) + self + end + end + def line_type(id) + tk_send('line', 'type', tagid(id)) + end + + ################### + def gridline_off tk_send_without_enc('grid', 'off') self @@ -1124,9 +1330,12 @@ module Tk::BLT end def legend_get(pos, y=nil) if y - Element.id2obj(self, tk_send('legend', 'get', _at(pos, y))) + Tk::BLT::PlotComponent::Element.id2obj(self, + tk_send('legend', 'get', + _at(pos, y))) else - Element.id2obj(self, tk_send('legend', 'get', pos)) + Tk::BLT::PlotComponent::Element.id2obj(self, + tk_send('legend', 'get', pos)) end end @@ -1142,7 +1351,7 @@ module Tk::BLT end def pen_names(*pats) simplelist(tk_send('pen', 'names', *pats)).collect{|pen| - Pen.id2obj(self, pen) + Tk::BLT::PlotComponent::Pen.id2obj(self, pen) } end @@ -1211,7 +1420,7 @@ module Tk::BLT end def marker_names(*pats) simplelist(tk_send('marker', 'names', *pats)).collect{|id| - Marker.id2obj(self, id) + Tk::BLT::PlotComponent::Marker.id2obj(self, id) } end def marker_type(id) @@ -1220,21 +1429,23 @@ module Tk::BLT ################### - alias line_cget element_cget - alias line_configure element_configure - alias line_configinfo element_configinfo - alias current_line_configinfo current_element_configinfo - alias line_bind element_bind - alias line_bind_append element_bind_append - alias line_bind_remove element_bind_remove - alias line_bindinfo element_bindinfo - - ################### - def xaxis_cget(option) itemcget('xaxis', option) end def xaxis_configure(slot, value=None) + if slot.kind_of?(Hash) + slot = _symbolkey2str(slot) + if cmd = slot.delete('command') + slot['command'] = proc{|w, tick| + cmd.call(TkComm.window(w), TkComm.num_or_str(tick)) + } + end + elsif slot == :command || slot == 'command' + cmd = value + value = proc{|w, tick| + cmd.call(TkComm.window(w), TkComm.num_or_str(tick)) + } + end itemconfigure('xaxis', slot, value) end def xaxis_configinfo(slot=nil) @@ -1279,9 +1490,11 @@ module Tk::BLT end def xaxis_use(target=nil) if target - Axis.id2obj(self, tk_send('xaxis', 'use', tagid(target))) + Tk::BLT::PlotComponent::Axis.id2obj(self, + tk_send('xaxis', 'use', + tagid(target))) else - Axis.id2obj(self, tk_send('xaxis', 'use')) + Tk::BLT::PlotComponent::Axis.id2obj(self, tk_send('xaxis', 'use')) end end @@ -1289,6 +1502,19 @@ module Tk::BLT itemcget('x2axis', option) end def x2axis_configure(slot, value=None) + if slot.kind_of?(Hash) + slot = _symbolkey2str(slot) + if cmd = slot.delete('command') + slot['command'] = proc{|w, tick| + cmd.call(TkComm.window(w), TkComm.num_or_str(tick)) + } + end + elsif slot == :command || slot == 'command' + cmd = value + value = proc{|w, tick| + cmd.call(TkComm.window(w), TkComm.num_or_str(tick)) + } + end itemconfigure('x2axis', slot, value) end def x2axis_configinfo(slot=nil) @@ -1333,9 +1559,11 @@ module Tk::BLT end def x2axis_use(target=nil) if target - Axis.id2obj(self, tk_send('x2axis', 'use', tagid(target))) + Tk::BLT::PlotComponent::Axis.id2obj(self, + tk_send('x2axis', 'use', + tagid(target))) else - Axis.id2obj(self, tk_send('x2axis', 'use')) + Tk::BLT::PlotComponent::Axis.id2obj(self, tk_send('x2axis', 'use')) end end @@ -1343,6 +1571,19 @@ module Tk::BLT itemcget('yaxis', option) end def yaxis_configure(slot, value=None) + if slot.kind_of?(Hash) + slot = _symbolkey2str(slot) + if cmd = slot.delete('command') + slot['command'] = proc{|w, tick| + cmd.call(TkComm.window(w), TkComm.num_or_str(tick)) + } + end + elsif slot == :command || slot == 'command' + cmd = value + value = proc{|w, tick| + cmd.call(TkComm.window(w), TkComm.num_or_str(tick)) + } + end itemconfigure('yaxis', slot, value) end def yaxis_configinfo(slot=nil) @@ -1387,9 +1628,11 @@ module Tk::BLT end def yaxis_use(target=nil) if target - Axis.id2obj(self, tk_send('yaxis', 'use', tagid(target))) + Tk::BLT::PlotComponent::Axis.id2obj(self, + tk_send('yaxis', 'use', + tagid(target))) else - Axis.id2obj(self, tk_send('yaxis', 'use')) + Tk::BLT::PlotComponent::Axis.id2obj(self, tk_send('yaxis', 'use')) end end @@ -1397,6 +1640,19 @@ module Tk::BLT itemcget('y2axis', option) end def y2axis_configure(slot, value=None) + if slot.kind_of?(Hash) + slot = _symbolkey2str(slot) + if cmd = slot.delete('command') + slot['command'] = proc{|w, tick| + cmd.call(TkComm.window(w), TkComm.num_or_str(tick)) + } + end + elsif slot == :command || slot == 'command' + cmd = value + value = proc{|w, tick| + cmd.call(TkComm.window(w), TkComm.num_or_str(tick)) + } + end itemconfigure('y2axis', slot, value) end def y2axis_configinfo(slot=nil) @@ -1441,9 +1697,11 @@ module Tk::BLT end def y2axis_use(target=nil) if target - Axis.id2obj(self, tk_send('y2axis', 'use', tagid(target))) + Tk::BLT::PlotComponent::Axis.id2obj(self, + tk_send('y2axis', 'use', + tagid(target))) else - Axis.id2obj(self, tk_send('y2axis', 'use')) + Tk::BLT::PlotComponent::Axis.id2obj(self, tk_send('y2axis', 'use')) end end end diff --git a/ext/tk/lib/tkextlib/blt/graph.rb b/ext/tk/lib/tkextlib/blt/graph.rb index b16c72458a..e9fbdd587a 100644 --- a/ext/tk/lib/tkextlib/blt/graph.rb +++ b/ext/tk/lib/tkextlib/blt/graph.rb @@ -26,6 +26,7 @@ module Tk::BLT end private :__strval_optkeys +=begin BarElement_ID = ['blt_graph_bar'.freeze, '00000'.taint].freeze def bar(elem=nil, keys={}) @@ -40,6 +41,7 @@ module Tk::BLT tk_send('bar', elem, keys) Element.new(self, elem, :without_creating=>true) end +=end def extents(item) num_or_str(tk_send_without_enc('extents', item)) diff --git a/ext/tk/lib/tkextlib/blt/stripchart.rb b/ext/tk/lib/tkextlib/blt/stripchart.rb index b8cbf8bc34..64c5c1abf8 100644 --- a/ext/tk/lib/tkextlib/blt/stripchart.rb +++ b/ext/tk/lib/tkextlib/blt/stripchart.rb @@ -26,6 +26,7 @@ module Tk::BLT end private :__strval_optkeys +=begin BarElement_ID = ['blt_stripchart_bar'.freeze, '00000'.taint].freeze def bar(elem=nil, keys={}) @@ -40,6 +41,7 @@ module Tk::BLT tk_send('bar', elem, keys) Element.new(self, elem, :without_creating=>true) end +=end def extents(item) num_or_str(tk_send_without_enc('extents', item)) diff --git a/ext/tk/sample/tkextlib/blt/calendar.rb b/ext/tk/sample/tkextlib/blt/calendar.rb new file mode 100644 index 0000000000..4fc6d64d9e --- /dev/null +++ b/ext/tk/sample/tkextlib/blt/calendar.rb @@ -0,0 +1,117 @@ +#!/usr/bin/env ruby + +require 'tk' +require 'tkextlib/blt' + +require 'date' + +dir = File.join(File.dirname(File.expand_path(__FILE__)), 'images') +file = File.join(dir, 'chalk.gif') +active = File.join(dir, 'rain.gif') + +texture1 = TkPhotoImage.new(:file=>file) +texture2 = TkPhotoImage.new(:file=>active) + +TkOption.add('*Tile', texture1) + +TkOption.add('*HighlightThickness', 0) +TkOption.add('*calendar.weekframe*Tile', texture2) +TkOption.add('*Calendar.Label.borderWidth', 0) +TkOption.add('*Calendar.Label.relief', :sunken) +TkOption.add('*Calendar.Frame.borderWidth', 2) +TkOption.add('*Calendar.Frame.relief', :raised) +TkOption.add('*Calendar.Label.font', 'Helvetica 11') +TkOption.add('*Calendar.Label.foreground', 'navyblue') +TkOption.add('*button.foreground', 'navyblue') +TkOption.add('*background', 'grey85') +TkOption.add('*Label.ipadX', 200) + +TkOption.add('*tile', texture2) + +class BLT_Calendar_sample + @@monthInfo = [ + nil, # dummy + ['January', 31], + ['February', 28], + ['March', 31], + ['April', 30], + ['May', 31], + ['June', 30], + ['July', 31], + ['August', 31], + ['Septembar', 30], + ['October', 31], + ['November', 30], + ['December', 31] + ] + + @@abbrDays = [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ] + + def initialize() + today = Date.today + + if TkComm.bool(Tk.info(:commands, '.calendar')) + Tk.destroy('.calendar') + end + cal = Tk::BLT::Tile::Frame.new(:widgetname=>'.calendar', + :classname=>'Calendar', + :width=>'3i', :height=>'3i') + + mon = Tk::BLT::Tile::Label.new(cal, :font=>'Courier 14 bold', + :text=>"#{@@monthInfo[today.month][0]} " + + "#{today.year}") + Tk::BLT::Table.add(cal, mon, [1, 0], :cspan=>7, :pady=>10) + + week_f = Tk::BLT::Tile::Frame.new(cal, :widgetname=>'weekframe', + :relief=>:sunken, :borderwidth=>1) + Tk::BLT::Table.add(cal, week_f, [2, 0], :columnspan=>7, :fill=>:both) + + @@abbrDays.each_with_index{|dayName, idx| + Tk::BLT::Table.add(cal, + Tk::BLT::Tile::Label.new(cal, :text=>dayName, + :font=>'Helvetica 12'), + [2, idx], :pady=>2, :padx=>2) + } + + Tk::BLT::Table.itemconfigure(cal, 'c*', 'r2', :pad=>4) + + numDays = @@monthInfo[today.month][1] + week = 0 + cnt = 1 + + wkday = today.wday - ((today.day - 1) % 7) + wkday += 7 if wkday < 0 + + while cnt <= numDays + Tk::BLT::Table.add(cal, + Tk::BLT::Tile::Label.new(cal, :text=>cnt){ + self.configure(:borderwidth=>1, + :relief=>:sunken) if cnt == today.day + }, + [week+3, wkday], :fill=>:both, :ipadx=>10, :ipady=>4) + cnt += 1 + wkday += 1 + if wkday == 7 + week += 1 + wkday = 0 + end + end + + Tk::BLT::Tile::Frame.new(cal, :borderwidth=>1, :relief=>:sunken){|f| + Tk::BLT::Table.add(f, + Tk::BLT::Tile::Button.new(f, :widgetname=>'button', + :command=>proc{exit}, + :borderwidth=>2, + :text=>'Quit'), + :padx=>4, :pady=>4) + Tk::BLT::Table.add(cal, f, [week+4, 5], :cspan=>2, :pady=>4) + } + + Tk::BLT::Table.add(Tk.root, cal, :fill=>:both) + Tk::BLT::Table.itemconfigure(cal, 'r0', :resize=>:none) + end +end + +BLT_Calendar_sample.new + +Tk.mainloop diff --git a/ext/tk/sample/tkextlib/blt/images/chalk.gif b/ext/tk/sample/tkextlib/blt/images/chalk.gif new file mode 100644 index 0000000000000000000000000000000000000000..30d29a72216297fbe3201803c4b3b2a78a95276b GIT binary patch literal 4378 zcmcgu_gfO$|34@iT6Sf)a^gbCG)ImyL&dF$iiqaGi6e7cn%yhzQ5J4149(qbs73RJ z;>gjp(1uzWZmldqE9>41Uwc0P!}t9Bem$>s-p@HsE{>KKp%g#?-vO9;H}`&Kp7(xX zmbW-JyEH$yyfDAAxUjmk_+feJvc z1^jOtg72FfTVFSS5TF18m;fLEfbDk&?HncohJX=Z0HAnG9s+@Y!C;m^S-@n85P%H> zy(p+E4~Qec_K2Y}XlF4I009Fq9`s%uScd@-46ug*)RYN+LjY(GK=GM!A_QR@3GD}9 z9RLv&u!&$Xnc1})0oes35TBxw`5n7O2pAjY2gM%;>)8M*U;<~TdpqDD01O7UH3Afq zDThE1U@&(c;P9C+5rVvk5_IuI5Coe5GaCX%Z9oD6#3=yqw@CnC0{{hW|1$=FySum; zXWJqG1mF%HahU5cgoprRrvkABl)D~}Bk{{L0VqRzSSSRL15o!iz;OrJV$5}b5CIt5 zUDk{vFoKCB2y6ma6mRPS2ng6l^!(c=XuBptAlNY2jthr3_)zg*<6s5qo&h+(oe4PW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-2t7@u2_hw3kn-}UNL?o}^y$HX#Y#Uh&iL$1OQMz+L0>8^2*k;##1!2#whHPZ_r z5Ob~J#`?F|s<1HkC*%U>wzu#Uo~|M((5-DYyP6VnX54ZE;Yusd7fyt$?lDV8F9$a- zYn-^Nf=E8`Btj>mNJBx(uGm(kRl#*$Ae+}%5@rK`xd zlb*w3ax!mM=JnzA+9Zg~ld6hEnw(8aTfgJazCypQ?6Cg*V;t{0nzl1|6t&1oq5BVi zLDqQ_GGSA%#Be zH{qDH1)t?DL~x3wv}9x`l`^8GJmKJ}ooebQVb?W#`029Ja-^D98s>9@t5j0_&L-1T zWPrs>w?8T|KblU;I?|g{wSID=tt<6*4y2G+en+~LvKNIGbb+seS@1*65L1V8C?V}L zt-LGLwWXW5V_Y$sYcBfcT*PSddT+%WX!XDV%=gN@6bzgs+3EQ(7F&Ko%OsKDCUYVR8-r^U$wA*L>u=n7bvk6&Xr zJP{M+7Y}MmTfEPS%~{?ZbisvdG}YFeu_tw#8F;=9K2Yf$*+eQ>&7JkJj&?Cr`>t8k zY1=Yj>5-BIT1{vBGG3iLdWe4@C7sTYvaKjIcH}#H`T@N`c!cJmm2OQ5qCs64+}T;v z-UlTPv2EBaIHcwKC8c7n*=C)udc^L)C;N;hp@d;gFCrq;Q#%iRwo|8eOXsk5%}sn7 zx7{rgZQ=UT)5|6G=X|J~`o9B|=sRdYADwKG-ioS)1dPlvG2M%t$Q#SgwakO z;jI=9R)`LpNR;N-@N>LJyA9BHN@JcFxg)67miyTlN3o{FY{!C0`wCogWPL?h-=dMv zuwxEa;YFnU`Dki}!tb%6*XbyQsFkd6`l1WVWyZDZTCd@}Vz-7Uq{{xj7WrP3# literal 0 HcmV?d00001 diff --git a/ext/tk/sample/tkextlib/blt/images/rain.gif b/ext/tk/sample/tkextlib/blt/images/rain.gif new file mode 100644 index 0000000000000000000000000000000000000000..d7bb417939dfe246c4975da10a5abd9096eeba4e GIT binary patch literal 3785 zcmV;)4mR;eNk%v~VQc_w0O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3PCpKU+v)3En5Ho;@2g?;RgvmFBhZz9&ZC^%X z)8HfolMuoKWpBA><5-nr253waLp9SljZ#v2H5E{$P_)TK3@HNkH&--CD}+@c64wN6 z22f}AXHfuRBWYOi_>Dr8L=oi`w%02Kpk9W~om9i1-AryrK zeFarC8juYpB$OLtL!A>N+($G@u>;Om66QDm5PLL(J&}8;l@y35B4np9vo|Oh&}CCt zh+@G?8(17L$Q<&3d+C*o7j|-9Bu$lJTu^|M2pS$jm3Z28Pc^ZDXcP~pq<*sETeOsY zVOTC6!G`utAJ+af-rcNXxXTvB)SAKHa zdP*At$$eiSGK8lhWuvHk=6&;#b%^+WpE|0Biq$T}2VpwsAfOUwXhCVY5kK(4V}LSM zgsCyDs$O=tMf~KRzY`cbd0^n-0ac|o@mVpp+L{tZ4mxR{RdEsA)n@>ij~xazeQ{vL zb~aynW$5dZ)?nc1i1 literal 0 HcmV?d00001 diff --git a/ext/tk/sample/tkextlib/blt/pareto.rb b/ext/tk/sample/tkextlib/blt/pareto.rb new file mode 100644 index 0000000000..94d5f3f97f --- /dev/null +++ b/ext/tk/sample/tkextlib/blt/pareto.rb @@ -0,0 +1,90 @@ +#!/usr/bin/env ruby + +require 'tk' +require 'tkextlib/blt' + +# Example of a pareto chart. +# +# The pareto chart mixes line and bar elements in the same graph. +# Each processing operating is represented by a bar element. The +# total accumulated defects is displayed with a single line element. +b = Tk::BLT::Barchart.new(:title=>'Defects Found During Inspection', + :font=>'Helvetica 12', :plotpady=>[12, 4], + :width=>'6i', :height=>'5i') +Tk::BLT::Table.add(Tk.root, b, :fill=>:both) + +data = [ + ["Spot Weld", 82, 'yellow'], + ["Lathe", 49, 'orange'], + ["Gear Cut", 38, 'green'], + ["Drill", 24, 'blue'], + ["Grind", 17, 'red'], + ["Lapping", 12, 'brown'], + ["Press", 8, 'purple'], + ["De-burr", 4, 'pink'], + ["Packaging", 3, 'cyan'], + ["Other", 12, 'magenta'] +] + +# Create an X-Y graph line element to trace the accumulated defects. +b.line_create('accum', :label=>'', :symbol=>:none, :color=>'red') + +# Define a bitmap to be used to stipple the background of each bar. +pattern1 = Tk::BLT::Bitmap.define([ [4, 4], [1, 2, 4, 8] ]) + +# For each process, create a bar element to display the magnitude. +count = 0 +sum = 0 +ydata = [0] +xdata = [0] +labels = [] + +data.each{|label, value, color| + count += 1 + b.element_create(label, :xdata=>count, :ydata=>value, :foreground=>color, + :relief=>:solid, :borderwidth=>1, :stipple=>pattern1, + :background=>'lightblue') + labels[count] = label + # Get the total number of defects. + sum += value + ydata << sum + xdata << count +} + +# Configure the coordinates of the accumulated defects, +# now that we know what they are. +b.element_configure('accum', :xdata=>xdata, :ydata=>ydata) + +# Add text markers to label the percentage of total at each point. +xdata.zip(ydata){|x, y| + percent = (y * 100.0) / sum + if x == 0 + text = ' 0%' + else + text = '%.1f' % percent + end + b.marker_create(:text, :coords=>[x, y], :text=>text, :font=>'Helvetica 10', + :foreground=>'red4', :anchor=>:center, :yoffset=>-5) +} + +# Display an auxillary y-axis for percentages. +b.axis_configure('y2', :hide=>false, :min=>0.0, :max=>100.0, + :title=>'Percentage') + +# Title the y-axis +b.axis_configure('y', :title=>'Defects') + +# Configure the x-axis to display the process names, instead of numbers. +b.axis_configure('x', :title=>'Process', :rotate=>90, :subdivisions=>0, + :command=>proc{|w, val| + val = val.round + labels[val]? labels[val]: val + }) + +# No legend needed. +b.legend_configure(:hide=>true) + +# Configure the grid lines. +b.gridline_configure(:mapx=>:x, :color=>'lightblue') + +Tk.mainloop