that’s of course the right approach when you have files on your hard drive
but onedrive is different I guess - it’s probably a kind of API where you need to figure out whether there is a way to get a file list and then browse the file list.
Thank you everyone. Lets focus on loading the local file first.
I have a hard time making loadTable accept the file name I select.
I browsed the whole internet, no examples… Please help
Here is what I got.
String Mach_Name []= {"00", "31", "200", "700", "POD1", "POD2", "BHX1", "BHX2", "EDG1", "EDG2", "10", "M_11"};// 11 vals
int [] Cycles = new int [100];
float [] Pr = new float [100]; // percentage of Uptime
Table table;
int incr=1;
File filename;
void setup() {
size(1900, 1000, JAVA2D);
selectInput("Select a file to process:", "fileSelected", filename);
//table = loadTable("https://onedrive.live.com/Edit.aspx?resid=B15E9906640B6318!83888&wd=cpe&authkey=!AK6-OP68Ew_FfGE", "csv");
}
void fileSelected(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
} else {
println("User selected " + selection.getAbsolutePath());
println ("Filename: "+ filename);
}
/*
table = loadTable(filename, "header");
println(("Row COunt is " + table.getRowCount()));
for (TableRow row : table.rows())
{
Mach_Name [incr] = row.getString("MACH ID");
Pr[incr] = row.getInt("UPTIME %");
Cycles [incr] = row.getInt("CYCLES TODAY");
incr++;
// println(name + " (" + species + ") has an ID of " + id);
}
for (int i=1; i<=10; i++)
{
println (i + " Mach_Name; "+Mach_Name[i]+ " %="+ Pr[i] );
}
*/
}
void mouseClicked()
{
selectInput("Window_name", "fileSelected");
println(filename);
}
Also,
The selectInput( function works only in setup?
I tried it under mouseClicked and nothing executes.
Thats a burmmer. The user should be able to load various files without restarting the sketch.
// Demo for selectInput
//states
final int stateWaitForFile = 0; // consts
final int stateDone = 1;
final int stateBreak = 2;
final int stateWaitForButton = 3;
int state = stateWaitForButton; // current
String fileGlobal = "";
Table tableTest ;
// ----------------------------------------------------------------------------------------
void setup() {
size (1100, 700);
background(111);
}
void draw() {
//
// switch
switch (state) {
case stateWaitForFile:
// waiting until file has been selected
background(111);
text("Please choose a file. Hit Cancel to abort.",
33, 33);
// THE WAIT IS OVER
if (!fileGlobal.equals("")) {
state = stateDone;
// here you would load the table
tableTest = loadTable(fileGlobal);
//
} // if
break;
case stateDone:
// here you would have the table and display it
background(111);
text("File is there now: "
+fileGlobal, 100, 100);
showButtons();
text(tableTest.getColumnCount(), 30, height-177); //
break;
case stateWaitForButton:
background(111);
text("Please selecr a button.", 100, 100);
showButtons();
break;
case stateBreak:
background(111);
text("Window was closed or the user hit cancel.", 33, 33);
showButtons();
break;
default:
// error
println ("error 91");
exit();
break;
//
} // switch
//debug
fill(255);
text(state, 30, height-30);
} // func
// -----------------------------------------------------------------
// file handling
void fileSelected(File selection) {
//
// the 'callback' function.
//
if (selection == null) {
println("Window was closed or the user hit cancel.");
state = stateBreak;
} else {
println("User selected " + selection.getAbsolutePath());
fileGlobal = selection.getAbsolutePath();
} // else
}//func
// ----------------------------------------------------------------
// Input
void mousePressed() {
// check Buttons
if (state==stateDone||state==stateBreak||state==stateWaitForButton) {
if (dist(mouseX, mouseY, 133, 133) < 66) {
// reset / restart
fileGlobal="";
selectInput("Select a file (Cancel to abort):",
"fileSelected");
state=stateWaitForFile;
}//if
else if (dist(mouseX, mouseY, 233, 133) < 66) {
exit();
}//else if
} //if
//
} //func
//-------------------------------------------------------------------
//Tools
void showButtons() {
// set mode for text and rect
textAlign(CENTER, CENTER);
rectMode(CENTER);
// rects
noFill();
rect(133-5, 133+3, 84, 23);
rect(233-1, 133+3, 84, 23);
// text
fill(255);
text ( "Choose file", 133, 133);
text ( "Quit", 233, 133);
// reset
textAlign(LEFT);
rectMode(CORNER); // The default mode is rectMode(CORNER)
}//func
//