# -*- coding: utf-8 -*-

def main():
    startApplication("sasview")
    clickButton(waitForObject(":groupBox.cmdLoad_QPushButton"))
    waitForObjectItem(":stackedWidget.listView_QListView", "test")
    doubleClickItem(":stackedWidget.listView_QListView", "test", 44, 10, 0, Qt.LeftButton)
    waitForObjectItem(":stackedWidget.listView_QListView", "1d\\_data")
    doubleClickItem(":stackedWidget.listView_QListView", "1d\\_data", 42, 4, 0, Qt.LeftButton)
    waitForObjectItem(":stackedWidget.listView_QListView", "cyl\\_400\\_20\\.txt")
    doubleClickItem(":stackedWidget.listView_QListView", "cyl\\_400\\_20\\.txt", 73, 5, 0, Qt.LeftButton)
    clickButton(waitForObject(":groupBox.cmdSendTo_QPushButton"))
    clickTab(waitForObject(":FittingWidgetUI.tabFitting_QTabWidget_2"), "Fit Options")
    mouseDrag(waitForObject(":groupBox_4.txtMinRange_QLineEdit"), 21, 13, 20, 3, 1, Qt.LeftButton)
    type(waitForObject(":groupBox_4.txtMinRange_QLineEdit"), "5")
    mouseClick(waitForObject(":groupBox_4.txtMaxRange_QLineEdit"), 20, 11, 0, Qt.LeftButton)
    type(waitForObject(":groupBox_4.txtMaxRange_QLineEdit"), "<Backspace>")
    type(waitForObject(":groupBox_4.txtMaxRange_QLineEdit"), "<Backspace>")
    type(waitForObject(":groupBox_4.txtMaxRange_QLineEdit"), "<Backspace>")
    type(waitForObject(":groupBox_4.txtMaxRange_QLineEdit"), "1.0")
    type(waitForObject(":groupBox_4.txtMaxRange_QLineEdit"), "<Tab>")
    clickTab(waitForObject(":FittingWidgetUI.tabFitting_QTabWidget_2"), "Model")
    test.compare(str(waitForObjectExists(":groupBox_8.lblMinRangeDef_QLabel").text), "0.05")
    test.compare(str(waitForObjectExists(":groupBox_8.lblMaxRangeDef_QLabel").text), "1.0")
    mouseClick(waitForObject(":groupBox_6.cbCategory_QComboBox_2"), 170, 7, 0, Qt.LeftButton)
    mouseClick(waitForObjectItem(":groupBox_6.cbCategory_QComboBox_2", "Cylinder"), 154, 3, 0, Qt.LeftButton)
    clickTab(waitForObject(":FittingWidgetUI.tabFitting_QTabWidget_2"), "Fit Options")
    test.compare(waitForObjectExists(":groupBox_5.txtNpts_QLineEdit").enabled, False)
    test.compare(str(waitForObjectExists(":groupBox_5.txtNpts_QLineEdit").text), "20")
    test.compare(waitForObjectExists(":groupBox_5.txtNpts_QLineEdit").visible, True)
    test.compare(waitForObjectExists(":groupBox_5.txtNptsFit_QLineEdit").visible, True)
    test.compare(str(waitForObjectExists(":groupBox_5.txtNptsFit_QLineEdit").text), "50")
    test.compare(waitForObjectExists(":groupBox_5.txtNptsFit_QLineEdit").enabled, False)
    activateItem(waitForObjectItem(":MainWindow.menubar_QMenuBar", "Fitting"))
    activateItem(waitForObjectItem(":MainWindow.menuFitting_QMenu", "New Fit Page"))
    clickTab(waitForObject(":qt_workspacechild.FitPage0_FittingWindow"), "FitPage1")
    mouseClick(waitForObject(":groupBox_6.cbCategory_QComboBox_2"), 154, 13, 0, Qt.LeftButton)
    mouseClick(waitForObjectItem(":groupBox_6.cbCategory_QComboBox_2", "Cylinder"), 137, 4, 0, Qt.LeftButton)
    clickTab(waitForObject(":FittingWidgetUI.tabFitting_QTabWidget_2"), "Fit Options")
    test.compare(waitForObjectExists(":groupBox_5.txtNpts_QLineEdit").enabled, True)
    test.compare(waitForObjectExists(":groupBox_5.txtNpts_QLineEdit").visible, True)
    test.compare(str(waitForObjectExists(":groupBox_5.txtNpts_QLineEdit").text), "25")
    test.compare(waitForObjectExists(":groupBox_5.txtNptsFit_QLineEdit").visible, True)
    test.compare(waitForObjectExists(":groupBox_5.txtNptsFit_QLineEdit").enabled, True)
    test.compare(str(waitForObjectExists(":groupBox_5.txtNptsFit_QLineEdit").text), "50")
    test.compare(waitForObjectExists(":groupBox_5.txtChi2_QLineEdit").enabled, True)
    test.compare(str(waitForObjectExists(":groupBox_5.txtChi2_QLineEdit").text), "")
    test.compare(waitForObjectExists(":groupBox_5.txtChi2_QLineEdit").visible, True)
    test.compare(waitForObjectExists(":tabOptions.boxWeighting_QGroupBox").enabled, False)
    clickButton(waitForObject(":FittingWidgetUI.cmdPlot_QPushButton_2"))
    clickButton(waitForObject(":FittingWidgetUI.cmdPlot_QPushButton_2"))
    sendEvent("QMouseEvent", waitForObject(":groupBox_4.txtMinRange_QLineEdit"), QEvent.MouseButtonPress, 53, 11, Qt.LeftButton, 1, 0)
    #sendEvent("QMouseEvent", waitForObject(":groupBox_4.txtMinRange_QLineEdit_2"), QEvent.MouseButtonRelease, 53, 11, Qt.LeftButton, 0, 0)
    type(waitForObject(":groupBox_4.txtMinRange_QLineEdit"), "<Backspace>")
    type(waitForObject(":groupBox_4.txtMinRange_QLineEdit"), "<Backspace>")
    type(waitForObject(":groupBox_4.txtMinRange_QLineEdit"), "<Backspace>")
    type(waitForObject(":groupBox_4.txtMinRange_QLineEdit"), "<Backspace>")
    type(waitForObject(":groupBox_4.txtMinRange_QLineEdit"), "<Backspace>")
    type(waitForObject(":groupBox_4.txtMinRange_QLineEdit"), "0.5")
    type(waitForObject(":groupBox_4.txtMinRange_QLineEdit"), "<Tab>")
    type(waitForObject(":groupBox_4.txtMaxRange_QLineEdit"), "1")
    type(waitForObject(":groupBox_4.txtMaxRange_QLineEdit"), "<Tab>")
    mouseDrag(waitForObject(":groupBox_5.txtNpts_QLineEdit"), 32, 9, -8, 3, 1, Qt.LeftButton)
    type(waitForObject(":groupBox_5.txtNpts_QLineEdit"), "<Backspace>")
    type(waitForObject(":groupBox_5.txtNpts_QLineEdit"), "<Backspace>")
    type(waitForObject(":groupBox_5.txtNpts_QLineEdit"), "100")
    type(waitForObject(":groupBox_5.txtNpts_QLineEdit"), "<Tab>")
    clickTab(waitForObject(":FittingWidgetUI.tabFitting_QTabWidget_3"), "Model")
    test.compare(str(waitForObjectExists(":groupBox_8.lblMinRangeDef_QLabel_2").text), "0.5")
    test.compare(str(waitForObjectExists(":groupBox_8.lblMaxRangeDef_QLabel_2").text), "1.0")
    test.vp("VP1")
