Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def save_geometry(self):
"""Save window size."""
with aeidon.util.silent(AttributeError):
# is_maximized was added in GTK+ 3.12.
if self.is_maximized(): return
gaupol.conf.output_window.size = list(self.get_size())
def code_to_name(code):
"""Convert ISO 15924 `code` to localized script name."""
if not _scripts:
_init_scripts()
with aeidon.util.silent(LookupError):
return d_("iso_15924", _scripts[code])
return code
def _update_actions(self, page):
"""Update sensitivities of all actions for page."""
rows = []
with aeidon.util.silent(AttributeError):
rows = page.view.get_selected_rows()
for name in self.window.list_actions():
action = self.get_action(name)
action.update_enabled(self, page, rows)
"""Remove custom framerates and corresponding UI elements."""
fallback = aeidon.framerates.FPS_23_976
if gaupol.conf.editor.framerate in self.framerates:
gaupol.conf.editor.framerate = fallback
# Go through all application's pages and reset those set
# to a custom framerate back to the default framerate.
orig_page = self.application.get_current_page()
for page in self.application.pages:
if not page.project.framerate in self.framerates: continue
self.application.set_current_page(page)
action = self.application.get_action("set-framerate")
action.activate(str(fallback))
self.application.set_current_page(orig_page)
for framerate in self.framerates:
delattr(aeidon.framerates, str(framerate))
with aeidon.util.silent(AttributeError):
# Menubar not available when running unit tests.
self.application.get_menubar_section(
"custom-framerates-placeholder").remove_all()
def _open_file(self, path, encodings, doc, check_open=True):
"""Open file at `path` and return corresponding page if successful."""
self._check_file_exists(path)
if check_open:
self._check_file_not_open(path)
self._check_file_size(path)
basename = os.path.basename(path)
page = (gaupol.Page() if doc == aeidon.documents.MAIN
else self.get_current_page())
for encoding in encodings:
with aeidon.util.silent(UnicodeError):
n = self._try_open_file(page, doc, path, encoding)
self._check_sort_count(path, n)
return page
# Report if all codecs failed to decode file.
self._show_encoding_error_dialog(basename)
raise gaupol.Default
def flash_message(self, message, duration=6):
"""Show `message` in statuslabel for `duration` seconds."""
self.statuslabel.flash_text(message, duration=duration)
self.statuslabel.register_hide_event(self.window, "button-press-event")
self.statuslabel.register_hide_event(self.window, "key-press-event")
self.statuslabel.register_hide_event(self.window, "scroll-event")
with aeidon.util.silent(AttributeError):
self.statuslabel.register_hide_event(
self.get_current_page().view, "button-press-event")
def update(self, application, page):
"""Update state of extension for `application` and active `page`."""
action = self._action_group.get_action("add-bookmark")
sensitive = False
with aeidon.util.silent(AttributeError):
sensitive = len(page.view.get_selected_rows()) == 1
action.set_sensitive(sensitive)
action = self._action_group.get_action("edit-bookmarks")
action.set_sensitive(page is not None)
action = self._action_group.get_action("next-bookmark")
sensitive = False
with aeidon.util.silent(KeyError):
sensitive = bool(self._bookmarks[page])
action.set_sensitive(sensitive)
action = self._action_group.get_action("previous-bookmark")
action.set_sensitive(sensitive)
def _init_text_view(self, output):
"""Initialize the text view."""
self._text_view.set_wrap_mode(Gtk.WrapMode.WORD)
self._text_view.set_editable(False)
self._text_view.set_cursor_visible(False)
self._text_view.set_accepts_tab(False)
self._text_view.set_left_margin(6)
self._text_view.set_right_margin(6)
with aeidon.util.silent(AttributeError):
# Available since GTK 3.18.
self._text_view.set_top_margin(6)
self._text_view.set_bottom_margin(6)
text_buffer = self._text_view.get_buffer()
text_buffer.set_text(output)
gaupol.style.use_font(self._text_view, "monospace")
scroller = Gtk.ScrolledWindow()
scroller.set_policy(*((Gtk.PolicyType.AUTOMATIC,)*2))
scroller.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
scroller.add(self._text_view)
box = self.get_message_area()
gaupol.util.pack_start_expand(box, scroller)
gaupol.util.scale_to_content(self._text_view,
min_nchar=60,
max_nchar=100,
min_nlines=10,
def code_to_name(code):
"""Convert ISO 3166 `code` to localized country name."""
if not _countries:
_init_countries()
with aeidon.util.silent(LookupError):
return d_("iso_3166", _countries[code])
return code