Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Obejet Oriented Programing Problem

Status
Not open for further replies.

akpr

Programmer
Jul 25, 2001
19
US
I have class Toolbar
the class will create a frame, label and place a bitmap over the label
in this call there are methods called show and hide.

Problem No 1:
from [a tcl] file , reference for this class is called as shown below
::Toolbar ToolbarFile ".file"
ToolbarFile Show

::Toolbar Toolbaredit ".edit"
Toolbaredit Show

Now how do I give a public reference for that ToolbarFile class
i.e. I should be able to call any method belongs to this class using the reference [ToolbarFile ]
I.e. from another TCL files I should be able to call [ToolbarFile hide]

Problem No 2:
How do I unpack a frame from window.
i.e. if I called ToolbarFile hide . The visible toolbar should be gone
and if I call the method show from any other tcl file it should be visible

Thanks
akpr


 
pack has a option "forget" so if I had a button "b" in a frame "f" like so

frame .f
button .f.b -text "foo"

The command "pack .f.b" would pack it and the command "pack forget .f" would "unpack" it. It still exists in memory so it can be repacked as often as you like.
 
Problem 1:

ToolbarFile is an object not a class. "Files" are not significant in Tcl as regard
scope, so if you have created the object at
global scope (i.e. not within another object
or namespace) then [ToolbarFile hide] should
work. If it was created in a namespace or
another object, then you can construct a
fully qualified name by prepending:

[namespace current]::

Try the following example:

package require Itcl

itcl::class C1 {
method m {} { puts "$this doing m" }
}

itcl::class C2 {
constructor {} {
set ::public_c1 [namespace current]::[C1 #auto]
}
}

C2 #auto
puts "The object of class C1 owned by the object of class C2 can be accessed via the name $public_c1"
$public_c1 m


Problem 2:

In Tk, the "packing" or "gridding" of objects
is separate from creating them. So I would
not try to implement a method "hide", but would arrange for the enclosing widget to do
&quot;pack forget <pathname>&quot; to unpack it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top