Signals for refreshing the Addon Manager?

Kari has created a SuperTool Script to add the Isotammi addon library to the Addon Manager’s list on the Projects tab.

However, the Addon Manager is not updating the GUI for the Projects tab. So he has the workaround of warning if the dialog is open and offering to close it.
image

It would less convoluted if the extra steps of a decision dialog, closing and re-opening the Addon Manager was unnecessary. Is there a signal to tell the Addon Manager GUI to update?

How do we discover if a signal exists for a particular dialog of the GUI? And what is the minimum code needed to emit a signal? The “Signals and Callbacks” wiki page is not explicit.

Here is the code to check for any Addon Manager dialogs and close them:

def close_addon_manager_windows():
    window_list = get_addon_manager_windows()
    if window_list:
        msg = textwrap.dedent("""
            There is at least one Addon Manager window open. 
            They should be closed while the project list is updated""")
        d = QuestionDialog2("Close Addon Manager(s)?", msg, "Close Addon Manager and continue", "Cancel")
        ok = d.run()
        if ok:
            for win in window_list:
                win.close()
            return True
        else:
            return False # Cancel
    return True

The code for get_addon_manager_windows() should be added:

def get_addon_manager_windows():
	ret = []
	gwm = uistate.gwm # GrampsWindowManager
	for menu in gwm.window_tree:
		if type(menu) == list:
			for win in menu:
				if isinstance(win, AddonManager):
					ret.append(win)
	return ret
1 Like

As far as I understand there is no such signal.

And the way to find out if a signal exists is to read the code :slight_smile:

1 Like

Well, I noticed the emit on line 121 and wondered whether it would do the job.

I was going to experiment with it but then discovered the wiki page (on signals and callbacks) did not include a minimal sample with the necessary “from” statements.

    def emit_signal(self):
        self.callback(self.addon_list)

There is a signal that is emitted when the background task has retrieved a list of updated addons, but it isn’t what you are looking for.

The AddonManager has a refresh method which will refresh the list of available addons. This will work but the project tab will not be updated since the project tab is the mechanism provided to update the list.

If you have modified the “behavior.addons-projects” configuration setting, you could update the list with code similar to the following:

for row in addon_manager.project_list.get_children():
    addon_manager.project_list.remove(row)
for project in config.get("behavior.addons-projects"):
    addon_manager.project_list.add(ProjectRow(addon_manager, project))
addon_manager.refresh()

I didn’t anticipate that someone would want to update the project list outside of the Addon Manager.

1 Like

My fault, I fear. The enhancements turned out to be more extensive than allowable for 5.2.3 update. There was a lot needed to have the Projects Reset support another listing in the default rows. So I began looking for other options.

It is likely that users are going to want regularly check with Isotammi, CDHorn, GlopGlop and jmichault for updates. (There are others.) And developers might want to have their local or GitHub repository in the queue. (You’ve nearly have evolved the process to self-publish addons to the ‘indistinguishable from magic’ stage.)

So I was looking for ways that wouldn’t require copy’n’paste of 2 or 3 items followed by a complex workflow for Users to leverage those published collections.

It didn’t look like there was a CLI option. (Which was my 1st thought.)

So I was thinking that an example of how to add a project would be useful. Developers might be able to insert it into their experimental addons. So once you download the ZIP from their GitHub Repository and use the ZIPinstall addon, the first run could offer to add a Project. (Which let’s them update their experimental add-ons more easily.)

Thanks. This will simplify the script considerably. Actually only the line

addon_manager.project_list.add(ProjectRow(addon_manager, project))

is needed. No need to remove the old entries.

2 Likes

Here’s the content of the SuperTool Script type Note for the Dashboard script that adds the Isotammi project on GitHub to the Addon Manager.

From this experiment, we discovered that to add a “Project” to the Addon Manager only takes 3 lines. Which means a developer can distribute the initial experiment using the GitHub repository zip feature to download. Then install the download with the Isotammi ZipInstall addon tool.

Afterwards, such ‘experimental’ or beta add-ons could have the option to add the project. And the frequent updates that happen with evolving add-ons would be under the direct distribution control of the developer.

[Gramps SuperTool script file]
version=1

[title]
Addon Manager project for Isotammi 

[description]
This script will add the Isotammi addons repository as a project in the Gramps 5.2 Addon Manager.

The project is not added if it is already defined.

Not yet implemented: 
support multiple rows of projects_addition without loops of pop-up dialogs
a user friendly way of sharing lists of projects_addition rows

[category]
Dashboard

[initial_statements]
import textwrap
from gramps.gen.config import config
from gramps.version import major_version, VERSION_TUPLE
from gramps.gui.plug._windows import AddonManager, ProjectRow
from gramps.gui.dialog import QuestionDialog2, OkDialog

projects_addition = [
    [
        'Isotammi project on GitHub',
        'https://raw.githubusercontent.com/Taapeli/isotammi-addons/master/addons/gramps52',
        False]
    ]
project_name = projects_addition[0][0]  
project_url = projects_addition[0][1]   
project_status = projects_addition[0][2]  

def my_project_exists():
    projects = config.get("behavior.addons-projects")
    for p in projects:
        if p[1] == project_url:
            return True
    return False

def get_addon_manager_windows():
    ret = []
    gwm = uistate.gwm # GrampsWindowManager
    for menu in gwm.window_tree:
        if type(menu) == list:
            for win in menu:
                if isinstance(win, AddonManager):
                    ret.append(win)
    return ret

def update_addon_manager_windows():
    window_list = get_addon_manager_windows()
    for win in window_list:
        win.project_list.add(ProjectRow(win, [project_name, project_url, project_status]))

def add_my_project():
    projects = config.get("behavior.addons-projects")
    projects.append([project_name, project_url, project_status])
    config.set("behavior.addons-projects", projects)
    if project_status:
        msg = f"The '{project_name}' was added to Gramps Addon Manager"
    else:
        msg = f"The '{project_name}' was added to Gramps Addon Manager but it is not yet enabled"
    OkDialog("Done", msg)

if VERSION_TUPLE < (5, 2, 0):
    msg = f"""
        This script would add the '{project_name}' to Gramps 5.2 Addon Manager but this is Gramps version {major_version} and not supported
    """.strip()
    OkDialog("Error", msg)
elif my_project_exists():
    msg = f"""
        This script wants to add the '{project_name}' to Gramps Addon Manager's projects. But the '{project_name}' already exists.
    """.strip()
    OkDialog("Error", msg)
else:
    msg = f"This script will add the '{project_name}' to Gramps Addon Manager"
    d = QuestionDialog2(f"Add the '{project_name}'?", msg, "Continue", "Cancel")
    ok = d.run()
    if ok:
        add_my_project()
        update_addon_manager_windows()

[statements]

[filter]

[expressions]

[scope]
selected

[unwind_lists]
False

[commit_changes]
False

[summary_only]
True