hlayout = QtGui.QHBoxLayout(self) self.setLayout(hlayout) vlayout = QtGui.QVBoxLayout() # hlayout.addLayout(vlayout, 1) hlayout.addWidget(self.canvas.native, 1) # vlayout.addWidget(self.vertLabel, 0) vlayout.addWidget(self.vertEdit, 1) vlayout.addWidget(self.fragLabel, 0) vlayout.addWidget(self.fragEdit, 1) vlayout.addWidget(self.theButton, 0) def on_compile(self): vert_code = str(self.vertEdit.toPlainText()) frag_code = str(self.fragEdit.toPlainText()) self.canvas.program.shaders[0].code = vert_code self.canvas.program.shaders[1].code = frag_code # Because the code has changed, the variables are re-created, # so we need to reset them. This can be considered a bug in gloo # and should be addressed at some point. self.canvas.program['u_projection'] = self.canvas.projection self.canvas.program['u_view'] = self.canvas.view if __name__ == '__main__': app.create() m = MainWindow() m.show() app.run()
self.canvas = Canvas(parent=self) # Layout hlayout = QtGui.QHBoxLayout(self) self.setLayout(hlayout) vlayout = QtGui.QVBoxLayout() # hlayout.addLayout(vlayout, 1) hlayout.addWidget(self.canvas.native, 1) # vlayout.addWidget(self.vertLabel, 0) vlayout.addWidget(self.vertEdit, 1) vlayout.addWidget(self.fragLabel, 0) vlayout.addWidget(self.fragEdit, 1) vlayout.addWidget(self.theButton, 0) self.show() def on_compile(self): vert_code = str(self.vertEdit.toPlainText()) frag_code = str(self.fragEdit.toPlainText()) self.canvas.program.set_shaders(vert_code, frag_code) # Note how we do not need to reset our variables, they are # re-set automatically (by gloo) if __name__ == "__main__": app.create() m = MainWindow() app.run()