1#!/usr/bin/env ruby
2# -*- coding: utf-8 -*-
3#
4# rolodex --
5# このスクリプトは Tom LaStrange の rolodex の一部です。
6#
7# Copyright (C) 1998 by Takaaki Tateishi <ttate@jaist.ac.jp>
8# Time-stamp: "04/04/09 00:32:12 nagai"
9#
10
11require "tk"
12Tk.encoding = "utf-8"
13
14def show_help(topic,x=0,y=0)
15  if( topic.is_a?(TkWindow) )
16    w = TkWinfo.containing(x,y)
17    if( w.is_a?(TkWindow) )
18      if( TkWinfo.exist?(w) )
19	topic = w
20      end
21    end
22  end
23
24  if( $helpTopics.include?(topic) )
25    msg = $helpTopics[topic]
26  else
27    msg = "このトピックについてのヘルプはまだ使用できません"
28  end
29  TkDialog.new("title"=>"Rolodex Help",
30	       "message"=>"「#{topic}」\n\n#{msg}",
31	       "default_button"=>0,
32	       "buttons"=>["OK"])
33end
34
35def fillCard
36  clearAction
37  $root.frame.entry[1].insert(0, "立石 孝彰")
38  $root.frame.entry[2].insert(0, "923-1292 石川県")
39  $root.frame.entry[3].insert(0, "辰口町 旭台 1-1")
40  $root.frame.entry[4].insert(0, "北陸先端科学技術大学院大学")
41  $root.frame.entry[5].insert(0,"private")
42  $root.frame.entry[6].insert(0,"***-***-****")
43  $root.frame.entry[7].insert(0,"***-***-****")
44end
45
46def addAction
47  for i in 1..7
48    STDERR.print format("%-12s %s\n",
49			RolodexFrame::LABEL[i],
50			$root.frame.entry[i].value)
51  end
52end
53
54def clearAction
55  for i in 1..7
56    $root.frame.entry[i].delete(0,"end")
57  end
58end
59
60def fileAction
61  TkDialog.new("title"=>"File Selection",
62	       "message"=>"これはファイル選択ダイアログのダミーです。\n",
63	       "default_button"=>0,
64	       "buttons"=>["OK"])
65  STDERR.print "dummy file name\n"
66end
67
68def deleteAction
69  result = TkDialog.new("title"=>"Confirm Action",
70			"message"=>"よろしいですか?",
71			"default_button"=>0,
72			"buttons"=>["キャンセル"])
73  if( result.value == 0 )
74    clearAction
75  end
76end
77
78
79class RolodexFrame < TkFrame
80  attr_reader :entry, :label
81
82  LABEL = ["","名前:","住所","","","電話(自宅):","電話(会社):","Fax:"]
83
84  def initialize(parent=nil,keys=nil)
85    super(parent,keys)
86    self["relief"] = "flat"
87    @i = []
88    @label = []
89    @entry = []
90    for i in 1..7
91      @i[i] = TkFrame.new(self)
92      @i[i].pack("side"=>"top",
93		 "pady"=>2,
94		 "anchor"=>"e")
95      @label[i] = TkLabel.new(@i[i],
96			      "text"=>LABEL[i],
97			      "anchor"=>"e")
98      @entry[i] = TkEntry.new(@i[i],
99			      "width"=>30,
100			      "relief"=>"sunken")
101      @entry[i].pack("side"=>"right")
102      @label[i].pack("side"=>"right")
103    end
104  end
105end
106
107class RolodexButtons < TkFrame
108  attr_reader :clear, :add, :search, :delete
109
110  def initialize(parent,keys=nil)
111    super(parent,keys)
112    @clear = TkButton.new(self,"text" => "クリアー")
113    @add = TkButton.new(self,  "text" => "追加")
114    @search = TkButton.new(self, "text" => "検索")
115    @delete = TkButton.new(self,  "text" => "消去")
116    for w in [@clear,@add,@search,@delete]
117      w.pack("side"=>"left", "padx"=>2)
118    end
119  end
120end
121
122class RolodexMenuFrame < TkFrame
123  attr_reader :file_menu, :help_menu, :file, :help
124
125  def initialize(parent,keys=nil)
126    super(parent,keys)
127    configure("relief"=>"raised",
128	      "borderwidth"=>1)
129
130    @file = TkMenubutton.new(self,
131			     "text"=> "ファイル",
132			     "underline"=>0)
133    @file_menu = TkMenu.new(@file)
134    @file_menu.add("command",
135		   "label" => "読み込み ...",
136		   "command" => proc{fileAction},
137		   "underline" => 0)
138    @file_menu.add("command",
139		   "label" => "終了",
140		   "command" => proc{$root.destroy},
141		   "underline" => 0)
142    @file.menu(@file_menu)
143    @file.pack("side"=>"left")
144
145    @help = TkMenubutton.new(self,
146			     "text"=> "ヘルプ",
147			     "underline"=>0)
148    @help_menu = TkMenu.new(@help)
149    @help_menu.add("command",
150		   "label"=> "コンテキストについて",
151		   "command"=>proc{show_help("コンテキスト")},
152		   "underline"=>3)
153    @help_menu.add("command",
154		   "label"=> "ヘルプについて",
155		   "command"=>proc{show_help("ヘルプ")},
156		   "underline"=>3)
157    @help_menu.add("command",
158		   "label"=> "ウィンドウについて",
159		   "command"=>proc{show_help("ウィンドウ")},
160		   "underline"=>3)
161    @help_menu.add("command",
162		   "label"=> "キー操作について",
163		   "command"=>proc{show_help("キー操作")},
164		   "underline"=>3)
165    @help_menu.add("command",
166		   "label"=> "バージョン情報",
167		   "command"=>proc{show_help("バージョン情報")},
168		   "underline"=>3)
169    @help.menu(@help_menu)
170    @help.pack("side"=>"right")
171  end
172end
173
174class Rolodex < TkRoot
175  attr_reader :frame, :buttons, :menu
176
177  def initialize(*args)
178    super(*args)
179    @frame = RolodexFrame.new(self)
180    @frame.pack("side"=>"top",
181		"fill"=>"y",
182		"anchor"=>"center")
183    @buttons = RolodexButtons.new(self)
184    @buttons.pack("side"=>"bottom",
185		  "pady"=>2,
186		  "anchor"=>"center")
187    @menu = RolodexMenuFrame.new(self)
188    @menu.pack("before"=>@frame,
189	       "side"=>"top",
190	       "fill"=>"x")
191  end
192end
193
194$root = Rolodex.new
195
196$root.buttons.delete.configure("command"=>proc{deleteAction})
197$root.buttons.add.configure("command"=>proc{addAction})
198$root.buttons.clear.configure("command"=>proc{clearAction})
199$root.buttons.search.configure("command"=>proc{addAction; fillCard})
200
201$root.buttons.clear.configure("text"=> "クリアー   Ctrl+C")
202$root.bind("Control-c",proc{clearAction})
203
204$root.buttons.add.configure("text"=> "追加   Ctrl+A")
205$root.bind("Control-a",proc{addAction})
206
207$root.buttons.search.configure("text"=> "検索   Ctrl+S")
208$root.bind("Control-s",proc{addAction; fillCard})
209
210$root.buttons.delete.configure("text"=> "消去   Ctrl+D")
211$root.bind("Control-d",proc{deleteAction})
212
213$root.menu.file_menu.entryconfigure(1, "accel"=>"Ctrl+F")
214$root.bind("Control-f",proc{fileAction})
215
216$root.menu.file_menu.entryconfigure(2, "accel"=>"Ctrl+Q")
217$root.bind("Control-q",proc{$root.destroy})
218
219$root.frame.entry[1].focus
220
221$root.bind("Any-F1",
222	   proc{|event| show_help(event.widget, event.x_root, event.y_root)})
223$root.bind("Any-Help",
224	   proc{|event| show_help(event.widget, event.x_root, event.y_root)})
225
226
227$helpTopics = {}
228
229$helpTopics[$root.menu.file] = <<EOF
230������������������������������������������������������������������������������������������
231���������������������������������
232EOF
233
234$helpTopics[$root.menu.file_menu.index(0)] = <<EOF
235���������������������������������������������������������������
236EOF
237
238$helpTopics[$root.menu.file_menu.index(1)] = <<EOF
239���������������������������������������������������������������
240EOF
241
242$helpTopics[$root.frame.entry[1]] = <<EOF
243������������������������������������������
244EOF
245
246$helpTopics[$root.frame.entry[2]] = <<EOF
247������������������������������������������
248EOF
249
250$helpTopics[$root.frame.entry[3]] = <<EOF
251������������������������������������������
252EOF
253
254$helpTopics[$root.frame.entry[4]] = <<EOF
255������������������������������������������
256EOF
257
258$helpTopics[$root.frame.entry[5]] = <<EOF
259���������������������������������������������������������������\
260������������������������ private ���������������������
261EOF
262
263$helpTopics[$root.frame.entry[6]] = <<EOF
264���������������������������������������������������������
265EOF
266
267$helpTopics[$root.frame.entry[7]] = <<EOF
268FAX������������������������������������������
269EOF
270
271$helpTopics["コンテキスト"] = <<EOF
272Ruby/Tk������grab������������������������������������������������������������\
273������������������������������������������������������������������
274���������������������������������bind������������������������Wedget���������\
275���������������������������������������
276EOF
277
278$helpTopics["ヘルプ"] = <<EOF
279������������������������������������������F1���������������������������������\
280������������������������������������������������
281EOF
282
283$helpTopics["ウィンドウ"] = <<EOF
284������������������������������������������
285EOF
286
287$helpTopics["キー操作"] = <<EOF
288Ctrl+A:		������
289Ctrl+C:		������������
290Ctrl+D:		������
291Ctrl+F:		������������������
292Ctrl+Q:		������
293Ctrl+S:		������
294EOF
295
296$helpTopics["バージョン情報"] = <<EOF
297������������������ 1.0.1j ���������
298EOF
299
300Tk.mainloop
301