wxPython button binding in XSI

arcsecond at gmail.com arcsecond at gmail.com
Thu Mar 1 15:07:31 EST 2007


I feel like an idiot. I've been struggling with this for 4 days. I can
make a window but I can't seem to close them. I think I've narrowed
down the problem being with my button event bindings. They don't seem
to take. But I don't get any errors either. So am I missing something?

Any help would be appreciated. Thanks in advance.

I'm building a tool in XSI 6.0 based on this:
http://www.xsi-blog.com/archives/138\
I've copied the XSISubFrame exactly.

My specific app looks like this:

<code>
class jpFrame(XSISubFrame):
	def __init__(self, parent, app):
		XSISubFrame.__init__(self, parent, app, -1, 'jpPointOven',
size=(100, 140))
		self.panel = jpPanel(self)


	def OnClose(self, event):
		"""
		This method is bound by XSISubFrame to the EVT_CLOSE event.
		It shows a modal dialog before closing.
		Notice the win32gui hack to disable the XSI top-level window during
the modal time.
		"""
		dlg = wx.MessageDialog(None, 'Are you sure?', 'Sure?')
		if self.showModalDialog(dlg) == wx.ID_OK:
			self.panel.onWindowClose()
			XSISubFrame.OnClose(self, event)



class jpPanel(wx.Panel):
	_runningInstances = []
	def __init__(self, parent):
		wx.Panel.__init__(self, parent, -1)
		self.frame = parent

		selectAllButton = wx.Button(self, -1, "Select*GEO")
		self.Bind(wx.EVT_BUTTON, self.selectAllGeo, selectAllButton)
		selectHeirButton = wx.Button(self, -1, "Select Heir *GEO")
		self.Bind(wx.EVT_BUTTON, self.selectHierGeo, selectHeirButton)

		btn = wx.Button(self, -1, "Close")
		self.Bind(wx.EVT_BUTTON, self.OnClose, btn)
		self.Bind(wx.EVT_CLOSE, self.OnClose)

		scenesFile = r"scenes.txt"
		scenes = self.jpReadLines(scenesFile)
		scenesList = wx.Choice(self, -1, choices=scenes)

		deformButton = wx.Button(self, -1, "Deform Selected")
		self.Bind(wx.EVT_BUTTON, self.applyDeformers, deformButton)

		tID = wx.NewId()

		sizer = wx.BoxSizer(wx.VERTICAL)
		sizer.Add(selectAllButton, 0, wx.ALL)
		sizer.Add(selectHeirButton, 0, wx.ALL)
		sizer.Add(scenesList, 0, wx.ALL)
		sizer.Add(deformButton, 0, wx.ALL)
		sizer.Add(btn, 0, wx.ALL)
		self.SetSizer(sizer)
		self.Layout()
		self.SetSize(sizer.GetSize())
		self.SetAutoLayout(True)
		self.frozen = False

		self.Show(True)
		jpPanel._runningInstances.append(self)


	def selectAllGeo(self,event):
		Application.LogMessage("This is a test: selectAllGeo")

		Application.selectobj('*GEO')

	def selectHierGeo(self, event):
		Application.LogMessage("This is a test: selectHeirGeo")

		Application.SelectTree()
		model = Application.Selection[0]
		Application.selectobj(model.FindChildren('*GEO'))

	def jpReadLines(self, fileToRead):
		lines = []
		badLines = []

		if os.path.exists(fileToRead) == False:
			print "File Not Found"
		else:
			thisFile = file(fileToRead, "r+")
			badLines = thisFile.readlines()
			thisFile.close()
		for i in range(0, len(badLines)):
			lines.append(badLines[i].strip())
		return lines

	def applyDeformers(self, event):
		Application.LogMessage("This is a test: applyDeformers")

		path = self.poPath
		scene = self.sceneList.get()
		objs = Application.Selection
		for thisObj in objs:
			try:
				Application.SetValue(str(thisObj) + ".polymsh.PO_XSI_Reader.Mute",
0, "")
				splitObj = re.split("\.", str(thisObj))
				thisPath = (path + os.sep + scene + os.sep + str(splitObj[0]) +
os.sep + str(splitObj[-1]) + ".mdd")
				Application.LogMessage(thisPath)
				Application.SetValue(str(thisObj) +
".polymsh.PO_XSI_Reader.FileName", (path + os.sep + scene + os.sep +
str(splitObj[0]) + os.sep + str(splitObj[-1]) + ".mdd"), "")
			except:
				Application.ApplyOp("POXSI", str(thisObj), "siUnspecified",
"siPersistentOperation", "", 0)
				Application.AddExpr((str(thisObj) +
".polymsh.PO_XSI_Reader.POTime"), "T", 1)
				Application.SetValue(str(thisObj) + ".polymsh.PO_XSI_Reader.Mute",
0, "")
				splitObj = re.split("\.", str(thisObj))
				thisPath = (path + os.sep + scene + os.sep + str(splitObj[0]) +
os.sep + str(splitObj[-1]) + ".mdd")
				Application.LogMessage(thisPath)
				Application.SetValue(str(thisObj) +
".polymsh.PO_XSI_Reader.FileName", (path + os.sep + scene + os.sep +
str(splitObj[0]) + os.sep + str(splitObj[-1]) + ".mdd"), "")


	def onWindowClose(self):
		jpPanel._runningInstances.remove(self)

	def OnClose(self, evt):
		"""Event handler for the button click."""
		self.frame.Close()



jpFrame.create()
</code>




More information about the Python-list mailing list