From 41470488934e851fcdd0ba70e0d519913de0daee Mon Sep 17 00:00:00 2001 From: MAKOMO Date: Tue, 12 Nov 2019 19:03:57 +0100 Subject: [PATCH] - improves on an overlap between the symbolic variable Y1 and Y11 - runs disconnectProbes in the background on OFF - ensures that Phidgets properly detach from the PhidgetManager on close to allow for a successful reconnect - updates Phidget lib - selects a higher-contrast text color for the tacked bar graph in the HTML ranking report (Issue #427) - updated Brazilian translations (thanks to Rodrigo!) --- src/artisanlib/main.py | 151 ++++++++++++++++++++---------- src/artisanlib/phidgets.py | 6 +- src/requirements.txt | 2 +- src/translations/artisan_pt_BR.ts | 107 ++++++++++----------- 4 files changed, 158 insertions(+), 108 deletions(-) mode change 100755 => 100644 src/translations/artisan_pt_BR.ts diff --git a/src/artisanlib/main.py b/src/artisanlib/main.py index 99108988c..f7a4b9d3d 100644 --- a/src/artisanlib/main.py +++ b/src/artisanlib/main.py @@ -4175,7 +4175,7 @@ def eval_math_expression(self,mathexpression,t,equeditnumber=None, RTsname=None, for i in range(len(timeshiftexpressions)): if timeshiftexpressions[i] not in mathdictionary: mathdictionary[timeshiftexpressions[i]] = timeshiftexpressionsvalues[i] - except: + except Exception: pass #background symbols just in case there was no profile loaded but a background loaded. @@ -4185,18 +4185,20 @@ def eval_math_expression(self,mathexpression,t,equeditnumber=None, RTsname=None, mathdictionary[timeshiftexpressions[i]] = timeshiftexpressionsvalues[i] try: # we exclude the main_events as they occur as substrings in others like CHARGE in dCHARGE - if any([k in mathexpression for k,v in mathdictionary.items() if (v == -1 and not (k in main_events))]): + # the special case of a variable Y1 overlapping with a variable Y11,..,Y12 in this simple test has to be excluded to avoid + # that if mathexpression="Y11" and mathdictionary contains {"Y1":-1} -1 is returned instead of the correct value of Y11 + if any([((k in mathexpression) if k!="Y1" else False) for k,v in mathdictionary.items() if (v == -1 and not (k in main_events))]): # if any variable is bound to the error value -1 we return -1 for the full formula return -1 else: res = float(eval(mathexpression,{"__builtins__":None},mathdictionary)) - except TypeError as e: + except TypeError: res = -1 - except ValueError as e: + except ValueError: res = -1 - except ZeroDivisionError as e: + except ZeroDivisionError: res = -1 - except IndexError as e: + except IndexError: res = -1 if res is None: return -1 @@ -7423,7 +7425,7 @@ def samplingAction(self): def AsyncSamplingActionTrigger(self): if aw.AsyncSamplingAction and aw.qmc.extra_event_sampling_delay and aw.qmc.extrabuttonactions[2]: - self.samplingAction() + self.samplingAction() QTimer.singleShot(aw.qmc.extra_event_sampling_delay,self.AsyncSamplingActionTrigger) def StartAsyncSamplingAction(self): @@ -7589,7 +7591,7 @@ def OffMonitor(self): self.flagon = False # now wait until the current sampling round is done while self.flagsampling: - libtime.sleep(0.02) + libtime.sleep(0.05) QApplication.processEvents() if len(self.timex) < 3: # clear data from monitoring-only mode @@ -7609,7 +7611,7 @@ def OffMonitor(self): except: pass aw.fujipid.sv = 0 - self.disconnectProbes() + QTimer.singleShot(5,self.disconnectProbes) # QApplication.processEvents() #enable RESET button: aw.button_7.setStyleSheet(aw.pushbuttonstyles["RESET"]) @@ -7631,13 +7633,13 @@ def OffMonitor(self): self.updateWebLCDs(bt=resLCD,et=resLCD) if not aw.HottopControlActive: aw.hideExtraButtons(changeDefault=False) - aw.updateSlidersVisibility() # update visibility of sliders based on the users preference - aw.updateExtraButtonsVisibility() + aw.updateSlidersVisibility() # update visibility of sliders based on the users preference + aw.updateExtraButtonsVisibility() aw.pidcontrol.activateONOFFeasySV(False) self.StopAsyncSamplingAction() aw.enableEditMenus() # QApplication.processEvents() - aw.qmc.redraw(recomputeAllDeltas=True,smooth=True) + aw.qmc.redraw(recomputeAllDeltas=True,smooth=True) if len(self.timex) > 2: # we autosave after full redraw after OFF to have the optional generated PDF containing all information if aw.qmc.autosaveflag and aw.qmc.autosavepath: @@ -7650,8 +7652,6 @@ def OffMonitor(self): # QApplication.processEvents() if recording and self.flagKeepON: self.OnMonitor() -# else: -# self.stopPhidgetManager() except Exception as ex: _, _, exc_tb = sys.exc_info() aw.qmc.adderror((QApplication.translate("Error Message", "Exception:",None) + " OffMonitor() {0}").format(str(ex)),exc_tb.tb_lineno) @@ -7728,23 +7728,40 @@ def disconnectProbesFromSerialDevice(self,ser): except Exception: pass # disconnect phidgets - if ser.PhidgetTemperatureSensor: + if ser.PhidgetTemperatureSensor is not None: try: if ser.PhidgetTemperatureSensor[0].getAttached(): + serial = ser.PhidgetTemperatureSensor[0].getDeviceSerialNumber() + port = ser.PhidgetTemperatureSensor[0].getHubPort() # returns 0 for USB Phidgets! + deviceType = ser.PhidgetTemperatureSensor[0].getDeviceID() ser.PhidgetTemperatureSensor[0].close() + ser.phidget1048detached(serial,port,deviceType,0) # call detach handler to release from PhidgetManager + except Exception: + pass + try: if len(ser.PhidgetTemperatureSensor) > 1 and ser.PhidgetTemperatureSensor[1].getAttached(): + serial = ser.PhidgetTemperatureSensor[1].getDeviceSerialNumber() + port = ser.PhidgetTemperatureSensor[1].getHubPort() # returns 0 for USB Phidgets! + deviceType = ser.PhidgetTemperatureSensor[1].getDeviceID() ser.PhidgetTemperatureSensor[1].close() + ser.phidget1048detached(serial,port,deviceType,1) # call detach handler to release from PhidgetManager except Exception: pass ser.Phidget1048values = [[],[],[],[]] ser.Phidget1048lastvalues = [-1]*4 ser.PhidgetTemperatureSensor = None - if ser.PhidgetIRSensor: + if ser.PhidgetIRSensor is not None: try: if ser.PhidgetIRSensor.getAttached(): + serial = ser.PhidgetIRSensor.getDeviceSerialNumber() + port = ser.PhidgetIRSensor.getHubPort() # returns 0 for USB Phidgets! + deviceType = ser.PhidgetIRSensor.getDeviceID() ser.PhidgetIRSensor.close() - - if ser.PhidgetIRSensorIC.getAttached(): + ser.phidget1045detached(serial,port,deviceType) # call detach handler to release from PhidgetManager + except Exception: + pass + try: + if ser.PhidgetIRSensorIC is not None and ser.PhidgetIRSensorIC.getAttached(): ser.PhidgetIRSensorIC.close() except Exception: pass @@ -7753,29 +7770,53 @@ def disconnectProbesFromSerialDevice(self,ser): ser.Phidget1045lastvalue = -1 ser.Phidget1045tempIRavg = None ser.PhidgetIRSensorIC = None - if ser.PhidgetBridgeSensor: + if ser.PhidgetBridgeSensor is not None: try: if ser.PhidgetBridgeSensor[0].getAttached(): + serial = ser.PhidgetBridgeSensor[0].getDeviceSerialNumber() + port = ser.PhidgetBridgeSensor[0].getHubPort() # returns 0 for USB Phidgets! + deviceType = ser.PhidgetBridgeSensor[0].getDeviceID() ser.PhidgetBridgeSensor[0].close() + ser.phidget1046detached(serial,port,deviceType,0) # call detach handler to release from PhidgetManager + except Exception: + pass + try: if len(ser.PhidgetBridgeSensor) > 1 and ser.PhidgetBridgeSensor[1].getAttached(): + serial = ser.PhidgetBridgeSensor[1].getDeviceSerialNumber() + port = ser.PhidgetBridgeSensor[1].getHubPort() # returns 0 for USB Phidgets! + deviceType = ser.PhidgetBridgeSensor[1].getDeviceID() ser.PhidgetBridgeSensor[1].close() + ser.phidget1046detached(serial,port,deviceType,1) # call detach handler to release from PhidgetManager except Exception: pass ser.Phidget1046values = [[],[],[],[]] ser.Phidget1046lastvalues = [-1]*4 ser.PhidgetBridgeSensor = None - if ser.PhidgetIO: + if ser.PhidgetIO is not None: try: if ser.PhidgetIO[0].getAttached(): + serial = ser.PhidgetIO[0].getDeviceSerialNumber() + port = ser.PhidgetIO[0].getHubPort() # returns 0 for USB Phidgets! + className = ser.PhidgetIO[0].getChannelClassName() + deviceType = ser.PhidgetIO[0].getDeviceID() ser.PhidgetIO[0].close() + ser.phidget1018detached(serial,port,className,deviceType,0) + except Exception: + pass + try: if len(ser.PhidgetIO) > 1 and ser.PhidgetIO[1].getAttached(): + serial = ser.PhidgetIO[1].getDeviceSerialNumber() + port = ser.PhidgetIO[1].getHubPort() # returns 0 for USB Phidgets! + className = ser.PhidgetIO[1].getChannelClassName() + deviceType = ser.PhidgetIO[1].getDeviceID() ser.PhidgetIO[1].close() + ser.phidget1018detached(serial,port,className,deviceType,1) except Exception: pass ser.PhidgetIO = None ser.PhidgetIOvalues = [[],[],[],[],[],[],[],[]] ser.PhidgetIOlastvalues = [-1]*8 - if ser.YOCTOsensor: + if ser.YOCTOsensor is not None: try: ser.YOCTOsensor = None ser.YOCTOchan1 = None @@ -25989,9 +26030,10 @@ def rankingReport(self,_=False): # setup the font if sys.platform.startswith("darwin") and darkdetect.isDark(): - fontcolor = 'lightgrey' + headerfontcolor = '#B2B2B2' else: - fontcolor = 'darkgrey' + headerfontcolor = '#707070' + fontcolor = '#303030' lightfontcolor = 'grey' prop.set_family(mpl.rcParams['font.family']) @@ -26024,11 +26066,11 @@ def rankingReport(self,_=False): ], (i*(barheight + barspacer), barheight*0.75), facecolors=facecolors ) - ax.text( m/2, i*(barheight + barspacer) + textoffset/3, 'Nr', ha='center', color=fontcolor, fontproperties=prop) - ax.text( 1+ n+g, i*(barheight + barspacer) + textoffset/3, 'Dry', ha='left', color=fontcolor, fontproperties=prop) - ax.text( 1+ n+g+ind+g, i*(barheight + barspacer) + textoffset/3, 'Mai', ha='left', color=fontcolor, fontproperties=prop) - ax.text( 1+ n+g+ind+g+ind+g, i*(barheight + barspacer) + textoffset/3, 'Dev', ha='left', color=fontcolor, fontproperties=prop) - ax.text( n+100 + 10/2, i*(barheight + barspacer) + textoffset/3, 'Drop', ha='center', color=fontcolor, fontproperties=prop) + ax.text( m/2, i*(barheight + barspacer) + textoffset/3, 'Nr', ha='center', color=headerfontcolor, fontproperties=prop) + ax.text( 1+ n+g, i*(barheight + barspacer) + textoffset/3, 'Dry', ha='left', color=headerfontcolor, fontproperties=prop) + ax.text( 1+ n+g+ind+g, i*(barheight + barspacer) + textoffset/3, 'Mai', ha='left', color=headerfontcolor, fontproperties=prop) + ax.text( 1+ n+g+ind+g+ind+g, i*(barheight + barspacer) + textoffset/3, 'Dev', ha='left', color=headerfontcolor, fontproperties=prop) + ax.text( n+100 + 10/2, i*(barheight + barspacer) + textoffset/3, 'Drop', ha='center', color=headerfontcolor, fontproperties=prop) # generate the bar graph prop.set_size("small") @@ -38712,7 +38754,7 @@ def showSliderHelp(self,_): string += u(QApplication.translate("Message", "
  • mwrite(slaveId,register,andMask,orMask)
    mask write register: MODBUS function 22",None)) string += u(QApplication.translate("Message", "
  • writem(slaveId,register,value) or writem(slaveId,register,[<int>,..,<int>])
    write registers: MODBUS function 16",None)) string += u(QApplication.translate("Message", "
  • writeBCD(slaveId,register,value) or writeBCD(slaveId,register,[<int>,..,<int>])
    write BCD encoded int register: MODBUS function 16 (BCD)",None)) - string += u(QApplication.translate("Message", "
  • writeWord(slaveId,register,value) or writeWord(slaveId,register,[<int>,..,<int>])
    write 32bit float to two 16bit int registers: MODBUS function 16 (Float)",None)) + string += u(QApplication.translate("Message", "
  • writeWord(slaveId,register,value)
    write 32bit float to two 16bit int registers: MODBUS function 16",None)) string += u(QApplication.translate("Message", "writes values to the registers in slaves specified by the given id",None)) string += u(QApplication.translate("Message", "
  • DTA Command: Insert Data address : value, ex. 4701:1000 and sv is 100. always multiply with 10 if value Unit: 0.1 / ex. 4719:0 stops heating",None)) + "" string += u(QApplication.translate("Message", "Offset added as offset to the slider value",None)) + "
    " @@ -40087,6 +40129,7 @@ def showEventbuttonhelp(self,_): string += u(QApplication.translate("Message", "
  • wcoils(slaveId,register,[<bool>,..,<bool>])
    write coils: MODBUS function 15",None)) string += u(QApplication.translate("Message", "
  • mwrite(slaveId,register,andMask,orMask)
    mask write register: MODBUS function 22",None)) string += u(QApplication.translate("Message", "
  • writem(slaveId,register,value) or writem(slaveId,register,[<int>,..,<int>])
    write registers: MODBUS function 16",None)) + string += u(QApplication.translate("Message", "
  • writeWord(slaveId,register,value)
    write 32bit float to two 16bit int registers: MODBUS function 16",None)) string += u(QApplication.translate("Message", "writes values to the registers in slaves specified by the given id",None)) string += u(QApplication.translate("Message", "
  • S7 Command: