1# -*- coding: utf-8 -*-
2#
3# paned2.rb --
4#
5# This demonstration script creates a toplevel window containing
6# a paned window that separates two windows vertically.
7#
8# based on "Id: paned2.tcl,v 1.1 2002/02/22 14:07:01 dkf Exp"
9
10if defined?($paned2_demo) && $paned2_demo
11  $paned2_demo.destroy
12  $paned2_demo = nil
13end
14
15$paned2_demo = TkToplevel.new {|w|
16  title("Vertical Paned Window Demonstration")
17  iconname("paned2")
18  positionWindow(w)
19}
20
21base_frame = TkFrame.new($paned2_demo).pack(:fill=>:both, :expand=>true)
22
23TkLabel.new(base_frame,
24            :font=>$font, :wraplength=>'4i', :justify=>:left,
25            :text=><<EOL).pack(:side=>:top)
26������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
27��������������������������������� Ruby ��������������������������� Tk ������������������ panedwindow ������������������������
28������������������������������������������������������������������������������ panedwindow ���������������������������������
29��������������������������������� Tk ���������������������������
30������������������������������
31EOL
32
33# The bottom buttons
34TkFrame.new(base_frame){|f|
35  pack(:side=>:bottom, :fill=>:x, :pady=>'2m')
36
37  TkButton.new(f, :text=>'閉じる', :width=>15, :command=>proc{
38                 $paned2_demo.destroy
39                 $paned2_demo = nil
40               }).pack(:side=>:left, :expand=>true)
41
42  TkButton.new(f, :text=>'コード参照', :width=>15, :command=>proc{
43                 showCode 'paned2'
44               }).pack(:side=>:left, :expand=>true)
45}
46
47paneList = TkVariable.new  # define as normal variable (not array)
48paneList.value = [         # ruby's array --> tcl's list
49    'Ruby/Tk のウィジェット一覧',
50    'TkButton',
51    'TkCanvas',
52    'TkCheckbutton',
53    'TkEntry',
54    'TkFrame',
55    'TkLabel',
56    'TkLabelframe',
57    'TkListbox',
58    'TkMenu',
59    'TkMenubutton',
60    'TkMessage',
61    'TkPanedwindow',
62    'TkRadiobutton',
63    'TkScale',
64    'TkScrollbar',
65    'TkSpinbox',
66    'TkText',
67    'TkToplevel'
68]
69
70# Create the pane itself
71TkPanedwindow.new(base_frame, :orient=>:vertical){|f|
72  pack(:side=>:top, :expand=>true, :fill=>:both, :pady=>2, :padx=>'2m')
73
74  add(TkFrame.new(f){|paned2_top|
75        TkListbox.new(paned2_top, :listvariable=>paneList) {
76          # Invert the first item to highlight it
77          itemconfigure(0, :background=>self.cget(:foreground),
78                           :foreground=>self.cget(:background) )
79          yscrollbar(TkScrollbar.new(paned2_top).pack(:side=>:right,
80                                                      :fill=>:y))
81          pack(:fill=>:both, :expand=>true)
82        }
83      },
84
85      TkFrame.new(f, :height=>120) {|paned2_bottom|
86        # The bottom window is a text widget with scrollbar
87        paned2_xscr = TkScrollbar.new(paned2_bottom)
88        paned2_yscr = TkScrollbar.new(paned2_bottom)
89        paned2_text = TkText.new(paned2_bottom, :width=>30, :wrap=>:non) {
90          insert('1.0', 'ここに配置されているのは、' +
91                        'ごく普通のテキストウィジェットです。')
92          xscrollbar(paned2_xscr)
93          yscrollbar(paned2_yscr)
94        }
95        Tk.grid(paned2_text, paned2_yscr, :sticky=>'nsew')
96        Tk.grid(paned2_xscr, :sticky=>'nsew')
97        TkGrid.columnconfigure(paned2_bottom, 0, :weight=>1)
98        TkGrid.rowconfigure(paned2_bottom, 0, :weight=>1)
99      } )
100}
101