root / ase / gui / setupwindow.py @ 4
Historique | Voir | Annoter | Télécharger (2,05 ko)
| 1 |
# encoding: utf-8
|
|---|---|
| 2 |
"""setupwindow.py - Window base class for setup modules.
|
| 3 |
"""
|
| 4 |
|
| 5 |
import gtk |
| 6 |
from ase.gui.widgets import pack, cancel_apply_ok, oops |
| 7 |
import ase |
| 8 |
|
| 9 |
class SetupWindow(gtk.Window): |
| 10 |
"Base class for ase.gui setup windows."
|
| 11 |
# __init__ inherited from gtk.Window
|
| 12 |
|
| 13 |
def packtext(self, vbox, text, label=None): |
| 14 |
"Pack an text frame into the window."
|
| 15 |
pack(vbox, gtk.Label(""))
|
| 16 |
txtframe = gtk.Frame(label) |
| 17 |
txtlbl = gtk.Label(text) |
| 18 |
txtframe.add(txtlbl) |
| 19 |
txtlbl.show() |
| 20 |
pack(vbox, txtframe) |
| 21 |
pack(vbox, gtk.Label(""))
|
| 22 |
|
| 23 |
def update_element(self, *args): |
| 24 |
"Called when a new element may have been entered."
|
| 25 |
# Assumes the element widget is self.element and that a label
|
| 26 |
# to keep updated is self.elementinfo. The chemical symbol is
|
| 27 |
# placed in self.legalelement - or None if the element is
|
| 28 |
# invalid.
|
| 29 |
elem = self.element.get_text()
|
| 30 |
if not elem: |
| 31 |
self.invalid_element(" No element specified!") |
| 32 |
return False |
| 33 |
try:
|
| 34 |
z = int(elem)
|
| 35 |
except ValueError: |
| 36 |
# Probably a symbol
|
| 37 |
try:
|
| 38 |
z = ase.data.atomic_numbers[elem] |
| 39 |
except KeyError: |
| 40 |
self.invalid_element()
|
| 41 |
return False |
| 42 |
try:
|
| 43 |
symb = ase.data.chemical_symbols[z] |
| 44 |
except KeyError: |
| 45 |
self.invalid_element()
|
| 46 |
return False |
| 47 |
name = ase.data.atomic_names[z] |
| 48 |
ref = ase.data.reference_states[z] |
| 49 |
if ref is None: |
| 50 |
struct = "No crystal structure data"
|
| 51 |
else:
|
| 52 |
struct = ref['symmetry'].lower()
|
| 53 |
if struct == 'fcc' or struct == 'bcc': |
| 54 |
struct = "%s (a=%.3f Å)" % (struct, ref['a']) |
| 55 |
|
| 56 |
txt = " %s: %s, Z=%i, %s" % (name, symb, z, struct)
|
| 57 |
self.elementinfo.set_text(txt)
|
| 58 |
self.legal_element = symb
|
| 59 |
return True |
| 60 |
|
| 61 |
def invalid_element(self, txt=" ERROR: Invalid element!"): |
| 62 |
self.legal_element = False |
| 63 |
self.elementinfo.set_text(txt)
|
| 64 |
|