Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > media > main > by-pkgid > e2a5fef11a7f55d2dc803b8b7498c8e5 > files > 407

ruby-tcltk-1.8.5-31.el5_9.x86_64.rpm

#!/usr/bin/env ruby
#
# rolodex --
# ¤³¤Î¥¹¥¯¥ê¥×¥È¤Ï Tom LaStrange ¤Î rolodex ¤Î°ìÉô¤Ç¤¹¡£
# 
# Copyright (C) 1998 by Takaaki Tateishi <ttate@jaist.ac.jp>
# Time-stamp: "03/08/02 14:02:04 nagai"
#

require "tk"

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 = "¤³¤Î¥È¥Ô¥Ã¥¯¤Ë¤Ä¤¤¤Æ¤Î¥Ø¥ë¥×¤Ï¤Þ¤À»ÈÍѤǤ­¤Þ¤»¤ó"
  end
  TkDialog.new("title"=>"Rolodex Help",
	       "message"=>"¡Ö#{topic}¡×\n\n#{msg}",
	       "font"=>$font,
	       "default_button"=>0,
	       "buttons"=>["OK"])
end

def fillCard
  clearAction
  $root.frame.entry[1].insert(0, "ΩÀÐ ¹§¾´")
  $root.frame.entry[2].insert(0, "923-1292 ÀÐÀ")
  $root.frame.entry[3].insert(0, "ä¸ýÄ® °°Âæ 1-1")
  $root.frame.entry[4].insert(0, "ËÌΦÀèü²Ê³Øµ»½ÑÂç³Ø±¡Âç³Ø")
  $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"=>"¤³¤ì¤Ï¥Õ¥¡¥¤¥ëÁªÂò¥À¥¤¥¢¥í¥°¤Î¥À¥ß¡¼¤Ç¤¹¡£\n",
	       "font"=>$font,
	       "default_button"=>0,
	       "buttons"=>["OK"])
  STDERR.print "dummy file name\n"
end

def deleteAction
  result = TkDialog.new("title"=>"Confirm Action",
			"message"=>"¤è¤í¤·¤¤¤Ç¤¹¤«¡©",
			"font"=>$font,
			"default_button"=>0,
			"buttons"=>["¥­¥ã¥ó¥»¥ë"])
  if( result.value == 0 )
    clearAction
  end
end


class RolodexFrame < TkFrame
  attr_reader :entry, :label

  LABEL = ["","̾Á°:","½»½ê","","","ÅÅÏÃ(¼«Âð):","ÅÅÏÃ(²ñ¼Ò):","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" => "¥¯¥ê¥¢¡¼",
			  "font" => $font)
    @add = TkButton.new(self,
			"text" => "ÄɲÃ",
			"font" => $font)
    @search = TkButton.new(self,
			   "text" => "¸¡º÷",
			   "font" => $font)
    @delete = TkButton.new(self,
			   "text" => "¾Ãµî",
			   "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"=> "¥Õ¥¡¥¤¥ë",
			     "font"=> $font,
			     "underline"=>0)
    @file_menu = TkMenu.new(@file)
    @file_menu.add("command",
		   "label" => "Æɤ߹þ¤ß ...",
		   "font" => $font,
		   "command" => proc{fileAction},
		   "underline" => 0)
    @file_menu.add("command",
		   "label" => "½ªÎ»",
		   "font" => $font,
		   "command" => proc{$root.destroy},
		   "underline" => 0)
    @file.menu(@file_menu)
    @file.pack("side"=>"left")

    @help = TkMenubutton.new(self,
			     "text"=> "¥Ø¥ë¥×",
			     "font"=> $font,
			     "underline"=>0)
    @help_menu = TkMenu.new(@help)
    @help_menu.add("command",
		   "label"=> "¥³¥ó¥Æ¥­¥¹¥È¤Ë¤Ä¤¤¤Æ",
		   "font" => $font,
		   "command"=>proc{show_help("¥³¥ó¥Æ¥­¥¹¥È")},
		   "underline"=>3)
    @help_menu.add("command",
		   "label"=> "¥Ø¥ë¥×¤Ë¤Ä¤¤¤Æ",
		   "font" => $font,
		   "command"=>proc{show_help("¥Ø¥ë¥×")},
		   "underline"=>3)
    @help_menu.add("command",
		   "label"=> "¥¦¥£¥ó¥É¥¦¤Ë¤Ä¤¤¤Æ",
		   "font" => $font,
		   "command"=>proc{show_help("¥¦¥£¥ó¥É¥¦")},
		   "underline"=>3)
    @help_menu.add("command",
		   "label"=> "¥­¡¼Áàºî¤Ë¤Ä¤¤¤Æ",
		   "font" => $font,
		   "command"=>proc{show_help("¥­¡¼Áàºî")},
		   "underline"=>3)
    @help_menu.add("command",
		   "label"=> "¥Ð¡¼¥¸¥ç¥ó¾ðÊó",
		   "font" => $font,
		   "command"=>proc{show_help("¥Ð¡¼¥¸¥ç¥ó¾ðÊó")},
		   "underline"=>3)
    @help.menu(@help_menu)
    @help.pack("side"=>"right")
  end
end

