diff --git a/octoprint_toptemp/__init__.py b/octoprint_toptemp/__init__.py index 6f8897a..16cc44e 100644 --- a/octoprint_toptemp/__init__.py +++ b/octoprint_toptemp/__init__.py @@ -38,7 +38,7 @@ def __init__(self): # List of psu self.psutilList = { - 'cpup' : ['CPU usage percentage'], + 'cpup' : ['CPU usage %'], 'cpuf' : ['CPU frequency in MHz'], 'loadavg1' : ['Average system load last 1 minute'], 'loadavg5' : ['Average system load last 5 minutes'], @@ -47,11 +47,11 @@ def __init__(self): 'memavail' : ['Total available memory in MB'], 'memused' : ['Memory used in MB'], 'memfree' : ['Memory not being used at all in MB'], - 'memp' : ['Memory free percentage'], + 'memp' : ['Memory free %'], 'swaptotal' : ['Total swap memory in MB'], 'swapused' : ['Used swap memory in MB'], 'swapfree' : ['Free swap memory in MB'], - 'swapperc' : ['Free swap percentage'] + 'swapperc' : ['Free swap %'] } # Gcode handling @@ -71,6 +71,7 @@ def __init__(self): 'fahrenheit' : False, 'leftAlignIcons' : False, 'hideInactiveTemps' : True, + 'clickPopover' : False, 'noTools' : self.noTools, 'sortOrder': ['bed','tool0','tool1','chamber','cu0'], 'outerMargin': 4, @@ -361,10 +362,10 @@ def buildPsuUtil(self): partitions = [partition._asdict() for partition in psutil.disk_partitions()] count = 0 for partition in partitions: - self.psutilList['diskfree_'+str(count)] = ["Disk free "+partition['mountpoint'],partition['mountpoint']] - self.psutilList['disktotal_'+str(count)] = ["Disk total "+partition['mountpoint'],partition['mountpoint']] - self.psutilList['diskused_'+str(count)] = ["Disk used "+partition['mountpoint'],partition['mountpoint']] - self.psutilList['diskperc_'+str(count)] = ["Disk used percent "+partition['mountpoint'],partition['mountpoint']] + self.psutilList['diskfree_'+str(count)] = ["Disk free \""+partition['mountpoint']+"\"",partition['mountpoint']] + self.psutilList['disktotal_'+str(count)] = ["Disk total \""+partition['mountpoint']+"\"",partition['mountpoint']] + self.psutilList['diskused_'+str(count)] = ["Disk used \""+partition['mountpoint']+"\"",partition['mountpoint']] + self.psutilList['diskperc_'+str(count)] = ["Disk used % \""+partition['mountpoint']+"\"",partition['mountpoint']] count += 1 # temperatures @@ -403,7 +404,7 @@ def buildPsuUtil(self): if hasattr(psutil, "sensors_battery"): battery = psutil.sensors_battery() if battery: - self.psutilList['batper'] = ["Battery power left percentage"] + self.psutilList['batper'] = ["Battery power left %"] self.psutilList['batsec'] = ["Battery power left seconds"] self.debugOut(self.psutilList) @@ -569,6 +570,23 @@ def runPSUtil(self,indx,cmd,returnData = False): # 'swapused' : ['Used swap memory'], # 'swapfree' : ['Free swap memory'], # 'swapperc' : ['Free swap percentage'] + # Icons to the above + # + # + # + # + # + # + # + # + # + # + # exchange-alt + # + # disk: + # temp: + # fan: + # battery: # self.psutilList['diskfree_'+str(count)] = ["Disk free "+partition['mountpoint'],partition['mountpoint']] # self.psutilList['disktotal_'+str(count)] = ["Disk total "+partition['mountpoint'],partition['mountpoint']] # self.psutilList['diskused_'+str(count)] = ["Disk used "+partition['mountpoint'],partition['mountpoint']] @@ -635,7 +653,7 @@ def runPSUtil(self,indx,cmd,returnData = False): if returnVal: self.debugOut("psutil " + cmd + " returned: " + str(returnVal) + " for index :"+indx) if returnData: - return returnVal; + return returnVal self.handleCustomData(indx,returnVal,time.time()) # Disk @@ -677,11 +695,11 @@ def runPSUtil(self,indx,cmd,returnData = False): if returnVal: self.debugOut("psutil " + cmd + " returned: " + str(returnVal) + " for index :"+indx) if returnData: - return returnVal; + return returnVal self.handleCustomData(indx,returnVal,time.time()) if returnData: - return None; + return None def handleCustomData(self,indx,out,time): self.debugOut("Got custom data: " + str(out)) @@ -709,7 +727,8 @@ def get_api_commands(self): monitorService=[], getCustomHistory=[], getDefaultSettings=[], - getPredefined=['reload'] + getPredefined=['reload'], + getItems=[] ) # handle api calls @@ -727,6 +746,26 @@ def on_api_command(self, command, data): self.debugOut("Sending options") return flask.jsonify({'cmds' : self.tempCmds,'psutil' : self.psutilList}) + if command == "getItems": + self._logger.info("Sending items monitored") + sortOrder = self._settings.get(["sortOrder"],merged=True,asdict=True) + custom = self._settings.get(["customMon"],merged=True,asdict=True) + curTemps = self._printer.get_current_temperatures(); + returnList = {} + lastValues = {} + for item in sortOrder: + lastVal = None + if item in custom: + returnList[item] = custom[item] + if item in self.customHistory: + lastVal = self.customHistory[item] and self.customHistory[item][-1][1] or None + else: + if item in curTemps: + lastVal = curTemps[item]['actual'] + returnList[item] = self._settings.get([item],merged=True,asdict=True) + lastValues[item] = lastVal + return flask.jsonify({'items' : returnList,'lastValues': lastValues}) + # Get history data if command == "getCustomHistory": self.debugOut("Sending custom history") diff --git a/octoprint_toptemp/static/css/TopTemp.css b/octoprint_toptemp/static/css/TopTemp.css index 8c3ccd7..5f5d7d7 100644 --- a/octoprint_toptemp/static/css/TopTemp.css +++ b/octoprint_toptemp/static/css/TopTemp.css @@ -48,6 +48,17 @@ height: 100%; overflow: hidden; } +#navbar_plugin_toptemp div.TopTempPrinter.popclick, #navbar_plugin_toptemp div.TopTempCustom.popclick{ + cursor: pointer; +} + +@media (max-width: 767px){ + #navbar_plugin_toptemp div.TopTempPrinter div.navbar-text, #navbar_plugin_toptemp div.TopTempCustom div.navbar-text{ + height: 100%; + margin-top: 6px; + line-height: initial; + } +} #navbar_plugin_toptemp div .TopTempIcon{ display: block; @@ -152,6 +163,12 @@ div.popover.toptempPopover { z-index: 1030; } +div.popover.toptempPopover .popover-title a{ + float: left; + margin-right: 5px; + margin-left: -8px; +} + #navbar_plugin_toptemp div.TopTempGraph .ct-line { stroke-width: 1px; stroke-opacity: 0.4; @@ -214,4 +231,8 @@ body.TopTemPreviewON div#settings_dialog { color: #333; } +#navbar_plugin_toptemp > div:not(.IconsLeft) .navbar-text{ + line-height: 15px; +} + /* TopTemp END */ \ No newline at end of file diff --git a/octoprint_toptemp/static/js/TopTemp.js b/octoprint_toptemp/static/js/TopTemp.js index ef2d710..915a3c2 100644 --- a/octoprint_toptemp/static/js/TopTemp.js +++ b/octoprint_toptemp/static/js/TopTemp.js @@ -43,6 +43,7 @@ $(function() { 'gcOut': { 'Cooling fan speed' : '^M106.*?S([^ ]+)', 'Feedrate %' : '^M220 S([^ ]+)', + '% Completed' : '^M73.*?P(\\d+)', // 'Extruder feed rate' : '^(?:G0|G1).*?F([^ ]+)' } }; @@ -101,7 +102,7 @@ $(function() { } }else{ var reval = 0; - graphData = {'series' : [OctoPrint.coreui.viewmodels.temperatureViewModel.temperatures[name].actual.slice(-300).map(function(val,i){return val[1]})]}; + graphData = {'series' : [self.tempModel.temperatures[name].actual.slice(-300).map(function(val,i){return val[1]})]}; } // DO we have what we need if (graphData != null && typeof Chartist == "object"){ @@ -267,7 +268,7 @@ $(function() { } } - // CPU Temps + // Custom data self.onDataUpdaterPluginMessage = function(plugin, data) { if (plugin != "toptemp"){ return; @@ -1038,7 +1039,6 @@ $(function() { } if (self.isCustom(name)){ self.buildContainer(name,'TopTempCustom TopTempLoad'); - }else{ self.buildContainer(name,'TopTempPrinter TopTempLoad'); } @@ -1078,10 +1078,16 @@ $(function() { return; } + // How should we show popovers + var popoverDmethod = 'manual'; + if (self.settings.clickPopover()){ + popoverDmethod = "click"; + } + // Initial creation if (!$this.data('popover') != null || !$this.data('popover').enabled){ $this.popover({ - 'trigger': 'manual', + 'trigger': popoverDmethod, 'placement' : 'bottom', 'container': '#page-container-main', 'html' : true, @@ -1092,19 +1098,19 @@ $(function() { if (iconClone.length){ iconstr = iconClone.clone().addClass('pull-right').wrap('

