コード例 #1
0
class MSGINFO(QDialog, Ui_Dialog_info,
              QWebEngineView):  #FORE_CLASS5        number 5
    def __init__(self, parent=None):
        QDialog.__init__(self, parent)
        self.setupUi(self)
        self.setWindowTitle('معلومات عني')
        self.setWindowIcon(QIcon('Icon/info_client.png'))
        self.buttonClose.clicked.connect(self.close)
        self.LineUp()
        self.frame1.setFixedHeight(100)
        self.LineDwon()
        self.frame2.setFixedHeight(250)

    def LineUp(self):
        self.pixmap = QPixmap('Icon/M3foOoS.png')
        self.AboutInofImagelabel.setPixmap(self.pixmap)

    def LineDwon(self):
        self.browser2 = QWebEngineView(self.frame2)
        self.browser2.setFixedWidth(750)
        self.browser2.setFixedHeight(300)
        # self.browser2.setHtml(sessions.Aboutinfo2)
        pathMSGFile = os.getcwd()
        url = QUrl.fromLocalFile(r"/Icon/MSG.html")
        self.browser2.load(url)
コード例 #2
0
ファイル: ow_x0p.py プロジェクト: lucarebuffi/XRayServer
class X0p(XrayServerWidget):
    name = "X0h Search"
    description = "X0p"
    icon = "icons/x0p.png"
    maintainer = "Luca Rebuffi"
    maintainer_email = "luca.rebuffi(@at@)elettra.eu"
    priority = 2
    category = "X0h"
    keywords = ["data", "file", "load", "read"]

    want_main_area = 1

    xway = Setting(2)
    wave = Setting(0.0)
    line = Setting("Cu-Ka1")

    code = Setting("Silicon")

    hkl11 = Setting(-5)
    hkl12 = Setting(-5)
    hkl13 = Setting(-5)

    hkl21 = Setting(5)
    hkl22 = Setting(5)
    hkl23 = Setting(5)

    qb1 = Setting(0.0)
    qb2 = Setting(90.0)

    prcmin = Setting(0.0)

    df1df2 = Setting(1)

    base1 = Setting(1)
    base2 = Setting(0)
    base3 = Setting(0)

    modesearch = Setting(0)

    q1 = Setting(0.0)
    q2 = Setting(180.0)


    def __init__(self):
        super().__init__()

        left_box_1 = oasysgui.widgetBox(self.controlArea, "X0h-Search Request Form", addSpace=True, orientation="vertical",
                                         width=400, height=630)

        left_box_2 = oasysgui.widgetBox(left_box_1, "X-rays", addSpace=True, orientation="horizontal", width=380, height=110)

        left_box_2_1 = oasysgui.widgetBox(left_box_2, "", addSpace=True, orientation="vertical", width=150, height=110)

        gui.radioButtons(left_box_2_1, self, "xway", ["Wavelength (Å)", "Energy (keV)", "Characteristic line"], callback=self.set_xway )

        self.box_wave = oasysgui.widgetBox(left_box_2, "", addSpace=True, orientation="vertical", width=190)
        gui.separator(self.box_wave, height=10)
        oasysgui.lineEdit(self.box_wave, self, "wave", label="", labelWidth=0, addSpace=False, valueType=float, orientation="horizontal")

        self.box_line = oasysgui.widgetBox(left_box_2, "", addSpace=True, orientation="horizontal", width=190, height=110)
        gui.separator(self.box_line, height=120)
        XRayServerGui.combobox_text(self.box_line, self, "line", label="", labelWidth=0,
                               items=self.get_lines(),
                               sendSelectedValue=True, orientation="horizontal", selectedValue=self.line)

        button = gui.button( self.box_line, self, "?", callback=self.help_lines)
        button.setFixedWidth(15)

        self.set_xway()

        left_box_3 = oasysgui.widgetBox(left_box_1, "Crystal", addSpace=True, orientation="horizontal", width=380, height=60)

        self.box_crystal = oasysgui.widgetBox(left_box_3, "", addSpace=True, orientation="horizontal", width=210)
        XRayServerGui.combobox_text(self.box_crystal, self, "code", label="", labelWidth=0,
                               items=self.get_crystals(),
                               sendSelectedValue=True, orientation="horizontal", selectedValue=self.code)


        button = gui.button( self.box_crystal, self, "?", callback=self.help_crystals)
        button.setFixedWidth(15)

        left_box_4 = oasysgui.widgetBox(left_box_1, "Bragg Planes Range", addSpace=True, orientation="horizontal", width=380, height=60)

        oasysgui.lineEdit(left_box_4, self, "hkl11", label="From", labelWidth=50, addSpace=False, valueType=int, orientation="horizontal")
        oasysgui.lineEdit(left_box_4, self, "hkl12", label=" ", labelWidth=1, addSpace=False, valueType=int, orientation="horizontal")
        oasysgui.lineEdit(left_box_4, self, "hkl13", label=" ", labelWidth=1, addSpace=False, valueType=int, orientation="horizontal")

        oasysgui.lineEdit(left_box_4, self, "hkl21", label="  To", labelWidth=50, addSpace=False, valueType=int, orientation="horizontal")
        oasysgui.lineEdit(left_box_4, self, "hkl22", label=" ", labelWidth=1, addSpace=False, valueType=int, orientation="horizontal")
        oasysgui.lineEdit(left_box_4, self, "hkl23", label=" ", labelWidth=1, addSpace=False, valueType=int, orientation="horizontal")

        left_box_7 = oasysgui.widgetBox(left_box_1, "Bragg Angle Range", addSpace=True, orientation="horizontal", width=380, height=60)

        oasysgui.lineEdit(left_box_7, self, "qb1", label="From", labelWidth=80, addSpace=False, valueType=float, orientation="horizontal")
        oasysgui.lineEdit(left_box_7, self, "qb2", label="  To", labelWidth=80, addSpace=False, valueType=float, orientation="horizontal")

        tab_central = oasysgui.tabWidget(left_box_1)
        tab_1 = oasysgui.createTabPage(tab_central, "Intensity Control")
        tab_2 = oasysgui.createTabPage(tab_central, "Find only Bragg planes making certain angles to the surface")

        left_box_5 = oasysgui.widgetBox(tab_1, "", addSpace=True, orientation="vertical", width=370, height=250)

        gui.separator(left_box_5)

        oasysgui.lineEdit(left_box_5, self, "prcmin", label="Minimum |xh/x0| (%)", labelWidth=250, addSpace=False, valueType=float, orientation="horizontal")

        left_box_5_1 = oasysgui.widgetBox(left_box_5, "Database Options for dispersion corrections df1, df2", addSpace=True, orientation="vertical", width=370, height=185)

        gui.radioButtons(left_box_5_1, self, "df1df2", ["Auto (Henke at low energy, X0h at mid, Brennan-Cowan\nat high)",
                                                      "Use X0h data (5-25 keV or 0.5-2.5 A), recommended for\nBragg diffraction",
                                                      "Use Henke data (0.01-30 keV or 0.4-1200 A),\nrecommended for soft x-rays",
                                                      "Use Brennan-Cowan data (0.03-700 keV or 0.02-400 A)"])

        left_box_6 = oasysgui.widgetBox(tab_2, "", addSpace=True, orientation="vertical", width=370, height=255)

        gui.separator(left_box_6)

        left_box_6_1 = oasysgui.widgetBox(left_box_6, "", addSpace=False, orientation="horizontal", width=370, height=30)

        oasysgui.lineEdit(left_box_6_1, self, "base1", label="Surface Plane Indices", labelWidth=200, addSpace=False, valueType=int, orientation="horizontal")
        oasysgui.lineEdit(left_box_6_1, self, "base2", label=" ", labelWidth=1, addSpace=False, valueType=int, orientation="horizontal")
        oasysgui.lineEdit(left_box_6_1, self, "base3", label=" ", labelWidth=1, addSpace=False, valueType=int, orientation="horizontal")

        gui.radioButtons(left_box_6, self, "modesearch", ["Planes make angles from Theta1 to Theta2",
                                                      "Planes make angles from Theta1 to (Bragg_Angle - Theta2)",
                                                      "Planes make angles from (Bragg_Angle - Theta1)\nto (Bragg_Angle - Theta2)"])

        gui.separator(left_box_6, height=10)

        left_box_6_2 = oasysgui.widgetBox(left_box_6, "", addSpace=True, orientation="horizontal", width=370, height=30)

        oasysgui.lineEdit(left_box_6_2, self, "q1", label="Theta1", labelWidth=80, addSpace=False, valueType=float, orientation="horizontal")
        oasysgui.lineEdit(left_box_6_2, self, "q2", label="  Theta2", labelWidth=80, addSpace=False, valueType=float, orientation="horizontal")

        button = gui.button(self.controlArea, self, "Find Planes!", callback=self.submit)
        button.setFixedHeight(30)

        gui.rubber(self.controlArea)

        self.tabs_widget = oasysgui.tabWidget(self.mainArea)
        self.tab_output = oasysgui.createTabPage(self.tabs_widget, "X-ray Server Ouput")

        self.x0h_output = QWebView(self.tab_output)

        self.tab_output.layout().addWidget(self.x0h_output)

        self.x0h_output.setFixedHeight(640)
        self.x0h_output.setFixedWidth(740)

    def set_xway(self):
        self.box_wave.setVisible(self.xway!=2)
        self.box_line.setVisible(self.xway==2)


    def submit(self):
        self.progressBarInit()
        self.setStatusMessage("Submitting Request")
        
        self.checkFields()

        parameters = {}

        parameters.update({"xway" : str(self.xway + 1)})
        parameters.update({"wave" : str(self.wave)})
        parameters.update({"line" : self.line})
        parameters.update({"code" : self.code})
        parameters.update({"hkl11" : str(self.hkl11)})
        parameters.update({"hkl12" : str(self.hkl12)})
        parameters.update({"hkl13" : str(self.hkl13)})
        parameters.update({"hkl21" : str(self.hkl21)})
        parameters.update({"hkl22" : str(self.hkl22)})
        parameters.update({"hkl23" : str(self.hkl23)})
        parameters.update({"qb1" : str(self.qb1)})
        parameters.update({"qb2" : str(self.qb2)})
        parameters.update({"prcmin" : str(self.prcmin)})
        parameters.update({"df1df2" : self.decode_df1df2()})
        parameters.update({"base1" : str(self.base1)})
        parameters.update({"base2" : str(self.base2)})
        parameters.update({"base3" : str(self.base3)})
        parameters.update({"modesearch" : self.decode_modesearch()})
        parameters.update({"q1" : str(self.q1)})
        parameters.update({"q2" : str(self.q2)})

        try:
            response = HttpManager.send_xray_server_request_GET(APPLICATION, parameters)
            response = response.split("<hr>")[0] + "\n </body></html>"

            temp_1, temp_2 = response.split("style.css")
            output = temp_1 + XRAY_SERVER_URL + "/style.css" + temp_2

            response = response.split("<td><img src=\"images/x.gif\" width=31 height=32 border=0></td>")[0] + "</tr></tr></body></html>"

            self.x0h_output.setHtml(response)

        except urllib.error.HTTPError as e:
            self.x0h_output.setHtml('The server couldn\'t fulfill the request.\nError Code: '
                                    + str(e.code) + "\n\n" +
                                    server.BaseHTTPRequestHandler.responses[e.code][1])
        except urllib.error.URLError as e:
            self.x0h_output.setHtml('We failed to reach a server.\nReason: '
                                    + e.reason)
        except XrayServerException as e:
            ShowHtmlDialog.show_html("X-ray Server Error", e.response, width=750, height=500, parent=self)
        except Exception as e:
            ShowTextDialog.show_text("Error", 'Error Occurred.\nReason: ' + str(e), parent=self)

        self.setStatusMessage("")
        self.progressBarFinished()

    def getLeftPartWidth(self):
        return 415

    def checkFields(self):
        pass

    def decode_df1df2(self):
        if self.df1df2 == 0: return "-1"
        elif self.df1df2 == 1: return "0"
        elif self.df1df2 == 2: return "2"
        elif self.df1df2 == 3: return "4"

    def decode_modesearch(self):
        if self.modesearch == 0: return "3"
        elif self.modesearch == 1: return "2"
        elif self.modesearch == 2: return "1"
コード例 #3
0
ファイル: ow_x0h.py プロジェクト: tschoonj/XRayServer
class X0h(XrayServerWidget):
    name = "X0h"
    description = "X0h"
    icon = "icons/x0h.png"
    maintainer = "Luca Rebuffi"
    maintainer_email = "luca.rebuffi(@at@)elettra.eu"
    priority = 1
    category = "X0h"
    keywords = ["data", "file", "load", "read"]

    want_main_area = 1

    outputs = [
        {
            "name": "xrayserver_data",
            "type": DataExchangeObject,
            "doc": "xrayserver_data",
            "id": "xrayserver_data"
        },
    ]

    def __init__(self):
        super().__init__()

        left_box_1 = oasysgui.widgetBox(self.controlArea,
                                        "X0h Request Form",
                                        addSpace=True,
                                        orientation="vertical",
                                        width=610,
                                        height=640)

        html = self.clear_input_form(
            HttpManager.send_xray_server_direct_request(
                "/cgi/www_form.exe?template=X0h_form.htm"))

        self.x0h_input = QWebView(left_box_1)
        self.x0h_input.setHtml(html)

        left_box_1.layout().addWidget(self.x0h_input)

        self.x0h_input.setFixedHeight(540)
        self.x0h_input.setFixedWidth(590)

        button = gui.button(self.controlArea,
                            self,
                            "Get X0h!",
                            callback=self.submit)
        button.setFixedHeight(30)

        gui.rubber(self.controlArea)

        self.tabs = []
        self.tabs_widget = oasysgui.tabWidget(self.mainArea)
        self.initializeTabs()

        self.x0h_output = QWebView(self.tabs[0])

        self.tabs[0].layout().addWidget(self.x0h_output)

        self.x0h_output.setFixedHeight(630)
        self.x0h_output.setFixedWidth(740)

    def clear_input_form(self, html):
        temp_1 = html.split("<body onload=\"setOnloads()\">")[0]
        temp_2 = html.split(
            "<table cellspacing=0 cellpadding=0 border=0 bgcolor=\"#c1c1c1\"><tr><td>"
        )[1]

        html = temp_1 + "\n<table cellspacing=0 cellpadding=0 border=0 bgcolor=\"#c1c1c1\"><tr><td>\n" + temp_2

        html = html.split(
            "<input type=SUBMIT value=\"Get X0h!\"><input type=RESET> <br>")[0]
        html += "\n<input type=SUBMIT style=\"display: none;\" id=\"submit-btn\"><input type=RESET style=\"display: none;\" id=\"reset-btn\"> <br>"
        html += "\n</form>"
        html += "\n</td></tr></table>"
        html += "\n</td></tr></table>"
        html += "\n</body>"
        html += "\n</html>"

        return html

    def getLeftPartWidth(self):
        return 620

    def initializeTabs(self):
        current_tab = self.tabs_widget.currentIndex()

        size = len(self.tabs)

        for index in range(0, size):
            self.tabs_widget.removeTab(size - 1 - index)

        self.tabs = [
            gui.createTabPage(self.tabs_widget, "X-ray Server Ouput"),
            gui.createTabPage(self.tabs_widget, "Critical Angle for TER"),
            gui.createTabPage(self.tabs_widget,
                              "Darwin Curve (" + u"\u03C3" + " Pol.)"),
            gui.createTabPage(self.tabs_widget,
                              "Darwin Curve (" + u"\u03C0" + " Pol.)"),
        ]

        for tab in self.tabs:
            tab.setFixedHeight(650)
            tab.setFixedWidth(750)

        self.plot_canvas = [None, None, None]

        self.tabs_widget.setCurrentIndex(current_tab)

    def js_callback(self, result):
        pass

    def _callable_1(self, html):
        self.original_signal = self.x0h_input.loadFinished
        self.x0h_input.loadFinished.connect(self.loadFinished)
        self.x0h_input.setHidden(True)
        self.x0h_input.page().runJavaScript(
            "document.getElementById('submit-btn').click()", self.js_callback)

    def loadFinished(self):
        self.x0h_input.page().toHtml(self._callable_2)

    def _callable_2(self, html):
        try:
            self.x0h_input.loadFinished.disconnect()
            self.x0h_input.back()
            self.x0h_input.setHidden(False)

            response_1 = self.clear_response(html)
            response_2 = self.clear_response(html)

            self.tabs_widget.setCurrentIndex(0)

            self.x0h_output.setHtml(response_1)

            data0, data1, data2 = self.extract_plots(response_2)

            exchange_data = DataExchangeObject("XRAYSERVER", "X0H")
            exchange_data.add_content("reflectivity", data0)
            exchange_data.add_content("reflectivity_units_to_degrees", 1.0)
            exchange_data.add_content("x-ray_diffraction_profile_sigma", data1)
            exchange_data.add_content(
                "x-ray_diffraction_profile_sigma_units_to_degrees",
                0.000277777805)
            exchange_data.add_content("x-ray_diffraction_profile_pi", data2)
            exchange_data.add_content(
                "x-ray_diffraction_profile_pi_units_to_degrees",
                0.000277777805)

            self.send("xrayserver_data", exchange_data)

        except urllib.error.HTTPError as e:
            self.x0h_output.setHtml(
                'The server couldn\'t fulfill the request.\nError Code: ' +
                str(e.code) + "\n\n" +
                server.BaseHTTPRequestHandler.responses[e.code][1])

        except urllib.error.URLError as e:
            self.x0h_output.setHtml('We failed to reach a server.\nReason: ' +
                                    e.reason)

        except XrayServerException as e:
            ShowHtmlDialog.show_html("X-ray Server Error",
                                     e.response,
                                     width=750,
                                     height=500,
                                     parent=self)

        except Exception as e:
            self.x0h_output.setHtml('We failed to reach a server.\nReason: ' +
                                    str(e))

        self.tabs_widget.setCurrentIndex(0)
        self.setStatusMessage("")
        self.progressBarFinished()

    def submit(self):
        self.progressBarInit()
        self.setStatusMessage("Submitting Request")

        if platform.system() == 'Darwin':
            self.x0h_input.page().toHtml(self._callable_1)

        elif platform.system() == 'Linux':
            doc = self.x0h_input.page().mainFrame().documentElement()
            submit_btn = doc.findFirst("input[id=submit-btn]")

            try:
                response = ""
                #response = HttpManager.send_xray_server_request_POST(APPLICATION, parameters)
                response = self.clear_response(response)

                self.tabs_widget.setCurrentIndex(0)
                self.x0h_output.setHtml(response)

                data0, data1, data2 = self.extract_plots(response)

                exchange_data = DataExchangeObject("XRAYSERVER", "X0H")
                exchange_data.add_content("reflectivity", data0)
                exchange_data.add_content("reflectivity_units_to_degrees", 1.0)
                exchange_data.add_content("x-ray_diffraction_profile_sigma",
                                          data1)
                exchange_data.add_content(
                    "x-ray_diffraction_profile_sigma_units_to_degrees",
                    0.000277777805)
                exchange_data.add_content("x-ray_diffraction_profile_pi",
                                          data2)
                exchange_data.add_content(
                    "x-ray_diffraction_profile_pi_units_to_degrees",
                    0.000277777805)

                self.send("xrayserver_data", exchange_data)

                pass
            except urllib.error.HTTPError as e:
                self.x0h_output.setHtml(
                    'The server couldn\'t fulfill the request.\nError Code: ' +
                    str(e.code) + "\n\n" +
                    server.BaseHTTPRequestHandler.responses[e.code][1])
                raise e

            except urllib.error.URLError as e:
                self.x0h_output.setHtml(
                    'We failed to reach a server.\nReason: ' + e.reason)
                raise e

            except XrayServerException as e:
                ShowHtmlDialog.show_html("X-ray Server Error",
                                         e.response,
                                         width=750,
                                         height=500,
                                         parent=self)

                raise e
            except Exception as e:
                self.x0h_output.setHtml(
                    'We failed to reach a server.\nReason: ' + str(e))

                raise e

            self.setStatusMessage("")
            self.progressBarFinished()

    def clear_response(self, response):

        # remove links
        output = response.split(
            "<img src=\"images/x.gif\" width=\"31\" height=\"32\" border=\"0\">"
        )[0] + "\n</body></html>"

        # remove "get the curve" images
        output = "".join(
            output.split(
                "<input type=image src=\"images/get_the_curve.gif\" border=0 width=102 height=12 alt=\"Get the reflectivity curve\">"
            ))
        output = "".join(
            output.split(
                "<input type=image src=\"images/get_the_curve.gif\" border=0 width=102 height=12 alt=\"Get the Bragg curve (sigma)\">"
            ))
        output = "".join(
            output.split(
                "<input type=image src=\"images/get_the_curve.gif\" border=0 width=102 height=12 alt=\"Get the Bragg curve (pi)\">"
            ))
        # remove question mark images and links
        output = "".join(
            output.split(
                "<a  href=\"javascript:void(0)\" onClick=\"Wfloat(\'images/x0h_help_0.gif\',\'x0h_0\',740,357);\"><b>?</b></a> &nbsp;"
            ))
        output = "".join(
            output.split(
                "<a  href=\"javascript:void(0)\" onClick=\"Wfloat(\'images/x0h_help_h.gif\',\'x0h_h\',705,853);\"><b>?</b></a> &nbsp;"
            ))

        return output

    def extract_plots(self, response):
        form_1_begin = False
        form_2_begin = False
        form_3_begin = False

        form_1 = None
        form_2 = None
        form_3 = None

        rows = response.split("\n")

        for row in rows:
            if form_1_begin:
                if "<td>" in row:
                    form_1_begin = False
            elif form_2_begin:
                if "<td>" in row:
                    form_2_begin = False
            elif form_3_begin:
                if "<td>" in row:
                    form_3_begin = False

            if form_1_begin:
                form_1.append(row)
            elif form_2_begin:
                form_2.append(row)
            elif form_3_begin:
                form_3.append(row)

            if "/cgi/ter_form.pl" in row:
                if form_1 is None:
                    form_1 = []
                    form_1_begin = True

            if "/cgi/gid_form.pl" in row:
                if form_2 is None:
                    form_2 = []
                    form_2_begin = True
                elif form_3 is None:
                    form_3 = []
                    form_3_begin = True

        self.setStatusMessage("Plotting Results")

        if not form_1 is None:
            x_1, y_1 = self.get_plots_from_form("/cgi/ter_form.pl", form_1)

            self.plot_histo(x_1, y_1, 40, 1, 0, "Critical Angle for TER",
                            "Incidence angle [degrees]", "Reflectivity")
            self.tabs_widget.setCurrentIndex(1)
        else:
            x_1 = None
            y_1 = None

        if not form_2 is None:
            x_2, y_2 = self.get_plots_from_form("/cgi/gid_form.pl", form_2)

            self.plot_histo(x_2, y_2, 60, 2, 1, "Darwin Curve ($\sigma$ Pol.)",
                            "Scan Angle [arcsec]", "Diffracted Intensity")
            self.tabs_widget.setCurrentIndex(2)
        else:
            x_2 = None
            y_2 = None

        if not form_3 is None:
            x_3, y_3 = self.get_plots_from_form("/cgi/gid_form.pl", form_3)

            self.plot_histo(x_3, y_3, 80, 3, 2, "Darwin Curve ($\pi$ Pol.)",
                            "Scan Angle [arcsec]", "Diffracted Intensity")
            self.tabs_widget.setCurrentIndex(3)
        else:
            x_3 = None
            y_3 = None

        return [x_1, y_1], [x_2, y_2], [x_3, y_3]
