Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: rrc1962 on April 10, 2017, 04:56:21 PM

Title: Reading text box on screen
Post by: rrc1962 on April 10, 2017, 04:56:21 PM
I'm having some diffiuclty with this.  I'm doing this numerous times with DRO's, but the text box seems to be an issue.  This is how I'm doing it with DRO's and it works great.  I figured the same approach would work with text boxes....

First, I save the text box value in the On Modify Script like this...

Code: [Select]
local inst = mc.mcGetInstance()
local val = scr.GetProperty("twFileName", "Value")
mc.mcProfileWriteString(inst, "PersistentDROs", "twFileName", string.format (val))

Then inside a Lua module, I try to read the value like this.  The code executes, but always returns "Error", which I'm assuming means that it's not finding the key value.

Code: [Select]
----------------------------------------------------------------
-- Get parameters
----------------------------------------------------------------
function getParam(key)
    local inst = mc.mcGetInstance()
    local theParam = mc.mcProfileGetString(inst,'PersistentDROs',key,'Error')
    return theParam
end
----------------------------------------------------------------
-- Display file name to dialog
----------------------------------------------------------------
function TW.ShowFileName()
    f = getParam('twFileName')
    wx.wxMessageBox(f)  
end

I can do this in a button event script as well, but I wasn't able to read the text box value there either.  Any idea what I'm doing wrong?  This works fine with DRO's.

Thanks
Title: Re: Reading text box on screen
Post by: rrc1962 on April 10, 2017, 05:26:51 PM
On a similar note, is there such a thing as a user input dialog in Lua?  Or maybe a way to invoke the windows file dialog and capture the users input?

I think the problem with text boxes is that there is no "value" or "text" property.  How do you read the value of a text box?  Problem here is the operator needs to enter alpha numeric data and I need to read it back.  DRO's can only take numbers.
Title: Re: Reading text box on screen
Post by: rrc1962 on April 10, 2017, 07:58:01 PM
Well, I found how to get input from the operator, which solves the problem at hand.  This function does it...

wxGetTextFromUser()

There is a file picker in the same group of function.  Might also give that a try.  I'd still like to find a way to read a text box though.
Title: Re: Reading text box on screen
Post by: gorf23 on April 10, 2017, 09:10:15 PM
if you created a text box on the mach4 screen you can read it like this

function m710()

local txt_Box = scr.GetProperty("txtBox", "Value")
wx.wxMessageBox(txt_Box)
end
if (mc.mcInEditor() == 1) then
 m710()
end

then put this in the, on modify script for the text button to save the text anytime you write in the text box
local inst = mc.mcGetInstance()

local val = scr.GetProperty("txtBox", "Value")
mc.mcProfileWriteString(inst, "PersistentDROs", "txtBox", string.format (val)) --Create a register and write to it
 
Title: Re: Reading text box on screen
Post by: rrc1962 on April 10, 2017, 11:30:40 PM
Have you tried that?  The text box element does not have a "value" parameter.  DROs do, text boxes don't.  Makes one wonder why there would be a screen element that allows user input, but no way to read that input.
Title: Re: Reading text box on screen
Post by: Chaoticone on April 11, 2017, 01:32:55 AM
Quote
Have you tried that?

I have. Can get it and set it as expected here.

Code: [Select]
MyTest = scr.GetProperty("txtTest", "Value")
wx.wxMessageBox(MyTest)
scr.SetProperty("txtTest", "Value", "Test2")
Title: Re: Reading text box on screen
Post by: rrc1962 on April 11, 2017, 10:23:31 AM
Quote
Have you tried that?

I have. Can get it and set it as expected here.

Code: [Select]
MyTest = scr.GetProperty("txtTest", "Value")
wx.wxMessageBox(MyTest)
scr.SetProperty("txtTest", "Value", "Test2")

Doesn't work on my end.  Maybe they exposed the value property in a later version.  What version are you running? 

Just so we're on the same page, we are talking about a textbox here, not a DRO.  If I place a textbox, I don't see a "Value" property associated with it.  If I place a DRO, I do see a "Value" property.

Title: Re: Reading text box on screen
Post by: gorf23 on April 11, 2017, 12:58:11 PM
mach4 ver 3346

I just tested it again and it works for me I have a textbox on the mach4 screen enter whatever text I want...

then I have the script in the editor running with the debugger and when it calls the messageBox  it displays the
info I just typed into the textbox... don't know what else to say.

gary
Title: Re: Reading text box on screen
Post by: Chaoticone on April 11, 2017, 03:32:46 PM
Quote
Have you tried that?

I have. Can get it and set it as expected here.

Code: [Select]
MyTest = scr.GetProperty("txtTest", "Value")
wx.wxMessageBox(MyTest)
scr.SetProperty("txtTest", "Value", "Test2")

Doesn't work on my end.  Maybe they exposed the value property in a later version.  What version are you running? 

Just so we're on the same page, we are talking about a textbox here, not a DRO.  If I place a textbox, I don't see a "Value" property associated with it.  If I place a DRO, I do see a "Value" property.



Version 3233, which you should be running too. It may well not have been accessible in earlier versions, I can't say for sure though.

Yup, I am talking about a textbox, not a DRO.
Title: Re: Reading text box on screen
Post by: rrc1962 on April 11, 2017, 04:08:42 PM
I'm on 2914.  Can I update without upsetting the license, screenset or directories I'm currently working on?  I know Mach 4 uses a different licensing scheme than Mach 3
Title: Re: Reading text box on screen
Post by: gorf23 on April 11, 2017, 06:44:45 PM
As far as I know I know they changed the license's with one of the updates but you can get a new one if that is the case...
 
Title: Re: Reading text box on screen
Post by: Chaoticone on April 11, 2017, 07:11:00 PM
I'm on 2914.  Can I update without upsetting the license, screenset or directories I'm currently working on?  I know Mach 4 uses a different licensing scheme than Mach 3

Other than the license, absolutely ........assuming of course you have not been modifying anything that comes with Mach (defaults, which no one should ever modify). Customizing defaults makes a mess and is almost always a very bad idea.

License changed at some point but you can login to your account you created when you bought the license and mange your license if you need to disable the existing and generate a new one.
Title: Re: Reading text box on screen
Post by: rrc1962 on April 11, 2017, 07:20:39 PM
That was it.  The textbox now has a "Value" property.  As far as I can tell, the license is still good.  How can you tell if you're in demo mode?  I'm not running a machine, just developing.
Title: Re: Reading text box on screen
Post by: rrc1962 on April 11, 2017, 07:40:21 PM
Licence is still good.  Another install I have that is not licenced says Demo at the top.  Also says Unlicenced on the about screen.
Title: Re: Reading text box on screen
Post by: gorf23 on April 11, 2017, 07:56:21 PM
contact support and ask for a new license