').parent().html() } + if (self.settings.clickPopover()){ + iconstr += ''; + } return self.getTempName($thisID)+iconstr; }, 'content': '

Wait…
' }); } - - // Show the popover and update content - $this.off('mouseenter').on('mouseenter',function(){ - if ($this.hasClass('TopTempLoad')){ - return; + // On show + $this.on('shown',function(){ + if (self.popoverOpen && self.settings.clickPopover()){ + $('#navbar_plugin_toptemp >div').not($this).popover('hide') } - // Fix offset problems - $this.popover('show'); self.popoverOpen = true; // Fix arrows hacks for small screens if ($(window).width() <=767){ @@ -1114,12 +1120,29 @@ $(function() { } // Build contents self.updatePopover($thisID,$isCustom,isettings); + }); + + // On hidden + $this.on('hidden',function(){ + self.popoverOpen = false; + }) + + // Show the popover and update content + $this.off('mouseenter').on('mouseenter',function(){ + if ($this.hasClass('TopTempLoad')){ + return; + } + // Fix offset problems + if (popoverDmethod == "manual"){ + $this.popover('show'); + } }).off('mouseleave').on('mouseleave',function(){ if ($this.hasClass('TopTempLoad')){ return; } - self.popoverOpen = false; - $this.popover('hide'); + if (popoverDmethod == "manual"){ + $this.popover('hide'); + } }).attr('title',"Show more information"); }); } @@ -1143,8 +1166,8 @@ $(function() { $('#TopTempPopoverText_'+$thisID).html(output); } }else{ - var actual = OctoPrint.coreui.viewmodels.temperatureViewModel.temperatures[$thisID].actual[OctoPrint.coreui.viewmodels.temperatureViewModel.temperatures[$thisID].actual.length-1][1]; - var target = OctoPrint.coreui.viewmodels.temperatureViewModel.temperatures[$thisID].target[OctoPrint.coreui.viewmodels.temperatureViewModel.temperatures[$thisID].target.length-1][1]; + var actual = self.tempModel.temperatures[$thisID].actual[self.tempModel.temperatures[$thisID].actual.length-1][1]; + var target = self.tempModel.temperatures[$thisID].target[self.tempModel.temperatures[$thisID].target.length-1][1]; var output = '
Actual: '+self.formatTempLabel($thisID,actual,iSettings)+'
Target: '; if (target == 0){ output += 'Off'; @@ -1261,8 +1284,8 @@ $(function() { // Assign it graphData = { 'series' : [ - {'data':buildSeries([...OctoPrint.coreui.viewmodels.temperatureViewModel.temperatures[$thisID].actual]),'className':'ct-series-a'}, - {'data':buildSeries([...OctoPrint.coreui.viewmodels.temperatureViewModel.temperatures[$thisID].target]),'className':'ct-series-g'}, + {'data':buildSeries([...self.tempModel.temperatures[$thisID].actual]),'className':'ct-series-a'}, + {'data':buildSeries([...self.tempModel.temperatures[$thisID].target]),'className':'ct-series-g'}, ] }; } @@ -1367,33 +1390,40 @@ $(function() { // Build a single container self.buildContainer = function(name,className){ var elname = 'navbar_plugin_toptemp_'+name; - var settings = self.getSettings(name); + var localSettings = self.getSettings(name); // Get name prettyName = self.getTempName(name); // Set type var isCust = false; if (self.isCustom(name)){ isCust = true; - if (settings.waitForPrint()){ + if (localSettings.waitForPrint()){ className += " TopTempWaitPrinter"; } } if (self.settings.leftAlignIcons()){ className += " IconsLeft"; } + var textClass = "TopTempText"; + if (!localSettings.graphSettings.show()){ + textClass = "navbar-text"; + } // Remove old $('#'+elname).remove(); // Build new - $('#navbar_plugin_toptemp').append('
'); - if (!settings.show()){ + if (self.settings.clickPopover() && localSettings.graphSettings.show()){ + className += " popclick"; + } + $('#navbar_plugin_toptemp').append('
'); + if (!localSettings.show()){ $('#'+elname).hide(); } // Set fixed width if entered - if (settings.width() > 0){ - $('#'+elname).css({'width':settings.width()+'px'}); + if (localSettings.width() > 0){ + $('#'+elname).css({'width':localSettings.width()+'px'}); } - self.setGraphStyle(name,settings.graphSettings); + self.setGraphStyle(name,localSettings.graphSettings); return elname; } diff --git a/octoprint_toptemp/templates/toptemp_settings.jinja2 b/octoprint_toptemp/templates/toptemp_settings.jinja2 index 5378142..6152894 100644 --- a/octoprint_toptemp/templates/toptemp_settings.jinja2 +++ b/octoprint_toptemp/templates/toptemp_settings.jinja2 @@ -46,6 +46,13 @@
+
+
+ +
+
@@ -130,7 +137,7 @@
- +
Blank for no icon
@@ -270,7 +277,7 @@
- +
Blank for no icon
@@ -410,7 +417,7 @@
- +
Blank for no icon
@@ -513,8 +520,8 @@ - "Command" is a command executed on the RPI/PC. "GCode sent" will look at the GCode sent to the printer and return a value based on the reg. exp. - "From printer" will look at the data returned from the printer and return a value based on the reg. exp. "Server data" will get data from RPI/PC. + "Command" is a command executed on the RPI/PC. "GCode sent" will look at the GCode sent to the printer and return a value based on the Regexp. + "From printer" will look at the data returned from the printer and return a value based on the Regexp. "Server data" will get data from built-in sensors and hardware info on the RPI/PC.
@@ -616,7 +623,7 @@
- +
Blank for no icon
diff --git a/setup.py b/setup.py index b31ca10..199465c 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ plugin_name = "Top Temp" # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "0.0.1.4" +plugin_version = "0.0.1.5" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module