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-en/rolodex-j

325 lines
7.8 KiB
Text
Raw Normal View History

#!/usr/bin/env ruby
#
# rolodex --
# <20><><EFBFBD>Υ<EFBFBD><CEA5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ץȤ<D7A5> Tom LaStrange <20><> rolodex <20>ΰ<EFBFBD><CEB0><EFBFBD><EFBFBD>Ǥ<EFBFBD><C7A4><EFBFBD>
#
# Copyright (C) 1998 by Takaaki Tateishi <ttate@jaist.ac.jp>
# Time-stamp: "98/07/20 12:00:36 ttate"
#
require "tk"
require 'tkencoding'
Tk.encoding = "euc-jp"
$font = TkFont.new('k14')
def show_help(topic,x=0,y=0)
if( topic.is_a?(TkWindow) )
w = TkWinfo.containing(x,y)
if( w.is_a?(TkWindow) )
if( TkWinfo.exist?(w) )
topic = w
end
end
end
if( $helpTopics.include?(topic) )
msg = $helpTopics[topic]
else
msg = "<22><><EFBFBD>Υȥԥå<D4A5><C3A5>ˤĤ<CBA4><C4A4>ƤΥإ<CEA5><D8A5>פϤޤ<CFA4><DEA4><EFBFBD><EFBFBD>ѤǤ<D1A4><C7A4>ޤ<EFBFBD><DEA4><EFBFBD>"
end
TkDialog.new("title"=>"Rolodex Help",
"message"=>"<22><>#{topic}<7D><>\n\n#{msg}",
"font"=>$font,
"default_button"=>0,
"buttons"=>["OK"])
end
def fillCard
clearAction
$root.frame.entry[1].insert(0, "Ω<><CEA9> <20><><EFBFBD><EFBFBD>")
$root.frame.entry[2].insert(0, "923-1292 <20><><EFBFBD>")
$root.frame.entry[3].insert(0, "ä<><C3A4>Į <20><><EFBFBD><EFBFBD> 1-1")
$root.frame.entry[4].insert(0, "<22><>Φ<EFBFBD><CEA6>ü<EFBFBD>ʳص<CAB3><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD>")
$root.frame.entry[5].insert(0,"private")
$root.frame.entry[6].insert(0,"***-***-****")
$root.frame.entry[7].insert(0,"***-***-****")
end
def addAction
for i in 1..7
STDERR.print format("%-12s %s\n",
RolodexFrame::LABEL[i],
$root.frame.entry[i].value)
end
end
def clearAction
for i in 1..7
$root.frame.entry[i].delete(0,"end")
end
end
def fileAction
TkDialog.new("title"=>"File Selection",
"message"=>"<22><><EFBFBD><EFBFBD><EFBFBD>ϥե<CFA5><D5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Υ<EFBFBD><CEA5>ߡ<EFBFBD><DFA1>Ǥ<EFBFBD><C7A4><EFBFBD>\n",
"font"=>$font,
"default_button"=>0,
"buttons"=>["OK"])
STDERR.print "dummy file name\n"
end
def deleteAction
result = TkDialog.new("title"=>"Confirm Action",
"message"=>"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǥ<EFBFBD><C7A4><EFBFBD><EFBFBD><EFBFBD>",
"font"=>$font,
"default_button"=>0,
"buttons"=>["<22><><EFBFBD><EFBFBD><EFBFBD>󥻥<EFBFBD>"])
if( result.value == 0 )
clearAction
end
end
class RolodexFrame < TkFrame
attr_reader :entry, :label
LABEL = ["","̾<><CCBE>:","<22><><EFBFBD><EFBFBD>","","","<22><><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD>):","<22><><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD>):","Fax:"]
def initialize(parent=nil,keys=nil)
super(parent,keys)
self["relief"] = "flat"
@i = []
@label = []
@entry = []
for i in 1..7
@i[i] = TkFrame.new(self)
@i[i].pack("side"=>"top",
"pady"=>2,
"anchor"=>"e")
@label[i] = TkLabel.new(@i[i],
"text"=>LABEL[i],
"anchor"=>"e",
"font" => $font)
@entry[i] = TkEntry.new(@i[i],
"width"=>30,
"relief"=>"sunken",
"font" => $font)
@entry[i].pack("side"=>"right")
@label[i].pack("side"=>"right")
end
end
end
class RolodexButtons < TkFrame
attr_reader :clear, :add, :search, :delete
def initialize(parent,keys=nil)
super(parent,keys)
@clear = TkButton.new(self,
"text" => "<22><><EFBFBD><EFBFBD><EAA5A2>",
"font" => $font)
@add = TkButton.new(self,
"text" => "<22>ɲ<EFBFBD>",
"font" => $font)
@search = TkButton.new(self,
"text" => "<22><><EFBFBD><EFBFBD>",
"font" => $font)
@delete = TkButton.new(self,
"text" => "<22>õ<EFBFBD>",
"font" => $font)
for w in [@clear,@add,@search,@delete]
w.pack("side"=>"left", "padx"=>2)
end
end
end
class RolodexMenuFrame < TkFrame
attr_reader :file_menu, :help_menu, :file, :help
def initialize(parent,keys=nil)
super(parent,keys)
configure("relief"=>"raised",
"borderwidth"=>1)
@file = TkMenubutton.new(self,
"text"=> "<22>ե<EFBFBD><D5A5><EFBFBD><EFBFBD><EFBFBD>",
"font"=> $font,
"underline"=>0)
@file_menu = TkMenu.new(@file)
@file_menu.add("command",
"label" => "<22>ɤ߹<C9A4><DFB9><EFBFBD> ...",
"font" => $font,
"command" => proc{fileAction},
"underline" => 0)
@file_menu.add("command",
"label" => "<22><>λ",
"font" => $font,
"command" => proc{$root.destroy},
"underline" => 0)
@file.menu(@file_menu)
@file.pack("side"=>"left")
@help = TkMenubutton.new(self,
"text"=> "<22>إ<EFBFBD><D8A5><EFBFBD>",
"font"=> $font,
"underline"=>0)
@help_menu = TkMenu.new(@help)
@help_menu.add("command",
"label"=> "<22><><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD><C6A5><EFBFBD><EFBFBD>ȤˤĤ<CBA4><C4A4><EFBFBD>",
"font" => $font,
"command"=>proc{show_help("<22><><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD><C6A5><EFBFBD><EFBFBD><EFBFBD>")},
"underline"=>3)
@help_menu.add("command",
"label"=> "<22>إ<EFBFBD><D8A5>פˤĤ<CBA4><C4A4><EFBFBD>",
"font" => $font,
"command"=>proc{show_help("<22>إ<EFBFBD><D8A5><EFBFBD>")},
"underline"=>3)
@help_menu.add("command",
"label"=> "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɥ<EFBFBD><C9A5>ˤĤ<CBA4><C4A4><EFBFBD>",
"font" => $font,
"command"=>proc{show_help("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɥ<EFBFBD>")},
"underline"=>3)
@help_menu.add("command",
"label"=> "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˤĤ<CBA4><C4A4><EFBFBD>",
"font" => $font,
"command"=>proc{show_help("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")},
"underline"=>3)
@help_menu.add("command",
"label"=> "<22>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"font" => $font,
"command"=>proc{show_help("<22>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")},
"underline"=>3)
@help.menu(@help_menu)
@help.pack("side"=>"right")
end
end
class Rolodex < TkRoot
attr_reader :frame, :buttons, :menu
def initialize
super
@frame = RolodexFrame.new(self)
@frame.pack("side"=>"top",
"fill"=>"y",
"anchor"=>"center")
@buttons = RolodexButtons.new(self)
@buttons.pack("side"=>"bottom",
"pady"=>2,
"anchor"=>"center")
@menu = RolodexMenuFrame.new(self)
@menu.pack("before"=>@frame,
"side"=>"top",
"fill"=>"x")
end
end
$root = Rolodex.new
$root.buttons.delete.configure("command"=>proc{deleteAction})
$root.buttons.add.configure("command"=>proc{addAction})
$root.buttons.clear.configure("command"=>proc{clearAction})
$root.buttons.search.configure("command"=>proc{addAction; fillCard})
$root.buttons.clear.configure("text"=> "<22><><EFBFBD><EFBFBD><EAA5A2> Ctrl+C", "font" => $font)
$root.bind("Control-c",proc{clearAction})
$root.buttons.add.configure("text"=> "<22>ɲ<EFBFBD> Ctrl+A", "font" => $font)
$root.bind("Control-a",proc{addAction})
$root.buttons.search.configure("text"=> "<22><><EFBFBD><EFBFBD> Ctrl+S", "font" => $font)
$root.bind("Control-s",proc{addAction; fillCard})
$root.buttons.delete.configure("text"=> "<22>õ<EFBFBD> Ctrl+D", "font" => $font)
$root.bind("Control-d",proc{deleteAction})
$root.menu.file_menu.entryconfigure(1, "accel"=>"Ctrl+F")
$root.bind("Control-f",proc{fileAction})
$root.menu.file_menu.entryconfigure(2, "accel"=>"Ctrl+Q")
$root.bind("Control-q",proc{$root.destroy})
$root.frame.entry[1].focus
$root.bind("Any-F1",
proc{|event| show_help(event.widget, event.x_root, event.y_root)})
$root.bind("Any-Help",
proc{|event| show_help(event.widget, event.x_root, event.y_root)})
$helpTopics = {}
$helpTopics[$root.menu.file] = <<EOF
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϡ֥ե<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ץ<EFBFBD><EFBFBD>˥塼<EFBFBD>Ǥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɤ߹<EFBFBD><EFBFBD>ߡפ<EFBFBD><EFBFBD>ֽ<EFBFBD>λ<EFBFBD>פʤɤ<EFBFBD>
<EFBFBD>Ԥʤ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȥ<EFBFBD><EFBFBD>Ǥ<EFBFBD><EFBFBD>ޤ<EFBFBD><EFBFBD><EFBFBD>
EOF
$helpTopics[$root.menu.file_menu.index(0)] = <<EOF
<EFBFBD>ե<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɤ߹<EFBFBD><EFBFBD>ߤ<EFBFBD><EFBFBD>Ԥʤ<EFBFBD><EFBFBD>Ȥ<EFBFBD><EFBFBD>˻Ȥ<EFBFBD><EFBFBD>ޤ<EFBFBD><EFBFBD><EFBFBD>
EOF
$helpTopics[$root.menu.file_menu.index(1)] = <<EOF
<EFBFBD><EFBFBD><EFBFBD>ץꥱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȥ<EFBFBD><EFBFBD>˻Ȥ<EFBFBD><EFBFBD>ޤ<EFBFBD><EFBFBD><EFBFBD>
EOF
$helpTopics[$root.frame.entry[1]] = <<EOF
̾<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȥ<EFBFBD><EFBFBD>Ǥ<EFBFBD><EFBFBD><EFBFBD>
EOF
$helpTopics[$root.frame.entry[2]] = <<EOF
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȥ<EFBFBD><EFBFBD>Ǥ<EFBFBD><EFBFBD><EFBFBD>
EOF
$helpTopics[$root.frame.entry[3]] = <<EOF
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȥ<EFBFBD><EFBFBD>Ǥ<EFBFBD><EFBFBD><EFBFBD>
EOF
$helpTopics[$root.frame.entry[4]] = <<EOF
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȥ<EFBFBD><EFBFBD>Ǥ<EFBFBD><EFBFBD><EFBFBD>
EOF
$helpTopics[$root.frame.entry[5]] = <<EOF
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȥ<EFBFBD><EFBFBD>Ǥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʤ<EFBFBD><EFBFBD>Ȥ<EFBFBD><EFBFBD><EFBFBD> private <20>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ޤ<EFBFBD><DEA4><EFBFBD>
EOF
$helpTopics[$root.frame.entry[6]] = <<EOF
<EFBFBD><EFBFBD><EFBFBD>Ҥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȥ<EFBFBD><EFBFBD>Ǥ<EFBFBD><EFBFBD><EFBFBD>
EOF
$helpTopics[$root.frame.entry[7]] = <<EOF
FAX<EFBFBD>ֹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȥ<EFBFBD><EFBFBD>Ǥ<EFBFBD><EFBFBD><EFBFBD>
EOF
$helpTopics["<22><><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD><C6A5><EFBFBD><EFBFBD><EFBFBD>"] = <<EOF
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