#!/usr/bin/python2 #ribview.pyw - RIBview 0.1 - 3 August 2001 #A script for Windows and Unix to launch OpenGL and rendered views #of RenderMan RIB files using Blue Moon Rendering Tools (BMRT). #Update at http://www.3dartist.com/3dao/r/allenbil/python/ #Created by Bill Allen """ HELP: Installation: You must have both Python 2.0+ and BMRT 2.6+ installed for this script to work. Python (www.python.org) is available for most platforms, and BMRT (www.exluna.com/bmrt/) for Windows and the Unix family. A good place to put RIBview in right in with your RIB files, such as in BMRT's own /examples folder. Stopping renders: Go to the window BMRT is working in (not the render window) and use Ctrl-Break (Windows). [[Is the same true for Unix?]] Button command queing: Any clicking you do on RIBview buttons while a rendering is in progress will have not an immediate result but _will_ take effect later. Long file names: You can optionally turn on the useDosName user variable below to use MS-DOS 8.3 path and file names (default is off). If this is on, RIBview attempts to create 8.3 files and paths, but only works with those that get numbered as ~1. It cannot deal with instances of ~2 and above. Is it done yet?: RIBview lets you set BMRT's rendrib completion sound, but it doesn't work if you also have RIBview redirect the rendrib stats to a text file. One way to know if a rendering is done or not is to leave the cursor over the rendering window, as the cursor icon will change. WARNING about running from IDLE or other Tkinter-based IDE: Make SURE to change "usingIDLE = 0" below to "= 1" if you run this RIBview from a Tkinter-base editor, and to have it "= 0" otherwise. WARNING about running under Windows: RIBview MUST be run on Windows as ribview.pyw--not ribview.py--to avoid a conflict between Python and BMRT's MS-DOS windows. There also may be a conflict in running IDLE and RIBview separately but at the same time, although this hasn't been confirmed. """ #LICENSE: This code is free software provided as is and without # warranty for fitness for any purpose. Use it at your own risk. # This code and derivations may be used anywhere, including for # commercial application. If used publicly, acknowledgment and a # link back would be appreciated. #The author and publisher of record, Bill Allen and Columbine, Inc. # are completely independent of any other companies and products # mentioned. Any trademarks mentioned are acknowledged as being # the property of their owners. #The RenderMan (R) Interface Procedures and Protocol are: # Copyright 1988, 1989, 2000, Pixar. All Rights Reserved ### BEGIN PROGRAM ### #--- user-set variable --- useDosName = 0 #set = 1 to force DOS-style 8.3 file names usingIDLE = 0 #set = 1 if running from IDLE, otherwise 0 #--- global app/GUI constants --- __version__ = '0.1' versionDate = '3 August 2001' #--- functions --- def msdos8_3(p): """ This function takes a simple stab at converting long file names into MS-DOS 8.3 names acceptable to BMRT 2.6, such as changing C:\My Documents\My RIB file.rib into c:\mydocu~1\myribf~1.rib However, if there are multiple instances, such as in a series like My RIB file 001.rib ... My RIB file 179.rib this function will only recognize one of those files. """ p = os.path.abspath(p).lower() #get back-slashes & lower-case pcs = string.split(p,'\\') p = '' for i in range(len(pcs)): s = '' for j in range(len(pcs[i])): if pcs[i][j] != ' ': #no spaces s = s + pcs[i][j] if len(s) > 8: if s.find('.') == -1: s = s[:6] + '~1' if i == 0: p = s else: p = p + '\\' + s return p #end msdos8_3 #--- classes --- class winClass: def __init__(self,master): self.ribDir,x = os.path.split(sys.argv[0]) self.ribName = '' self.frame = tk.Toplevel(master,relief='flat',borderwidth=2) ww = self.frame.winfo_screenwidth() wh = self.frame.winfo_screenheight() self.frame.geometry('400x100+'+str(ww-410)+'+'+str(wh-160)) self.frame.resizable(0,0) bold = ('Helvetica',8,'bold') if not usingIDLE: self.frame.protocol('WM_DELETE_WINDOW',self.quit) #---dialog internal label self.idName = tk.Label(self.frame,text='RIBview '+__version__ +' (requires BMRT)') self.idName.pack(side='top',anchor='w',padx=7,pady=4) #---get file button & label self.nameFrame = tk.Frame(self.frame,relief='groove',bd=1, width=390) self.getRibB = tk.Button(self.nameFrame,text='Get RIB', font=bold,command=self.getRib) self.getRibB.pack(side='left',anchor='w') self.fileName = tk.Label(self.nameFrame,text='(no file)') self.fileName.pack(side='left',anchor='w') self.nameFrame.pack(side='top',anchor='nw',pady=2) #--- controls for viewing a RIB file with rgl self.rglFrame = tk.Frame(self.frame,relief='groove',bd=1) self.rglGoB = tk.Button(self.rglFrame,text='View', font=bold,command=self.rglView) self.rglGoB.pack(side='left',anchor='w') self.rglHowB = tk.Button(self.rglFrame,text='normal', command=self.rglHow) self.rglHowB.pack(side='left',anchor='w') self.rglFrame.pack(side='left',anchor='w',padx=2,pady=2) #--- controls for rendering a RIB file with rendrib self.rrFrame = tk.Frame(self.frame,relief='groove',bd=1) self.rrGoB = tk.Button(self.rrFrame,text='Render', font=bold,command=self.render) self.rrGoB.pack(side='left',anchor='w') self.rrBeepB = tk.Button(self.rrFrame,text='bell', command=self.rrBeepTog) self.rrBeepB.pack(side='left',anchor='w') self.rrStatB = tk.Button(self.rrFrame,text='no stats', command=self.rrStatTog) self.rrStatB.pack(side='left',anchor='w') self.rrFrame.pack(side='left',padx=2,pady=2) #--- set up QUIT button self.quitB = tk.Button(self.frame,text='QUIT', font=bold,command=self.quit) self.quitB.pack(side='bottom',anchor='se',padx=20,pady=5) def getRib(self): n = tkFD.askopenfilename(title='Open RIB File',parent=self.frame, filetypes=[('RIB files','*.rib'),('All Files','*.*')], initialdir=self.ribDir) if n != '' and n[-4:].lower() == '.rib': self.ribDir,x = os.path.split(n) if useDosName: n = msdos8_3(n) self.ribName = n self.fileName.config(text=n) self.nameFrame.update_idletasks() return 1 else: return 0 def quit(self): if usingIDLE: self.frame.destroy() else: self.frame.quit() root.quit() def render(self): if self.ribName == '': if not self.getRib(): tkMB.showerror('Nothing to Render', 'Please use [Get RIB] file.',parent=self.frame) return opt = ' -d -v ' if self.rrBeepB.cget('text') == 'BELL': opt = opt + '-beep ' if self.rrStatB.cget('text') != 'no stats': #keep this last! opt = opt + '-stats ' if self.rrStatB.cget('text') != '#s > file': x = os.system('rendrib'+opt+self.ribName) else: x = os.system('rendrib'+opt+self.ribName+' >> ' +self.ribName[:-4]+'_stats.txt') def rglHow(self): if self.rglHowB.cget('text') == 'normal': self.rglHowB.config(text='as lines') elif self.rglHowB.cget('text') == 'as lines': self.rglHowB.config(text='as sketch') else: self.rglHowB.config(text='normal') def rglView(self): if self.ribName == '': if not self.getRib(): tkMB.showerror('Nothing to View', 'Please select a RIB file.',parent=self.frame) return opt = '' if self.rglHowB.cget('text') == 'normal': opt = ' ' else: if self.rglHowB.cget('text') == 'as lines': opt = ' -lines ' else: opt = ' -sketch ' x = os.system('rgl'+opt+self.ribName) def rrBeepTog(self): if self.rrBeepB.cget('text') == 'bell': self.rrBeepB.config(text='BELL') else: self.rrBeepB.config(text='bell') def rrStatTog(self): if self.rrStatB.cget('text') == 'no stats': self.rrStatB.config(text='#s > scrn') elif self.rrStatB.cget('text') == '#s > scrn': self.rrStatB.config(text='#s > file') else: self.rrStatB.config(text='no stats') #end class winClass #--- get some work done --- if __name__ == '__main__': import Tkinter as tk import tkMessageBox as tkMB import tkFileDialog as tkFD import os, string, sys root = tk.Tk() root.withdraw() #don't want the root's window root.title('RIBview') mainWin = winClass(root) #create our own window if not usingIDLE: #set this value at the top of this file root.mainloop() root.destroy() #all done