View Single Post
Old 02-13-2024, 06:10 AM   #1
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
New action to save & restore GUI pane layouts

I added the ability to save and restore the GUI pane layout, including Narrow/Wide, what panes show, the pane sizes, and where supported by base calibre the pane positions. The new operations are added to the existing "Layout actions".

Notes:
  • You can assign a keyboard shortcut to open the Layout actions menu.
  • With the Action chains plugin you can assign shortcuts to specific menu actions such as restoring a layout.
  • I included an API for plugin writers to use to save/restore/delete layouts (View manager?). The API methods are documented in calibre.gui2.actions.layout_actions.py.
    Spoiler:
    Code:
        # Public API
        def apply_layout(self, name):
            '''apply_layout()
            Apply a saved GUI panel layout.
    
            :param:`name` The name of the saved layout
    
             Throws KeyError if the name doesn't exist.
            '''
    
        def save_current_layout(self):
            '''save_current_layout()
            Opens a dialog asking for the name to use to save the current layout.
            Saves the current settings under the provided name.
            '''
    
        def current_settings(self):
            '''current_settings()
    
            :return: the current gui layout settings.
            '''
    
        def save_named_layout(self, name, settings):
            '''save_named_layout()
            Saves the settings under the provided name.
    
            :param:`name` The name for the settings.
            :param:`settings`: The gui layout settings to save.
            '''
    
        def delete_layout(self, name, show_warning=True):
            '''delete_layout()
            Delete a saved layout.
    
            :param:`name` The name of the layout to delete
            :param:`show_warning`: If True a warning dialog will be shown before deleting the layout.
            '''
    
        def saved_layout_names(self):
            '''saved_layout_names()
            Get a list of saved layout names
    
            :return: the sorted list of names. The list is empty if there are no names.
            '''

    This python template is a small example.
    Spoiler:
    Code:
    python:
    def evaluate(book, context):
    	from calibre.gui2.ui import get_gui
    	gui = get_gui()
    
    	api = gui.iactions['Layout Actions'] # Note the capitalization.
    	settings = api.current_settings()
    	print(settings)
    	names = api.saved_layout_names()
    	print(names)
    	api.apply_layout('Normal')
    	return ', '.join(names)
  • While there I added toggling panes to the existing abilities to show and hide panes. All the pane visibility actions are visible in Action chains.
  • The changes are in calibre source and will be included in the next calibre release.
Attached Thumbnails
Click image for larger version

Name:	Clipboard02.jpg
Views:	241
Size:	44.8 KB
ID:	206361   Click image for larger version

Name:	Clipboard03.jpg
Views:	231
Size:	69.2 KB
ID:	206362  

Last edited by chaley; 02-13-2024 at 06:14 AM.
chaley is offline   Reply With Quote