# -*- coding: utf-8 -*- import names import math import squish from time import sleep from dialin.ui import utils from dialin.ui import unittests from dialin.ui.hd_simulator import HDSimulator def TriggerDragAndDrop(Obj=None, topLeftXOffset=150, topLeftYOffset=None): """ Function to enter into drag and drop mode in squish. Arguments: Obj - target object topLeftXOffset - int value for X offset of widget topLeftXOffset - int value for Y offset of widget Return: None """ objRect = object.globalBounds(Obj) x = objRect.x if topLeftXOffset is None: x = objRect.center().x else: x += topLeftXOffset y = objRect.y if topLeftYOffset is None: y = objRect.center().y else: y += topLeftYOffset delta = 10 snoozeTime = 0.01 for i in range(delta): squish.QCursor.setPos(x+i, y) # alternative function -> mouseMove() squish.snooze(snoozeTime) for i in range(delta): squish.QCursor.setPos(x, y+i) squish.snooze(snoozeTime) for i in range(delta): squish.QCursor.setPos(x-i, y) squish.snooze(snoozeTime) for i in range(delta): squish.QCursor.setPos(x, y-i) squish.snooze(snoozeTime) def StartDrag(Obj=None, topLeftXOffset=None, topLeftYOffset=None): """ Function to start a drag on a widget. Arguments: Obj - target object topLeftXOffset - int value for X offset of widget topLeftXOffset - int value for Y offset of widget Return: None """ objRect = object.globalBounds(Obj) if topLeftXOffset is None or topLeftYOffset is None: squish.mousePress(Obj, squish.Qt.LeftButton) else: if topLeftXOffset is None: topLeftXOffset = objRect.center().x if topLeftYOffset is None: topLeftYOffset = objRect.center().y squish.mousePress(Obj, topLeftXOffset, topLeftYOffset, squish.Qt.LeftButton) TriggerDragAndDrop(Obj, topLeftXOffset, topLeftYOffset) def DropOnWidget(Obj=None, topLeftXOffset=None, topLeftYOffset=None): """ Function to Drop on the target widget. Arguments: Obj - target object topLeftXOffset - int value for X offset of widget topLeftXOffset - int value for Y offset of widget Return: None """ TriggerDragAndDrop(Obj, topLeftXOffset, topLeftYOffset) squish.mouseRelease(squish.Qt.LeftButton) def dragAndDropObject(source=None, target=None): """ Drag and drop the source object to target. Arguments: source - Button Object target - Target tab object Return: None """ StartDrag(Obj=source) DropOnWidget(Obj=target) def set_random_slider_weight(value, slider_object): """ Method to drag_slider_position of weight widget Argument: N/A Return: return slider current position """ actual_value = value counter = 0 while True: squish.mouseDrag(slider_object, 0, 0, value, 0, squish.Qt.NoModifier, squish.Qt.LeftButton) if counter == 10: test.fail("User unable to fix slider value") return False if actual_value == int(slider_object.value): return True if value >= slider_object.value: value = value + 30 if value <= slider_object.value: value = value - 30 counter = counter + 1 def main(): startApplication("denaliSquish") hd = HDSimulator() hd.cmd_send_power_on_self_test_version_request() hd._handler_ui_first_check_in(message = None) mouseClick(waitForObject(names.patient_id), 264, 15, Qt.LeftButton) type(waitForObject(names.patient_id), "id") mouseClick(waitForObject(names.confirm_button)) #slider_object = {"container": names. , # "objectName": slider_object_name, # "type": "Slider" } #demo = {"container" : names.o_PreTreatmentCreateStack_PreTreatmentCreate_PreTreatmentCreate, 'gradient':0, 'id':_handler, type:'Rectangle', 'unnamed':1, visible: 'true'}(QQuickRectangle_QML_78) #demo = {"container": names.o_PreTreatmentCreateStack_PreTreatmentCreate_PreTreatmentCreate, "gradient": 0, "id": "_handler", "type": "Rectangle", "unnamed": 1, "visible": True}#(QQuickRectangle_QML_78) """ "bloodFlowRate": [200, 300, 400, 150, 250], "dialysateFlowRate": [150, 250, 300, 450, 500], "duration": [120, 150, 240, 300, 450], "heparinDispensingRate": [0.2, 0.3, 0.6, 0.8, 0.5], "heparinBolusVolume": [0.2, 0.5, 0.8, 1.0, 1.6], "heparinStopTime": [20, 60, 270, 320, 420, 440], "salineBolus": [200], "dialysateTemperature": [35.5, 36.0, 36.5, 37.0, 37.5], "bloodPressureMeasurementInterval": [5, 15, 20, 30, 45, 55], "rinsebackFlowRate": [75, 100, 125], """ slider_object = waitForObject(names.create_treatment_screen) child = object.children(slider_object)[0] child = object.children(child)[0] child = object.children(child)[3] child = object.children(child)[2] child1 = object.children(child)[5] move = object.children(child)[2] set_random_slider_weight(value = 450, slider_object = child) #dragAndDropObject(child1,move) snooze(5)