Author image Graham Bell
and 3 contributors


Tk::SourceCatalog - creates a self-standing sources catalog widget


  use Tk::AstroCatalog;

  $cat = new Tk::AstroCatalog($MW, $addCmd, $upDate, $onDestroy);


Tk::AstroCatalog creates a non-editable text widget, displaying sources from a default catalog or user-selected catalog file.


Methods available in this class:


Create a new Tk::AstroCatalog object. A new catalog object will be created. Callbacks must be specified for -addCmd and -upDate; a warning is issued for -onDestroy when it is missing.

  $cat = new Tk::AstroCatalog($MW,
                            -addCmd => $addCmd,
                            -upDate => $upDate,
                            -onDestroy => $onDestroy);

Additionally a pre-existing Astro::Catalog object can be supplied using the "-catalog" option.

  $cat = new Tk::AstroCatalog($MW,
                            -addCmd => $addCmd,
                            -upDate => $upDate
                            -catalog => $cat,

The "-transient" option can be used if only a single value is required from the widget. Default behaviour is for the widget to be permanent. The "-transient" button does not have a "Done" button on the screen (ie no button to close the window without a selection)

The "-addCmd" callback is triggered whenever a source is selected from the widget. If the widget is transient the widget will be closed after the first add is triggered.

The "-onDestroy" callback is triggered when the "Done" button is pressed.

The "-upDate" method is triggered whenever the contents of the catalog widget are refreshed/updated.

It makes more sense for this widget to work like Tk::FileSelect when used in transient mode since we want to get the answer back rather than enter an event loop.

The "-customColumns" method can be used to add additional columns to the display. This is an array of hashes specifying the title, width and generator function for each column. This generating function will be called with an Astro::Catalog::Item and must return a string of the given width.

  -customColumns => [{title     => 'Example',
                      width     => 7,
                      generator => sub {
                                     my $item = shift;
                                     return sprintf('%7s', 'test');

Returns and sets the Astro::Catalog object.

  $catalog = $cat->Catalog();
  $cat->Catalog(new Astro::Catalog(...));

returns and sets the AddCommand callback code for the catalog

  $addCommand = $cat->AddCommand();

returns and sets the UpDate callback code for the catalog

  $update = $cat->UpDate();

Called whenever the contents of the text widget are redisplayed. The first argument will be the current object.


returns and sets the onDestroy callback code for the catalog

  $reset = $cat->Reset();

returns and sets the name of the Toplevel

  $toplevel = $cat->Toplevel();

returns and sets whether the widget should be destroyed after the next Add.

  $toplevel = $cat->Transient();

returns and sets the name of the Text

  $text = $cat->Text();

Configure the text displayed in the reference label widget. Usually a summary of the reference position.


Returns a reference to a scalar that can be used to associate the value with a widget.


returns and sets the name of the CatClass

  $class = $cat->CatClass();

returns the Selected array or the indexed value of this array

  @selected = $cat->Selected();
  $value = $cat->Selected($index);

returns and sets the File name

  $file = $cat->file();

makeCatalog creates a window that displays the contents of a catalog and allows the user to select as many entries as the user wishes.

  $catalog = $cat->makeCatalog();
  $catalog = $cat->makeCatalog($selected);

Remove the widget from display. Leaves calling the Reset handler to the DESTROY method.


Object destructor. Triggers when the object is destroyed. Guarantees to destroy the Toplevel widget and does trigger the onDestroy callback.


fills a text widget with the list of current sources


Also triggers the UpDate method.


returns a color from @COLOR_LIST and increments the latter's index

  $color = $cat->color();

Displays an error message in Tk

   $cat->error('Error message');
 inswt inserts text into a given text widget and applies
 one or more tags to that text.

        $text  -  Text to insert (it's inserted at the "insert" mark)
        $args  -  One or more tags to apply to text.  If this is empty
                  then all tags are removed from the text.

   $cat->inswt($text, $args);

getSource prompts the user to enter source coords and name and filters the catalog based on the input provided.

Takes the new top level widget to use, and the search button to be re-activated when this window closes.

   $obj = $cat->getSource($toplevel, $search_button);
  isWithin returns a boolean value as to whether an element is
  within the array specified.

   $obj = $cat->isWithin($element, @array);
   Removes the item passed from the array specified.

   $obj = $cat->remove($element, @array);


Astro::Catalog, Astro::Catalog::Star, Astro::Coords


Copyright (C) 2013 Science & Technology Facilities Council. Copyright (C) 1999-2002,2004 Particle Physics and Astronomy Research Council. All Rights Reserved.


Major subroutines and layout originally designed by Casey Best (University of Victoria) with modifications to create independent composite widget by Tim Jenness and Pam Shimek (University of Victoria)

Revamped for Astro::Catalog by Tim Jenness.