Skip to content

Commit

Permalink
add one time execute flag, use snake_case gets
Browse files Browse the repository at this point in the history
  • Loading branch information
Booli committed Mar 9, 2015
1 parent 240d6ba commit ecc77de
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
32 changes: 23 additions & 9 deletions octoprint_actiontrigger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

s = octoprint.plugin.plugin_settings("actiontrigger", defaults=default_settings)

##~~ Init Plugin and Metadata

__plugin_name__ = "Action Trigger"


def __plugin_init__():
global _plugin
global __plugin_implementations__
Expand All @@ -26,10 +31,13 @@ def __plugin_init__():

class ActionTriggerPlugin(octoprint.plugin.TemplatePlugin,
octoprint.plugin.AssetPlugin,
octoprint.plugin.SettingsPlugin):
octoprint.plugin.SettingsPlugin,
octoprint.plugin.EventHandlerPlugin):

def __init__(self):
self.filament_action = False

##~~ TemplatePlugin
# this might needs some vars later on
def get_template_configs(self):
return [
dict(type="settings", name="Action Trigger", custom_bindings=False)
Expand All @@ -45,34 +53,40 @@ def get_assets(self):
##~ SettingsPlugin
def on_settings_load(self):
return dict(
action_door=s.getBoolean(["action_door"]),
action_filament=s.getBoolean(["action_filament"])
action_door=s.get_boolean(["action_door"]),
action_filament=s.get_boolean(["action_filament"])
)

def on_settings_save(self, data):
if "action_door" in data:
s.setBoolean(["action_door"], data["action_door"])
s.set_boolean(["action_door"], data["action_door"])
if "action_filament" in data:
s.setBoolean(["action_filament"], data["action_filament"])
s.set_boolean(["action_filament"], data["action_filament"])


##~~ ActionTriggerPlugin
def hook_actiontrigger(self, comm, line, action_trigger):
if action_trigger == None:
return
elif action_trigger == "door_open" and s.getBoolean(["action_door"]) and comm.isPrinting():
elif action_trigger == "door_open" and s.get_boolean(["action_door"]) and comm.isPrinting():
self._send_client_message(action_trigger, dict(line=line))
# might want to put this in separate function
comm.setPause(True)
self._printer.home("x")
elif action_trigger == "door_closed" and s.getBoolean(["action_door"]):
elif action_trigger == "door_closed" and s.get_boolean(["action_door"]):
self._send_client_message(action_trigger, dict(line=line))
comm.setPause(False)
elif action_trigger == "filament" and s.getBoolean(["action_filament"]):
elif action_trigger == "filament" and s.get_boolean(["action_filament"]) and self.filament_action == False:
self._send_client_message(action_trigger, dict(line=line))
comm.setPause(True)
self._printer.home("x")
self.filament_action = True

# Send trigger to front end
def _send_client_message(self, message_type, data=None):
self._plugin_manager.send_plugin_message("actiontrigger", dict(type=message_type, data=data))

# Set flags on event
def on_event(self, event, payload):
if event == "PrintResumed" or event == "PrintStarted":
self.filament_action = False
7 changes: 6 additions & 1 deletion octoprint_actiontrigger/static/js/actiontrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ $(function() {
actionTriggerDialogAck.bind("click", function (e) {
e.preventDefault();
$("#action_trigger_dialog").modal("hide");
self.showControls();
//prob going to do some stuff here huh.
});
actionTriggerDialog.modal({
Expand All @@ -30,13 +31,17 @@ $(function() {

};

//$('#action_trigger_dialog').on('hidden', function(){
// $('#action_trigger_dialog').data('modal', null);
//});

self.onBeforeBinding = function() {
self.settings = self.settingsViewModel.settings;
};

self.showControls = function() {
$('#tabs a[href="#control"]').tab('show')
}
};

self.onDataUpdaterPluginMessage = function (plugin, data) {
if (plugin != "actiontrigger") {
Expand Down
6 changes: 3 additions & 3 deletions octoprint_actiontrigger/templates/actiontrigger.jinja2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div id="action_trigger_dialog" class="modal hide fade">
<div id="action_trigger_dialog" class="modal hide">
<div class="modal-header">
<!--<a href="#" class="close" data-dismiss="modal" aria-hidden="true">&times;</a> Out for now-->
<h3><p class="action_trigger_title"></p></h3> <!-- trigger title variable -->
Expand All @@ -16,7 +16,7 @@
To disable this feature go to Settings -> ActionTrigger and untick "Door detection".
</div>
<div class="modal-footer">
<a href="#" class="btn btn-warning" data-dismiss="modal" aria-hidden="true">{{ _('I understand, let me access the controls') }}</a>
<a href="#" class="btn btn-warning action_trigger_dialog_acknowledge" aria-hidden="true">{{ _('I understand, let me access the controls') }}</a>
</div>
</script>

Expand All @@ -28,6 +28,6 @@
Use the Control tab to load a new roll filament if needed. Resume print through the status panel.
</div>
<div class="modal-footer">
<a href="#" class="btn btn-warning" data-dismiss="modal" aria-hidden="true" data-bind="click: showControls">{{ _('Proceed to controls') }}</a>
<a href="#" class="btn btn-warning action_trigger_dialog_acknowledge" aria-hidden="true">{{ _('Proceed to controls') }}</a>
</div>
</script>

0 comments on commit ecc77de

Please sign in to comment.