problem changing text wxStaticText
problem changing text wxStaticText
i have a panel created with wxStaticText that shows the text,
also a input textbox, a couple radio buttons and a couple toggle buttons,
everything is working good.
The thing i am trying to do is when i hit a toggle button i can change the
text in the panel to a new text phase, i want to write over the old text
I can get the new text to show in the panel. but i can't figure out how
to get it to the proper position in the panel, to over write the old text...
Hopefully this makes sense,
Any suggestions?
thanks gary
also a input textbox, a couple radio buttons and a couple toggle buttons,
everything is working good.
The thing i am trying to do is when i hit a toggle button i can change the
text in the panel to a new text phase, i want to write over the old text
I can get the new text to show in the panel. but i can't figure out how
to get it to the proper position in the panel, to over write the old text...
Hopefully this makes sense,
Any suggestions?
thanks gary
Re: problem changing text wxStaticText
When creating the wxStaticText, store its pointer in a member variable, e.g. wxStaticText *m_statictext;
Then, in the button event handler you can change it like this:
Then, in the button event handler you can change it like this:
Code: Select all
m_statictext->SetLabel( "new value" );
m_statictext->Refresh(); // this may not be necessary
Use the source, Luke!
Re: problem changing text wxStaticText
you might need to add the wxST_NO_AUTORESIZE flag to your static text.
By default, the control will adjust its size to exactly fit to the size of the text when SetLabel is called. If this style flag is given, the control will not change its size (this style is especially useful with controls which also have wxALIGN_RIGHT or CENTER style because otherwise they won't make sense any longer after a call to SetLabel).
Re: problem changing text wxStaticText
Thanks for the help i had that working where it changes what was in the text box...
I don't think i explained it clear enough my bad...
local staticText = wx.wxStaticText( panel, wx.wxID_ANY, name_string)
in front of the text box is a string in the panel name_string = "whatever"
then after the name_string is the textbox i am trying to change the name_string.
I tested the code SetLabel but that changed text in the textbox and not the name_string text..
Hopefully this is a little clearer
Thanks gary
I don't think i explained it clear enough my bad...
local staticText = wx.wxStaticText( panel, wx.wxID_ANY, name_string)
in front of the text box is a string in the panel name_string = "whatever"
then after the name_string is the textbox i am trying to change the name_string.
I tested the code SetLabel but that changed text in the textbox and not the name_string text..
Hopefully this is a little clearer
Thanks gary
Re: problem changing text wxStaticText
No, not reallyHopefully this is a little clearer
Can you show your code?
Use the source, Luke!
Re: problem changing text wxStaticText
i attached the code
Thanks gary
Thanks gary
- Attachments
-
- my.txt
- (6.73 KiB) Downloaded 360 times
Re: problem changing text wxStaticText
I really know Lua, but i guess i understood it well enough.
In m_XpartLength you store a pointer to the TextCtrl, so when you call SetValue() it will just change the content of the text field.
You also need a variable to store a pointer to the wxStaticText and then use that variable to change the label.
Here are the three functions i changed. I introduced a new variable mXpartLabel. I don't know if this code is syntactically correct, but you should get the idea.
In m_XpartLength you store a pointer to the TextCtrl, so when you call SetValue() it will just change the content of the text field.
You also need a variable to store a pointer to the wxStaticText and then use that variable to change the label.
Here are the three functions i changed. I introduced a new variable mXpartLabel. I don't know if this code is syntactically correct, but you should get the idea.
Code: Select all
function Setupinputs()
--Add all the inputs
local val
m_XpartLength, mXpartLabel = AddInputControl("Enter Distanct to travel",nil)
m_XpartLength:SetValue( mc.mcProfileGetString(0 , tostring(m_iniName), "X partLengh", "0.000") )
end
function AddInputControl(name_string, width)
if(width == nil)then
width = 100
end
local textCtrlID = GetNextID()
local staticText = wx.wxStaticText( panel, wx.wxID_ANY, name_string)
local textCtrl = wx.wxTextCtrl( panel, textCtrlID, "0.000", wx.wxDefaultPosition, wx.wxSize(width, -1), wx.wxTE_PROCESS_ENTER ,wx.wxTextValidator(wx.wxFILTER_NUMERIC))
InputsGridSizer:Add( staticText, 0, wx.wxALIGN_CENTER_VERTICAL+wx.wxALL+wx.wxALIGN_RIGHT, 2)
InputsGridSizer:Add( textCtrl, 0, wx.wxGROW+wx.wxALIGN_CENTER+wx.wxALL+wx.wxALIGN_LEFT, 2)
return textCtrl, staticText, textCtrlID
end
function Getunitsper()
local inst = mc.mcGetInstance(); --Captures current instance of Mach 4
local CountsPerUnit = 0;
--m_XpartLength = NewText("Enter Distanct Travled",nil)
mXpartLabel:SetValue( mc.mcProfileGetString(0 , tostring(m_iniName), "DisTravled", "2.000") )
CountsPerUnit, rc = mc.mcProfileGetDouble(inst,"Motor0", "CountsPerUnit", 2000.0);
--rc = mc.mcProfileWriteDouble(inst,"Motor0", "CountsPerUnit", 2000.0);--12700.0
wx.wxMessageBox("Get the units per",
"About wxLua "..CountsPerUnit,
wx.wxOK + wx.wxICON_INFORMATION,
mainframe)
end
Use the source, Luke!
Re: problem changing text wxStaticText
when i add this it doesn't change the text and one other strange thing, the messagebox just after this code doesn't display any message but the program doesn't crash just no messagebox
if i change mXpartLabel: to m_Xpartlength it changes the textbox and the messagebox pops up also
but thats not what i want to change its the m_XpartLength, mXpartLabel = AddInputControl("Enter Distance to travel",nil)
I want to change the text "Enter Distance to travel" to a new - text like "Enter Distance to traveled"
then you can enter a keyboard input into the input textbox i don't seem to be having a problem with the input box just changing the phrase's
I can put the new text on the panel but its always in the top left corner doesn't overwrite the old text ...
Thanks gary
if i change mXpartLabel: to m_Xpartlength it changes the textbox and the messagebox pops up also
but thats not what i want to change its the m_XpartLength, mXpartLabel = AddInputControl("Enter Distance to travel",nil)
I want to change the text "Enter Distance to travel" to a new - text like "Enter Distance to traveled"
then you can enter a keyboard input into the input textbox i don't seem to be having a problem with the input box just changing the phrase's
I can put the new text on the panel but its always in the top left corner doesn't overwrite the old text ...
Code: Select all
mXpartLabel:SetValue( mc.mcProfileGetString(0 , tostring(m_iniName), "DisTravled", "2.000") )
Re: problem changing text wxStaticText
Thanks for your help i got it working just used
m_XpartLabel:SetLabel("Hello button clicked"); --this worked
it changed the text in the correct position..
Gary
m_XpartLabel:SetLabel("Hello button clicked"); --this worked
it changed the text in the correct position..
Gary
Code: Select all
function Setupinputs()
--Add all the inputs
local val
m_XpartLength, mXpartLabel = AddInputControl("Enter Distanct to travel",nil)
m_XpartLength:SetValue( mc.mcProfileGetString(0 , tostring(m_iniName), "X partLengh", "0.000") )
end
function AddInputControl(name_string, width)
if(width == nil)then
width = 100
end
local textCtrlID = GetNextID()
local staticText = wx.wxStaticText( panel, wx.wxID_ANY, name_string)
local textCtrl = wx.wxTextCtrl( panel, textCtrlID, "0.000", wx.wxDefaultPosition, wx.wxSize(width, -1), wx.wxTE_PROCESS_ENTER ,wx.wxTextValidator(wx.wxFILTER_NUMERIC))
InputsGridSizer:Add( staticText, 0, wx.wxALIGN_CENTER_VERTICAL+wx.wxALL+wx.wxALIGN_RIGHT, 2)
InputsGridSizer:Add( textCtrl, 0, wx.wxGROW+wx.wxALIGN_CENTER+wx.wxALL+wx.wxALIGN_LEFT, 2)
return textCtrl, staticText, textCtrlID
end
--wx.wxGetApp():MainLoop()
function Getunitsper()
local inst = mc.mcGetInstance(); --Captures current instance of Mach 4
local CountsPerUnit = 0;
--m_XpartLength = NewText("Enter Distanct Travled",nil)
-- m_XpartLabel:SetValue( mc.mcProfileGetString(0 , tostring(m_iniName), "DisTravled", "2.000") )
m_XpartLabel:SetLabel("Hello button clicked"); --this worked
-- CountsPerUnit, rc = mc.mcProfileGetDouble(inst,"Motor0", "CountsPerUnit", 2000.0);
--rc = mc.mcProfileWriteDouble(inst,"Motor0", "CountsPerUnit", 2000.0);--12700.0
wx.wxMessageBox("Get the units per",
"About wxLua "..CountsPerUnit,
wx.wxOK + wx.wxICON_INFORMATION,
mainframe)
end