diff --git a/Octoprint_MultiCam_Control.png b/Octoprint_MultiCam_Control.png new file mode 100644 index 0000000..c0c5464 Binary files /dev/null and b/Octoprint_MultiCam_Control.png differ diff --git a/Octoprint_MultiCam_Settings.png b/Octoprint_MultiCam_Settings.png new file mode 100644 index 0000000..8f20077 Binary files /dev/null and b/Octoprint_MultiCam_Settings.png differ diff --git a/README.md b/README.md index 6e2c1a8..ed83e2e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,10 @@ -# OctoPrint_MultiCam -Extends the Control tab of OctoPrint, allowing the ability to switch between multiple webcam feeds. +# OctoPrint MultiCam +Extents the Control tab to include a webcam section with buttons that you can configure in the settings to switch between multiple webcam feeds. + +Future updates will include the more options to show different types of streams, as well as the abilitly to show more than one stream at a time. + +## Screenshots + +![Control Preview][Octoprint_MultiCam_Control.png] + +![Setting Preview][Octoprint_MultiCam_Settings.png] diff --git a/octoprint_multicam/__init__.py b/octoprint_multicam/__init__.py index 1657252..0574fe8 100644 --- a/octoprint_multicam/__init__.py +++ b/octoprint_multicam/__init__.py @@ -6,7 +6,8 @@ class MultiCamPlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplatePlugin, octoprint.plugin.SettingsPlugin, - octoprint.plugin.AssetPlugin): + octoprint.plugin.AssetPlugin, + octoprint.plugin.ReloadNeedingPlugin): def get_assets(self): return dict( @@ -18,7 +19,7 @@ def on_after_startup(self): self._logger.info("MultiCam Loaded! (more: %s)" % self._settings.get(["multicamStream1"])) def get_settings_defaults(self): - return dict(multicam_profiles=[{'name':'Default','URL':octoprint.settings.settings().get(["webcam","stream"])}]) + return dict(multicam_profiles=[{'name':'Default','URL':octoprint.settings.settings().get(["webcam","stream"]), 'isButtonEnabled':'true'}]) def on_settings_save(self, data): old_profiles = self._settings.get(["multicam_profiles"]) @@ -27,11 +28,11 @@ def on_settings_save(self, data): new_profiles = self._settings.get(["multicam_profiles"]) if old_profiles != new_profiles: - self._logger.info("profiles changed from {old_profiles} to {new_profiles} reordering tabs.".format(**locals())) + self._logger.info("profiles changed from {old_profiles} to {new_profiles}".format(**locals())) flattened_profiles = [] for profiles in new_profiles: - flattened_profiles.append(profiles["name"]) - self._settings.global_set(["name","URL"],flattened_profiles) + flattened_profiles.append(profiles['name']) + self._settings.global_set(["name","URL","isButtonEnabled"],flattened_profiles) self._plugin_manager.send_plugin_message(self._identifier, dict(reload=True)) def get_template_configs(self): diff --git a/octoprint_multicam/static/css/multicam.css b/octoprint_multicam/static/css/multicam.css index 0e4ea4b..3e98516 100644 --- a/octoprint_multicam/static/css/multicam.css +++ b/octoprint_multicam/static/css/multicam.css @@ -8,3 +8,33 @@ color: #fff; padding: 0; } + +.ui-pnotify.multicam-reloadneeded .ui-pnotify-container { + background-color: #404040 !important; + background-image: none !important; + border: none !important; + -moz-border-radius: 10px; + -webkit-border-radius: 10px; + border-radius: 10px; +} +.ui-pnotify.multicam-reloadneeded .ui-pnotify-title, .ui-pnotify.multicam-reloadneeded .ui-pnotify-text { + color: #FFF !important; +} +.ui-pnotify.multicam-reloadneeded .ui-pnotify-title { + font-weight: bold; + margin-bottom: 10px; + padding-bottom: 10px; + border-bottom: 1px solid #FFF; + text-indent: -60px; +} +.ui-pnotify.multicam-reloadneeded .ui-pnotify-icon { + margin-top: 40px; + float: left; +} +.ui-pnotify.multicam-reloadneeded .icon { + margin: 10px; + width: 40px; + height: 40px; + font-size: 40px; + color: #FFF; +} diff --git a/octoprint_multicam/static/js/multicam.js b/octoprint_multicam/static/js/multicam.js index 1101a1b..4316926 100644 --- a/octoprint_multicam/static/js/multicam.js +++ b/octoprint_multicam/static/js/multicam.js @@ -4,52 +4,108 @@ $(function() { var camViewPort = $('#webcam_image'); - var currentStream = ""; //camViewPort.attr('src').substr(0, camViewPort.attr('src').indexOf('?')); - self.settings = parameters[0]; self.multicam_profiles = ko.observableArray(); + self.enabled_buttons = ko.observableArray(); + self.onBeforeBinding = function() { self.multicam_profiles(self.settings.settings.plugins.multicam.multicam_profiles()); }; + self.onSettingsBeforeSave = function() { + ko.utils.arrayForEach(self.multicam_profiles(), function (item, index) { + if(index == 0 && item.URL != $('#settings-webcamStreamUrl').val()) { + console.log("Changes Detected in Webcam & Timelaspse URL"); + item.URL($('#settings-webcamStreamUrl').val()); + } + }); + self.onAfterTabChange(); + }; + self.onEventSettingsUpdated = function(payload) { - self.multicam_profiles(self.settings.settings.plugins.multicam.multicam_profiles()); + //self.multicam_profiles(self.settings.settings.plugins.multicam.multicam_profiles()); + self.settings.settings.plugins.multicam.multicam_profiles(self.multicam_profiles.slice(0)); }; self.addMultiCamProfile = function() { - //console.log("Adding New profile for Webcam "+self.multicam_profiles().length); - self.settings.settings.plugins.multicam.multicam_profiles.push({name: ko.observable('Webcam '+self.multicam_profiles().length), URL: ko.observable('http://')}); - //console.log("Updating local multicam_profiles variable"); + self.settings.settings.plugins.multicam.multicam_profiles.push({name: ko.observable('Webcam '+self.multicam_profiles().length), URL: ko.observable('http://'), isButtonEnabled: ko.observable(true)}); self.multicam_profiles(self.settings.settings.plugins.multicam.multicam_profiles()); }; self.removeMultiCamProfile = function(profile) { - //console.log("Removing profile"); self.settings.settings.plugins.multicam.multicam_profiles.remove(profile); - //console.log("Updating local multicam_profiles variable"); self.multicam_profiles(self.settings.settings.plugins.multicam.multicam_profiles()); }; - //TODO: get binding working with: enable: $parent.currentLoaded(URL) - self.currentLoaded = function(URL) { - return URL != currentStream; - }.bind(MultiCamViewModel); - self.loadWebcam = function(profile, event) { - console.log("CurrentStream:"+currentStream); - console.log("Changing stream to: "+ko.toJS(profile).URL); camViewPort.attr('src',ko.toJS(profile).URL); - currentStream = ko.toJS(profile).URL; + //console.log(ko.toJS(self.multicam_profiles())); + ko.utils.arrayForEach(self.multicam_profiles(), function (item) { + item.isButtonEnabled(true); + }); + profile.isButtonEnabled(false); + //console.log(ko.toJS(self.multicam_profiles())); }; self.onAfterBinding = function() { var camControl = $('#camControl'); var container = $('#control-jog-general'); - // Inserts the control after the general settings under Control Tab camControl.insertAfter(container); + camControl.css('display', ''); + }; + + self.onAfterTabChange = function(current, previous) { + ko.utils.arrayForEach(self.multicam_profiles(), function (item, index) { + if(index == 0) { + item.isButtonEnabled(false); + } else { + item.isButtonEnabled(true); + } + }); + }; + + //Saving the buttons seems to effect the databinding, until the bug is fixed a reload of the ui is required! + self.onDataUpdaterPluginMessage = function(plugin, data) { + if (plugin != "multicam") { + return; + } + if (data.reload) { + new PNotify({ + title: 'Reload Required', + text: 'MultiCam has changed and a reload of the web interface is required.\n\nAfter the save operation is complete<\/span> press the F5<\/span> key.\n', + hide: false, + icon: 'icon icon-refresh', + addclass: 'multicam-reloadneeded', + confirm: { + confirm: true, + buttons: [{ + text: 'Ok', + addClass: 'btn', + click: function(notice) { + notice.remove(); + } + }, + { + text: 'Cancel', + addClass: 'hidden', + click: function(notice) { + notice.remove(); + } + }, + ] + }, + buttons: { + closer: false, + sticker: false + }, + history: { + history: false + } + }); + }; }; } diff --git a/octoprint_multicam/templates/multicam.jinja2 b/octoprint_multicam/templates/multicam.jinja2 index 4a41a16..ac5163d 100644 --- a/octoprint_multicam/templates/multicam.jinja2 +++ b/octoprint_multicam/templates/multicam.jinja2 @@ -1,8 +1,8 @@ -
+ diff --git a/octoprint_multicam/templates/multicam_settings.jinja2 b/octoprint_multicam/templates/multicam_settings.jinja2 index f280771..cd75c59 100644 --- a/octoprint_multicam/templates/multicam_settings.jinja2 +++ b/octoprint_multicam/templates/multicam_settings.jinja2 @@ -11,10 +11,10 @@
- +
- +
diff --git a/setup.py b/setup.py index 78b9392..30c1751 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ plugin_name = "OctoPrint-MultiCam" # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "0.1.0" +plugin_version = "0.2.0" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module