How can I use values from def Configure() in an eg.ActionBase class?

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
Septik
Posts: 39
Joined: Sun Feb 15, 2015 1:29 pm

How can I use values from def Configure() in an eg.ActionBase class?

Post by Septik » Fri Oct 13, 2017 6:00 pm

Trying to write a plugin with another user on the forum, and I got stuck at that. I'm taking in some user variables in the def Configure() function and would like to use those elsewhere. As per the tutorial my code looks something like this:

Code: Select all

class SpotifyWebAPI(eg.PluginBase):
    def Configure(self, clientID="", clientSecret="", username=""):
        panel = eg.ConfigPanel()
        
        
        clientIDCtrl = wx.TextCtrl(panel, -1, clientID)
        clientSecretCtrl = panel.TextCtrl(clientSecret)
        usernameCtrl = panel.TextCtrl(username)
        
        
        
        panel.AddLine(u"Client ID:", clientIDCtrl)
        panel.AddLine(u"Client Secret:", clientSecretCtrl)
        panel.AddLine(u"Spotify username:", usernameCtrl)

        
        while panel.Affirmed():
            panel.SetResult(
                clientIDCtrl.GetValue(),
                clientSecretCtrl.GetValue(),
                usernameCtrl.GetValue()
                )
I am able to save the values entered (between restarts of EventGhost for example), but unable to use those values in other methods (like eg.ActionBase). How would I go about doing so?

User avatar
yokel22
Experienced User
Posts: 265
Joined: Thu Feb 05, 2015 5:56 pm
Location: U.S. - Kansas city

Re: How can I use values from def Configure() in an eg.ActionBase class?

Post by yokel22 » Fri Oct 13, 2017 7:20 pm

I believe the syntax for that is gonna be "self.plugin.variableName". I'd have to check on a pc for sure.

So, in plugin base initialize as self.clientID . Then within the action base use self.plugin.clientID .

Take a look at some of the other plugins on your system for a quick example.

User avatar
yokel22
Experienced User
Posts: 265
Joined: Thu Feb 05, 2015 5:56 pm
Location: U.S. - Kansas city

Re: How can I use values from def Configure() in an eg.ActionBase class?

Post by yokel22 » Fri Oct 13, 2017 7:50 pm

Take a look at this plugin here. It should help clarify a bit.
Attachments
__init__.py
(27.54 KiB) Downloaded 61 times

Septik
Posts: 39
Joined: Sun Feb 15, 2015 1:29 pm

Re: How can I use values from def Configure() in an eg.ActionBase class?

Post by Septik » Fri Oct 13, 2017 8:54 pm

yokel22 wrote:
Fri Oct 13, 2017 7:20 pm
I believe the syntax for that is gonna be "self.plugin.variableName". I'd have to check on a pc for sure.

So, in plugin base initialize as self.clientID . Then within the action base use self.plugin.clientID .

Take a look at some of the other plugins on your system for a quick example.
Thanks! :)

Post Reply