Python Panel - how to catch application close event.

   6242   4   2
User Avatar
Member
183 posts
Joined: Nov. 2008
Offline
Hi. I need to perform some actions in my Python Panel when houdini is exiting, and i can't catch this event.

1. closeEvent() is not called.
2. __del__() method is not called.
3. QApplication aboutToQuit signal is not emited.

Could you please tell me, how can i catch this event ?



from PySide.QtGui import *
import logging

class My(QFrame):
def __init__(self, logger):
super(My, self).__init__()
self.logger = logger
QApplication.instance().aboutToQuit.connect(self._app_quit)

def __del__(self):
self.logger.debug('In __del__')

def closeEvent(self, event):
self.logger.debug('In closeEvent')
self.close()

def _app_quit(self):
self.logger.debug('aboutToQuit signal')

def createInterface():
h = logging.FileHandler(filename=r'c:\temp\testhoudini_event.log')
logger = logging.getLogger('test')
logger.addHandler(h)
logger.setLevel(logging.DEBUG)

widget = My(logger)
return widget
Aleksei Rusev
Sr. Graphics Tools Engineer @ Nvidia
User Avatar
Member
7750 posts
Joined: July 2005
Offline
I wonder if Python's atexit module works in Houdini.
User Avatar
Member
183 posts
Joined: Nov. 2008
Offline
Hi Edward,
Yes, atexit works if registering a function from python shell or hou.session.
Doing so in python panel didn't work.


from PySide.QtGui import *
import logging
import atexit

class My(QFrame):
def __init__(self, logger):
super(My, self).__init__()
self.logger = logger

@atexit.register
def _exit(self):
self.logger.debug('In _exit')

def createInterface():
h = logging.FileHandler(filename=r'c:\temp\testhoudini_event.log')
logger = logging.getLogger('test')
logger.addHandler(h)
logger.setLevel(logging.DEBUG)

widget = My(logger)
return widget


I'll try to install my custom event to QApplication, but this this a dirty hack…
Aleksei Rusev
Sr. Graphics Tools Engineer @ Nvidia
User Avatar
Staff
1256 posts
Joined: July 2005
Offline
Hello,

Starting in tomorrow's build, the __del__ function will get called when the Python Panel is closed/destroyed.

We are still looking into hooking up __del__ so that it also gets called when the Houdini application exits/quits.

Cheers,
Rob
User Avatar
Member
183 posts
Joined: Nov. 2008
Offline
rvinluan
Hello,

Starting in tomorrow's build, the __del__ function will get called when the Python Panel is closed/destroyed.

We are still looking into hooking up __del__ so that it also gets called when the Houdini application exits/quits.

Cheers,
Rob

Hi Rob,
Currently, hideEvent is working like it should, why not make closeEvent working? __del__ should be good for now, but closeEvent should also work.

Anyway, thanks, at least we'll be able to save data
Aleksei Rusev
Sr. Graphics Tools Engineer @ Nvidia
  • Quick Links