Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Programmatically installing a plugin

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Programmatically installing a plugin

Post by kgschlosser »

here is some code that you can add to your plugin if it relies on another plugin being installed to work

for this example I am going to use the Broadcaster plugin. you can use either the plugin's GUID or the name of the plugin will also work. but this will use the class name to check and see if the plugin is installed

Code: Select all


BROADCASTER_GUID = "{5E8DA56B-24AC-4092-9521-169343C5171C}"
BROADCASTER_CLASS_NAME = "BroadcastListener"

def InstallPlugin(plugInfo):
    eg.AsTasklet(eg.UndoHandler.NewPlugin(eg.document).Do)(plugInfo)
        
if not hasattr(eg.plugins, BROADCASTER_CLASS_NAME):
    pluginInfo = eg.pluginManager.GetPluginInfo(BROADCASTER_GUID)
    wx.CallAfter(InstallPlugin, pluginInfo)

If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Programmatically installing a plugin

Post by kgschlosser »

and here is some code if you wanted to set the plugins startup parameters programmatically. if and only if the plugins default parameters will not throw a traceback. this closes the plugins config dialog and then sets the new parameters.

the only way to do this if it does throw a traceback is to use dialog.panel.GetChildren() and set the values for each of the specific widgets then call wx.CallAfter(dialog.DispatchEvent, None, wx.ID_OK) this will set the values then close the dialog.. and you can then remove the wx.CallAfter(treeItem.SetArguments, STARTUP_PARAMETERS)

Code: Select all

import wx
import threading


BROADCASTER_GUID = "{5E8DA56B-24AC-4092-9521-169343C5171C}"
BROADCASTER_CLASS_NAME = "BroadcastListener"
BROADCASTER_NAME = "Broadcaster"
STARTUP_PARAMETERS = ("TestBroadcaster", "255.255.255.255", 33333, False, "&&", "")
EVENT = threading.Event()

def InstallPlugin(plugInfo):
    eg.UndoHandler.NewPlugin(eg.document).Do(plugInfo)
    EVENT.set()

def CloseDialog():
    while not EVENT.isSet():
        if eg.document.frame.openDialogs:
            dialog = eg.document.frame.openDialogs[-1]
            if hasattr(dialog.treeItem, 'info') and dialog.treeItem.info.guid == BROADCASTER_GUID:
                EVENT.set()
                treeItem = dialog.treeItem
                wx.CallAfter(dialog.DispatchEvent, None, wx.ID_OK)
                wx.CallAfter(treeItem.SetArguments, STARTUP_PARAMETERS)
        
if not hasattr(eg.plugins, BROADCASTER_CLASS_NAME):
    pluginInfo = eg.pluginManager.GetPluginInfo(BROADCASTER_GUID)
    wx.CallAfter(eg.AsTasklet(InstallPlugin), pluginInfo)
    threading.Thread(target=CloseDialog).start()
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Programmatically installing a plugin

Post by kgschlosser »

and here is an example of setting the parameters at the widget level

Code: Select all

import wx
import threading


BROADCASTER_GUID = "{5E8DA56B-24AC-4092-9521-169343C5171C}"
BROADCASTER_CLASS_NAME = "BroadcastListener"
BROADCASTER_NAME = "Broadcaster"
STARTUP_PARAMETERS = ("TestBroadcaster", "255.255.255.255", 0, 33333, False, "&&")
EVENT = threading.Event()

def InstallPlugin(plugInfo):
    eg.UndoHandler.NewPlugin(eg.document).Do(plugInfo)
    EVENT.set()

def CloseDialog():
    while not EVENT.isSet():
        if eg.document.frame.openDialogs:
            dialog = eg.document.frame.openDialogs[-1]
            if hasattr(dialog.treeItem, 'info') and dialog.treeItem.info.guid == BROADCASTER_GUID:
                try:
                    children = dialog.panel.GetChildren()
                    if len(children) < 6:
                        continue
                except:
                    continue
                    
                prefixCtrl, zoneCtrl, portCtrl, addrCtrl, selfbroadCtrl, _ = children
                prefixCtrl.SetValue("TestBroadcaster")
                zoneCtrl.SetValue("255.255.255.255")
                portCtrl.SetValue(12345)
                addrCtrl.SetValue(0)
                selfbroadCtrl.SetValue(True)
                wx.CallAfter(dialog.DispatchEvent, None, wx.ID_OK)
                EVENT.wait()
        
if not hasattr(eg.plugins, BROADCASTER_CLASS_NAME):
    pluginInfo = eg.pluginManager.GetPluginInfo(BROADCASTER_GUID)
    wx.CallAfter(eg.AsTasklet(InstallPlugin), pluginInfo)
    threading.Thread(target=CloseDialog).start()
If you like the work I have been doing then feel free to Image
Post Reply