How to use the octoprint.plugin.TemplatePlugin function in OctoPrint

To help you get started, we’ve selected a few OctoPrint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tjjfvi / OctoPrint-IFTTT / octoprint_IFTTT / __init__.py View on Github external
# coding=utf-8
from __future__ import absolute_import

import octoprint
import requests

class IFTTTplugin(
	octoprint.plugin.StartupPlugin,
	octoprint.plugin.SettingsPlugin,
    octoprint.plugin.AssetPlugin,
    octoprint.plugin.TemplatePlugin,
	octoprint.plugin.EventHandlerPlugin,
):
	def on_after_startup(self):
		self._storage_interface = self._file_manager._storage("local")

	def on_event(self, event_name, event_payload):
		events = self._settings.get(["events"])
		default_prefixes = self._settings.get(["default_prefixes"])
		makerkeys = self._settings.get(["makerkeys"])


		for event in events:
			if event["event_name"] != event_name: continue

			trigger_names = event["trigger_names"]
github michaelnew / Octoprint-Print-Queue / octoprint_print_queue / __init__.py View on Github external
# coding=utf-8
from __future__ import absolute_import

import octoprint.plugin
from pprint import pprint
from octoprint.server import printer, NO_CONTENT
import flask, json
import os

class PrintQueuePlugin(octoprint.plugin.StartupPlugin,
    octoprint.plugin.TemplatePlugin,
    octoprint.plugin.SettingsPlugin,
    octoprint.plugin.AssetPlugin,
    octoprint.plugin.BlueprintPlugin,
    octoprint.plugin.EventHandlerPlugin):

    printqueue = []
    selected_file = ""
    uploads_dir = "/home/pi/.octoprint/uploads/"

# StartupPlugin
    def on_after_startup(self):
        self._print_queue_file_path = os.path.join(self.get_plugin_data_folder(), "print_queue.yaml")
        self._configuration_dict = None
        self._getConfigurationFile()

# BluePrintPlugin (api requests)
github jneilliii / OctoPrint-YouTubeLive / octoprint_youtubelive / __init__.py View on Github external
# coding=utf-8
from __future__ import absolute_import

import octoprint.plugin

