#!/usr/bin/env python # # Use Own Fonts extension: Let users easily enable/disable the usage of # their own fonts instead of the fonts from the web pages. # # Copyright (C) 2006 Wouter Bolsterlee # Copyright (C) 2006 Reinout van Schouwen # Copyright (C) 2005 Adam Hooper # import gtk import gconf # The UI string that defines the place in the menu _ui_str = """ """ # Some settings gconf_key_name = '/apps/epiphany/web/use_own_fonts' action_path = '/menubar/ViewMenu/UseOwnFonts' # All methods below are callbacks def _fonts_cb(action, window): """Callback which is called when the menu item is pressed""" # get the action and it's current status action = window.get_ui_manager().get_action(action_path) new_setting = action.get_active() # toggle the gconf key gconf_client = gconf.client_get_default() gconf_client.set_bool(gconf_key_name, new_setting) # update the checkbox action = window.get_ui_manager().get_action(action_path) action.set_active(new_setting) # The methods below are needed to implement the EphyExtension interface. def attach_window(window): """Adds the item to the menu""" # Define the menu entry. # to the menu actions = [ ('UseOwnFonts', None, 'Always use _own fonts', None, None, _fonts_cb, 0) ] # create an action and add it to the menu ui_manager = window.get_ui_manager() group = gtk.ActionGroup('UseOwnFonts') group.add_toggle_actions(actions, window) ui_manager.insert_action_group(group, -1) ui_id = ui_manager.add_ui_from_string(_ui_str) # initial setting action = window.get_ui_manager().get_action(action_path) gconf_client = gconf.client_get_default() initial_setting = gconf_client.get_bool(gconf_key_name) action.set_active(initial_setting) # store the group and ui_id, because we want to remove them later on window._use_own_fonts_window_data = (group, ui_id) def detach_window(window): """Removes the item from the menu""" # clean up group, ui_id = window._use_own_fonts_window_data del window._use_own_fonts_window_data ui_manager = window.get_ui_manager() ui_manager.remove_ui(ui_id) ui_manager.remove_action_group(group) ui_manager.ensure_update()