Weather plugin system (need help)
#1
I've added checks so you don't try and run the script/plugin more than once. this may not be the best way, but i don't want to block xbmc at any time.

what i need now is a delay. say you're flipping thru the locations, i want to wait 500msec or so before the script is launched.

i'm not sure how to do this.

here is a diff and a picture of it in action.

PHP Code:
Indexxbmc/GUIWindowWeather.cpp
===================================================================
--- 
xbmc/GUIWindowWeather.cpp (revision 18588)
+++ 
xbmc/GUIWindowWeather.cpp (working copy)
@@ -
26,+26,@@
 
#include "GUISettings.h"
 #include "GUIWindowManager.h"
 #include "Util.h"
+#include "lib/libPython/XBPython.h"
 
 #define CONTROL_BTNREFRESH             2
 #define CONTROL_SELECTLOCATION         3
@@ -120,+121,@@
     {
       
UpdateLocations();
       
SetProperties();
+      
CallPlugin();
     }
     break;
   }
@@ -
242,+244,10 @@
 
 
void CGUIWindowWeather::SetProperties()
 {
-  
CStdString fanartcode;
+  
// we only want to clear properties if location is different
+  if (!GetProperty("Location").Equals(g_weatherManager.GetLocation(m_iCurWeather)))
+    
ClearProperties();
+
   
// Current weather
   
SetProperty("Location"g_weatherManager.GetLocation(m_iCurWeather));
   
CStdString strSetting;
@@ -
257,+262,@@
   
SetProperty("Current.Wind"g_weatherManager.GetInfo(WEATHER_LABEL_CURRENT_WIND));
   
SetProperty("Current.DewPoint"g_weatherManager.GetInfo(WEATHER_LABEL_CURRENT_DEWP));
   
SetProperty("Current.Humidity"g_weatherManager.GetInfo(WEATHER_LABEL_CURRENT_HUMI));
-  
fanartcode CUtil::GetFileName(g_weatherManager.GetInfo(WEATHER_IMAGE_CURRENT_ICON));
+  
// we use the icons code number for fanart as it's the safest way
+  CStdString fanartcode CUtil::GetFileName(g_weatherManager.GetInfo(WEATHER_IMAGE_CURRENT_ICON));
   
CUtil::RemoveExtension(fanartcode);
   
SetProperty("Current.FanartCode"fanartcode);
 
@@ -
276,+282,29 @@
     
SetProperty(day "FanartCode"fanartcode);
   }
 }
+
+
void CGUIWindowWeather::CallPlugin()
+{
+  if (!
g_guiSettings.GetString("weather.pluginpath"false).empty())
+  {
+    
CStdString strSetting;
+    
strSetting.Format("weather.areacode%i"m_iCurWeather 1);
+    const 
CStdString &areacode g_weatherManager.GetAreaCode(g_guiSettings.GetString(strSetting)).c_str();
+
+    
unsigned int argc 2;
+    
char ** argv = new char*[argc];
+    
argv[0] = (char*)g_guiSettings.GetString("weather.pluginpath"false).c_str();
+    
argv[1] = (char*)areacode.c_str();
+
+    
int id g_pythonParser.getScriptId(argv[0]);
+    if (
id != -&& g_pythonParser.isRunning(id))
+    {
+      
CLog::Log(LOGDEBUG"%s - Weather plugin cancelled: %s"__FUNCTION__argv[0]);
+      
g_pythonParser.stopScript(id);
+    }
+
+    
g_pythonParser.evalFile(argv[0], argc, (const char**)argv);
+
+    
CLog::Log(LOGDEBUG"%s - Weather plugin called: %s (%s)"__FUNCTION__argv[0], argv[1]);
+  }
+}
Indexxbmc/GUIWindowWeather.h
===================================================================
--- 
xbmc/GUIWindowWeather.(revision 18588)
+++ 
xbmc/GUIWindowWeather.(working copy)
@@ -
38,+38,10 @@
   
void UpdateButtons();
   
void UpdateLocations();
   
void SetProperties();
+  
void CallPlugin();
 
   
void Refresh();
 
   
unsigned int m_iCurWeather;
+
 }; 

Image
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#2
do i need to do it the way skin loading works?

something like g_application.DelayLoadSkin();

also could/should i move this into weather.cpp
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#3
In where you have callplugin you'd start a timer (CStopWatch) at zero via StartZero() and then check for it in Render() and, if passed 500ms launch the script and stop the timer, resetting it to zero.

Cheers,
Jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#4
thanks jmarshall.

now i have the issue where that lovely script error dialog pops up when i call
g_pythonParser.stopScript(id);

is there anyway to silence that? it may be causing issues. sometimes xbmc wants to close out. i don't know if it's that dialog or not causing it.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#5
It seems to actually work fine and better with out cancelling the script.

Maybe I should just let it run. The scripter should as i do in the script cache the data and only update when necessary anyways.

Do you see any problems with launching the script multiple times?

i have a 1000 msec timer, so if they go thru them fast the script never launches. i'm not sure how to handle if the callplugin() calls stack up.

it the lyrics script i can check if the song has changed and if cancel the call, but that's not multi threaded.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#6
WeatherPlugin.diff:

This is the last version. it adds checks and a timer. it seems to work pretty smoothly.

the CallPlugin() function will wait 1000 msec before launching and reset when the location changes when in the weather window. it will run immediately when not in the weather window.

if you are in the weather window and the plugin is running, it will keep resetting the timer instead of closing the plugin. maybe it could do both? i was getting the script error dialog when i was force closing the script, but might have been other issue.

i have a test plugin if you would like to see it in action. it is not complete. I've separated MyWeather.xml into separate files, i can send that also.

it uses the exiting plugin schema sort of. basically it's just a script in special://home/plugins/weather/

http://trac.xbmc.org/ticket/5815#comment:15

feedback would be good even if you don't want to include it as i need it it my builds and want it to work right.

http://trac.xbmc.org/attachment/ticket/5...lugin.diff
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply

Logout Mark Read Team Forum Stats Members Help
Weather plugin system (need help)0