Hi,
I am using pymol with a wxpython interface and everything seems to work,
except when I try to change the color of an object using the internal gui,
I get a NameError: name 'util' is not defined error... can you see what is
the problem here?
Best,
Soren
Here is the script I am using:
import wx
from wx.glcanvas import GLCanvas
import OpenGL.GL as OGL
import pymol2
class PyMOLCanvas(GLCanvas):
def __init__(self, parent):
GLCanvas.__init__(self, parent,-1,
attribList=[wx.glcanvas.WX_GL_DOUBLEBUFFER, wx.glcanvas.WX_GL_RGBA])
self.context = wx.glcanvas.GLContext(self)
wx.EVT_PAINT(self, self.OnPaint)
wx.EVT_SIZE(self, self.OnSize)
wx.EVT_MOTION(self, self.OnMouseMotion)
wx.EVT_RIGHT_DOWN(self, self.OnMouseDown)
wx.EVT_RIGHT_UP(self, self.OnMouseUp)
wx.EVT_LEFT_DOWN(self, self.OnMouseDown)
wx.EVT_LEFT_UP(self, self.OnMouseUp)
wx.EVT_MIDDLE_DOWN(self, self.OnMouseDown)
wx.EVT_MIDDLE_UP(self, self.OnMouseUp)
wx.EVT_MOUSEWHEEL(self, self.OnMouseWheel)
self.button_map = {wx.MOUSE_BTN_LEFT:0, wx.MOUSE_BTN_MIDDLE:1,
wx.MOUSE_BTN_RIGHT:2}
self.InitGL()
self.LoadMolFile("C:/Programming/RAW/BSA_mono.pdb")
def OnPaint(self, event):
self.SetCurrent(self.context)
width, height = self.GetSize()
try:
OGL.glViewport(0, 0, width, height)
self._pymol.idle()
self._pymol.draw()
self.SwapBuffers()
except Exception:
pass
def InitGL(self):
self._pymol = pymol2.PyMOL()
self._pymol.start()
width, height = self.GetSize()
self._pymol.reshape(width, height)
self.PymolProcess()
def OnSize(self, event):
try:
width, height = event.GetSize()
except:
width = event.GetSize().width
height = event.GetSize().height
try:
self._pymol.reshape(width, height, True)
self.PymolProcess()
except AttributeError, e:
print 'GL not init yet'
self.Refresh()
self.Update()
def PymolProcess(self):
self._pymol.idle()
self.Refresh()
self.Update()
def OnMouseMotion(self, event):
width, height = self.GetSize()
self._pymol.drag(event.GetX(), height - event.GetY(), 0)
self.PymolProcess()
event.Skip()
def OnMouseDown(self, event):
width, height = self.GetSize()
self._pymol.button(self.button_map[event.GetButton()], 0,
event.GetX(), height - event.GetY(), 0)
self.PymolProcess()
event.Skip()
def OnMouseUp(self, event):
width, height = self.GetSize()
self._pymol.button(self.button_map[event.GetButton()], 1,
event.GetX(), height - event.GetY(), 0)
self.PymolProcess()
event.Skip()
def OnMouseWheel(self, event):
button = 4 if event.GetWheelRotation() > 0 else 3
self._pymol.button(button, 0, event.GetX(), event.GetY(), 0)
self.PymolProcess()
event.Skip()
def LoadMolFile(self, mol_file):
self._pymol.cmd.load(str(mol_file))
class PyMOLPanel(wx.Panel):
def __init__(self, parent, panel_id, name, enable_gui = False, *args,
**kwargs):
wx.Panel.__init__(self, parent, panel_id, *args, name = name,
**kwargs)
self._createLayout()
def _createLayout(self):
self.canvas = PyMOLCanvas(self)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.canvas, 1, wx.ALL | wx.GROW)
self.SetSizerAndFit(sizer)
if __name__ == '__main__':
app = wx.App()
frame = wx.Frame(None, -1, 'PyMol', wx.DefaultPosition,
wx.Size(400,400))
canvas = PyMOLCanvas(frame)
frame.Show()
app.MainLoop()
_______________________________________________
PyMOL-users mailing list
Archives: http://www.mail-archive.com/[email protected]
Unsubscribe:
https://sourceforge.net/projects/pymol/lists/pymol-users/unsubscribe