summaryrefslogtreecommitdiff
path: root/ext/tk/sample/editable_listbox.rb
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-11-06 06:56:37 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-11-06 06:56:37 +0000
commit2ec88c167b2dd0e3c13a77dadb9518f8d06d0c59 (patch)
tree5a810d5880298b9c85fb4109db9262931a131be4 /ext/tk/sample/editable_listbox.rb
parentced53248ff41863ef7adf62db215380d5089bc24 (diff)
* ext/tk/lib/tk/itemconfig.rb: bug fix on 'itemconfiginfo' method, and
modify to make it easy to override 'itemconfiginfo' method. * ext/tk/lib/tkextlib/tile/treeview.rb : support Tile 0.7.8. * ext/tk/lib/tkextlib/version.rb : [new] add Tk::Tkextlib_RELEASE_DATE to get the information from scripts. * ext/tk/lib/tk.rb: load 'tkextlib/version.rb', and update RELEASE_DATE. * ext/tk/lib/tkextlib/SUPPORT_STATUS: update. * ext/tk/sample/editable_listbox.rb: [new] the listbox with editable items. It's one of the example about usage of Place geometry manager. * ext/tk/sample/tktextio.rb: improve the functions of TkTextIO class. Those are required by 'irbtkw.rbw'. * ext/tk/sample/irbtkw.rbw: [new] IRB on Ruby/Tk. It doesn't need any real console. IRB works on a text widget without I/O blocking. That is, thread switching on IRB will work properly, even if on Windows. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11283 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/sample/editable_listbox.rb')
-rw-r--r--ext/tk/sample/editable_listbox.rb69
1 files changed, 69 insertions, 0 deletions
diff --git a/ext/tk/sample/editable_listbox.rb b/ext/tk/sample/editable_listbox.rb
new file mode 100644
index 0000000000..99345da380
--- /dev/null
+++ b/ext/tk/sample/editable_listbox.rb
@@ -0,0 +1,69 @@
+#
+# Editable_TkListbox class
+#
+# When "DoubleClick-1" on a listbox item, the entry box is opend on the
+# item. And when hit "Return" key on the entry box after modifying the
+# text, the entry box is closed and the item is changed. Or when hit
+# "Escape" key, the entry box is closed without modification.
+#
+# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
+#
+require 'tk'
+
+class Editable_TkListbox < TkListbox
+ def _ebox_placer(coord_y)
+ idx = self.nearest(coord_y)
+ x, y, w, h = self.bbox(idx)
+ @ebox.place(:x => 0, :relwidth => 1.0,
+ :y => y - self.selectborderwidth,
+ :height => h + 2 * self.selectborderwidth)
+ @ebox.pos = idx
+ @ebox.value = self.listvariable.list[idx]
+ @ebox.focus
+ end
+ private :_ebox_placer
+
+
+ def create_self(keys)
+ super(keys)
+
+ unless self.listvariable
+ self.listvariable = TkVariable.new(self.get(0, :end))
+ end
+
+ @ebox = TkEntry.new(self){
+ @pos = -1
+ def self.pos; @pos; end
+ def self.pos=(idx); @pos = idx; end
+ }
+
+ @ebox.bind('Return'){
+ list = self.listvariable.list
+ list[@ebox.pos] = @ebox.value
+ self.listvariable.value = list
+ @ebox.place_forget
+ @ebox.pos = -1
+ }
+
+ @ebox.bind('Escape'){
+ @ebox.place_forget
+ @ebox.pos = -1
+ }
+
+ self.bind('Double-1', '%y'){|y| _ebox_placer(y) }
+ end
+end
+
+if $0 == __FILE__
+ scr = TkScrollbar.new.pack(:side=>:right, :fill=>:y)
+
+ lbox1 = Editable_TkListbox.new.pack(:side=>:left)
+ lbox2 = Editable_TkListbox.new.pack(:side=>:left)
+
+ scr.assign(lbox1, lbox2)
+
+ lbox1.insert(:end, *%w(a b c d e f g h i j k l m n))
+ lbox2.insert(:end, 0,1,2,3,4,5,6,7,8,9,0,1,2,3)
+
+ Tk.mainloop
+end