def click_menuChoice(self, fname, fcode): if self.argPanel != None: self.argPanel.destroy() self.argPanel = ImportShardPanel(self.argCanvas, fname, fcode) self.argPanel.update_idletasks() self.argCanvas.itemconfigure(self.argCanvasWID, window=self.argPanel) self.argCanvas['scrollregion'] = self.argCanvas.bbox("all")
class ImportShardsGUI(TkWindow): """ A dialogue box component. Initialised with a path, it will extract the code of all the functions in any .py files it finds in the tree. These will be listed in a drop down menu. Selecting one will display its code. Two 'add' options are given: as an inline shard, or as a complete function. The inline option sends out just the body of the function as a shardGen object, otherwise the code for the function definition will be included. """ def __init__(self, path): self.selectedComponent = None self.uid = 1 self.functions = glomfrompath(path) super(ImportShardsGUI, self).__init__() def setupWindow(self): self.window.title("Shard Builder") self.addframe = Tkinter.Frame(self.window, borderwidth=2, relief=Tkinter.GROOVE) self.addframe.grid(row=0, column=0, sticky=Tkinter.N + Tkinter.E + Tkinter.W + Tkinter.S, padx=4, pady=4) def menuCallback(index, text): self.click_menuChoice(self.getname(text), self.functions[text]) items = list(self.functions.keys()) self.choosebutton = ScrollingMenu(self.addframe, items, command=menuCallback) self.choosebutton.grid(row=0, column=0, columnspan=2, sticky=Tkinter.N) self.argPanel = None self.argCanvas = Tkinter.Canvas(self.addframe, relief=Tkinter.SUNKEN, borderwidth=2) self.argCanvas.grid(row=1, column=0, sticky=Tkinter.N + Tkinter.S + Tkinter.E + Tkinter.W) self.argCanvasWID = self.argCanvas.create_window(0, 0, anchor=Tkinter.NW) self.argCanvasScroll = Tkinter.Scrollbar(self.addframe, orient=Tkinter.VERTICAL) self.argCanvasScroll.grid(row=1, column=1, sticky=Tkinter.N + Tkinter.S + Tkinter.E) self.argCanvasScroll['command'] = self.argCanvas.yview self.argCanvas['yscrollcommand'] = self.argCanvasScroll.set if self.functions: self.click_menuChoice(self.getname(items[0]), self.functions[items[0]]) self.addbutton = Tkinter.Button(self.addframe, text="ADD Shard", command=self.click_addComponent) self.addbutton.grid(row=2, column=0, columnspan=2, sticky=Tkinter.S) self.addframe.rowconfigure(1, weight=1) self.addframe.columnconfigure(0, weight=1) # just adds component same atm. self.inlinebutton = Tkinter.Button(self.addframe, text="ADD Inline Shard", command=self.click_addInline) self.inlinebutton.grid(row=3, column=0, columnspan=2, sticky=Tkinter.S) self.window.rowconfigure(0, weight=1) self.window.columnconfigure(0, weight=1) self.window.protocol("WM_DELETE_WINDOW", self.handleCloseWindowRequest) def main(self): while not self.isDestroyed(): while self.dataReady("control"): msg = self.recv("control") if isinstance(msg, producerFinished) or isinstance( msg, shutdownMicroprocess): self.send(msg, "signal") self.window.destroy() self.tkupdate() yield 1 def handleCloseWindowRequest(self): self.send(shutdownMicroprocess(self), "signal") self.window.destroy() def getname(self, fname): return fname.split(':')[1].lstrip() def click_addComponent(self): node, name = self.argPanel.getDef() self.send(("ADD", node, name), "outbox") def click_addInline(self): node, name = self.argPanel.getInlineDef() self.send(("ADD", node, name), "outbox") def click_menuChoice(self, fname, fcode): if self.argPanel != None: self.argPanel.destroy() self.argPanel = ImportShardPanel(self.argCanvas, fname, fcode) self.argPanel.update_idletasks() self.argCanvas.itemconfigure(self.argCanvasWID, window=self.argPanel) self.argCanvas['scrollregion'] = self.argCanvas.bbox("all")
class ImportShardsGUI(TkWindow): def __init__(self, path): self.selectedComponent = None self.uid = 1 self.functions = glomfrompath(path) super(ImportShardsGUI, self).__init__() def setupWindow(self): items = [] lookup = {} # This is a bit of a nasty hack really ... :-) # Why is this a hack ? # Oh it's viewed here as a hack because it's a closure self.window.title("Shard Builder") self.addframe = Tkinter.Frame(self.window, borderwidth=2, relief=Tkinter.GROOVE) self.addframe.grid(row=0, column=0, sticky=Tkinter.N+Tkinter.E+Tkinter.W+Tkinter.S, padx=4, pady=4) # called when item selected from function list def menuCallback(index, text): self.click_menuChoice(self.getname(text), self.functions[text]) items = list(self.functions.keys()) self.choosebutton = ScrollingMenu(self.addframe, items, command = menuCallback) self.choosebutton.grid(row=0, column=0, columnspan=2, sticky=Tkinter.N) self.argPanel = None self.argCanvas = Tkinter.Canvas(self.addframe, relief=Tkinter.SUNKEN, borderwidth=2) self.argCanvas.grid(row=1, column=0, sticky=Tkinter.N+Tkinter.S+Tkinter.E+Tkinter.W) self.argCanvasWID = self.argCanvas.create_window(0,0, anchor=Tkinter.NW) self.argCanvasScroll = Tkinter.Scrollbar(self.addframe, orient=Tkinter.VERTICAL) self.argCanvasScroll.grid(row=1, column=1, sticky=Tkinter.N+Tkinter.S+Tkinter.E) self.argCanvasScroll['command'] = self.argCanvas.yview self.argCanvas['yscrollcommand'] = self.argCanvasScroll.set self.click_menuChoice(self.getname(items[0]), self.functions[items[0]]) self.addbutton = Tkinter.Button(self.addframe, text="ADD Shard", command=self.click_addComponent) self.addbutton.grid(row=2, column=0, columnspan=2, sticky=Tkinter.S) self.addframe.rowconfigure(1, weight=1) self.addframe.columnconfigure(0, weight=1) # just adds component same atm. self.inlinebutton = Tkinter.Button(self.addframe, text="ADD Inline Shard", command=self.click_addInline) self.inlinebutton.grid(row=3, column=0, columnspan=2, sticky=Tkinter.S) self.window.rowconfigure(0, weight=1) self.window.columnconfigure(0, weight=1) self.window.protocol("WM_DELETE_WINDOW", self.handleCloseWindowRequest ) def main(self): while not self.isDestroyed(): while self.dataReady("control"): msg = self.recv("control") if isinstance(msg, producerFinished) or isinstance(msg, shutdownMicroprocess): self.send(msg, "signal") self.window.destroy() self.tkupdate() yield 1 def handleCloseWindowRequest(self): self.send( shutdownMicroprocess(self), "signal") self.window.destroy() def getname(self, fname): return fname.split(':')[1].lstrip() def click_addComponent(self): node, name = self.argPanel.getDef() self.send(("ADD", node, name),"outbox") def click_addInline(self): node, name = self.argPanel.getInlineDef() self.send(("ADD", node, name),"outbox") def click_menuChoice(self, fname, fcode): if self.argPanel != None: self.argPanel.destroy() self.argPanel = ImportShardPanel(self.argCanvas, fname, fcode) self.argPanel.update_idletasks() self.argCanvas.itemconfigure(self.argCanvasWID, window=self.argPanel) self.argCanvas['scrollregion'] = self.argCanvas.bbox("all")
class ImportShardsGUI(TkWindow): """ A dialogue box component. Initialised with a path, it will extract the code of all the functions in any .py files it finds in the tree. These will be listed in a drop down menu. Selecting one will display its code. Two 'add' options are given: as an inline shard, or as a complete function. The inline option sends out just the body of the function as a shardGen object, otherwise the code for the function definition will be included. """ def __init__(self, path): self.selectedComponent = None self.uid = 1 self.functions = glomfrompath(path) super(ImportShardsGUI, self).__init__() def setupWindow(self): self.window.title("Shard Builder") self.addframe = Tkinter.Frame(self.window, borderwidth=2, relief=Tkinter.GROOVE) self.addframe.grid(row=0, column=0, sticky=Tkinter.N+Tkinter.E+Tkinter.W+Tkinter.S, padx=4, pady=4) def menuCallback(index, text): self.click_menuChoice(self.getname(text), self.functions[text]) items = list(self.functions.keys()) self.choosebutton = ScrollingMenu(self.addframe, items, command = menuCallback) self.choosebutton.grid(row=0, column=0, columnspan=2, sticky=Tkinter.N) self.argPanel = None self.argCanvas = Tkinter.Canvas(self.addframe, relief=Tkinter.SUNKEN, borderwidth=2) self.argCanvas.grid(row=1, column=0, sticky=Tkinter.N+Tkinter.S+Tkinter.E+Tkinter.W) self.argCanvasWID = self.argCanvas.create_window(0,0, anchor=Tkinter.NW) self.argCanvasScroll = Tkinter.Scrollbar(self.addframe, orient=Tkinter.VERTICAL) self.argCanvasScroll.grid(row=1, column=1, sticky=Tkinter.N+Tkinter.S+Tkinter.E) self.argCanvasScroll['command'] = self.argCanvas.yview self.argCanvas['yscrollcommand'] = self.argCanvasScroll.set if self.functions: self.click_menuChoice(self.getname(items[0]), self.functions[items[0]]) self.addbutton = Tkinter.Button(self.addframe, text="ADD Shard", command=self.click_addComponent) self.addbutton.grid(row=2, column=0, columnspan=2, sticky=Tkinter.S) self.addframe.rowconfigure(1, weight=1) self.addframe.columnconfigure(0, weight=1) # just adds component same atm. self.inlinebutton = Tkinter.Button(self.addframe, text="ADD Inline Shard", command=self.click_addInline) self.inlinebutton.grid(row=3, column=0, columnspan=2, sticky=Tkinter.S) self.window.rowconfigure(0, weight=1) self.window.columnconfigure(0, weight=1) self.window.protocol("WM_DELETE_WINDOW", self.handleCloseWindowRequest ) def main(self): while not self.isDestroyed(): while self.dataReady("control"): msg = self.recv("control") if isinstance(msg, producerFinished) or isinstance(msg, shutdownMicroprocess): self.send(msg, "signal") self.window.destroy() self.tkupdate() yield 1 def handleCloseWindowRequest(self): self.send(shutdownMicroprocess(self), "signal") self.window.destroy() def getname(self, fname): return fname.split(':')[1].lstrip() def click_addComponent(self): node, name = self.argPanel.getDef() self.send(("ADD", node, name),"outbox") def click_addInline(self): node, name = self.argPanel.getInlineDef() self.send(("ADD", node, name),"outbox") def click_menuChoice(self, fname, fcode): if self.argPanel != None: self.argPanel.destroy() self.argPanel = ImportShardPanel(self.argCanvas, fname, fcode) self.argPanel.update_idletasks() self.argCanvas.itemconfigure(self.argCanvasWID, window=self.argPanel) self.argCanvas['scrollregion'] = self.argCanvas.bbox("all")