Forum: Ruby Equivalent to Perl's Tk::Tiler?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
430373cc99a1c2526b0651089ef11b35?d=identicon&s=25 fkc_email-news (Guest)
on 2005-12-05 18:18
(Received via mailing list)
Hi All:

   I making arbitrarily large forms and in doing similar in Perl, I've
used Tk::Tiler, a scrollable frame.  I'd just pack my various entries
into the form, and set a max size, from which the form would
automatically scroll if the contents were larger than the form size.

   I've found a scrollable canvas sample I could use, but worry about
the
of resources it might take up.  Any pointers?

   Thanks.

Forrest
E4f967492dbd03c526cc9b397e68021d?d=identicon&s=25 nagai (Guest)
on 2005-12-07 03:44
(Received via mailing list)
From: Forrest Chang <fkc_email-news@yahoo.com>
Subject: [tk] Equivalent to Perl's Tk::Tiler?
Date: Tue, 6 Dec 2005 02:17:33 +0900
Message-ID: <81lkyz79dm.fsf@yahoo.com>
>    I making arbitrarily large forms and in doing similar in Perl, I've
> used Tk::Tiler, a scrollable frame.  I'd just pack my various entries
> into the form, and set a max size, from which the form would
> automatically scroll if the contents were larger than the form size.
>
>    I've found a scrollable canvas sample I could use, but worry about the
> of resources it might take up.  Any pointers?

I don't know Perl's Tk::Tiler. Is it the one like the following?
---------------------------------------------------------------
#
#  scrframe.rb
#
require 'tk'

class Tk::ScrollFrame < TkFrame
  include TkComposite

  DEFAULT_WIDTH  = 200
  DEFAULT_HEIGHT = 200

  def initialize_composite(keys={})
    @frame.configure(:width=>DEFAULT_WIDTH, :height=>DEFAULT_HEIGHT)

    # create scrollbars
    @v_scroll = TkScrollbar.new(@frame, 'orient'=>'vertical')
    @h_scroll = TkScrollbar.new(@frame, 'orient'=>'horizontal')

    # create a canvas widget
    @canvas = TkCanvas.new(@frame)

    # allignment
    TkGrid.rowconfigure(@frame, 0, 'weight'=>1, 'minsize'=>0)
    TkGrid.columnconfigure(@frame, 0, 'weight'=>1, 'minsize'=>0)
    @canvas.grid('row'=>0, 'column'=>0, 'sticky'=>'news')
    @frame.grid_propagate(false)

    # assign scrollbars
    @canvas.xscrollbar(@h_scroll)
    @canvas.yscrollbar(@v_scroll)

    # scrollbars ON
    vscroll(keys.delete('vscroll'){true})
    hscroll(keys.delete('hscroll'){true})

    # create base frame
    @base = TkFrame.new(@canvas)

    # embed base frame
    @cwin = TkcWindow.new(@canvas, [0, 0], :window=>@base,
:anchor=>'nw')
    @canvas.scrollregion(@cwin.bbox)

    # binding to reset scrollregion
    @base.bind('Configure'){ @canvas.scrollregion(@cwin.bbox) }

    # set default receiver of method calls
    @path = @base.path

    # please check the differences of the following definitions
    option_methods(
      :scrollbarwidth
    )

    # set receiver widgets for configure methods (with alias)
    delegate_alias('scrollbarrelief', 'relief', @h_scroll, @v_scroll)

    # set receiver widgets for configure methods
    delegate('DEFAULT', @base)
    delegate('background', @frame, @base, @canvas, @h_scroll, @v_scroll)
    delegate('width', @frame)
    delegate('height', @frame)
    delegate('activebackground', @h_scroll, @v_scroll)
    delegate('troughcolor', @h_scroll, @v_scroll)
    delegate('repeatdelay', @h_scroll, @v_scroll)
    delegate('repeatinterval', @h_scroll, @v_scroll)
    delegate('borderwidth', @frame)
    delegate('relief', @frame)

    # do configure
    configure keys unless keys.empty?
  end

  # forbid to change binding of @base frame
  def bind(*args)
    @frame.bind(*args)
  end
  def bind_append(*args)
    @frame.bind_append(*args)
  end
  def bind_remove(*args)
    @frame.bind_remove(*args)
  end
  def bindinfo(*args)
    @frame.bindinfo(*args)
  end

  # set width of scrollbar
  def scrollbarwidth(width = nil)
    if width
      @h_scroll.width(width)
      @v_scroll.width(width)
    else
      @h_scroll.width
    end
  end

  # vertical scrollbar : ON/OFF
  def vscroll(mode)
    st = TkGrid.info(@v_scroll)
    if mode && st.size == 0 then
      @v_scroll.grid('row'=>0, 'column'=>1, 'sticky'=>'ns')
    elsif !mode && st.size != 0 then
      @v_scroll.ungrid
    end
    self
  end

  # horizontal scrollbar : ON/OFF
  def hscroll(mode)
    st = TkGrid.info(@h_scroll)
    if mode && st.size == 0 then
      @h_scroll.grid('row'=>1, 'column'=>0, 'sticky'=>'ew')
    elsif !mode && st.size != 0 then
      @h_scroll.ungrid
    end
    self
  end
