Hi,

I have written 2 procedures. how best may i put it in class, def form. if i do not have procedures within a class, is it possible to call them where and as they are. Is this the best way to use python's strength.

BRgds,

kNish

import maya.cmds as cmds
import smtplib
import os
import maya.mel as mm
import performReleaseOptionVar
def performSendM():
	global contents
	global fromUser
	global toUser
	global subject

	if cmds.window('sendMailWindow',exists=True):
		cmds.deleteUI('sendMailWindow', window=True)
	sendMailwindow = cmds.window('sendMailWindow',title = 'Send Mail', width=369, height=385, sizeable = False)
	form = cmds.formLayout(numberOfDivisions=100)

	fromText = cmds.text( label='From : ' )
	fromUser = cmds.textField(width=250)

	toText = cmds.text( label='To : ' )
	toUser = cmds.textField(width=250)

	subjectText = cmds.text( label='Subject : ' )
	subject = cmds.textField(width=250)

	contentsText = cmds.text( label='Contents : ' )
	contents = cmds.scrollField(editable=True, wordWrap=True, width=250, height=100)

#	submit = cmds.button(label="   Send Mail   ")
	submit = cmds.symbolButton('submitButton',image='abcd_01.bmp')
	cmds.textField(fromUser, edit=True, text = (os.getenv("USERNAME" ) + '@abcdef.com'), enable = False)
	cmds.textField(toUser, edit=True, text = "abcdef@abcdef.com", enable = False)
	cmds.textField(subject,edit=True, text = "abcd.abcd", enable = False)
	cmds.scrollField(contents,edit=True)

	cmds.symbolButton('submitButton', edit = True, image='abcd_01.bmp', command = 'performSendMail.performSendMessage()' )

	cmds.formLayout( form, edit=True, attachForm=[(fromText, 'left', 5), (fromText, 'top', 5), (toText, 'left', 15), (fromUser, 'top', 5), (contents, 'left', 5), (submit, 'left', 125) ], 
	attachControl=[(toText, 'top', 15, fromText), (subjectText, 'top', 25, toText), (contentsText, 'top',25,subjectText), (fromUser, 'left', 15, fromText), (toUser, 'top', 15, fromUser), (toUser, 'left', 15, toText), (subject, 'top', 15, toUser), (subject, 'left', 10, subjectText), (contents, 'top', 15, subject), (contents, 'left', 5, contentsText), (submit, 'top', 15, contents)])
	cmds.showWindow( sendMailwindow )

def performSendMessage():

	fUser = cmds.textField(fromUser, query = True, text = True)
	tUser = cmds.textField(toUser, query = True, text = True)
	cont = cmds.scrollField(contents, query = True, text = True)
#	print 'type cont',type(cont),'\n'
	
	subj = cmds.textField(subject, query = True, text = True)
#	print 'type subj',type(subj),'\n'
	
	if ((cont == "") or (subj == "")):
		mm.eval("warning \"blank data does not communicate anything. Please complete the blank fields.\\n\";")
	else:
		content = ( "From: %s\r\n"
		            "To: %s\r\n"
		            "Subject: %s\r\n"
		            "\r\n%s"
		       % ( fUser,  tUser , subj, cont ) )
		cmds.optionVar(sv=("optionVartUser", tUser))
		
		cServer = smtplib.SMTP("XXX.XXX.X.XX:XXX")
		cServer.sendmail(fUser,tUser,content)
		cServer.quit()
		cmds.deleteUI('sendMailWindow')
		mm.eval("string $optiontUser = `optionVar -query \"optionVartUser\"`;")
		mm.eval("print (\"pcon :message sent to \" + $optiontUser)")
                performReleaseOptionVar.performReleaseOptionVar()

import module
define class
initialize that class
define funcions in the class
use them

That is sequence I can guess of these classes, Not geek though

A class should only group functions together that belong together. I would also avoid globals, they are devils as your program grows. A class handles globals within the class using self.

This article has been dead for over six months. Start a new discussion instead.