I am creating a basic plugin for implementing notifications from my Raspberry Pi / Arduino home automation through my Beyonwiz T4. As far as the coding on the Arduino / Pi side I am fine and have gone with the writing to a file on the T4 (/tmp/test) which then displays Text on screen with the related information from the file. Note: Arduino / Pi checks that the T4 is on and the current Activity (through Harmony API Hack) before posting the file.
What I need help on is the following
1. How do I make the plugin start automatically on bootup
2. How do I put the Main routine in a loop checking for the file (in the background). Currently when I run the plugin it checks immediately for the file and then seemingly the app closes (I want it to run the Main routine indefinitely. I did try a while loop but it appears to crash the T4. Would like to sort this before I sort point 1 so that if the plugin crashes at least I don't have issues with bootup whilst I get it all functional but if programs on a loop only works for autostart .
3. Lastly I want the message to display for a set time period and then disappear
The code I am using currently has been taken from IhadTutorial and modified to start to suit my needs
Code: Select all
# Ihad.tv enigma2-plugin tutorial 2010
# lesson 3
# by emanuel
from Screens.Screen import Screen
from Components.Label import Label
from Components.ActionMap import ActionMap
from Screens.MessageBox import MessageBox
from Plugins.Plugin import PluginDescriptor
import os
global msgx
###########################################################################
class CallMyMsg(Screen):
skin = """
<screen position="10,50" size="460,75" title="Home System Update" >
<widget name="myLabel" position="10,5" size="400,20" font="Regular;20"/>
</screen>"""
def __init__(self, session, args = 0):
self.session = session
Screen.__init__(self, session)
self["myLabel"] = Label(_(msgx))
self["myActionMap"] = ActionMap(["SetupActions"],
{
"ok": self.myMsg,
"cancel": self.cancel
}, -1)
def callMyMsg(self, result):
print "\n[CallMyMsg] checking result\n"
if result:
print "\n[CallMyMsg] cancel\n"
self.close(None)
else:
self.session.open(MessageBox,_("Ah, you like the Ihad plugin!\n;-)"), MessageBox.TYPE_INFO)
def myMsg(self):
print "\n[CallMyMsg] OK pressed \n"
self.session.openWithCallback(self.callMyMsg, MessageBox, _("Do you want to exit the plugin?"), MessageBox.TYPE_YESNO)
def cancel(self):
print "\n[CallMyMsg] cancel\n"
self.close(None)
###########################################################################
def main(session, **kwargs):
global msgx
if os.path.isfile('/tmp/test'):
msgfile = open('/tmp/test')
msgx = msgfile.read()
msgfile.close()
os.remove('/tmp/test')
session.open(CallMyMsg)
###########################################################################
def Plugins(**kwargs):
return PluginDescriptor(
name="00 Craig Test",
description="Adapted from IHADTutorial",
where = PluginDescriptor.WHERE_PLUGINMENU,
icon="../ihad_tut.png",
fnc=main)