Select Folder in the Second Sketch??

I am looking for pop up a window from my sketch like this,


So when people click the select , the window to choose folder will pop up. So usually we call the selectFolder() to pop up this window. However, the SelectFolder did not work in this very case and I do not understand how it happened. To simplify my question, I simplify the code as follows.

void setup()
{
  new Pwindow();
}
void draw(){}
class Pwindow extends PApplet{
  Pwindow()
  {
   super();
    PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);

  }
void setup()
{
  print("a");
  selectFolder("fasdf","operation");
  
}
void draw(){;}
public void operation(File fa){
println("dfsa");
}
}

This is the message given by the terminal
aobjc[54817]: Class FIFinderSyncExtensionHost is implemented in both /System/Library/PrivateFrameworks/FinderKit.framework/Versions/A/FinderKit (0x7fffa610c1d0) and /System/Library/PrivateFrameworks/FileProvider.framework/OverrideBundles/FinderSyncCollaborationFileProviderOverride.bundle/Contents/MacOS/FinderSyncCollaborationFileProviderOverride (0x12a00bdc8). One of the two will be used. Which one is undefined.
operation() must be public

I dive into the raw code of the processing, seriously still got no clue for it…
It would be great if you can help me with it. maybe not debugging this code, giving another solution would be also great. Thanks for your time~
@quark need your expertise! appreciate it if you can help me with it

Emmmm I find a one to do it.
I put the function selectFolder function in the main sketch and made two global boolean variables to control it.
So it’s a functional implementation…

import controlP5.*;
RecordFileSelection file_Behavior_Window;
ControlP5 cp5;
import java.lang.reflect.Method; 

String play_back_folder_path;
void setup()
{
initialize_playback_mode();

}
static class BehavioralConfig{
static boolean behavioral_training_select_folder = false; 
static boolean behavioral_training_folder_selected = false; 
static String  behaviroal_para_folder_path = "";
}

void open_folder_window(){
if (BehavioralConfig.behavioral_training_select_folder&(!BehavioralConfig.behavioral_training_folder_selected)){
  selectFolder("the User choose","set_text_field");
  BehavioralConfig.behavioral_training_select_folder = false; 

}
}

void set_text_field(File selection){
  
  if (selection == null) {
    println("Window was closed or the user hit cancel.");
  } else {
    println("User selected " + selection.getAbsolutePath());
    file_Behavior_Window.textField_playback.setText(selection.getAbsolutePath());
    BehavioralConfig.behavioral_training_folder_selected = true;
  }
  
}


void draw()
{
open_folder_window();


}
  
void initialize_playback_mode(){
    

  file_Behavior_Window = new RecordFileSelection();
}


  
class RecordFileSelection extends PApplet {
 public Textfield textField_playback;
  RecordFileSelection() {
    super();
    PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
  }

  void settings() {
  size(795,40);

  }
void setup()
{
  cp5 = new ControlP5(this); 

  cp5.addButton("choose")
  .setPosition(795-238,303-280)
  .setSize(100,20).setId(1);
  cp5.addButton("select")
  .setPosition(913-238,303-280)
  .setSize(100,20).setId(2);
  textField_playback = cp5.addTextfield("")
     .setPosition(32,13)
     .setSize(485,20)
     .setFont(createFont("arial",20))
     .setText(sketchPath())
     .setAutoClear(false).setId(3);
}
void draw() {
  background(color(#C4C4C4));
}


  

  
 void exit()
  {
    dispose();
     file_Behavior_Window = null;
  }
  



void controlEvent(ControlEvent theEvent) {
  println("got a control event from controller with id "+theEvent.getController().getId());
  switch(theEvent.getController().getId()) {
    case(1):
    BehavioralConfig.behavioral_training_select_folder = true;
    break;
    case(2):
    play_back_folder_path = file_Behavior_Window.textField_playback.getText();
    exit();
    break; 
    default:
    break;
  }
}
 
  
  


}

1 Like