gaupol/dialogs/framerate_convert.py¶
Source code for module gaupol.dialogs.framerate_convert from file gaupol/dialogs/framerate_convert.py.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | # -*- coding: utf-8 -*-
# Copyright (C) 2005 Osmo Salomaa
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Dialog for converting framerates."""
import aeidon
import gaupol
from gi.repository import Gtk
__all__ = ("FramerateConvertDialog",)
class FramerateConvertDialog(gaupol.BuilderDialog):
"""Dialog for converting framerates."""
_widgets = ("all_radio", "current_radio", "input_combo", "output_combo")
def __init__(self, parent, application):
"""Initialize a :class:`FramerateConvertDialog` instance."""
gaupol.BuilderDialog.__init__(self, "framerate-convert-dialog.ui")
self.application = application
self._init_input_combo()
self._init_output_combo()
self._init_values()
self._dialog.set_transient_for(parent)
self._dialog.set_default_response(Gtk.ResponseType.OK)
def _convert_framerates(self):
"""Convert framerates in target projects."""
target = self._get_target()
ifps = aeidon.framerates[self._input_combo.get_active()]
ofps = aeidon.framerates[self._output_combo.get_active()]
for page in self.application.get_target_pages(target):
self.application.set_current_page(page)
page.project.convert_framerate(None, ifps, ofps)
def _get_target(self):
"""Return the selected target."""
if self._current_radio.get_active():
return gaupol.targets.CURRENT
if self._all_radio.get_active():
return gaupol.targets.ALL
raise ValueError("Invalid target radio state")
def _init_input_combo(self):
"""Initialize the input framerate combo box."""
store = Gtk.ListStore(str)
self._input_combo.set_model(store)
for label in (x.label for x in aeidon.framerates):
store.append((label,))
renderer = Gtk.CellRendererText()
self._input_combo.pack_start(renderer, expand=True)
self._input_combo.add_attribute(renderer, "text", 0)
def _init_output_combo(self):
"""Initialize the output framerate combo box."""
store = Gtk.ListStore(str)
self._output_combo.set_model(store)
for label in (x.label for x in aeidon.framerates):
store.append((label,))
renderer = Gtk.CellRendererText()
self._output_combo.pack_start(renderer, expand=True)
self._output_combo.add_attribute(renderer, "text", 0)
def _init_values(self):
"""Intialize default values for widgets."""
page = self.application.get_current_page()
target = gaupol.conf.framerate_convert.target
self._input_combo.set_active(page.project.framerate)
self._output_combo.set_active(page.project.framerate)
self._all_radio.set_active(target == gaupol.targets.ALL)
self._current_radio.set_active(target == gaupol.targets.CURRENT)
def _on_input_combo_changed(self, *args):
"""Set response sensitivity."""
index_in = self._input_combo.get_active()
index_out = self._output_combo.get_active()
sensitive = (index_in != index_out)
self._dialog.set_response_sensitive(Gtk.ResponseType.OK, sensitive)
def _on_output_combo_changed(self, *args):
"""Set response sensitivity."""
index_in = self._input_combo.get_active()
index_out = self._output_combo.get_active()
sensitive = (index_in != index_out)
self._dialog.set_response_sensitive(Gtk.ResponseType.OK, sensitive)
def _on_response(self, dialog, response):
"""Save target and convert framerates."""
gaupol.conf.framerate_convert.target = self._get_target()
if response == Gtk.ResponseType.OK:
self._convert_framerates()
|