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

def main():
    startApplication("sasview")
    clickButton(waitForObject(":groupBox.cmdLoad_QPushButton"))
    waitForObjectItem(":stackedWidget.listView_QListView", "test")
    doubleClickItem(":stackedWidget.listView_QListView", "test", 58, 14, 0, Qt.LeftButton)
    waitForObjectItem(":stackedWidget.listView_QListView", "1d\\_data")
    doubleClickItem(":stackedWidget.listView_QListView", "1d\\_data", 51, 7, 0, Qt.LeftButton)
    waitForObjectItem(":stackedWidget.listView_QListView", "cyl\\_400\\_20\\.txt")
    doubleClickItem(":stackedWidget.listView_QListView", "cyl\\_400\\_20\\.txt", 73, 10, 0, Qt.LeftButton)
    clickButton(waitForObject(":groupBox.cmdSendTo_QPushButton"))
    clickButton(waitForObject(":groupBox_3.cmdNew_QPushButton"))
    openContextMenu(waitForObject(":qt_workspacechild_FigureCanvasQTAgg"), 131, 224, 0)
    activateItem(waitForObjectItem(":MainWindow_QMenu", "Save Image"))
    test.compare(waitForObjectExists(":QFileDialog_QFileDialog").visible, True)
    test.compare(str(waitForObjectExists(":QFileDialog_QFileDialog").windowTitle), "Choose a filename to save to")
    test.compare(waitForObjectExists(":fileNameEdit_QLineEdit").visible, True)
    test.compare(str(waitForObjectExists(":fileNameEdit_QLineEdit").text), "image.png")
    mouseClick(waitForObject(":QFileDialog.fileTypeCombo_QComboBox"), 461, 12, 0, Qt.LeftButton)
    mouseClick(waitForObjectItem(":QFileDialog.fileTypeCombo_QComboBox", "Encapsulated Postscript (*\\.eps)"), 436, 9, 0, Qt.LeftButton)
    test.compare(str(waitForObjectExists(":fileNameEdit_QLineEdit").text), "image.eps")
    mouseClick(waitForObject(":QFileDialog.fileTypeCombo_QComboBox"), 423, 6, 0, Qt.LeftButton)
    mouseClick(waitForObjectItem(":QFileDialog.fileTypeCombo_QComboBox", "Joint Photographic Experts Group (*\\.jpeg *\\.jpg)"), 364, 4, 0, Qt.LeftButton)
    test.compare(str(waitForObjectExists(":fileNameEdit_QLineEdit").text), "image.jpeg")
    sendEvent("QCloseEvent", waitForObject(":QFileDialog_QFileDialog"))
    #openContextMenu(waitForObject(":qt_workspacechild_FigureCanvasQTAgg"), 162, 232, 0)
    #activateItem(waitForObjectItem(":MainWindow_QMenu", "Print Image"))
    #clickButton(waitForObject(":Print.Cancel_Button"))
    openContextMenu(waitForObject(":qt_workspacechild_FigureCanvasQTAgg"), 290, 296, 0)
    activateItem(waitForObjectItem(":MainWindow_QMenu", "Add Text"))
    test.compare(waitForObjectExists(":AddText_AddText").visible, True)
    test.compare(str(waitForObjectExists(":AddText_AddText").windowTitle), "Add Text")
    test.compare(str(waitForObjectExists(":groupBox.textEdit_QTextEdit").html), "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\np, li { white-space: pre-wrap; }\n</style></head><body style=\" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p></body></html>")
    sendEvent("QCloseEvent", waitForObject(":AddText_AddText"))
    openContextMenu(waitForObject(":qt_workspacechild_FigureCanvasQTAgg"), 211, 271, 0)
    activateItem(waitForObjectItem(":MainWindow_QMenu", "Add Text"))
    type(waitForObject(":groupBox.textEdit_QTextEdit"), "test")
    clickButton(waitForObject(":qt_workspacechild.OK_QPushButton"))
    test.vp("VP1")
    openContextMenu(waitForObject(":qt_workspacechild_FigureCanvasQTAgg"), 169, 327, 0)
    activateItem(waitForObjectItem(":MainWindow_QMenu", "Remove Text"))
    test.vp("VP2")
    openContextMenu(waitForObject(":qt_workspacechild_FigureCanvasQTAgg"), 276, 287, 0)
    activateItem(waitForObjectItem(":MainWindow_QMenu", "Change Scale"))
    test.compare(str(waitForObjectExists(":scalePropertiesUI_ScaleProperties").windowTitle), "Scale Properties")
    test.compare(waitForObjectExists(":scalePropertiesUI_ScaleProperties").visible, True)
    clickButton(waitForObject(":qt_workspacechild.Cancel_QPushButton_2"))
    openContextMenu(waitForObject(":qt_workspacechild_FigureCanvasQTAgg"), 182, 346, 0)
    activateItem(waitForObjectItem(":MainWindow_QMenu", "Set Graph Range"))
    test.compare(waitForObjectExists(":setGraphRangeUI_SetGraphRange").visible, True)
    test.compare(str(waitForObjectExists(":setGraphRangeUI_SetGraphRange").windowTitle), "Set Graph Range")
    clickButton(waitForObject(":setGraphRangeUI.Cancel_QPushButton"))
    openContextMenu(waitForObject(":qt_workspacechild_FigureCanvasQTAgg"), 186, 366, 0)
    activateItem(waitForObjectItem(":MainWindow_QMenu", "Reset Graph Range"))
    openContextMenu(waitForObject(":qt_workspacechild_FigureCanvasQTAgg"), 178, 349, 0)
    activateItem(waitForObjectItem(":MainWindow_QMenu", "Window Title"))
    test.compare(waitForObjectExists(":WindowTitle_WindowTitle").visible, True)
    test.compare(str(waitForObjectExists(":WindowTitle_WindowTitle").windowTitle), "Modify Window Title")
    clickButton(waitForObject(":qt_workspacechild.Cancel_QPushButton_2"))
