summaryrefslogtreecommitdiff
path: root/ext/tk/sample
diff options
context:
space:
mode:
Diffstat (limited to 'ext/tk/sample')
-rw-r--r--ext/tk/sample/demos-en/dialog1.rb3
-rw-r--r--ext/tk/sample/demos-en/dialog2.rb3
-rw-r--r--ext/tk/sample/demos-jp/dialog1.rb3
-rw-r--r--ext/tk/sample/demos-jp/dialog2.rb3
-rw-r--r--ext/tk/sample/tkalignbox.rb83
-rw-r--r--ext/tk/sample/tkcombobox.rb7
-rw-r--r--ext/tk/sample/tkmultilistbox.rb1
-rw-r--r--ext/tk/sample/tkoptdb.rb1
-rw-r--r--ext/tk/sample/tktextframe.rb1
9 files changed, 88 insertions, 17 deletions
diff --git a/ext/tk/sample/demos-en/dialog1.rb b/ext/tk/sample/demos-en/dialog1.rb
index d2b34e6b46..374fedc985 100644
--- a/ext/tk/sample/demos-en/dialog1.rb
+++ b/ext/tk/sample/demos-en/dialog1.rb
@@ -2,6 +2,9 @@
# a dialog box with a local grab (called by 'widget')
#
class TkDialog_Demo1 < TkDialog
+ ###############
+ private
+ ###############
def title
"Dialog with local grab"
end
diff --git a/ext/tk/sample/demos-en/dialog2.rb b/ext/tk/sample/demos-en/dialog2.rb
index c441dda62f..21bf25c88d 100644
--- a/ext/tk/sample/demos-en/dialog2.rb
+++ b/ext/tk/sample/demos-en/dialog2.rb
@@ -2,6 +2,9 @@
# a dialog box with a global grab (called by 'widget')
#
class TkDialog_Demo2 < TkDialog
+ ###############
+ private
+ ###############
def title
"Dialog with global grab"
end
diff --git a/ext/tk/sample/demos-jp/dialog1.rb b/ext/tk/sample/demos-jp/dialog1.rb
index 317b6d9eb3..5b578a981d 100644
--- a/ext/tk/sample/demos-jp/dialog1.rb
+++ b/ext/tk/sample/demos-jp/dialog1.rb
@@ -2,6 +2,9 @@
# a dialog box with a local grab (called by 'widget')
#
class TkDialog_Demo1 < TkDialog
+ ###############
+ private
+ ###############
def title
"Dialog with local grab"
end
diff --git a/ext/tk/sample/demos-jp/dialog2.rb b/ext/tk/sample/demos-jp/dialog2.rb
index 295522e562..4819f18a03 100644
--- a/ext/tk/sample/demos-jp/dialog2.rb
+++ b/ext/tk/sample/demos-jp/dialog2.rb
@@ -2,6 +2,9 @@
# a dialog box with a global grab (called by 'widget')
#
class TkDialog_Demo2 < TkDialog
+ ###############
+ private
+ ###############
def title
"Dialog with global grab"
end
diff --git a/ext/tk/sample/tkalignbox.rb b/ext/tk/sample/tkalignbox.rb
index cca91c9b0d..b56c9cc11e 100644
--- a/ext/tk/sample/tkalignbox.rb
+++ b/ext/tk/sample/tkalignbox.rb
@@ -12,6 +12,17 @@ require 'tk'
class TkAlignBox < TkFrame
def initialize(*args)
+ if self.class == TkAlignBox
+ fail RuntimeError, "TkAlignBox is an abstract class"
+ end
+ @padx = 0
+ @pady = 0
+ if args[-1].kind_of? Hash
+ keys = _symbolkey2str(args.pop)
+ @padx = keys.delete('padx') || 0
+ @pady = keys.delete('pady') || 0
+ args.push(keys)
+ end
super(*args)
@max_width = 0
@max_height = 0
@@ -53,7 +64,6 @@ class TkAlignBox < TkFrame
@max_height = sz if @max_height < sz
}
align
- self
end
def <<(widget)
@@ -71,7 +81,6 @@ class TkAlignBox < TkFrame
sz = widget.winfo_reqheight
@max_height = sz if @max_height < sz
align
- self
end
def delete(idx)
@@ -87,46 +96,85 @@ class TkAlignBox < TkFrame
ret
end
+ def padx(size = nil)
+ if size
+ @padx = size
+ align
+ else
+ @padx
+ end
+ end
+
+ def pady(size = nil)
+ if size
+ @pady = size
+ align
+ else
+ @pady
+ end
+ end
+
attr_accessor :propagate
end
class TkHBox < TkAlignBox
def _set_framesize
bd = self.borderwidth
- self.width(@max_width * @widgets.size + 2 * bd)
- self.height(@max_height + 2 * bd)
+ self.width((@max_width + 2*@padx) * @widgets.size + 2*bd)
+ self.height(@max_height + 2*@pady + 2*bd)
end
+ private :_set_framesize
+
def _place_config(widget, idx, cnt)
- widget.place_in(self, 'relx'=>idx/cnt, 'relwidth'=>1.0/cnt,
- 'relheight'=>1.0)
+ widget.place_in(self,
+ 'relx'=>idx/cnt, 'x'=>@padx,
+ 'rely'=>0, 'y'=>@pady,
+ 'relwidth'=>1.0/cnt, 'width'=>-2*@padx,
+ 'relheight'=>1.0, 'height'=>-2*@pady)
end
+ private :_place_config
end
TkHLBox = TkHBox
class TkHRBox < TkHBox
def _place_config(widget, idx, cnt)
- widget.place_in(self, 'relx'=>(cnt - idx - 1)/cnt, 'relwidth'=>1.0/cnt,
- 'relheight'=>1.0)
+ widget.place_in(self,
+ 'relx'=>(cnt - idx - 1)/cnt, 'x'=>@padx,
+ 'rely'=>0, 'y'=>@pady,
+ 'relwidth'=>1.0/cnt, 'width'=>-2*@padx,
+ 'relheight'=>1.0, 'height'=>-2*@pady)
end
+ private :_place_config
end
class TkVBox < TkAlignBox
def _set_framesize
- self.width(@max_width + 2 * bd)
- self.height(@max_height * @widgets.size + 2 * bd)
+ bd = self.borderwidth
+ self.width(@max_width + 2*@padx + 2*bd)
+ self.height((@max_height + 2*@pady) * @widgets.size + 2*bd)
end
+ private :_set_framesize
+
def _place_config(widget, idx, cnt)
- widget.place_in(self, 'rely'=>idx/cnt, 'relheight'=>1.0/cnt,
- 'relwidth'=>1.0)
+ widget.place_in(self,
+ 'relx'=>0, 'x'=>@padx,
+ 'rely'=>idx/cnt, 'y'=>@pady,
+ 'relwidth'=>1.0, 'width'=>-2*@padx,
+ 'relheight'=>1.0/cnt, 'height'=>-2*@pady)
end
+ private :_place_config
end
TkVTBox = TkVBox
class TkVBBox < TkVBox
def _place_config(widget, idx, cnt)
- widget.place_in(self, 'rely'=>(cnt - idx - 1)/cnt, 'relheight'=>1.0/cnt,
- 'relwidth'=>1.0)
+ widget.place_in(self,
+ 'relx'=>0, 'x'=>@padx,
+ 'rely'=>(cnt - idx - 1)/cnt, 'y'=>@pady,
+ 'relwidth'=>1.0, 'width'=>-2*@padx,
+ 'relheight'=>1.0/cnt, 'height'=>-2*@pady)
end
+ private :_place_config
end
################################################
@@ -139,6 +187,13 @@ if __FILE__ == $0
TkButton.new(f, :text=>'aaa'),
TkButton.new(f, :text=>'aaaa'))
+ f = TkHBox.new(:borderwidth=>3, :relief=>'ridge',
+ :padx=>7, :pady=>3, :background=>'yellow').pack
+ f.add(TkButton.new(f, :text=>'a'),
+ TkButton.new(f, :text=>'aa', :font=>'Helvetica 16'),
+ TkButton.new(f, :text=>'aaa'),
+ TkButton.new(f, :text=>'aaaa'))
+
f = TkVBox.new(:borderwidth=>5, :relief=>'groove').pack
f.add(TkButton.new(f, :text=>'a'),
TkButton.new(f, :text=>'aa', :font=>'Helvetica 30'),
diff --git a/ext/tk/sample/tkcombobox.rb b/ext/tk/sample/tkcombobox.rb
index 08a2dd73a7..f0cbdac3ba 100644
--- a/ext/tk/sample/tkcombobox.rb
+++ b/ext/tk/sample/tkcombobox.rb
@@ -24,6 +24,9 @@ static unsigned char down_arrow_bits[] = {
0x10, 0x00, 0x10, 0x00, 0x00, 0x00};
EOD
+ ############################
+ private
+ ############################
def initialize_composite(keys={})
keys = _symbolkey2str(keys)
@@ -64,9 +67,6 @@ EOD
configure keys unless keys.empty?
end
- ############################
- private
- ############################
def _show_up_arrow
unless @up_arrow.winfo_mapped?
@up_arrow.pack(:side=>:top, :fill=>:x)
@@ -330,6 +330,7 @@ EOD
configure keys unless keys.empty?
end
+ private :initialize_composite
def scrollbar(mode)
@lst.scrollbar(mode)
diff --git a/ext/tk/sample/tkmultilistbox.rb b/ext/tk/sample/tkmultilistbox.rb
index 9b66d401b9..1896c66dac 100644
--- a/ext/tk/sample/tkmultilistbox.rb
+++ b/ext/tk/sample/tkmultilistbox.rb
@@ -182,6 +182,7 @@ class TkMultiListbox < TkListbox
delegate('borderwidth', @frame)
delegate('relief', @frame)
end
+ private :initialize_composite
# set 'mode' option of listboxes
def mode(sel_mode)
diff --git a/ext/tk/sample/tkoptdb.rb b/ext/tk/sample/tkoptdb.rb
index ab8515ac16..897701c222 100644
--- a/ext/tk/sample/tkoptdb.rb
+++ b/ext/tk/sample/tkoptdb.rb
@@ -33,6 +33,7 @@ cmd = TkOptionDB.new_proc_class(:BTN_CMD, [:show_msg, :bye_msg], 3) {
print "==>#{str.tainted?} (<<< $SAFE=#{$SAFE}): "
str
end
+ private :__check_proc_string__
end
}
diff --git a/ext/tk/sample/tktextframe.rb b/ext/tk/sample/tktextframe.rb
index d1076c5b72..78efdf0970 100644
--- a/ext/tk/sample/tktextframe.rb
+++ b/ext/tk/sample/tktextframe.rb
@@ -51,6 +51,7 @@ class TkTextFrame < TkText
# do configure
configure keys unless keys.empty?
end
+ private :initialize_composite
# set background color of text widget
def textbackground(color = nil)