Cant close python windows if they exist??

Discussions concerning programming of SOFTIMAGE©
bergj
Posts: 36
Joined: 06 May 2012, 03:58

Cant close python windows if they exist??

Post by bergj » 04 Jun 2012, 16:21




I wrote a hotbox in python and am calling it with space. What I would like to do is have the script read

Code: Select all

	if __any window title included in the script is running_
		close all windows and end the script
      
	else    
		run the script	
			 



This way, I can close it with space n open it and not run into the problem of having multiple instances of the script running at once.


I've tried "states" but I dont have any python syntax for em?

Code: Select all

//This example demonstrates how to set view states

var layout = Desktop.ActiveLayout;
var v1 = layout.CreateView( "Explorer", "First" );

v1.State = siClosed;
v1.State = siMinimized;
v1.State = siNormal;

Thanks guys :-bd

User avatar
Hirazi Blue
Administrator
Posts: 5113
Joined: 04 Jun 2009, 10:15

Re: Cant close python windows if they exist??

Post by Hirazi Blue » 04 Jun 2012, 18:17

The Pythonesk problem you seem to run into is being described on this page in the SDK guide: Getting Python to Recognize Softimage Constants (Enums). Basically you need to import the constants module at the beginning of your script and refer to each constant (or enum) as a member of the constants module.
This would result in the following example from the SDK docs transcribed to Python:

Code: Select all

# Import the Softimage constants module
from win32com.client import constants

layout = Application.Desktop.ActiveLayout
v1 = layout.CreateView( "Explorer", "First" )
v2 = layout.CreateView( "Explorer", "Second" )
v3 = layout.CreateView( "Explorer", "Third" )
v1.State = constants.siClosed
v2.State = constants.siMinimized
v3.State = constants.siNormal
AFAIK the plugin wizards (for custom commands and such) include the

Code: Select all

from win32com.client import constants
"automagically" in your Wizard-generated code, but you still have to use the "constants."-"prefix" with every constant.
To limit typing you could change the import line to read

Code: Select all

from win32com.client import constants as c
after which an referring to an enum with just "c" instead of "constants", like "c.siClosed", would suffice.
Stay safe, sane & healthy!

bergj
Posts: 36
Joined: 06 May 2012, 03:58

Re: Cant close python windows if they exist??

Post by bergj » 04 Jun 2012, 19:07

Thanks. That example worked in the small example provided but I couldnt get it to work in my script. I call everything at the bottom and when I tested the minimized or closed action no change.

Also do you think i should check for the existence of a win from another script entirely? I am ok with having Ctrl+space close it, but not sure exactly on the method to do so.

A small example:

Code: Select all

		
import blurdev
from PyQt4 import QtGui, QtCore, Qt
from PyQt4.QtGui import QApplication, QMainWindow, QPushButton, QVBoxLayout, QWidget, QCursor
import win32com.client
from win32com.client import constants as c
xsi	= win32com.client.Dispatch( "XSI.Application" ).Application


class primitiveCMDS(QtGui.QMainWindow):
	def __init__(self, parent = None):
		super(primitiveCMDS, self).__init__(parent, QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint)
		
	def Null(self):
		xsi.GetPrim("Null", "", "", "")

	def ConePoly(self):
		xsi.CreatePrim("Cone", "MeshSurface", "", "")
		
		###########etc
		
class primitiveBranch(primitiveCMDS):
	def __init__(self, parent = None):
		super(primitiveCMDS, self).__init__(parent, QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint)
		
		myGUIFont = QtGui.QFont()
		myGUIFont.setFamily(_fromUtf8("Mangal"))
		myGUIFont.setPointSize(15)
		myGUIFont.setBold(True)
		myGUIFont.setWeight(75)	
		
		menubar = self.menuBar()
		primitiveMenu = menubar.addMenu("Primitive")
		primitiveMenu.setTearOffEnabled(True)
		primitiveMenu.setWindowTitle("Primitive")
		
		self.setFont(myGUIFont)
		
		Null = QtGui.QAction(self)
		Null.setText("Null")
		Null.triggered.connect(self.Null)
	
		ConePoly = QtGui.QAction(self)
		ConePoly.setText("Cone")
		ConePoly.triggered.connect(self.ConePoly)
		
		###############
		
		primitiveMenu.addAction(Null)
		
		polygonPrimitiveMenu = primitiveMenu.addMenu("Poly Mesh")
		polygonPrimitiveMenu.setTearOffEnabled(True)
		polygonPrimitiveMenu.setWindowTitle("Poly Mesh")		
		polygonPrimitiveMenu.addAction(ConePoly)
		
		quitAction = QtGui.QAction("Exit", self, triggered=self.closeHot)
		self.addAction(quitAction)		
		self.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
		
	def closeHot(self):
		primitiveGUI.close()
		propertyGUI.close()
		parameterGUI.close()
		curveGUI.close()
		skeletonGUI.close()
		deformGUI.close()
		arnoldGUI.close()
		delightGUI.close()
		speciesGUI.close()
		modelGUI.close()
		renderGUI.close()
		simulateGUI.close()
		xsiButton.close()
		transpBackground.close()		

	def showAtMouse(self, moveX, moveY):
		self.show()
		self.moveX = moveX
		self.moveY = moveY		
		mousePosition = QtGui.QCursor.pos()
		self.move(mousePosition.x() + (moveX), mousePosition.y() + (moveY))		
		
