Skip to content

Commit

Permalink
New Version 1.3.0
Browse files Browse the repository at this point in the history
- #53 take a camera snapshot via gcode
- #57 improved text for selecting snapshot methode
  • Loading branch information
OllisGit committed Jun 12, 2020
1 parent 7ccc9e5 commit 6c0e4fd
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 38 deletions.
2 changes: 1 addition & 1 deletion octoprint_PrintJobHistory/CameraManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def takeSnapshot(self, snapshotFilename, sendErrorMessageToClientFunction):
flipV = self._globalSettings.global_get(["webcam", "flipV"])

try:
response = requests.get(snapshotUrl, verify=not True,timeout=float(60))
response = requests.get(snapshotUrl, verify=not True,timeout=float(30))
if response.status_code == requests.codes.ok:
self._logger.info("Process snapshot image")
with i_open(snapshotFilename, 'wb') as snapshot_file:
Expand Down
61 changes: 43 additions & 18 deletions octoprint_PrintJobHistory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from .DatabaseManager import DatabaseManager
from .CameraManager import CameraManager

from octoprint_PrintJobHistory.common import StringUtils


class PrintJobHistoryPlugin(
PrintJobHistoryAPI,
Expand Down Expand Up @@ -290,7 +292,7 @@ def _createPrintJobModel(self, payload):



def _readCurrentTemeratureFromPrinterAsync(self, printer, printJobModel, addTemperatureToPrintModel):
def _readCurrentTemperatureFromPrinterAsync(self, printer, printJobModel, addTemperatureToPrintModel):
dealyInSeconds = self._settings.get_int([SettingsKeys.SETTINGS_KEY_DELAY_READING_TEMPERATURE_FROM_PRINTER])
time.sleep(dealyInSeconds)

Expand All @@ -304,7 +306,7 @@ def _readCurrentTemeratureFromPrinterAsync(self, printer, printJobModel, addTemp

def _readAndAssignCurrentTemperatureDelayed(self, printJobModel):
thread = threading.Thread(name='ReadCurrentTemperature',
target=self._readCurrentTemeratureFromPrinterAsync,
target=self._readCurrentTemperatureFromPrinterAsync,
args=(self._printer, printJobModel, self._addTemperatureToPrintModel,))
thread.daemon = True
thread.start()
Expand Down Expand Up @@ -353,22 +355,27 @@ def _printJobFinished(self, printStatus, payload):
if (slicerSettings.settingsAsText != None and len(slicerSettings.settingsAsText) != 0):
self._currentPrintJobModel.slicerSettingsAsText = slicerSettings.settingsAsText

# Image
if (self._settings.get_boolean([SettingsKeys.SETTINGS_KEY_TAKE_SNAPSHOT_AFTER_PRINT])):
self._cameraManager.takeSnapshotAsync(
CameraManager.buildSnapshotFilename(self._currentPrintJobModel.printStartDateTime),
self._sendErrorMessageToClient
)

if self._settings.get_boolean([SettingsKeys.SETTINGS_KEY_TAKE_PLUGIN_THUMBNAIL_AFTER_PRINT]):
metadata = self._file_manager.get_metadata(payload["origin"], payload["path"])
# check if available
if ("thumbnail" in metadata):
self._cameraManager.takeThumbnailAsync(
CameraManager.buildSnapshotFilename(self._currentPrintJobModel.printStartDateTime),
metadata["thumbnail"])
else:
self._logger.warn("Thumbnail not found in print metadata")
# Image / Thumbnail
if (self._settings.get_boolean([SettingsKeys.SETTINGS_KEY_TAKE_SNAPSHOT_ON_GCODE_COMMAND])):
# Image is (hopefully) already taken by gcode-sent-listener
pass
else:
if (self._settings.get_boolean([SettingsKeys.SETTINGS_KEY_TAKE_SNAPSHOT_AFTER_PRINT])):
self._cameraManager.takeSnapshotAsync(
CameraManager.buildSnapshotFilename(self._currentPrintJobModel.printStartDateTime),
self._sendErrorMessageToClient
)


if self._settings.get_boolean([SettingsKeys.SETTINGS_KEY_TAKE_PLUGIN_THUMBNAIL_AFTER_PRINT]):
metadata = self._file_manager.get_metadata(payload["origin"], payload["path"])
# check if available
if ("thumbnail" in metadata):
self._cameraManager.takeThumbnailAsync(
CameraManager.buildSnapshotFilename(self._currentPrintJobModel.printStartDateTime),
metadata["thumbnail"])
else:
self._logger.warn("Thumbnail not found in print metadata")

# FilamentInformations e.g. length
self._createAndAssignFilamentModel(self._currentPrintJobModel, payload)
Expand Down Expand Up @@ -413,6 +420,20 @@ def on_after_startup(self):
# check if needed plugins were available
self._checkForMissingPluginInfos()

# Listen to all g-code which where already sent to the printer (thread: comm.sending_thread)
def on_sentGCodeHook(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs):
# take snapshot an gcode command
if (self._settings.get_boolean([SettingsKeys.SETTINGS_KEY_TAKE_SNAPSHOT_ON_GCODE_COMMAND])):
gcodePattern = self._settings.get([SettingsKeys.SETTINGS_KEY_TAKE_SNAPSHOT_GCODE_COMMAND_PATTERN])
commandAsString = StringUtils.to_native_str(cmd)
if (commandAsString.startswith(gcodePattern)):
self._cameraManager.takeSnapshotAsync(
CameraManager.buildSnapshotFilename(self._currentPrintJobModel.printStartDateTime),
self._sendErrorMessageToClient
)
pass
pass

def on_event(self, event, payload):
# WebBrowser opened
if Events.CLIENT_OPENED == event:
Expand Down Expand Up @@ -512,6 +533,9 @@ def get_settings_defaults(self):
## Camera
settings[SettingsKeys.SETTINGS_KEY_TAKE_SNAPSHOT_AFTER_PRINT] = True
settings[SettingsKeys.SETTINGS_KEY_TAKE_PLUGIN_THUMBNAIL_AFTER_PRINT] = True
settings[SettingsKeys.SETTINGS_KEY_TAKE_SNAPSHOT_ON_GCODE_COMMAND] = False
settings[SettingsKeys.SETTINGS_KEY_TAKE_SNAPSHOT_GCODE_COMMAND_PATTERN] = "M117 Snap"


## Temperature
settings[SettingsKeys.SETTINGS_KEY_TAKE_TEMPERATURE_FROM_PREHEAT] = True
Expand Down Expand Up @@ -617,6 +641,7 @@ def __plugin_load__():
global __plugin_hooks__
__plugin_hooks__ = {
# "octoprint.server.http.routes": __plugin_implementation__.route_hook,
"octoprint.comm.protocol.gcode.sent": __plugin_implementation__.on_sentGCodeHook,
"octoprint.server.http.bodysize": __plugin_implementation__.bodysize_hook,
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
}
Expand Down
3 changes: 3 additions & 0 deletions octoprint_PrintJobHistory/common/SettingsKeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class SettingsKeys():
## Camera
SETTINGS_KEY_TAKE_SNAPSHOT_AFTER_PRINT = "takeSnapshotAfterPrint"
SETTINGS_KEY_TAKE_PLUGIN_THUMBNAIL_AFTER_PRINT = "takePluginThumbnailAfterPrint"
SETTINGS_KEY_TAKE_SNAPSHOT_ON_GCODE_COMMAND = "takeSnapshotOnGCodeCommnd"
SETTINGS_KEY_TAKE_SNAPSHOT_GCODE_COMMAND_PATTERN = "takeSnapshotGCodeCommndPattern"


SETTINGS_KEY_TAKE_TEMPERATURE_FROM_PREHEAT = "takeTemperatureFromPreHeatPlugin"
SETTINGS_KEY_DELAY_READING_TEMPERATURE_FROM_PRINTER = "delayReadingTemperatureFromPrinter"
Expand Down
8 changes: 7 additions & 1 deletion octoprint_PrintJobHistory/static/js/TableItemHelper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
function TableItemHelper(loadItemsFunction, defaultPageSize, defaultSortColumn, defaultFilterName){
/**
* loadItemsFunction,
* defaultPageSize,
* defaultSortColumn,
* defaultFilterName
*/
function TableItemHelper(loadItemsFunction, defaultPageSize, defaultSortColumn, defaultFilterName){

var self = this;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<!-- <li><a href="#tab-pjh-Visibility" data-toggle="tab">Visibility</a></li>-->
<!-- <li><a href="#tab-pjh-Filament" data-toggle="tab">Filament</a></li>-->
<li><a href="#tab-pjh-Camera" data-toggle="tab">Camera</a></li>
<li><a href="#tab-pjh-Temerature" data-toggle="tab">Temerature</a></li>
<li><a href="#tab-pjh-Temperature" data-toggle="tab">Temperature</a></li>
<li><a href="#tab-pjh-Export-Import" data-toggle="tab">Export / Import</a></li>
<li><a href="#tab-pjh-Storage" data-toggle="tab">Storage</a></li>
<li><a href="#tab-pjh-Debugging" data-toggle="tab">Debugging</a></li>
Expand Down Expand Up @@ -62,25 +62,25 @@
<!-- <div class="tab-pane" id="tab-pjh-Filament">-->
<!-- TODO some filament-settings-->
<!-- </div>-->

<!-- CAMERA - TAB -->
<div class="tab-pane" id="tab-pjh-Camera">
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: pluginSettings.takeSnapshotAfterPrint" > Take snapshot after print
<input type="checkbox" data-bind="checked: pluginSettings.takeSnapshotAfterPrint,
disable: pluginSettings.takeSnapshotOnGCodeCommnd" > Take camera snapshot after print
</label>
<span class="help-inline">Hint: if enabled, the thumbnail image from the gcode is not stored in the history!</span>
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: pluginSettings.takePluginThumbnailAfterPrint" > Use thumbnail (if provided) after print, instead of snapshot
<input type="checkbox" data-bind="checked: pluginSettings.takePluginThumbnailAfterPrint,
disable: pluginSettings.takeSnapshotOnGCodeCommnd" > Use thumbnail (if provided) after print, instead of camera snapshot
</label>
</div>
</div>
<div class="control-group">
<div class="controls">
<div>
<div class="help-inline">
Currently tested thumbnail plugins:
<ul>
<li>Ultimaker Format Package (if uploaded in ufp format)</li>
Expand All @@ -89,9 +89,21 @@
</div>
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: pluginSettings.takeSnapshotOnGCodeCommnd" > Take camera snapshot if following gcode was sent
<div><input type="text" data-bind="value: pluginSettings.takeSnapshotGCodeCommndPattern" ></div>
</label>
<div class="help-inline">
You don't need to enter the command exactly, the plugin checks if the gcode starts with the entered text.
<div>E.g. Text: <code>M117 Snap</code>. Sent gcode was: <code>M117 Snapshot</code>. Result: snapshot is taken</div>
</div>
</div>
</div>
</div>
<!-- TEMPERATURE - TAB -->
<div class="tab-pane" id="tab-pjh-Temerature">
<div class="tab-pane" id="tab-pjh-Temperature">
<div class="control-group">
<div class="">
<label class="checkbox">
Expand Down
19 changes: 11 additions & 8 deletions octoprint_PrintJobHistory/templates/PrintJobHistory_tab.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
</small>
</div>
<div class="pull-right" style="clear: both;">
<small>
Show prints:
<a href="#" data-bind="click: function() { printJobHistoryTableHelper.changeFilter('all'); }"><i class="icon-ok" data-bind="style: {visibility: printJobHistoryTableHelper.isFilterSelected('all') ? 'visible' : 'hidden'}"></i> all</a> |
<a href="#" data-bind="click: function() { printJobHistoryTableHelper.changeFilter('onlySuccess'); }"><i class="icon-ok" data-bind="style: {visibility: printJobHistoryTableHelper.isFilterSelected('onlySuccess') ? 'visible' : 'hidden'}"></i> only successful</a> |
<a href="#" data-bind="click: function() { printJobHistoryTableHelper.changeFilter('onlyFailed'); }"><i class="icon-ok" data-bind="style: {visibility: printJobHistoryTableHelper.isFilterSelected('onlyFailed') ? 'visible' : 'hidden'}"></i> only failed</a>
</small>
<small>
Show prints:
<a href="#" data-bind="click: function() { printJobHistoryTableHelper.changeFilter('all'); }"><i class="icon-ok" data-bind="style: {visibility: printJobHistoryTableHelper.isFilterSelected('all') ? 'visible' : 'hidden'}"></i> all</a> |
<a href="#" data-bind="click: function() { printJobHistoryTableHelper.changeFilter('onlySuccess'); }"><i class="icon-ok" data-bind="style: {visibility: printJobHistoryTableHelper.isFilterSelected('onlySuccess') ? 'visible' : 'hidden'}"></i> only successful</a> |
<a href="#" data-bind="click: function() { printJobHistoryTableHelper.changeFilter('onlyFailed'); }"><i class="icon-ok" data-bind="style: {visibility: printJobHistoryTableHelper.isFilterSelected('onlyFailed') ? 'visible' : 'hidden'}"></i> only failed</a>
</small>
</div>
</div>
</div>
Expand Down Expand Up @@ -201,7 +201,7 @@
</ul>
</div>


<!-- START: PAGEINATION BLOCK -->
<div class="pagination pagination-mini pagination-centered" style="margin:0px">
<ul>
<li data-bind="css: {disabled: printJobHistoryTableHelper.currentPage() === 0}">
Expand All @@ -219,6 +219,8 @@
</li>
</ul>
</div>
<!-- END: PAGEINATION BLOCK -->


<table id="printjobhistory_main_table" class="table table-striped table-hover table-condensed table-hover" style="clear: both;">
<thead>
Expand Down Expand Up @@ -291,7 +293,7 @@




<!-- START: PAGEINATION BLOCK -->
<div class="pagination pagination-mini pagination-centered" style="margin:0px">
<ul>
<li data-bind="css: {disabled: printJobHistoryTableHelper.currentPage() === 0}">
Expand All @@ -309,5 +311,6 @@
</li>
</ul>
</div>
<!-- END: PAGEINATION BLOCK -->

</div>
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plugin_name = "Print Job History"

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

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit 6c0e4fd

Please sign in to comment.