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': '