Hi, jneilliii,
I tried to mimic the example with following:
- create a
update_time
functionin __ init __.py
- I put this function inside
on_after_startup(self)
- in javascript file, I created a
onDataUpdaterPluginMessage
function, and set the time_data variable from the python script to self.timeData()
, a ko.observable()
- And then reference the ko.observable in tab jinja2
Problem:
If I set breakpoint in javascript on line self.timeData(data.time_data())
using Firefox's Web Developer's Debugger, I can actually see time_data() has successfully stored the time.time() variable, but it is still not showing in the actual tab.
Is it because "on_after_startup" only gets to run once?
Content of __ init __.py
def get_current_time(self):
return time.time()
def update_time(self):
self._plugin_manager.send_plugin_message(self._identifier, dict(time_data=self.get_current_time()))
def on_after_startup(self):
self.update_time()
Content of javascript
self.timeData = ko.observable();
self.onDataUpdaterPluginMessage = function (plugin, data) {
if (plugin !== "AutoBedLevelChecker") {
return;
}
if (typeof plugin == 'undefined'){
return;
}
if(self.settingsOpen){
return;
}
if (data.hasOwnProperty("time_data")) {
self.timeData(data.time_data())
}
}
Content of tab.jinja2
<p> timeData: <strong data-bind="text: timeData"></strong></p>