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/sample/demos-jp/plot.rb

125 lines
3.5 KiB
Ruby
Raw Normal View History

* encoding.c: provide basic features for M17N. * parse.y: encoding aware parsing. * parse.y (pragma_encoding): encoding specification pragma. * parse.y (rb_intern3): encoding specified symbols. * string.c (rb_str_length): length based on characters. for older behavior, bytesize method added. * string.c (rb_str_index_m): index based on characters. rindex as well. * string.c (succ_char): encoding aware succeeding string. * string.c (rb_str_reverse): reverse based on characters. * string.c (rb_str_inspect): encoding aware string description. * string.c (rb_str_upcase_bang): encoding aware case conversion. downcase, capitalize, swapcase as well. * string.c (rb_str_tr_bang): tr based on characters. delete, squeeze, tr_s, count as well. * string.c (rb_str_split_m): split based on characters. * string.c (rb_str_each_line): encoding aware each_line. * string.c (rb_str_each_char): added. iteration based on characters. * string.c (rb_str_strip_bang): encoding aware whitespace stripping. lstrip, rstrip as well. * string.c (rb_str_justify): encoding aware justifying (ljust, rjust, center). * string.c (str_encoding): get encoding attribute from a string. * re.c (rb_reg_initialize): encoding aware regular expression * sprintf.c (rb_str_format): formatting (i.e. length count) based on characters. * io.c (rb_io_getc): getc to return one-character string. for older behavior, getbyte method added. * ext/stringio/stringio.c (strio_getc): ditto. * io.c (rb_io_ungetc): allow pushing arbitrary string at the current reading point. * ext/stringio/stringio.c (strio_ungetc): ditto. * ext/strscan/strscan.c: encoding support. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-24 23:29:39 -04:00
# -*- coding: euc-jp -*-
#
# 2-D plot widget demo (called by 'widget')
#
# toplevel widget <20><>¸<EFBFBD>ߤ<EFBFBD><DFA4><EFBFBD><EFBFBD>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if defined?($plot_demo) && $plot_demo
$plot_demo.destroy
$plot_demo = nil
end
# demo <20>Ѥ<EFBFBD> toplevel widget <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
$plot_demo = TkToplevel.new {|w|
title("Plot Demonstration")
iconname("Plot")
positionWindow(w)
}
# label <20><><EFBFBD><EFBFBD>
TkLabel.new($plot_demo, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left',
'text'=>"<EFBFBD><EFBFBD><EFBFBD>Υ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɥ<EFBFBD><EFBFBD>ϴ<EFBFBD>ñ<EFBFBD><EFBFBD>2<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Υץ<EFBFBD><EFBFBD>åȤ<EFBFBD><EFBFBD>ޤ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Х<EFBFBD> widget<65>Ǥ<EFBFBD><C7A4><EFBFBD>ɽ<EFBFBD><C9BD><EFBFBD><EFBFBD><EFBFBD>줿<EFBFBD><ECA4BF><EFBFBD><EFBFBD><EFBFBD>ޥ<EFBFBD><DEA5><EFBFBD><EFBFBD>ܥ<EFBFBD><DCA5><EFBFBD>1<EFBFBD>ǥɥ<C7A5><C9A5>å<EFBFBD><C3A5><EFBFBD><EFBFBD>ƥǡ<C6A5><C7A1><EFBFBD><EFBFBD>򤤤<EFBFBD><F2A4A4A4><EFBFBD>Ȥ<EFBFBD><C8A4>Ǥ<EFBFBD><C7A4>ޤ<EFBFBD><DEA4><EFBFBD>"){
pack('side'=>'top')
}
# frame <20><><EFBFBD><EFBFBD>
$plot_buttons = TkFrame.new($plot_demo) {|frame|
TkButton.new(frame) {
#text 'λ<><CEBB>'
text '<27>Ĥ<EFBFBD><C4A4><EFBFBD>'
command proc{
tmppath = $plot_demo
$plot_demo = nil
tmppath.destroy
}
}.pack('side'=>'left', 'expand'=>'yes')
TkButton.new(frame) {
text '<27><><EFBFBD><EFBFBD><EFBFBD>ɻ<EFBFBD><C9BB><EFBFBD>'
command proc{showCode 'plot'}
}.pack('side'=>'left', 'expand'=>'yes')
}
$plot_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# font <20><><EFBFBD><EFBFBD>
* 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 01:25:12 -04:00
if $tk_version =~ /^4.*/
plotFont = '-*-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*'
else
font = 'Helvetica 18'
end
# canvas <20><><EFBFBD><EFBFBD>
$plot_canvas = TkCanvas.new($plot_demo,'relief'=>'raised','width'=>450,'height'=>300)
$plot_canvas.pack('side'=>'top', 'fill'=>'x')
# plot <20><><EFBFBD><EFBFBD>
TkcLine.new($plot_canvas, 100, 250, 400, 250, 'width'=>2)
TkcLine.new($plot_canvas, 100, 250, 100, 50, 'width'=>2)
TkcText.new($plot_canvas, 225, 20,
'text'=>"<EFBFBD><EFBFBD>ñ<EFBFBD>ʥץ<EFBFBD><EFBFBD>å<EFBFBD>", 'font'=>plotFont, 'fill'=>'brown')
(0..10).each {|i|
x = 100 + (i * 30)
TkcLine.new($plot_canvas, x, 250, x, 245, 'width'=>2)
TkcText.new($plot_canvas, x, 254,
'text'=>10*i, 'font'=>plotFont, 'anchor'=>'n')
}
(0..5).each {|i|
y = 250 - (i * 40)
TkcLine.new($plot_canvas, 100, y, 105, y, 'width'=>2)
TkcText.new($plot_canvas, 96, y,
'text'=>"#{i*50}.0", 'font'=>plotFont, 'anchor'=>'e')
}
for xx, yy in [[12,56],[20,94],[33,98],[32,120],[61,180],[75,160],[98,223]]
x = 100 + (3*xx)
y = 250 - (4*yy)/5
item = TkcOval.new($plot_canvas, x-6, y-6, x+6, y+6,
'width'=>1, 'outline'=>'black', 'fill'=>'SkyBlue2')
item.addtag 'point'
end
$plot_canvas.itembind('point', 'Any-Enter',
proc{$plot_canvas.itemconfigure 'current','fill','red'})
$plot_canvas.itembind('point', 'Any-Leave',
proc{$plot_canvas.itemconfigure 'current','fill','SkyBlue2'})
$plot_canvas.itembind('point', '1',
proc{|x,y| plotDown $plot_canvas,x,y}, "%x %y")
$plot_canvas.itembind('point', 'ButtonRelease-1',
proc{$plot_canvas.dtag 'selected'})
$plot_canvas.bind('B1-Motion',
proc{|x,y| plotMove $plot_canvas,x,y}, "%x %y")
$plot = {'lastX'=>0, 'lastY'=>0}
# plotDown --
# This method is invoked when the mouse is pressed over one of the
# data points. It sets up state to allow the point to be dragged.
#
# Arguments:
# w - The canvas window.
# x, y - The coordinates of the mouse press.
def plotDown (w, x, y)
w.dtag 'selected'
w.addtag_withtag 'selected', 'current'
w.raise 'current'
$plot['lastX'] = x
$plot['lastY'] = y
end
# plotMove --
# This method is invoked during mouse motion events. It drags the
# current item.
#
# Arguments:
# w - The canvas window.
# x, y - The coordinates of the mouse.
def plotMove (w, x, y)
w.move 'selected', x - $plot['lastX'], y - $plot['lastY']
$plot['lastX'] = x
$plot['lastY'] = y
end