0

before-session-write event

Hi,

I'm caching the event before-session-write in order to check some stuff. One of the things I'm checking is if the file has already been saved. I'm doing this checking if the name returned by commands.sessionFileName() is a file or not (os.path.isfile(fileName)), is there a better way to do this?

The main problem I'm having is related to the default name that rv uses to save the session if it hasn't already been saved. If you open an image called image1.jpg and click on Save the session is saved as image1.rv without giving you the chance to choose a proper name.

To change that behaviour what I would like to do is:

- Catch the before-session-write event

- Choose a proper name for the file

- Continue the execution of the save event

Right now I'm able to do the two first steps but I'm stuck in the last one? Does exist any command to choose the name for the session that is going to be saved? I would like to use that command in the function called by the before-session-write event.

Thanks!

Manu.

8 comments

  • 0
    Avatar
    Jon Morley

    Hi Manu,

    I think what you want to do is catch the before-session-write event, and the run commands.setSessionName. Finally make sure to do event.reject() to allow the save to continue processing.

    Please let me know if that does the trick.

    Thanks,
    Jon

  • 0
    Avatar
    Manuel

    Hi Jon,

    I think this is not working. The content of the function I have is:

    (I use a try/except because if the user press the "Cancel" button in the saveDialog an exception is thrown, any idea of the reason?)

    try:
         fileName = commands.saveFileDialog(False, "", None, False)
    except Exception as e:
         if fileName:
              print e
         else:
              print 'Save action cancelled by the user.'
    else:
         commands.setSessionName(fileName)
         event.reject()

     

    After that saves the session with the same name that the image has but with the extension "rv". Any idea why is this happening?

    Thanks!

    Manu.

  • 0
    Avatar
    Manuel

    Hi,

    If I check the name of the session with "commands.sessionFileName" before and after executing "commands.setSessionName"
    the result is the same so it seems "commands.setSessionName" is not working right in my case.

    Manu.

  • 0
    Avatar
    Jon Morley

    Hi Manu,

    I was mistaken. The thing value that is used to define the name of the save file is the fileName of the session. Which cannot be set from a package (Mu or Python). I think the method you will want to call is commands.saveSession(). But I think we stopped the behavior you are describing several releases ago. If you save a session for the first time now it should not be named after the source, but should launch a dialog to get you to put in a file name. Can you please tell me which version of RV you are using?

    Thanks,
    Jon

  • 0
    Avatar
    Manuel

    Hi Jon,

    This is happening with rv3.12.20. I have tested with version rv4.0.8 and works fine.

    The problem using command.saveSession inside the before-session-write is that it triggers again the before-session-write event. To avoid this behaviour I have tried to use a flag to control the flow inside the event. So what I'm doing is to show the save dialog, choose a proper name and click the "Save" button.

    At this point what is happening is that I have to different files saved, one with the name I have written and another one with the wrong name (imageName.rv) BUT the one that remains opened as the current session is the one with wrong one.

    Any idea?

    At least it seems this is fixed in rv4.

    Thanks,

    Manu.

  • 0
    Avatar
    Jon Morley

    Hi Manu,

    I think that there is no good way to do what you are looking for with RV-3. As I mentioned there is no scripting level support for setting the file name of the session which is what is used for naming the output session file, except by using commands.saveSession which is problematic for all of the reasons you listed. As a result I would highly recommend updating to RV-4. In addition to fixing this issue there are many other improvements it has over RV-3. Are there any outstanding issues with RV-4 that have kept you from updating? Please let me know.

    Thanks,
    Jon

  • 0
    Avatar
    Manuel

    Hi Jon,

    I think we'll have to wait until we update to rv4 as you said.

    We are working on a couple of issues that we have with rv4 and as soon as we fix those we'll update to rv4.

    Thanks,

    Manu.

  • 0
    Avatar
    Jon Morley

    Hi Manu,

    Gotcha. Well keep me posted in case there is something else I can do.

    Thanks,
    Jon

Please sign in to leave a comment.