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

def main():
    startApplication("sasview")
    clickButton(waitForObject(":groupBox.cmdLoad_QPushButton"))
    waitForObjectItem(":stackedWidget.listView_QListView", "test")
    doubleClickItem(":stackedWidget.listView_QListView", "test", 36, 9, 0, Qt.LeftButton)
    waitForObjectItem(":stackedWidget.listView_QListView", "1d\\_data")
    doubleClickItem(":stackedWidget.listView_QListView", "1d\\_data", 44, 10, 0, Qt.LeftButton)
    waitForObjectItem(":stackedWidget.listView_QListView", "cyl\\_400\\_20\\.txt")
    doubleClickItem(":stackedWidget.listView_QListView", "cyl\\_400\\_20\\.txt", 48, 12, 0, Qt.LeftButton)
    waitForObjectItem(":groupBox.treeView_QTreeView", "cyl\\_400\\_20\\.txt")
    clickItem(":groupBox.treeView_QTreeView", "cyl\\_400\\_20\\.txt", 51, 10, 0, Qt.LeftButton)
    openItemContextMenu(waitForObject(":groupBox.treeView_QTreeView"), "cyl\\_400\\_20\\.txt", 51, 10, 0)
    activateItem(waitForObjectItem(":MainWindow_QMenu", "Data Info"))
    test.compare(str(waitForObjectExists(":Data Info: cyl_400_20.txt_QTextEdit").windowTitle), "Data Info: cyl_400_20.txt")
    test.compare(waitForObjectExists(":Data Info: cyl_400_20.txt_QTextEdit").visible, True)
    test.compare(str(waitForObjectExists(":_QTextControl").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=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">File:            cyl_400_20.txt</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Title:           cyl_400_20.txt</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Run:             []</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">SESANS:          None</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Instrument:      </p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Sample:</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">   ID:           </p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">   Transmission: None</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">   Thickness:    None [mm]</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">   Temperature:  None [None]</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">   Position:     x = None	y = None	z = None [mm]</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">   Orientation:  x = None	y = None	z = None [degree]</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">   Details:</p>\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>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Source:</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">   Radiation:    None</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">   Shape:        None</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">   Wavelength:   None [A]</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">   Waveln_min:   None [nm]</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">   Waveln_max:   None [nm]</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">   Waveln_spread:None [percent]</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">   Beam_size:    x = None	y = None	z = None [mm]</p>\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>\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>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Data:</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">   Type:         Data1D</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">   X-axis:       \\rm{Q}	[A^{-1}]</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">   Y-axis:       \\rm{Intensity}	[cm^{-1}]</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">   Length:       20</p>\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>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Data Min Max:</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">X_min = 0.025:  X_max = 0.5</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Y_min = 0.00121297:  Y_max = 125.852</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">dY_min = 0.0:  dY_max = 0.0</p>\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>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Data Points:</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">&lt;index&gt; 	&lt;X&gt; 	&lt;Y&gt; 	&lt;dY&gt; 	&lt;dX&gt;</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">0 	0.025 	125.852 	0.0 	0.0</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">1 	0.05 	53.6662 	0.0 	0.0</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">2 	0.075 	26.0733 	0.0 	0.0</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">3 	0.1 	11.8935 	0.0 	0.0</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">4 	0.125 	4.61714 	0.0 	0.0</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">5 	0.15 	1.29983 	0.0 	0.0</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">6 	0.175 	0.171347 	0.0 	0.0</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">7 	0.2 	0.0417614 	0.0 	0.0</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">8 	0.225 	0.172719 	0.0 	0.0</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">9 	0.25 	0.247876 	0.0 	0.0</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">10 	0.275 	0.20301 	0.0 	0.0</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">11 	0.3 	0.104599 	0.0 	0.0</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">12 	0.325 	0.0285595 	0.0 	0.0</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">13 	0.35 	0.00213344 	0.0 	0.0</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">14 	0.375 	0.0137511 	0.0 	0.0</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">15 	0.4 	0.0312374 	0.0 	0.0</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">16 	0.425 	0.0350328 	0.0 	0.0</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">17 	0.45 	0.0243172 	0.0 	0.0</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">18 	0.475 	0.00923067 	0.0 	0.0</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">19 	0.5 	0.00121297 	0.0 	0.0</p>\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(":Data Info: cyl_400_20.txt_QTextEdit"))
    openItemContextMenu(waitForObject(":groupBox.treeView_QTreeView"), "cyl\\_400\\_20\\.txt", 181, 3, 0)
    activateItem(waitForObjectItem(":MainWindow_QMenu", "Save As"))
    test.compare(str(waitForObjectExists(":QFileDialog_QFileDialog").windowTitle), "Save As")
    test.compare(waitForObjectExists(":QFileDialog_QFileDialog").visible, True)
    test.compare(str(waitForObjectExists(":fileNameEdit_QLineEdit").text), "cyl_400_20_out.txt")
    test.compare(str(waitForObjectExists(":QFileDialog.fileTypeCombo_QComboBox").currentText), "Text files (*.txt)")
    test.compare(waitForObjectExists(":QFileDialog.fileTypeCombo_QComboBox").currentIndex, 0)
    sendEvent("QMouseEvent", waitForObject(":QFileDialog.Cancel_QPushButton"), QEvent.MouseButtonPress, 63, 11, Qt.LeftButton, 1, 0)
    sendEvent("QMouseEvent", waitForObject(":QFileDialog.Cancel_QPushButton"), QEvent.MouseButtonRelease, 63, 11, Qt.LeftButton, 0, 0)
    openItemContextMenu(waitForObject(":groupBox.treeView_QTreeView"), "cyl\\_400\\_20\\.txt", 168, 5, 0)
    activateItem(waitForObjectItem(":MainWindow_QMenu", "Quick Plot"))
    test.compare(waitForObjectExists(":Plot cyl_400_20.txt_FigureCanvasQTAgg").visible, True)
    test.compare(waitForObjectExists(":Plot cyl_400_20.txt_Plotter").visible, True)
    test.compare(str(waitForObjectExists(":Plot cyl_400_20.txt_Plotter").windowTitle), "Plot cyl_400_20.txt")
    sendEvent("QCloseEvent", waitForObject(":Plot cyl_400_20.txt_Plotter"))
    openItemContextMenu(waitForObject(":groupBox.treeView_QTreeView"), "cyl\\_400\\_20\\.txt", 233, 3, 0)
    clickButton(waitForObject(":groupBox.cmdLoad_QPushButton"))
    waitForObjectItem(":stackedWidget.listView_QListView", "test")
    doubleClickItem(":stackedWidget.listView_QListView", "test", 44, 16, 0, Qt.LeftButton)
    waitForObjectItem(":stackedWidget.listView_QListView", "2d\\_data")
    doubleClickItem(":stackedWidget.listView_QListView", "2d\\_data", 51, 12, 0, Qt.LeftButton)
    waitForObjectItem(":stackedWidget.listView_QListView", "P123\\_D2O\\_30\\_percent\\.dat")
    doubleClickItem(":stackedWidget.listView_QListView", "P123\\_D2O\\_30\\_percent\\.dat", 66, 2, 0, Qt.LeftButton)
    waitForObjectItem(":groupBox.treeView_QTreeView", "P123\\_D2O\\_30\\_percent\\.dat")
    clickItem(":groupBox.treeView_QTreeView", "P123\\_D2O\\_30\\_percent\\.dat", 47, 8, 0, Qt.LeftButton)
    openItemContextMenu(waitForObject(":groupBox.treeView_QTreeView"), "P123\\_D2O\\_30\\_percent\\.dat", 47, 8, 0)
    activateItem(waitForObjectItem(":MainWindow_QMenu", "Data Info"))
    test.compare(waitForObjectExists(":Data Info: P123_D2O_30_percent.dat_QTextEdit").visible, True)
    test.compare(str(waitForObjectExists(":Data Info: P123_D2O_30_percent.dat_QTextEdit").windowTitle), "Data Info: P123_D2O_30_percent.dat")
    sendEvent("QCloseEvent", waitForObject(":Data Info: P123_D2O_30_percent.dat_QTextEdit"))
