Entry 1948

wxPython with Maya

   

Submitted by anonymous on June 25, 2009 at 12:42 a.m.
Language: Python. Code size: 2.6 KB.

import glob,os
import wx
from telnetlib import Telnet

class wxBarosManager(wx.Frame):
    def __init__(self):
        self.mayaScriptPath = 'd:\\MAYA_script\\'
        self.categoryFolders = [(x,self.mayaScriptPath+'\\'+x) for x in os.listdir(self.mayaScriptPath) if '_' != x[0] and os.path.isdir(self.mayaScriptPath+'\\'+x) ]

        self.theHost = 'localhost'
        self.thePort = '2255'       
        
        wx.Frame.__init__(self,None, -1, '  Baros Manager  - Stand Alone  ',pos=(5,5),size=(420, 380))
        icon=wx.Icon('C:\\Python26\\DLLs\\py.ico',wx.BITMAP_TYPE_ICO)
        self.SetIcon(icon) 
        self.tree = wx.TreeCtrl(self)
        root = self.tree.AddRoot("Maya Scripts")
        self.AddTreeNodes(root,self.categoryFolders)
        
        self.Bind(wx.EVT_TREE_ITEM_EXPANDED,self.OnItemExpanded,self.tree)
        self.Bind(wx.EVT_TREE_ITEM_COLLAPSED,self.OnItemCollapsed,self.tree)
        self.Bind(wx.EVT_TREE_SEL_CHANGED,self.OnSelChanged, self.tree)
        self.Bind(wx.EVT_TREE_ITEM_ACTIVATED,self.OnActivated, self.tree)
        self.tree.Expand(root)        
		
    def getScriptNames(self,theCategory):		
        theScriptNames = [s for s in os.listdir(self.mayaScriptPath+theCategory) if s[0] != '_' and os.path.isdir(self.mayaScriptPath+theCategory+'\\'+s)]
        return theScriptNames

    def AddTreeNodes(self, parentItem, items):
        for x in items:            
            if self.testChildFolder(x[1]):
                newItem = self.tree.AppendItem(parentItem, x[0])
                self.AddTreeNodes(newItem,self.childNodes(x[1]))                
            else :
                self.tree.AppendItem(parentItem, x[0])
                
    def childNodes(self,node):                    
        return [(x,node+'\\'+x) for x in os.listdir(node+'\\') if os.path.isdir(node+'\\'+x) and '_'!= x[0]]
            
    def testChildFolder(self,theFolder):
        if [x for x in glob.glob(theFolder+'\\*') if os.path.isdir(x)] :
            return True
        else : return False  

    def GetItemText(self, item):
        if item:
            return self.tree.GetItemText(item)
        else:
            return ""

    def OnActivated(self, evt):
        cmd = 'python(\"'+self.GetItemText(evt.GetItem())+ '()\");'     
        try : 
            tel.open(self.theHost,self.thePort)
            cmd = self.GetItemText(evt.GetItem())
            tel.write(str(cmd))
        except :
            print self.GetItemText(evt.GetItem())
		
app = wx.PySimpleApp()
try:
    wxBarosManager().Show()
    app.MainLoop()
finally:
    del app

This snippet took 0.02 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).