primitiveGUI = blurdev.launch(primitiveBranch)
primitiveGUI.showAtMouse(210, -70)
primitiveGUI.State = c.siMinimized ####??		
		

User avatar
Hirazi Blue
Administrator
Posts: 5113
Joined: 04 Jun 2009, 10:15

Re: Cant close python windows if they exist??

Post by Hirazi Blue » 04 Jun 2012, 19:27

I have no experience whatsoever with PyQT, so this is merely guesswork:
As you create the hotbox with the help of PyQT, shouldn't PyQT give you the necessary information about the status of your hotbox? Shouldn't you be looking for a PyQT attribute that gives you the same info as the View.State?

But again: I have no experience with PyQT, so this probably doesn't make any sense. :p
Stay safe, sane & healthy!

User avatar
xsisupport
Posts: 713
Joined: 09 Jun 2009, 09:02
Location: Montreal Canada

Re: Cant close python windows if they exist??

Post by xsisupport » 04 Jun 2012, 19:47

Makes sense to me. View.State is only for Softimage views, not PyQt windows.
// Steve Blair
// "You're not a runner, you're just a guy who runs" -- my wife
//
// My Blogs: Arnold | Softimage

scaron
Posts: 119
Joined: 08 Jul 2009, 03:16

Re: Cant close python windows if they exist??

Post by scaron » 04 Jun 2012, 22:17

hey bergj

i am going to try this with our pyqt plugin to see if it works.

s

bergj
Posts: 36
Joined: 06 May 2012, 03:58

Re: Cant close python windows if they exist??

Post by bergj » 05 Jun 2012, 15:45

I've been told that the best method would be to get a list of all open windows in SI and then take names from that and destroy them. Whats the command for this? I've done the same in maya very easily but I cant find the command here after searching for a while.


Steve,

Good luck. Please tell me if you can figure something out to close that window. It would be appreciated.

User avatar
CiaranM
Posts: 87
Joined: 08 Jun 2009, 23:37
Location: London

Re: Cant close python windows if they exist??

Post by CiaranM » 07 Jun 2012, 08:06

bergj wrote:I've been told that the best method would be to get a list of all open windows in SI and then take names from that and destroy them. Whats the command for this? I've done the same in maya very easily but I cant find the command here after searching for a while.
Since you're drawing pyQt UI windows, Softimage won't have any knowledge of them, so I doubt there's a built in method to do what you ask.
If I understand your problem correctly, I think you should create your own simple 'state', or just a global flag. If you're using a self-installing plugin, you can store the current state i.e. open or closed in Plugin.UserData, which will persist for the whole Softimage session. When you fire the callback associated to spacebar, check the contents of UserData to see if the menus are currently open or not, then update the UserData based on what you do next (open or close GUI). Now you can be sure if you want to close or open the UI and you will be able to make sure there aren't multiple sessions of the UI being drawn.

Nice work btw!!!

User avatar
Hirazi Blue
Administrator
Posts: 5113
Joined: 04 Jun 2009, 10:15

Re: Cant close python windows if they exist??

Post by Hirazi Blue » 07 Jun 2012, 10:20

bergj wrote:I've done the same in maya very easily but I cant find the command here after searching for a while.
That's exactly where the "real" problem lies, AFAIK, Maya is QT-based, so one would expect a better integration of QT in Maya. Softimage isn't QT based (yet?), hence the difficulties, I guess...
"Apples and oranges"... ;)
Stay safe, sane & healthy!

luceric
Posts: 1252
Joined: 21 Jun 2009, 22:08

Re: Cant close python windows if they exist??

Post by luceric » 07 Jun 2012, 17:01

XSI has commands to close XSI Views. they are not the same thing as an OS window. Views are a type of Softimage objects that supports a specific interface and implements variety of services, including a "State" property.

If you create a window parented to XSI, no matter which API you use (ex: python, .net, MFC, Win32), it isn't a XSI view, it's just a random OS window. It's up to you to keep track of that window know how to close that window that you created; that window is not known by XSI. You'll notice that your window doesn't apear in XSI's Window or View menu menu.

(Stephen replied this above).

If you had written the window in Win32, you'd use Win32 APIs to close that window. So I assume that if you write a window in QT, then you need to use QT's API to find and close that window.