From 2d54ab5fcfaf303f5591920bef5302b7a066939e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 30 Mar 2015 22:08:10 +0200 Subject: [PATCH 1/6] Fix: identifer => identifier (is it really that hard to type foosel?) --- src/octoprint/plugin/__init__.py | 2 +- src/octoprint/server/api/settings.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/octoprint/plugin/__init__.py b/src/octoprint/plugin/__init__.py index 96cd50d5a..5b2bdea04 100644 --- a/src/octoprint/plugin/__init__.py +++ b/src/octoprint/plugin/__init__.py @@ -188,7 +188,7 @@ class PluginSettings(object): Arguments: settings (Settings): The :class:`~octoprint.settings.Settings` instance on which to operate. - plugin_key (str): The plugin identifer of the plugin for which to create this instance. + plugin_key (str): The plugin identifier of the plugin for which to create this instance. defaults (dict): The plugin's defaults settings, will be used to determine valid paths within the plugin's settings structure diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py index f290d61ae..ce8382579 100644 --- a/src/octoprint/server/api/settings.py +++ b/src/octoprint/server/api/settings.py @@ -225,7 +225,7 @@ def setSettings(): if "plugins" in data: for plugin in octoprint.plugin.plugin_manager().get_implementations(octoprint.plugin.SettingsPlugin): - plugin_id = plugin._identifer + plugin_id = plugin._identifier if plugin_id in data["plugins"]: plugin.on_settings_save(data["plugins"][plugin_id]) From c9f54765883836386c008584f65c9250644be208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 31 Mar 2015 18:20:44 +0200 Subject: [PATCH 2/6] Settings now allow providing a custom "config" dict to work on Can be used to always retrieve the defaults (by providing an empty config dict) or to utilize the get method with other settings than the system settings. --- src/octoprint/settings.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 4ba776a45..5d3d57936 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -757,13 +757,14 @@ class Settings(object): #~~ getter - def get(self, path, asdict=False, defaults=None, preprocessors=None, merged=False): + def get(self, path, asdict=False, config=None, defaults=None, preprocessors=None, merged=False): import octoprint.util as util if len(path) == 0: return None - config = self._config + if config is None: + config = self._config if defaults is None: defaults = default_settings if preprocessors is None: @@ -820,7 +821,7 @@ class Settings(object): else: return results - def getInt(self, path, defaults=None, preprocessors=None): + def getInt(self, path, config=None, defaults=None, preprocessors=None): value = self.get(path, defaults=defaults, preprocessors=preprocessors) if value is None: return None @@ -831,8 +832,8 @@ class Settings(object): self._logger.warn("Could not convert %r to a valid integer when getting option %r" % (value, path)) return None - def getFloat(self, path, defaults=None, preprocessors=None): - value = self.get(path, defaults=defaults, preprocessors=preprocessors) + def getFloat(self, path, config=None, defaults=None, preprocessors=None): + value = self.get(path, config=config, defaults=defaults, preprocessors=preprocessors) if value is None: return None @@ -842,8 +843,8 @@ class Settings(object): self._logger.warn("Could not convert %r to a valid integer when getting option %r" % (value, path)) return None - def getBoolean(self, path, defaults=None, preprocessors=None): - value = self.get(path, defaults=defaults, preprocessors=preprocessors) + def getBoolean(self, path, config=None, defaults=None, preprocessors=None): + value = self.get(path, config=config, defaults=defaults, preprocessors=preprocessors) if value is None: return None if isinstance(value, bool): From 8a3993ca592406ca82b4345c38b61c054e8c2d48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 31 Mar 2015 18:22:38 +0200 Subject: [PATCH 3/6] To determine order of template components, first use user order, then default order, then type ordering Also moved suffix calculation for template keys into _process_template_config --- src/octoprint/server/__init__.py | 33 ++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index 2a625d5dc..0f430acfa 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -311,8 +311,7 @@ def index(): else: data = include[1] - suffix = data["suffix"] if "suffix" in data else "" - key = "plugin_" + name + suffix + key = data["_key"] if "replaces" in data: key = data["replaces"] templates[t]["entries"][key] = include @@ -324,25 +323,38 @@ def index(): # 2) we have all entries located somewhere within the order for t in template_types: + default_order = settings().get(["appearance", "components", "order", t], merged=True, config=dict()) configured_order = settings().get(["appearance", "components", "order", t], merged=True) configured_disabled = settings().get(["appearance", "components", "disabled", t]) + + # first create the ordered list of all component ids according to the configured order templates[t]["order"] = [x for x in configured_order if x in templates[t]["entries"] and not x in configured_disabled] + # now append the entries from the default order that are not already in there + templates[t]["order"] += [x for x in default_order if not x in templates[t]["order"] and x in templates[t]["entries"] and not x in configured_disabled] + all_ordered = set(templates[t]["order"]) all_disabled = set(configured_disabled) + # check if anything is missing, if not we are done here missing_in_order = set(templates[t]["entries"].keys()).difference(all_ordered).difference(all_disabled) if len(missing_in_order) == 0: continue + # finally add anything that's not included in our order yet sorted_missing = list(missing_in_order) if not t == "navbar" and not t == "generic": + # anything but navbar and generic components get sorted by their name sorted_missing = sorted(missing_in_order, key=lambda x: templates[t]["entries"][x][0]) + if t == "navbar": + # additional navbar components are prepended templates[t]["order"] = sorted_missing + templates[t]["order"] elif t == "sidebar" or t == "tab" or t == "generic" or t == "usersettings": + # additional sidebar, generic or usersettings components are appended templates[t]["order"] += sorted_missing elif t == "settings": + # additional settings items are added to the plugin section templates[t]["entries"]["section_plugins"] = (gettext("Plugins"), None) templates[t]["order"] += ["section_plugins"] + sorted_missing @@ -432,27 +444,32 @@ def _process_template_config(name, implementation, rule, config=None, counter=1) config = dict() data = dict(config) + if not "suffix" in data and counter > 1: + data["suffix"] = "_%d" % counter + if "div" in data: data["_div"] = data["div"] elif "div" in rule: data["_div"] = rule["div"](name) if "suffix" in data: - data["_div"] += "_" + data["suffix"] - elif counter > 1: - data["_div"] += "_%d" % counter - data["suffix"] = "_%d" % counter - else: - data["suffix"] = "" + data["_div"] = data["_div"] + data["suffix"] + if not "template" in data: data["template"] = rule["template"](name) + if not "name" in data: data["name"] = implementation._plugin_name + if not "custom_bindings" in data or data["custom_bindings"]: data_bind = "allowBindings: true" if "data_bind" in data: data_bind = data_bind + ", " + data["data_bind"] data["data_bind"] = data_bind + data["_key"] = "plugin_" + name + if "suffix" in data: + data["_key"] += data["suffix"] + return data @app.route("/robots.txt") From 5c228e6071cb6a188bbc65357fe29124025e1b13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 31 Mar 2015 18:23:18 +0200 Subject: [PATCH 4/6] [Doc] Big overhaul of TemplatePlugin docs & component ordering --- docs/configuration/config_yaml.rst | 145 ++++++++++++++- docs/plugins/gettingstarted.rst | 2 +- docs/plugins/templates.rst | 98 +++++++++- src/octoprint/plugin/types.py | 282 +++++++++++------------------ 4 files changed, 344 insertions(+), 183 deletions(-) diff --git a/docs/configuration/config_yaml.rst b/docs/configuration/config_yaml.rst index 141167965..9efa5f477 100644 --- a/docs/configuration/config_yaml.rst +++ b/docs/configuration/config_yaml.rst @@ -11,6 +11,10 @@ settings. Note that many of these settings are available from the "Settings" menu in OctoPrint itself. +.. contents:: + +.. _sec-configuration-config_yaml-serial: + Serial ------ @@ -52,6 +56,8 @@ Use the following settings to configure the serial connection to the printer: additionalPorts: - /dev/myPrinterSymlink +.. _sec-configuration-config_yaml-server: + Server ------ @@ -95,6 +101,8 @@ Use the following settings to configure the server: `into OctoPrint's wiki `_ for a couple of examples on how to configure this. +.. _sec-configuration-config_yaml-webcam: + Webcam ------ @@ -133,6 +141,8 @@ Use the following settings to configure webcam support: options: interval: 2 +.. _sec-configuration-config_yaml-feature: + Feature ------- @@ -162,6 +172,8 @@ Use the following settings to enable or disable OctoPrint features: # Specifies whether support for SD printing and file management should be enabled sdSupport: true +.. _sec-configuration-config_yaml-folder: + Folder ------ @@ -194,6 +206,8 @@ Use the following settings to set custom paths for folders used by OctoPrint: # and/or sliced objects to print in the future. watched: /path/to/watched/folder +.. _sec-configuration-config_yaml-temperature: + Temperature ----------- @@ -210,21 +224,128 @@ Use the following settings to configure temperature profiles which will be displ extruder: 180 bed: 60 +.. _sec-configuration-config_yaml-appearance: + Appearance ---------- Use the following settings to tweak OctoPrint's appearance a bit to better distinguish multiple instances/printers -appearance: +appearance or to modify the order and presence of the various UI components: .. code-block:: yaml appearance: - # Use this to give your printer a name. It will be displayed in the title bar (as " [OctoPrint]") and in the - # navigation bar (as "OctoPrint: ") - name: My Printer Model + # Use this to give your printer a name. It will be displayed in the title bar + # (as " [OctoPrint]") and in the navigation bar (as "OctoPrint: ") + name: My Printer - # Use this to color the navigation bar. Supported colors are red, orange, yellow, green, blue, violet and default. - color: blue + # Use this to color the navigation bar. Supported colors are red, orange, + # yellow, green, blue, violet and default. + color: default + + # Makes the color of the navigation bar "transparent". In case your printer uses + # acrylic for its frame ;) + colorTransparent: false + + # Configures the order and availability of the UI components + components: + + # Defines the order of the components within their respective containers. + # + # If overridden by the user the resulting order for display will be calculated as + # follows: + # + # - first all components as defined by the user + # - then all enabled core components as define in the default order (see below) + # + # Components not contained within the default order (e.g. from plugins) will be either + # prepended or appended to that result, depending on component type. + # + # Note that a component is not included in the order as defined by the user will still + # be put into the container, according to the default order. To fully disable a + # component, you'll need to add it to the container's disabled list further below. + order: + + # order of navbar items + navbar: + - settings + - systemmenu + - login + + # order of sidebar items + sidebar: + - connection + - state + - files + + # order of tab items + tab: + - temperature + - control + - gcodeviewer + - terminal + - timelapse + + # order of settings, if settings plugins are registered gets extended internally by + # section_plugins and all settings plugins + settings + - section_printer + - serial + - printerprofiles + - temperatures + - terminalfilters + - gcodescripts + - section_features + - features + - webcam + - accesscontrol + - api + - section_octoprint + - folders + - appearance + - logs + + # order of user settings + usersettings: + - access + - interface + + # order of generic templates + generic: [] + + # Disabled components per container. If a component is included here it will not + # be included in OctoPrint's UI at all. Note that this might mean that critical + # functionality will not be available if no replacement is registered. + disabled: + navbar: [], + sidebar: [], + tab: [], + settings: [], + usersettings: [], + generic: [] + +.. note:: + + By modifying the ``components`` > ``order`` lists you may reorder OctoPrint's UI components as you like. You can also + inject Plugins at another than their default location in their respective container by adding the entry + ``plugin_`` where you want them to appear. + + Example: If you want the tab of the :ref:`Hello World Plugin ` to appear as the first tab + in OctoPrint, you'd need to redefine ``components`` > ``order`` > ``tab`` by including something like this in your + ``config.yaml``: + + .. code-block:: yaml + + appearance: + components: + order: + tab: + - plugin_helloworld + + OctoPrint will then turn this into the order ``plugin_helloworld``, ``temperature``, ``control``, ``gcodeviewer``, + ``terminal``, ``timelapse`` plus any other plugins. + +.. _sec-configuration-config_yaml-controls: Controls -------- @@ -249,6 +370,8 @@ OctoPrint. type: command command: M107 +.. _sec-configuration-config_yaml-system: + System ------ @@ -269,6 +392,8 @@ OctoPrint is running is allowed to do this without password entry: command: sudo shutdown -h now confirm: You are about to shutdown the system. +.. _sec-configuration-config_yaml-accesscontrol: + Access Control -------------- @@ -305,6 +430,8 @@ Use the following settings to enable access control: - 127.0.0.0/8 - 192.168.1.0/24 +.. _sec-configuration-config_yaml-events: + Events ------ @@ -326,6 +453,8 @@ Use the following settings to add shell/gcode commands to be executed on certain type: gcode enabled: False +.. _sec-configuration-config_yaml-terminalfilters: + Terminal Filters ---------------- @@ -343,6 +472,8 @@ Use `Javascript regular expressions `_. + +.. _sec-plugins-templates-navbar: + +Navbar +------ + +The right part of the navigation bar located at the top of the UI can be enriched with additional links. Note that +with the current implementation, plugins will always be located *to the left* of the existing links. + +The included template must be called ``_navbar.jinja2`` (e.g. ``myplugin_navbar.jinja2``) unless +overridden by the configuration supplied through :func:`get_template_configs`. + +The template will be already wrapped into the necessary structure, plugins just need to supply the pure content. The +wrapper structure will have all additional classes and styles applied as specified via the configuration supplied +through :func:`get_template_configs`. + +.. _sec-plugins-templates-sidebar: + +Sidebar +------- + +The left side bar containing Connection, State and Files sections can be enriched with additional sections. Note +that with the current implementations, plugins will always be located *beneath* the existing sections. + +The included template must be called ``_sidebar.jinja2`` (e.g. ``myplugin_sidebar.jinja2``) unless +overridden by the configuration supplied through :func:`get_template_configs`. + +The template will be already wrapped into the necessary structure, plugins just need to supply the pure content. The +wrapper divs for both the whole box as well as the content pane will have all additional classes and styles applied +as specified via the configuration supplied through :func:`get_template_configs`. + +.. _sec-plugins-templates-tabs: + +Tabs +---- + +The available tabs of the main part of the interface may be extended with additional tabs originating from within +plugins. Note that with the current implementation, plugins will always be located *to the right* of the existing +tabs. + +The included template must be called ``_tab.jinja2`` (e.g. ``myplugin_tab.jinja2``) unless +overridden by the configuration supplied through :func:`get_template_configs`. + +The template will be already wrapped into the necessary structure, plugins just need to supply the pure content. The +wrapper div and the link in the navigation will have the additional classes and styles applied as specified via the +configuration supplied through :func:`get_template_configs`. + +.. _sec-plugins-templates-settings: + +Settings +-------- + +Plugins may inject a dialog into the existing settings view. Note that with the current implementations, plugins +will always be listed beneath the "Plugins" header in the settings link list, ordered alphabetically after +their displayed name. + +The included template must be called ``_settings.jinja2`` (e.g. ``myplugin_settings.jinja2``) unless +overridden by the configuration supplied through :func:`get_template_configs`. + +The template will be already wrapped into the necessary structure, plugins just need to supply the pure content. The +wrapper div and the link in the navigation will have the additional classes and styles applied as defined via the +supplied configuration supplied through :func:`get_template_configs`. + +.. _sec-plugins-templates-generic: + +Generic +------- + +Plugins may also inject arbitrary templates into the page of the web interface itself, e.g. in order to +add overlays or dialogs to be called from within the plugin's javascript code. + +.. _sec-plugins-templates-replacement: + +Replacing existing components +----------------------------- diff --git a/src/octoprint/plugin/types.py b/src/octoprint/plugin/types.py index fdaff494d..2f38879d0 100644 --- a/src/octoprint/plugin/types.py +++ b/src/octoprint/plugin/types.py @@ -232,218 +232,134 @@ class TemplatePlugin(OctoPrintPlugin): Template injection types in the settings - You can find an example for a simple plugin which injects navbar, sidebar, tab and settings content into the interface in - `the "helloworld" plugin in OctoPrint's collection of plugin examples `_. + You can find an example for a simple plugin which injects navbar, tab and settings content into the interface in + the "helloworld" plugin in OctoPrint's :ref:`Plugin Tutorial `. + + Plugins may replace existing components, see the ``replaces`` keyword in the template configurations returned by + :meth:`.get_template_configs` below. Note that if a plugin replaces a core component, it is the plugin's + responsibility to ensure that all core functionality is still maintained. """ def get_template_configs(self): """ Allows configuration of injected navbar, sidebar, tab and settings templates. Should be a list containing one - configuration object per template to inject. Each configuration object is represented by a dictionary with a mandatory key - ``type`` encoding the template type the configuration is targeting. Possible values here are ``navbar``, ``sidebar``, - ``tab``, ``settings`` and ``generic``. + configuration object per template to inject. Each configuration object is represented by a dictionary which + may contain the following keys: + + .. list-table:: + :widths: 5 95 + + * - type + - The template type the configuration is targeting. Possible values here are ``navbar``, ``sidebar``, + ``tab``, ``settings`` and ``generic``. Mandatory. + * - name + - The name of the component, if not set the name of the plugin will be used. The name will be visible at + a location depending on the ``type``: + + * ``navbar``: unused + * ``sidebar``: sidebar heading + * ``tab``: tab heading + * ``settings``: settings link + * ``generic``: unused + + * - template + - Name of the template to inject, default value depends on the ``type``: + + * ``navbar``: ``_navbar.jinja2`` + * ``sidebar``: ``_sidebar.jinja2`` + * ``tab``: ``_tab.jinja2`` + * ``settings``: ``_settings.jinja2`` + * ``generic``: ``.jinja2`` + + * - suffix + - Suffix to attach to the component identifier and the div identifier of the injected template. Will be + ``_`` if not provided and not the first template of the type, with ``index`` counting from 1 and + increasing for each template of the same type. + + Example: If your plugin with identifier ``myplugin`` defines two tab components like this: + + .. code-block:: python + + return [ + dict(type="tab", template="myplugin_first_tab.jinja2"), + dict(type="tab", template="myplugin_second_tab.jinja2") + ] + + then the first tab will have the component identifier ``plugin_myplugin`` and the second one will have + the component identifier ``plugin_myplugin_2`` (the generated divs will be ``tab_plugin_myplugin`` and + ``tab_plugin_myplugin_2`` accordingly). Notice that the first tab is *not* called ``plugin_myplugin_1`` -- + as stated above while the ``index`` used as default suffix starts counting at 1, it will not be applied + for the first component of a given type. + + If on the other hand your plugin's definition looks like this: + + .. code-block:: python + + return [ + dict(type="tab", template="myplugin_first_tab_jinja2", suffix="_1st"), + dict(type="tab", template="myplugin_second_tab_jinja2", suffix="_2nd") + ] + + then the generated component identifier will be ``plugin_myplugin_1st`` and ``plugin_myplugin_2nd`` + (and the divs will be ``tab_plugin_myplugin_1st`` and ``tab_plugin_myplugin_2nd``). + + * - div + - Id for the div containing the component. If not provided, defaults to ``_plugin_`` plus + the ``suffix`` if provided or required. + * - replaces + - Id of the component this one replaces, might be either one of the core components or a component + provided by another plugin. A list of the core component identifiers can be found + :ref:`in the configuration documentation `. The identifiers of + other plugin components always follow the format described above. + * - custom_bindings + - A boolean value indicating whether the default view model should be bound to the component (``false``) + or if a custom binding will be used by the plugin (``true``, default). + * - data_bind + - Additional knockout data bindings to apply to the component, can be used to add further behaviour to + the container based on internal state if necessary. + * - classes + - Additional classes to apply to the component, as a list of individual classes + (e.g. ``classes=["myclass", "myotherclass"]``) which will be joined into the correct format by the template engine. + * - styles + - Additional CSS styles to apply to the component, as a list of individual declarations + (e.g. ``styles=["color: red", "display: block"]``) which will be joined into the correct format by the template + engine. Further keys to be included in the dictionary depend on the type: - ``navbar`` type - .. figure:: ../images/template-plugin-type-navbar.png - :align: center - :alt: Structure of navbar plugins - - Structure of navbar plugins - - Configures a navbar component to inject. The following keys are supported: - - .. list-table:: - :widths: 5 95 - - * - template - - Name of the template to inject, defaults to ``_navbar.jinja2``. - * - suffix - - Suffix to attach to the element ID of the injected template, will be ``_`` if not provided and not - the first template of the type, with ``index`` counting from 1 and increasing for each template of the same - type. - * - div - - Id for the div containing the component. If not provided, defaults to ``plugin_`` plus - the suffix if provided or required. - * - replaces - - Id of navbar component this one replaces, might be either one of the core components or a component - provided by another plugin. See :ref:`this section ` for more on replacing template components. - * - custom_bindings - - A boolean value indicating whether the default view model should be bound to the navbar entry (``false``) - or if a custom binding will be used by the plugin (``true``, default). - * - data_bind - - Additional knockout data bindings to apply to the navbar entry, can be used to add further behaviour to - the container based on internal state if necessary. - * - classes - - Additional classes to apply to the navbar entry, as a list of individual classes - (e.g. ``classes=["myclass", "myotherclass"]``) which will be joined into the correct format by the template engine. - * - styles - - Additional CSS styles to apply to the navbar entry, as a list of individual declarations - (e.g. ``styles=["color: red", "display: block"]``) which will be joined into the correct format by the template - engine. - ``sidebar`` type - .. figure:: ../images/template-plugin-type-sidebar.png - :align: center - :alt: Structure of sidebar plugins - - Structure of sidebar plugins - - Configures a sidebar component to inject. The following keys are supported: .. list-table:: :widths: 5 95 - * - name - - The name of the sidebar entry, if not set the name of the plugin will be used. * - icon - Icon to use for the sidebar header, should be the name of a Font Awesome icon without the leading ``icon-`` part. - * - template - - Name of the template to inject, defaults to ``_sidebar.jinja2``. * - template_header - Additional template to include in the head section of the sidebar item. For an example of this, see the additional options included in the "Files" section. - * - suffix - - Suffix to attach to the element ID of the injected template, will be ``_`` if not provided and not - the first template of the type, with ``index`` counting from 1 and increasing for each template of the same - type. - * - div - - Id for the div containing the component. If not provided, defaults to ``plugin_`` plus - the suffix if provided or required. - * - replaces - - Id of sidebar component this one replaces, might be either one of the core components or a component - provided by another plugin. See :ref:`this section ` for more on replacing template components. - * - custom_bindings - - A boolean value indicating whether the default view model should be bound to the sidebar container (``false``) - or if a custom binding will be used by the plugin (``true``, default). - * - data_bind - - Additional knockout data bindings to apply to the template container, can be used to add further behaviour to - the container based on internal state if necessary. - * - classes - - Additional classes to apply to both the wrapper around the sidebar box as well as the content pane itself, as a - list of individual classes (e.g. ``classes=["myclass", "myotherclass"]``) which will be joined into the correct - format by the template engine. * - classes_wrapper - Like ``classes`` but only applied to the whole wrapper around the sidebar box. * - classes_content - Like ``classes`` but only applied to the content pane itself. - * - styles - - Additional CSS styles to apply to both the wrapper around the sidebar box as well as the content pane itself, - as a list of individual declarations (e.g. ``styles=["color: red", "display: block"]``) which will be joined - into the correct format by the template engine. * - styles_wrapper - Like ``styles`` but only applied to the whole wrapper around the sidebar box. * - styles_content - Like ``styles`` but only applied to the content pane itself - ``tab`` type - .. figure:: ../images/template-plugin-type-tab.png - :align: center - :alt: Structure of tab plugins - - Structure of tab plugins - - Configures a tab component to inject. The value must be a dictionary, supported values are the following: + ``tab`` type and ``settings`` type .. list-table:: :widths: 5 95 - * - name - - The name under which to include the tab, if not set the name of the plugin will be used. - * - template - - Name of the template to inject, defaults to ``_tab.jinja2``. - * - suffix - - Suffix to attach to the element ID of the injected template, will be ``_`` if not provided and not - the first template of the type, with ``index`` counting from 1 and increasing for each template of the same - type. - * - div - - Id for the div containing the component. If not provided, defaults to ``plugin_`` plus - the suffix if provided or required. - * - replaces - - Id of tab component this one replaces, might be either one of the core components or a component - provided by another plugin. See :ref:`this section ` for more on replacing template components. - * - custom_bindings - - A boolean value indicating whether the default view model should be bound to the tab pane and link - in the navigation (``false``) or if a custom binding will be used by the plugin (``true``, default). - * - data_bind - - Additional knockout data bindings to apply to the template container, can be used to add further behaviour to - the container based on internal state if necessary. - * - classes - - Additional classes to apply to both the wrapper around the sidebar box as well as the content pane itself, as a - list of individual classes (e.g. ``classes=["myclass", "myotherclass"]``) which will be joined into the correct - format by the template engine. * - classes_link - Like ``classes`` but only applied to the link in the navigation. * - classes_content - Like ``classes`` but only applied to the content pane itself. - * - styles - - Additional CSS styles to apply to both the wrapper around the sidebar box as well as the content pane itself, - as a list of individual declarations (e.g. ``styles=["color: red", "display: block"]``) which will be joined - into the correct format by the template engine. * - styles_link - Like ``styles`` but only applied to the link in the navigation. * - styles_content - Like ``styles`` but only applied to the content pane itself. - ``settings`` type - .. figure:: ../images/template-plugin-type-settings.png - :align: center - :alt: Structure of settings plugins - - Structure of settings plugins - - Configures a settings component to inject. The value must be a dictionary, supported values are the following: - - .. list-table:: - :widths: 5 95 - - * - name - - The name under which to include the settings pane, if not set the name of the plugin will be used. - * - template - - Name of the template to inject, defaults to ``_settings.jinja2``. - * - suffix - - Suffix to attach to the element ID of the injected template, will be ``_`` if not provided and not - the first template of the type, with ``index`` counting from 1 and increasing for each template of the same - type. - * - div - - Id for the div containing the component. If not provided, defaults to ``plugin_`` plus - the suffix if provided or required. - * - replaces - - Id of settings component this one replaces, might be either one of the core components or a component - provided by another plugin. See :ref:`this section ` for more on replacing template components. - * - custom_bindings - - A boolean value indicating whether the default settings view model should be bound to the settings pane and link - in the navigation (``false``) or if a custom binding will be used by the plugin (``true``, default). - * - data_bind - - Additional knockout data bindings to apply to the template container, can be used to add further behaviour to - the container based on internal state if necessary. - * - classes - - Additional classes to apply to both the wrapper around the navigation link as well as the content pane itself, as a - list of individual classes (e.g. ``classes=["myclass", "myotherclass"]``) which will be joined into the correct - format by the template engine. - * - classes_link - - Like ``classes`` but only applied to the link in the navigation. - * - classes_content - - Like ``classes`` but only applied to the content pane itself. - * - styles - - Additional CSS styles to apply to both the wrapper around the navigation link as well as the content pane itself, - as a list of individual declarations (e.g. ``styles=["color: red", "display: block"]``) which will be joined - into the correct format by the template engine. - * - styles_link - - Like ``styles`` but only applied to the link in the navigation. - * - styles_content - - Like ``styles`` but only applied to the content pane itself - - ``generic`` type - Configures a generic template to inject. The following keys are supported: - - .. list-table:: - :widths: 5 95 - - * - template - - Name of the template to inject, defaults to ``.jinja2``. - .. note:: As already outlined above, each template type has a default template name (i.e. the default navbar template @@ -452,6 +368,28 @@ class TemplatePlugin(OctoPrintPlugin): those, since the implicit default template will only be included automatically if no other templates of that type are defined. + Example: If you have a plugin that injects two tab components, one defined in the template file + ``myplugin_tab.jinja2`` (the default template) and one in the template ``myplugin_othertab.jinja2``, you + might be tempted to just return the following configuration since one your templates is named by the default + template name: + + .. code-block:: python + + return [ + dict(type="tab", template="myplugin_othertab.jinja2") + ] + + This will only include the tab defined in ``myplugin_othertab.jinja2`` though, ``myplugin_tab.jinja2`` will + not be included automatically since the presence of a defintion for the ``tab`` type overrides the automatic + injection of the default template. You'll have to include it explicitely: + + .. code-block:: python + + return [ + dict(type="tab", template="myplugin_tab.jinja2"), + dict(type="tab", template="myplugin_othertab.jinja2") + ] + :return list: a list containing the configuration options for the plugin's injected templates """ return [] From 8a41cef00b95ddfded8683d1723306f986da151a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 31 Mar 2015 20:08:32 +0200 Subject: [PATCH 5/6] [Doc] Restructured the plugins section so it makes more sense --- docs/features/index.rst | 1 + docs/features/plugins.rst | 64 ++++++++++++++++++++ docs/plugins/concepts.rst | 103 +++++++++++++++++++++++++++++++- docs/plugins/distributing.rst | 45 ++++++++++---- docs/plugins/gettingstarted.rst | 38 ++++++++---- docs/plugins/index.rst | 18 ++---- docs/plugins/infrastructure.rst | 70 ---------------------- docs/plugins/templates.rst | 98 ------------------------------ docs/plugins/using.rst | 44 -------------- src/octoprint/plugin/core.py | 2 +- 10 files changed, 231 insertions(+), 252 deletions(-) create mode 100644 docs/features/plugins.rst delete mode 100644 docs/plugins/infrastructure.rst delete mode 100644 docs/plugins/templates.rst delete mode 100644 docs/plugins/using.rst diff --git a/docs/features/index.rst b/docs/features/index.rst index 29015bf6a..5ebc86208 100644 --- a/docs/features/index.rst +++ b/docs/features/index.rst @@ -10,3 +10,4 @@ Features custom_controls.rst gcode_scripts.rst action_commands.rst + plugins.rst diff --git a/docs/features/plugins.rst b/docs/features/plugins.rst new file mode 100644 index 000000000..7d574824e --- /dev/null +++ b/docs/features/plugins.rst @@ -0,0 +1,64 @@ +.. _sec-features-plugins: + +******* +Plugins +******* + +Starting with OctoPrint 1.2.0, there's now a plugin system in place which allows to individually +extend OctoPrint's functionality. + +Right now plugins can be used to extend OctoPrint's web interface, to execute specific tasks on server startup and +shutdown, to provide custom (API) endpoints or whole user interfaces with special functionality, to react to system +events or progress reports or to add support for additional slicers. More plugin types are planned for the future. + +.. _sec-features-plugins-available: + +Finding Plugins +=============== + +Currently there's no such thing as a centralized plugin repository for available plugins. + +Plugins may be found in the lists provided in `the OctoPrint wiki `_ +and on the `OctoPrint organization Github page `_. + +.. _sec-features-plugins-installing: + +Installing Plugins +================== + +Plugins can be installed either by unpacking them into one of the configured plugin folders (regularly those are +``/plugins`` and ``/plugins`` [#f1]_ or by installing them as regular python +modules via ``pip`` [#f2]_. + +Please refer to the documentation of the plugin for installations instructions. + +For a plugin available on the Python Package Index (PyPi), the process is as simple as issuing a + +.. code-block:: bash + + pip install + +For plugins not available on PyPi, you'll have to give ``pip`` an URL from which to install the package (e.g. the URL to +a ZIP file of the current master branch of a Github repository hosting a plugin, or even a ``git+https`` URL), example: + +.. code-block:: bash + + pip install https://github.com/OctoPrint/OctoPrint-Growl/archive/master.zip + +See `the pip install documentation `_ for what URL +types are possible. + +.. _sec-features-plugins-developing: + +Developing Plugins +================== + +See :ref:`Developing Plugins `. + +.. rubric:: Footnotes + +.. [#f1] For Linux that will be ``~/.octoprint/plugins``, for Windows it will be ``%APPDATA%/OctoPrint/plugins`` and for + Mac ``~/Library/Application Support/OctoPrint`` +.. [#f2] Make sure to use the exact same Python installation for installing the plugin that you also used for + installing & running OctoPrint. For OctoPi this means using ``~/oprint/bin/pip`` for installing plugins + instead of just ``pip``. diff --git a/docs/plugins/concepts.rst b/docs/plugins/concepts.rst index 368f51e41..b57535a74 100644 --- a/docs/plugins/concepts.rst +++ b/docs/plugins/concepts.rst @@ -4,7 +4,7 @@ Concepts ======== OctoPrint's plugins are `Python Packages `_ which in their -top-level module define a bunch of :ref:`control properties ` defining +top-level module define a bunch of :ref:`control properties ` defining metadata (like name, version etc of the plugin) as well as information on how to initialize the plugin and into what parts of the system the plugin will actually plug in to perform its job. @@ -13,6 +13,57 @@ There are three types of ways a plugin might attach itself to the system, throug :ref:`hook ` or by offering :ref:`helper ` functionality to be used by other plugins. +Plugin mixin implementations will get a bunch of :ref:`properties injected ` +by OctoPrint plugin system to help them work. + +.. _sec-plugin-concepts-controlproperties: + +Control Properties +------------------ + +As already mentioned above, plugins are Python packages which provide certain pieces of metadata to tell OctoPrint's +plugin subsystem about themselves. These are simple package attributes defined in the top most package file, e.g.: + +.. code-block:: python + + import octoprint.plugin + + # ... + + __plugin_name__ = "My Plugin" + def __plugin_init__(): + # whatever you need to do to init your plugin, if anything at all + pass + +The following properties are recognized: + +``__plugin_name__`` + Name of your plugin, optional, overrides the name specified in ``setup.py`` if provided. If neither this property nor + a name from ``setup.py`` is available to the plugin subsystem, the plugin's identifier (= package name) will be + used instead. +``__plugin_version__`` + Version of your plugin, optional, overrides the version specified in ``setup.py`` if provided. +``__plugin_description__`` + Description of your plugin, optional, overrides the description specified in ``setup.py`` if provided. +``__plugin_author__`` + Author of your plugin, optional, overrides the author specified in ``setup.py`` if provided. +``__plugin_url__`` + URL of the webpage of your plugin, e.g. the Github repository, optional, overrides the URL specified in ``setup.py`` if + provided. +``__plugin_license__`` + License of your plugin, optional, overrides the license specified in ``setup.py`` if provided. +``__plugin_implementation__`` + Instance of an implementation of one or more :ref:`plugin mixins `. +``__plugin_hooks__`` + Handlers for one or more of the various :ref:`plugin hooks `. +``__plugin_check__`` + Method called upon discovery of the plugin by the plugin subsystem, should return ``True`` if the + plugin can be instantiated later on, ``False`` if there are reasons why not, e.g. if dependencies + are missing. +``__plugin_init__`` + Method called upon initializing of the plugin by the plugin subsystem, can be used to instantiate + plugin implementations, connecting them to hooks etc. + .. _sec-plugin-concepts-mixins: Mixins @@ -223,4 +274,52 @@ them as (hopefully) documented. return flask.jsonify(dict( browsing_enabled=True, growl_instances=growl_instances - )) \ No newline at end of file + )) + +.. _sec-plugins-concepts-injectedproperties: + +Injected Properties +------------------- + +OctoPrint's plugin subsystem will inject a bunch of properties into each :ref:`mixin implementation `. +An overview of these properties follows. + +``self._identifier`` + The plugin's identifier. +``self._plugin_name`` + The plugin's name, as taken from either the ``__plugin_name__`` control property or the package info. +``self._plugin_version`` + The plugin's version, as taken from either the ``__plugin_version__`` control property or the package info. +``self._basefolder`` + The plugin's base folder where it's installed. Can be used to refer to files relative to the plugin's installation + location, e.g. included scripts, templates or assets. +``self._logger`` + A `python logger instance `_ logging to the log target + ``octoprint.plugin.``. +``self._settings`` + The plugin's personalized settings manager, injected only into plugins that include the :class:`~octoprint.plugin.SettingsPlugin` mixin. + An instance of :class:`octoprint.plugin.PluginSettings`. +``self._plugin_manager`` + OctoPrint's plugin manager object, an instance of :class:`octoprint.plugin.core.PluginManager`. +``self._printer_profile_manager`` + OctoPrint's printer profile manager, an instance of :class:`octoprint.printer.profile.PrinterProfileManager`. +``self._event_bus`` + OctoPrint's event bus, an instance of :class:`octoprint.events.EventManager`. +``self._analysis_queue`` + OctoPrint's analysis queue for analyzing GCODEs or other files, an instance of :class:`octoprint.filemanager.analysis.AnalysisQueue`. +``self._slicing_manager`` + OctoPrint's slicing manager, an instance of :class:`octoprint.slicing.SlicingManager`. +``self._file_manager`` + OctoPrint's file manager, an instance of :class:`octoprint.filemanager.FileManager`. +``self._printer`` + OctoPrint's printer management object, an instance of :class:`octoprint.printer.PrinterInterface`. +``self._app_session_manager`` + OctoPrint's application session manager, an instance of :class:`octoprint.server.util.flask.AppSessionManager`. + +.. seealso:: + + :class:`~octoprint.plugin.core.Plugin` and :class:`~octoprint.plugin.types.OctoPrintPlugin` + Class documentation also containing the properties shared among all mixing implementations. + + :ref:`Available Mixins ` + Some mixin types trigger the injection of additional properties. diff --git a/docs/plugins/distributing.rst b/docs/plugins/distributing.rst index 7a8d6fc0e..9cdeba2e1 100644 --- a/docs/plugins/distributing.rst +++ b/docs/plugins/distributing.rst @@ -3,25 +3,44 @@ Distributing your plugin ======================== -You can distribute a plugin with OctoPrint via two ways: +You can distribute a plugin with OctoPrint via two ways. - - You can have your users copy it to OctoPrint's plugin folder (normally located at ``~/.octoprint/plugins`` under Linux, - ``%APPDATA%\OctoPrint\plugins`` on Windows and ... on Mac). In this case your plugin will be distributed directly - as a Python module (a single ``.py`` file containing all of your plugin's code directly and named - like your plugin) or a package (a folder named like your plugin + ``__init.py__`` contained within). - - You can have your users install it via ``pip`` and register it for the `entry point `_ ``octoprint.plugin`` via - your plugin's ``setup.py``, this way it will be found automatically by OctoPrint upon initialization of the - plugin subsystem [#f1]_. +.. _sec-plugins-distribution-manual: - For an example of how the directory structure and related files would look like in this case, please take a - look at the `helloworld example from OctoPrint's example plugins `_. +Manual file distribution +------------------------ - This variant is highly recommended for pretty much any plugin besides the most basic ones since it also allows - requirements management and pretty much any thing else that Python's setuptools provide to the developer. +You can have your users copy it to OctoPrint's plugin folder (normally located at ``~/.octoprint/plugins`` under Linux, +``%APPDATA%\OctoPrint\plugins`` on Windows and ... on Mac). In this case your plugin will be distributed directly +as a Python module (a single ``.py`` file containing all of your plugin's code directly and named +like your plugin) or a package (a folder named like your plugin + ``__init.py__`` contained within). + +.. _sec-plugins-distribution-pip: + +Proper packages installable via pip +----------------------------------- + +You can have your users install it via ``pip`` and register it for the `entry point `_ ``octoprint.plugin`` via +your plugin's ``setup.py``, this way it will be found automatically by OctoPrint upon initialization of the +plugin subsystem [#f1]_. + +For an example of how the directory structure and related files would look like in this case, please take a +look at the `helloworld example from OctoPrint's example plugins `_. + +This variant is highly recommended for pretty much any plugin besides the most basic ones since it also allows +requirements management and pretty much any thing else that Python's setuptools provide to the developer. + +.. seealso:: + + `OctoPrint Plugin Skeleton `_ + A basic plugin skeleton providing you with all you need to get started with distributing your plugin as a proper + package. See the :ref:`Getting Started Guide ` for an + :ref:`example ` on how to use this. .. rubric:: Footnotes .. [#f1] The automatic registration will only work within the same Python installation (this also includes virtual environments), so make sure to instruct your users to use the exact same Python installation for installing - the plugin that they also used for installing & running OctoPrint. + the plugin that they also used for installing & running OctoPrint. For OctoPi this means using + ``~/oprint/bin/pip`` for installing plugins instead of just ``pip``. diff --git a/docs/plugins/gettingstarted.rst b/docs/plugins/gettingstarted.rst index ebbd73bf2..2b310e4ee 100644 --- a/docs/plugins/gettingstarted.rst +++ b/docs/plugins/gettingstarted.rst @@ -22,8 +22,13 @@ We'll start at the most basic form a plugin can take - just a couple of simple l Saving this as ``helloworld.py`` in ``~/.octoprint/plugins`` yields you something resembling these log entries upon server startup:: 2015-01-27 11:14:35,124 - octoprint.server - INFO - Starting OctoPrint 1.2.0-dev-448-gd96e56e (devel branch) + [...] 2015-01-27 11:14:35,124 - octoprint.plugin.core - INFO - Loading plugins from /home/pi/.octoprint/plugins, /home/pi/OctoPrint/src/octoprint/plugins and installed plugin packages... - 2015-01-27 11:14:36,135 - octoprint.plugin.core - INFO - Found 3 plugin(s): Hello World (1.0), CuraEngine (0.1), Discovery (0.1) + [...] + 2015-01-27 11:14:36,135 - octoprint.plugin.core - INFO - 3 plugin(s) registered with the system: + | CuraEngine (bundled) = /home/pi/OctoPrint/src/octoprint/plugins/cura + | Discovery (bundled) = /home/pi/OctoPrint/src/octoprint/plugins/discovery + | Hello World (1.0) = /home/pi/.octoprint/plugins/helloworld.py OctoPrint found that plugin in the folder and took a look into it. The name and the version it displays in that log entry it got from the ``__plugin_name__`` and ``__plugin_version__`` lines. It also read the description from @@ -68,7 +73,7 @@ used :func:`~octoprint.plugin.StartupPlugin.on_startup` instead, in which case o up and ready to serve requests. You'll also note that we are using ``self._logger`` for logging. Where did that one come from? OctoPrint's plugin system -injects :ref:`a couple of useful objects ` into our plugin implementation classes, +injects :ref:`a couple of useful objects ` into our plugin implementation classes, one of those being a fully instantiated `python logger `_ ready to be used by your plugin. As you can see in the log output above, that logger uses the namespace ``octoprint.plugins.helloworld`` for our little plugin here, or more generally ``octoprint.plugins.``. @@ -85,8 +90,7 @@ You basically have two options to distribute your plugin. One would be about the as a simple python file following the naming convention ``.py`` that your users add to their ``~/.octoprint/plugins`` folder. You already know how that works. But let's say you have more than just a simple plugin that can be done in one file. Distributing multiple files and getting your users to install them in the right way -so that OctoPrint will be able to actually find and load them is certainly not impossible (see :ref:`the plugin distribution -documentation ` if you want to take a closer look at that option), but we want to do it in the +so that OctoPrint will be able to actually find and load them is certainly not impossible, but we want to do it in the best way possible, meaning we want to make our plugin a fully installable python module that your users will be able to install directly via Python's standard package manager ``pip`` or alternatively via `OctoPrint's own plugin manager `_. @@ -130,8 +134,13 @@ discoverable by OctoPrint, however we don't have to reinstall it after any chang Restart OctoPrint. Your plugin should still be properly discovered and the log line should be printed:: 2015-01-27 13:43:34,134 - octoprint.server - INFO - Starting OctoPrint 1.2.0-dev-448-gd96e56e (devel branch) + [...] 2015-01-27 13:43:34,134 - octoprint.plugin.core - INFO - Loading plugins from /home/pi/.octoprint/plugins, /home/pi/OctoPrint/src/octoprint/plugins and installed plugin packages... - 2015-01-27 13:43:34,818 - octoprint.plugin.core - INFO - Found 3 plugin(s): Hello World (1.0), CuraEngine (0.1), Discovery (0.1) + [...] + 2015-01-27 13:43:34,818 - octoprint.plugin.core - INFO - 3 plugin(s) registered with the system: + | CuraEngine (bundled) = /home/pi/OctoPrint/src/octoprint/plugins/cura + | Discovery (bundled) = /home/pi/OctoPrint/src/octoprint/plugins/discovery + | Hello World (1.0) = /home/pi/OctoPrint-HelloWorld/octoprint_helloworld [...] 2015-01-27 13:43:38,997 - octoprint.plugins.helloworld - INFO - Hello World! @@ -142,13 +151,16 @@ of information now defined twice: .. code-block:: python :linenos: + :caption: __init__.py - # __init__.py: __plugin_name__ = "Hello World" __plugin_version__ = "1.0" __plugin_description__ = "A quick \"Hello World\" example plugin for OctoPrint" - # setup.py +.. code-block:: python + :linenos: + :caption: setup.py + plugin_name = "OctoPrint-HelloWorld" plugin_version = "1.0" plugin_description = "A quick \"Hello World\" example plugin for OctoPrint" @@ -173,7 +185,10 @@ and ``__plugin_description__`` from ``__init__.py``: and restart OctoPrint:: - 2015-01-27 13:46:33,786 - octoprint.plugin.core - INFO - Found 3 plugin(s): OctoPrint-HelloWorld (1.0), CuraEngine (0.1), Discovery (0.1) + 2015-01-27 13:46:33,786 - octoprint.plugin.core - INFO - 3 plugin(s) registered with the system: + | CuraEngine (bundled) = /home/pi/OctoPrint/src/octoprint/plugins/cura + | Discovery (bundled) = /home/pi/OctoPrint/src/octoprint/plugins/discovery + | OctoPrint-HelloWorld (1.0) = /home/pi/OctoPrint-HelloWorld/octoprint_helloworld Our "Hello World" Plugin still gets detected fine, but it's now listed under the same name it's installed under, "OctoPrint-HelloWorld". That's a bit redundant and squashed, so we'll override that bit via ``__plugin_name__`` again: @@ -197,10 +212,13 @@ Our "Hello World" Plugin still gets detected fine, but it's now listed under the Restart OctoPrint again:: - 2015-01-27 13:48:54,122 - octoprint.plugin.core - INFO - Found 3 plugin(s): Hello World (1.0), CuraEngine (0.1), Discovery (0.1) + 2015-01-27 13:48:54,122 - octoprint.plugin.core - INFO - 3 plugin(s) registered with the system: + | CuraEngine (bundled) = /home/pi/OctoPrint/src/octoprint/plugins/cura + | Discovery (bundled) = /home/pi/OctoPrint/src/octoprint/plugins/discovery + | Hello World (1.0) = /home/pi/OctoPrint-HelloWorld/octoprint_helloworld Much better! You can override pretty much all of the metadata defined within ``setup.py`` from within your Plugin itself -- -take a look at :ref:`the available control properties ` for all available +take a look at :ref:`the available control properties ` for all available overrides. Following the README of the `Plugin Skeleton `_ you could now diff --git a/docs/plugins/index.rst b/docs/plugins/index.rst index 74d23be2d..f70097ef5 100644 --- a/docs/plugins/index.rst +++ b/docs/plugins/index.rst @@ -1,24 +1,14 @@ .. _sec-plugins: -####### -Plugins -####### - -Starting with OctoPrint 1.2.0, there's now a plugin system in place which allows to individually -extend OctoPrint's functionality. - -Right now plugins can be used to extend OctoPrint's web interface, to execute specific tasks on server startup and -shutdown, to provide custom (API) endpoints with special functionality, to react on system events or to add support for -additional slicers. More plugin types are planned for the future. +################## +Developing Plugins +################## .. toctree:: :maxdepth: 3 - using.rst - concepts.rst gettingstarted.rst - infrastructure.rst - templates.rst + concepts.rst distributing.rst mixins.rst hooks.rst diff --git a/docs/plugins/infrastructure.rst b/docs/plugins/infrastructure.rst deleted file mode 100644 index 94a192c83..000000000 --- a/docs/plugins/infrastructure.rst +++ /dev/null @@ -1,70 +0,0 @@ -.. _sec-plugins-infrastructure: - -Plugin Infrastructure -===================== - -.. _sec-plugins-infrastructure-controlproperties: - -Control Properties ------------------- - -``__plugin_name__`` - Name of your plugin, optional, overrides the name specified in ``setup.py`` if provided. -``__plugin_version__`` - Version of your plugin, optional, overrides the version specified in ``setup.py`` if provided. -``__plugin_description__`` - Description of your plugin, optional, overrides the description specified in ``setup.py`` if provided. -``__plugin_author__`` - Author of your plugin, optional, overrides the author specified in ``setup.py`` if provided. -``__plugin_url__`` - URL of the webpage of your plugin, e.g. the Github repository, optional, overrides the URL specified in ``setup.py`` if - provided. -``__plugin_license__`` - License of your plugin, optional, overrides the license specified in ``setup.py`` if provided. -``__plugin_implementation__`` - Instance of an implementation of one or more :ref:`plugin mixins ` -``__plugin_hooks__`` - Handlers for one or more of the various :ref:`plugin hooks ` -``__plugin_check__`` - Method called upon discovery of the plugin by the plugin subsystem, should return ``True`` if the - plugin can be instantiated later on, ``False`` if there are reasons why not, e.g. if dependencies - are missing. -``__plugin_init__`` - Method called upon initializing of the plugin by the plugin subsystem, can be used to instantiate - plugin implementations, connecting them to hooks etc. - -.. _sec-plugins-infrastructure-injections: - -Injected Properties -------------------- - -``self._identifier`` - The plugin's identifier. -``self._plugin_name`` - The plugin's name, as taken from either the ``__plugin_name__`` control property or the package info. -``self._plugin_version`` - The plugin's version, as taken from either the ``__plugin_version__`` control property or the package info. -``self._basefolder`` - The plugin's base folder where it's installed. Can be used to refer to files relative to the plugin's installation - location, e.g. included scripts, templates or assets. -``self._logger`` - A `python logger instance `_ logging to the log target - ``octoprint.plugin.``. -``self._settings`` - The plugin's personalized settings manager, injected only into plugins that include the :class:`SettingsPlugin` mixin. -``self._plugin_manager`` - OctoPrint's plugin manager. -``self._printer_profile_manager`` - OctoPrint's printer profile manager. -``self._event_bus`` - OctoPrint's event bus. -``self._analysis_queue`` - OctoPrint's analysis queue for analyzing GCODEs or other files. -``self._slicing_manager`` - OctoPrint's slicing manager. -``self._file_manager`` - OctoPrint's file manager. -``self._printer`` - OctoPrint's printer management object. -``self._app_session_manager`` - OctoPrint's application session manager. diff --git a/docs/plugins/templates.rst b/docs/plugins/templates.rst deleted file mode 100644 index c569dcba9..000000000 --- a/docs/plugins/templates.rst +++ /dev/null @@ -1,98 +0,0 @@ -.. _sec-plugins-templates: - -Component Templates -=================== - -OctoPrint allows plugins to extend the UI of OctoPrint through the use of the :class:`~octoprint.plugin.TemplatePlugin` -mixin. By implementing this mixing and providing templates and their configuration through it, Plugins may currently -create one or more of navbar, sidebar, tabs, settings and generic components. - -.. figure:: ../images/template-plugin-types-main.png - :align: center - :alt: Template injection types in the main part of the interface - - Template injection types in the main part of the interface - -.. figure:: ../images/template-plugin-types-settings.png - :align: center - :alt: Template injection types in the settings - - Template injection types in the settings - -You can find an example for a simple plugin which injects navbar, sidebar, tab and settings content into the interface in -`the "helloworld" plugin in OctoPrint's collection of plugin examples `_. - -.. _sec-plugins-templates-navbar: - -Navbar ------- - -The right part of the navigation bar located at the top of the UI can be enriched with additional links. Note that -with the current implementation, plugins will always be located *to the left* of the existing links. - -The included template must be called ``_navbar.jinja2`` (e.g. ``myplugin_navbar.jinja2``) unless -overridden by the configuration supplied through :func:`get_template_configs`. - -The template will be already wrapped into the necessary structure, plugins just need to supply the pure content. The -wrapper structure will have all additional classes and styles applied as specified via the configuration supplied -through :func:`get_template_configs`. - -.. _sec-plugins-templates-sidebar: - -Sidebar -------- - -The left side bar containing Connection, State and Files sections can be enriched with additional sections. Note -that with the current implementations, plugins will always be located *beneath* the existing sections. - -The included template must be called ``_sidebar.jinja2`` (e.g. ``myplugin_sidebar.jinja2``) unless -overridden by the configuration supplied through :func:`get_template_configs`. - -The template will be already wrapped into the necessary structure, plugins just need to supply the pure content. The -wrapper divs for both the whole box as well as the content pane will have all additional classes and styles applied -as specified via the configuration supplied through :func:`get_template_configs`. - -.. _sec-plugins-templates-tabs: - -Tabs ----- - -The available tabs of the main part of the interface may be extended with additional tabs originating from within -plugins. Note that with the current implementation, plugins will always be located *to the right* of the existing -tabs. - -The included template must be called ``_tab.jinja2`` (e.g. ``myplugin_tab.jinja2``) unless -overridden by the configuration supplied through :func:`get_template_configs`. - -The template will be already wrapped into the necessary structure, plugins just need to supply the pure content. The -wrapper div and the link in the navigation will have the additional classes and styles applied as specified via the -configuration supplied through :func:`get_template_configs`. - -.. _sec-plugins-templates-settings: - -Settings --------- - -Plugins may inject a dialog into the existing settings view. Note that with the current implementations, plugins -will always be listed beneath the "Plugins" header in the settings link list, ordered alphabetically after -their displayed name. - -The included template must be called ``_settings.jinja2`` (e.g. ``myplugin_settings.jinja2``) unless -overridden by the configuration supplied through :func:`get_template_configs`. - -The template will be already wrapped into the necessary structure, plugins just need to supply the pure content. The -wrapper div and the link in the navigation will have the additional classes and styles applied as defined via the -supplied configuration supplied through :func:`get_template_configs`. - -.. _sec-plugins-templates-generic: - -Generic -------- - -Plugins may also inject arbitrary templates into the page of the web interface itself, e.g. in order to -add overlays or dialogs to be called from within the plugin's javascript code. - -.. _sec-plugins-templates-replacement: - -Replacing existing components ------------------------------ diff --git a/docs/plugins/using.rst b/docs/plugins/using.rst deleted file mode 100644 index 898996e51..000000000 --- a/docs/plugins/using.rst +++ /dev/null @@ -1,44 +0,0 @@ -.. _sec-plugins-using: - -************* -Using Plugins -************* - -.. _sec-plugins-using-available: - -Finding Plugins -=============== - -Currently there's no such thing as a centralized plugin repository for available plugins. - -Plugins may be found in the lists provided in `the OctoPrint wiki `_ -and on the `OctoPrint organization Github page `_. - -.. _sec-plugins-using-installing: - -Installing Plugins -================== - -Plugins can be installed either by unpacking them into one of the configured plugin folders (regularly those are -``/plugins`` and ``~/.octoprint/plugins`` or by installing them as regular python modules via ``pip``. -Please refer to the documentation of the plugin for installations instructions. - -The latter is the more common case since all currently published plugins not bundled with OctoPrint can and should be installed -this way. - -For a plugin available on the Python Package Index (PyPi), the process is as simple as issuing a - -.. code-block:: bash - - pip install - -For plugins not available on PyPi, you'll have to give ``pip`` an URL from which to install the package (e.g. the URL to -a ZIP file of the current master branch of a Github repository hosting a plugin, or even a ``git+https`` URL), example: - -.. code-block:: bash - - pip install https://github.com/OctoPrint/OctoPrint-Growl/archive/master.zip - -See `the pip install documentation `_ for what URL -types are possible. - diff --git a/src/octoprint/plugin/core.py b/src/octoprint/plugin/core.py index 5b1f831f2..c98a58db6 100644 --- a/src/octoprint/plugin/core.py +++ b/src/octoprint/plugin/core.py @@ -35,7 +35,7 @@ class PluginInfo(object): implementations, hooks and helpers. It works on Python module objects and extracts the relevant data from those via accessing the - :ref:`control properties `. + :ref:`control properties `. Arguments: key (str): Identifier of the plugin From 0ed8afd999004d34a0575b11fed38961e4dd4c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 1 Apr 2015 11:54:11 +0200 Subject: [PATCH 6/6] Fix: Validate plugins separately from constructor Otherwise plugins that inject data via __plugin_init__ won't work properly --- src/octoprint/plugin/core.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/octoprint/plugin/core.py b/src/octoprint/plugin/core.py index c98a58db6..109db26ca 100644 --- a/src/octoprint/plugin/core.py +++ b/src/octoprint/plugin/core.py @@ -109,9 +109,7 @@ class PluginInfo(object): self._url = url self._license = license - self._validate() - - def _validate(self): + def validate(self): # if the plugin still uses __plugin_implementations__, log a deprecation warning and put the first # item into __plugin_implementation__ if hasattr(self.instance, self.__class__.attr_implementations): @@ -484,6 +482,9 @@ class PluginManager(object): # initialize the plugin plugin.init() + # validate the plugin + plugin.validate() + # evaluate registered hooks for hook, callback in plugin.hooks.items(): self.plugin_hooks[hook].append((name, callback))