gvSIG feature requests #2715

Add progress bar for long running script

Added by Antonio Falciano almost 10 years ago. Updated almost 10 years ago.

Status:Invalid% Done:

0%

Priority:NormalSpent time:-
Assignee:-
Category:Scripting
Target version:-
gvSIG version:2.1.0 Add-on resolve version:
Keywords:locale, progressbar, script Add-on resolve build:
Has patch: Proyecto:
Add-on name:Scripting framework (org.gvsig.scripting.app.extension) Hito:
Add-on version:

Description

Some days ago, tired to play with preferences during some tests, I've written a simple Jython script in order to switch the gvSIG Locale (in attachment). Because it's a quite long running one, it seems it does nothing during its execution. So adding an indefinite progress bar for script could be a good idea in order to show that it's working.

switchLocale.zip - An example of long running script (680 Bytes) Antonio Falciano, 07/24/2014 06:13 AM

History

#1 Updated by Antonio Falciano almost 10 years ago

I forgot to mention where, sorry... At least in the status bar (it should be very useful when the script is launched form the Scripting launcher), optionally in the Scripting composer.

#2 Updated by Joaquín del Cerro Murciano almost 10 years ago

Hola Antonio,
todos los scripts tienen asociada un "taskStatus" que es usado para
mostrar informacion en la barra de progreso de la barra de estado de gvSIG. Es responsabilidad del que realiza el script activarlo o no.

Tu script podria quedar como:

#from gvsig import *
from commonsdialog import *
from org.gvsig.andami import PluginsLocator
from java.util import Locale

def main(*args):

    # Add the progress-bar to the status-bar of gvSIG
    taskStatus.add()
    try:
      localeManager = PluginsLocator.getLocaleManager()
      currentLocale = localeManager.getCurrentLocale()

      if currentLocale == Locale("it"):
          localeManager.setCurrentLocale(Locale("en"))
      else:
          localeManager.setCurrentLocale(Locale("it"))

      currentLocale = localeManager.getCurrentLocale()
      #print "currentLocale: " + str(currentLocale)
    finally:
      # Set to terminate flag of the task
      taskStatus.terminate()
      # Remove from the status-bar of gvSIG
      taskStatus.remove()      

    msgbox("currentLocale: " + str(currentLocale), "Current locale", IDEA)

Esto hace que se muestre la barra de progreso "indefinida". Si tuviesemos control sobre las iteraciones del proceso podriamos usar:

taskStatus.setRangeOfValues(0,count);

Para indicarle el rango en el que nos moveremos y

taskStatus.setCurValue(counter)

Para ir actualizando el estado.

Tengo escrito un pequeñito articulo que esta pendiente de publicar en el blog que lo usaba... voy a darle a publicar antes de que se me vuelva a olvidar y asi tienes alli un ejemplo.

Tambien hay un problema con la inicializacion del motor de scripting. El primer script que se ejecuta lo inicializa y tarda un rato, que suele desesperar al usuario. Cuando tenga un rato, intentare inicializarlo al cargarse la extension de scripting.

Perdon por el castellano... si he de contestar en ingles acabo dejandolo para mas tarde y a veces se me olvida.

saludos
Joaquin

#3 Updated by Antonio Falciano almost 10 years ago

  • Status changed from New to Invalid

Hi Joaquin,
don't worry for your castellano, fortunately I understand it quite well. Many thanks for you kind suggestions, it works like a charm now! :)
In reference to the initial delay, loading the scripting engine during (or after) the post-initialization of extensions could be a solution.
I set the ticket status on Invalid, because it's a feature already available (even if not documented yet).

Cheers,
Antonio

Also available in: Atom PDF