Example Lua code to show a progress bar?

818 views
Skip to first unread message

ToddA

unread,
May 2, 2012, 11:00:12 PM5/2/12
to noteca...@googlegroups.com
Hi All,

Can anyone point me to an existing NCP script, or maybe provide a snippet of code, that shows how to display a progress bar while importing a file? I've got some large files and would like to know NCP is actually reading records OK and not just "stuck."

When I want to do this in other languages, I usually have to resort to one of two methods:

1) Use two passes. The first pass simply counts the =lines=, and the second pass does the importing showing a percentage complete calculation of linesReadSoFar/totalLines. Not very efficient but it works.

2) Get the file size in bytes from the OS, then when importing accumulate the total number of =bytes= per line. The percentage complete calculation is bytesReadSoFar/totalBytes.

The progress indicator doesn't have to show an actual percentage number. A graphical progress bar would be just fine. Whatever is easiest.

Thanks in advance,
Todd

marbux

unread,
May 3, 2012, 1:14:21 AM5/3/12
to noteca...@googlegroups.com
Hi, Todd,

I haven't used the relevant APIs myself, but I think the ones you should be aware of are documented in the Help file at:

Automation, Scripts and Plugins > Scripting NoteCase Pro > Scriptable Program Commands > Document Commands > Nc_Doc_Import (see the bShowProgress parameter). 

Automation, Scripts and Plugins > Scripting NoteCase Pro > Scriptable Program Commands > GUI Commands > Nc_GUI_ProgressDlg_SetPos

Automation, Scripts and Plugins > Scripting NoteCase Pro > Scriptable Program Commands > GUI Commands > Nc_GUI_ProgressDlg_SetText

Automation, Scripts and Plugins > Scripting NoteCase Pro > Scriptable Program Commands > GUI Commands > Nc_GUI_ProgressDlg_Start

From the documentation, the following line should do the trick:

Nc_Doc_Import(nDocID, strFilePath, 1)

... where nDocID is the document ID number of the target document that will receive the imported content. 

But you might get the results if you omitted the last integer parameter

Best regards,

Paul 

Miro

unread,
May 3, 2012, 1:47:28 AM5/3/12
to noteca...@googlegroups.com
Hi Todd,

the script named "42_ImportRtfFileFolder.lua" (comes with NcPro installation) is an example of progress
where you count number of files to be imported and then start the process incrementing progress by 1 for each file (similar to your case #1)

The example of your case #2 can be found here: http://notecasepro.com/lua/ImportIniFile.lua
This script uses current file position (once per each text line) to increment the progress.

Regards,
  Miro


Todd A

unread,
May 3, 2012, 9:53:06 AM5/3/12
to noteca...@googlegroups.com
Thanks, Paul and Miro. I'll take a look into those solutions.




--
You received this message because you are subscribed to the Google Groups "Notecase Pro" group.
To view this discussion on the web visit https://groups.google.com/d/msg/notecase-pro/-/RHhkep21Tw8J.

To post to this group, send email to noteca...@googlegroups.com.
To unsubscribe from this group, send email to notecase-pro...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/notecase-pro?hl=en.

Daniel H

unread,
May 4, 2012, 3:21:13 AM5/4/12
to Notecase Pro
Here is how I use the progress bar APIs in my GTD Plugin
(nGtdNoteCount is the "100%" absolute value, which I calculated before
by counting the relevant items in another loop, just as you suggested
with file size or number of lines; In the below code I deleted
everything not relevant to the progress bar handling):


Nc_GUI_ProgressDlg_Start(Nc_Doc_Title_Get(nDocID) .. ":\nRearranging
tasks in GTD subsystem: " .. i .. " of " .. nGtdNoteCount .. "
", nGtdNoteCount, 1)

for i,v in ipairs(tNoteIDs) do -- loop though all notes by their IDs
now
Nc_GUI_ProgressDlg_SetPos(i)
Nc_GUI_ProgressDlg_SetText(Nc_Doc_Title_Get(nDocID) .. ":
\nRearranging tasks in GTD subsystem: " .. i .. " of " ..
nGtdNoteCount .. "\n" .. Nc_Note_Title_Get(nDocID, strNoteID))

if Nc_GUI_ProgressDlg_IsCanceled() == 1 then
break
end

end

Nc_GUI_ProgressDlg_SetText(Nc_Doc_Title_Get(nDocID) .. ":\nRearranging
tasks in GTD subsystem:\nFinishing...")

-- [ .. some code to clean up ....]

Nc_GUI_ProgressDlg_Close()




Daniel

Reply all
Reply to author
Forward
0 new messages