Skip to content
This repository has been archived by the owner on Jun 25, 2022. It is now read-only.

Disable/Enable menuItems #40

Closed
Bluscream opened this issue Jan 19, 2017 · 4 comments
Closed

Disable/Enable menuItems #40

Bluscream opened this issue Jan 19, 2017 · 4 comments

Comments

@Bluscream
Copy link
Contributor

https://github.com/Kleberstoff/TS-Plugins-API-21/blob/master/anti-move/src/plugin.c#L161

	ts3Functions.setPluginMenuEnabled(pluginID, Rubberband_Enabled, 1);
	ts3Functions.setPluginMenuEnabled(pluginID, Rubberband_Disabled, 0);

I wish this would exist in pyTSon

@Bluscream
Copy link
Contributor Author

Fixed with 110e9d8

@pathmann
Copy link
Owner

PluginHost.globalMenuID is currently undocumented (and there was a bug, fixed in master), but with the next release it should work.

from ts3plugin import ts3plugin, PluginHost

import ts3defines, ts3lib


class menutest(ts3plugin):
    name = "menutest"
    requestAutoload = False
    version = "1.0.0"
    apiVersion = 21
    author = "Thomas \"PLuS\" Pathmann"
    description = "Showcase to enable/disable pluginmenus"
    offersConfigure = False
    commandKeyword = "menu"
    infoTitle = None
    menuItems = [(ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_GLOBAL, 0, "Menutest", "icon.png")]
    hotkeys = []

    def __init__(self):
        self.dlg = None

    def stop(self):
        pass

    def onMenuItemEvent(self, schid, atype, menuItemID, selectedItemID):
        if menuItemID == 0:
            print("menu clicked")

    def enableMenu(self, on):
        globid = PluginHost.globalMenuID(self, 0)

        if globid:
            ts3lib.setPluginMenuEnabled(globid, on)

    def processCommand(self, schid, command):
        tokens = command.split(' ')

        if len(tokens) == 0:
            return False

        if tokens[0] == "enable":
            self.enableMenu(True)
            return True
        elif tokens[0] == "disable":
            self.enableMenu(False)
            return True

        return False

@Bluscream
Copy link
Contributor Author

Bluscream commented Jan 20, 2017

Does your code still apply to 229c137 ?
Also .globalMenuID() seems to only apply to global menus, what about channel and client ones?
I'd also suggest splitting https://github.com/pathmann/pyTSon_repository/blob/master/repository.json into a production and a development/test repo and adding the snippet above to the test repo.

Bluscream referenced this issue Jan 20, 2017
…ems are setup (again), eg after reload, to let them possibly disable them again
@pathmann
Copy link
Owner

Does your code still apply to 229c137 ?

Yes.

Also .globalMenuID() seems to only apply to global menus, what about channel and client ones?

No, that's not the meaning of "global" in that function. Every plugin uses "local identifier" to reference only the menuItems, this specific plugin uses. The PythonHost translates them to "global identifiers" and sends them to the TS3 client. With this method, it is not necessary, that each plugin uses unique identifiers.

I'd also suggest splitting https://github.com/pathmann/pyTSon_repository/blob/master/repository.json into a production and a development/test repo and adding the snippet above to the test repo.

The masterplan is, to update the documentation.

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

No branches or pull requests

2 participants