2003-07-31 16:52:40 -04:00
|
|
|
|
#
|
|
|
|
|
# 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',
|
2004-10-11 00:51:21 -04:00
|
|
|
|
'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>"){
|
2003-07-31 16:52:40 -04:00
|
|
|
|
pack('side'=>'top')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# frame <20><><EFBFBD><EFBFBD>
|
|
|
|
|
$plot_buttons = TkFrame.new($plot_demo) {|frame|
|
|
|
|
|
TkButton.new(frame) {
|
2004-05-01 12:09:54 -04:00
|
|
|
|
#text 'λ<><CEBB>'
|
|
|
|
|
text '<27>Ĥ<EFBFBD><C4A4><EFBFBD>'
|
2003-07-31 16:52:40 -04:00
|
|
|
|
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>
|
|
|
|
|
plotFont = '-*-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*'
|
|
|
|
|
|
|
|
|
|
# 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,
|
2004-10-11 00:51:21 -04:00
|
|
|
|
'text'=>"<EFBFBD><EFBFBD>ñ<EFBFBD>ʥץ<EFBFBD><EFBFBD>å<EFBFBD>", 'font'=>plotFont, 'fill'=>'brown')
|
2003-07-31 16:52:40 -04:00
|
|
|
|
|
|
|
|
|
(0..10).each {|i|
|
|
|
|
|
x = 100 + (i * 30)
|
|
|
|
|
TkcLine.new($plot_canvas, x, 250, x, 245, 'width'=>2)
|
|
|
|
|
TkcText.new($plot_canvas, x, 254,
|
2004-10-11 00:51:21 -04:00
|
|
|
|
'text'=>10*i, 'font'=>plotFont, 'anchor'=>'n')
|
2003-07-31 16:52:40 -04:00
|
|
|
|
}
|
|
|
|
|
(0..5).each {|i|
|
|
|
|
|
y = 250 - (i * 40)
|
|
|
|
|
TkcLine.new($plot_canvas, 100, y, 105, y, 'width'=>2)
|
|
|
|
|
TkcText.new($plot_canvas, 96, y,
|
2004-10-11 00:51:21 -04:00
|
|
|
|
'text'=>"#{i*50}.0", 'font'=>plotFont, 'anchor'=>'e')
|
2003-07-31 16:52:40 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,
|
2004-10-11 00:51:21 -04:00
|
|
|
|
'width'=>1, 'outline'=>'black', 'fill'=>'SkyBlue2')
|
2003-07-31 16:52:40 -04:00
|
|
|
|
item.addtag 'point'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
$plot_canvas.itembind('point', 'Any-Enter',
|
2004-10-11 00:51:21 -04:00
|
|
|
|
proc{$plot_canvas.itemconfigure 'current','fill','red'})
|
2003-07-31 16:52:40 -04:00
|
|
|
|
$plot_canvas.itembind('point', 'Any-Leave',
|
2004-10-11 00:51:21 -04:00
|
|
|
|
proc{$plot_canvas.itemconfigure 'current','fill','SkyBlue2'})
|
2003-07-31 16:52:40 -04:00
|
|
|
|
$plot_canvas.itembind('point', '1',
|
2004-10-11 00:51:21 -04:00
|
|
|
|
proc{|x,y| plotDown $plot_canvas,x,y}, "%x %y")
|
2003-07-31 16:52:40 -04:00
|
|
|
|
$plot_canvas.itembind('point', 'ButtonRelease-1',
|
2004-10-11 00:51:21 -04:00
|
|
|
|
proc{$plot_canvas.dtag 'selected'})
|
2003-07-31 16:52:40 -04:00
|
|
|
|
$plot_canvas.bind('B1-Motion',
|
2004-10-11 00:51:21 -04:00
|
|
|
|
proc{|x,y| plotMove $plot_canvas,x,y}, "%x %y")
|
2003-07-31 16:52:40 -04:00
|
|
|
|
|
|
|
|
|
$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:
|
2004-10-11 00:51:21 -04:00
|
|
|
|
# w - The canvas window.
|
|
|
|
|
# x, y - The coordinates of the mouse press.
|
2003-07-31 16:52:40 -04:00
|
|
|
|
|
|
|
|
|
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:
|
2004-10-11 00:51:21 -04:00
|
|
|
|
# w - The canvas window.
|
|
|
|
|
# x, y - The coordinates of the mouse.
|
2003-07-31 16:52:40 -04:00
|
|
|
|
|
|
|
|
|
def plotMove (w, x, y)
|
|
|
|
|
w.move 'selected', x - $plot['lastX'], y - $plot['lastY']
|
|
|
|
|
$plot['lastX'] = x
|
|
|
|
|
$plot['lastY'] = y
|
|
|
|
|
end
|
|
|
|
|
|