Creating a new widget 
Author Message
 Creating a new widget

Hello,

 I'm trying to create a new (axis) widget. It would be a canvas on which are
drawn the X and Y axis. I have a working version as a perl program, but I'm not
very familiar on how to put it in a package.
 I had a look at FileDialog.pm which was posted lately to this list. But this
seems rather complex. Is there a simple example which might guide me and which
should stop me from asking simple questions here.
 A problem I'm having for the moment is the following. The axis widget will
have the same options as a Canvas, but with some additional ones. When there is
a Axis->new(-option_1 => 5, -option_2 => 4); Is there an easy way to determine
if option_1 is specific for Axis or if it goes with Canvas.
 Which functions do I need. Do new, show, configure suffice ?

Kris,
--

Biomolecular NMR unit   < http://www.*-*-*.com/ ~kris>
University of Ghent, Belgium

--




Sat, 04 Jul 1998 03:00:00 GMT  
 Creating a new widget

On Tue, 16 Jan 1996 17:05:19 +0100

Quote:

>Hello,

> I'm trying to create a new (axis) widget. It would be a canvas on which are
>drawn the X and Y axis. I have a working version as a perl program, but I'm not
>very familiar on how to put it in a package.
> I had a look at FileDialog.pm which was posted lately to this list. But this                                                                      
>seems rather complex.

It is also very old-style way of making a package.
It is easier now but different.

Quote:
>Is there a simple example which might guide me and which
>should stop me from asking simple questions here.

Try and use Tk-b9.01 if you can...

Look at Tk-b9.01's HTML/HTMLText.pm, it is not that simple though...

Quote:
> A problem I'm having for the moment is the following. The axis widget will
>have the same options as a Canvas, but with some additional ones. When there is
>a Axis->new(-option_1 => 5, -option_2 => 4); Is there an easy way to determine
>if option_1 is specific for Axis or if it goes with Canvas.
> Which functions do I need. Do new, show, configure suffice ?

Don't mess with new or configure, just inherit from Tk::Derived
and add ConfigSpecs for your new options.

Skeleton is appended. There are other kinds of ConfigSpec
apart from METHOD, see perldoc Tk::ConfigSpec

-------------------------------------------------------------------
package Whatever;
require 5.002; # Sorry uses SUPER::

Tk::Widget->Construct('Whatever');

# Only Frame's have Populate so we have to go one level
# lower to InitObject
sub InitObject
{

 $w->SUPER::InitObject($args);
 $w->ConfigSpecs('-option_1' => ['METHOD',undef,undef,'some_default_1'],
                 '-option_2' => ['METHOD',undef,undef,'another-default'],
                );

Quote:
}

sub option_1  # name of new option
{


  {
   # $val is new value for -option_1
  }
 return whatever-current-value-of-option_1-is;

Quote:
}

sub option_2  # name of new option
{


  {
   # $val is new value for -option_2
  }
 return whatever-current-value-of-option_2-is;

Quote:
}

--




Sat, 04 Jul 1998 03:00:00 GMT  
 Creating a new widget
Kris Boulez wrote on 16-JAN-1996 13:15:40.65:

Quote:
> I'm trying to create a new (axis) widget. It would be a canvas on which are
>drawn the X and Y axis. I have a working version as a perl program, but I'm not
>very familiar on how to put it in a package.
> I had a look at FileDialog.pm which was posted lately to this list. But this
>seems rather complex. Is there a simple example which might guide me and which
>should stop me from asking simple questions here.

The Dial.pm widget that is distributed with Tk-b9.01 is a short succinct
example. (The "pod" documentation at the top of the requires an extra line.
 Instead of:
!-------------------------------------------------------------------
August 1995: Released for critique by pTk mailing list
=cut
!-------------------------------------------------------------------
 it should read:
!-------------------------------------------------------------------
August 1995: Released for critique by pTk mailing list

=cut
!-------------------------------------------------------------------
 but this is purely a documentation problem...does not affect functionality.)

The module is avaible (for Tk-b8 or older) on the web at:

    http://w4.lns.cornell.edu/~pvhp/ptk/etc/Dial.pm

Admittedly this sample widget is not excessively complicated and you may very
well be past the point where it would provide you with relevant info. Others
may find it illuminating however.

Peter Prymmer

--




Sat, 04 Jul 1998 03:00:00 GMT  
 Creating a new widget

On Wed, 17 Jan 1996 18:29:44 +0100

Quote:


>> NO YOU DON'T.  Please read the Tk/ConfigSpec.pod

>> (So, when I actually *do* write documentation it is not read,
>>  mumble mumble ... ;-))

> I have read it perhaps five times (or even more). The problem is that for Joe
>User (who I think I am) this is a whole new world and it is very hard to keep
>seeing the forest when one is confronted with a lot of new trees :-)

> I'm afraid I must be overlooking something because none of the suggested
>methods of retrieving the attributes seeems to work.

