Author Topic: How to handle multiple windows in a script?  (Read 482 times)

0 Members and 1 Guest are viewing this topic.

KylePierce

  • Newbie
  • *
  • Posts: 11
    • View Profile
How to handle multiple windows in a script?
« on: August 20, 2020, 08:47:55 PM »
I want to extend an existing script module by adding a button to open another window. I'm not sure whether a temporary window is possible or if not, can a window be hidden and shown to mimic closing and opening? I know I can include a library but does it say anywhere how multiple windows behave? I will find the limits by experimenting, I'm sure, but maybe there's something I'm overlooking?
« Last Edit: August 20, 2020, 08:49:57 PM by KylePierce »

ABer

  • Administrator
  • Jr. Member
  • *****
  • Posts: 88
    • View Profile
Re: How to handle multiple windows in a script?
« Reply #1 on: August 20, 2020, 09:07:03 PM »
Hi Kyle - I use canvas() a lot. It works quite well. You can see examples in Horoscope-Extra-Cosmobiology and many other scripts of mine. You can only have one canvas at a time. Ed

KylePierce

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: How to handle multiple windows in a script?
« Reply #2 on: August 20, 2020, 10:04:39 PM »
Thanks, Ed. I will check it out and see what works. Can you put controls on a canvas?

ABer

  • Administrator
  • Jr. Member
  • *****
  • Posts: 88
    • View Profile
Re: How to handle multiple windows in a script?
« Reply #3 on: August 21, 2020, 06:16:25 AM »
Hi Kyle - I've never gone that far with them. I have a feeling that the canvas can only take output, so essentially they're for displaying data. Another option is tab(). You can see this in action in Horoscope-Various-Chart Scopes. I've only started using this function recently. I'm going to be using this in the new version of Ed Greek Horoscope and probably in a lot more of the scripts that I write.

The advantage that I can see is that the user can step through tabs easier than going back to the menus for new output written to a canvas. You will see that one part of the tab can be dedicated to a permanent output (say a chart) while another part can be re-written with new output (say a listing of data). Again I'm not sure if the tabs can take controls, but they operate more like windows unlike canvas(), so they might do.

The limitation is screenwidth on this one. I think a lot of tabs can be generated but eventually you will run out of screenwidth to display them. I'm not sure if they wrap. Obviously the number of menu items is virtually unlimited but there's some practical display limits on tabs. They also take some vertical space from the display.

This is from the help:

tab

Syntax: tab(char menus[][$], label onchange)

Action:
makes a tabcontrol (see c:\planetdance\ab\extra settings.ab) with tab names found in 'str'. When a tab is clicked the label is called and the number of the tab is put in the variable 'tabnumber'.

Ed

Jean

  • Administrator
  • Full Member
  • *****
  • Posts: 145
    • View Profile
Re: How to handle multiple windows in a script?
« Reply #4 on: August 21, 2020, 09:09:36 AM »
So great to see discussion about ab here!!

A canvas can't hold controls, hence the name, only for painting.

A window with tabs can hold controls and you can put different controls on each tab, like Ed says an example is c:\planetdance\system\extra settings.ab
The script is a bit big though. Also it only puts the controls on each tab when it's selected, which makes it more complicated.

It makes use of some commands like group() to group controls.
In the tabchange label, which gets called on every tab click you see:
command(GROUP, -1, tabnumber + 1, 0);
This makes the controls from one group visible and hides the rest. There is an init() function that puts the controls on a window if needed.
See also the docs on group()
If you're stuck with that example say so, maybe it needs more documentation.


There's also c:\planetdance\ab\horoscope\extra\Wva.ab, it's much simpler because only one tab has controls.

