Hi again Forum people. Quick question
I have a picker wheel with two columns that have specific values and I want to then pass the specific index number for the chosen item in the list rather than its value?
My issue is that I am parsing an HTML URL and it needs the two variables for x and x
blah.blah/graph_export/graphs/graph_x_x.png
The first column on the picker seems to pass the index number rather than its value but the issue is the second column. It seems to pass the value rather than the index number.
Example
Column1 Value Index
Temps 1
Electric Usage 2
Column2 Value Index
1hour 1
2hour 2
3hour 3
So the way its currently working if I wanted to display the ‘Temps’ for the last ‘3hours’ would parse the URL as
blah.blah/graph_export/graphs/graph_1_3hour.png
whereas I want to parse
blah.blah/graph_export/graphs/graph_1_3.png
Thanks in anticipation
Si
Here’s the code
[lua]
local storyboard = require “storyboard”
local scene = storyboard.newScene()
local widget = require “widget”
local url = require(“socket.url”)
function scene:createScene( event )
local loading
local view = self.view
local graph
local newGraphbtn = { x = 0, y = 0, width = 150, height = 40 }
– Position graph under the newGraphBtn
local graphBounds = { x = 0,
y = newGraphbtn.y + newGraphbtn.height,
width = display.viewableContentWidth,
height = display.viewableContentHeight -
newGraphbtn.height - widget.theme.segmentedControl.height }
– Show something whilst network traffic is happening.
local loading = display.newGroup()
local r = display.newRect(graphBounds.x, graphBounds.y, graphBounds.width, graphBounds.height)
r:setFillColor(128,128,128)
loading:insert®
local spinner = widget.newSpinner{left = display.contentCenterX - widget.theme.spinner.width/2,
top = display.contentCenterY - widget.theme.spinner.height/2
}
loading:insert(spinner)
loading.isVisible = false
view:insert(loading)
local function graphload(datastream, pickerGroup)
loading.isVisible = true
spinner:start()
local file = system.pathForFile( “CactiChart.png”, system.TemporaryDirectory )
os.remove( file )
local datastreamNumber = datastream[1].index
local httpaddress= “x.x.x.x/cacti/graph_”…datastreamNumber…"_"…datastream[2].index…".png"
display.loadRemoteImage( httpaddress, “GET”,
function(event)
spinner:stop()
loading.isVisible = false
if event.isError == false then
pickerGroup.isVisible = false
graph = event.target
view:insert(graph)
end
end,
“CactiChart.png”, system.TemporaryDirectory,
graphBounds.x, graphBounds.y )
end
local function pickerWheelPopup()
local grp = display.newGroup()
local columnData = {
{
align = “left”,
startIndex = 1,
width=180,
labels =
{
“Memory Usage”, “Load Average”, “Logged In Users”,
“Processes”, “Ping1”, “Ping2”, “Ping3”, “LOS”,
“CRC”, “ES”, “FEC”, “Line Attenuation”,
“DSL Speed”, “LOF”, “SES”, “DSL SNR”,
“”, “”, “”, “”, “”, “”, “Electricity Usage”, “1Wire”, “Traffic”,
“”, “”, “”, “Temp”
},
},
{
align = “left”,
startIndex = 5,
width=display.contentWidth-180,
labels =
{
“Daily”, “Weekly”, “Monthly”, “Yearly”, “4hrs”
},
},
}
myPicker = widget.newPickerWheel
{
left = 0, top = 0,
font = native.systemFontBold,
fontSize = 17,
columns = columnData
}
grp:insert(myPicker)
local btnWidth = 100
selectButton = widget.newButton
{
left = display.contentCenterX-btnWidth/2, top = myPicker.height,
width= btnWidth, height=40,
font=“Arial”, fontSize=18,
label=“Select”, labelAlign=“center”,
labelColor = { default = {0,0,0}, over = {255,255,255} },
onPress = function()
grp.isVisible = false
graphload(myPicker:getValues(), grp)
end
}
grp:insert(selectButton)
grp.isVisible = false – we initialize hidden.
return grp
end
– Build the UI
local pickerGroup = pickerWheelPopup()
view:insert(widget.newButton
{
left = newGraphbtn.x, top= newGraphbtn.y,
width= newGraphbtn.width, height=newGraphbtn.height,
font=“Arial”, fontSize=18,
label=“New Graph”, labelAlign=“center”,
labelColor = { default = {0,0,0}, over = {255,255,255} },
onEvent = function()
– If there was a graph being displayed remove it.
if graph then
view:remove(graph)
graph = nil
end
pickerGroup.isVisible = true
end
}
)
view:insert(pickerGroup)
end
scene:addEventListener( “createScene”, scene )
return scene
[/lua]