1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/ext/tk/lib/tkextlib/tcllib/tkpiechart.rb
nagai 3024ffdc3a * ext/tk/*: full update Ruby/Tk to support Ruby(1.9|1.8) and Tc/Tk8.5.
* ext/tk/lib/tkextlib/tile.rb: [incompatible] remove TileWidgets' 
  instate/state/identify method to avoid the conflict with standard
  widget options. Those methods are renamed to ttk_instate/ttk_state/
  ttk_identify (tile_instate/tile_state/tile_identify are available 
  too). Although I don't recommend, if you realy need old methods, 
  please define "Tk::USE_OBSOLETE_TILE_STATE_METHOD = true" before 
  "require 'tkextlib/tile'".

* ext/tk/lib/tkextlib/tile.rb: "Tk::Tile::__Import_Tile_Widgets__!"
  is obsolete. It outputs warning. To control default widget set, 
  use "Tk.default_widget_set = :Ttk".

* ext/tk/lib/tk.rb: __IGNORE_UNKNOWN_CONFIGURE_OPTION__ method and 
  __set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode) method are defind 
  as module methods of TkConfigMethod. It may help users to wrap old 
  Ruby/Tk scripts (use standard widgets) to force to use Ttk widgets.
  Ttk widgets don't have some options of standard widgets which are 
  control the view of widgets. When set ignore-mode true, configure 
  method tries to ignoure such unknown options with no exception. 
  Of course, it may raise other troubles on the GUI design. 
  So, those are a little danger methods. 

* ext/tk/lib/tk/itemconfig.rb: __IGNORE_UNKNOWN_CONFIGURE_OPTION__ 
  method and __set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode) method 
  are defind as module methods of TkItemConfigMethod as the same 
  purpose as TkConfigMethod's ones.

* ext/tk/sample/ttk_wrapper.rb: A new example. This is a tool for 
  wrapping old Ruby/Tk scripts (which use standard widgets) to use 
  Ttk (Tile) widgets as default.

* ext/tk/sample/tkextlib/tile/demo.rb: use ttk_instate/ttk_state 
  method instead of instate/state method.

* ext/tk/lib/tk/root, ext/tk/lib/tk/namespace.rb,
  ext/tk/lib/tk/text.rb, ext/tk/lib/tkextlib/*: some 'instance_eval's  
  are replaced to "instance_exec(self)".

* ext/tk/lib/tk/event.rb: bug fix on KEY_TBL and PROC_TBL (?x is not 
  a character code on Ruby1.9).

* ext/tk/lib/tk/variable.rb: support new style of operation argument 
  on Tcl/Tk's 'trace' command for variables. 

* ext/tk/sample/demos-jp/widget, ext/tk/sample/demos-en/widget: bug fix

* ext/tk/sammple/demos-jp/textpeer.rb, 
  ext/tk/sammple/demos-en/textpeer.rb: new widget demo.

* ext/tk/tcltklib.c: decrase SEGV troubles (probably)

* ext/tk/lib/tk.rb: remove Thread.critical access if Ruby1.9

* ext/tk/lib/tk/multi-tk.rb: support Ruby1.9 (probably)

* ext/tk/lib/tkextlib/tile.rb: add method to define Tcl/Tk command 
  to make Tcl/Tk theme sources (based on different version of Tile 
  extension) available. 
  (Tk::Tile::__define_LoadImages_proc_for_comaptibility__)

* ext/tk/lib/tk.rb, ext/tk/lib/tk/wm.rb: support dockable frames
  (Tcl/Tk8.5 feature). 'wm' command can treat many kinds of widgets 
  as toplevel widgets.

* ext/tk/lib/tkextlib/tile/style.rb: ditto.
  (Tk::Tile::Style.__define_wrapper_proc_for_compatibility__)

* ext/tk/lib/tk/font.rb: add actual_hash and metrics_hash to get 
  properties as a hash. metrics_hash method returns a boolean value 
  for 'fixed' option. But metrics method returns numeric value 
  (0 or 1) for 'fixed' option, because of backward compatibility. 

* ext/tk/lib/tk/timer.rb: somtimes fail to set callback procedure.

* ext/tk/lib/tk.rb: add Tk.sleep and Tk.wakeup method. Tk.sleep 
  doesn't block the eventloop. It will be better to use the method 
  in event callbacks.

* ext/tk/sample/tksleep_sample.rb: sample script about Tk.sleep.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15848 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-03-29 05:25:12 +00:00

314 lines
7 KiB
Ruby

#
# tkextlib/tcllib/tkpiechart.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
# * Part of tcllib extension
# * Create 2D or 3D pies with labels in Tcl canvases
#
require 'tk'
require 'tk/canvas'
require 'tkextlib/tcllib.rb'
# TkPackage.require('tkpiechart', '6.6')
TkPackage.require('tkpiechart')
module Tk
module Tcllib
module Tkpiechart
end
end
end
module Tk::Tcllib::Tkpiechart
PACKAGE_NAME = 'tkpiechart'.freeze
def self.package_name
PACKAGE_NAME
end
def self.package_version
begin
TkPackage.require('tkpiechart')
rescue
''
end
end
module ConfigMethod
include TkConfigMethod
def __pathname
self.path + ';' + self.tag
end
private :__pathname
def __cget_cmd
['::switched::cget', self.tag]
end
def __config_cmd
['::switched::configure', self.tag]
end
private :__config_cmd
def __configinfo_struct
{:key=>0, :alias=>nil, :db_name=>nil, :db_class=>nil,
:default_value=>1, :current_value=>2}
end
private :__configinfo_struct
def __boolval_optkeys
super() << 'select' << 'autoupdate' << 'selectable'
end
private :__boolval_optkeys
def __strval_optkeys
super() << 'bordercolor' << 'textbackground' <<
'widestvaluetext' << 'title'
end
private :__strval_optkeys
def __listval_optkeys
super() << 'colors'
end
private :__listval_optkeys
end
####################################
class PieChartObj < TkcItem
include ConfigMethod
def __font_optkeys
['titlefont']
end
private :__font_optkeys
end
####################################
class Pie < TkcItem
include ConfigMethod
def create_self(x, y, width, height, keys=None)
if keys and keys != None
@tag_key = tk_call_without_enc('::stooop::new', 'pie',
@c, x, y, *hash_kv(keys, true))
else
@tag_key = tk_call_without_enc('::stooop::new', 'pie', @c, x, y)
end
@slice_tbl = {}
id = "pie(#{@tag_key})"
@tag = @tag_pie = TkcNamedTag(@c, id)
@tag_slices = TkcNamedTag(@c, "pieSlices(#{@tag_key})")
id
end
private :create_self
def tag_key
@tag_key
end
def tag
@tag
end
def canvas
@c
end
def _entry_slice(slice)
@slice_tbl[slice.to_eval] = slice
end
def _delete_slice(slice)
@slice_tbl.delete(slice.to_eval)
end
def delete
tk_call_without_enc('::stooop::delete', @tag_key)
CItemID_TBL.mutex.synchronize{
CItemID_TBL[@path].delete(@id) if CItemID_TBL[@path]
}
self
end
def new_slice(text=None)
Slice.new(self, text)
end
def delete_slice(slice)
unless slice.kind_of?(Slice)
unless (slice = @slice_tbl[slice])
return tk_call_without_enc('pie::deleteSlice', @tag_key, slice)
end
end
unless slice.kind_of?(Slice) && slice.pie == self
fail ArgumentError, "argument is not a slice of self"
end
slice.delete
end
def selected_slices
tk_split_simplelist(tk_call_without_enc('pie::selectedSlices',
@tag_key)).collect{|slice|
@slice_tbl[slice] || Slice.new(:no_create, self, slice)
}
end
end
####################################
class Slice < TkcItem
include ConfigMethod
def __config_cmd
['::switched::configure', self.tag]
end
private :__config_cmd
#------------------------
def initialize(pie, *args)
unless pie.kind_of?(Pie) && pie != :no_create
fail ArgumentError, "expects TkPiechart::Pie for 1st argument"
end
if pie == :no_create
@pie, @tag_key = args
else
text = args[0] || None
@pie = pie
@tag_key = tk_call_without_enc('pie::newSlice', @pie.tag_key, text)
end
@parent = @c = @pie.canvas
@path = @parent.path
@pie._entry_slice(self)
@id = "slices(#{@tag_key})"
@tag = TkcNamedTag.new(@pie.canvas, @id)
CItemID_TBL.mutex.synchronize{
CItemID_TBL[@path] = {} unless CItemID_TBL[@path]
CItemID_TBL[@path][@id] = self
}
end
def tag_key
@tag_key
end
def tag
@tag
end
def pie
@pie
end
def delete
tk_call_without_enc('pie::deleteSlice', @pie.tag_key, @tag_key)
CItemID_TBL.mutex.synchronize{
CItemID_TBL[@path].delete(@id) if CItemID_TBL[@path]
}
@pie._delete_slice(self)
self
end
def size(share, disp=None)
tk_call_without_enc('pie::sizeSlice',
@pie.tag_key, @tag_key, share, disp)
self
end
def label(text)
tk_call_without_enc('pie::labelSlice', @pie.tag_key, @tag_key, text)
self
end
end
####################################
class BoxLabeler < TkcItem
include ConfigMethod
def __config_cmd
['::switched::configure', self.tag]
end
private :__config_cmd
#------------------------
def create_self(keys=None)
if keys and keys != None
@tag_key = tk_call_without_enc('::stooop::new', 'pieBoxLabeler',
*hash_kv(keys, true))
else
@tag_key = tk_call_without_enc('::stooop::new', 'pieBoxLabeler')
end
id = "pieBoxLabeler(#{@tag_key})"
@tag = TkcNamedTag(@c, id)
id
end
private :create_self
end
####################################
class PeripheralLabeler < TkcItem
include ConfigMethod
def __font_optkeys
['font', 'smallfont']
end
private :__font_optkeys
def __config_cmd
['::switched::configure', self.tag]
end
private :__config_cmd
#------------------------
def create_self(keys=None)
if keys and keys != None
@tag_key = tk_call_without_enc('::stooop::new',
'piePeripheralLabeler',
*hash_kv(keys, true))
else
@tag_key = tk_call_without_enc('::stooop::new', 'piePeripheralLabeler')
end
id = "piePeripheralLabeler(#{@tag_key})"
@tag = TkcNamedTag(@c, id)
id
end
private :create_self
end
####################################
class Label < TkcItem
include ConfigMethod
def __config_cmd
['::switched::configure', self.tag]
end
private :__config_cmd
#------------------------
def create_self(x, y, keys=None)
if keys and keys != None
@tag_key = tk_call_without_enc('::stooop::new', 'canvasLabel',
@c, x, y, width, height,
*hash_kv(keys, true))
else
@tag_key = tk_call_without_enc('::stooop::new', 'canvasLabel',
@c, x, y, width, height)
end
id = "canvasLabel(#{@tag_key})"
@tag = TkcNamedTag(@c, id)
id
end
private :create_self
end
end