def update_encoder_options(): encoder = form.input_encoder.currentText() for fmt, enabled in support[encoder].items(): w = getattr(form, 'format_' + fmt) w.setEnabled(enabled) if not enabled and w.isChecked(): if encoder == 'mpeg_encode': form.format_mpg.setChecked(True) elif encoder == 'convert': form.format_gif.setChecked(True) else: form.format_png.setChecked(True) form.input_quality.setEnabled(encoder not in ("", "convert")) if encoder and not has_exe(encoder): msg = "Encoder '%s' is not installed." % encoder pkg = None url = None if not pkg: QtWidgets.QMessageBox.warning(parent, "Warning", msg) else: from pymol.Qt import utils utils.conda_ask_install(pkg[1], pkg[0], msg, url=url)
def update_encoder_options(): encoder = form.input_encoder.currentText() for fmt, enabled in support[encoder].items(): w = getattr(form, 'format_' + fmt) w.setEnabled(enabled) if not enabled and w.isChecked(): if encoder == 'mpeg_encode': form.format_mpg.setChecked(True) elif encoder == 'convert': form.format_gif.setChecked(True) else: form.format_png.setChecked(True) form.input_quality.setEnabled(encoder not in ("", "convert")) if encoder and not has_exe(encoder): msg = "Encoder '%s' is not installed." % encoder pkg = None url = None if not pkg: QtWidgets.QMessageBox.warning(parent, "Warning", msg) else: from pymol.Qt import utils utils.conda_ask_install(pkg[1], pkg[0], msg, url=url)
def update_encoder_options(): encoder = form.input_encoder.currentText() for fmt, enabled in support[encoder].items(): w = getattr(form, 'format_' + fmt) w.setEnabled(enabled) if not enabled and w.isChecked(): if encoder == 'mpeg_encode': form.format_mpg.setChecked(True) elif encoder == 'convert': form.format_gif.setChecked(True) else: form.format_png.setChecked(True) form.input_quality.setEnabled(encoder not in ("", "convert")) if encoder and not has_exe(encoder): msg = "Encoder '%s' is not installed." % encoder pkg = None url = None if encoder == 'ffmpeg': # anaconda::ffmpeg lacks codecs, don't use it pkg = ('conda-forge', 'ffmpeg') url = "https://www.ffmpeg.org/legal.html" elif encoder == 'convert' and pymol.IS_MACOS: # Linux package downgrades qt; Windows not available pkg = ('conda-forge', 'imagemagick') url = "https://www.imagemagick.org/script/license.php" if not pkg: QtWidgets.QMessageBox.warning(parent, "Warning", msg) else: from pymol.Qt import utils utils.conda_ask_install(pkg[1], pkg[0], msg, url=url)
def file_save_mpeg(parent, _preselect=None): form = parent.load_form('movieexport') filters = { 'png': 'Numbered PNG Files (*.png)', 'mp4': 'MPEG 4 movie file (*.mp4)', 'mpg': 'MPEG 1 movie file (*.mpg *.mpeg)', 'mov': 'QuickTime (*.mov)', 'gif': 'Animated GIF (*.gif)', } support = { '': { 'mp4': 0, 'mpg': 0, 'mov': 0, 'gif': 0 }, 'ffmpeg': { 'mp4': 1, 'mpg': 1, 'mov': 1, 'gif': 1 }, 'mpeg_encode': { 'mp4': 0, 'mpg': 1, 'mov': 0, 'gif': 0 }, 'convert': { 'mp4': 0, 'mpg': 0, 'mov': 0, 'gif': 1 }, } from pymol.movie import find_exe as has_exe def update_encoder_options(): encoder = form.input_encoder.currentText() for fmt, enabled in support[encoder].items(): w = getattr(form, 'format_' + fmt) w.setEnabled(enabled) if not enabled and w.isChecked(): if encoder == 'mpeg_encode': form.format_mpg.setChecked(True) elif encoder == 'convert': form.format_gif.setChecked(True) else: form.format_png.setChecked(True) form.input_quality.setEnabled(encoder not in ("", "convert")) if encoder and not has_exe(encoder): msg = "Encoder '%s' is not installed." % encoder pkg = None url = None if not pkg: QtWidgets.QMessageBox.warning(parent, "Warning", msg) else: from pymol.Qt import utils utils.conda_ask_install(pkg[1], pkg[0], msg, url=url) if _preselect == 'png': form.format_png.setChecked(True) form.group_format.hide() else: for i in range(1, form.input_encoder.count()): encoder = form.input_encoder.itemText(i) if has_exe(encoder): form.input_encoder.setCurrentIndex(i) break if _preselect == 'mov': encoder = 'ffmpeg' form.input_encoder.setCurrentIndex(1) form.format_mov.setChecked(True) elif encoder == 'ffmpeg': form.format_mp4.setChecked(True) else: form.format_mpg.setChecked(True) form._dialog.adjustSize() @PopupOnException.decorator def run(*_): for fmt in filters: w = getattr(form, 'format_' + fmt) if w.isChecked(): break fname = getSaveFileNameWithExt(parent, 'Save As...', parent.initialdir, filter=filters[fmt]) if not fname: return parent.initialdir = os.path.dirname(fname) if fmt == 'png': parent.cmd.mpng(fname, width=form.input_width.value(), height=form.input_height.value(), mode=2 if form.input_ray.isChecked() else 1, quiet=0, modal=-1) else: mode = 'ray' if form.input_ray.isChecked() else 'draw' encoder = form.input_encoder.currentText() parent.cmd.movie.produce(fname, width=form.input_width.value(), height=form.input_height.value(), quality=form.input_quality.value(), mode=mode, encoder=encoder, quiet=0) def set_resolution(height): w, h = form.input_width.value(), max(1, form.input_height.value()) aspect = (w / h) if (w and h) else 9999 width = int(round(min(aspect, 16. / 9.) * height / 2.)) * 2 form.input_width.setValue(width) form.input_height.setValue(height) # initial values viewport = parent.cmd.get_viewport() form.input_width.setValue(viewport[0]) form.input_height.setValue(viewport[1]) form.input_quality.setValue(parent.cmd.get_setting_int('movie_quality')) if parent.cmd.get_setting_int('ray_trace_frames'): form.input_ray.setChecked(True) update_encoder_options() # hook up events form.button_ok.clicked.connect(run) form.input_encoder.currentIndexChanged.connect(update_encoder_options) for height in (720, 480, 360): button = getattr(form, 'button_%dp' % height) button.pressed.connect(lambda h=height: set_resolution(h)) form._dialog.show()
def file_save_mpeg(parent, _preselect=None): form = parent.load_form('movieexport') filters = { 'png': 'Numbered PNG Files (*.png)', 'mp4': 'MPEG 4 movie file (*.mp4)', 'mpg': 'MPEG 1 movie file (*.mpg *.mpeg)', 'mov': 'QuickTime (*.mov)', 'gif': 'Animated GIF (*.gif)', } support = { '': {'mp4': 0, 'mpg': 0, 'mov': 0, 'gif': 0}, 'ffmpeg': {'mp4': 1, 'mpg': 1, 'mov': 1, 'gif': 1}, 'mpeg_encode': {'mp4': 0, 'mpg': 1, 'mov': 0, 'gif': 0}, 'convert': {'mp4': 0, 'mpg': 0, 'mov': 0, 'gif': 1}, } from pymol.movie import find_exe as has_exe def update_encoder_options(): encoder = form.input_encoder.currentText() for fmt, enabled in support[encoder].items(): w = getattr(form, 'format_' + fmt) w.setEnabled(enabled) if not enabled and w.isChecked(): if encoder == 'mpeg_encode': form.format_mpg.setChecked(True) elif encoder == 'convert': form.format_gif.setChecked(True) else: form.format_png.setChecked(True) form.input_quality.setEnabled(encoder not in ("", "convert")) if encoder and not has_exe(encoder): msg = "Encoder '%s' is not installed." % encoder pkg = None url = None if not pkg: QtWidgets.QMessageBox.warning(parent, "Warning", msg) else: from pymol.Qt import utils utils.conda_ask_install(pkg[1], pkg[0], msg, url=url) if _preselect == 'png': form.format_png.setChecked(True) form.group_format.hide() else: for i in range(1, form.input_encoder.count()): encoder = form.input_encoder.itemText(i) if has_exe(encoder): form.input_encoder.setCurrentIndex(i) break if _preselect == 'mov': encoder = 'ffmpeg' form.input_encoder.setCurrentIndex(1) form.format_mov.setChecked(True) elif encoder == 'ffmpeg': form.format_mp4.setChecked(True) else: form.format_mpg.setChecked(True) form._dialog.adjustSize() @PopupOnException.decorator def run(*_): for fmt in filters: w = getattr(form, 'format_' + fmt) if w.isChecked(): break fname = getSaveFileNameWithExt(parent, 'Save As...', parent.initialdir, filter=filters[fmt]) if not fname: return parent.initialdir = os.path.dirname(fname) if fmt == 'png': parent.cmd.mpng(fname, width=form.input_width.value(), height=form.input_height.value(), mode=2 if form.input_ray.isChecked() else 1, quiet=0, modal=-1) else: mode = 'ray' if form.input_ray.isChecked() else 'draw' encoder = form.input_encoder.currentText() parent.cmd.movie.produce(fname, width=form.input_width.value(), height=form.input_height.value(), quality=form.input_quality.value(), mode=mode, encoder=encoder, quiet=0) def set_resolution(height): w, h = form.input_width.value(), max(1, form.input_height.value()) aspect = (w / h) if (w and h) else 9999 width = int(round(min(aspect, 16. / 9.) * height / 2.)) * 2 form.input_width.setValue(width) form.input_height.setValue(height) # initial values viewport = parent.cmd.get_viewport() form.input_width.setValue(viewport[0]) form.input_height.setValue(viewport[1]) form.input_quality.setValue(parent.cmd.get_setting_int('movie_quality')) if parent.cmd.get_setting_int('ray_trace_frames'): form.input_ray.setChecked(True) update_encoder_options() # hook up events form.button_ok.clicked.connect(run) form.input_encoder.currentIndexChanged.connect(update_encoder_options) for height in (720, 480, 360): button = getattr(form, 'button_%dp' % height) button.pressed.connect(lambda h=height: set_resolution(h)) form._dialog.show()