File: rotate.py

package info (click to toggle)
python-ase 3.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 14,192 kB
  • ctags: 8,112
  • sloc: python: 93,375; sh: 99; makefile: 94
file content (46 lines) | stat: -rw-r--r-- 1,569 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import gtk
from gettext import gettext as _

from ase.gui.widgets import pack
from ase.utils import rotate, irotate


class Rotate(gtk.Window):
    update = True
    
    def __init__(self, gui):
        gtk.Window.__init__(self)
        angles = irotate(gui.axes)
        self.set_title(_('Rotate'))
        vbox = gtk.VBox()
        pack(vbox, gtk.Label(_('Rotation angles:')))
        self.rotate = [gtk.Adjustment(value=a, lower=-360, upper=360,
                                      step_incr=1, page_incr=10)
                       for a in angles]
        pack(vbox, [gtk.SpinButton(a, climb_rate=0, digits=1)
                    for a in self.rotate])
        for r in self.rotate:
            r.connect('value-changed', self.change)
        button = pack(vbox, gtk.Button(_('Update')))
        button.connect('clicked', self.update_angles)
        pack(vbox, gtk.Label(_('Note:\nYou can rotate freely\n'
                               'with the mouse, by holding\n'
                               'down mouse button 2.')))
        self.add(vbox)
        vbox.show()
        self.show()
        self.gui = gui

    def change(self, adjustment):
        if self.update:
            x, y, z = [float(a.value) for a in self.rotate]
            self.gui.axes = rotate('%fx,%fy,%fz' % (x, y, z))
            self.gui.set_coordinates()
        return True
        
    def update_angles(self, button):
        angles = irotate(self.gui.axes)
        self.update = False
        for r, a in zip(self.rotate, angles):
            r.value = a
        self.update = True