From ce1b23b7a5a496f4b6d3ad4627a161b1dc6945fe Mon Sep 17 00:00:00 2001 From: nagai Date: Thu, 15 Jul 2004 01:18:57 +0000 Subject: * ext/tk/, ext/tcltklib/: bug fix * ext/tk/lib/tk.rb: better operation for SIGINT when processing callbacks. * ext/tk/lib/tk/msgcat.rb: ditto. * ext/tk/lib/tk/variable.rb: ditto. * ext/tk/lib/tk/timer.rb: ditto. * ext/tk/lib/tk/validation.rb: add Tk::ValidateConfigure.__def_validcmd() to define validatecommand methods easier * ext/tk/lib/tk.rb (_genobj_for_tkwidget): support autoload Tk ext classes * ext/tk/lib/tk/canvas.rb and so on: remove the parent widget type check for items (e.g. canvas items; depends on the class) to avoid some troubles on Tk extension widget class definition. * ext/tk/lib/tkextlib/: add Iwidget and TkTable extension support * ext/tk/sample/tkextlib/: add samples of Iwidget and TkTable git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6630 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/lib/tkextlib/tcllib/autoscroll.rb | 59 +++++++++++++++++----- ext/tk/lib/tkextlib/tcllib/cursor.rb | 55 +++++++++++++++++--- ext/tk/lib/tkextlib/tcllib/ip_entry.rb | 1 + ext/tk/lib/tkextlib/tcllib/plotchart.rb | 87 +++++++++++++++++++++++--------- ext/tk/lib/tkextlib/tcllib/style.rb | 28 ++++++++-- 5 files changed, 182 insertions(+), 48 deletions(-) (limited to 'ext/tk/lib/tkextlib/tcllib') diff --git a/ext/tk/lib/tkextlib/tcllib/autoscroll.rb b/ext/tk/lib/tkextlib/tcllib/autoscroll.rb index 117ed8d98a..d0cb2812cb 100644 --- a/ext/tk/lib/tkextlib/tcllib/autoscroll.rb +++ b/ext/tk/lib/tkextlib/tcllib/autoscroll.rb @@ -38,31 +38,40 @@ module Tk '' end end + + def self.not_available + fail RuntimeError, "'tkextlib/tcllib/autoscroll' extension is not available on your current environment." + end + + def self.autoscroll(win) + Tk::Tcllib::Autoscroll.not_available + end + + def self.unautoscroll(win) + Tk::Tcllib::Autoscroll.not_available + end end end end -# TkPackage.require('autoscroll', '1.0') -TkPackage.require('autoscroll') - module Tk module Scrollable def autoscroll(mode = nil) case mode when :x, 'x' if @xscrollbar - tk_send_without_enc('::autoscroll::autoscroll', @xscrollbar) + Tk::Tcllib::Autoscroll.autoscroll(@xscrollbar) end when :y, 'y' if @yscrollbar - tk_send_without_enc('::autoscroll::autoscroll', @yscrollbar) + Tk::Tcllib::Autoscroll.autoscroll(@yscrollbar) end when nil, :both, 'both' if @xscrollbar - tk_send_without_enc('::autoscroll::autoscroll', @xscrollbar) + Tk::Tcllib::Autoscroll.autoscroll(@xscrollbar) end if @yscrollbar - tk_send_without_enc('::autoscroll::autoscroll', @yscrollbar) + Tk::Tcllib::Autoscroll.autoscroll(@yscrollbar) end else fail ArgumentError, "'x', 'y' or 'both' (String or Symbol) is expected" @@ -73,18 +82,18 @@ module Tk case mode when :x, 'x' if @xscrollbar - tk_send_without_enc('::autoscroll::unautoscroll', @xscrollbar) + Tk::Tcllib::Autoscroll.unautoscroll(@xscrollbar) end when :y, 'y' if @yscrollbar - tk_send_without_enc('::autoscroll::unautoscroll', @yscrollbar) + Tk::Tcllib::Autoscroll.unautoscroll(@yscrollbar) end when nil, :both, 'both' if @xscrollbar - tk_send_without_enc('::autoscroll::unautoscroll', @xscrollbar) + Tk::Tcllib::Autoscroll.unautoscroll(@xscrollbar) end if @yscrollbar - tk_send_without_enc('::autoscroll::unautoscroll', @yscrollbar) + Tk::Tcllib::Autoscroll.unautoscroll(@yscrollbar) end else fail ArgumentError, "'x', 'y' or 'both' (String or Symbol) is expected" @@ -98,12 +107,36 @@ class TkScrollbar def autoscroll # Arranges for the already existing scrollbar to be mapped # and unmapped as needed. - tk_send_without_enc('::autoscroll::autoscroll', @path) + #tk_call_without_enc('::autoscroll::autoscroll', @path) + Tk::Tcllib::Autoscroll.autoscroll(self) self end def unautoscroll # Returns the scrollbar to its original static state. - tk_send_without_enc('::autoscroll::unautoscroll', @path) + #tk_call_without_enc('::autoscroll::unautoscroll', @path) + Tk::Tcllib::Autoscroll.unautoscroll(self) self end end + +# TkPackage.require('autoscroll', '1.0') +TkPackage.require('autoscroll') + +module Tk + module Tcllib + class << Autoscroll + undef not_available + end + + module Autoscroll + def self.autoscroll(win) + tk_call_without_enc('::autoscroll::autoscroll', win.path) + end + + def self.unautoscroll(win) + tk_call_without_enc('::autoscroll::unautoscroll', win.path) + end + end + end +end + diff --git a/ext/tk/lib/tkextlib/tcllib/cursor.rb b/ext/tk/lib/tkextlib/tcllib/cursor.rb index 119b8a143f..8813aa05dd 100644 --- a/ext/tk/lib/tkextlib/tcllib/cursor.rb +++ b/ext/tk/lib/tkextlib/tcllib/cursor.rb @@ -9,19 +9,32 @@ require 'tk' require 'tkextlib/tcllib.rb' -# TkPackage.require('cursor', '0.1') -TkPackage.require('cursor') - module Tk module Tcllib module Cursor def self.package_version begin - TkPackage.require('ipentry') + TkPackage.require('cursor') rescue '' end end + + def self.not_available + fail RuntimeError, "'tkextlib/tcllib/cursor' extension is not available on your current environment." + end + + def self.cursor_display(win=None) + Tk::Tcllib::Cursor.not_available + end + + def self.cursor_propagate(win, cursor) + Tk::Tcllib::Cursor.not_available + end + + def self.cursor_restore(win, cursor = None) + Tk::Tcllib::Cursor.not_available + end end end @@ -29,20 +42,48 @@ module Tk # Pops up a dialog with a listbox containing all the cursor names. # Selecting a cursor name will display it in that dialog. # This is simply for viewing any available cursors on the platform . - tk_call_without_enc('::cursor::display', parent) + #tk_call_without_enc('::cursor::display', parent) + Tk::Tcllib::Cursor.cursor_display(parent) end end class TkWindow def cursor_propagate(cursor) # Sets the cursor for self and all its descendants to cursor. - tk_send_without_enc('::cursor::propagate', @path, cursor) + #tk_call_without_enc('::cursor::propagate', @path, cursor) + Tk::Tcllib::Cursor.cursor_propagate(cursor) end def cursor_restore(cursor = None) # Restore the original or previously set cursor for self and all its # descendants. If cursor is specified, that will be used if on any # widget that did not have a preset cursor (set by a previous call # to TkWindow#cursor_propagate). - tk_send_without_enc('::cursor::restore', @path, cursor) + #tk_call_without_enc('::cursor::restore', @path, cursor) + Tk::Tcllib::Cursor.cursor_restore(cursor) + end +end + +# TkPackage.require('cursor', '0.1') +TkPackage.require('cursor') + +module Tk + module Tcllib + class << Cursor + undef not_available + end + + module Cursor + def self.cursor_display(win=None) + tk_call_without_enc('::cursor::display', win) + end + + def self.cursor_propagate(win, cursor) + tk_call_without_enc('::cursor::propagate', win.path, cursor) + end + + def self.cursor_restore(win, cursor = None) + tk_call_without_enc('::cursor::restore', win.path, cursor) + end + end end end diff --git a/ext/tk/lib/tkextlib/tcllib/ip_entry.rb b/ext/tk/lib/tkextlib/tcllib/ip_entry.rb index 748478a322..977ef4e5c8 100644 --- a/ext/tk/lib/tkextlib/tcllib/ip_entry.rb +++ b/ext/tk/lib/tkextlib/tcllib/ip_entry.rb @@ -27,6 +27,7 @@ module Tk end end end + IPEntry = IP_Entry end end diff --git a/ext/tk/lib/tkextlib/tcllib/plotchart.rb b/ext/tk/lib/tkextlib/tcllib/plotchart.rb index b22a4ebbdf..65451a27a9 100644 --- a/ext/tk/lib/tkextlib/tcllib/plotchart.rb +++ b/ext/tk/lib/tkextlib/tcllib/plotchart.rb @@ -221,7 +221,10 @@ module Tk::Tcllib::Plotchart class XYPlot < TkCanvas include ChartMethod - TkCommandNames = ['::Plotchart::createXYPlot'.freeze].freeze + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::createXYPlot'.freeze + ].freeze def initialize(*args) # args := ([parent,] xaxis, yaxis [, keys]) # xaxis := Array of [minimum, maximum, stepsize] @@ -248,12 +251,16 @@ module Tk::Tcllib::Plotchart end def _create_chart - p self.class::TkCommandNames[0] if $DEBUG - tk_call_without_enc(self.class::TkCommandNames[0], @path, + p self.class::TkCommandNames[1] if $DEBUG + tk_call_without_enc(self.class::TkCommandNames[1], @path, array2tk_list(@xaxis), array2tk_list(@yaxis)) end private :_create_chart + def __destroy_hook__ + Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.delete(@path) + end + def plot(series, x, y) tk_call_without_enc(@chart, 'plot', _get_eval_enc_str(series), x, y) self @@ -271,14 +278,20 @@ module Tk::Tcllib::Plotchart ############################ class Stripchart < XYPlot - TkCommandNames = ['::Plotchart::createStripchart'.freeze].freeze + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::createStripchart'.freeze + ].freeze end ############################ class PolarPlot < TkCanvas include ChartMethod - TkCommandNames = ['::Plotchart::createPolarplot'.freeze].freeze + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::createPolarplot'.freeze + ].freeze def initialize(*args) # args := ([parent,] radius_data [, keys]) # radius_data := Array of [maximum_radius, stepsize] @@ -302,12 +315,16 @@ module Tk::Tcllib::Plotchart end def _create_chart - p self.class::TkCommandNames[0] if $DEBUG - tk_call_without_enc(self.class::TkCommandNames[0], @path, + p self.class::TkCommandNames[1] if $DEBUG + tk_call_without_enc(self.class::TkCommandNames[1], @path, array2tk_list(@radius_data)) end private :_create_chart + def __destroy_hook__ + Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.delete(@path) + end + def plot(series, radius, angle) tk_call_without_enc(@chart, 'plot', _get_eval_enc_str(series), radius, angle) @@ -329,7 +346,10 @@ module Tk::Tcllib::Plotchart class IsometricPlot < TkCanvas include ChartMethod - TkCommandNames = ['::Plotchart::createIsometricPlot'.freeze].freeze + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::createIsometricPlot'.freeze + ].freeze def initialize(*args) # args := ([parent,] xaxis, yaxis, [, step] [, keys]) # xaxis := Array of [minimum, maximum] @@ -369,8 +389,8 @@ module Tk::Tcllib::Plotchart end def _create_chart - p self.class::TkCommandNames[0] if $DEBUG - tk_call_without_enc(self.class::TkCommandNames[0], @path, + p self.class::TkCommandNames[1] if $DEBUG + tk_call_without_enc(self.class::TkCommandNames[1], @path, array2tk_list(@xaxis), array2tk_list(@yaxis), @stepsize) end @@ -406,7 +426,10 @@ module Tk::Tcllib::Plotchart class Plot3D < TkCanvas include ChartMethod - TkCommandNames = ['::Plotchart::create3DPlot'.freeze].freeze + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::create3DPlot'.freeze + ].freeze def initialize(*args) # args := ([parent,] xaxis, yaxis, zaxis [, keys]) # xaxis := Array of [minimum, maximum, stepsize] @@ -436,8 +459,8 @@ module Tk::Tcllib::Plotchart end def _create_chart - p self.class::TkCommandNames[0] if $DEBUG - tk_call_without_enc(self.class::TkCommandNames[0], @path, + p self.class::TkCommandNames[1] if $DEBUG + tk_call_without_enc(self.class::TkCommandNames[1], @path, array2tk_list(@xaxis), array2tk_list(@yaxis), array2tk_list(@zaxis)) @@ -478,7 +501,10 @@ module Tk::Tcllib::Plotchart class Piechart < TkCanvas include ChartMethod - TkCommandNames = ['::Plotchart::createPiechart'.freeze].freeze + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::createPiechart'.freeze + ].freeze def initialize(*args) # args := ([parent] [, keys]) if args[0].kind_of?(TkCanvas) @@ -491,8 +517,8 @@ module Tk::Tcllib::Plotchart end def _create_chart - p self.class::TkCommandNames[0] if $DEBUG - tk_call_without_enc(self.class::TkCommandNames[0], @path) + p self.class::TkCommandNames[1] if $DEBUG + tk_call_without_enc(self.class::TkCommandNames[1], @path) end private :_create_chart @@ -506,7 +532,10 @@ module Tk::Tcllib::Plotchart class Barchart < TkCanvas include ChartMethod - TkCommandNames = ['::Plotchart::createBarchart'.freeze].freeze + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::createBarchart'.freeze + ].freeze def initialize(*args) # args := ([parent,] xlabels, ylabels [, series] [, keys]) @@ -549,13 +578,17 @@ module Tk::Tcllib::Plotchart end def _create_chart - p self.class::TkCommandNames[0] if $DEBUG - tk_call_without_enc(self.class::TkCommandNames[0], @path, + p self.class::TkCommandNames[1] if $DEBUG + tk_call_without_enc(self.class::TkCommandNames[1], @path, array2tk_list(@xlabels), array2tk_list(@ylabels), @series_size) end private :_create_chart + def __destroy_hook__ + Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.delete(@path) + end + def plot(series, dat, col=None) tk_call_without_enc(@chart, 'plot', series, dat, col) self @@ -573,14 +606,20 @@ module Tk::Tcllib::Plotchart ############################ class HorizontalBarchart < Barchart - TkCommandNames = ['::Plotchart::createHorizontalBarchart'.freeze].freeze + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::createHorizontalBarchart'.freeze + ].freeze end ############################ class Timechart < TkCanvas include ChartMethod - TkCommandNames = ['::Plotchart::createTimechart'.freeze].freeze + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::createTimechart'.freeze + ].freeze def initialize(*args) # args := ([parent,] time_begin, time_end, items [, keys]) @@ -612,8 +651,8 @@ module Tk::Tcllib::Plotchart end def _create_chart - p self.class::TkCommandNames[0] if $DEBUG - tk_call_without_enc(self.class::TkCommandNames[0], @path, + p self.class::TkCommandNames[1] if $DEBUG + tk_call_without_enc(self.class::TkCommandNames[1], @path, @time_begin, @time_end, @items) end private :_create_chart @@ -650,7 +689,7 @@ module Tk::Tcllib::Plotchart @parent = @chart_obj = chart @ppath = @chart_obj.path @path = @series = @id = Series_ID.join(TkCore::INTERP._ip_id_) - SeriesID_TBL[@id] = self + # SeriesID_TBL[@id] = self SeriesID_TBL[@ppath] = {} unless SeriesID_TBL[@ppath] SeriesID_TBL[@ppath][@id] = self Series_ID[1].succ! diff --git a/ext/tk/lib/tkextlib/tcllib/style.rb b/ext/tk/lib/tkextlib/tcllib/style.rb index dea2962b7f..17fc834ccb 100644 --- a/ext/tk/lib/tkextlib/tcllib/style.rb +++ b/ext/tk/lib/tkextlib/tcllib/style.rb @@ -9,10 +9,7 @@ require 'tk' require 'tkextlib/tcllib.rb' -# TkPackage.require('style', '0.1') -TkPackage.require('style') - -module Tk +module Tk::Tcllib module Style def self.package_version begin @@ -22,6 +19,29 @@ module Tk end end + def self.not_available + fail RuntimeError, "'tkextlib/tcllib/style' extension is not available on your current environment." + end + + def self.names + Tk::Tcllib::Style.not_available + end + + def self.use(style) + Tk::Tcllib::Style.not_available + end + end +end + +# TkPackage.require('style', '0.1') +TkPackage.require('style') + +module Tk::Tcllib + class << Style + undef not_available + end + + module Style def self.names tk_split_simplelist(tk_call('style::names')) end -- cgit v1.2.3