end

# test
if __FILE__ == $0
  f = Tk::ScrollFrame.new(:scrollbarwidth=>10, :width=>300,
:height=>200)
  f.pack(:expand=>true, :fill=>:both)

  TkButton.new(f, :text=>'foo bar button', :command=>proc{puts 'foo
bar'}).pack
  Tk.after(3000){TkText.new(f).pack(:expand=>true, :fill=>:both)}

  Tk.mainloop
end
430373cc99a1c2526b0651089ef11b35?d=identicon&s=25 fkc_email-news (Guest)
on 2005-12-07 21:08
(Received via mailing list)
Hi:

        So I get the following error when running it (latest stable 1
click installer on windows xp)

ruby scrframe.rb
c:/ruby/lib/ruby/1.8/tk.rb:3630:in `grid_propagate': undefined method
`propagete' for TkGrid:Module (NoMethodError)
	from scrframe.rb:26:in `initialize_composite'
	from c:/ruby/lib/ruby/1.8/tk/composite.rb:20:in `initialize'
	from scrframe.rb:122:in `new'
	from scrframe.rb:122

Thanks

Forrest
E4f967492dbd03c526cc9b397e68021d?d=identicon&s=25 nagai (Guest)
on 2005-12-08 03:20
(Received via mailing list)
From: Forrest Chang <fkc_email-news@yahoo.com>
Subject: Re: [tk] Equivalent to Perl's Tk::Tiler?
Date: Thu, 8 Dec 2005 05:07:35 +0900
Message-ID: <81acfc7ju3.fsf@yahoo.com>
>         So I get the following error when running it (latest stable 1 click installer on 
windows xp)
>
> ruby scrframe.rb
> c:/ruby/lib/ruby/1.8/tk.rb:3630:in `grid_propagate': undefined method `propagete' for 
TkGrid:Module (NoMethodError)

Oh, sorry. The method is available ruby-1.8.2 or later.
Please replace
430373cc99a1c2526b0651089ef11b35?d=identicon&s=25 fkc_email-news (Guest)
on 2005-12-09 23:55
(Received via mailing list)
Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> writes:

> Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
Now it displays a window briefly and then segfaults, both on win XP and
win 2K

---------------------
c:/ruby/lib/ruby/1.8/tk.rb:1383: [BUG] Segmentation fault
ruby 1.8.2 (2004-12-25) [i386-mswin32]


This application has requested the Runtime to terminate it in an unusual
way.
Please contact the application's support team for more information.
E4f967492dbd03c526cc9b397e68021d?d=identicon&s=25 nagai (Guest)
on 2005-12-11 16:36
(Received via mailing list)
From: Forrest Chang <fkc_email-news@yahoo.com>
Subject: Re: [tk] Equivalent to Perl's Tk::Tiler?
Date: Sat, 10 Dec 2005 07:52:36 +0900
Message-ID: <81vexx6g7a.fsf@yahoo.com>
> Now it displays a window briefly and then segfaults, both on win XP and win 2K

When do you get SEGV? Before displaying Tk window?
Or at about 3 seconds after running the sample?
Even if replace
-------------------------------------------------------------------
  Tk.after(3000){TkText.new(f).pack(:expand=>true, :fill=>:both)}
430373cc99a1c2526b0651089ef11b35?d=identicon&s=25 Forrest Chang (Guest)
on 2005-12-12 22:40
(Received via mailing list)
Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> writes:

> When do you get SEGV? Before displaying Tk window?
  Pretty much immediately after I see the tk window.

> Or at about 3 seconds after running the sample?
> Even if replace
> -------------------------------------------------------------------
>   Tk.after(3000){TkText.new(f).pack(:expand=>true, :fill=>:both)}
> -------------------------------------------------------------------
> to
> -------------------------------------------------------------------
>   TkText.new(f).pack(:expand=>true, :fill=>:both)
> -------------------------------------------------------------------

  If I replace with this, it seems stable as long as I don't change the
horizontal sizing or scrolling, i.e. moving the horizontal scrollbar
crashes, or sizing it in the horizontal direction causes a crash.
Vertical scrolling and sizing doesn't crash it.

> , do you get SEGV?
> Can you try one of the later version (e.g. 1.8.3 or 1.8.4preview) ?
> --

  I'm using the 1 click installer, I'm not really setup to compile on
XP, but if I find time I can try.

  Thanks for your help thus far though

Forrest
This topic is locked and can not be replied to.