Forum

Author Topic: Some user interaction / dialog box basics  (Read 1870 times)

Mycobiont

  • Newbie
  • *
  • Posts: 21
    • View Profile
Some user interaction / dialog box basics
« on: February 03, 2021, 08:03:33 PM »
Two questions:
1. I have a custom dialog box that runs from a menu item. When the user adjusts values in the dialog and runs a routine, I want their adjusted values to show up as default the next time they pull it up from the menu (within the session is fine - I don't need to save between sessions).  I tried using global variables within the python script: defined at the top of the script and then set to new values as the routine runs.  The original values set at the top of the script do appear within my dialog class, but setting the new values does not allow them to persist into the next run of the dialog.  How is this best handled?

2. My dialog is modeled primarily from the "split in chunks" script, where the dialog does not close until the user clicks on the quit button.  I would like to automatically close the dialog after the routine runs.  Simply calling QtCore.SLOT("reject()") does not seem to do the job.  How should this be done?

Thanks!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: Some user interaction / dialog box basics
« Reply #1 on: February 03, 2021, 09:37:26 PM »
Hello Mycobiont,

I think you can use keep the values in chunk.meta (as dictionary with str keys and values) as a workaround. They could be cleared upon the script close.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Mycobiont

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Some user interaction / dialog box basics
« Reply #2 on: February 04, 2021, 06:49:41 AM »
Thanks Alexey - that did the trick! 
For others who may come across this, note that values need to be stored as strings.

Code: [Select]

### near top of code, I start my default value
Metashape.app.document.chunk.meta['Mycobiont/ReproErr'] = "0.5"

         ### later using it in a routine
         reproErr = float(Metashape.app.document.chunk.meta['Mycobiont/ReproErr'])

         ### then after user may have changed it, store the current value
         Metashape.app.document.chunk.meta['Mycobiont/ReproErr'] = str(reproErr)


SAV

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
Re: Some user interaction / dialog box basics
« Reply #3 on: February 10, 2021, 05:28:18 AM »
That's very useful. Thanks for sharing   :D

Regards,
SAV