import maya.cmds as cmds
import os

class AR_QtConePtrWindow(object):
    """A class for a window to create a cone pointing in a direciton"""
    ## reference to the most recent instance
    use = None
    @classmethod
    def showUI(cls, uiFile):
        """A function to instantiate the window"""
        win = cls(uiFile)
        win.create()
        return win
    def __init__(self, filePath):
        """Initialize data attributes"""
        ## allow controls to initialize using class attribute
        AR_QtConePtrWindow.use = self
        ## unique window handle
        self.window = 'ar_conePtrWindow'
        ## name of rotation input field
        self.rotField = 'inputRotation'
        ## the path to the .ui file
        self.uiFile = filePath
    def create(self, verbose=False):
        """Draw the window"""
        # delete the window if its handle exists
        if cmds.window(self.window, exists=True):
            cmds.deleteUI(self.window)
        # initialize the window
        self.window = cmds.loadUI(
            uiFile=self.uiFile,
            verbose=verbose
        )
        cmds.showWindow(self.window)
    def createBtnCmd(self, *args):
        """Function to execute when Create button is pressed"""
        rotation = None
        # obtain input as a float
        try:
            ctrlPath = '|'.join(
                [self.window, 'centralwidget', self.rotField]
            )
            rotation = float(
                cmds.textField(ctrlPath, q=True, text=True)
            )
        except: raise
        # create a cone and rotate it into proper orientation
        cone = cmds.polyCone()
        cmds.setAttr('%s.rx'%cone[0], 90)
        cmds.rotate(0, rotation, 0, cone[0], relative=True)