First Of all I haven't had much luck to get this Blender Python Startup script to work successfully and second the api in 2.5 hasen't been working with my scripts from 2.4 so I am going to updating the blender aspect of it. I would appreciate some help getting it to detect whether it started with the blender gui or without. And It needs curses or atleast a buffer blocking of some kind. Appreciate the help.
import sys,threading,time,curses,tempfile
#python2.6
import __builtin__
#python3.1
#import builtins
class _thread(threading.Thread):
import sys,time,bpy,Blender
def load_gui(self):
thread.gui_load=1
def exit(self):
self.pout("Killing Session")
thread._Thread__stop()
thread.notdone=0
thread.gui_load=1
def quit(self):
self.pout("Killing Session")
thread._Thread__stop()
thread.notdone=0
thread.gui_load=1
class WrapExceptions():
def __init__(self,msg,type=None):
if (type==None):
self.type='WrapExceptions'
else:
self.type=type
self.msg=' '.join([":'''",self.type,msg,"'''"])
def __str__(self):
return("Exception: "+self.msg.__str__())
def __repr__(self):
return(self.msg)
def pout(self,arg):
self.stdout.write(arg.__str__())
def pin(self):
return(self.stdin.readline())
def _init(self):
self.notdone=1
self.gui_load=1
self.stdin=sys.stdin
self.stdout=sys.stderr
#self.scr=curses.initscr()
#self.inwin=curses.newwin()
#self.sbuf=[tempfile.TemporaryFile(),tempfile.TemporaryFile()]
#self.scr.putwin(self.sbuf[0])
#self.sbuf[0].seek(0)
#curses.savetty()
self.__init__(target=self._slave_thread,args=[])
self.start()
def build_globals(self,objects):
ret={'__all__':[]}
for anObj in objects:
dl=self.__builtins__.dir(anObj)
ret['__all__'].append(dl)
for Objs in dl:
ret[Objs.__str__()]=anObj.__getattribute__(Objs.__str__())
return(ret)
def _slave_thread(self):
cmdStr='';ind=0;cmdHistory=[];cmdP=0
self.LastExc=self.WrapExceptions(self.__str__())
self.local=self.build_globals([self.__builtins__,self])
self.pout('#For import; use setattr(__builtins__,\'name\',__import__(\'name\'))\n')
try:
while(self.notdone):
if (cmdStr==''):
self.pout('\n>>> ')
else:
self.pout('\n... '+self.__builtins__.chr(9).zfill(ind))
cmdStr+=self.pin()
p=cmdStr.__len__()
while (p>0):
if (cmdStr[p-1]==':'):
ind+=1
break
elif(cmdStr[p-1].__eq__(" ") or cmdStr[p-1].__eq__("\n")):
p-=1
#elif(cmdStr[p-1].__eq__("\x1b")):
# cmdHistory.insert(cmdP,cmdStr)
# if (cmdHistory.__len__()>cmdP):
# pout("\n"+cmdHistory[cmdP])
# else:
# pout("\n")
else:
try:
code=self.__builtins__.compile(cmdStr,'','eval')
self.__builtins__.eval(code,self.local)
except:
print(self.LastExc.__str__())
cmdStr=''
break
except(self.WrapException):
print "Exception Raised Above Main.\n"
#finally:
# curses.endwin()
# curses.resetty()
def m_Gc(target):
while(target.notdone and not target.gui_load):
time.sleep(1)
if (not target.isAlive()):
target._init()
thread=_thread()
thread.__builtins__=__builtin__
thread._init()
if (__name__=='__main__'):
m_Gc(thread)
No replies to this topic
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









