Page 1 of 1
Pass an eg.globals variable to a plugin?
Posted: Fri Jan 27, 2012 2:00 pm
by speedreeder
I'm trying to modify a plugin so that it will accept an eg.globals variable that is created by a python script when it's macro gets run. I worked the variable into the _init_.py file, but that only gets called when adding the plugin, so it only uses whatever value the variable is when the plugin gets added. How do I make that more dynamic? The plugin runs an action at the end of the macro that needs the updated variable value, but it just keeps giving me the old value.
Confusing, I know.
Re: Pass an eg.globals variable to a plugin?
Posted: Fri Jan 27, 2012 2:47 pm
by Pako
You've probably not read this post:
viewtopic.php?f=10&t=604&start=15#p10256.
Bitmonster wrote:The eg.globals namespace is exclusive for the user's Python scripts and commands.
You probably know that just Bitmonster is the author of this program.
He probably knew why he wrote it.
You'd have to try to find some other way.
What plugin is it?
What do you want to do?
But it is possible that you just do some mistake and it can work.
We can not help you if we do not know anything about it.
Pako
Re: Pass an eg.globals variable to a plugin?
Posted: Fri Jan 27, 2012 7:08 pm
by speedreeder
Oh hey, I have no problem with how the program is written. I'm sure there's a reason for how it is. The plugin is
Google Voice by cfull1. It's a little old, so I've been trying to make some improvements for my own use.
Specifically, I've been trying to incorporate it as part of my TV download macro, so that when a new episode is downloaded it sends me an SMS including the name of the episode. I have a python script that (among other things) stores the name of the episode in eg.globals.FileName. I then added some code to the _init_.py that modified the "Send SMS" action so that it would recognize the user input of '%n' in the message box and then substitute eg.globals.FileName variable for it (see the while panel.Affirmed() towards the bottom):
Code: Select all
class SendSMS(eg.ActionBase):
text = Text
def __call__(self, number='', msg=''):
try:
self.plugin.voice.send_sms(number, msg)
except Exception,e:
print str(e)
print "Number is not valid"
def Configure(self, number="", msg=""):
FileNameCheck = 0
theTime = strftime("%H:%M:%S", localtime())
try:
eg.globals.FileName
except (NameError, AttributeError):
FileNameCheck = 1
text = self.text
panel = eg.ConfigPanel()
numCtrl = panel.TextCtrl(number)
msgCtrl = panel.TextCtrl(msg, style=wx.TE_MULTILINE)
msgCtrl.SetMinSize((-1, 100))
#msgCtrl.SetMaxSize((-1, 60))
number = panel.StaticText(text.number)
message = panel.StaticText("Message \n%n = eg.globals.FileName\n%t = Current Time")
panel.sizer.Add(number, 0, wx.EXPAND)
panel.sizer.Add((5, 5))
panel.sizer.Add(numCtrl, 0, wx.EXPAND)
panel.sizer.Add((5, 5))
panel.sizer.Add(message, 0, wx.EXPAND)
panel.sizer.Add((5, 5))
panel.sizer.Add(msgCtrl, 0, wx.EXPAND)
panel.sizer.Add((5, 5))
while panel.Affirmed():
preMsg = msgCtrl.GetValue()
if FileNameCheck == 0:
a = re.sub(r'%n', eg.globals.FileName, preMsg)
b = re.sub(r'%t', theTime, a)
panel.SetResult(numCtrl.GetValue(),b)
How can I get this variable into the plugin, without using eg.globals? Perhaps some Get method?
Re: Pass an eg.globals variable to a plugin?
Posted: Fri Jan 27, 2012 7:37 pm
by speedreeder
Figured it out! I just made a python command to send the SMS, instead of using the action:
Totally forgot that you can get the Python version of an action by creating the action and then copying it into a text editor. You can then call that in a Python script by using the "eg.plugins" syntax.
Code: Select all
import eg
message = eg.globals.FileName + " is ready."
eg.plugins.GoogleVoice.SendSMS(u'1112223333', message)
Re: Pass an eg.globals variable to a plugin?
Posted: Sat Jan 28, 2012 7:13 am
by Pako
Correctly it should be done like this:
Code: Select all
class SendSMS(eg.ActionBase):
def __call__(self, number='', msg='', flnm=''):
try:
from time import strftime, localtime
msg = msg.replace("%n",eg.ParseString(flnm))
msg = msg.replace("%t",strftime("%H:%M:%S", localtime()))
self.plugin.voice.send_sms(number, eg.ParseString(msg))
except Exception,e:
print str(e)
print "Number is not valid"
def Configure(self, number="", msg="", flnm=""):
panel = eg.ConfigPanel()
numCtrl = panel.TextCtrl(number)
filenameCtrl = panel.TextCtrl(flnm)
msgCtrl = panel.TextCtrl(msg, style=wx.TE_MULTILINE)
msgCtrl.SetMinSize((-1, 100))
#msgCtrl.SetMaxSize((-1, 60))
number = panel.StaticText("Number")
filename = panel.StaticText("Filename")
message = panel.StaticText("Message (%n = Filename, %t = Current Time)")
panel.sizer.Add(number, 0, wx.EXPAND)
panel.sizer.Add((-1, 2))
panel.sizer.Add(numCtrl, 0, wx.EXPAND)
panel.sizer.Add((-1, 10))
panel.sizer.Add(filename, 0, wx.EXPAND)
panel.sizer.Add((-1, 2))
panel.sizer.Add(filenameCtrl, 0, wx.EXPAND)
panel.sizer.Add((-1, 10))
panel.sizer.Add(message, 0, wx.EXPAND)
panel.sizer.Add((-1, 2))
panel.sizer.Add(msgCtrl, 0, wx.EXPAND)
while panel.Affirmed():
panel.SetResult(
numCtrl.GetValue(),
msgCtrl.GetValue(),
filenameCtrl.GetValue(),
)

Never would have an expression like eg.globals occur in the plugin source text !
Pako