Barra di avanzamento ha mostrato come creare una barra di avanzamento. @abmayfield domanda dentro "non risponde" vs. "pensa ancora" mi ha spinto a rivedere questo. Ecco un'altra ripresa, incluso un pulsante Annulla.
not cancelednot cancelednot cancelednot cancelednon annullato
Cancel button pressed.Cancel button pressed.Cancel button pressed.Cancel button pressed.Pulsante Annulla premuto.
progressBarWidth = 500;
progressUpdatesSeconds = 1 / 4; // 1/2 sec updates -> 1300ips, 1/30 -> 1000ips (1/4 compromise speed vs appearance)
cancel = 0; // clear the cancel flag
New Window( "Progressbar demo", //
V List Box( //
cats = Text Box( "" ), // output from the work function
t = Text Box( "", <<SETWRAP> ^workCalls/runSeconds^ ips" ) );
t << updatewindow; // this works without the wait
);
totalCats = 0;
dowork = Function( {},
x = "";
For( i = 1, i <= 1000, i += 1, x = x || "." );
totalCats += 1000;
cats << settext( Eval Insert( "total concatenations=^totalCats^" ) );
);
While( runSeconds < limitSeconds & !cancel, // change this to represent the work you are doing
// do some work, simulated by concatenating strings...
dowork();
// update the progressbar
workCalls += 1;
nowMicroSeconds = HP Time();
// how often does it need to update on the screen?
If( (nowMicroSeconds - recentUpdateMicroSeconds) / 1e6 > progressUpdatesSeconds,
// in this example I'm using a fixed time duration of "limitSeconds" to represent the
// amount of work to be done. And "runSeconds" to represent the amount of work done so far.
// Usually you'll have something other than time: number of rows in a table perhaps, or
// number of categories to make reports for. As long as you know how many total and how
// many completed, you can compute this fraction...
updateProgress( runSeconds / limitSeconds ); // change this to represent the fraction of work finished
recentUpdateMicroSeconds = nowMicroSeconds;
Wait( 0 ); // this wait is needed to let the cancel button work
);
runSeconds = (nowMicroSeconds - startMicroSeconds) / 1e6;
);
If( cancel, // test the cancel flag
Beep(); // audio flag
left << color( "dark red" ); // visual flag something is awry
right << color( "red" );
, //
updateProgress( 1.0 ); // people like to see the bar go to 100%
);
cancelButton << setbuttonname( "Close" ); // visual flag the button function is changed
cancelButton << setscript( (cancelButton << closewindow) ); // and what to do if the button is pressed
</SETWRAP>
Testando tra JMP 15 e 16, ho notato che 16 è a quantità più veloce su questo carico di lavoro di concatenazione di stringhe! Bel lavoro!
Modifica: se JMP esegue una piattaforma che non dispone di una propria barra di avanzamento annullabile e funziona da molto tempo, questo non sarà di aiuto. Il supporto tecnico sarebbe un buon posto per richiedere il supporto della piattaforma per una barra di avanzamento. Senza di esso, non c'è modo (a parte la chiusura forzata di JMP) per fermarlo finché non è terminato.
Vuole essere confezionato, grazie!
Nel tuo esempio, pb<
Hai anche sottolineato qualcosa che mi è sfuggito Come utilizzare Definisci classe : pensavo di aver bisogno di disporre esplicitamente i membri della classe nel prototipo di classe define, ma Questo: può crearli anche tu.
Define Class("bubble",
//not needed: m_xpos = .;
_init_ = Method( {x}, <BR />//because using explicit this: ...
this:m_xpos = x;
Grazie @Craige_Hales ! Mi è capitato di aver bisogno di una barra di avanzamento (o qualcosa di simile) per uno dei miei script, quindi l'ho preso e l'ho modificato un po' per adattarlo alle mie esigenze. L'ho trasformato in una classe (sono molto principiante con le classi e le classi di JMP in generale) per pratica e perché mi sentivo come se potesse inserirsi in uno. Ho anche aggiunto della documentazione che può essere analizzata con Natural Docs.
Codice:
Visualizza altro...I documenti naturali avranno un aspetto simile a questo:
