Beispiel #1
0
class IdialsInnerrWidget(QWidget):
    lst_commands = [
        "import", "find_spots", "index", "refine_bravais_settings", "reindex",
        "refine", "integrate", "export"
    ]

    def __init__(self, parent=None, dials_logo=None):
        super(IdialsInnerrWidget, self).__init__(parent)
        self.super_parent = parent
        self.controller = Controller(".")
        self.next_cmd = "import"
        self.failed = None

        if (self.super_parent.embedded_reindex):
            big_box = QHBoxLayout()
        else:
            big_box = QVBoxLayout()

        self.tree_nav = TreeNavWidget(self)
        big_box.addWidget(self.tree_nav)

        self.thrd = MyThread(self)  #, self.controller)
        self.thrd.set_controler(self.controller)
        self.thrd.std_handler.write_signal.connect(self.append_text)
        self.thrd.err_handler.write_signal.connect(self.err_append_text)
        self.thrd.started.connect(self.started_thread)
        self.thrd.finished.connect(self.finished_thread)

        self.setLayout(big_box)
        self.show()

    def _set_current_mode(self):
        print "...current.mode =", self.controller.get_current().name
        self.next_cmd = self.controller.get_current().name
        self.controller.set_mode(self.next_cmd)

    def goto(self, idx):
        print "goto: ", idx
        self.failed = None
        self.controller.goto(idx)
        #self._set_current_mode()
        self._update_tree()
        try:
            html_rep = self.controller.get_report()
        except:
            html_rep = None

        self.super_parent.jump(html_rep)
        self.update_info()
        # this is NOT the only place where self.update_info gets called

        from_david_trick = '''
        from dials.util.command_line import interactive_console; interactive_console(); 1/0
        '''

    def update_info(self):

        exp_json_path = None
        refl_pikl_path = None
        dblock_json_path = None

        try:
            dblock_json_path = self.controller.get_current().datablock
        except:
            print "failed to find << dblock_json_path >>"

        try:
            exp_json_path = self.controller.get_current().experiments
            print "exp_json_path =", exp_json_path

        except:
            print "failed to find << exp_json_path >>"

        try:
            refl_pikl_path = self.controller.get_current().reflections
        except:
            print "failed to find << refl_pikl_path >>"

        self.super_parent.info_widget.update_data(
            dblock_json_path=dblock_json_path,
            exp_json_path=exp_json_path,
            refl_pikl_path=refl_pikl_path)

        xb_p_siz = self.super_parent.info_widget.all_data.x_px_size
        yb_p_siz = self.super_parent.info_widget.all_data.y_px_size
        xb = self.super_parent.info_widget.all_data.xb
        yb = self.super_parent.info_widget.all_data.yb

        try:
            tmpl_str = self.super_parent.info_widget.all_data.tmpl_str
            print "\ntemplate ( from info_widget ) =", tmpl_str, "\n"
            title_str = "DUI/idials: " + tmpl_str
            self.super_parent.setWindowTitle(title_str)

        except:
            print "failed to << setWindowTitle >>"

        if (xb != None and yb != None and xb_p_siz != None
                and yb_p_siz != None):
            xb = xb / xb_p_siz
            yb = yb / yb_p_siz

        else:
            xb = None
            yb = None

        self.super_parent.output_wg.img_view.update_beam_centre(xb, yb)

    def prv_clicked(self):
        print "prv_clicked(self)"
        current = self.controller.get_current()
        previous = current.parent
        self.controller.goto(previous.index)
        self._set_current_mode()
        self._update_tree()

    def stop_clicked(self):
        #import os
        print "\n_____________ << Stopping >>_____________\n "

        my_process = self.thrd.to_run.state.command.external_command.command_run.process

        print "self.thrd.to_run.state.my_command.extr_comm_run.my_ext_cmd.cli_process =", my_process
        print "my_process.pid =", my_process.pid

        kill_child_processes(my_process.pid)

    def run_clicked(self):
        self.failed = None
        print "\n run_clicked(self)"
        print "Running ", self.next_cmd, "\n"
        self.controller.set_mode(self.next_cmd)
        if (self.controller.get_mode() == "import"):
            self.controller.reset_parameters()
            tmpl_str = "template=" + str(
                self.super_parent.widg_lst[0].templ_lin.text())
            print "tmpl_str =", tmpl_str, "\n"
            self.change_parameter(tmpl_str)

        self.thrd.start()

    def append_text(self, text):
        trim_cor_text = text[0:len(text) - 1]
        self.super_parent.txt_out.append_green(trim_cor_text)

        if (self.rtime_txt_on == True):
            self.super_parent.update_pbar_text(trim_cor_text)

    def err_append_text(self, text):
        trim_cor_text = text[0:len(text) - 1]
        self.super_parent.txt_out.append_red(trim_cor_text)

        if (self.rtime_txt_on == True):
            print "\n _____________________________________________________ err_append_text\n"
            print "text =<<", text, ">>"
            self.failed = True
            self.super_parent.update_pbar_text(trim_cor_text)

    def started_thread(self):
        self.super_parent.start_pbar_motion()

    def finished_thread(self):
        self._update_tree()

        print "\n _____________________________________________________finished_thread(self) \n"

        self.super_parent.update_after_command_end()

    def nxt_clicked(self):
        print "nxt_clicked(self)"
        last_mod = self.controller.get_current().name
        for pos, cmd in enumerate(self.lst_commands):
            if (cmd == last_mod):
                self.next_cmd = self.lst_commands[pos + 1]

        self.controller.set_mode(self.next_cmd)
        self._update_tree()

    def change_mode(self, new_mode):
        print "change_mode(self)"
        self.next_cmd = new_mode
        self.controller.set_mode(self.next_cmd)
        self._update_tree()

    def change_parameter(self, par_str):
        self.controller.set_parameters(par_str, short_syntax=True)

    def param_reset(self):
        print "\n reset_param for iDIALS \n\n"
        self.controller.reset_parameters()
        #print dir(self.controller), "\n"

    def _update_tree(self):

        history = self.controller.get_history()
        print "history =", history

        current = self.controller.get_current()
        print "current.success =", current.success

        lst_path_idx = [current.index]
        lst_path_cmd = [current.name]

        while current.index > 0:
            previous = current.parent

            lst_path_idx.insert(0, previous.index)
            lst_path_cmd.insert(0, previous.name)

            current = previous

        self.tree_nav.update_me(current, lst_path_idx)

        updt_str = " Click the Dials icon to run >> " + self.controller.get_mode(
        )
        print updt_str
        self.super_parent.update_pbar_text(updt_str)
Beispiel #2
0
class MainWidget(QWidget):
    lst_commands = [
        "import", "find_spots", "index", "refine_bravais_settings", "reindex",
        "refine", "integrate", "export"
    ]

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

        self.controller = Controller(".")
        self.next_cmd = "import"

        big_vbox = QVBoxLayout()

        self.btn_up = QPushButton('\n    Up  \n', self)
        self.btn_up.clicked.connect(self.up_clicked)
        big_vbox.addWidget(self.btn_up)

        midl_hbox = QHBoxLayout()

        self.btn_prv = QPushButton('\n  Prev \n', self)
        self.btn_prv.clicked.connect(self.prv_clicked)
        midl_hbox.addWidget(self.btn_prv)

        self.btn_go = QPushButton('\n    Go/Next  \n', self)
        self.btn_go.clicked.connect(self.go_clicked)
        midl_hbox.addWidget(self.btn_go)

        tmp_off = '''
        self.btn_nxt =  QPushButton('\n  Next \n', self)
        self.btn_nxt.clicked.connect(self.nxt_clicked)
        midl_hbox.addWidget(self.btn_nxt)
        '''
        big_vbox.addLayout(midl_hbox)

        self.btn_dwn = QPushButton('\n  Down \n', self)
        self.btn_dwn.clicked.connect(self.dwn_clicked)
        big_vbox.addWidget(self.btn_dwn)

        self.setLayout(big_vbox)
        self.setWindowTitle('Shell dialog')
        self.show()

    def up_clicked(self):
        print "up_clicked"
        print "self.curr_lin =", self.curr_lin
        self.controller.goto(self.lst_line_number[self.curr_lin - 2])
        print "...current.mode =", self.controller.get_current().name
        #self._update_tree()
        self.nxt_clicked()

    def dwn_clicked(self):
        print "dw_clicked"
        print "self.curr_lin =", self.curr_lin
        self.controller.goto(self.lst_line_number[self.curr_lin])
        print "...current.mode =", self.controller.get_current().name
        #self._update_tree()
        self.nxt_clicked()

    def go_clicked(self):
        print "go_clicked(self)"
        print "Running ", self.next_cmd

        self.controller.set_mode(self.next_cmd)

        if (self.controller.get_mode() == "import"):
            self.controller.set_parameters(
                "template=../X4_wide_M1S4_2_####.cbf", short_syntax=True)
            #self.controller.set_parameters("template=../th_8_2_####.cbf", short_syntax=True)

        self.controller.run(stdout=sys.stdout, stderr=sys.stderr).wait()
        #self._update_tree()
        self.nxt_clicked()

    def nxt_clicked(self):
        print "nxt_clicked(self)"

        last_mod = self.controller.get_current().name
        #print "last_mod =<<<", last_mod, ">>>"
        for pos, cmd in enumerate(self.lst_commands):
            if (cmd == last_mod):
                self.next_cmd = self.lst_commands[pos + 1]

        self.controller.set_mode(self.next_cmd)
        self._update_tree()

    def prv_clicked(self):
        print "prv_clicked(self)"

        mod_now = self.controller.get_current().name
        for pos, cmd in enumerate(self.lst_commands):
            if (cmd == mod_now):
                prev_mod = self.lst_commands[pos - 1]

        #print "mode to search = ", prev_mod

        tmp_curr_lin = self.curr_lin
        while True:
            tmp_curr_lin -= 1
            if (self.lst_usr_cmd[tmp_curr_lin] == prev_mod):
                self.controller.goto(self.lst_line_number[tmp_curr_lin])
                break

        self.nxt_clicked()

    def _update_tree(self):

        history = self.controller.get_history()
        print "history =", history
        self.lst_line_number = []

        self.lst_usr_cmd = []

        for lst_num, single_line in enumerate(history.split("\n")):
            lst_data = single_line.lstrip().split(" ")

            #print "lst_data =", lst_data

            if (len(lst_data) >= 3):
                line_number = int(lst_data[0])
                self.lst_line_number.append(line_number)
                if (lst_data[len(lst_data) - 1] == "(current)"):
                    self.curr_lin = lst_num
                    uncut_str = lst_data[len(lst_data) - 2]

                else:
                    uncut_str = lst_data[len(lst_data) - 1]

                usr_cmd = uncut_str[3:]
                self.lst_usr_cmd.append(usr_cmd)
        '''
        print "lst_usr_cmd ="
        print self.lst_usr_cmd
        '''
        print
        print "<<<========== Ready to run:", self.controller.get_mode()