Hello Guest it is March 28, 2024, 11:41:34 AM

Author Topic: Reading text box on screen  (Read 4776 times)

0 Members and 1 Guest are viewing this topic.

Reading text box on screen
« 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
« Last Edit: April 10, 2017, 04:58:23 PM by rrc1962 »
Re: Reading text box on screen
« Reply #1 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.
« Last Edit: April 10, 2017, 05:35:05 PM by rrc1962 »
Re: Reading text box on screen
« Reply #2 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.

Offline gorf23

*
  •  183 183
    • View Profile
Re: Reading text box on screen
« Reply #3 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
 
Re: Reading text box on screen
« Reply #4 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.
« Last Edit: April 10, 2017, 11:32:43 PM by rrc1962 »

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Reading text box on screen
« Reply #5 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")
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Reading text box on screen
« Reply #6 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.

Offline gorf23

*
  •  183 183
    • View Profile
Re: Reading text box on screen
« Reply #7 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

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Reading text box on screen
« Reply #8 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.
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Reading text box on screen
« Reply #9 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