>In the perl program I have

>use Tk;
>use Axis;
>my $MW = MainWindow->new;
>my $t = $MW->Axis(-height => 150, -xmin =>3);

>In Axis.pm there is

>package Axis;

>require 5.002;
>require Tk::Canvas;


>Tk::Widget->Construct('Axis');

>sub InitObject
>{

>  $w->SUPER::InitObject($args);
>  $w->ConfigSpecs('-xmin' => ['PASSIVE',undef,undef,undef]);
>  $value = $w->{Configure}{-xmin};
>print "Value $value\n"; # this prints nothing ('undef')
>....

>changing this to $value = $w->cget(xmin); gives the same result. There is no
>error message, so he must have seen the xmin option.

As InitObject _defines_ what options are understood,
they Cannot be _set_ until InitObject returns.

Once InitObject returns 'new' (which is still in progress) does

$w->configure(-xmin => ...)

to set them. Once new returns it looks like any other object.

Note if you use METHOD mechanism you will be called back
when new does configure....

If you need value of xmin at 'InitObject' time, the options
passed to new are are in %$args - but don't forget defaults
processing is not done yet...

sub InitObject
{

  $w->SUPER::InitObject($args);

  $value = $args->{-xmin};
  print "xmin is $value\n";

  $w->ConfigSpecs('-xmin' => ['PASSIVE',undef,undef,undef]);

Quote:
}

>I must state here that I very much appreciate what you're doing and I find ptk
>great (I use it for my research and I'm rewriting a perl program to use TK to
>visualize the results).
>I must say that when I only try to do the things described in the Ousterhout
>book I have no real problems. It is only now when I'm trying to create a new
>widget I got stuck.

Thats the problem of course - creating a new widget in Tcl/Tk is just
as tricky even with Tix...

--




Sun, 05 Jul 1998 03:00:00 GMT  
 Creating a new widget

On Thu, 18 Jan 1996 09:55:52 +0100

Quote:

>[ I've reread the ConfigSpecs pod again and again. It must be in there but I'm
>obviously reading over it ]

I think it needs work...

Quote:

>Hello,

> OK, that works now. I can retrieve the options now where and when I want (if I
>had use the -w switch I would perhaps have noticed).

> I can't however retrieve the value of an option I haven't set, but for which I
>have given a default in the ConfigSpecs call.

Oh dear, I seem to have been misleading you.

It seems that as of Tk-b9.01 I have already tidied up Tk::Derived more
than I thought.  I also neglected to mention the need to call ConfigDefault
in an over-ridden InitObject.

So - here is real answer...

You *CAN* use Populate in any Tk::Derived, and that is appropriate
place to do ConfigSpecs.
Tk::Derived's InitObject will do the defaulting for you.

Thus your example can be made to work as follows:

Leave this bit alone:

Quote:

>#!/usr/local/bin/perl -w
>use Tk;
>use Axis;
>my $MWn = MainWindow->new;
>my($t) = $MWn->Axis;
>$t->configure(
>                -height => 150,
>                -width  => 200,
>               # -xmin   => 3,
>             );
>$t1 = $t->cget('-xmin');
>print "xmin is $t1\n";  #prints nothing

>MainLoop;

However in:

Quote:
>---------------Axis.pm----------------------------
>package Axis;

>require 5.002;
>require Tk::Canvas;


>Tk::Widget->Construct('Axis');

Loose InitObject or rather change to Populate:

sub Populate
{

  $w->SUPER::Populate($args);
  $w->ConfigSpecs('-xmin' => ['PASSIVE',undef,undef,5]);
  $w->pack;

Quote:
}

>1;

>__END__

And it works.

Many appologies...

--




Mon, 06 Jul 1998 03:00:00 GMT  
 Creating a new widget

On Mon, 22 Jan 1996 19:58:21 +0900

Quote:

>Is there anything like an emacs widget?

>I mean a text widget that has emacs-like keybindings, including cut-and-paste.

>Dave

The Text widget has some emacs bindings, but only where the don't
conflict with Motif-ness (as I understand it).

It should have cut-and-paste ...

--




Fri, 10 Jul 1998 03:00:00 GMT  
 Creating a new widget
Is there anything like an emacs widget?

I mean a text widget that has emacs-like keybindings, including cut-and-paste.

Dave

--




Fri, 10 Jul 1998 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. how to create new widgets ?

2. Is there any way to derive a widget without creating a new .pm

3. creating new widget

4. How to create the vertical text in canvas widget

5. Help needed to create a module exporting Tk widgets

6. TOGL widget create under Win32 crash - TOGL bug?

7. Need help creating custom widget

8. Create widgets via loop

9. creating a table with different widgets

10. Cannot create widgets!

11. Newer version of Enhanced Text widget available

12. RFC: Namespace for new module (tab widgets in HTML)

 

 
Powered by phpBB® Forum Software