Shows how to write a tool in Python, register it and interact with the graphical objects in the scene.
2 This script illustrates how to implement a custom tool for interacting with the
8 class ColorTool(gui.Tool):
10 gui.Tool.__init__(self,
"Color Tool")
11 self.tool_options.AddOption(gui.ToolOptionFloat(
"r", "Red", 0.5, 0.0, 1.0))
12 self.tool_options.AddOption(gui.ToolOptionFloat(
"g",
"Green", 0.5, 0.0, 1.0))
13 self.tool_options.AddOption(gui.ToolOptionFloat(
"b",
"Blue", 0.5, 0.0, 1.0))
14 apply_to=gui.ToolOptionEnum(
"apply_to",
"Apply To")
15 apply_to.Add(
"Atom", 0)
16 apply_to.Add(
"Residue", 1)
17 apply_to.Add(
"Chain", 2)
19 self.tool_options.AddOption(apply_to)
22 return gfx.Color(self.tool_options.GetOption(
'r').value,
23 self.tool_options.GetOption('g').value,
24 self.tool_options.GetOption(
'b').value)
26 def CanOperateOn(self, obj):
28 def GetIconPath(self):
30 def GetAtomsToColor(self, atom):
31 apply_to=self.tool_options.GetOption(
'apply_to').value
35 return atom.residue.atoms
38 for r
in atom.residue.chain.residues:
43 def Click(self, event):
44 obj, atom=gfx.PickAtom(scene, event.pos.x(), event.pos.y())
46 atoms=self.GetAtomsToColor(atom)
49 obj.SetColorForAtom(color, atom.handle)
51 color_tool=ColorTool()
53 gui.ToolManager.Instance().AddTool(color_tool)
55 e=io.LoadEntity(len(sys.argv)>1
and sys.argv[1]
or '../entity/fragment.pdb')
57 g.SetRenderMode(gfx.RenderMode.CUSTOM)