Posted by member 12025 on 2006-12-12 00:43:48
See the commented part for docs. It's pretty simple.
Here is a pic of it where the following was done:
--[[
Progress dialog 1.0
by cerbie
It's to show things are going on when tasks that may take meningful time are
being completed, using text, not a graphical bar.
It assumes there is a label, mainlabel, that has logolabel and textlabel
hooked. Rolling is the number of lines.
*** xLabel 4.0.1 and LSLua 0.5 were used to test this ***
init, kill: placeholders, mainly.
label is the label that will house the text.
prefix goes before the sent string on a line.
lines is the table of current lines, in order from oldest to newest.
minimalism is a setting that doesn't really do anything right now. Its purpose
is to create the label on show, and destroy it on hide.
How to use:
0. Save to a progress.lua, put in script module path, require "progres"
1. Create a label named as label, like "progress"
2. Set progress.label to that label's name
3. execute progress.setlines ()
4. execute progress.add ("your text") at will to add a line
5. execute progress.append ("your text") to add to the current line
6. To change labels used, do steps 2 and on.
]]
require "evar"
local exec = lslua.exec;
local _G = _G;
local ins = table.insert;
local rem = table.remove;
local concat = table.concat;
local rep = string.rep;
local len = string.len;
local sub = string.sub;
local evar = evar;
local lslua = lslua;
local num = tonumber;
local tostring = tostring;
module "progress"
label = "progress"; -- designed to be changed from outside the module
prefix = "> "; -- also to be changed from outside
lines = {}; -- same as above
minimalism = false;
up = false;
numlines = 1;
numchars = 1;
init = function ()
end;
kill = function ()
end;
show = function ()
if not up then
init ()
up = true;
end
exec ("!labelShow "..label)
end;
hide = function ()
exec ("!labelhide "..label)
if minimalism then
up = false;
kill ()
end
end;
add = function (s)
s = prefix..tostring (s)
rem (lines, 1)
ins (lines,s)
exec ("!labelsettext "..label.." "..concat (lines,"") )
end;
append = function (s)
lines[numlines] = lines[numlines]..tostring (s)
exec ("!labelsettext "..label.." "..concat (lines,""))
end;
setlines = function ()
local vis = evar[label.."Visible"]
if vis == "true" then
exec ("!labelhide "..label)
end
exec ("!labelresizeby "..label.." 1 1")
exec ("!labelresizeby "..label.." -1 -1")
local maxwidth = num ( evar [label.."CurrentWidth"] )
local maxheight = num ( evar [label.."CurrentHeight"] )
exec ("!labelrefresh "..label.." "..label.."autoheightmode top")
exec ("!labelsettext "..label.." "..prefix) -- starting w/h) (one row)
local sh = num ( evar [label.."CurrentHeight"] )
exec ("!labelsettext "..label.." "..prefix.."W"..prefix.."W") -- delta w/h
dh = evar [label.."CurrentHeight"] - sh
numlines = _G.math.floor ( (maxheight-sh)/dh ) + 1
-- optionally, round: numlines = _G.math.floor ( ( (maxheight-sh)/ dh) +0.5 ) + 1
exec ("!labelrefresh "..label.." "..label.."autoheightmode .none")
exec ("!labelsettext "..label.." ")
exec ("!labelresize "..label.." "..maxwidth.." "..maxheight)
if vis == "true" then
exec ("!labelshow "..label)
end
lines = {}
for i=1,numlines do
ins (lines, " ")
end
end;
Progress dialog 1.0
by cerbie
It's to show things are going on when tasks that may take meningful time are
being completed, using text, not a graphical bar.
It assumes there is a label, mainlabel, that has logolabel and textlabel
hooked. Rolling is the number of lines.
*** xLabel 4.0.1 and LSLua 0.5 were used to test this ***
init, kill: placeholders, mainly.
label is the label that will house the text.
prefix goes before the sent string on a line.
lines is the table of current lines, in order from oldest to newest.
minimalism is a setting that doesn't really do anything right now. Its purpose
is to create the label on show, and destroy it on hide.
How to use:
0. Save to a progress.lua, put in script module path, require "progres"
1. Create a label named as label, like "progress"
2. Set progress.label to that label's name
3. execute progress.setlines ()
4. execute progress.add ("your text") at will to add a line
5. execute progress.append ("your text") to add to the current line
6. To change labels used, do steps 2 and on.
]]
require "evar"
local exec = lslua.exec;
local _G = _G;
local ins = table.insert;
local rem = table.remove;
local concat = table.concat;
local rep = string.rep;
local len = string.len;
local sub = string.sub;
local evar = evar;
local lslua = lslua;
local num = tonumber;
local tostring = tostring;
module "progress"
label = "progress"; -- designed to be changed from outside the module
prefix = "> "; -- also to be changed from outside
lines = {}; -- same as above
minimalism = false;
up = false;
numlines = 1;
numchars = 1;
init = function ()
end;
kill = function ()
end;
show = function ()
if not up then
init ()
up = true;
end
exec ("!labelShow "..label)
end;
hide = function ()
exec ("!labelhide "..label)
if minimalism then
up = false;
kill ()
end
end;
add = function (s)
s = prefix..tostring (s)
rem (lines, 1)
ins (lines,s)
exec ("!labelsettext "..label.." "..concat (lines,"") )
end;
append = function (s)
lines[numlines] = lines[numlines]..tostring (s)
exec ("!labelsettext "..label.." "..concat (lines,""))
end;
setlines = function ()
local vis = evar[label.."Visible"]
if vis == "true" then
exec ("!labelhide "..label)
end
exec ("!labelresizeby "..label.." 1 1")
exec ("!labelresizeby "..label.." -1 -1")
local maxwidth = num ( evar [label.."CurrentWidth"] )
local maxheight = num ( evar [label.."CurrentHeight"] )
exec ("!labelrefresh "..label.." "..label.."autoheightmode top")
exec ("!labelsettext "..label.." "..prefix) -- starting w/h) (one row)
local sh = num ( evar [label.."CurrentHeight"] )
exec ("!labelsettext "..label.." "..prefix.."W"..prefix.."W") -- delta w/h
dh = evar [label.."CurrentHeight"] - sh
numlines = _G.math.floor ( (maxheight-sh)/dh ) + 1
-- optionally, round: numlines = _G.math.floor ( ( (maxheight-sh)/ dh) +0.5 ) + 1
exec ("!labelrefresh "..label.." "..label.."autoheightmode .none")
exec ("!labelsettext "..label.." ")
exec ("!labelresize "..label.." "..maxwidth.." "..maxheight)
if vis == "true" then
exec ("!labelshow "..label)
end
lines = {}
for i=1,numlines do
ins (lines, " ")
end
end;
Here is a pic of it where the following was done:
progresswidth 500
progressheight 115
progressFontAlign left
progressFontVertAlign bottom
progressheight 115
progressFontAlign left
progressFontVertAlign bottom
!labelcreate progress
!luaexec progress.add (string.rep (os.date(),2))
!luaexec progress.add (string.rep (os.date(),2))
!luaexec progress.add (string.rep (os.date(),2))
!luaexec progress.add (string.rep (os.date(),2))
!luaexec progress.add (string.rep (os.date(),2))
!luaexec progress.add (string.rep (os.date(),2))
!luaexec progress.add (string.rep (os.date(),2))
!luaexec progress.add (string.rep (os.date(),2))
!luaexec progress.add (string.rep (os.date(),2))
!luaexec progress.add (string.rep (os.date(),2))
!luaexec progress.add (string.rep (os.date(),2))
!luaexec progress.add (string.rep (os.date(),2))