def pywindow(title, callback): code = callback() if code is None: ui.error( _('No Python code'), _('You have not (yet) specified a consistent set of parameters.')) else: win = ui.Window(title) win.add(ui.Text(code))
def save_dialog(gui, filename=None): dialog = ui.SaveFileDialog(gui.window.win, _('Save ...')) ui.Text(text).pack(dialog.top) filename = filename or dialog.go() if not filename: return filename, index = parse_filename(filename) if index is None: index = slice(gui.frame, gui.frame + 1) elif isinstance(index, basestring): index = string2index(index) elif isinstance(index, slice): pass else: if index < 0: index += len(gui.images) index = slice(index, index + 1) format = filetype(filename, read=False) io = get_ioformat(format) extra = {} remove_hidden = False if format in ['png', 'eps', 'pov']: bbox = np.empty(4) size = gui.window.size / gui.scale bbox[0:2] = np.dot(gui.center, gui.axes[:, :2]) - size / 2 bbox[2:] = bbox[:2] + size extra['rotation'] = gui.axes extra['show_unit_cell'] = gui.window['toggle-show-unit-cell'] extra['bbox'] = bbox colors = gui.get_colors(rgb=True) extra['colors'] = [ rgb for rgb, visible in zip(colors, gui.images.visible) if visible ] remove_hidden = True images = [ gui.images.get_atoms(i, remove_hidden=remove_hidden) for i in range(*index.indices(len(gui.images))) ] if len(images) > 1 and io.single: # We want to write multiple images, but the file format does not # support it. The solution is to write multiple files, inserting # a number in the file name before the suffix. j = filename.rfind('.') filename = filename[:j] + '{0:05d}' + filename[j:] for i, atoms in enumerate(images): write(filename.format(i), atoms, **extra) else: try: write(filename, images, **extra) except Exception as err: from ase.gui.ui import showerror showerror(_('Error'), err) raise
def __init__(self, gui): self.element = Element('', self.apply) self.structure = ui.ComboBox(structures, structures, self.structure_changed) self.structure_warn = ui.Label('', 'red') self.orthogonal = ui.CheckButton('', True, self.make) self.lattice_a = ui.SpinBox(3.2, 0.0, 10.0, 0.001, self.make) self.retrieve = ui.Button(_('Get from database'), self.structure_changed) self.lattice_c = ui.SpinBox(None, 0.0, 10.0, 0.001, self.make) self.x = ui.SpinBox(1, 1, 30, 1, self.make) self.x_warn = ui.Label('', 'red') self.y = ui.SpinBox(1, 1, 30, 1, self.make) self.y_warn = ui.Label('', 'red') self.z = ui.SpinBox(1, 1, 30, 1, self.make) self.vacuum_check = ui.CheckButton('', False, self.vacuum_checked) self.vacuum = ui.SpinBox(5, 0, 40, 0.01, self.make) self.description = ui.Label('') win = self.win = ui.Window(_('Surface')) win.add(ui.Text(introtext)) win.add(self.element) win.add([_('Structure:'), self.structure, self.structure_warn]) win.add([_('Orthogonal cell:'), self.orthogonal]) win.add([_('Lattice constant:')]) win.add([_('\ta'), self.lattice_a, (u'Å'), self.retrieve]) win.add([_('\tc'), self.lattice_c, (u'Å')]) win.add([_('Size:')]) win.add([_('\tx: '), self.x, _(' unit cells'), self.x_warn]) win.add([_('\ty: '), self.y, _(' unit cells'), self.y_warn]) win.add([_('\tz: '), self.z, _(' unit cells')]) win.add([_('Vacuum: '), self.vacuum_check, self.vacuum, (u'Å')]) win.add(self.description) # TRANSLATORS: This is a title of a window. win.add([ pybutton(_('Creating a surface.'), self.make), ui.Button(_('Apply'), self.apply), ui.Button(_('OK'), self.ok) ]) self.element.grab_focus() self.gui = gui self.atoms = None self.lattice_c.active = False self.vacuum.active = False self.structure_changed()
def __init__(self, gui): self.element = Element('C', self.make) self.bondlength = ui.SpinBox(1.42, 0.0, 10.0, 0.01, self.make) self.n = ui.SpinBox(5, 1, 100, 1, self.make) self.m = ui.SpinBox(5, 0, 100, 1, self.make) self.length = ui.SpinBox(1, 1, 100, 1, self.make) self.description = ui.Label('') win = self.win = ui.Window(_('Nanotube')) win.add(ui.Text(introtext)) win.add(self.element) win.add([_('Bond length: '), self.bondlength, _(u'Å')]) win.add(_('Select roll-up vector (n,m) and tube length:')) win.add(['n:', self.n, 'm:', self.m, _('Length:'), self.length]) win.add(self.description) win.add([ pybutton(_('Creating a nanoparticle.'), self.make), ui.Button(_('Apply'), self.apply), ui.Button(_('OK'), self.ok) ]) self.gui = gui self.atoms = None
def __init__(self, gui): self.atoms = None self.no_update = True self.old_structure = 'undefined' win = self.win = ui.Window(_('Nanoparticle')) win.add(ui.Text(introtext)) self.element = Element('', self.apply) lattice_button = ui.Button(_('Get structure'), self.set_structure_data) self.elementinfo = ui.Label(' ') win.add(self.element) win.add(self.elementinfo) win.add(lattice_button) # The structure and lattice constant labels = [] values = [] self.needs_4index = {} self.needs_2lat = {} self.factory = {} for abbrev, name, n4, c, factory in self.structure_data: labels.append(name) values.append(abbrev) self.needs_4index[abbrev] = n4 self.needs_2lat[abbrev] = c self.factory[abbrev] = factory self.structure = ui.ComboBox(labels, values, self.update_structure) win.add([_('Structure:'), self.structure]) self.fourindex = self.needs_4index[values[0]] self.a = ui.SpinBox(3.0, 0.0, 1000.0, 0.01, self.update) self.c = ui.SpinBox(3.0, 0.0, 1000.0, 0.01, self.update) win.add([_('Lattice constant: a ='), self.a, ' c =', self.c]) # Choose specification method self.method = ui.ComboBox( [_('Layer specification'), _('Wulff construction')], ['layers', 'wulff'], self.update_gui_method) win.add([_('Method: '), self.method]) self.layerlabel = ui.Label('Missing text') # Filled in later win.add(self.layerlabel) self.direction_table_rows = ui.Rows() win.add(self.direction_table_rows) self.default_direction_table() win.add(_('Add new direction:')) self.new_direction_and_size_rows = ui.Rows() win.add(self.new_direction_and_size_rows) self.update_new_direction_and_size_stuff() # Information win.add(_('Information about the created cluster:')) self.info = [ _('Number of atoms: '), ui.Label('-'), _(' Approx. diameter: '), ui.Label('-') ] win.add(self.info) # Finalize setup self.update_structure('fcc') self.update_gui_method() self.no_update = False self.auto = ui.CheckButton(_('Automatic Apply')) win.add(self.auto) win.add([ pybutton(_('Creating a nanoparticle.'), self.makeatoms), ui.helpbutton(helptext), ui.Button(_('Apply'), self.apply), ui.Button(_('OK'), self.ok) ]) self.gui = gui self.smaller_button = None self.largeer_button = None self.element.grab_focus()