def window(): def hello(event=None): print('hello', event) menu = [('Hi', [ui.MenuItem('_Hello', hello, 'Ctrl+H')]), ('Hell_o', [ui.MenuItem('ABC', hello, choices='ABC')])] win = ui.MainWindow('Test', menu=menu) win.add(ui.Label('Hello')) win.add(ui.Button('Hello', hello)) r = ui.Rows([ui.Label(x * 7) for x in 'abcd']) win.add(r) r.add('11111\n2222\n333\n44\n5') def abc(x): print(x, r.rows) cb = ui.ComboBox(['Aa', 'Bb', 'Cc'], callback=abc) win.add(cb) rb = ui.RadioButtons(['A', 'B', 'C'], 'ABC', abc) win.add(rb) b = ui.CheckButton('Hello') def hi(): print(b.value, rb.value, cb.value) del r[2] r.add('-------------') win.add([b, ui.Button('Hi', hi)]) return win
def __init__(self, gui): win = ui.Window(_('Constraints')) win.add([ui.Button(_('Fix'), self.selected), _('selected atoms')]) win.add( [ui.Button(_('Release'), self.unconstrain), _('selected atoms')]) win.add(ui.Button(_('Clear all constraints'), self.clear)) self.gui = gui
def __init__(self, gui): ui.Window.__init__(self) self.gui = gui self.set_title(_('Expert user mode')) vbox = ui.VBox() vbox.set_border_width(5) self.sw = ui.ScrolledWindow() self.sw.set_policy(ui.POLICY_AUTOMATIC, ui.POLICY_AUTOMATIC) self.textview = ui.TextView() self.textbuffer = self.textview.get_buffer() self.textview.set_editable(False) self.textview.set_cursor_visible(False) self.sw.add(self.textview) pack(vbox, self.sw, expand=True, padding=5) self.sw.set_size_request(540, 150) self.textview.show() self.add_text(_('Welcome to the ASE Expert user mode')) self.cmd = ui.Entry(60) self.cmd.connect('activate', self.execute) self.cmd.connect('key-press-event', self.update_command_buffer) pack(vbox, [ui.Label('>>>'), self.cmd]) self.cmd_buffer = getattr(gui, 'expert_mode_buffer', ['']) self.cmd_position = len(self.cmd_buffer) - 1 self.selected = ui.CheckButton(_('Only selected atoms (sa) ')) self.selected.connect('toggled', self.selected_changed) self.images_only = ui.CheckButton(_('Only current frame (cf) ')) self.images_only.connect('toggled', self.images_changed) pack(vbox, [self.selected, self.images_only]) save_button = ui.Button(_('Save')) save_button.connect('clicked', self.save_output) help_button = ui.Button(_('Help')) help_button.connect('clicked', self.terminal_help, "") stop_button = ui.Button(_('Stop')) stop_button.connect('clicked', self.stop_execution) self.stop = False pack(vbox, [ ui.Label( _('Global: Use A, D, E, M, N, R, S, n, frame;' ' Atoms: Use a, f, m, s, x, y, z, Z ')), stop_button, help_button, save_button ], end=True) self.add(vbox) vbox.show() self.show() # set color mode to manual when opening this window for rgb # manipulation self.colors = self.gui.get_colors() rgb_data = self.gui.get_colors(rgb=True) self.rgb_data = [] # ensure proper format of rgb_data for i, rgb in enumerate(rgb_data): self.rgb_data += [[i, rgb]] self.gui.colordata = self.rgb_data self.gui.colors = list(self.colors) self.gui.colormode = 'manual' self.cmd.grab_focus()
def __init__(self, gui): win = ui.Window(_('Constraints')) win.add([ui.Button(_('Constrain'), self.selected), _('selected atoms')]) win.add([ui.Button(_('Constrain'), self.immobile), _('immobile atoms')]) win.add([ui.Button(_('Unconstrain'), self.unconstrain), _('selected atoms')]) win.add(ui.Button(_('Clear constraints'), self.clear)) self.gui = gui
def update_new_direction_and_size_stuff(self): if self.needs_4index[self.structure.value]: n = 4 else: n = 3 rows = self.new_direction_and_size_rows rows.clear() self.new_direction = row = ['('] for i in range(n): if i > 0: row.append(',') row.append(ui.SpinBox(0, -100, 100, 1)) row.append('):') if self.method.value == 'wulff': row.append(ui.SpinBox(1.0, 0.0, 1000.0, 0.1)) else: row.append(ui.SpinBox(5, 1, 100, 1)) row.append(ui.Button(_('Add'), self.row_add)) rows.add(row) if self.method.value == 'wulff': # Extra widgets for the Wulff construction self.size_radio = ui.RadioButtons( [_('Number of atoms'), _('Diameter')], ['natoms', 'diameter'], self.update_gui_size) self.size_natoms = ui.SpinBox(100, 1, 100000, 1, self.update_size_natoms) self.size_diameter = ui.SpinBox(5.0, 0, 100.0, 0.1, self.update_size_diameter) self.round_radio = ui.RadioButtons( [_('above '), _('below '), _('closest ')], ['above', 'below', 'closest'], callback=self.update) self.smaller_button = ui.Button(_('Smaller'), self.wulff_smaller) self.larger_button = ui.Button(_('Larger'), self.wulff_larger) rows.add(_('Choose size using:')) rows.add(self.size_radio) rows.add( [_('atoms'), self.size_natoms, _(u'ų'), self.size_diameter]) rows.add( _('Rounding: If exact size is not possible, choose the size:')) rows.add(self.round_radio) rows.add([self.smaller_button, self.larger_button]) self.update_gui_size() else: self.smaller_button = None self.larger_button = None
def __init__(self, gui): win = ui.Window('Graphs') self.expr = ui.Entry('', 50, self.plot) win.add([self.expr, ui.helpbutton(graph_help_text)]) win.add([ui.Button(_('Plot'), self.plot, 'xy'), ' x, y1, y2, ...'], 'w') win.add([ui.Button(_('Plot'), self.plot, 'y'), ' y1, y2, ...'], 'w') win.add([ui.Button(_('Save'), self.save)], 'w') self.gui = gui
def __init__(self, gui): self.gui = gui win = self.win = ui.Window(_('Add atoms')) win.add(_('Specify chemical symbol, formula, or filename.')) def choose_file(): chooser = ui.ASEFileChooser(self.win.win) filename = chooser.go() if filename is None: # No file selected return self.combobox.value = filename # Load the file immediately, so we can warn now in case of error self.readfile(filename, format=chooser.format) if self.gui.images.selected.any(): default = current_selection_string else: default = 'H2' self._filename = None self._atoms_from_file = None from ase.collections import g2 labels = list(sorted(name for name in g2.names if len(g2[name]) > 1)) values = labels combobox = ui.ComboBox(labels, values) win.add([ _('Add:'), combobox, ui.Button(_('File ...'), callback=choose_file) ]) combobox.widget.bind('<Return>', lambda e: self.add()) combobox.value = default self.combobox = combobox spinners = [ ui.SpinBox(0.0, -1e3, 1e3, 0.1, rounding=2, width=3) for __ in range(3) ] win.add([_('Coordinates:')] + spinners) self.spinners = spinners win.add( _('Coordinates are relative to the center of the selection, ' 'if any, else absolute.')) self.picky = ui.CheckButton(_('Check positions'), True) win.add([ui.Button(_('Add'), self.add), self.picky]) self.focus()
def __init__(self, gui): # XXXXXXXXXXX still array based, not Atoms-based. Will crash win = ui.Window(_('Add atoms')) self.element = Element() win.add(self.element) self.absolute_position = ui.Entry('0,0,0') self.relative_position = ui.Entry('1.5,0,0') win.add([_('Absolute position:'), self.absolute_position, ui.Button(_('Add'), self.add_absolute)]) win.add([_('Relative to average position (of selection):'), self.relative_position, ui.Button(_('Add'), self.add_relative)]) self.gui = gui
def __init__(self, gui): self.gui = gui win = self.win = ui.Window(_('Add atoms')) win.add(_('Specify chemical symbol, formula, or filename.')) def set_molecule(value): self.entry.value = value self.focus() def choose_file(): chooser = ui.ASEFileChooser(self.win.win) filename = chooser.go() if filename is None: # No file selected return self.entry.value = filename # Load the file immediately, so we can warn now in case of error self.readfile(filename, format=chooser.format) self.entry = ui.Entry('', callback=self.add) win.add([ _('Add:'), self.entry, ui.Button(_('File ...'), callback=choose_file) ]) self._filename = None self._atoms_from_file = None from ase.collections import g2 labels = list(sorted(g2.names)) values = labels box = ui.ComboBox(labels, values, callback=set_molecule) win.add([_('Get molecule:'), box]) box.value = 'H2' spinners = [ ui.SpinBox(0.0, -1e3, 1e3, 0.1, rounding=2, width=3) for __ in range(3) ] win.add([_('Coordinates:')] + spinners) self.spinners = spinners win.add( _('Coordinates are relative to the center of the selection, ' 'if any, else absolute.')) self.picky = ui.CheckButton(_('Check positions'), True) win.add([ui.Button(_('Add'), self.add), self.picky]) self.focus()
def makebutbox(self, vbox, helptext=None): self.buttons = ui.HButtonBox() runbut = ui.Button(_("Run")) runbut.connect('clicked', self.run) closebut = ui.Button('Close') closebut.connect('clicked', lambda x: self.destroy()) for w in (runbut, closebut): self.buttons.pack_start(w, 0, 0) w.show() if helptext: helpbut = [help(helptext)] else: helpbut = [] pack(vbox, helpbut + [self.buttons], end=True, bottom=True)
def __init__(self, gui): self.gui = gui selected = self.selection() if not selected.any(): ui.error(_('No atoms selected!')) return win = ui.Window(_('Modify')) element = Element(callback=self.set_element) win.add(element) win.add( ui.Button(_('Change element'), partial(self.set_element, element))) self.tag = ui.SpinBox(0, -1000, 1000, 1, self.set_tag) win.add([_('Tag'), self.tag]) self.magmom = ui.SpinBox(0.0, -10, 10, 0.1, self.set_magmom) win.add([_('Moment'), self.magmom]) atoms = self.gui.atoms Z = atoms.numbers if Z.ptp() == 0: element.Z = Z[0] tags = atoms.get_tags()[selected] if tags.ptp() == 0: self.tag.value = tags[0] magmoms = get_magmoms(atoms)[selected] if magmoms.round(2).ptp() == 0.0: self.magmom.value = round(magmoms[0], 2)
def pybutton(title, callback): """A button for displaying Python code. When pressed, it opens a window displaying some Python code, or an error message if no Python code is ready. """ return ui.Button('Python', pywindow, title, callback)
def __init__(self): ui.Window.__init__(self) self.set_title(_("Progress")) self.globalbox = ui.VBox() self.nextupdate = 0 self.fmax_max = 1.0 # Scaling deformation progress frame self.scalebox = ui.VBox() self.scaleframe = ui.Frame(_("Scaling deformation:")) vbox = ui.VBox() self.scaleframe.add(vbox) pack(self.scalebox, [self.scaleframe]) pack(self.scalebox, ui.Label("")) self.label_scale_stepno_format = _("Step number %s of %s.") self.label_scale_stepno = ui.Label(self.label_scale_stepno_format % ("-", "-")) pack(vbox, [self.label_scale_stepno]) self.scale_progress = ui.ProgressBar() self.scale_progress.modify_bg(ui.STATE_PRELIGHT, '#00AA00') pack(vbox, [self.scale_progress]) vbox.show() self.scaleframe.show() self.globalbox.pack_start(self.scalebox) # Minimization progress frame self.minbox = ui.VBox() # Box containing frame and spacing self.minframe = ui.Frame(_("Energy minimization:")) vbox = ui.VBox() # Box containing the frames content. self.minframe.add(vbox) pack(self.minbox, [self.minframe]) pack(self.minbox, ui.Label("")) self.label_min_stepno = ui.Label("-") pack(vbox, [ui.Label(_("Step number: ")), self.label_min_stepno]) lbl = ui.Label() lbl.set_markup(_("F<sub>max</sub>: ")) self.minimize_progress = ui.ProgressBar() pack(vbox, [lbl, self.minimize_progress]) self.label_min_fmax = ui.Label("-") lbl = ui.Label() lbl.set_markup(_("Convergence criterion: F<sub>max</sub> = ")) pack(vbox, [lbl, self.label_min_fmax]) self.label_min_maxsteps = ui.Label("-") pack(vbox, [ui.Label(_("Max. number of steps: ")), self.label_min_maxsteps]) vbox.show() self.minframe.show() self.globalbox.pack_start(self.minbox) self.globalbox.show() self.add(self.globalbox) # Make the cancel button self.cancelbut = ui.Button('Cancel') self.cancelbut.connect('clicked', self.cancel) pack(self.globalbox, [self.cancelbut], end=True, bottom=True)
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, symbol='', callback=None): list.__init__(self, [ _('Element:'), ui.Entry(symbol, 3, self.enter), ui.Button(_('Help'), self.show_help), ui.Label('', 'red') ]) self.callback = callback
def __init__(self, gui): self.gui = gui win = ui.Window(_('Settings')) # Constraints win.add(_('Constraints:')) win.add([ ui.Button(_('Constrain'), self.constrain_selected), '/', ui.Button(_('release'), self.release_selected), _(' selected atoms') ]) win.add(ui.Button(_('Constrain immobile atoms'), self.immobile)) win.add(ui.Button(_('Clear all constraints'), self.clear_constraints)) # Visibility win.add(_('Visibility:')) win.add([ ui.Button(_('Hide'), self.hide_selected), '/', ui.Button(_('show'), self.show_selected), _(' selected atoms') ]) win.add(ui.Button(_('View all atoms'), self.view_all)) # Miscellaneous win.add(_('Miscellaneous:')) self.scale = ui.SpinBox(self.gui.images.atom_scale, 0.2, 2.0, 0.1, self.scale_radii) win.add([_('Scale atomic radii:'), self.scale])
def __init__(self, symbol='', callback=None, allow_molecule=False): list.__init__(self, [ _('Element:'), ui.Entry(symbol, 10 if allow_molecule else 3, self.enter), ui.Button(_('Help'), self.show_help), ui.Label('', 'red') ]) self.callback = callback self.allow_molecule = allow_molecule
def __init__(self, gui): self.gui = gui self.win = win = ui.Window(_('Render current view in povray ... ')) win.add(ui.Label(_("Rendering %d atoms.") % len(self.gui.atoms))) guiwidth, guiheight = self.get_guisize() self.width_widget = ui.SpinBox(guiwidth, start=1, end=9999, step=1) self.height_widget = ui.SpinBox(guiheight, start=1, end=9999, step=1) win.add([ui.Label(_('Size')), self.width_widget, ui.Label('⨯'), self.height_widget]) self.linewidth_widget = ui.SpinBox(0.07, start=0.01, end=9.99, step=0.01) win.add([ui.Label(_('Line width')), self.linewidth_widget, ui.Label(_('Ångström'))]) self.constraints_widget = ui.CheckButton(_("Render constraints")) self.cell_widget = ui.CheckButton(_("Render unit cell"), value=True) win.add([self.cell_widget, self.constraints_widget]) formula = gui.atoms.get_chemical_formula(mode='hill') self.basename_widget = ui.Entry(width=30, value=formula, callback=self.update_outputname) win.add([ui.Label(_('Output basename: ')), self.basename_widget]) self.povray_executable = ui.Entry(width=30,value='povray') win.add([ui.Label(_('POVRAY executable')), self.povray_executable]) self.outputname_widget = ui.Label() win.add([ui.Label(_('Output filename: ')), self.outputname_widget]) self.update_outputname() self.texture_widget = ui.ComboBox(labels=self.texture_list, values=self.texture_list) win.add([ui.Label(_('Atomic texture set:')), self.texture_widget]) # complicated texture stuff self.camera_widget = ui.ComboBox(labels=self.cameras, values=self.cameras) self.camera_distance_widget = ui.SpinBox(50.0, -99.0, 99.0, 1.0) win.add([ui.Label(_('Camera type: ')), self.camera_widget]) win.add([ui.Label(_('Camera distance')), self.camera_distance_widget]) # render current frame/all frames self.frames_widget = ui.RadioButtons([_('Render current frame'), _('Render all frames')]) win.add(self.frames_widget) if len(gui.images) == 1: self.frames_widget.buttons[1].widget.configure(state='disabled') self.run_povray_widget = ui.CheckButton(_('Run povray'), True) self.keep_files_widget = ui.CheckButton(_('Keep povray files'), False) self.show_output_widget = ui.CheckButton(_('Show output window'), True) self.transparent = ui.CheckButton(_("Transparent background"), True) win.add(self.transparent) win.add([self.run_povray_widget, self.keep_files_widget, self.show_output_widget]) win.add(ui.Button(_('Render'), self.ok))
def __init__(self, gui): self.gui = gui win = ui.Window(_('Rotate')) win.add(_('Rotation angles:')) self.rotate = [ui.SpinBox(42.0, -360, 360, 1, self.change) for i in '123'] win.add(self.rotate) win.add(ui.Button(_('Update'), self.update_angles)) win.add(_('Note:\nYou can rotate freely\n' 'with the mouse, by holding\n' 'down mouse button 2.')) self.update_angles()
def __init__(self, gui): self.gui = gui self.gui.register_vulnerable(self) # Create grid control for cells # xx xy xz ||x|| pbc # yx yy yz ||y|| pbc # zx zy zz ||z|| pbc self.cell_grid = [] self.pbc = [] self.angles = [] atoms = self.gui.atoms cell = atoms.cell mags = cell.lengths() angles = cell.angles() pbc = atoms.pbc for i in [0, 1, 2]: # x_ y_ z_ row = [] for j in [0, 1, 2]: # _x _y _z row.append(ui.SpinBox(cell[i][j], -30, 30, 0.1, self.apply_vectors, rounding=7, width=9)) row.append(ui.SpinBox(mags[i], -30, 30, 0.1, self.apply_magnitudes, rounding=7, width=9)) self.cell_grid.append(row) self.pbc.append(ui.CheckButton('', bool(pbc[i]), self.apply_pbc)) self.angles.append(ui.SpinBox(angles[i], -360, 360, 15, self.apply_angles, rounding=7, width=9)) self.scale_atoms = ui.CheckButton('', False) self.vacuum = ui.SpinBox(5, 0, 15, 0.1, self.apply_vacuum) # TRANSLATORS: This is a title of a window. win = self.win = ui.Window(_('Cell Editor')) x, y, z = self.cell_grid win.add([_('A:'), x[0], x[1], x[2], _('||A||:'), x[3], _('periodic:'), self.pbc[0]]) win.add([_('B:'), y[0], y[1], y[2], _('||B||:'), y[3], _('periodic:'), self.pbc[1]]) win.add([_('C:'), z[0], z[1], z[2], _('||C||:'), z[3], _('periodic:'), self.pbc[2]]) win.add([_('∠BC:'), self.angles[0], _('∠AC:'), self.angles[1], _('∠AB:'), self.angles[2]]) win.add([_('Scale atoms with cell:'), self.scale_atoms]) win.add([ui.Button(_('Apply Vectors'), self.apply_vectors), ui.Button(_('Apply Magnitudes'), self.apply_magnitudes), ui.Button(_('Apply Angles'), self.apply_angles)]) win.add([_('Pressing 〈Enter〉 as you enter values will ' 'automatically apply correctly')]) # TRANSLATORS: verb win.add([ui.Button(_('Center'), self.apply_center), ui.Button(_('Wrap'), self.apply_wrap), _('Vacuum:'), self.vacuum, ui.Button(_('Apply Vacuum'), self.apply_vacuum)])
def __init__(self, gui): win = ui.Window(_('Repeat')) win.add(_('Repeat atoms:')) self.repeat = [ui.SpinBox(r, 1, 9, 1, self.change) for r in gui.images.repeat] win.add(self.repeat) win.add(ui.Button(_('Set unit cell'), self.set_unit_cell)) for sb, vec in zip(self.repeat, gui.atoms.cell): if not vec.any(): sb.active = False self.gui = gui
def add_direction(self, direction, layers, energy): i = len(self.direction_table_rows) if self.method.value == 'wulff': spin = ui.SpinBox(energy, 0.0, 1000.0, 0.1, self.update) else: spin = ui.SpinBox(layers, 1, 100, 1, self.update) up = ui.Button(_('Up'), self.row_swap_next, i - 1) down = ui.Button(_('Down'), self.row_swap_next, i) delete = ui.Button(_('Delete'), self.row_delete, i) self.direction_table_rows.add( [str(direction) + ':', spin, up, down, delete]) up.active = i > 0 down.active = False delete.active = i > 0 if i > 0: down, delete = self.direction_table_rows[-2][3:] down.active = True delete.active = True
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 add_basis_atom(self, *args): """ add an atom to the customizable basis """ n = len(self.elements) self.elements += [[ ui.Entry(max=3), ui.Entry(max=8), ui.Entry(max=8), ui.Entry(max=8), ui.Label('\t\t\t'), ui.Label('\tx: '), ui.Label(' y: '), ui.Label(' z: '), ui.Label(' '), ui.Button('Delete'), True ]] self.elements[n][-2].connect("clicked", self.delete_basis_atom, {'n': n}) pack(self.vbox_basis, [ self.elements[n][4], self.elements[n][0], self.elements[n][5], self.elements[n][1], self.elements[n][6], self.elements[n][2], self.elements[n][7], self.elements[n][3], self.elements[n][8], self.elements[n][9] ]) self.update()
def material_from_selection(self, *args): box_selection = self.get_selection() selection = self.gui.images.selected.copy() if selection.any(): Z = [] for n in range(len(selection)): if selection[n]: Z += [self.gui.atoms.Z[n]] name = formula(Z) if (box_selection == selection).all(): name += ': ' + self.texture_selection.get_text() texture_button = ui.combo_box_new_text() for t in self.finish_list: texture_button.append_text(t) texture_button.set_active(1) transparency = ui.Adjustment(0, 0.0, 1.0, 0.01) transparency_spin = ui.SpinButton(transparency, 0, 0) transparency_spin.set_digits(2) delete_button = ui.Button('Delete') index = len(self.materials) delete_button.connect("clicked", self.delete_material, {"n": index}) self.materials += [[ True, selection, texture_button, ui.Label(_(" transparency: ")), transparency_spin, ui.Label(" "), delete_button, ui.Label() ]] self.materials[-1][-1].set_markup(" " + name) pack(self.tbox, [ self.materials[-1][2], self.materials[-1][3], self.materials[-1][4], self.materials[-1][5], self.materials[-1][6], self.materials[-1][7] ]) else: error( _('Can not create new texture! Must have some atoms selected ' 'to create a new material!'))
def makeoutputfield(self, box, label=_("Output:"), heading=None): frame = ui.Frame(label) if box is not None: box.pack_start(frame, True, True, 0) box2 = ui.VBox() frame.add(box2) if heading is not None: pack(box2, [ui.Label(heading)]) scrwin = ui.ScrolledWindow() scrwin.set_policy(ui.POLICY_AUTOMATIC, ui.POLICY_AUTOMATIC) self.output = ui.TextBuffer() txtview = ui.TextView(self.output) txtview.set_editable(False) scrwin.add(txtview) scrwin.show_all() box2.pack_start(scrwin, True, True, 0) self.savebutton = ui.Button('Save') self.savebutton.connect('clicked', self.saveoutput) self.savebutton.set_sensitive(False) pack(box2, [self.savebutton]) box2.show() frame.show() return frame
def __init__(self, gui): self.win = win = ui.Window(_('Movie'), self.close) win.add(_('Image number:')) self.frame_number = ui.Scale(gui.frame + 1, 1, len(gui.images), callback=self.new_frame) win.add(self.frame_number) win.add([ ui.Button(_('First'), self.click, -1, True), ui.Button(_('Back'), self.click, -1), ui.Button(_('Forward'), self.click, 1), ui.Button(_('Last'), self.click, 1, True) ]) play = ui.Button(_('Play'), self.play) stop = ui.Button(_('Stop'), self.stop) # TRANSLATORS: This function plays an animation forwards and backwards # alternatingly, e.g. for displaying vibrational movement self.rock = ui.CheckButton(_('Rock')) win.add([play, stop, self.rock]) if len(gui.images) > 150: skipdefault = len(gui.images) // 150 tdefault = min(max(len(gui.images) / (skipdefault * 5.0), 1.0), 30) else: skipdefault = 0 tdefault = min(max(len(gui.images) / 5.0, 1.0), 30) self.time = ui.SpinBox(tdefault, 1.0, 99, 0.1) self.skip = ui.SpinBox(skipdefault, 0, 99, 1) win.add( [_(' Frame rate: '), self.time, _(' Skip frames: '), self.skip]) self.gui = gui self.direction = 1 self.timer = None gui.register_vulnerable(self)
def __init__(self, gui): self.gui = gui win = ui.Window(_('Settings')) # Constraints win.add(_('Constraints:')) win.add([ui.Button(_('Fix'), self.constrain_selected), '/', ui.Button(_('release'), self.release_selected), _(' selected atoms')]) win.add(ui.Button(_('Clear all constraints'), self.clear_constraints)) # Visibility win.add(_('Visibility:')) win.add([ui.Button(_('Hide'), self.hide_selected), '/', ui.Button(_('show'), self.show_selected), _(' selected atoms')]) win.add(ui.Button(_('View all atoms'), self.view_all)) # Miscellaneous win.add(_('Miscellaneous:')) self.scale = ui.SpinBox(self.gui.images.atom_scale, 0.2, 2.0, 0.1, self.scale_radii) win.add([_('Scale atomic radii:'), self.scale]) self.force_vector_scale = ui.SpinBox( self.gui.force_vector_scale, 0.0, 1e32, 0.1, rounding=2, callback=self.scale_force_vectors ) win.add([_('Scale force vectors:'), self.force_vector_scale]) self.velocity_vector_scale = ui.SpinBox( self.gui.velocity_vector_scale, 0.0, 1e32, 0.1, rounding=2, callback=self.scale_velocity_vectors ) win.add([_('Scale velocity vectors:'), self.velocity_vector_scale])
def __init__(self, gui): self.gui = gui ui.Window.__init__(self) self.set_title(_('Render current view in povray ... ')) vbox = ui.VBox() vbox.set_border_width(5) self.natoms = len(self.gui.atoms) pack(vbox, [ui.Label(_("Rendering %d atoms.") % self.natoms)]) self.size = [ ui.Adjustment(self.gui.width, 1, 9999, 50), ui.Adjustment(self.gui.height, 1, 9999, 50) ] self.width = ui.SpinButton(self.size[0], 0, 0) self.height = ui.SpinButton(self.size[1], 0, 0) self.render_constraints = ui.CheckButton(_("Render constraints")) self.render_constraints.set_sensitive( not self.gui.images.get_dynamic(self.gui.atoms).all()) self.render_constraints.connect("toggled", self.toggle_render_lines) pack(vbox, [ ui.Label(_("Width")), self.width, ui.Label(_(" Height")), self.height, ui.Label(" "), self.render_constraints ]) self.width.connect('value-changed', self.change_width, "") self.height.connect('value-changed', self.change_height, "") self.sizeratio = gui.width / float(gui.height) self.line_width = ui.SpinButton(ui.Adjustment(0.07, 0.01, 9.99, 0.01), 0, 0) self.line_width.set_digits(3) self.render_cell = ui.CheckButton(_("Render unit cell")) if self.gui.ui.get_widget( '/MenuBar/ViewMenu/ShowUnitCell').get_active(): self.render_cell.set_active(True) else: self.render_cell.set_active(False) self.render_cell.set_sensitive(False) self.render_cell.connect("toggled", self.toggle_render_lines) have_lines = (not self.gui.images.dynamic.all() ) or self.render_cell.get_active() self.line_width.set_sensitive(have_lines) pack(vbox, [ ui.Label(_("Line width")), self.line_width, ui.Label(_("Angstrom ")), self.render_cell ]) pack(vbox, [ui.Label("")]) filename = gui.window.get_title() len_suffix = len(filename.split('.')[-1]) + 1 if len(filename) > len_suffix: filename = filename[:-len_suffix] self.basename = ui.Entry(max=30) self.basename.connect("activate", self.set_outputname, "") self.basename.set_text(basename(filename)) set_name = ui.Button(_("Set")) set_name.connect("clicked", self.set_outputname, "") pack(vbox, [ui.Label(_("Output basename: ")), self.basename, set_name]) self.outputname = ui.Label("") pack(vbox, [ui.Label(_(" Filename: ")), self.outputname]) pack(vbox, [ui.Label("")]) self.tbox = ui.VBox() self.tbox.set_border_width(10) self.default_texture = ui.combo_box_new_text() for t in self.finish_list: self.default_texture.append_text(t) self.default_texture.set_active(1) self.default_transparency = ui.Adjustment(0, 0.0, 1.0, 0.01) self.transparency = ui.SpinButton(self.default_transparency, 0, 0) self.transparency.set_digits(2) pack(self.tbox, [ ui.Label(_(" Default texture for atoms: ")), self.default_texture, ui.Label(_(" transparency: ")), self.transparency ]) pack(self.tbox, [ui.Label(_("Define atom selection for new texture:"))]) self.texture_selection = ui.Entry(max=50) self.texture_select_but = ui.Button(_("Select")) self.texture_selection.connect("activate", self.select_texture, "") self.texture_select_but.connect("clicked", self.select_texture, "") pack(self.tbox, [self.texture_selection, self.texture_select_but]) self.create_texture = ui.Button(_("Create new texture from selection")) self.create_texture.connect("clicked", self.material_from_selection, "") self.selection_help_but = ui.Button(_("Help on textures")) self.selection_help_but.connect("clicked", self.selection_help, "") self.materials = [] pack(self.tbox, [ self.create_texture, ui.Label(" "), self.selection_help_but ]) pack(vbox, [self.tbox]) pack(vbox, [ui.Label("")]) self.camera_style = ui.combo_box_new_text() for c in self.cameras: self.camera_style.append_text(c) self.camera_style.set_active(0) self.camera_distance = ui.SpinButton( ui.Adjustment(50.0, -99.0, 99.0, 1.0), 0, 0) self.camera_distance.set_digits(1) pack(vbox, [ ui.Label(_("Camera type: ")), self.camera_style, ui.Label(_(" Camera distance")), self.camera_distance ]) self.single_frame = ui.RadioButton(None, _("Render current frame")) self.nimages = len(self.gui.images) self.iframe = self.gui.frame self.movie = ui.RadioButton(self.single_frame, _("Render all %d frames") % self.nimages) self.movie.connect("toggled", self.set_movie) self.movie.set_sensitive(self.nimages > 1) self.set_outputname() pack(vbox, [self.single_frame, ui.Label(" "), self.movie]) self.transparent = ui.CheckButton(_("Transparent background")) self.transparent.set_active(True) pack(vbox, [self.transparent]) self.run_povray = ui.CheckButton(_("Run povray ")) self.run_povray.set_active(True) self.run_povray.connect("toggled", self.toggle_run_povray, "") self.keep_files = ui.CheckButton(_("Keep povray files ")) self.keep_files.set_active(False) self.keep_files_status = True self.window_open = ui.CheckButton(_("Show output window")) self.window_open.set_active(True) self.window_open_status = True pack(vbox, [self.run_povray, self.keep_files, self.window_open]) pack(vbox, [ui.Label("")]) cancel_but = ui.Button('Cancel') cancel_but.connect('clicked', lambda widget: self.destroy()) ok_but = ui.Button('OK') ok_but.connect('clicked', self.ok) close_but = ui.Button('Close') close_but.connect('clicked', lambda widget: self.destroy()) butbox = ui.HButtonBox() butbox.pack_start(cancel_but, 0, 0) butbox.pack_start(ok_but, 0, 0) butbox.pack_start(close_but, 0, 0) butbox.show_all() pack(vbox, [butbox], end=True, bottom=True) self.add(vbox) vbox.show() self.show()
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()