Manual de Calibre | Page 201

Manual de usuario de calibre, Publicación 2.73.0 class DemoTool( Tool):
#: Set this to a unique name it will be used as a key name = ' demo-tool '
#: If True the user can choose to place this tool in the plugins toolbar allowed _ in _ toolbar = True
#: If True the user can choose to place this tool in the plugins menu allowed _ in _ menu = True
def create _ action( self, for _ toolbar = True): # Create an action, this will be added to the plugins toolbar and # the plugins menu ac = QAction( get _ icons(' images / icon. png '), ' Magnify fonts ', self. gui) # noqa if not for _ toolbar: # Register a keyboard shortcut for this toolbar action. We only # register it for the action created for the menu, not the toolbar, # to avoid a double trigger self. register _ shortcut( ac, ' magnify-fonts-tool ', default _ keys =(
˓→ ' Ctrl + Shift + Alt + D ',)) ac. triggered. connect( self. ask _ user) return ac
def ask _ user( self): # Ask the user for a factor by which to multiply all font sizes factor, ok = QInputDialog. getDouble( self. gui, ' Enter a magnification factor ', ' Allow font sizes in the book ˓→will be multiplied by the specified factor ', value = 2, min = 0.1, max = 4
) if ok:
# Ensure any in progress editing the user is doing is present in the
˓→container self. boss. commit _ all _ editors _ to _ container() try: self. magnify _ fonts( factor) except Exception: # Something bad happened report the error to the user import traceback error _ dialog( self. gui, _(' Failed to magnify fonts '), _( ' Failed to magnify fonts, click " Show details " for more info '), det _ msg = traceback. format _ exc(), show = True) # Revert to the saved restore point self. boss. revert _ requested( self. boss. global _ undo. previous _ container) else: # Show the user what changes we have made, allowing her to # revert them if necessary self. boss. show _ current _ diff() # Update the editor UI to take into account all the changes we # have made self. boss. apply _ container _ update _ to _ gui()
def magnify _ fonts( self, factor): # Magnify all font sizes defined in the book by the specified factor # First we create a restore point so that the user can undo all changes # we make.
1.9. Cursillos 197