1# -*- coding: utf-8 -*-
2#
3# ttkmenu.rb --
4#
5# This demonstration script creates a toplevel window containing several Ttk
6# menubutton widgets.
7#
8# based on "Id: ttkmenu.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp"
9
10if defined?($ttkmenu_demo) && $ttkmenu_demo
11  $ttkmenu_demo.destroy
12  $ttkmenu_demo = nil
13end
14
15$ttkmenu_demo = TkToplevel.new {|w|
16  title("Ttk Menu Buttons")
17  iconname("ttkmenu")
18  positionWindow(w)
19}
20
21base_frame = Ttk::Frame.new($ttkmenu_demo).pack(:fill=>:both, :expand=>true)
22
23Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i', :justify=>:left,
24               :text=><<EOL).pack(:side=>:top, :fill=>:x)
25Ttk���������������������������������������������������������������������������\
26������������������������������������������������������������������������������������������������������������\
27���������������������������������������\
28������������������������������������������������������������������������������������������������������\
29������������������������������������������������������������������������������������������\
30������������������������������������������������������������������������������������������\
31������������������������������������������������������������\
32(���������������������������������������������������������)���������������������������������\
33���������������������������\
34������������������������������������������������������������������������������������������������������������\
35���������������������������������������������������������������������������������������������������\
36���������������������������Tk������������������������������������\
37������������������������������������������������������������������������������������������������\
38������������������������������������������������������������������������������������������������������\
39���������������������������������������
40EOL
41
42Ttk::Separator.new(base_frame).pack(:side=>:top, :fill=>:x)
43
44## See Code / Dismiss
45Ttk::Frame.new($ttkmenu_demo) {|frame|
46  sep = Ttk::Separator.new(frame)
47  Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
48  TkGrid('x',
49         Ttk::Button.new(frame, :text=>'コード参照',
50                         :image=>$image['view'], :compound=>:left,
51                         :command=>proc{showCode 'ttkmenu'}),
52         Ttk::Button.new(frame, :text=>'閉じる',
53                         :image=>$image['delete'], :compound=>:left,
54                         :command=>proc{
55                           $ttkmenu_demo.destroy
56                           $ttkmenu_demo = nil
57                         }),
58         :padx=>4, :pady=>4)
59  grid_columnconfigure(0, :weight=>1)
60  pack(:side=>:bottom, :fill=>:x)
61}
62
63b1 = Ttk::Menubutton.new(base_frame,:text=>'テーマを選択',:direction=>:above)
64b2 = Ttk::Menubutton.new(base_frame,:text=>'テーマを選択',:direction=>:left)
65b3 = Ttk::Menubutton.new(base_frame,:text=>'テーマを選択',:direction=>:right)
66b4 = Ttk::Menubutton.new(base_frame,:text=>'テーマを選択',:direction=>:flush,
67                         :style=>Ttk::Menubutton.style('Toolbutton'))
68b5 = Ttk::Menubutton.new(base_frame,:text=>'テーマを選択',:direction=>:below)
69
70b1.menu(m1 = Tk::Menu.new(b1, :tearoff=>false))
71b2.menu(m2 = Tk::Menu.new(b2, :tearoff=>false))
72b3.menu(m3 = Tk::Menu.new(b3, :tearoff=>false))
73b4.menu(m4 = Tk::Menu.new(b4, :tearoff=>false))
74b5.menu(m5 = Tk::Menu.new(b5, :tearoff=>false))
75
76Ttk.themes.each{|theme|
77  m1.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme})
78  m2.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme})
79  m3.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme})
80  m4.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme})
81  m5.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme})
82}
83
84f = Ttk::Frame.new(base_frame).pack(:fill=>:x)
85f1 = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true)
86f.lower
87
88f.grid_anchor(:center)
89TkGrid('x', b1, 'x', :in=>f, :padx=>3, :pady=>2)
90TkGrid(b2,  b4, b3,  :in=>f, :padx=>3, :pady=>2)
91TkGrid('x', b5, 'x', :in=>f, :padx=>3, :pady=>2)
92