1# msgbox.rb
2#
3# This demonstration script creates message boxes of various type
4#
5# message boxes widget demo (called by 'widget')
6#
7
8# toplevel widget
9if defined?($msgbox_demo) && $msgbox_demo
10  $msgbox_demo.destroy
11  $msgbox_demo = nil
12end
13
14# demo toplevel widget
15$msgbox_demo = TkToplevel.new {|w|
16  title("Message Box Demonstration")
17  iconname("messagebox")
18  positionWindow(w)
19}
20
21base_frame = TkFrame.new($msgbox_demo).pack(:fill=>:both, :expand=>true)
22
23# label
24TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left',
25            'text'=>"Choose the icon and type option of the message box. Then press the \"Message Box\" button to see the message box.").pack('side'=>'top')
26
27# frame
28TkFrame.new(base_frame) {|frame|
29  TkButton.new(frame) {
30    text 'Dismiss'
31    command proc{
32      tmppath = $msgbox_demo
33      $msgbox_demo = nil
34      tmppath.destroy
35    }
36  }.pack('side'=>'left', 'expand'=>'yes')
37
38  TkButton.new(frame) {
39    text 'Show Code'
40    command proc{showCode 'msgbox'}
41  }.pack('side'=>'left', 'expand'=>'yes')
42
43  TkButton.new(frame) {
44    text 'Message Box'
45    command proc{showMessageBox $msgbox_demo}
46  }.pack('side'=>'left', 'expand'=>'yes')
47}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
48
49# frame
50$msgbox_leftframe  = TkFrame.new(base_frame)
51$msgbox_rightframe = TkFrame.new(base_frame)
52$msgbox_leftframe .pack('side'=>'left', 'expand'=>'yes', 'fill'=>'y',
53                        'pady'=>'.5c', 'padx'=>'.5c')
54$msgbox_rightframe.pack('side'=>'left', 'expand'=>'yes', 'fill'=>'y',
55                        'pady'=>'.5c', 'padx'=>'.5c')
56
57TkLabel.new($msgbox_leftframe, 'text'=>'Icon').pack('side'=>'top')
58TkFrame.new($msgbox_leftframe, 'relief'=>'ridge', 'bd'=>1, 'height'=>2)\
59.pack('side'=>'top', 'fill'=>'x', 'expand'=>'no')
60
61$msgboxIcon = TkVariable.new('info')
62['error', 'info', 'question', 'warning'].each {|icon|
63  TkRadioButton.new($msgbox_leftframe, 'text'=>icon, 'variable'=>$msgboxIcon,
64                    'relief'=>'flat', 'value'=>icon, 'width'=>16,
65                    'anchor'=>'w').pack('side'=>'top', 'pady'=>2,
66                                        'anchor'=>'w', 'fill'=>'x')
67}
68
69TkLabel.new($msgbox_rightframe, 'text'=>'Type').pack('side'=>'top')
70TkFrame.new($msgbox_rightframe, 'relief'=>'ridge', 'bd'=>1, 'height'=>2)\
71.pack('side'=>'top', 'fill'=>'x', 'expand'=>'no')
72
73$msgboxType = TkVariable.new('ok')
74['abortretryignore', 'ok', 'okcancel',
75  'retrycancel', 'yesno', 'yesnocancel'].each {|type|
76  TkRadioButton.new($msgbox_rightframe, 'text'=>type, 'variable'=>$msgboxType,
77                    'relief'=>'flat', 'value'=>type, 'width'=>16,
78                    'anchor'=>'w').pack('side'=>'top', 'pady'=>2,
79                                        'anchor'=>'w', 'fill'=>'x')
80}
81
82def showMessageBox(w)
83  button = Tk.messageBox('icon'=>$msgboxIcon.value, 'type'=>$msgboxType.value,
84                         'title'=>'Message', 'parent'=>w,
85                         'message'=>"This is a \"#{$msgboxType.value}\" type messagebox with the \"#{$msgboxIcon.value}\" icon")
86
87  Tk.messageBox('icon'=>'info', 'type'=>'ok', 'parent'=>w,
88                'message'=>"You have selected  \"#{button}\"")
89end
90
91