from Tkinter import * import poser import os scene = poser.Scene() fig = scene.CurrentFigure() def magGroups(groups,zones): pdir = os.path.dirname(poser.AppLocation()) path = os.path.normpath(os.path.join(pdir,"mag_grp.pz2")) for zone in zones: pose = ['{\n', '\n', 'version\n', '\t{\n', '\tnumber 5\n', '\t}\n', '\n', 'sphereZoneProp %s\n' %(zone), '\t{\n', '\tzoneGroups %s\n' %(groups), '\t}\n', '}\n'] f = open(path,"w") for line in pose: f.write(line) f.flush() f.close() zname = scene.ActorByInternalName(zone).Name() print "***Applied ",groups,"to",zname,"for",fig.Name(),":",scene.CurrentActor().Name(),"***" scene.LoadLibraryPose(path) os.remove(path) #===============GUI======================================================= class App: def __init__(self, master): self.master = master master.title("Magzone Grouper") self.refresh = 0 # ---- Frames ---- self.masterFrame = Frame(self.master,borderwidth=2,relief=RIDGE) self.masterFrame.grid(row=1,column=0) self.ButtonFrame = Frame(self.masterFrame,borderwidth=2,relief=RIDGE) self.ButtonFrame.grid(row=2,column=3) self.ListFrame = Frame(self.masterFrame,borderwidth=2,relief=RIDGE) self.ListFrame.grid(row = 2, column = 0) self.ListFrame2 = Frame(self.masterFrame,borderwidth=2,relief=RIDGE) self.ListFrame2.grid(row = 2, column = 1) # ---- Lists ---- self.ListScroll = Scrollbar(self.ListFrame, orient=VERTICAL) # groups self.ListScroll.grid( row=2, column=0,sticky=N+S+E) self.List = Listbox(self.ListFrame, height=17, width=20, selectmode=MULTIPLE,exportselection=0, yscrollcommand=self.ListScroll.set) self.List.grid( row=2, column=1) self.ListScroll["command"] = self.List.yview self.ListScroll2 = Scrollbar(self.ListFrame2, orient=VERTICAL) # magnets self.ListScroll2.grid( row=2, column=0,sticky=N+S+E) self.List2 = Listbox(self.ListFrame2, height=17, width=16, selectmode=MULTIPLE,exportselection=0, yscrollcommand=self.ListScroll2.set) self.List2.grid( row=2, column=1) self.ListScroll2["command"] = self.List2.yview self.buttonQuit = Button(self.ButtonFrame, text="Quit", command=self.die) self.buttonQuit.grid(row=2, column=0) self.buttonGo = Button(self.ButtonFrame, text="Run", command=self.handleGo) self.buttonGo.grid(row=0, column=0) self.buttonReset = Button(self.ButtonFrame, text="Refresh", command=self.handleFill) self.buttonReset.grid(row=1, column=0) self.handleFill() def die(self): scene.DrawAll() self.master.destroy() def handleGo(self): groups = "" zones = [] for i in range(len(self.List.curselection())): groups += self.List.get(self.List.curselection()[i]) if i < len(self.List.curselection())-1: groups += " " for i in self.List2.curselection(): act = fig.Actor(self.List2.get(i)) zones.append(act.InternalName()) magGroups(groups,zones) def handleFill(self): SelAct = scene.CurrentActor() self.List.delete(0,END) self.List2.delete(0,END) groups = SelAct.Geometry().Groups() for grp in groups: self.List.insert(END,grp) for act in fig.Actors(): if act.IsZone() and act.Parent().InternalName() == SelAct.InternalName(): self.List2.insert(END,act.Name()) #----------------------GUI focus handling------------------ def scrollPress(self,event): self.refresh = 1 def scrollRelease(self,event): self.refresh = 0 def refreshIt(self): try: self.master.lift() except: pass if self.refresh == 0: scene.ProcessSomeEvents() self.master.update_idletasks() self.master.after(250, self.refreshIt) if fig != None: root = Tk() app = App(root) app.refreshIt() root.mainloop() else: print "Scene has no figures!"