Skip to content
This repository has been archived by the owner on May 8, 2023. It is now read-only.

Commit

Permalink
bump version 0.2.0, close #1, close #3, close #4, close #6
Browse files Browse the repository at this point in the history
  • Loading branch information
mike1pol committed Jul 18, 2020
1 parent 522fab2 commit 224a741
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 34 deletions.
41 changes: 17 additions & 24 deletions octoprint_macro/__init__.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,53 @@
# coding=utf-8
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

class SidebarmacrosPlugin(octoprint.plugin.SettingsPlugin,
octoprint.plugin.AssetPlugin,
octoprint.plugin.TemplatePlugin):

##~~ SettingsPlugin mixin
def get_settings_defaults(self):
return dict(
column = 1,
macros = [
dict(name="Home", macro="G28", active=True)
dict(name="Home", macro="G28", active=True, type = "default")
]
)

def get_settings_version(self):
return 1

def on_settings_migrate(self, target, current=None):
if current is None or current < 1:
new_macros = []
self._logger.info(self._settings.get(['macros']))
for macros in self._settings.get(['macros']):
macros['type'] = "default"
new_macros.append(macros)
self._settings.set(['macros'], new_macros)
self._settings.set(['column'], 1)

def get_template_configs(self):
return [
dict(type="settings", custom_bindings=True, template="macro_settings.jinja2"),
dict(type="sidebar", icon="rocket", custom_bindings=True, template="macro_sidebar.jinja2")
]
##~~ AssetPlugin mixin

def get_assets(self):
# Define your plugin's asset files to automatically include in the
# core UI here.
return dict(
js=["js/macro.js", "js/macro_settings.js"]
js=["js/macro.js", "js/macro_settings.js"],
css=["css/macro.css"]
)

##~~ Softwareupdate hook

def get_update_information(self):
# Define the configuration for your plugin to use with the Software Update
# Plugin here. See https://docs.octoprint.org/en/master/bundledplugins/softwareupdate.html
# for details.
return dict(
sidebarmacros=dict(
displayName="Macro Plugin",
displayVersion=self._plugin_version,

# version check: github repository
type="github_release",
user="mike1pol",
repo="octoprint_macro",
current=self._plugin_version,

# update method: pip
pip="https://github.com/mike1pol/octoprint_macro/archive/{target_version}.zip"
)
)
Expand Down
34 changes: 34 additions & 0 deletions octoprint_macro/static/css/macro.css
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
/* TODO: Have your plugin's CSS files generated to here. */
.macro-mb20 {
margin-bottom: 20px;
}

.span4 select {
max-width: 100%;
}

.macro-btn {
display: grid;
}
.macro-column-1 {
grid-template-columns: 1fr;
}
.macro-column-2 {
grid-template-columns: 1fr 1fr;
}
.macro-column-3 {
grid-template-columns: 1fr 1fr 1fr;
}
.macro-column-4 {
grid-template-columns: 1fr 1fr 1fr 1fr;
}
.macro-column-5 {
grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
}

.macro-btn button {
width: auto;
padding-left: 8px;
padding-right: 8px;
margin: 8px;
min-width: 120px;
}
24 changes: 21 additions & 3 deletions octoprint_macro/static/js/macro.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,27 @@ $(function () {
self.isActive = function () {
return self.connectionState.isOperational() && self.loginState.isUser();
}
self.executeMacro = function() {
OctoPrint.control.sendGcode(this.macro());
}
self.executeMacro = function () {
const macro = this.macro();
const commands = macro.split('\n');
for (let i = 0; i < commands.length; i += 1) {
const command = commands[i];
if (!command.includes(';;')) {
OctoPrint.control.sendGcode(command.trim());
} else if (!command.startsWith(';;')) {
const idx = command.indexOf(';;');
const newCommand = command.slice(0, idx);
OctoPrint.control.sendGcode(newCommand.trim());
}
}
}
self.getClass = function () {
var columns = this.settings.settings.plugins.macro.column();
return `macro-column-${columns <= 0 || columns > 5 ? 1 : columns}`;
}
self.getBtnClass = function (type) {
return `btn-${typeof type === 'function' ? type() : type}`;
}
}
OCTOPRINT_VIEWMODELS.push({
construct: MacroViewModel,
Expand Down
1 change: 1 addition & 0 deletions octoprint_macro/static/js/macro_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ $(function () {
self.settings.settings.plugins.macro.macros.push({
name: 'Macro',
macro: '',
type: 'default',
active: true
});
}
Expand Down
24 changes: 21 additions & 3 deletions octoprint_macro/templates/macro_settings.jinja2
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
<form class="form-horizontal">
<div class="control-group">
<label class="control-label">{{ _('Columns:')}}</label>
<div class="controls">
<div class="row-fluid">
<input type="number" class="span2 input-block-level" data-bind="value: settings.settings.plugins.macro.column" />
</div>
</div>
</div>
<div data-bind="foreach: settings.settings.plugins.macro.macros" style="margin-bottom: 12px">
<div class="control-group">
<label class="control-label">{{ _('Name') }}</label>
<div class="controls">
<div class="row-fluid">
<div class="span8">
<div class="span4">
<input type="text" class="input-block-level" data-bind="value: name"/>
</div>
<div class="span4">
<select data-bind="value: type">
<option value="default">Default</option>
<option value="primary">Primary</option>
<option value="info">Info</option>
<option value="success">Success</option>
<option value="danger">Danger</option>
<option value="warning">Warning</option>
</select>
</div>
<div class="span1">
<input type="checkbox" class="input-block-level" data-bind="checked: active"/>
</div>
Expand All @@ -19,10 +37,10 @@
</div>
</div>
<label class="control-label">{{ _('Command') }}</label>
<div class="controls" style="margin-bottom: 20px">
<div class="controls macro-mb20">
<div class="row-fluid">
<div class="span8">
<textarea rows="2" class="block" data-bind="value: macro">
<textarea rows="4" class="block" data-bind="value: macro">
</textarea>
</div>
<div class="span2"></div>
Expand Down
4 changes: 2 additions & 2 deletions octoprint_macro/templates/macro_sidebar.jinja2
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div class="control-group">
<div class="controls">
<div data-bind="foreach: settings.settings.plugins.macro.macros">
<div class="macro-btn" data-bind="css: getClass(), foreach: settings.settings.plugins.macro.macros">
<!-- ko if: active -->
<button class="btn btn-block" data-bind="text: name, click: $parent.executeMacro, enable: $parent.isActive()"></button>
<button class="btn btn-block" data-bind="css: $parent.getBtnClass(type), text: name, click: $parent.executeMacro, enable: $parent.isActive()"></button>
<!-- /ko -->
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
plugin_name = "Macro"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "0.1.1"
plugin_version = "0.2.0"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
plugin_description = """Macro"""
plugin_description = """Adds feature to create various gcode macros and display them in sidebar menu"""

# The plugin's author. Can be overwritten within OctoPrint's internal data via __plugin_author__ in the plugin module
plugin_author = "Mikhail Poluboyarinov"
Expand Down

0 comments on commit 224a741

Please sign in to comment.