def Var_Round(uVarName: str, uPos: str) -> str: """ Rounds a var value to the given round position. The changed variable value will be return and stored in the user vars (Triggers raised if set) Example: Round(1.81,0) return 2. Round(1.81,1) returns 1.80 :param str uVarName: The variable name for the action, from where the value is pulled :param str uPos: The round position :return: The changed variable value """ uValue: str = GetVar(uVarName=uVarName) try: if uValue == u'': return u'' uPosToUse: str = GetVar(uVarName=uPos) if uPosToUse == u'': uPosToUse = uPos iPos: int = int(uPosToUse) uValue = ToUnicode(Round(ToFloat(uValue), iPos)) SetVar(uVarName=uVarName, oVarValue=uValue) return uValue except Exception as e: LogError(uMsg=u'Var_Round: Invalid Argument [' + uVarName + u'=' + uValue + u']:', oException=e) return u'Error'
def UpdateWidget(self) -> None: """ Updates the silder pos, based on the assigned Var """ uValue: str fMax: float fMin: float super().UpdateWidget() if not self.uDestVar == u'': uValue = GetVar(uVarName=self.uDestVar) fNewValue = ToFloat(uValue) if GetVar(uVarName=self.uMax) != u'': fMax = ToFloat(GetVar(uVarName=self.uMax)) else: fMax = self.fMax if GetVar(uVarName=self.uMin) != u'': fMin = ToFloat(GetVar(uVarName=self.uMin)) else: fMin = self.fMin if fNewValue > fMax: fNewValue = fMax if fNewValue < fMin: fNewValue = fMin if self.oObject: self.oObject.SetValue(fNewValue) self.fValue = Round(fNewValue, self.iRoundPos) self.UpdateVars()
def OnNotifyChange(self, instance: Image) -> None: """ called, when the knob has been turned """ iRangePos: int fRangeProz: float if self.bDiscardMoves and (instance.uMoveType == u'move'): return if not self.uDestVar == u'': iRangePos = self.oObject.iAngle - self.iLeftBoundaryAngle if not self.iRange == 0: fRangeProz = float(iRangePos) / float(self.iRange) else: fRangeProz = 0.0 if self.fMin < self.fMax: self.fValue = Round(self.fMin + self.fDataRange * fRangeProz, self.iRoundPos) else: self.fValue = Round(self.fMin - self.fDataRange * fRangeProz, self.iRoundPos) if self.iRoundPos == 0: self.fValue = int(self.fValue) #fValue=self.fMin+self.fDataRange*fRangeProz # print 'degree:',self.oObject.iAngle # print 'Range:',self.iRange # print 'DataRange:',self.fDataRange # print 'iRangePos:',iRangePos # print 'RangeProz:',fRangeProz # print 'Value:',fValue self.iAbsAngle = self.oObject.iAngle if self.iAbsAngle != 0: self.iAbsAngle = self.iAbsAngle % 360 self.UpdateVars() if not self.uActionName == u'': if self.fOldValue != self.fValue or ( self.iLeftBoundaryAngle == self.iRightBoundaryAngle): self.fOldValue = self.fValue self.On_Button_Up(instance)
def UpdateWidget(self): if not self.uDestVar == u'': if not self.fDataRange == 0: uValue = GetVar(uVarName=self.uDestVar) fNewValue = ToFloat(uValue) iNewProz = (fNewValue - self.fMin) / self.fDataRange iNewDegree = self.iLeftBoundaryAngle + self.iRange * iNewProz self.oObject.SetValue(iNewDegree) self.fValue = Round(fNewValue, self.iRoundPos) self.UpdateVars()
def OnNotifyChange(self, instance): """ will be called, when the slider will be moved """ if self.bDiscardMoves and (instance.uMoveType == u'move'): return if not self.bIsEnabled: return if not self.uDestVar == u'': if self.fMin < self.fMax: self.fValue = Round(self.oObject.value, self.iRoundPos) else: self.fValue = Round(self.fMax - self.oObject.value, self.iRoundPos) if self.iRoundPos == 0: self.fValue = int(self.fValue) self.UpdateVars() if not self.uActionName == u'': if self.fOldValue != self.fValue: self.fOldValue = self.fValue self.On_Button_Up(instance)
def On_Enter(self, instance: TextInput) -> None: """ when the user enters a value without slider """ try: fValue = float(instance.text) if fValue < self.slider.min: fValue = self.slider.min if fValue > self.slider.max: fValue = self.slider.max fValue = Round(fValue, self.iRoundPos) self.slider.value = float(fValue) self.textvalue.text = ToUnicode(fValue) except Exception: pass
def UpdateWidget(self) -> None: super().UpdateWidget() fNewValue: float fNewProz: float fNewDegree: float uValue: str if not self.uDestVar == u'': if not self.fDataRange == 0: uValue = GetVar(uVarName=self.uDestVar) fNewValue = ToFloat(uValue) fNewProz = (fNewValue - self.fMin) / self.fDataRange fNewDegree = self.iLeftBoundaryAngle + self.iRange * fNewProz self.oObject.SetValue(fNewDegree) self.fValue = Round(fNewValue, self.iRoundPos) self.UpdateVars()
def UpdateWidget(self): """ Updates the silder pos, based on the assigned Var """ if not self.uDestVar == u'': uValue = GetVar(uVarName=self.uDestVar) fNewValue = ToFloat(uValue) if isinstance(self.fMax, float): fMax = self.fMax else: fMax = ToFloat(GetVar(uVarName=self.fMax)) if isinstance(self.fMin, float): fMin = self.fMin else: fMin = ToFloat(GetVar(uVarName=self.fMin)) if fNewValue > fMax: fNewValue = fMax if fNewValue < fMin: fNewValue = fMin if self.oObject: self.oObject.SetValue(fNewValue) self.fValue = Round(fNewValue, self.iRoundPos) self.UpdateVars()
def OnSliderMoved(self, instance: Slider, touch) -> None: """ updates the text value, whne the slider is moved """ self.textvalue.text = ToUnicode(Round(instance.value, self.iRoundPos))
def _validate(self, instance) -> None: """ returns the value of the slider """ self._dismiss() self.value = ToUnicode(Round(self.slider.value, self.iRoundPos))