class youtubelive(octoprint.plugin.StartupPlugin,
				octoprint.plugin.TemplatePlugin,
				octoprint.plugin.AssetPlugin,
                octoprint.plugin.SettingsPlugin):
	
	##~~ StartupPlugin
	def on_after_startup(self):
		self._logger.info("OctoPrint-YouTubeLive loaded!")
	
	##~~ TemplatePlugin
	def get_template_configs(self):
		return [dict(type="settings",custom_bindings=True)]
		
	##~~ AssetPlugin
	def get_assets(self):
		return dict(
			js=["js/youtubelive.js"],
			css=["css/youtubelive.css"]
github eyal0 / OctoPrint-PrintTimeGenius / octoprint_PrintTimeGenius / __init__.py View on Github external
function, restart the timer.  This means that if there is a string of calls
     to the decorated function such that each call is less than 5 seconds apart,
     only the last one will happen."""
  def new_decorator(f, *args, **kwargs):
    def to_do_later(*args, **kwargs):
      if to_do_later.__timer is not None:
        to_do_later.__timer.cancel()
      to_do_later.__timer = Timer(seconds, f, args, kwargs)
      to_do_later.__timer.start()
    to_do_later.__timer = None
    return to_do_later
  return new_decorator

class PrintTimeGeniusPlugin(octoprint.plugin.SettingsPlugin,
                            octoprint.plugin.AssetPlugin,
                            octoprint.plugin.TemplatePlugin,
                            octoprint.plugin.StartupPlugin,
                            octoprint.plugin.ShutdownPlugin,
                            octoprint.plugin.EventHandlerPlugin,
                            octoprint.plugin.BlueprintPlugin):
  def __init__(self):
    self._logger = logging.getLogger(__name__)
    self._current_history = {}
    dd = lambda: defaultdict(dd)
    self._current_config = PrinterConfig() # dict of timing-relevant config commands
    self._old_printer_config = self._current_config.as_list() # Cache of the config that is on disk.

  ##~~ SettingsPlugin mixin
  def get_settings_defaults(self):
    current_path = os.path.dirname(os.path.realpath(__file__))
    built_in_analyzers = [
        (gettext("All gcode analyzers (usually not as good as marlin-calc)"),
github MoonshineSG / OctoPrint-MultiColors / octoprint_multi_colors / __init__.py View on Github external
import logging

from flask import jsonify
import os.path
from os import linesep
import datetime
import mmap
import re
import contextlib
from shutil import copyfile
import os
import io

class MultiColorsPlugin(octoprint.plugin.AssetPlugin,
					octoprint.plugin.SimpleApiPlugin,
					octoprint.plugin.TemplatePlugin,
					octoprint.plugin.SettingsPlugin):

	def initialize(self):
		#self._logger.setLevel(logging.DEBUG)
		self.gcode_file = os.path.join(self.get_plugin_data_folder(),"gcode.txt")
		self.regex_file = os.path.join(self.get_plugin_data_folder(),"regex.txt")
		self._logger.info("MultiColors init")

	def get_template_configs(self):
		return [
			dict(type="tab", template="multi_colors_tab.jinja2", custom_bindings=True)
		]

	def get_assets(self):
		return dict(
			js=["js/multi_colors.js"]
github marian42 / octoprint-preheat / octoprint_preheat / __init__.py View on Github external
import octoprint.plugin
from octoprint.util.comm import strip_comment
from octoprint.printer import PrinterInterface

import flask
import time
from threading import Thread

__plugin_pythoncompat__ = ">=2.7,<4"

class PreheatError(Exception):
	def __init__(self, message):
		super(PreheatError, self).__init__(message)
		self.message = message

class PreheatAPIPlugin(octoprint.plugin.TemplatePlugin,
					   octoprint.plugin.SimpleApiPlugin,
					   octoprint.plugin.AssetPlugin,
					   octoprint.plugin.SettingsPlugin):
	
	def get_settings_defaults(self):
		return dict(enable_tool = True,
					enable_bed = True,
					enable_chamber = True,
					fallback_tool = 0,
					fallback_bed = 0,
					fallback_chamber = 0,
					wait_for_bed = False,
					on_start_send_gcode = False,
					on_start_send_gcode_command = "M117 Preheating... ; Update LCD",
					on_complete_show_popup = False,
					on_conplete_send_gcode = False,
github OutsourcedGuru / OctoPrint-GitFiles / octoprint_gitfiles / __init__.py View on Github external
# coding=utf-8
from __future__ import absolute_import
from subprocess import check_output
from subprocess import call
from octoprint.settings import settings, valid_boolean_trues
import octoprint.plugin
import os

class GitfilesPlugin(octoprint.plugin.SettingsPlugin,
                     octoprint.plugin.AssetPlugin,
										 octoprint.plugin.SimpleApiPlugin,
                     octoprint.plugin.TemplatePlugin):

	def get_settings_defaults(self):
		return dict(url="https://github.com/YourUserID/YourRepository.git", path="gitfiles")

	def get_template_vars(self):
		return dict(url=self._settings.get(["url"]), path=self._settings.get(["path"]))

	def get_template_configs(self):
		return [dict(type="settings", custom_bindings=False)]

	def get_assets(self):
		return dict(
			js=["js/gitfiles.js"],
			css=["css/gitfiles.css"],
			less=["less/gitfiles.less"]
		)
github adilinden-oss / octoprint-webcamstreamer / octoprint_webcamstreamer / __init__.py View on Github external
from __future__ import absolute_import

### (Don't forget to remove me)
# This is a basic skeleton for your plugin's __init__.py. You probably want to adjust the class name of your plugin
# as well as the plugin mixins it's subclassing from. This is really just a basic skeleton to get you started,
# defining your plugin as a template plugin, settings and asset plugin. Feel free to add or remove mixins
# as necessary.
#
# Take a look at the documentation on what other plugin mixins are available.

import octoprint.plugin
from octoprint.server import user_permission
import docker

class WebcamStreamerPlugin(octoprint.plugin.StartupPlugin,
                           octoprint.plugin.TemplatePlugin,
                           octoprint.plugin.AssetPlugin,
                           octoprint.plugin.SettingsPlugin,
                           octoprint.plugin.SimpleApiPlugin,
                           octoprint.plugin.EventHandlerPlugin):

    def __init__(self):
        # Docker connection and container object
        self.client = None
        self.image = None
        self.container = None
    
        self.frame_rate_default = 5
        self.ffmpeg_cmd_default = (
            "ffmpeg -re -f mjpeg -framerate 5 -i {webcam_url} "                                                                   # Video input
            "-ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero "                                               # Audio input
            "-acodec aac -ab 128k "                                                                                        # Audio output
github google / OctoPrint-TemperatureFailsafe / octoprint_TemperatureFailsafe / __init__.py View on Github external
# See the License for the specific language governing permissions and
# limitations under the License.
#
# coding=utf-8

from __future__ import absolute_import

import octoprint.plugin
from octoprint.util import RepeatedTimer
from easyprocess import EasyProcess

class TemperatureFailsafe(octoprint.plugin.AssetPlugin,
						  octoprint.plugin.SettingsPlugin,
						  octoprint.plugin.ShutdownPlugin,
						  octoprint.plugin.StartupPlugin,
						  octoprint.plugin.TemplatePlugin):

	def __init__(self):
		self._checkTempTimer = None

	def _restartTimer(self):
		# stop the timer
		if self._checkTempTimer:
			self._logger.debug(u"Stopping Timer...")
			self._checkTempTimer.cancel()
			self._checkTempTimer = None

		# start a new timer
		interval = self._settings.get_int(['interval'])
		if self._settings.get_boolean(['enabled']) and interval:
			self._logger.debug(u"Starting Timer...")
			self._checkTempTimer = RepeatedTimer(interval, self.CheckTemps, None, None, True)