Hello guys.
First of all, I'm pretty good with python, but totally new with javascript.
I'm trying to create a small plugin. After doing all the tutorial.. Of course we learn about javascript and python. But getting all the informations (properties/variables) about the printer/job is missing.
1. How can I open a tab page after I click a button in a sidebar. I know how to create a sidebar and a tab. Do I need to do it in javascript before it's the frontend? Or python (octoprint) can redirect? I can find the baseurl with:
@property
def get_url_tab(self):
return "#tab_" + self.template_folder_key
If I need to use javascript, how do i send the url from python to js? For now I use a static url:
$(function() {
function MyPluginViewModel(parameters) {
var self = this;
self.settings = parameters[0]
self.baseurl = OctoPrint.options.baseurl
self.test = function(data) {
//OctoPrint.simpleApiCommand("myplugin", "test");
window.open(self.baseurl + "#tab_plugin_myplugin", "_self")
};
}
OCTOPRINT_VIEWMODELS.push({
construct: MyPluginViewModel,
elements: ["#test"]
});
});
Is it the good way?
2. Where can I find the job (or file selected) ?
Exemple of Sidebar STATE:
I tried to search the behavior of /template/sidebar/state.jinja2
But i never saw the init.py file for this template. (Just to see how the file is found with all the informations needed..)
Do I need to use the EventHandlerPlugin with on_event?
We can see that the file is selected with:
def on_event(self, event, payload):
if event == octoprint.events.Events.FILE_SELECTED:
self._logger.info("File Selected =>", payload)
print("JOB:", self._printer.get_current_job())
But I think there is a better way. Because if I'm searching with self._printer.get_current_job() it find nothing. Might be because the Event is done before the file is selected.
I have so much questions. The communications between javascript and python is in a learning curve
Thanks for your help.