Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AddonManager: Support selecting addon on start #14168

Merged
merged 1 commit into from
May 27, 2024

Conversation

pieterhijma
Copy link
Contributor

@pieterhijma pieterhijma commented May 20, 2024

This PR supports the functionality to start the Addon Manager for a specific addon.

The current implementation tries to be as unobtrusive to the original code as possible. This is accomplished by introducing a new preference that captures a search string and filter based on whether this preference is set. It also emits signals for when the Addon Manager is finished, allowing a client addon to reset the preferences to their original values.

For a client addon to open the Addon Manager, it can do the following (as taken from the Ondsel Lens addon):

class UpdateManager:
    def storePreferences(self):
        pref = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Addons")
        self.autocheck = pref.GetBool("AutoCheck")
        self.statusSelection = pref.GetInt("StatusSelection")
        self.packageTypeSelection = pref.GetInt("PackageTypeSelection")
        self.searchString = pref.GetString("SearchString")

    def setCustomPreferences(self):
        pref = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Addons")
        pref.SetBool("AutoCheck", True)
        pref.SetInt("StatusSelection", 3)
        pref.SetInt("PackageTypeSelection", 1)
        pref.SetString("SearchString", "Ondsel Lens")

    def restorePreferences(self):
        pref = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Addons")
        pref.SetBool("AutoCheck", self.autocheck)
        pref.SetInt("StatusSelection", self.statusSelection)
        pref.SetInt("PackageTypeSelection", self.packageTypeSelection)
        pref.SetString("SearchString", self.searchString)

    def openAddonManager(self, finishFunction):
        """Open the addon manager with custom preferences."""

        self.storePreferences()
        self.setCustomPreferences()

        addonManager = AddonManager.CommandAddonManager()
        addonManager.finished.connect(finishFunction)
        addonManager.Activated()

class YourAddonClass:
    def openAddonManager(self):
        self.updateManager = UpdateManager()
        self.updateManager.openAddonManager(self.addonManagerFinished)

    def addonManagerFinished(self):
        self.updateManager.restorePreferences()
        self.UpdateManager = None

I think there are better implementations possible for this functionality. For example, instead of using preferences, I would prefer static variables. I haven't implemented this because it requires more checking code than with the preferences as it is currently.

A video that shows the behavior for the Ondsel Lens addon is below. It shows that the Addon Manager behaves normally, then the update button opens the Addon Manager focusing on a specific Addon, then afterwards, it behaves normally again.

video-select-addon-addon-manager.mp4

Closes #14166

@chennes chennes merged commit 0229715 into FreeCAD:main May 27, 2024
10 checks passed
@Syres916
Copy link
Contributor

@pieterhijma this PR has caused a regression for not just myself but also see https://forum.freecad.org/viewtopic.php?t=87996 I don't receive the sea of red reported there but no update or install appears to even start properly hence if you try a second one it states that you must wait until the last one has finished. I've manually backed the change out locally to get back a working AddonManager.

OS: Debian GNU/Linux 12 (bookworm) (X-Cinnamon/cinnamon)
Word size of FreeCAD: 64-bit
Version: 0.22.0dev.37537 (Git)
Build type: Release
Branch: main
Hash: 1bcf8ac9dc8f520a052848dffaec71a5a15458b5
Python 3.11.2, Qt 5.15.8, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.3
Locale: English/United Kingdom (en_GB)
Installed mods: 
  * sheetmetal 0.4.13
  * Design456 0.0.1
  * Rocket 3.3.0
  * CfdOF 1.24.8
  * Assembly3 0.12.0
  * Assembly4 0.50.12
  * fasteners 0.5.20
  * freecad.gears 1.1.0

@pieterhijma
Copy link
Contributor Author

Oh dear, I'm on it. Thanks for reporting!

@pieterhijma
Copy link
Contributor Author

@pieterhijma this PR has caused a regression for not just myself but also see https://forum.freecad.org/viewtopic.php?t=87996 I don't receive the sea of red reported there but no update or install appears to even start properly hence if you try a second one it states that you must wait until the last one has finished. I've manually backed the change out locally to get back a working AddonManager.

@Syres916: I see the behavior that you report. I commented out all the changes of this PR but the addons are still not loading properly for me. Could you tell me what changes you made to make it work?

@Syres916
Copy link
Contributor

I did exactly the same by commenting out all the additions to the two files, restarted FC and tested successfully.

@Syres916
Copy link
Contributor

Also note the exact build revision I'm using, it's 6 commits before the weekly builds so I'll extract the latest AppImage and see if I get a different result after commenting out all the additions to the two files.

@Syres916
Copy link
Contributor

OK, again the AppImage works after backing out the PR, the one thing perhaps I should have made clear is I backed out the class CommandAddonManager(QtCore.QObject): line to class CommandAddonManager:

@pieterhijma
Copy link
Contributor Author

Right, thanks! So you commented out all the lines from this PR except class CommandAddonManager(QtCore.QObject)? Or did you change only that line to class CommandAddonManager?

I'm currently at loss to explain it because the addon manager doesn't work at all for me, regardless of this PR. It may have to do with Qt 6 that I'm running. I'm now about to test on Qt 5.

@Syres916
Copy link
Contributor

Or did you change only that line to class CommandAddonManager?

Yes I changed it back to how it was before the PR, I perhaps was better off just adding the commit hash to .git-blame-ignore-revs and saved a lot of typing!!

@pieterhijma
Copy link
Contributor Author

@Syres916, I cannot reproduce your issues, but in any case, I found this issue that doesn't seem to affect you.

@pieterhijma
Copy link
Contributor Author

@Syres916, I initially said that I saw the behavior you reported, but now I'm not so sure I saw the same thing. The behavior that I noticed is the following (after removing ~/.cache/FreeCAD/Cache/AddonManager):

  • I start the Addon Manager
  • It performs "Check for updates" automatically
  • It blocks at 41% and is in an infinite loop (one of my cores is at 100%)

This behavior is the same for this PR enabled or not.

I run this on a machine with Qt 6, so to verify that it is not a Qt 6 problem, I tested it on a virtual machine with Qt 5, but on that machine I saw the exact same behavior and I reported it in issue #14340. Since adding debugging commands would sometimes get FreeCAD in a blocked state and the behavior was sometimes non-deterministic, I ran the same code but gave the VM only one core. The behavior described above doesn't appear in that case and the check for updates is completed without a problem.

On a single core on my VM where I have an addon manager that operates normally, turning on this PR does not affect the installation procedure of addons for me. I see the list of addons, I can install addons, etc. So for me, the Addon Manager works as expected with this PR enabled.

Perhaps @chennes has ideas on what could cause your issue and #14340?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Addon Manager: Allow to "focus" on a single addon
3 participants