diff options
Diffstat (limited to 'ext/tk/sample/tkmultilistframe.rb')
-rw-r--r-- | ext/tk/sample/tkmultilistframe.rb | 168 |
1 files changed, 84 insertions, 84 deletions
diff --git a/ext/tk/sample/tkmultilistframe.rb b/ext/tk/sample/tkmultilistframe.rb index ef1a0a824d..7c0aac9a9e 100644 --- a/ext/tk/sample/tkmultilistframe.rb +++ b/ext/tk/sample/tkmultilistframe.rb @@ -32,7 +32,7 @@ class TkMultiListFrame < TkListbox # decide total width @lbox_total = title_info.size @width_total = 0 - title_info.each{|title, width, cmd| + title_info.each{|title, width, cmd| @width_total += width.to_f @title_cmd << cmd } @@ -54,37 +54,37 @@ class TkMultiListFrame < TkListbox # virtical scrollbar =begin - @v_scroll = TkScrollbar.new(@frame, 'highlightthickness'=>@h_l_thick, - 'borderwidth'=>@scrbar_border, + @v_scroll = TkScrollbar.new(@frame, 'highlightthickness'=>@h_l_thick, + 'borderwidth'=>@scrbar_border, 'orient'=>'vertical', 'width'=>@scrbar_width) =end - @v_scroll = TkYScrollbar.new(@frame, 'highlightthickness'=>@h_l_thick, - 'borderwidth'=>@scrbar_border, + @v_scroll = TkYScrollbar.new(@frame, 'highlightthickness'=>@h_l_thick, + 'borderwidth'=>@scrbar_border, 'width'=>@scrbar_width) # horizontal scrollbar =begin - @h_scroll = TkScrollbar.new(@frame, 'highlightthickness'=>@h_l_thick, - 'borderwidth'=>@scrbar_border, + @h_scroll = TkScrollbar.new(@frame, 'highlightthickness'=>@h_l_thick, + 'borderwidth'=>@scrbar_border, 'orient'=>'horizontal', 'width'=>@scrbar_width) =end - @h_scroll = TkXScrollbar.new(@frame, 'highlightthickness'=>@h_l_thick, - 'borderwidth'=>@scrbar_border, + @h_scroll = TkXScrollbar.new(@frame, 'highlightthickness'=>@h_l_thick, + 'borderwidth'=>@scrbar_border, 'width'=>@scrbar_width) # create base flames - @c_title = TkCanvas.new(@frame, 'highlightthickness'=>@h_l_thick, + @c_title = TkCanvas.new(@frame, 'highlightthickness'=>@h_l_thick, 'width'=>@window_width) @f_title = TkFrame.new(@c_title, 'width'=>@width_total) - @w_title = TkcWindow.new(@c_title, 0, 0, + @w_title = TkcWindow.new(@c_title, 0, 0, 'window'=>@f_title, 'anchor'=>'nw') - @c_lbox = TkCanvas.new(@frame, 'highlightthickness'=>@h_l_thick, + @c_lbox = TkCanvas.new(@frame, 'highlightthickness'=>@h_l_thick, 'width'=>@window_width) @f_lbox = TkFrame.new(@c_lbox, 'width'=>@width_total) @w_lbox = TkcWindow.new(@c_lbox, 0, 0, 'window'=>@f_lbox, 'anchor'=>'nw') - @c_hscr = TkCanvas.new(@frame, 'highlightthickness'=>@h_l_thick, + @c_hscr = TkCanvas.new(@frame, 'highlightthickness'=>@h_l_thick, 'width'=>@window_width) @f_hscr = TkFrame.new(@c_hscr, 'width'=>@width_total) @w_hscr = TkcWindow.new(@c_hscr, 0, 0, 'window'=>@f_hscr, 'anchor'=>'nw') @@ -108,45 +108,45 @@ class TkMultiListFrame < TkListbox f = TkFrame.new(@f_title, 'width'=>width) base = [f] - title = TkLabel.new(f, 'text'=>label, 'borderwidth'=>@title_border, + title = TkLabel.new(f, 'text'=>label, 'borderwidth'=>@title_border, 'relief'=>'raised', 'highlightthickness'=>@h_l_thick) title_binding(title, idx) title.pack('fill'=>'x') @title_list << title - f.place('relx'=>@rel_list[idx], 'y'=>0, 'anchor'=>'nw', 'width'=>1, - 'relheight'=>1.0, + f.place('relx'=>@rel_list[idx], 'y'=>0, 'anchor'=>'nw', 'width'=>1, + 'relheight'=>1.0, 'relwidth'=>@rel_list[idx+1] - @rel_list[idx]) # listbox field f = TkFrame.new(@f_lbox, 'width'=>width) base << f - @lbox_list << TkListbox.new(f, 'highlightthickness'=>@h_l_thick, + @lbox_list << TkListbox.new(f, 'highlightthickness'=>@h_l_thick, 'borderwidth'=>@lbox_border ).pack('fill'=>'both', 'expand'=>true) - f.place('relx'=>@rel_list[idx], 'y'=>0, 'anchor'=>'nw', 'width'=>1, + f.place('relx'=>@rel_list[idx], 'y'=>0, 'anchor'=>'nw', 'width'=>1, 'relwidth'=>@rel_list[idx+1] - @rel_list[idx], 'relheight'=>1.0) # scrollbar field f = TkFrame.new(@f_hscr, 'width'=>width) base << f =begin - @hscr_list << TkScrollbar.new(f, 'orient'=>'horizontal', - 'width'=>@scrbar_width, - 'borderwidth'=>@scrbar_border, + @hscr_list << TkScrollbar.new(f, 'orient'=>'horizontal', + 'width'=>@scrbar_width, + 'borderwidth'=>@scrbar_border, 'highlightthickness'=>@h_l_thick ).pack('fill'=>'x', 'anchor'=>'w') =end - @hscr_list << TkXScrollbar.new(f, 'width'=>@scrbar_width, - 'borderwidth'=>@scrbar_border, + @hscr_list << TkXScrollbar.new(f, 'width'=>@scrbar_width, + 'borderwidth'=>@scrbar_border, 'highlightthickness'=>@h_l_thick ).pack('fill'=>'x', 'anchor'=>'w') - f.place('relx'=>@rel_list[idx], 'y'=>0, 'anchor'=>'nw', 'width'=>1, + f.place('relx'=>@rel_list[idx], 'y'=>0, 'anchor'=>'nw', 'width'=>1, 'relwidth'=>@rel_list[idx+1] - @rel_list[idx]) =begin - @lbox_list[idx].xscrollcommand proc{|first, last| + @lbox_list[idx].xscrollcommand proc{|first, last| @hscr_list[idx].set first, last } @hscr_list[idx].command proc{|*args| @lbox_list[idx].xview *args} @@ -159,23 +159,23 @@ class TkMultiListFrame < TkListbox # pad # @f_title_pad = TkFrame.new(@frame) - @f_title_pad = TkFrame.new(@frame, 'relief'=>'raised', - 'borderwidth'=>@title_border, + @f_title_pad = TkFrame.new(@frame, 'relief'=>'raised', + 'borderwidth'=>@title_border, 'highlightthickness'=>@h_l_thick) - @f_scr_pad = TkFrame.new(@frame, 'relief'=>'sunken', - 'borderwidth'=>1, + @f_scr_pad = TkFrame.new(@frame, 'relief'=>'sunken', + 'borderwidth'=>1, 'highlightthickness'=>@h_l_thick) # height check title_height = 0 - @title_list.each{|w| + @title_list.each{|w| h = w.winfo_reqheight title_height = h if title_height < h } hscr_height = 0 - @hscr_list.each{|w| + @hscr_list.each{|w| h = w.winfo_reqheight hscr_height = h if hscr_height < h } @@ -187,7 +187,7 @@ class TkMultiListFrame < TkListbox # set control procedure for virtical scroll =begin @lbox_list.each{|lbox| - lbox.yscrollcommand proc{|first, last| + lbox.yscrollcommand proc{|first, last| @v_scroll.set first, last } } @@ -197,16 +197,16 @@ class TkMultiListFrame < TkListbox # set control procedure for horizoncal scroll =begin - @c_title.xscrollcommand proc{|first, last| + @c_title.xscrollcommand proc{|first, last| @h_scroll.set first, last } - @c_lbox.xscrollcommand proc{|first, last| + @c_lbox.xscrollcommand proc{|first, last| @h_scroll.set first, last } - @c_hscr.xscrollcommand proc{|first, last| + @c_hscr.xscrollcommand proc{|first, last| @h_scroll.set first, last } - @h_scroll.command proc{|*args| + @h_scroll.command proc{|*args| @c_title.xview *args @c_lbox.xview *args @c_hscr.xview *args if @show_each_hscr @@ -221,17 +221,17 @@ class TkMultiListFrame < TkListbox @lbox_mode['extended'] = extended_mode_bindtag @lbox_mode['multiple'] = multiple_mode_bindtag @current_mode = 'browse' - @lbox_list.each_with_index{|l, idx| - l.bind('Shift-Key-Left', + @lbox_list.each_with_index{|l, idx| + l.bind('Shift-Key-Left', proc{|w| focus_shift(w, -1); Tk.callback_break}, '%W') - l.bind('Shift-Key-Right', + l.bind('Shift-Key-Right', proc{|w| focus_shift(w, 1); Tk.callback_break}, '%W') - l.bind('Button-2', proc{|x, y| + l.bind('Button-2', proc{|x, y| @lbox_mark_x = x @lbox_list.each{|lbox| lbox.scan_mark(x, y)} }, '%x %y') - l.bind('B2-Motion', proc{|x, y| + l.bind('B2-Motion', proc{|x, y| @lbox_list.each{|lbox| lbox.scan_dragto(@lbox_mark_x, y)} l.scan_dragto(x, y) }, '%x %y') @@ -270,8 +270,8 @@ class TkMultiListFrame < TkListbox @f_scr_pad.grid('row'=>2, 'rowspan'=>2, 'column'=>2, 'sticky'=>'news') # binding for 'Configure' event - @c_lbox.bind('Configure', - proc{|height, width| reconstruct(height, width)}, + @c_lbox.bind('Configure', + proc{|height, width| reconstruct(height, width)}, '%h %w') # set default receiver of method calls @@ -316,7 +316,7 @@ class TkMultiListFrame < TkListbox # set 'mode' option of listboxes def mode(sel_mode) - @lbox_list.each{|l| + @lbox_list.each{|l| tags = l.bindtags tags = tags - [ @lbox_mode[@current_mode] ] l.bindtags(tags.unshift(@lbox_mode[sel_mode])) @@ -395,7 +395,7 @@ class TkMultiListFrame < TkListbox def titlefont(font) @title_list.each{|label| label['font'] = font} title_height = 0 - @title_list.each{|w| + @title_list.each{|w| h = w.winfo_reqheight title_height = h if title_height < h } @@ -498,7 +498,7 @@ class TkMultiListFrame < TkListbox array[indices[0]] = line[label] else if line[label].kind_of? Array - indices.each_with_index{|index, num| + indices.each_with_index{|index, num| array[index] = line[label][num] } else @@ -516,9 +516,9 @@ class TkMultiListFrame < TkListbox indices.each{|index| lbox_ins[index] << line[index]} end } - } + } - @lbox_list.each_with_index{|lbox, index| + @lbox_list.each_with_index{|lbox, index| lbox.insert(idx, *lbox_ins[index]) if lbox_ins[index] } end @@ -560,7 +560,7 @@ class TkMultiListFrame < TkListbox (0..(@rel_list.size - 2)).each{|idx| title, lbox, hscr = @base_list[idx] title.place('relwidth'=>@rel_list[idx+1] - @rel_list[idx]) - lbox.place('relwidth'=>@rel_list[idx+1] - @rel_list[idx], + lbox.place('relwidth'=>@rel_list[idx+1] - @rel_list[idx], 'relheight'=>1.0) hscr.place('relwidth'=>@rel_list[idx+1] - @rel_list[idx]) } @@ -587,11 +587,11 @@ class TkMultiListFrame < TkListbox # adjustment of rightside widget of the sash title, lbox, hscr = @base_list[idx] - title.place('relwidth'=>@rel_list[idx+1] - @rel_list[idx], + title.place('relwidth'=>@rel_list[idx+1] - @rel_list[idx], 'relx'=>@rel_list[idx]) - lbox.place('relwidth'=>@rel_list[idx+1] - @rel_list[idx], + lbox.place('relwidth'=>@rel_list[idx+1] - @rel_list[idx], 'relx'=>@rel_list[idx], 'relheight'=>1.0) - hscr.place('relwidth'=>@rel_list[idx+1] - @rel_list[idx], + hscr.place('relwidth'=>@rel_list[idx+1] - @rel_list[idx], 'relx'=>@rel_list[idx]) # update reference position @@ -615,34 +615,34 @@ class TkMultiListFrame < TkListbox end def title_binding(title, index) - title.bind('Motion', proc{|w, x, idx| motion_cb(w, x, idx.to_i)}, + title.bind('Motion', proc{|w, x, idx| motion_cb(w, x, idx.to_i)}, "%W %x #{index}") - title.bind('Enter', proc{|w, x, idx| motion_cb(w, x, idx.to_i)}, + title.bind('Enter', proc{|w, x, idx| motion_cb(w, x, idx.to_i)}, "%W %x #{index}") title.bind('Leave', proc{|w| w.cursor ""}, "%W") - title.bind('Button-1', - proc{|w, x| + title.bind('Button-1', + proc{|w, x| if @mode == :sash @x = x @frame_width = TkWinfo.width(@f_title).to_f else title.relief 'sunken' end - }, + }, '%W %X') - title.bind('ButtonRelease-1', - proc{|w, x, idx| + title.bind('ButtonRelease-1', + proc{|w, x, idx| i = idx.to_i if @mode == :title && @title_cmd[i].kind_of?(Proc) @title_cmd[i].call end title.relief 'raised' motion_cb(w,x,i) - }, + }, "%W %x #{index}") title.bind('B1-Motion', proc{|x| resize(x) if @mode == :sash}, "%X") @@ -651,11 +651,11 @@ class TkMultiListFrame < TkListbox ################################# def browse_mode_bindtag t = TkBindTag.new - t.bind('Button-1', + t.bind('Button-1', proc{|w, y| w.focus; select_line(w, w.nearest(y))}, '%W %y') t.bind('B1-Motion', proc{|w, y| select_line(w, w.nearest(y))}, '%W %y') - t.bind('Shift-Button-1', + t.bind('Shift-Button-1', proc{|w, y| active_line(w, w.nearest(y))}, '%W %y') t.bind('Key-Up', proc{|w| select_shift(w, -1)}, '%W') @@ -666,7 +666,7 @@ class TkMultiListFrame < TkListbox t.bind('space', proc{|w| select_line(w, w.index('active').to_i)}, '%W') t.bind('Select', proc{|w| select_line(w, w.index('active').to_i)}, '%W') - t.bind('Control-slash', + t.bind('Control-slash', proc{|w| select_line(w, w.index('active').to_i)}, '%W') t @@ -675,12 +675,12 @@ class TkMultiListFrame < TkListbox ######################## def single_mode_bindtag t = TkBindTag.new - t.bind('Button-1', + t.bind('Button-1', proc{|w, y| w.focus; select_only(w, w.nearest(y))}, '%W %y') - t.bind('ButtonRelease-1', + t.bind('ButtonRelease-1', proc{|w, y| active_line(w, w.nearest(y))}, '%W %y') - t.bind('Shift-Button-1', + t.bind('Shift-Button-1', proc{|w, y| active_line(w, w.nearest(y))}, '%W %y') t.bind('Key-Up', proc{|w| select_shift(w, -1)}, '%W') @@ -691,9 +691,9 @@ class TkMultiListFrame < TkListbox t.bind('space', proc{|w| select_line(w, w.index('active').to_i)}, '%W') t.bind('Select', proc{|w| select_line(w, w.index('active').to_i)}, '%W') - t.bind('Control-slash', + t.bind('Control-slash', proc{|w| select_line(w, w.index('active').to_i)}, '%W') - t.bind('Control-backslash', + t.bind('Control-backslash', proc{@lbox_list.each{|l| l.selection_clear(0, 'end')}}) t @@ -702,22 +702,22 @@ class TkMultiListFrame < TkListbox ######################## def extended_mode_bindtag t = TkBindTag.new - t.bind('Button-1', + t.bind('Button-1', proc{|w, y| w.focus; select_only(w, w.nearest(y))}, '%W %y') t.bind('B1-Motion', proc{|w, y| select_range(w, w.nearest(y))}, '%W %y') - t.bind('ButtonRelease-1', + t.bind('ButtonRelease-1', proc{|w, y| active_line(w, w.nearest(y))}, '%W %y') - t.bind('Shift-Button-1', + t.bind('Shift-Button-1', proc{|w, y| select_range(w, w.nearest(y))}, '%W %y') - t.bind('Shift-B1-Motion', + t.bind('Shift-B1-Motion', proc{|w, y| select_range(w, w.nearest(y))}, '%W %y') - t.bind('Control-Button-1', + t.bind('Control-Button-1', proc{|w, y| select_toggle(w, w.nearest(y))}, '%W %y') - t.bind('Control-B1-Motion', + t.bind('Control-B1-Motion', proc{|w, y| select_drag(w, w.nearest(y))}, '%W %y') t.bind('Key-Up', proc{|w| active_shift(w, -1)}, '%W') @@ -743,9 +743,9 @@ class TkMultiListFrame < TkListbox ######################## def multiple_mode_bindtag t = TkBindTag.new - t.bind('Button-1', + t.bind('Button-1', proc{|w, y| w.focus; select_line3(w, w.nearest(y))}, '%W %y') - t.bind('ButtonRelease-1', + t.bind('ButtonRelease-1', proc{|w, y| active_line(w, w.nearest(y))}, '%W %y') t.bind('Key-Up', proc{|w| active_shift(w, -1)}, '%W') @@ -905,13 +905,13 @@ end # test ################################################ if __FILE__ == $0 - l = TkMultiListFrame.new(nil, 200, - [ ['L1', 200, proc{p 'click L1'}], - ['L2', 100], - ['L3', 200] ], - 'width'=>350, - #'titleforeground'=>'yellow', - 'titleforeground'=>'white', + l = TkMultiListFrame.new(nil, 200, + [ ['L1', 200, proc{p 'click L1'}], + ['L2', 100], + ['L3', 200] ], + 'width'=>350, + #'titleforeground'=>'yellow', + 'titleforeground'=>'white', #'titlebackground'=>'navy', 'titlebackground'=>'blue', 'titlefont'=>'courier' @@ -919,7 +919,7 @@ if __FILE__ == $0 l.insert('end', [1,2,3]) l.insert('end', [4,5,6]) l.insert('end', [4,5,6], [4,5,6]) - l.insert('end', ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + l.insert('end', ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'cccccccccccccccccccccccccccccccccccccccccccccccccccc']) l.insert('end', [1,2,3]) |