def open(self, button=None, filename=None): from ase.io.formats import all_formats, get_ioformat labels = [_('Automatic')] values = [''] def key(item): return item[1][0] for format, (description, code) in sorted(list(all_formats.items()), key=key): io = get_ioformat(format) if io.read and description != '?': labels.append(_(description)) values.append(format) format = [None] def callback(value): format[0] = value chooser = ui.LoadFileDialog(self.window.win, _('Open ...')) ui.Label(_('Choose parser:')).pack(chooser.top) formats = ui.ComboBox(labels, values, callback) formats.pack(chooser.top) filename = filename or chooser.go() if filename: self.images.read([filename], slice(None), format[0]) self.set_colors() self.set_coordinates(self.images.nimages - 1, focus=True)
def open(self, button=None, filename=None): from ase.io.formats import all_formats, get_ioformat labels = [_('Automatic')] values = [''] def key(item): return item[1][0] for format, (description, code) in sorted(all_formats.items(), key=key): io = get_ioformat(format) if io.read and description != '?': labels.append(_(description)) values.append(format) format = [None] def callback(value): format[0] = value chooser = ui.LoadFileDialog(self.window.win, _('Open ...')) ui.Label(_('Choose parser:')).pack(chooser.top) formats = ui.ComboBox(labels, values, callback) formats.pack(chooser.top) filename = filename or chooser.go() if filename: self.images.read([filename], slice(None), format[0]) self.set_frame(len(self.images) - 1, focus=True)
def open(self, button=None): from ase.io.formats import all_formats, get_ioformat formats = [(_('Automatic'), None)] def key(item): return item[1][0] for format, (description, code) in sorted(all_formats.items(), key=key): io = get_ioformat(format) if io.read and description != '?': formats.append((_(description), format)) chooser = gtk.FileChooserDialog( _('Open ...'), None, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) chooser.set_filename(_("<<filename>>")) # Add a file type filter name_to_format = {} types = gtk.combo_box_new_text() for name, format in formats: types.append_text(name) name_to_format[name] = format types.set_active(0) img_vbox = gtk.VBox() pack(img_vbox, [gtk.Label(_('File type:')), types]) img_vbox.show() chooser.set_extra_widget(img_vbox) ok = chooser.run() == gtk.RESPONSE_OK if ok: filenames = [chooser.get_filename()] filetype = types.get_active_text() chooser.destroy() if not ok: return self.reset_tools_modes() self.images.read(filenames, slice(None), name_to_format[filetype]) self.set_colors() self.set_coordinates(self.images.nimages - 1, focus=True)
def __init__(self, win, formatcallback=lambda event: None): from ase.io.formats import all_formats, get_ioformat LoadFileDialog.__init__(self, win, _('Open ...')) labels = [_('Automatic')] values = [''] def key(item): return item[1][0] for format, (description, code) in sorted(all_formats.items(), key=key): io = get_ioformat(format) if io.read and description != '?': labels.append(_(description)) values.append(format) self.format = None def callback(value): self.format = value Label(_('Choose parser:')).pack(self.top) formats = ComboBox(labels, values, callback) formats.pack(self.top)