# How to observe save button event

**URL:** <https://discourse.slicer.org/t/how-to-observe-save-button-event/39498>\
**Category:** Development\
**Tags:** python\
**Created:** [October 2, 2024, 5:23pm UTC](https://discourse.slicer.org/t/how-to-observe-save-button-event/39498 "2024-10-02T17:23:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cavers\_Chen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cavers_chen/32/76896_2.png) [@Cavers\_Chen](https://discourse.slicer.org/u/Cavers_Chen)\
**Post date:** [October 2, 2024, 5:23pm UTC](https://discourse.slicer.org/t/how-to-observe-save-button-event/39498/1 "2024-10-02T17:23:50Z")

</div>

Hi!  
I am writing a Python script and encountered a problem recently. I want to save a specific component’s data through MRMLTextnode. However, I need to update and write them into the MRMLTextnode before users open the save dialog.

Is there a way to observe the Save Scene and Unsaved Data button event?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 2, 2024, 5:28pm UTC](https://discourse.slicer.org/t/how-to-observe-save-button-event/39498/2 "2024-10-02T17:28:49Z")

</div>

You can override the default scene save dialog as shown in the [example in the script repository](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#override-default-scene-save-dialog).

---

<div class="post-metadata">

**Author:** ![Cavers\_Chen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cavers_chen/32/76896_2.png) [@Cavers\_Chen](https://discourse.slicer.org/u/Cavers_Chen)\
**Post date:** [October 7, 2024, 4:30pm UTC](https://discourse.slicer.org/t/how-to-observe-save-button-event/39498/3 "2024-10-07T16:30:03Z")

</div>

Hi, I added this module to my code, but it doesn’t seem to work. When I click the save button, there is no output in the console. Should I register it?

```auto
import os

import vtk

import slicer, qt
from slicer.ScriptedLoadableModule import *
from slicer.util import VTKObservationMixin

class MyModuleFileDialog ():
  """This specially named class is detected by the scripted loadable
  module and is the target for optional drag and drop operations.
  See: Base/QTGUI/qSlicerScriptedFileDialog.h.

  This class is used for overriding default scene save dialog
  with simple saving the scene without asking anything.
  """

  def __init__ (self,qSlicerFileDialog ):
    self.qSlicerFileDialog = qSlicerFileDialog
    qSlicerFileDialog.fileType = "NoFile"
    qSlicerFileDialog.description = "Save scene"
    qSlicerFileDialog.action = slicer.qSlicerFileDialog.Write

  def execDialog(self):
    # Implement custom scene save operation here.
    # Return True if saving completed successfully,
    # return False if saving was cancelled.
    print("hello")
    return True
  
  
#
# BCMaker
#
....

```

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 23, 2024, 7:22pm UTC](https://discourse.slicer.org/t/how-to-observe-save-button-event/39498/4 "2024-10-23T19:22:17Z")

</div>

The class must be called `(YourModuleName)FileDialog`, for example in your case something like `BCMakerFileDialog`.
