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): 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()