Author Topic: How can I access to controls in a tabbox page?  (Read 5396 times)

Offline Silvercup

  • PixInsight Addict
  • ***
  • Posts: 187
How can I access to controls in a tabbox page?
« on: 2010 February 27 13:13:29 »
Hi I need help:

I need to update a Edit control inside a tab page. How I can access to the control?

I can do ->  parent.tabs.currentPageIndex and return the active tab index.

Thanks. Silvercup

Offline Niall Saunders

  • PTeam Member
  • PixInsight Jedi Knight
  • *****
  • Posts: 1456
  • We have cookies? Where ?
Re: How can I access to controls in a tabbox page?
« Reply #1 on: 2010 February 27 18:49:14 »
I don't know if I can help you at all.

However, about a year ago Juan sent me the following code snippet to help get me going with <TABS> in PJSR, but I never had time to pursue things. Perhap it may be of 'some' use to you, I don't know

Code: [Select]
#include <pjsr/Sizer.jsh>
#include <pjsr/FrameStyle.jsh>
#include <pjsr/TextAlign.jsh>

function RandomChars( howMany )
{
   const c = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
   const n = c.length;
   var s = new String;
   for ( var i = 0; i < howMany; ++i )
      s += c[Math.round( Math.random()*(n-1) )];
   return s;
}

function MyTabPageControl( parent )
{
   this.__base__ = Control;
   if ( parent )
      this.__base__( parent );
   else
      this.__base__();

   this.helpLabel = new Label( this );
   this.helpLabel.frameStyle = FrameStyle_Box;
   this.helpLabel.margin = 4;
   this.helpLabel.wordWrapping = true;
   this.helpLabel.useRichText = true;
   this.helpLabel.text = "<p>This is a Control object inside a TabBox.<br/>" +
                         "This is a random string:<br/>" +
                         RandomChars( 40 ) + "</p>";

   this.targetImage_Label = new Label( this );
   this.targetImage_Label.text = "Target image:";
   this.targetImage_Label.textAlignment = TextAlign_Right|TextAlign_VertCenter;

   this.targetImage_ViewList = new ViewList( this );
   this.targetImage_ViewList.getAll(); // include main views as well as previews
   this.targetImage_ViewList.toolTip = "<p>This is just an example.</p>";

   this.targetImage_Sizer = new HorizontalSizer;
   this.targetImage_Sizer.spacing = 4;
   this.targetImage_Sizer.add( this.targetImage_Label );
   this.targetImage_Sizer.add( this.targetImage_ViewList, 100 );

   this.sizer = new VerticalSizer;
   this.sizer.margin = 6;
   this.sizer.spacing = 6;
   this.sizer.add( this.helpLabel );
   this.sizer.addSpacing( 4 );
   this.sizer.add( this.targetImage_Sizer );
}

MyTabPageControl.prototype = new Control;

function MyTabbedDialog()
{
   this.__base__ = Dialog;
   this.__base__();

   this.pages = new Array;
   this.pages.push( new MyTabPageControl( this ) );
   this.pages.push( new MyTabPageControl( this ) );
   this.pages.push( new MyTabPageControl( this ) );
   this.pages.push( new MyTabPageControl( this ) );

   this.tabs = new TabBox( this );
   this.tabs.setMinSize( 400, 200 );
   this.tabs.addPage( this.pages[0], "First" );
   this.tabs.addPage( this.pages[1], "Second" );
   this.tabs.addPage( this.pages[2], "Third" );
   this.tabs.addPage( this.pages[3], "Fourth" );

   this.okButton = new PushButton( this );
   this.okButton.text = "OK";
   this.okButton.onClick = function()
   {
      this.dialog.ok();
   }

   this.buttons = new HorizontalSizer;
   this.buttons.addStretch();
   this.buttons.add( this.okButton );

   this.sizer = new VerticalSizer;
   this.sizer.margin = 6;
   this.sizer.spacing = 6;
   this.sizer.add( this.tabs );
   this.sizer.add( this.buttons );

   this.windowTitle = "TabBox Example Script";
   this.adjustToContents();
}

MyTabbedDialog.prototype = new Dialog;

var dlg = new MyTabbedDialog;
dlg.execute();

Cheers,
Cheers,
Niall Saunders
Clinterty Observatories
Aberdeen, UK

Altair Astro GSO 10" f/8 Ritchey Chrétien CF OTA on EQ8 mount with homebrew 3D Balance and Pier
Moonfish ED80 APO & Celestron Omni XLT 120
QHY10 CCD & QHY5L-II Colour
9mm TS-OAG and Meade DSI-IIC

Offline Silvercup

  • PixInsight Addict
  • ***
  • Posts: 187
Re: How can I access to controls in a tabbox page?
« Reply #2 on: 2010 February 27 18:58:20 »
Thanks for your support Niall.

With some trials I have found it. You can acces this form:

parent.tabs.pageControlByIndex(0).Ltext_Edit.text=""


Where tabs is the TabBox object and Ltext_Edit is the Edit object control which is in the first tab (first page) i.e. pageControlByIndex(0).

You can acces to controls on secont tab simply using pageControlByIndex(1).

Best. Silvercup.

Offline Niall Saunders

  • PTeam Member
  • PixInsight Jedi Knight
  • *****
  • Posts: 1456
  • We have cookies? Where ?
Re: How can I access to controls in a tabbox page?
« Reply #3 on: 2010 February 27 19:12:15 »
I'll be looking forward to your completed script - adding TABS was the one thing I would have liked to have done with my <Batch deBayer> script (which I wrote out of necessity at the time, but which I also used to help me 'understand' PJSR in the absence of a "How to write PJSR" manual - hence the reason that the code is so long, and so FULL of detailed comments).

In fact, I will be interested to see your final code myself - if only to take your work with TABS and to then comment all the code sections in the same way as I did in my deBayer script!! In fact, despite my code being so camera-specific (for a Meade DSI-IC or -IIC camera), I reckon that Juan wanted to include it with all future 'standard distributions' of PI simply because it WAS so fully commented.

Cheers,
Cheers,
Niall Saunders
Clinterty Observatories
Aberdeen, UK

Altair Astro GSO 10" f/8 Ritchey Chrétien CF OTA on EQ8 mount with homebrew 3D Balance and Pier
Moonfish ED80 APO & Celestron Omni XLT 120
QHY10 CCD & QHY5L-II Colour
9mm TS-OAG and Meade DSI-IIC