Scripts: fov.py

File fov.py, 1.3 KB (added by goddard, 13 years ago)
Line 
1# Shortcuts to change the field of view.
2
3def increase_field_of_view(degrees = 1):
4 import chimera
5 k = chimera.viewer.camera
6 k.fieldOfView = max(1, min(179, k.fieldOfView + degrees))
7
8def decrease_field_of_view(degrees = -1):
9 increase_field_of_view(degrees)
10
11# Register shortcuts.
12from Accelerators import add_accelerator
13add_accelerator('f+', 'Increase field of view by 1 degree',
14 increase_field_of_view)
15add_accelerator('f-', 'Decrease field of view by 1 degree',
16 decrease_field_of_view)
17
18# Mouse mode
19class AdjustFieldOfView:
20
21 def __init__(self):
22 self.last_xy = None
23 callbacks = (self.mouse_down_cb, self.mouse_drag_cb, self.mouse_up_cb)
24 icon = None
25 from chimera import mousemodes
26 mousemodes.addFunction('Field of View', callbacks, icon)
27
28 def mouse_down_cb(self, viewer, event):
29 self.last_xy = (event.x, event.y)
30
31 def mouse_drag_cb(self, viewer, event):
32 if self.last_xy:
33 dy = event.y - self.last_xy[1]
34 self.last_xy = (event.x, event.y)
35 increase_field_of_view(dy/5)
36
37 def mouse_up_cb(self, viewer, event):
38 self.last_xy = None
39
40# Make ctrl-right-mouse adjust field of view
41afov = AdjustFieldOfView()
42from chimera import mousemodes
43mousemodes.setButtonFunction('3', ['Ctrl'], 'Field of View')