Tk scrolled canvas

  • Thread starter R. Mark Volkmann
  • Start date
R

R. Mark Volkmann

I can create a canvas like this.

root = TkRoot.new {title 'Diagram'}
canvas = TkCanvas.new(root)

I think I should be able to create a scrolled canvas like this, but it
doesn't work.

scrolled = TkScrolledcanvas.new(root)

I've search the mailing list for the answer and can't find it.
What's the correct syntax?
 
H

Hidetoshi NAGAI

Hi,

From: "R. Mark Volkmann" <[email protected]>
Subject: Tk scrolled canvas
Date: Sun, 5 Dec 2004 12:17:01 +0900
Message-ID: said:
I think I should be able to create a scrolled canvas like this, but it
doesn't work.

Please define the widget class which you want. ;-)
See sample scripts at ext/tk/samples directory of Ruby source archive.

If refer to ext/tk/samples/tktextframe.rb,
TkScrolledCanvas can be defined as such as the following.
---------------------------------------------------------------------
#!/usr/bin/env ruby
require 'tk'

class TkScrolledCanvas < TkCanvas
include TkComposite

def initialize_composite(keys={})
@h_scr = TkScrollbar.new(@frame)
@v_scr = TkScrollbar.new(@frame)

@canvas = TkCanvas.new(@frame)
@path = @canvas.path

@canvas.xscrollbar(@h_scr)
@canvas.yscrollbar(@v_scr)

TkGrid.rowconfigure(@frame, 0, :weight=>1, :minsize=>0)
TkGrid.columnconfigure(@frame, 0, :weight=>1, :minsize=>0)

@canvas.grid:)row=>0, :column=>0, :sticky=>'news')
@h_scr.grid:)row=>1, :column=>0, :sticky=>'ew')
@v_scr.grid:)row=>0, :column=>1, :sticky=>'ns')

delegate('DEFAULT', @canvas)
delegate('background', @text, @h_scr, @v_scr)
delegate('activeforeground', @h_scr, @v_scr)
delegate('troughcolor', @h_scr, @v_scr)
delegate('repeatdelay', @h_scr, @v_scr)
delegate('repeatinterval', @h_scr, @v_scr)
delegate('borderwidth', @frame)
delegate('relief', @frame)

delegate_alias('canvasborderwidth', 'borderwidth', @canvas)
delegate_alias('canvasrelief', 'relief', @canvas)

delegate_alias('scrollbarborderwidth', 'borderwidth', @h_scr, @v_scr)
delegate_alias('scrollbarrelief', 'relief', @h_scr, @v_scr)

configure(keys) unless keys.empty?
end
end

c = TkScrolledCanvas.new:)scrollregion=>[0,0,500,400]).pack
TkcRectangle.new(c, [100,100], [300, 200])

Tk.mainloop
 
R

R. Mark Volkmann

----- Original Message -----
From: "Hidetoshi NAGAI" <[email protected]>
To: "ruby-talk ML" <[email protected]>
Sent: Sunday, December 05, 2004 2:09 AM
Subject: Re: Tk scrolled canvas

Hi,

From: "R. Mark Volkmann" <[email protected]>
Subject: Tk scrolled canvas
Date: Sun, 5 Dec 2004 12:17:01 +0900


Please define the widget class which you want. ;-)

I don't understand why I have to write my own TkScrolledCanvas class.
Why doesn't a scrolled canvas already exist?
It is discussed in the book "Learning Perl/Tk" on the first page of chapter
9.
The author says you can either create a plain "Canvas" or a "Scrolled" which
is a scrollable Canvas.
See sample scripts at ext/tk/samples directory of Ruby source archive.

If refer to ext/tk/samples/tktextframe.rb,
TkScrolledCanvas can be defined as such as the following.
---------------------------------------------------------------------
#!/usr/bin/env ruby
require 'tk'

class TkScrolledCanvas < TkCanvas
include TkComposite

def initialize_composite(keys={})
@h_scr = TkScrollbar.new(@frame)
@v_scr = TkScrollbar.new(@frame)

@canvas = TkCanvas.new(@frame)
@path = @canvas.path

@canvas.xscrollbar(@h_scr)
@canvas.yscrollbar(@v_scr)

TkGrid.rowconfigure(@frame, 0, :weight=>1, :minsize=>0)
TkGrid.columnconfigure(@frame, 0, :weight=>1, :minsize=>0)

@canvas.grid:)row=>0, :column=>0, :sticky=>'news')
@h_scr.grid:)row=>1, :column=>0, :sticky=>'ew')
@v_scr.grid:)row=>0, :column=>1, :sticky=>'ns')

delegate('DEFAULT', @canvas)
delegate('background', @text, @h_scr, @v_scr)
delegate('activeforeground', @h_scr, @v_scr)
delegate('troughcolor', @h_scr, @v_scr)
delegate('repeatdelay', @h_scr, @v_scr)
delegate('repeatinterval', @h_scr, @v_scr)
delegate('borderwidth', @frame)
delegate('relief', @frame)

delegate_alias('canvasborderwidth', 'borderwidth', @canvas)
delegate_alias('canvasrelief', 'relief', @canvas)

delegate_alias('scrollbarborderwidth', 'borderwidth', @h_scr, @v_scr)
delegate_alias('scrollbarrelief', 'relief', @h_scr, @v_scr)

configure(keys) unless keys.empty?
end
end

c = TkScrolledCanvas.new:)scrollregion=>[0,0,500,400]).pack
TkcRectangle.new(c, [100,100], [300, 200])

Tk.mainloop
 
H

Hidetoshi NAGAI

Hi,

From: "R. Mark Volkmann" <[email protected]>
Subject: Re: Tk scrolled canvas
Date: Mon, 6 Dec 2004 00:45:10 +0900
Message-ID: said:
I don't understand why I have to write my own TkScrolledCanvas class.
Why doesn't a scrolled canvas already exist?

Because a scrolled canvas is not a standard widget of Tcl/Tk. :)

As I showed my last mail, it is easy to create a TkScrolledCanvas
widget class. However, it is not clear how much configurable the
class is required to add it to Ruby/Tk standard libraries.

Of course, we can allow full configuration of all part of the widget
by delegate_alias method and so on. But, is it realy right solution?
Maybe it only create many of configuration keys which have a very
long name and rare necessity. Possibly, it is not so easy to decide
the balance point. If a widget class is entried as a standard library,
it is a litte difficult to change specification of the widget.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,163
Messages
2,570,897
Members
47,434
Latest member
TobiasLoan

Latest Threads

Top