EDIT: gonna make an working tab example and add it to the templates function.
Greetings from Groningen Netherlands <)))><.`.><(((>

KylePierce

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: How to handle multiple windows in a script?
« Reply #5 on: August 21, 2020, 02:07:16 PM »
Jean and Ed, thanks for your very helpful thoughts! I had not thought of using tabs, but that would probably do the job for me. I will check out the group() too.

Jean

  • Administrator
  • Full Member
  • *****
  • Posts: 145
    • View Profile
Re: How to handle multiple windows in a script?
« Reply #6 on: August 21, 2020, 02:52:57 PM »
I've added an example of a tabbed interface to the templates in the editor. You can mix it with canvas() if you fancy.
You could of course just as well make a main menu with the the same functions beside Close, it's just a user interface thing.
Multiple windows is not easy, have to keep track where the output goes, which windows are open etc and there are already some extra windows like grid().
Code: [Select]
window(800, 600);
menu(0, "Close", close);
char tabs[3][9]= "1", "2", "3", x;
tab(tabs, tabchange);

group(1);                   ` 0 is default group, these belong to group 1
button(33, 33, "Hi", NULL);
label(33, 99, "Hi world");

group(2);                        ` these belong to group 2
checkbox(33, 33, "x", x, NULL);

group(3);                         ` these belong to group 3
edit(33, 33, 99, tabs[0], NULL);

@tabchange;                       ` call it by hand the very first time, tabnumber is still 0
run;

:tabchange;
  command(GROUP, -1, tabnumber + 1, 0); ` set group tabnumber + 1 active (tabnumber is zero based, groups start at 1)
  fill(0, 0, width, height, -2);        ` clear previous grafix output
  switch (tabnumber)
    {
    :0; @dofirst; break;
    :1; @dosecond; break;
    :2; @dothird; break;
    }
  return;

:dofirst;
  line(0, 0, width, height, RED);
  return;

:dosecond;
  circle(99, 99, 66, BLUE);
  return;

:dothird;
  box(0, 0, width, height, PURPLE, 2);
  return;

:close;
  quit;
Greetings from Groningen Netherlands <)))><.`.><(((>

ABer

  • Administrator
  • Jr. Member
  • *****
  • Posts: 88
    • View Profile
Re: How to handle multiple windows in a script?
« Reply #7 on: August 21, 2020, 06:32:17 PM »
Thanks Jean - that's a really helpful template. I like tabs. They worked well on the scripts that I used them in.

All the best. Ed

Jean

  • Administrator
  • Full Member
  • *****
  • Posts: 145
    • View Profile
Re: How to handle multiple windows in a script?
« Reply #8 on: August 21, 2020, 09:14:54 PM »
Yes but in fact you can achieve the same with a plain menu, and have even more screenspace. Strictly speaking it's only a bigger sized menu. :)
Greetings from Groningen Netherlands <)))><.`.><(((>

Jean

  • Administrator
  • Full Member
  • *****
  • Posts: 145
    • View Profile
Re: How to handle multiple windows in a script?
« Reply #9 on: August 22, 2020, 03:37:01 PM »
Another template: window with menu / group
Same as above but with a plain menu. It also shows a control to modify the width of the circle on one of the pages.
Code: [Select]
window(800, 600);
char x, s[9]="world";
int r = 99;
menu(0, "Close", close);
menu(0, "One", do);
menu(0, "Two", do);
menu(0, "Three", do);

group(1);                   ` 0 is default group, these belong to group 1
button(33, 33, "Hi", NULL);
edit(111, 33, 99, s, NULL);

group(2);                        ` these belong to group 2
updownx(11, 11, x, dosecond, 0, 60, 10, &r);
label(33, 99, "Hi world");

group(3);                         ` these belong to group 3
checkbox(33, 33, "x", x, NULL);
menunumber = 1;`                   ` this is menu One
@do;
run;

:do;
  command(GROUP, -1, menunumber, 0);  ` activate the group
  fill(0, 0, width, height, -2);      ` clear screen
  switch (menunumber)
    {
    :1; @dofirst; break;
    :2; @dosecond; break;
    :3; @dothird; break;
    }
  return;

:dofirst;
  line(0, 0, width, height, RED);
  return;
 
:dosecond;
  fill(0, 0, width, height, -2);           ` clear screen for new radius
  circle(width / 2, height / 2, r, BLUE);
  return;

:dothird;
  box(0, 0, width, height, PURPLE, 2);
  return;

:close;
  quit;

Greetings from Groningen Netherlands <)))><.`.><(((>