Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _show_encoding_error_dialog(self):
"""Show an error dialog after failing to encode file."""
title = _('Failed to encode subtitle file to temporary directory "{}"').format(tempfile.gettempdir())
message = _("Subtitle data could not be encoded to a temporary file for preview with the current character encoding. Please first save the subtitle file with a different character encoding.")
dialog = gaupol.ErrorDialog(self.window, title, message)
dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
dialog.set_default_response(Gtk.ResponseType.OK)
gaupol.util.flash_dialog(dialog)
def __init__(self):
"""Initialize a :class:`ShowHelpMenuAction` instance."""
gaupol.TopMenuAction.__init__(self, "show_help_menu")
self.set_label(_("_Help"))
self.action_group = "main-safe"
def set_framerate(self, framerate, register=-1):
"""Set the value of framerate."""
orig_framerate = self.framerate
self.framerate = framerate
self.calc = aeidon.Calculator(framerate)
for subtitle in self.subtitles:
subtitle.framerate = framerate
action = aeidon.RevertableAction(register=register)
action.docs = tuple(aeidon.documents)
action.description = _("Setting framerate")
action.revert_function = self.set_framerate
action.revert_args = (orig_framerate,)
self.register_action(action)
def _show_translation_warning_dialog(self, page):
"""Show a warning dialog if opening a new translation file."""
title = _('Save changes to translation document "{}" before opening a new one?').format(page.get_translation_basename())
message = _("If you don't save, changes will be permanently lost.")
dialog = gaupol.WarningDialog(self.window, title, message)
dialog.add_button(_("Open _Without Saving"), Gtk.ResponseType.NO)
dialog.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL)
dialog.add_button(_("_Save"), Gtk.ResponseType.YES)
dialog.set_default_response(Gtk.ResponseType.YES)
response = gaupol.util.flash_dialog(dialog)
if response == Gtk.ResponseType.YES:
return self.save_translation(page)
gaupol.util.raise_default(response != Gtk.ResponseType.NO)
label=_("Seek _Previous"), icon_name="media-skip-backward")
button.set_action_name("win.seek-previous")
button.set_tooltip_text(_("Seek to the start of the previous subtitle"))
self.player_toolbar.insert(button, -1)
# win.seek-next
button = Gtk.ToolButton(
label=_("Seek _Next"), icon_name="media-skip-forward")
button.set_action_name("win.seek-next")
button.set_tooltip_text(_("Seek to the start of the next subtitle"))
self.player_toolbar.insert(button, -1)
self.player_toolbar.insert(Gtk.SeparatorToolItem(), -1)
# win.seek-backward
button = Gtk.ToolButton(
label=_("Seek _Backward"), icon_name="media-seek-backward")
button.set_action_name("win.seek-backward")
button.set_tooltip_text(_("Seek backward"))
self.player_toolbar.insert(button, -1)
# win.seek-forward
button = Gtk.ToolButton(
label=_("Seek _Forward"), icon_name="media-seek-forward")
button.set_action_name("win.seek-forward")
button.set_tooltip_text(_("Seek forward"))
self.player_toolbar.insert(button, -1)
self.player_toolbar.insert(Gtk.SeparatorToolItem(), -1)
# Volume button
self.volume_button = Gtk.VolumeButton()
self.volume_button.props.use_symbolic = False
adjustment = self.volume_button.get_adjustment()
adjustment.set_lower(0)
adjustment.set_upper(1)
adjustment.set_value(self.player.volume)
aeidon.util.connect(self, "volume_button", "value-changed")
def _confirm_close_document(self, page, doc):
"""Close `page` after asking to save `doc`."""
title = _('Save changes to document "{}" before closing?')
title = title.format(page.get_basename(doc))
message = _("If you don't save, changes will be permanently lost.")
dialog = gaupol.WarningDialog(self.window, title, message)
dialog.add_button(_("Close _Without Saving"), Gtk.ResponseType.NO)
dialog.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL)
dialog.add_button(_("_Save"), Gtk.ResponseType.YES)
dialog.set_default_response(Gtk.ResponseType.YES)
response = gaupol.util.flash_dialog(dialog)
gaupol.util.raise_default(not response in (
Gtk.ResponseType.YES, Gtk.ResponseType.NO))
if response == Gtk.ResponseType.YES:
self.save(page, doc)
def _show_io_error_dialog(self, basename, message):
"""Show an error dialog after failing to read file."""
title = _('Failed to open file "{}"').format(basename)
dialog = gaupol.ErrorDialog(self.window, title, message)
dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
dialog.set_default_response(Gtk.ResponseType.OK)
gaupol.util.flash_dialog(dialog)
class Framerate23976(aeidon.EnumerationItem):
label = _("23.976 fps")
value = 24 / 1.001
class Framerate24000(aeidon.EnumerationItem):
label = _("24.000 fps")
value = 24.0
class Framerate25000(aeidon.EnumerationItem):
label = _("25.000 fps")
value = 25.0
class Framerate29970(aeidon.EnumerationItem):
label = _("29.970 fps")
value = 30 / 1.001
framerates = aeidon.Enumeration()
framerates.FPS_23_976 = Framerate23976()
framerates.FPS_24_000 = Framerate24000()
framerates.FPS_25_000 = Framerate25000()
framerates.FPS_29_970 = Framerate29970()
def _check_file_not_open(self, path):
"""Raise :exc:`gaupol.Default` if file at `path` already open."""
for page in self.pages:
files = [page.project.main_file, page.project.tran_file]
paths = [x.path for x in files if x]
if not path in paths: continue
self.set_current_page(page)
message = _('File "{}" is already open')
self.flash_message(message.format(os.path.basename(path)))
raise gaupol.Default
gaupol.conf.connect_notify("application_window", "toolbar_style", self)
gaupol.util.pack_start(vbox, self.main_toolbar)
# win.open-main-files
button = Gtk.MenuToolButton(
label=_("Open"), icon_name="document-open")
button.set_menu(Gtk.Menu())
button.set_is_important(True)
button.set_action_name("win.open-main-files")
button.set_tooltip_text(_("Open main files"))
callback = self._on_open_button_show_menu
button.connect("show-menu", callback)
self.main_toolbar.insert(button, -1)
self.open_button = button
# win.save-main-document
button = Gtk.ToolButton(
label=_("Save"), icon_name="document-save")
button.set_is_important(True)
button.set_action_name("win.save-main-document")
button.set_tooltip_text(_("Save the current main document"))
self.main_toolbar.insert(button, -1)
self.main_toolbar.insert(Gtk.SeparatorToolItem(), -1)
# win.undo-action
button = Gtk.MenuToolButton(
label=_("Undo"), icon_name="edit-undo")
button.set_menu(Gtk.Menu())
button.set_is_important(True)
button.set_action_name("win.undo-action")
button.set_tooltip_text(_("Undo the last action"))
callback = self._on_undo_button_show_menu
button.connect("show-menu", callback)
self.main_toolbar.insert(button, -1)
self.undo_button = button