The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Create a button by a script?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

tib

Switzerland
105 Posts

Posted - 01/11/2002 :  10:12:14 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
What I can do is:
label -s -sa -n start "Press here to start"; // create label;
start.text$="Press here to stop"; // change label text;
start.x=1000; // x position label;
start.y=1000; // y position label;
start.color=2; // set color;
start.script=1; // change text label to button;

I can also run this button by start.run();

But how can I assign a script via script to this button?
I expected something like start.script.text$="type -b Hello"; But I haven't found anything so far...

Thanks for any suggestions, Tilman.

Mike Buess

USA
3037 Posts

Posted - 01/11/2002 :  11:44:40 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can't assign an object's script with LabTalk. It has to be typed manually in the Label Control. One alternative is to create the button, add the script and save it as an OGO file.

draw -n start -f save %Ystart.ogo;

Then you can add it to any window you want with

draw -n start -f read %Ystart.ogo;

I use this method frequently.

Mike Buess
Origin WebRing Member
Go to Top of Page

tib

Switzerland
105 Posts

Posted - 01/11/2002 :  10:50:07 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Mike,
thank you, but your method is OK for one and the same button.
But I wanted to create 100 buttons (even more) arranged in a 10x10 matrix, where each button when pressed returns different values to variables and triggers an according action.
So, I wanted to avoid creating 100 buttons and change the script text by hand. But obviously, I have to do so...
Maybe there's an other solution to this problem?
Tilman.
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 01/12/2002 :  08:34:09 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Just assign different text to each button and have the script run a different command based on the button text.

// script in start button control label
run.section(MyScript,Main);

// save start button from script window
draw -n start -f save %Ystart.ogo

// recreate 100 times, label and position each
// you'll have to add something to define x and y for each button
loop (ii,1,100)
{
draw -n s$(ii) -f read %Ystart.ogo;
s$(ii).text$=s$(ii);
s$(ii).x=x; s$(ii).y=y;
};

// Myscript.ogs - this is the script that each button runs
[Main]
%A=this.text$;
run.section(,%A);

[s1]
-- button #1 commands --

[s2]
-- button #2 commands --
.
.
.
[s100]
-- button #100 commands --

Note: It's even simpler if you have OriginPro, in which you can create objects with multiple buttons.

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 01/12/2002 08:38:23

Edited by - Mike Buess on 01/12/2002 08:40:59

Edited by - Mike Buess on 01/12/2002 09:07:08
Go to Top of Page

tib

Switzerland
105 Posts

Posted - 01/13/2002 :  07:18:57 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Yes, Mike, this way works. I didn't remember the "this.text$" property.
In my special case this works even simpler. Since my buttons just return the x and y position of the button in the matrix.

Like you proposed...
[Main]
%A=this.text$; // use as button text 00 ... 99;
XPOS=int($(A)/10); // extract x position;
YPOS=mod($(A),10); // extract y position;

Then, I actually do not need these 100 sections.
[B00]
xpos=0; ypos=0;
.
.
[B99]
xpos=9; ypos=9;

BTW, how did you want to create these 100 sections? By hand?


I'm still convinced that a way like below would be much simpler and more flexible and would open up new ways of user interaction.

loop (xx,0,9) {
loop (yy,0,9) {
label -s -n B$(xx)$(yy) $(xx)$(yy); // create label with text;
B$(xx)$(yy).script=1; // change to button;
B$(xx)$(yy).x=...; // x-position of button in window, same for y;
B$(xx)$(yy).script.text$="XPOS=$(xx); YPOS=$(yy);"; // assign script text;
};
};

Would the semicolons in the text be problematic?
Maybe this is connected to an other problem which I also had, that it seems to be impossible via script to link a text label to variables. See posting "Adding a path stamp by script?".
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 01/13/2002 :  11:21:15 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Tilman,

Yes, it looks like this approach is tailor-made for your situation. As for creating 100 sections, I was going to leave that up to you.

I think your suggestion about "scriptable" scripts is a good one. There have been a number of times where it would have made my life easier. Whether or not semicolons would be a problem depends on how it was implemented. I rather doubt if it would be too hard to avoid such problems, but I'm not an Origin developer.

There may indeed be a connection between this problem and your "add path stamp..." topic. It also resembles the previous Expressing strings between { } topic, although the issues involved may be very different.



Mike Buess
Origin WebRing Member
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000