csp Posted July 10, 2014 Share Posted July 10, 2014 Hi, I have python script using PyQt ui based on SESI's recommended example. As is, I will have unlimited instances when I hit shelf tool. How is possible to keep a single instance open. Either deleting previous instance and opening a fresh one or blocking a new instance if there is already one open. My last question is how to quit script/ui once using a button. Let's say "Open Hip", first command to open a new hip and then quit the tool. cheers, Quote Link to comment Share on other sites More sharing options...
Alexey Vanzhula Posted July 11, 2014 Share Posted July 11, 2014 (edited) import hou from PySide import QtCore as qtc from PySide import QtGui as qtg #---------------------------------------------------------------------------------------- try: app = qtg.QApplication(['houdini']) except: app = qtg.QApplication.instance() event_loop = qtc.QEventLoop() #---------------------------------------------------------------------------------------- def qt_callback(): if not ctl.isVisible(): try: hou.ui.removeEventLoopCallback( qt_callback ) except: pass event_loop.processEvents() app.sendPostedEvents(None, 0) #---------------------------------------------------------------------------------------- ctl = None def show( ctl_ ): global ctl ctl = ctl_ ctl.show() hou.ui.addEventLoopCallback( qt_callback ) #---------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------- button_widget = qtg.QPushButton('Hello World !!!') button_widget.clicked.connect( button_widget.hide ) button_widget.setWindowFlags( qtc.Qt.FramelessWindowHint | qtc.Qt.WindowStaysOnTopHint ) show(button_widget) 1. This simple one-widget solution use one QApplication instance. 2. You can connect clicked button signal to hide widget. Hide widget with no parents leads to finish script Edited July 11, 2014 by Alexey Vanzhula Quote Link to comment Share on other sites More sharing options...
Alexey Vanzhula Posted July 11, 2014 Share Posted July 11, 2014 (edited) And this is example: http://youtu.be/WEW95Yu_Ijs Edited July 11, 2014 by Alexey Vanzhula Quote Link to comment Share on other sites More sharing options...
csp Posted July 11, 2014 Author Share Posted July 11, 2014 Thanks for your replies Alexey. I have hard time to make your code work inside my script. Here is my working script. I am bringing in the ui with loadUi. The hide function will not work, probably I am using it wrong. The Qt.WindowStaysOnTopHint is working in my mac but I am using PySide there. At work's linux I can't get it stay on top. And most important the single instance. import hou, os import pyqt_houdini from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4.uic import * app = QApplication.instance() if app is None: app = QApplication(['houdini']) projectsDir = '/jobs' pwd = os.path.dirname(__file__) class StartShot(QWidget): def __init__(self, parent=None): super(StartShot, self).__init__(parent) # ui loader self.ui = loadUi(pwd+'/ui/open.ui', self) # get parameters self.filter = self.ui.findChild(QLineEdit, 'filter') self.project = self.ui.findChild(QComboBox, 'project') self.shot = self.ui.findChild(QComboBox, 'shot') self.hip = self.ui.findChild(QComboBox, 'hip') self.open = self.ui.findChild(QPushButton, 'load') # initial function self.getProject() # set connections self.filter.textChanged.connect(self.getProject) self.project.currentIndexChanged.connect(self.getShot) self.shot.currentIndexChanged.connect(self.getHip) self.open.clicked.connect(self.loadHip) self.ui.setWindowFlags(Qt.WindowStaysOnTopHint) #will not work in Linux self.ui.show() def getProject(self): #code def getShot(self): #code def getHip(self): #code def loadHip(self): project = str(self.project.currentText()) shot = str(self.shot.currentText()) job = os.path.join(projectsDir, project, shot) hip = job+'/hip/'+str(self.hip.currentText()) if os.path.isfile(hip): hou.hipFile.load(hip) hou.hscript('setenv JOB = %s'%job) self.hide #will not work but no error def runApp(): dialog = StartShot() pyqt_houdini.exec_(app, dialog) Quote Link to comment Share on other sites More sharing options...
Alexey Vanzhula Posted July 11, 2014 Share Posted July 11, 2014 (edited) 1. I this case there is no difference between PySide and PyQt4. 2. For linux there is some situations where you need to setup your window manager for WindowStaysOnTopHint. 3. I never used uic and Designer for build ui - just manually layouting controls. It is my firm position 4. This solution works well for me and my linux desktop. But you can also try this http://paulwinex.blogspot.com/2014/06/pyside-helper-for-houdini.html Edited July 11, 2014 by Alexey Vanzhula Quote Link to comment Share on other sites More sharing options...
csp Posted July 11, 2014 Author Share Posted July 11, 2014 So, if you had to edit my code to do what yours does... single instance, etc. How would you do that? Quote Link to comment Share on other sites More sharing options...
Alexey Vanzhula Posted July 11, 2014 Share Posted July 11, 2014 (edited) There are many ways to do that. So, give me open.ui file for testing it Edited July 11, 2014 by Alexey Vanzhula Quote Link to comment Share on other sites More sharing options...
csp Posted July 11, 2014 Author Share Posted July 11, 2014 Alexey, please check your messages. Quote Link to comment Share on other sites More sharing options...
stevegh Posted July 22, 2014 Share Posted July 22, 2014 Can you share what portions of your ui file were misbehaving? Quote Link to comment Share on other sites More sharing options...
csp Posted July 30, 2014 Author Share Posted July 30, 2014 hello stevegh, there is nothing wrong with the script as is. I just wanted to have some functionalities, as single instance and close window on button clicked, which I can live without. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.