class Rolodex < TkRoot
  attr_reader :frame, :buttons, :menu

  def initialize(*args)
    super(*args)
    @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"=> "¥¯¥ê¥¢¡¼   Ctrl+C", "font" => $font)
$root.bind("Control-c",proc{clearAction})

$root.buttons.add.configure("text"=> "Äɲà   Ctrl+A", "font" => $font)
$root.bind("Control-a",proc{addAction})

$root.buttons.search.configure("text"=> "¸¡º÷   Ctrl+S", "font" => $font)
$root.bind("Control-s",proc{addAction; fillCard})

$root.buttons.delete.configure("text"=> "¾Ãµî   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
¤³¤ì¤Ï¡Ö¥Õ¥¡¥¤¥ë¡×¥á¥Ë¥å¡¼¤Ç¤¹¡£¡ÖÆɤ߹þ¤ß¡×¤ä¡Ö½ªÎ»¡×¤Ê¤É¤ò
¹Ô¤Ê¤¦¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
EOF

$helpTopics[$root.menu.file_menu.index(0)] = <<EOF
¥Õ¥¡¥¤¥ë¤ÎÆɤ߹þ¤ß¤ò¹Ô¤Ê¤¦¤È¤­¤Ë»È¤¤¤Þ¤¹¡£
EOF

$helpTopics[$root.menu.file_menu.index(1)] = <<EOF
¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤ò½ªÎ»¤¹¤ë¤È¤­¤Ë»È¤¤¤Þ¤¹¡£
EOF

$helpTopics[$root.frame.entry[1]] = <<EOF
̾Á°¤òµ­Æþ¤¹¤ë¥¨¥ó¥È¥ê¤Ç¤¹¡£
EOF

$helpTopics[$root.frame.entry[2]] = <<EOF
½»½ê¤òµ­Æþ¤¹¤ë¥¨¥ó¥È¥ê¤Ç¤¹¡£
EOF

$helpTopics[$root.frame.entry[3]] = <<EOF
½»½ê¤òµ­Æþ¤¹¤ë¥¨¥ó¥È¥ê¤Ç¤¹¡£
EOF

$helpTopics[$root.frame.entry[4]] = <<EOF
½»½ê¤òµ­Æþ¤¹¤ë¥¨¥ó¥È¥ê¤Ç¤¹¡£
EOF

$helpTopics[$root.frame.entry[5]] = <<EOF
¼«Âð¤ÎÅÅÏÃÈÖ¹æ¤òµ­Æþ¤¹¤ë¥¨¥ó¥È¥ê¤Ç¤¹¡£¸ø³«\
¤·¤¿¤¯¤Ê¤¤¤È¤­¤Ï private ¤Èµ­Æþ¤·¤Þ¤¹¡£
EOF

$helpTopics[$root.frame.entry[6]] = <<EOF
²ñ¼Ò¤ÎÅÅÏÃÈÖ¹æ¤òµ­Æþ¤¹¤ë¥¨¥ó¥È¥ê¤Ç¤¹¡£
EOF

$helpTopics[$root.frame.entry[7]] = <<EOF
FAXÈÖ¹æ¤òµ­Æþ¤¹¤ë¥¨¥ó¥È¥ê¤Ç¤¹¡£
EOF

$helpTopics["¥³¥ó¥Æ¥­¥¹¥È"] = <<EOF
Ruby/Tk¤Ç¤Ïgrab¤Îµ¡¹½¤¬¤Ê¤¤¤¿¤á¤³¤Î¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï\
¥³¥ó¥Æ¥­¥¹¥È¥Ø¥ë¥×¤Ï¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£
¤·¤«¤·Æ±¤¸¤è¤¦¤Ê¸ú²Ì¤òbind¤È¥Þ¥¦¥¹¤Î°ÌÃÖ¤ÎWedget¤òÃΤë\
¤³¤È¤ÇÆÀ¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
EOF

$helpTopics["¥Ø¥ë¥×"] = <<EOF
¥Þ¥¦¥¹¤ò¥¦¥£¥ó¥É¥¦¤Ë¤¢¤ï¤»¤ÆF1¥­¡¼¤ò²¡¤¹¤³¤È¤Ë¤è¤Ã¤Æ\
¤½¤Î¥Ø¥ë¥×¤ò¸«¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
EOF

$helpTopics["¥¦¥£¥ó¥É¥¦"] = <<EOF
¤³¤Î¥¦¥£¥ó¥É¥¦¤Ï¥À¥ß¡¼¤Ç¤¹¡£
EOF

$helpTopics["¥­¡¼Áàºî"] = <<EOF
Ctrl+A:		ÄɲÃ
Ctrl+C:		¥¯¥ê¥¢¡¼
Ctrl+D:		¾Ãµî
Ctrl+F:		¥Õ¥¡¥¤¥ëÁªÂò
Ctrl+Q:		½ªÎ»
Ctrl+S:		¸¡º÷
EOF

$helpTopics["¥Ð¡¼¥¸¥ç¥ó¾ðÊó"] = <<EOF
¥Ð¡¼¥¸¥ç¥ó¤Ï 1.0.1e ¤Ç¤¹¡£
EOF

Tk.mainloop