From: Hidetoshi NAGAI Date: 2008-02-05T18:13:28+09:00 Subject: Re: Ruby/Tk/Iwidgets tabnotebook (and scrollbar) From: Karl Miller Subject: Ruby/Tk/Iwidgets tabnotebook (and scrollbar) Date: Tue, 29 Jan 2008 10:55:26 +0900 Message-ID: <870d25c134b16e7234d146b03c43a1df@ruby-forum.com> > I've created an iwidgets tabnotebook, with a large number of tabs, > and attached a scrollbar. > > Moving the scroll bar successfully moves back and forth amongst pages, > but the subset of tabs displayed does not change. (snip) > Am I doing something wrong? You must control start position of the tabset. > #!/usr/bin/env ruby > require 'tk' > require 'tkextlib/iwidgets' > > # Create the tabnotebook widget and pack it. > tn = Tk::Iwidgets::Tabnotebook.new(:width=>300, :height=>100) > tn.pack(:anchor=>:nw, :fill=>:both, :expand=>true, > :side=>:top, :padx=>10, :pady=>0) > > # Add twenty pages to the tabnotebook > 1.upto(20) { |t| > txt = 'Page ' + t.to_s > tn.add(:label => txt) > } # Command to control the tabset tabset = tn.component_widget('tabset') tabset.command{|idx| left = tabset.tabcget(idx, :left) prev = tabset.index(idx) - 1 if prev < 0 tabset.start = 0 elsif left < 0 tabset.start -= left elsif left + (tabwidth = tabset.tabcget(idx,:width)) > (tabset_width = tabset.width) tabset.start -= left - tabset_width + 2*(left - tabset.tabcget(prev,:left)) - tabwidth + 1 end } > # Add a button on page 1 to change to tab 20 > button = TkButton.new(tn.child_site(0),:text =>'Go to Page 20').pack > button.command { > tn.select(19) # tn.view etc have the same problem > } > > # Select the first page of the tabnotebook. > tn.select(0) > > # Create the scrollbar > # and the notebook together, then pack the scrollbar > tn.xscrollbar(TkScrollbar.new).pack(:fill=>:x, > :expand=>true, :padx=>10) > > Tk.mainloop -- Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)