コード例 #4
0
    createPage()


openFile = QFileDialog.getOpenFileName()
if openFile[0] != "":
    openedFile = open(openFile[0], 'r')
    Lines = openedFile.readlines()
    for i in Lines:
        comparisonsData.append(list(map(int, i.replace("\n", "").split(">"))))

print(comparisonsData)

web.setHtml(html)
submit.clicked.connect(submitLink)
team1.clicked.connect(submitTeam1)
team2.clicked.connect(submitTeam2)
saveFileButton.clicked.connect(saveFile)

web.setFixedHeight(int(app.primaryScreen().size().height() * .75))
leftLayout.addWidget(top, 0, 0)
leftLayout.addWidget(web, 2, 0)
left.setLayout(leftLayout)

layout.addWidget(left, 0, 0)
layout.addWidget(rankDisplayScroll, 0, 1)
layout.setAlignment(Qt.AlignTop)
win.setLayout(layout)
win.setWindowTitle("Robot Tinder")
win.show()
sys.exit(app.exec_())
コード例 #5
0
    }
    .twitter {
        color: #0084b4;
        font-size: 1.5em;
    }
    </style>
    <body bgcolor="black">%s</body>
    </html>
"""

tab2 = QWidget()
tab2.setStyleSheet("background-color:white;")

twitter_info = QWebEngineView(instagram_tab)
twitter_info.setFixedWidth(714)
twitter_info.setFixedHeight(200)
twitter_info.setHtml(twitter_label_html_fmt % '')
twitter_info.show()

tab_widget.addTab(instagram_tab, qta.icon('fa.instagram', color='#fb3958'),
                  "Instagram")
tab_widget.addTab(tab2, qta.icon('fa.twitter', color='#0084b4'), "Twitter")

match_button = QPushButton('Instagram Match', instagram_tab)
match_button.move(754, 20)
non_match_button = QPushButton('Not Instagram Match', instagram_tab)
non_match_button.move(754, 55)
found_button = QPushButton('Found', instagram_tab)
found_button.move(754, 90)

search_button = QPushButton('Search', instagram_tab)
コード例 #6
0
class X0h(XrayServerWidget):
    name = "X0h"
    description = "X0h"
    icon = "icons/x0h.png"
    maintainer = "Luca Rebuffi"
    maintainer_email = "luca.rebuffi(@at@)elettra.eu"
    priority = 1
    category = "X0h"
    keywords = ["data", "file", "load", "read"]

    want_main_area = 1

    outputs = [
        {
            "name": "xrayserver_data",
            "type": DataExchangeObject,
            "doc": "xrayserver_data",
            "id": "xrayserver_data"
        },
    ]

    xway = Setting(2)
    wave = Setting(0.0)
    line = Setting("Cu-Ka1")

    coway = Setting(0)
    code = Setting("Silicon")
    amor = Setting("")
    chem = Setting("")
    rho = Setting(0.0)

    i1 = Setting(1)
    i2 = Setting(1)
    i3 = Setting(1)

    df1df2 = Setting(1)
    detail = Setting(1)

    def __init__(self):
        super().__init__()

        left_box_1 = oasysgui.widgetBox(self.controlArea,
                                        "X0h Request Form",
                                        addSpace=True,
                                        orientation="vertical",
                                        width=400,
                                        height=630)

        left_box_2 = oasysgui.widgetBox(left_box_1,
                                        "X-rays",
                                        addSpace=True,
                                        orientation="horizontal",
                                        width=380,
                                        height=110)

        left_box_2_1 = oasysgui.widgetBox(left_box_2,
                                          "",
                                          addSpace=True,
                                          orientation="vertical",
                                          width=150,
                                          height=110)

        gui.radioButtons(
            left_box_2_1,
            self,
            "xway", ["Wavelength (Å)", "Energy (keV)", "Characteristic line"],
            callback=self.set_xway)

        self.box_wave = oasysgui.widgetBox(left_box_2,
                                           "",
                                           addSpace=True,
                                           orientation="vertical",
                                           width=190)
        gui.separator(self.box_wave, height=10)
        gui.lineEdit(self.box_wave,
                     self,
                     "wave",
                     label="",
                     labelWidth=0,
                     addSpace=False,
                     valueType=float,
                     orientation="horizontal")

        self.box_line = oasysgui.widgetBox(left_box_2,
                                           "",
                                           addSpace=True,
                                           orientation="horizontal",
                                           width=190,
                                           height=110)
        gui.separator(self.box_line, height=120)
        XRayServerGui.combobox_text(self.box_line,
                                    self,
                                    "line",
                                    label="",
                                    labelWidth=0,
                                    items=self.get_lines(),
                                    sendSelectedValue=True,
                                    orientation="horizontal",
                                    selectedValue=self.line)

        button = gui.button(self.box_line, self, "?", callback=self.help_lines)
        button.setFixedWidth(15)

        self.set_xway()

        left_box_3 = oasysgui.widgetBox(left_box_1,
                                        "Target",
                                        addSpace=True,
                                        orientation="horizontal",
                                        width=380,
                                        height=140)

        left_box_3_1 = oasysgui.widgetBox(left_box_3,
                                          "",
                                          addSpace=True,
                                          orientation="vertical",
                                          width=125,
                                          height=110)

        gui.radioButtons(left_box_3_1,
                         self,
                         "coway",
                         ["Crystal", "Other Material", "Chemical Formula"],
                         callback=self.set_coway)

        self.box_crystal = oasysgui.widgetBox(left_box_3,
                                              "",
                                              addSpace=True,
                                              orientation="horizontal",
                                              width=210)
        XRayServerGui.combobox_text(self.box_crystal,
                                    self,
                                    "code",
                                    label="",
                                    labelWidth=0,
                                    items=self.get_crystals(),
                                    sendSelectedValue=True,
                                    orientation="horizontal",
                                    selectedValue=self.code)

        button = gui.button(self.box_crystal,
                            self,
                            "?",
                            callback=self.help_crystals)
        button.setFixedWidth(15)

        self.box_other = oasysgui.widgetBox(left_box_3,
                                            "",
                                            addSpace=True,
                                            orientation="horizontal",
                                            width=210)
        gui.separator(self.box_other, height=75)
        XRayServerGui.combobox_text(self.box_other,
                                    self,
                                    "amor",
                                    label="",
                                    labelWidth=0,
                                    items=self.get_others(),
                                    sendSelectedValue=True,
                                    orientation="horizontal",
                                    selectedValue=self.amor)

        button = gui.button(self.box_other,
                            self,
                            "?",
                            callback=self.help_others)
        button.setFixedWidth(15)

        self.box_chemical = oasysgui.widgetBox(left_box_3,
                                               "",
                                               addSpace=True,
                                               orientation="vertical",
                                               width=210,
                                               height=140)
        gui.separator(self.box_chemical, height=50)

        gui.lineEdit(self.box_chemical,
                     self,
                     "chem",
                     label=" ",
                     labelWidth=1,
                     addSpace=False,
                     valueType=str,
                     orientation="horizontal",
                     callback=self.set_rho)
        gui.lineEdit(self.box_chemical,
                     self,
                     "rho",
                     label=u"\u03C1" + " (g/cm3)",
                     labelWidth=60,
                     addSpace=False,
                     valueType=float,
                     orientation="horizontal")

        self.set_coway()

        left_box_4 = oasysgui.widgetBox(left_box_1,
                                        "Reflection",
                                        addSpace=True,
                                        orientation="horizontal",
                                        width=380,
                                        height=60)

        gui.lineEdit(left_box_4,
                     self,
                     "i1",
                     label="Miller indices",
                     labelWidth=200,
                     addSpace=False,
                     valueType=int,
                     orientation="horizontal")
        gui.lineEdit(left_box_4,
                     self,
                     "i2",
                     label=" ",
                     labelWidth=1,
                     addSpace=False,
                     valueType=int,
                     orientation="horizontal")
        gui.lineEdit(left_box_4,
                     self,
                     "i3",
                     label=" ",
                     labelWidth=1,
                     addSpace=False,
                     valueType=int,
                     orientation="horizontal")

        left_box_5 = oasysgui.widgetBox(
            left_box_1,
            "Database Options for dispersion corrections df1, df2",
            addSpace=True,
            orientation="vertical",
            width=380,
            height=185)

        gui.radioButtons(left_box_5, self, "df1df2", [
            "Auto (Henke at low energy, X0h at mid, Brennan-Cowan\nat high)",
            "Use X0h data (5-25 keV or 0.5-2.5 A), recommended for\nBragg diffraction",
            "Use Henke data (0.01-30 keV or 0.4-1200 A),\nrecommended for soft x-rays",
            "Use Brennan-Cowan data (0.03-700 keV or 0.02-400 A)",
            "Compare results for all of the above sources"
        ])

        left_box_6 = oasysgui.widgetBox(left_box_1,
                                        "Output Options",
                                        addSpace=True,
                                        orientation="vertical",
                                        width=380,
                                        height=50)

        gui.checkBox(left_box_6,
                     self,
                     "detail",
                     "Print atomic coordinates",
                     labelWidth=250)

        button = gui.button(self.controlArea,
                            self,
                            "Get X0h!",
                            callback=self.submit)
        button.setFixedHeight(30)

        gui.rubber(self.controlArea)

        self.tabs = []
        self.tabs_widget = oasysgui.tabWidget(self.mainArea)
        self.initializeTabs()

        self.x0h_output = QWebView(self.tabs[0])

        self.tabs[0].layout().addWidget(self.x0h_output)

        self.x0h_output.setFixedHeight(640)
        self.x0h_output.setFixedWidth(740)

    def getLeftPartWidth(self):
        return 415

    def set_xway(self):
        self.box_wave.setVisible(self.xway != 2)
        self.box_line.setVisible(self.xway == 2)

    def set_coway(self):
        self.box_crystal.setVisible(self.coway == 0)
        self.box_other.setVisible(self.coway == 1)
        self.box_chemical.setVisible(self.coway == 2)

    def set_rho(self):
        if not self.chem is None:
            if not self.chem.strip() == "":
                self.chem = self.chem.strip()
                self.rho = XRayServerPhysics.getMaterialDensity(self.chem)

    def initializeTabs(self):
        current_tab = self.tabs_widget.currentIndex()

        size = len(self.tabs)

        for index in range(0, size):
            self.tabs_widget.removeTab(size - 1 - index)

        self.tabs = [
            gui.createTabPage(self.tabs_widget, "X-ray Server Ouput"),
            gui.createTabPage(self.tabs_widget, "Critical Angle for TER"),
            gui.createTabPage(self.tabs_widget,
                              "Darwin Curve (" + u"\u03C3" + " Pol.)"),
            gui.createTabPage(self.tabs_widget,
                              "Darwin Curve (" + u"\u03C0" + " Pol.)"),
        ]

        for tab in self.tabs:
            tab.setFixedHeight(650)
            tab.setFixedWidth(750)

        self.plot_canvas = [None, None, None]

        self.tabs_widget.setCurrentIndex(current_tab)

    def submit(self):
        self.progressBarInit()
        self.setStatusMessage("Submitting Request")

        self.checkFields()

        parameters = {}

        parameters.update({"xway": str(self.xway + 1)})
        parameters.update({"wave": str(self.wave)})
        parameters.update({"line": self.line})
        parameters.update({"coway": str(self.coway)})
        parameters.update({"code": self.code})
        parameters.update({"amor": self.amor})
        parameters.update({"chem": self.chem})
        parameters.update({"rho": str(self.rho)})

        parameters.update({"i1": str(self.i1)})
        parameters.update({"i2": str(self.i2)})
        parameters.update({"i3": str(self.i3)})
        parameters.update({"df1df2": self.decode_df1df2()})

        parameters.update({"modeout": "0"})
        parameters.update({"detail": str(self.detail)})

        try:
            response = HttpManager.send_xray_server_request_POST(
                APPLICATION, parameters)
            response = self.clear_response(response)

            self.tabs_widget.setCurrentIndex(0)
            self.x0h_output.setHtml(response)

            data0, data1, data2 = self.extract_plots(response)

            exchange_data = DataExchangeObject("XRAYSERVER", "X0H")
            exchange_data.add_content("reflectivity", data0)
            exchange_data.add_content("reflectivity_units_to_degrees", 1.0)
            exchange_data.add_content("x-ray_diffraction_profile_sigma", data1)
            exchange_data.add_content(
                "x-ray_diffraction_profile_sigma_units_to_degrees",
                0.000277777805)
            exchange_data.add_content("x-ray_diffraction_profile_pi", data2)
            exchange_data.add_content(
                "x-ray_diffraction_profile_pi_units_to_degrees",
                0.000277777805)

            self.send("xrayserver_data", exchange_data)

        except urllib.error.HTTPError as e:
            self.x0h_output.setHtml(
                'The server couldn\'t fulfill the request.\nError Code: ' +
                str(e.code) + "\n\n" +
                server.BaseHTTPRequestHandler.responses[e.code][1])
            raise e

        except urllib.error.URLError as e:
            self.x0h_output.setHtml('We failed to reach a server.\nReason: ' +
                                    e.reason)
            raise e

        except XrayServerException as e:
            ShowHtmlDialog.show_html("X-ray Server Error",
                                     e.response,
                                     width=750,
                                     height=500,
                                     parent=self)

            raise e
        except Exception as e:
            self.x0h_output.setHtml('We failed to reach a server.\nReason: ' +
                                    str(e))

            raise e

        self.setStatusMessage("")
        self.progressBarFinished()

    def clear_response(self, response):
        # remove links
        output = response.split("<hr>")[0] + "\n</body></html>"

        # remove "get the curve" images
        output = "".join(
            output.split(
                "<input type=image src=\"images/get_the_curve.gif\" border=0 width=102 height=12 alt=\"Get the reflectivity curve\">"
            ))
        output = "".join(
            output.split(
                "<input type=image src=\"images/get_the_curve.gif\" border=0 width=102 height=12 alt=\"Get the Bragg curve (sigma)\">"
            ))
        output = "".join(
            output.split(
                "<input type=image src=\"images/get_the_curve.gif\" border=0 width=102 height=12 alt=\"Get the Bragg curve (pi)\">"
            ))
        # remove question mark images and links
        output = "".join(
            output.split(
                "<a  href=\"javascript:void(0)\" onClick=\"Wfloat(\'images/x0h_help_0.gif\',\'x0h_0\',740,357);\"><b>?</b></a> &nbsp;"
            ))
        output = "".join(
            output.split(
                "<a  href=\"javascript:void(0)\" onClick=\"Wfloat(\'images/x0h_help_h.gif\',\'x0h_h\',705,853);\"><b>?</b></a> &nbsp;"
            ))

        return output

    def checkFields(self):
        pass

    def decode_df1df2(self):
        if self.df1df2 == 0: return "-1"
        elif self.df1df2 == 1: return "0"
        elif self.df1df2 == 2: return "2"
        elif self.df1df2 == 3: return "4"
        elif self.df1df2 == 4: return "10"

    def extract_plots(self, response):
        form_1_begin = False
        form_2_begin = False
        form_3_begin = False

        form_1 = None
        form_2 = None
        form_3 = None

        rows = response.split("\r\n")

        for row in rows:
            if form_1_begin:
                if "<td>" in row:
                    form_1_begin = False
            elif form_2_begin:
                if "<td>" in row:
                    form_2_begin = False
            elif form_3_begin:
                if "<td>" in row:
                    form_3_begin = False

            if form_1_begin:
                form_1.append(row)
            elif form_2_begin:
                form_2.append(row)
            elif form_3_begin:
                form_3.append(row)

            if "/cgi/ter_form.pl" in row:
                if form_1 is None:
                    form_1 = []
                    form_1_begin = True

            if "/cgi/gid_form.pl" in row:
                if form_2 is None:
                    form_2 = []
                    form_2_begin = True
                elif form_3 is None:
                    form_3 = []
                    form_3_begin = True

        self.setStatusMessage("Plotting Results")

        if not form_1 is None:
            x_1, y_1 = self.get_plots_from_form("/cgi/ter_form.pl", form_1)

            self.plot_histo(x_1, y_1, 40, 1, 0, "Critical Angle for TER",
                            "Incidence angle [degrees]", "Reflectivity")
            self.tabs_widget.setCurrentIndex(1)
        else:
            x_1 = None
            y_1 = None

        if not form_2 is None:
            x_2, y_2 = self.get_plots_from_form("/cgi/gid_form.pl", form_2)

            self.plot_histo(x_2, y_2, 60, 2, 1, "Darwin Curve ($\sigma$ Pol.)",
                            "Scan Angle [arcsec]", "Diffracted Intensity")
            self.tabs_widget.setCurrentIndex(2)
        else:
            x_2 = None
            y_2 = None

        if not form_3 is None:
            x_3, y_3 = self.get_plots_from_form("/cgi/gid_form.pl", form_3)

            self.plot_histo(x_3, y_3, 80, 3, 2, "Darwin Curve ($\pi$ Pol.)",
                            "Scan Angle [arcsec]", "Diffracted Intensity")
            self.tabs_widget.setCurrentIndex(3)
        else:
            x_3 = None
            y_3 = None

        return [x_1, y_1], [x_2, y_2], [x_3, y_3]
コード例 #7
0
ファイル: background.py プロジェクト: kmcintyre/scewpt
def background_pic(background, prefix='/tmp'):
    print 'background:', background[
        keys.
        entity_league], 'http://twitter.com/' + background[keys.entity_twitter]
    curator = User().get_curator(background[keys.entity_league])
    bgs = s3.get_twitter_media(background, 'background')
    if len(bgs) > 10:
        print 'more than 10 backgrounds:', len(bgs)
        bgs = bgs[:10]
    bgstringarray = ['"' + fixed.key_url(s) + '"' for s in bgs]
    print bgstringarray
    bgstring = ','.join(bgstringarray)
    bgcolor = 'white'
    cv = QWebEngineView()
    cv.setFixedWidth(590)
    minheight = 210
    minwidth = 570
    for b in bgs:
        currentheight = minwidth / 3
        minwidth = minwidth - 25
        newheight = minwidth / 3
        actual_diff = 35 + (newheight - currentheight)
        minheight = minheight + actual_diff
    cv.setFixedHeight(minheight)
    cv.show()

    def html_loaded(result=None):
        print 'html_loaded:', result
        local_file_name = prefix + '/bg_update_' + background[
            keys.entity_twitter] + '.png'
        qimg = QImage(cv.width(), cv.height(),
                      QImage.Format_ARGB32_Premultiplied)
        painter = QPainter(qimg)
        cv.page().view().render(painter)
        qimg.save(local_file_name)
        print 'saved:', local_file_name, 'painter:', painter, 'qimg:', qimg
        del painter
        if background and twitter_keys.message_tweet in background:
            upload_png = background[keys.entity_league] + '/tweet/' + ''.join(
                random.choice(string.ascii_lowercase)
                for _ in range(10)) + '.png'
            b = s3.bucket_straight(curator['role'])
            s3.save_s3(b, upload_png, None, local_file_name, 'image/png')
            bg_message_pic = 'http://' + b.name + '/' + upload_png
            print 'bg_message_pic:', bg_message_pic
            if background:
                background[twitter_keys.message_pic] = bg_message_pic
                print 'append to tweet:', background[
                    twitter_keys.message_tweet], 'url:', background[
                        twitter_keys.message_pic]
                TweetQueue().createMessage(background)
        cv.close()
        reactor.stop()

    def post_load(result=None):
        print 'post load:', result
        QTimer.singleShot(10000, html_loaded)

    cv.page().loadFinished.connect(post_load)
    formatted_html = background_html.format(bgstring, bgcolor)
    cv.page().setHtml(formatted_html)
コード例 #8
0
topLayout = QGridLayout()
layout = QGridLayout()

top = QWidget()
topLayout.addWidget(linkEntry, 0, 0)
topLayout.addWidget(submit, 0, 1)
topLayout.setAlignment(Qt.AlignTop)

top.setLayout(topLayout)

layout.addWidget(top, 0, 0)
layout.addWidget(web, 1, 0)

win.setLayout(layout)

layout.setAlignment(Qt.AlignTop)

web.setFixedHeight(900)


def gotoURL():
    web.load(QUrl(linkEntry.text()))


submit.clicked.connect(gotoURL)

win.setWindowTitle("Probot Browse")
win.show()

sys.exit(app.exec_())
コード例 #9
0
ファイル: ow_x0h.py プロジェクト: lucarebuffi/XRayServer
class X0h(XrayServerWidget):
    name = "X0h"
    description = "X0h"
    icon = "icons/x0h.png"
    maintainer = "Luca Rebuffi"
    maintainer_email = "luca.rebuffi(@at@)elettra.eu"
    priority = 1
    category = "X0h"
    keywords = ["data", "file", "load", "read"]

    want_main_area = 1

    outputs = [{"name": "xrayserver_data",
                "type": DataExchangeObject,
                "doc": "xrayserver_data",
                "id": "xrayserver_data"}, ]


    xway = Setting(2)
    wave = Setting(0.0)
    line = Setting("Cu-Ka1")

    coway = Setting(0)
    code = Setting("Silicon")
    amor = Setting("")
    chem = Setting("")
    rho = Setting(0.0)

    i1 = Setting(1)
    i2 = Setting(1)
    i3 = Setting(1)

    df1df2 = Setting(1)
    detail = Setting(1)

    def __init__(self):
        super().__init__()

        left_box_1 = oasysgui.widgetBox(self.controlArea, "X0h Request Form", addSpace=True, orientation="vertical",
                                         width=400, height=630)

        left_box_2 = oasysgui.widgetBox(left_box_1, "X-rays", addSpace=True, orientation="horizontal", width=380, height=110)

        left_box_2_1 = oasysgui.widgetBox(left_box_2, "", addSpace=True, orientation="vertical", width=150, height=110)

        gui.radioButtons(left_box_2_1, self, "xway", ["Wavelength (Å)", "Energy (keV)", "Characteristic line"], callback=self.set_xway )

        self.box_wave = oasysgui.widgetBox(left_box_2, "", addSpace=True, orientation="vertical", width=190)
        gui.separator(self.box_wave, height=10)
        oasysgui.lineEdit(self.box_wave, self, "wave", label="", labelWidth=0, addSpace=False, valueType=float, orientation="horizontal")

        self.box_line = oasysgui.widgetBox(left_box_2, "", addSpace=True, orientation="horizontal", width=190, height=110)
        gui.separator(self.box_line, height=120)
        XRayServerGui.combobox_text(self.box_line, self, "line", label="", labelWidth=0,
                               items=self.get_lines(),
                               sendSelectedValue=True, orientation="horizontal", selectedValue=self.line)

        button = gui.button( self.box_line, self, "?", callback=self.help_lines)
        button.setFixedWidth(15)

        self.set_xway()

        left_box_3 = oasysgui.widgetBox(left_box_1, "Target", addSpace=True, orientation="horizontal", width=380, height=140)

        left_box_3_1 = oasysgui.widgetBox(left_box_3, "", addSpace=True, orientation="vertical", width=125, height=110)

        gui.radioButtons(left_box_3_1, self, "coway", ["Crystal", "Other Material", "Chemical Formula"], callback=self.set_coway )

        self.box_crystal = oasysgui.widgetBox(left_box_3, "", addSpace=True, orientation="horizontal", width=210)
        XRayServerGui.combobox_text(self.box_crystal, self, "code", label="", labelWidth=0,
                               items=self.get_crystals(),
                               sendSelectedValue=True, orientation="horizontal", selectedValue=self.code)


        button = gui.button( self.box_crystal, self, "?", callback=self.help_crystals)
        button.setFixedWidth(15)

        self.box_other = oasysgui.widgetBox(left_box_3, "", addSpace=True, orientation="horizontal", width=210)
        gui.separator(self.box_other, height=75)
        XRayServerGui.combobox_text(self.box_other, self, "amor", label="", labelWidth=0,
                               items=self.get_others(),
                               sendSelectedValue=True, orientation="horizontal", selectedValue=self.amor)

        button = gui.button( self.box_other, self, "?", callback=self.help_others)
        button.setFixedWidth(15)

        self.box_chemical = oasysgui.widgetBox(left_box_3, "", addSpace=True, orientation="vertical", width=210, height=140)
        gui.separator(self.box_chemical, height=50)

        oasysgui.lineEdit(self.box_chemical, self, "chem", label=" ", labelWidth=1, addSpace=False, valueType=str, orientation="horizontal", callback=self.set_rho)
        oasysgui.lineEdit(self.box_chemical, self, "rho", label=u"\u03C1" + " (g/cm3)", labelWidth=60, addSpace=False, valueType=float, orientation="horizontal")

        self.set_coway()

        left_box_4 = oasysgui.widgetBox(left_box_1, "Reflection", addSpace=True, orientation="horizontal", width=380, height=60)

        oasysgui.lineEdit(left_box_4, self, "i1", label="Miller indices", labelWidth=200, addSpace=False, valueType=int, orientation="horizontal")
        oasysgui.lineEdit(left_box_4, self, "i2", label=" ", labelWidth=1, addSpace=False, valueType=int, orientation="horizontal")
        oasysgui.lineEdit(left_box_4, self, "i3", label=" ", labelWidth=1, addSpace=False, valueType=int, orientation="horizontal")

        left_box_5 = oasysgui.widgetBox(left_box_1, "Database Options for dispersion corrections df1, df2", addSpace=True, orientation="vertical", width=380, height=185)

        gui.radioButtons(left_box_5, self, "df1df2", ["Auto (Henke at low energy, X0h at mid, Brennan-Cowan\nat high)",
                                                      "Use X0h data (5-25 keV or 0.5-2.5 A), recommended for\nBragg diffraction",
                                                      "Use Henke data (0.01-30 keV or 0.4-1200 A),\nrecommended for soft x-rays",
                                                      "Use Brennan-Cowan data (0.03-700 keV or 0.02-400 A)",
                                                      "Compare results for all of the above sources"])

        left_box_6 = oasysgui.widgetBox(left_box_1, "Output Options", addSpace=True, orientation="vertical", width=380, height=50)

        gui.checkBox(left_box_6, self, "detail", "Print atomic coordinates", labelWidth=250)

        button = gui.button(self.controlArea, self, "Get X0h!", callback=self.submit)
        button.setFixedHeight(30)

        gui.rubber(self.controlArea)

        self.tabs = []
        self.tabs_widget = oasysgui.tabWidget(self.mainArea)
        self.initializeTabs()

        self.x0h_output = QWebView(self.tabs[0])

        self.tabs[0].layout().addWidget(self.x0h_output)

        self.x0h_output.setFixedHeight(640)
        self.x0h_output.setFixedWidth(740)

    def getLeftPartWidth(self):
        return 415

    def set_xway(self):
        self.box_wave.setVisible(self.xway!=2)
        self.box_line.setVisible(self.xway==2)

    def set_coway(self):
        self.box_crystal.setVisible(self.coway==0)
        self.box_other.setVisible(self.coway==1)
        self.box_chemical.setVisible(self.coway==2)

    def set_rho(self):
        if not self.chem is None:
            if not self.chem.strip() == "":
                self.chem = self.chem.strip()
                self.rho = XRayServerPhysics.getMaterialDensity(self.chem)

    def initializeTabs(self):
        current_tab = self.tabs_widget.currentIndex()

        size = len(self.tabs)

        for index in range(0, size):
            self.tabs_widget.removeTab(size-1-index)

        self.tabs = [gui.createTabPage(self.tabs_widget, "X-ray Server Ouput"),
                     gui.createTabPage(self.tabs_widget, "Critical Angle for TER"),
                     gui.createTabPage(self.tabs_widget, "Darwin Curve (" + u"\u03C3" + " Pol.)"),
                     gui.createTabPage(self.tabs_widget, "Darwin Curve (" + u"\u03C0" + " Pol.)"),
                     ]

        for tab in self.tabs:
            tab.setFixedHeight(650)
            tab.setFixedWidth(750)

        self.plot_canvas = [None, None, None]

        self.tabs_widget.setCurrentIndex(current_tab)

    def submit(self):
        self.progressBarInit()
        self.setStatusMessage("Submitting Request")
        
        self.checkFields()

        parameters = {}

        parameters.update({"xway" : str(self.xway + 1)})
        parameters.update({"wave" : str(self.wave)})
        parameters.update({"line" : self.line})
        parameters.update({"coway" : str(self.coway)})
        parameters.update({"code" : self.code})
        parameters.update({"amor" : self.amor})
        parameters.update({"chem" : self.chem})
        parameters.update({"rho" : str(self.rho)})

        parameters.update({"i1" : str(self.i1)})
        parameters.update({"i2" : str(self.i2)})
        parameters.update({"i3" : str(self.i3)})
        parameters.update({"df1df2" : self.decode_df1df2()})

        parameters.update({"modeout" : "0" })
        parameters.update({"detail" : str(self.detail)})

        try:
            response = HttpManager.send_xray_server_request_GET(APPLICATION, parameters)

            response = self.clear_response(response)

            self.tabs_widget.setCurrentIndex(0)
            self.x0h_output.setHtml(response)

            data0, data1, data2 = self.extract_plots(response)

            try:
                exchange_data = DataExchangeObject("XRAYSERVER", "X0H")

                if self.coway == 0: # crystals
                    dictionary = self.extract_structure_data(response)

                    exchange_data.add_content("structure", dictionary["structure"])
                    exchange_data.add_content("h", self.i1)
                    exchange_data.add_content("k", self.i2)
                    exchange_data.add_content("l", self.i3)
                    exchange_data.add_content("d_spacing",  dictionary["d_spacing"])
                    exchange_data.add_content("energy", dictionary["energy"])
                    exchange_data.add_content("bragg_angle",  dictionary["bragg_angle"])
                    exchange_data.add_content("xr0",  dictionary["xr0"])
                    exchange_data.add_content("xi0",  dictionary["xi0"])
                    exchange_data.add_content("xrh_s",  dictionary["xrh_s"])
                    exchange_data.add_content("xih_s",  dictionary["xih_s"])
                    exchange_data.add_content("xrh_p",  dictionary["xrh_p"])
                    exchange_data.add_content("xih_p",  dictionary["xih_p"])

                exchange_data.add_content("reflectivity", data0)
                exchange_data.add_content("reflectivity_units_to_degrees", 1.0)
                exchange_data.add_content("x-ray_diffraction_profile_sigma", data1)
                exchange_data.add_content("x-ray_diffraction_profile_sigma_units_to_degrees", 0.000277777805)
                exchange_data.add_content("x-ray_diffraction_profile_pi", data2)
                exchange_data.add_content("x-ray_diffraction_profile_pi_units_to_degrees", 0.000277777805)

                self.send("xrayserver_data", exchange_data)
            except: #problems with xrayserver, no data found
                pass
        except urllib.error.HTTPError as e:
            self.x0h_output.setHtml('The server couldn\'t fulfill the request.\nError Code: '
                                    + str(e.code) + "\n\n" +
                                    server.BaseHTTPRequestHandler.responses[e.code][1])
        except urllib.error.URLError as e:
            self.x0h_output.setHtml('We failed to reach a server.\nReason: ' + e.reason)
        except XrayServerException as e:
            ShowHtmlDialog.show_html("X-ray Server Error", e.response, width=750, height=500, parent=self)
        except Exception as e:
            ShowTextDialog.show_text("Error", 'Error Occurred.\nReason: ' + str(e), parent=self)

        self.setStatusMessage("")
        self.progressBarFinished()

    def clear_response(self, response):
        # remove links
        output = response.split("<hr>")[0] + "\n</body></html>"

        # remove "get the curve" images
        output = "".join(output.split("<input type=image src=\"images/get_the_curve.gif\" border=0 width=102 height=12 alt=\"Get the reflectivity curve\">"))
        output = "".join(output.split("<input type=image src=\"images/get_the_curve.gif\" border=0 width=102 height=12 alt=\"Get the Bragg curve (sigma)\">"))
        output = "".join(output.split("<input type=image src=\"images/get_the_curve.gif\" border=0 width=102 height=12 alt=\"Get the Bragg curve (pi)\">"))
        # remove question mark images and links
        output = "".join(output.split("<a  href=\"javascript:void(0)\" onClick=\"Wfloat(\'images/x0h_help_0.gif\',\'x0h_0\',740,357);\"><b>?</b></a> &nbsp;"))
        output = "".join(output.split("<a  href=\"javascript:void(0)\" onClick=\"Wfloat(\'images/x0h_help_h.gif\',\'x0h_h\',705,853);\"><b>?</b></a> &nbsp;"))

        temp_1, temp_2 = output.split("style.css")
        output = temp_1 + XRAY_SERVER_URL + "/style.css" + temp_2

        output = output.split("<td><img src=\"images/x.gif\" width=31 height=32 border=0></td>")[0] + "</tr></tr></body></html>"

        return output

    def checkFields(self):
        pass

    def decode_df1df2(self):
        if self.df1df2 == 0: return "-1"
        elif self.df1df2 == 1: return "0"
        elif self.df1df2 == 2: return "2"
        elif self.df1df2 == 3: return "4"
        elif self.df1df2 == 4: return "10"


    def extract_structure_data(self, response=""):
        dictionary = {}

        try:
            dictionary["structure"] = response.split(sep="<tr><td>Structure :   </td><td>")[1].split("</td></tr>")[0].strip()
            dictionary["energy"]   = float(response.split(sep="<dt>Closest absorption edge (keV) :  </dt>")[1].split(sep="<dt>")[3].split(sep="</dt>")[0].strip())

            try:
                x0_string = response.split(sep="Critical angle for TER (degr., mrad) :  </dt>")[1].split(sep="<dt>")[1].split(sep=", &nbsp; &nbsp;")

                dictionary["xr0"] = float(x0_string[0].strip())
                dictionary["xi0"] = float(x0_string[1].split(sep="<sub>")[0].strip())
            except:
                dictionary["xr0"] = 0.0
                dictionary["xi0"] = 0.0

            try:
                bragg_angle_d_spacing_string = response.split("<dt> ESinTheta=12.398/(2d) : </dt>")[1].split(sep="<dt>")

                dictionary["bragg_angle"] = float(bragg_angle_d_spacing_string[1].split(sep="</dt>")[0].strip())
                dictionary["d_spacing"] = float(bragg_angle_d_spacing_string[2].split(sep="</dt>")[0].strip())
            except:
                dictionary["bragg_angle"] = 0.0
                dictionary["d_spacing"] = 0.0

            try:
                xh_s_string = response.split(sep="<dt><b><i>Sigma <sub>&nbsp;</sub></i></b></dt>")[1].split(sep="<dt>")[1].split(sep=", &nbsp; &nbsp;")

                dictionary["xrh_s"] = float(xh_s_string[0].strip())
                dictionary["xih_s"] = float(xh_s_string[1].split(sep="<sub>")[0].strip())
            except:
                dictionary["xrh_s"] = 0.0
                dictionary["xih_s"] = 0.0

            try:
                xh_p_string = response.split(sep="<dt><b><i>Pi <sub>&nbsp;</sub></i></b></dt>")[1].split(sep="<dt>")[1].split(sep=", &nbsp; &nbsp;")

                dictionary["xrh_p"] = float(xh_p_string[0].strip())
                dictionary["xih_p"] = float(xh_p_string[1].split(sep="<sub>")[0].strip())
            except:
                dictionary["xrh_p"] = 0.0
                dictionary["xih_p"] = 0.0
        except:
            dictionary["structure"] = "Problems while reading structure"
            dictionary["energy"]    = 0.0


        return dictionary


    def extract_plots(self, response):
        form_1_begin = False
        form_2_begin = False
        form_3_begin = False

        form_1 = None
        form_2 = None
        form_3 = None

        rows = response.split("\n")

        for row in rows:
            if form_1_begin:
                if "<td>" in row:
                    form_1_begin = False
            elif form_2_begin:
                if "<td>" in row:
                    form_2_begin = False
            elif form_3_begin:
                if "<td>" in row:
                    form_3_begin = False

            if form_1_begin:
                form_1.append(row)
            elif form_2_begin:
                form_2.append(row)
            elif form_3_begin:
                form_3.append(row)

            if "/cgi/ter_form.pl" in row:
                if form_1 is None:
                    form_1 = []
                    form_1_begin = True

            if "/cgi/gid_form.pl" in row:
                if form_2 is None:
                    form_2 = []
                    form_2_begin = True
                elif form_3 is None:
                    form_3 = []
                    form_3_begin = True

        self.setStatusMessage("Plotting Results")

        if not form_1 is None:
            x_1, y_1 = self.get_plots_from_form("/cgi/ter_form.pl", form_1)

            self.plot_histo(x_1, y_1, 40, 1, 0, "Critical Angle for TER", "Incidence angle [degrees]", "Reflectivity")
            self.tabs_widget.setCurrentIndex(1)
        else:
            x_1 = None
            y_1 = None
            
        if not form_2 is None:
            x_2, y_2 = self.get_plots_from_form("/cgi/gid_form.pl", form_2)

            self.plot_histo(x_2, y_2, 60, 2, 1, "Darwin Curve ($\sigma$ Pol.)", "Scan Angle [arcsec]", "Diffracted Intensity")
            self.tabs_widget.setCurrentIndex(2)
        else:
            x_2 = None
            y_2 = None

        if not form_3 is None:
            x_3, y_3 = self.get_plots_from_form("/cgi/gid_form.pl", form_3)

            self.plot_histo(x_3, y_3, 80, 3, 2, "Darwin Curve ($\pi$ Pol.)", "Scan Angle [arcsec]", "Diffracted Intensity")
            self.tabs_widget.setCurrentIndex(3)
        else:
            x_3 = None
            y_3 = None

        return [x_1, y_1], [x_2, y_2], [x_3, y_3]
コード例 #10
0
ファイル: ow_x0h_NEW.py プロジェクト: lucarebuffi/XRayServer
class X0h(XrayServerWidget):
    name = "X0h"
    description = "X0h"
    icon = "icons/x0h.png"
    maintainer = "Luca Rebuffi"
    maintainer_email = "luca.rebuffi(@at@)elettra.eu"
    priority = 1
    category = "X0h"
    keywords = ["data", "file", "load", "read"]

    want_main_area = 1

    outputs = [{"name": "xrayserver_data",
                "type": DataExchangeObject,
                "doc": "xrayserver_data",
                "id": "xrayserver_data"}, ]

    def __init__(self):
        super().__init__()

        left_box_1 = oasysgui.widgetBox(self.controlArea, "X0h Request Form", addSpace=True, orientation="vertical",
                                         width=610, height=640)

        html = self.clear_input_form(HttpManager.send_xray_server_direct_request("/cgi/www_form.exe?template=x0h_form.htm"))

        self.x0h_input = QWebView(left_box_1)
        self.x0h_input.setHtml(html)

        left_box_1.layout().addWidget(self.x0h_input)

        self.x0h_input.setFixedHeight(540)
        self.x0h_input.setFixedWidth(590)

        button = gui.button(self.controlArea, self, "Get X0h!", callback=self.submit)
        button.setFixedHeight(30)

        gui.rubber(self.controlArea)

        self.tabs = []
        self.tabs_widget = oasysgui.tabWidget(self.mainArea)
        self.initializeTabs()

        self.x0h_output = QWebView(self.tabs[0])

        self.tabs[0].layout().addWidget(self.x0h_output)

        self.x0h_output.setFixedHeight(630)
        self.x0h_output.setFixedWidth(740)


    def clear_input_form(self, html):
        temp_1 = html.split("<body onload=\"setOnloads()\">")[0]
        temp_2 = html.split("<table cellspacing=0 cellpadding=0 border=0 bgcolor=\"#c1c1c1\"><tr><td>")[1]

        html = temp_1 + "<body>\n<table cellspacing=0 cellpadding=0 border=0 bgcolor=\"#c1c1c1\"><tr><td>\n" + temp_2

        html = html.split("<input type=SUBMIT value=\"Get X0h!\"><input type=RESET> <br>")[0]
        html += "\n<input type=SUBMIT style=\"display: none;\" id=\"submit-btn\"><input type=RESET style=\"display: none;\" id=\"reset-btn\"> <br>"
        html += "\n</form>"
        html += "\n</td></tr></table>"
        html += "\n</td></tr></table>"
        html += "\n</body>"
        html += "\n</html>"

        temp_1, temp_2 = html.split("x0h.js")
        html = temp_1 + XRAY_SERVER_URL + "/x0h.js" + temp_2

        temp_1, temp_2 = html.split("/cgi/x0h_form.exe")
        html = temp_1 + XRAY_SERVER_URL + "/cgi/x0h_form.exe" + temp_2

        return html

    def getLeftPartWidth(self):
        return 620

    def initializeTabs(self):
        current_tab = self.tabs_widget.currentIndex()

        size = len(self.tabs)

        for index in range(0, size):
            self.tabs_widget.removeTab(size-1-index)

        self.tabs = [gui.createTabPage(self.tabs_widget, "X-ray Server Ouput"),
                     gui.createTabPage(self.tabs_widget, "Critical Angle for TER"),
                     gui.createTabPage(self.tabs_widget, "Darwin Curve (" + u"\u03C3" + " Pol.)"),
                     gui.createTabPage(self.tabs_widget, "Darwin Curve (" + u"\u03C0" + " Pol.)"),
                     ]

        for tab in self.tabs:
            tab.setFixedHeight(650)
            tab.setFixedWidth(750)

        self.plot_canvas = [None, None, None]

        self.tabs_widget.setCurrentIndex(current_tab)

    def js_callback(self, result):
        pass

    def _callable_1(self, html):
        self.original_signal = self.x0h_input.loadFinished
        self.x0h_input.loadFinished.connect(self.loadFinished)
        self.x0h_input.setHidden(True)
        self.x0h_input.page().runJavaScript("document.getElementById('submit-btn').click()", self.js_callback)

    def loadFinished(self):
        self.x0h_input.page().toHtml(self._callable_2)

    def _callable_2(self, html):
        try:
            self.x0h_input.loadFinished.disconnect()
            self.x0h_input.back()
            self.x0h_input.setHidden(False)

            response_1 = self.clear_response(html)
            response_2 = self.clear_response(html)

            self.tabs_widget.setCurrentIndex(0)

            self.x0h_output.setHtml(response_1)

            data0, data1, data2 = self.extract_plots(response_2)

            exchange_data = DataExchangeObject("XRAYSERVER", "X0H")
            exchange_data.add_content("reflectivity", data0)
            exchange_data.add_content("reflectivity_units_to_degrees", 1.0)
            exchange_data.add_content("x-ray_diffraction_profile_sigma", data1)
            exchange_data.add_content("x-ray_diffraction_profile_sigma_units_to_degrees", 0.000277777805)
            exchange_data.add_content("x-ray_diffraction_profile_pi", data2)
            exchange_data.add_content("x-ray_diffraction_profile_pi_units_to_degrees", 0.000277777805)

            self.send("xrayserver_data", exchange_data)


        except urllib.error.HTTPError as e:
            self.x0h_output.setHtml('The server couldn\'t fulfill the request.\nError Code: '
                                    + str(e.code) + "\n\n" +
                                    server.BaseHTTPRequestHandler.responses[e.code][1])

        except urllib.error.URLError as e:
            self.x0h_output.setHtml('We failed to reach a server.\nReason: '
                                    + e.reason)

        except XrayServerException as e:
            ShowHtmlDialog.show_html("X-ray Server Error", e.response, width=750, height=500, parent=self)

        except Exception as e:
            self.x0h_output.setHtml('We failed to reach a server.\nReason: '
                                    + str(e))

        self.tabs_widget.setCurrentIndex(0)
        self.setStatusMessage("")
        self.progressBarFinished()

    def submit(self):
        self.progressBarInit()
        self.setStatusMessage("Submitting Request")

        if platform.system() == 'Darwin':
            self.x0h_input.page().toHtml(self._callable_1)

        elif platform.system() == 'Linux':
            doc = self.x0h_input.page().mainFrame().documentElement()
            submit_btn = doc.findFirst("input[id=submit-btn]")

            try:
                response = ""
                #response = HttpManager.send_xray_server_request_POST(APPLICATION, parameters)
                response = self.clear_response(response)

                self.tabs_widget.setCurrentIndex(0)
                self.x0h_output.setHtml(response)

                data0, data1, data2 = self.extract_plots(response)

                exchange_data = DataExchangeObject("XRAYSERVER", "X0H")
                exchange_data.add_content("reflectivity", data0)
                exchange_data.add_content("reflectivity_units_to_degrees", 1.0)
                exchange_data.add_content("x-ray_diffraction_profile_sigma", data1)
                exchange_data.add_content("x-ray_diffraction_profile_sigma_units_to_degrees", 0.000277777805)
                exchange_data.add_content("x-ray_diffraction_profile_pi", data2)
                exchange_data.add_content("x-ray_diffraction_profile_pi_units_to_degrees", 0.000277777805)

                self.send("xrayserver_data", exchange_data)

                pass
            except urllib.error.HTTPError as e:
                self.x0h_output.setHtml('The server couldn\'t fulfill the request.\nError Code: '
                                        + str(e.code) + "\n\n" +
                                        server.BaseHTTPRequestHandler.responses[e.code][1])
                raise e

            except urllib.error.URLError as e:
                self.x0h_output.setHtml('We failed to reach a server.\nReason: '
                                        + e.reason)
                raise e

            except XrayServerException as e:
                ShowHtmlDialog.show_html("X-ray Server Error", e.response, width=750, height=500, parent=self)

                raise e
            except Exception as e:
                self.x0h_output.setHtml('We failed to reach a server.\nReason: '
                                        + str(e))

                raise e


            self.setStatusMessage("")
            self.progressBarFinished()

    def clear_response(self, response):

        print(response)

        # remove links
        output = response.split("<img src=\"images/x.gif\" width=\"31\" height=\"32\" border=\"0\">")[0] + "\n</body></html>"

        # remove "get the curve" images
        output = "".join(output.split("<input type=image src=\"images/get_the_curve.gif\" border=0 width=102 height=12 alt=\"Get the reflectivity curve\">"))
        output = "".join(output.split("<input type=image src=\"images/get_the_curve.gif\" border=0 width=102 height=12 alt=\"Get the Bragg curve (sigma)\">"))
        output = "".join(output.split("<input type=image src=\"images/get_the_curve.gif\" border=0 width=102 height=12 alt=\"Get the Bragg curve (pi)\">"))
        # remove question mark images and links
        output = "".join(output.split("<a  href=\"javascript:void(0)\" onClick=\"Wfloat(\'images/x0h_help_0.gif\',\'x0h_0\',740,357);\"><b>?</b></a> &nbsp;"))
        output = "".join(output.split("<a  href=\"javascript:void(0)\" onClick=\"Wfloat(\'images/x0h_help_h.gif\',\'x0h_h\',705,853);\"><b>?</b></a> &nbsp;"))

        temp_1, temp_2 = output.split("style.css")
        output = temp_1 + XRAY_SERVER_URL + "/style.css" + temp_2

        return output

    def extract_plots(self, response):
        form_1_begin = False
        form_2_begin = False
        form_3_begin = False

        form_1 = None
        form_2 = None
        form_3 = None

        rows = response.split("\n")

        for row in rows:
            if form_1_begin:
                if "<td>" in row:
                    form_1_begin = False
            elif form_2_begin:
                if "<td>" in row:
                    form_2_begin = False
            elif form_3_begin:
                if "<td>" in row:
                    form_3_begin = False

            if form_1_begin:
                form_1.append(row)
            elif form_2_begin:
                form_2.append(row)
            elif form_3_begin:
                form_3.append(row)

            if "/cgi/ter_form.pl" in row:
                if form_1 is None:
                    form_1 = []
                    form_1_begin = True

            if "/cgi/gid_form.pl" in row:
                if form_2 is None:
                    form_2 = []
                    form_2_begin = True
                elif form_3 is None:
                    form_3 = []
                    form_3_begin = True

        self.setStatusMessage("Plotting Results")

        if not form_1 is None:
            x_1, y_1 = self.get_plots_from_form("/cgi/ter_form.pl", form_1)

            self.plot_histo(x_1, y_1, 40, 1, 0, "Critical Angle for TER", "Incidence angle [degrees]", "Reflectivity")
            self.tabs_widget.setCurrentIndex(1)
        else:
            x_1 = None
            y_1 = None
            
        if not form_2 is None:
            x_2, y_2 = self.get_plots_from_form("/cgi/gid_form.pl", form_2)

            self.plot_histo(x_2, y_2, 60, 2, 1, "Darwin Curve ($\sigma$ Pol.)", "Scan Angle [arcsec]", "Diffracted Intensity")
            self.tabs_widget.setCurrentIndex(2)
        else:
            x_2 = None
            y_2 = None

        if not form_3 is None:
            x_3, y_3 = self.get_plots_from_form("/cgi/gid_form.pl", form_3)

            self.plot_histo(x_3, y_3, 80, 3, 2, "Darwin Curve ($\pi$ Pol.)", "Scan Angle [arcsec]", "Diffracted Intensity")
            self.tabs_widget.setCurrentIndex(3)
        else:
            x_3 = None
            y_3 = None

        return [x_1, y_1], [x_2, y_2], [x_3, y_3]