Exemplo n.º 1
0
    def __init__(self):
        super(MainWidget, self).__init__()

        try:
            with open('bkp.pickle', 'rb') as bkp_in:
                self.uni_controler = pickle.load(bkp_in)

        except:
            self.uni_controler = Runner()

        self.cli_tree_output = TreeShow()
        self.cli_tree_output(self.uni_controler)

        self.cur_html = None
        self.cur_pick = None
        self.cur_json = None

        main_box = QVBoxLayout()

        h_main_splitter = QSplitter()
        h_main_splitter.setOrientation(Qt.Horizontal)

        self.tree_out = TreeNavWidget()
        self.tree_out.clicked[QModelIndex].connect(self.item_clicked)
        self.tree_out.update_me(self.uni_controler.step_list[0],
                                self.uni_controler.current)

        h_main_splitter.addWidget(self.tree_out)

        self.centre_widget = CentreWidget()
        self.centre_widget.run_btn.clicked.connect(self.run_clicked)
        h_main_splitter.addWidget(self.centre_widget)

        self.cli_out = CliOutView()
        self.web_view = WebTab()
        self.img_view = MyImgWin()

        self.my_tabs = QTabWidget()
        self.my_tabs.addTab(self.img_view, "Image View")
        self.my_tabs.addTab(self.cli_out, "CLI Output")
        self.my_tabs.addTab(self.web_view, "Report View")

        h_main_splitter.addWidget(self.my_tabs)

        main_box.addWidget(h_main_splitter)

        self.custom_thread = MyThread()
        self.custom_thread.finished.connect(self.update_after_finished)
        self.custom_thread.str_print_signal.connect(self.cli_out.add_txt)

        self.main_widget = QWidget()
        self.main_widget.setLayout(main_box)
        self.setCentralWidget(self.main_widget)
Exemplo n.º 2
0
    def __init__(self, parent=None):
        super(outputs_widget, self).__init__()
        self.super_parent = parent

        #FIXME remember the upper case convention with class names

        my_box = QVBoxLayout()
        self.my_tabs = QTabWidget()

        #self.img_view = MyImgWin("/home/luiso/dui/dui_test/only_9_img/dui_idials_tst_01/dials-1/1_import/datablock.json")
        self.img_view = MyImgWin()

        self.web_view = WebTab()
        self.in_txt_out = TextOut()

        self.my_tabs.addTab(self.img_view, "Image View")
        self.my_tabs.addTab(self.in_txt_out, "Log View")
        self.my_tabs.addTab(self.web_view, "Report View")

        if (self.super_parent.embedded_reindex == False):
            #TODO make sure consistent the way to use the "super_parent" reference in the next line
            self.reindex_tool = MyReindexOpts(parent)

        my_box.addWidget(self.my_tabs)

        to_remove = '''
        self.pref_tab_pos = self.img_view
        self.my_tabs.currentChanged.connect(self.tab_changed)
        '''

        self.setLayout(my_box)
        self.show()

        to_remove = '''
Exemplo n.º 3
0
    def __init__(self):
        super(MainWidget, self).__init__()

        self.my_pop = None  # Any child popup windows. Only bravais_table ATM
        self.storage_path = sys_arg.directory

        refresh_gui = False

        # Load the previous state of DUI, if present
        dui_files_path = os.path.join(self.storage_path, "dui_files")

        if os.path.isfile(os.path.join(dui_files_path, "bkp.pickle")):
            try:
                self.idials_runner = load_previous_state(dui_files_path)

            except Exception as e:
                # Something went wrong - tell the user then close
                msg = traceback.format_exc()
                logger.error("ERROR LOADING PREVIOUS DATA:\n%s", msg)
                raise_from(DUIDataLoadingError(msg), e)

            refresh_gui = True
        else:
            # No dui_files path - start with a fresh state
            if not os.path.isdir(dui_files_path):
                os.mkdir(dui_files_path)

            self.idials_runner = Runner()

        self.gui2_log = {"pairs_list": []}

        self.cli_tree_output = TreeShow()
        self.cli_tree_output(self.idials_runner)

        self.cur_html = None
        self.cur_pick = None
        self.cur_json = None
        self.cur_log = None
        self.cur_cmd_name = "None"

        main_box = QVBoxLayout()

        self.centre_par_widget = ControlWidget()
        self.centre_par_widget.pass_sys_arg_object_to_import(sys_arg)
        self.stop_run_retry = StopRunRetry()
        self.tree_out = TreeNavWidget()

        left_control_box = QHBoxLayout()

        left_top_control_box = QVBoxLayout()
        left_top_control_box.addWidget(self.centre_par_widget)
        left_top_control_box.addStretch()
        left_control_box.addLayout(left_top_control_box)

        centre_control_box = QVBoxLayout()

        v_control_splitter = QSplitter()
        v_control_splitter.setOrientation(Qt.Vertical)
        v_control_splitter.addWidget(self.tree_out)
        v_control_splitter.addWidget(self.centre_par_widget.step_param_widg)

        centre_control_box.addWidget(v_control_splitter)
        centre_control_box.addWidget(self.stop_run_retry)
        left_control_box.addLayout(centre_control_box)

        dummy_left_widget = QWidget()
        dummy_h_layout = QHBoxLayout()
        dummy_h_layout.addLayout(left_control_box)
        dummy_left_widget.setLayout(dummy_h_layout)
        dummy_left_widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

        h_main_splitter = QSplitter()
        h_main_splitter.setOrientation(Qt.Horizontal)
        h_main_splitter.addWidget(dummy_left_widget)

        self.cli_out = CliOutView()
        self.web_view = WebTab()
        self.img_view = MyImgWin()
        self.ext_view = OuterCaller()
        self.info_widget = InfoWidget()

        self.output_info_tabs = QTabWidget()
        self.output_info_tabs.addTab(self.img_view, "Image")
        self.output_info_tabs.addTab(self.cli_out, "Log")
        self.output_info_tabs.addTab(self.web_view, "Report")
        self.output_info_tabs.addTab(self.ext_view, "Tools")
        self.output_info_tabs.addTab(self.info_widget, "Experiment")

        self.view_tab_num = 0
        self.output_info_tabs.currentChanged.connect(self.tab_changed)

        self.img_view.mask_applied.connect(self.pop_mask_list)
        self.img_view.predic_changed.connect(self.tab_changed)
        self.img_view.bc_applied.connect(self.pop_b_centr_coord)

        self.img_view.new_pars_applied.connect(self.pass_parmams)

        # self.ext_view.pass_parmam_lst.connect(self.pass_parmams)

        self.centre_par_widget.finished_masking.connect(self.img_view.unchec_my_mask)
        self.centre_par_widget.click_mask.connect(self.img_view.chec_my_mask)
        self.centre_par_widget.finished_b_centr.connect(self.img_view.unchec_b_centr)
        self.centre_par_widget.click_b_centr.connect(self.img_view.chec_b_centr)

        v_info_splitter = QSplitter()
        v_info_splitter.setOrientation(Qt.Vertical)
        v_info_splitter.addWidget(self.output_info_tabs)

        h_main_splitter.addWidget(v_info_splitter)

        main_box.addWidget(h_main_splitter)

        self.txt_bar = Text_w_Bar()
        main_box.addWidget(self.txt_bar)

        self.connect_all()

        self.custom_thread = CommandThread()
        self.custom_thread.finished.connect(self.update_after_finished)
        self.custom_thread.str_fail_signal.connect(self.after_failed)
        self.custom_thread.str_print_signal.connect(self.cli_out.add_txt)
        self.custom_thread.str_print_signal.connect(self.txt_bar.setText)

        self.custom_thread.busy_box_on.connect(self.pop_busy_box)
        self.custom_thread.busy_box_off.connect(self.close_busy_box)

        self.main_widget = QWidget()
        self.main_widget.setLayout(main_box)
        self.setCentralWidget(self.main_widget)

        self.setWindowTitle("CCP4 DUI - {}: {}".format(__version__,
                dui_files_path))
        self.setWindowIcon(QIcon(self.stop_run_retry.dials_logo_path))

        self.just_reindexed = False
        self.user_stoped = False
        self.reconnect_when_ready()

        self.my_pop = None

        if refresh_gui:
            self.refresh_my_gui()
Exemplo n.º 4
0
class MainWidget(QMainWindow):
    def __init__(self):
        super(MainWidget, self).__init__()

        self.my_pop = None  # Any child popup windows. Only bravais_table ATM
        self.storage_path = sys_arg.directory

        refresh_gui = False

        # Load the previous state of DUI, if present
        dui_files_path = os.path.join(self.storage_path, "dui_files")

        if os.path.isfile(os.path.join(dui_files_path, "bkp.pickle")):
            try:
                self.idials_runner = load_previous_state(dui_files_path)

            except Exception as e:
                # Something went wrong - tell the user then close
                msg = traceback.format_exc()
                logger.error("ERROR LOADING PREVIOUS DATA:\n%s", msg)
                raise_from(DUIDataLoadingError(msg), e)

            refresh_gui = True
        else:
            # No dui_files path - start with a fresh state
            if not os.path.isdir(dui_files_path):
                os.mkdir(dui_files_path)

            self.idials_runner = Runner()

        self.gui2_log = {"pairs_list": []}

        self.cli_tree_output = TreeShow()
        self.cli_tree_output(self.idials_runner)

        self.cur_html = None
        self.cur_pick = None
        self.cur_json = None
        self.cur_log = None
        self.cur_cmd_name = "None"

        main_box = QVBoxLayout()

        self.centre_par_widget = ControlWidget()
        self.centre_par_widget.pass_sys_arg_object_to_import(sys_arg)
        self.stop_run_retry = StopRunRetry()
        self.tree_out = TreeNavWidget()

        left_control_box = QHBoxLayout()

        left_top_control_box = QVBoxLayout()
        left_top_control_box.addWidget(self.centre_par_widget)
        left_top_control_box.addStretch()
        left_control_box.addLayout(left_top_control_box)

        centre_control_box = QVBoxLayout()

        v_control_splitter = QSplitter()
        v_control_splitter.setOrientation(Qt.Vertical)
        v_control_splitter.addWidget(self.tree_out)
        v_control_splitter.addWidget(self.centre_par_widget.step_param_widg)

        centre_control_box.addWidget(v_control_splitter)
        centre_control_box.addWidget(self.stop_run_retry)
        left_control_box.addLayout(centre_control_box)

        dummy_left_widget = QWidget()
        dummy_h_layout = QHBoxLayout()
        dummy_h_layout.addLayout(left_control_box)
        dummy_left_widget.setLayout(dummy_h_layout)
        dummy_left_widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

        h_main_splitter = QSplitter()
        h_main_splitter.setOrientation(Qt.Horizontal)
        h_main_splitter.addWidget(dummy_left_widget)

        self.cli_out = CliOutView()
        self.web_view = WebTab()
        self.img_view = MyImgWin()
        self.ext_view = OuterCaller()
        self.info_widget = InfoWidget()

        self.output_info_tabs = QTabWidget()
        self.output_info_tabs.addTab(self.img_view, "Image")
        self.output_info_tabs.addTab(self.cli_out, "Log")
        self.output_info_tabs.addTab(self.web_view, "Report")
        self.output_info_tabs.addTab(self.ext_view, "Tools")
        self.output_info_tabs.addTab(self.info_widget, "Experiment")

        self.view_tab_num = 0
        self.output_info_tabs.currentChanged.connect(self.tab_changed)

        self.img_view.mask_applied.connect(self.pop_mask_list)
        self.img_view.predic_changed.connect(self.tab_changed)
        self.img_view.bc_applied.connect(self.pop_b_centr_coord)

        self.img_view.new_pars_applied.connect(self.pass_parmams)

        # self.ext_view.pass_parmam_lst.connect(self.pass_parmams)

        self.centre_par_widget.finished_masking.connect(self.img_view.unchec_my_mask)
        self.centre_par_widget.click_mask.connect(self.img_view.chec_my_mask)
        self.centre_par_widget.finished_b_centr.connect(self.img_view.unchec_b_centr)
        self.centre_par_widget.click_b_centr.connect(self.img_view.chec_b_centr)

        v_info_splitter = QSplitter()
        v_info_splitter.setOrientation(Qt.Vertical)
        v_info_splitter.addWidget(self.output_info_tabs)

        h_main_splitter.addWidget(v_info_splitter)

        main_box.addWidget(h_main_splitter)

        self.txt_bar = Text_w_Bar()
        main_box.addWidget(self.txt_bar)

        self.connect_all()

        self.custom_thread = CommandThread()
        self.custom_thread.finished.connect(self.update_after_finished)
        self.custom_thread.str_fail_signal.connect(self.after_failed)
        self.custom_thread.str_print_signal.connect(self.cli_out.add_txt)
        self.custom_thread.str_print_signal.connect(self.txt_bar.setText)

        self.custom_thread.busy_box_on.connect(self.pop_busy_box)
        self.custom_thread.busy_box_off.connect(self.close_busy_box)

        self.main_widget = QWidget()
        self.main_widget.setLayout(main_box)
        self.setCentralWidget(self.main_widget)

        self.setWindowTitle("CCP4 DUI - {}: {}".format(__version__,
                dui_files_path))
        self.setWindowIcon(QIcon(self.stop_run_retry.dials_logo_path))

        self.just_reindexed = False
        self.user_stoped = False
        self.reconnect_when_ready()

        self.my_pop = None

        if refresh_gui:
            self.refresh_my_gui()

    def pop_mask_list(self, mask_itm_lst):

        tmp_cmd_lst = build_mask_command_lst(mask_itm_lst)

        self.centre_par_widget.mask_page.set_par(tmp_cmd_lst)
        self.centre_par_widget.step_param_widg.setCurrentWidget(
            self.centre_par_widget.mask_page
        )

    def pop_b_centr_coord(self, new_b_centr):
        logger.info("New b_centr =", new_b_centr)
        self.centre_par_widget.b_centr_page.set_par(new_b_centr)
        self.centre_par_widget.step_param_widg.setCurrentWidget(
            self.centre_par_widget.b_centr_page
        )

    def connect_all(self):
        self.setCursor(Qt.ArrowCursor)
        self.tree_clickable = True
        self.tree_out.clicked[QModelIndex].connect(self.node_clicked)

        self.stop_run_retry.repeat_btn.clicked.connect(self.rep_clicked)
        self.stop_run_retry.run_btn.clicked.connect(self.run_clicked)
        self.stop_run_retry.stop_btn.clicked.connect(self.stop_clicked)

        self.centre_par_widget.user_changed.connect(self.cmd_changed_by_user)
        self.centre_par_widget.update_command_lst_high_level.connect(
            self.update_low_level_command_lst
        )
        self.centre_par_widget.step_param_widg.currentChanged.connect(
            self.cmd_changed_by_any
        )
        self.check_gray_outs()

    def disconnect_while_running(self):

        self.setCursor(Qt.BusyCursor)
        self.tree_clickable = False

        self.stop_run_retry.repeat_btn.setEnabled(False)
        self.stop_run_retry.run_btn.setEnabled(False)
        self.stop_run_retry.stop_btn.setEnabled(True)
        self.centre_par_widget.gray_outs_all()
        self.centre_par_widget.step_param_widg.currentWidget().my_widget.gray_me_out()

        self.user_stoped = False

    def reconnect_when_ready(self):

        self.setCursor(Qt.ArrowCursor)
        self.tree_clickable = True

        self.stop_run_retry.repeat_btn.setEnabled(False)
        self.stop_run_retry.stop_btn.setEnabled(False)
        self.stop_run_retry.run_btn.setEnabled(False)

        if self.user_stoped:
            self.idials_runner.current_node.success = None

        my_widget = self.centre_par_widget.step_param_widg.currentWidget().my_widget
        if self.idials_runner.current_node.success is None:
            self.stop_run_retry.run_btn.setEnabled(True)
            my_widget.activate_me(cur_nod=self.idials_runner.current_node)

        else:
            if self.idials_runner.current_node.ll_command_lst[0][0] != "export":
                self.stop_run_retry.repeat_btn.setEnabled(True)

            my_widget.gray_me_out()

        if self.idials_runner.current_node.ll_command_lst[0][0] == "reindex":
            self.stop_run_retry.run_btn.setEnabled(False)
            self.stop_run_retry.repeat_btn.setEnabled(False)

        self.check_gray_outs()
        self.user_stoped = False
        self.update_nav_tree()

    def chouse_if_predict_or_report(self):
        if (
            self.idials_runner.current_node.ll_command_lst[0][0]
            != "refine_bravais_settings"
        ):
            if self.view_tab_num == 0 and self.img_view.rad_but_pre_hkl.checkState():
                self.pop_busy_box(text_in_bar="Generating Predictions")
                self.idials_runner.current_node.gen_repr_n_pred(to_run="predict")
                self.close_busy_box()

            elif self.view_tab_num == 2:
                """
                ##########################################################################
                tmp_bar = ProgBarBox(min_val=0, max_val=10, text=text_in_bar)
                tmp_bar(5)
                tmp_bar.ended()
                ################################################################################
                """

                tmp_bar = ProgBarBox(min_val=0, max_val=10, text="Generating Report")
                tmp_bar(5)
                self.idials_runner.current_node.gen_repr_n_pred(to_run="report")
                tmp_bar.ended()

    def tab_changed(self, num=0):
        self.view_tab_num = num
        self.chouse_if_predict_or_report()

        update_info(self)

    def pass_parmams(self, cmd_lst):
        """(We've been passed a parameter by the external tool signal)"""

        current_parameter_widget = (
            self.centre_par_widget.step_param_widg.currentWidget()
        )
        action_name = current_parameter_widget.my_widget.command_lst[0][0]

        to_remove = """
        if (
            action_name in ["find_spots", "integrate"]
            and self.idials_runner.current_node.success is None
        ):
        """

        if (
            action_name == "find_spots"
            and self.idials_runner.current_node.success is None
        ):

            gain = cmd_lst[0]
            size = cmd_lst[1]
            nsig_b = cmd_lst[2]
            nsig_s = cmd_lst[3]
            global_threshold = cmd_lst[4]
            min_count = cmd_lst[5]

            full_command = [
                "find_spots",
                "spotfinder.threshold.dispersion.gain=" + str(gain),
                "spotfinder.threshold.dispersion.kernel_size="
                + str(size[0])
                + ","
                + str(size[1]),
                "spotfinder.threshold.dispersion.sigma_background=" + str(nsig_b),
                "spotfinder.threshold.dispersion.sigma_strong=" + str(nsig_s),
                "spotfinder.threshold.dispersion.min_local=" + str(min_count),
                "spotfinder.threshold.dispersion.global_threshold="
                + str(global_threshold),
            ]

            current_parameter_widget.my_widget.update_param_w_lst(full_command)

        else:
            logger.debug("No need to feed back params")
            """
            logger.info(
                "my_widget_now.my_widget.command_lst = %s",
                current_parameter_widget.my_widget.command_lst,
            )
            """

    def update_low_level_command_lst(self, command_lst):
        self.idials_runner.current_node.ll_command_lst = command_lst
        self.reconnect_when_ready()

    def cmd_changed_by_user(self, my_label):
        logger.debug("cmd_changed_by_user()")
        tmp_curr = self.idials_runner.current_node
        if tmp_curr.success is True:
            self.cmd_exe(["mkchi"])
            self.idials_runner.current_node.ll_command_lst = [[str(my_label)]]
            self.centre_par_widget.step_param_widg.currentWidget().my_widget.reset_par()

            path_to_mask_pickle = None
            if self.idials_runner.current_node.ll_command_lst[0][0] == "integrate":
                logger.debug("Running: try_find_prev_mask_pickle")
                path_to_mask_pickle = try_find_prev_mask_pickle(
                    self.idials_runner.current_node
                )
                if path_to_mask_pickle is not None:
                    self.pass_parmams(["lookup.mask=" + path_to_mask_pickle])

            self.cmd_exe(["clean"])

        elif tmp_curr.success is None:
            self.idials_runner.current_node.ll_command_lst[0] = [str(my_label)]
            self.reconnect_when_ready()

    def cmd_changed_by_any(self):
        tmp_curr_widg = self.centre_par_widget.step_param_widg.currentWidget()
        self.cur_cmd_name = tmp_curr_widg.my_widget.command_lst[0][0]
        self.reconnect_when_ready()

    def rep_clicked(self):
        logger.debug("rep_clicked")
        self.cmd_exe(["mksib"])
        self.cmd_exe(["clean"])
        self.check_gray_outs()

    def stop_clicked(self):
        logger.debug("\n\n <<< Stop clicked >>> \n\n")
        # TODO fix spelling on << dials_command >>
        pr_to_kill = self.idials_runner.current_node.dials_command.my_pid
        logger.debug(
            "self.idials_runner.current_node.dials_command.my_pid = %s", pr_to_kill
        )
        self.user_stoped = True
        kill_w_child(pr_to_kill)

    def run_clicked(self):
        logger.debug("run_clicked")
        logger.debug(
            "...currentWidget(ref) = %s",
            self.centre_par_widget.step_param_widg.currentWidget(),
        )

        self.img_view.draw_img_img()

        cmd_tmp = (
            self.centre_par_widget.step_param_widg.currentWidget().my_widget.command_lst
        )
        self.cmd_launch(cmd_tmp)

    def cmd_exe(self, new_cmd):
        # Running NOT in parallel
        update_info(self)
        self.idials_runner.run(command=new_cmd, ref_to_class=None)
        self.check_reindex_pop()
        self.reconnect_when_ready()

    def cmd_launch(self, new_cmd):
        # Running WITH threading
        self.cli_out.clear()
        self.cli_out.make_green()
        self.txt_bar.start_motion()
        self.txt_bar.setText("Running")
        self.disconnect_while_running()
        self.custom_thread(new_cmd, self.idials_runner)

    def update_after_finished(self):
        self.chouse_if_predict_or_report()
        update_info(self)

        self.txt_bar.end_motion()
        self.just_reindexed = False

        tmp_curr = self.idials_runner.current_node

        prn_lst_lst_cmd(tmp_curr)

        if (
            tmp_curr.ll_command_lst[0][0] == "refine_bravais_settings"
            and tmp_curr.success is True
        ):
            self.idials_runner.run(command=["mkchi"], ref_to_class=None)
            self.idials_runner.current_node.ll_command_lst = [["reindex"]]

        elif tmp_curr.ll_command_lst[0][0] == "reindex" and tmp_curr.success is True:

            self.just_reindexed = True
            try:
                self.my_pop.close()
            except BaseException as e:
                # We don't want to catch bare exceptions but don't know
                # what this was supposed to catch. Log it.
                logger.debug(
                    "Caught unknown exception type %s: %s", type(e).__name__, e
                )
                logger.debug("no need to close reindex table")

        elif tmp_curr.ll_command_lst[0][0] == "export" and tmp_curr.success is True:
            self.gui2_log = try_move_last_info(tmp_curr, self.gui2_log)

        self.check_reindex_pop()
        self.check_gray_outs()
        self.reconnect_when_ready()

        if (
            tmp_curr.ll_command_lst[0][0] == "generate_mask"
            and tmp_curr.success is True
        ):
            self.img_view.my_painter.reset_mask_tool(None)

        elif (
            tmp_curr.ll_command_lst[0][0] == "modify_geometry"
            and tmp_curr.success is True
        ):
            self.img_view.my_painter.reset_bc_tool(None)

        with open(self.storage_path + "/dui_files/bkp.pickle", "wb") as bkp_out:
            pickle.dump(self.idials_runner, bkp_out)

    def pop_busy_box(self, text_in_bar):
        #logger.info("OPENING busy pop bar with the text: ", text_in_bar)
        if (
            self.idials_runner.current_node.ll_command_lst[0][0]
            != "refine_bravais_settings"
        ):
            self.my_bar = ProgBarBox(min_val=0, max_val=10, text=text_in_bar)
            self.my_bar(5)

    def close_busy_box(self):
        logger.info("trying to close busy pop bar")
        try:
            self.my_bar.ended()

        except AttributeError:
            logger.info("no need to close busy pop bar")

    def check_gray_outs(self):
        tmp_curr = self.idials_runner.current_node
        if tmp_curr.success is not True:
            tmp_curr = tmp_curr.prev_step

        # TODO fix "generate_mask" and "modify_geometry" : it should be the same as the previous step

        # This dictionary defines which tasks can be performed at each step and
        # which should be grayed out
        cmd_connects = {
            "Root": ["import"],
            "import": ["find_spots"],
            "find_spots": ["index"],
            "index": ["refine_bravais_settings", "refine", "integrate"],
            "refine_bravais_settings": [None],
            "reindex": ["refine", "integrate", "index"],
            "refine": [
                "refine_bravais_settings",
                "refine",
                "integrate",
                "index",
            ],
            "integrate": ["symmetry", "scale", "export", "index", "export"],
            "symmetry": ["refine_bravais_settings", "scale", "export"],
            "scale": ["refine_bravais_settings", "symmetry", "export"],
            "export": [None],
            "generate_mask": ["find_spots"],
            "modify_geometry": ["find_spots"],
            "None": [None],
        }

        more_conservative = """
        cmd_connects = {
            "Root": ["import"],
            "import": ["find_spots"],
            "find_spots": ["index"],
            "index": ["refine_bravais_settings", "refine", "integrate"],
            "refine_bravais_settings": [None],
            "reindex": ["refine", "integrate"],
            "refine": ["refine_bravais_settings", "refine", "integrate"],
            "integrate": ["symmetry", "scale", "export"],
            "symmetry": ["scale", "export"],
            "scale": ["symmetry", "export"],
            "export": [None],
            "generate_mask": ["find_spots"],
            "modify_geometry":["find_spots"],
            "None": [None],
        }
        """

        lst_nxt = cmd_connects[str(tmp_curr.ll_command_lst[0][0])]
        self.centre_par_widget.gray_outs_from_lst(lst_nxt)

    def check_reindex_pop(self):
        tmp_curr = self.idials_runner.current_node
        #logger.info("\n_________________________ check_reindex_pop 01 \n")
        if tmp_curr.ll_command_lst[0][0] == "reindex" and not self.just_reindexed:
            #logger.info("\n_________________________ check_reindex_pop 02 \n")

            try:
                self.my_pop = MyReindexOpts()
                self.my_pop.set_ref(
                    in_json_path=tmp_curr.prev_step.json_file_out,
                    lin_num=tmp_curr.prev_step.lin_num,
                )
                self.my_pop.my_inner_table.opt_signal.connect(self.opt_dobl_clicked)

            except Exception as my_err:
                logger.info("ERROR in check_reindex_pop(m_idials_gui) \n")
                logger.info("str(my_err) = ", str(my_err))
                logger.info("my_err.__doc__ = ", my_err.__doc__)
                logger.info("my_err.message = ", my_err.message)

            # TODO find an elegant way to interrupt and remove nodes

        else:
            try:
                self.my_pop.close()
            except BaseException as e:
                # We don't want to catch bare exceptions but don't know
                # what this was supposed to catch. Log it.
                logger.debug(
                    "Caught unknown exception type %s: %s", type(e).__name__, e
                )
                logger.debug("no need to close reindex table")

        self.just_reindexed = False

    def update_nav_tree(self):
        self.tree_out.update_me(
            self.idials_runner.step_list[0], self.idials_runner.current_line
        )
        update_pbar_msg(self)
        self.img_view.my_painter.repaint()

    def after_failed(self):
        logger.info("\n FAILED STEP:")
        self.update_nav_tree()
        self.txt_bar.end_motion()

        curr_step = self.idials_runner.current_node

        for err_lin in curr_step.dials_command.tmp_std_all:
            logger.debug(err_lin)

        err_log_file_out = (
            self.storage_path
            + "/dui_files"
            + os.sep
            + str(curr_step.lin_num)
            + "_err_out.log"
        )

        logger.info("\n ERROR \n err_log_file_out = %s %s", err_log_file_out, "\n")

        fil_obj = open(err_log_file_out, "w")
        for err_lin in curr_step.dials_command.tmp_std_all:
            fil_obj.write(err_lin)
            fil_obj.write("\n")

        fil_obj.close()
        self.idials_runner.current_node.err_file_out = err_log_file_out

    def opt_dobl_clicked(self, row):
        re_idx = row + 1
        logger.debug("Solution clicked = %s", re_idx)
        cmd_tmp = ["reindex", "solution=" + str(re_idx)]
        self.cmd_launch([cmd_tmp])

    def node_clicked(self, it_index):

        logger.debug("\n it_index = %s", it_index)
        logger.debug(" type(it_index) = %s", type(it_index))

        if self.tree_clickable:
            # TODO Think of a more robust way to "disconnect" ... next line
            try:
                self.centre_par_widget.update_command_lst_high_level.disconnect(
                    self.update_low_level_command_lst
                )
            except BaseException as e:
                # We don't want to catch bare exceptions but don't know
                # what this was supposed to catch. Log it.
                logger.info(" Caught unknown exception type %s: %s", type(e).__name__, e)
                logger.info("\n Tst A1 \n")

            item = self.tree_out.std_mod.itemFromIndex(it_index)
            prn_lst_lst_cmd(item.idials_node)
            lin_num = item.idials_node.lin_num
            cmd_ovr = "goto " + str(lin_num)
            self.cmd_exe(cmd_ovr)

            self.centre_par_widget.set_widget(
                nxt_cmd=item.idials_node.ll_command_lst[0][0],
                curr_step=self.idials_runner.current_node,
            )

            self.check_reindex_pop()

            self.chouse_if_predict_or_report()
            update_info(self)

            self.check_gray_outs()
            self.reconnect_when_ready()

            self.centre_par_widget.update_command_lst_high_level.connect(
                self.update_low_level_command_lst
            )

    def refresh_my_gui(self):

        lin_num = self.idials_runner.current_node.lin_num
        logger.debug("doing goto:  %s", lin_num)
        cmd_ovr = "goto " + str(lin_num)
        self.cmd_exe(cmd_ovr)
        self.centre_par_widget.set_widget(
            nxt_cmd=self.idials_runner.current_node.ll_command_lst[0][0],
            curr_step=self.idials_runner.current_node,
        )

        self.check_reindex_pop()
        self.chouse_if_predict_or_report()
        update_info(self)
        self.check_gray_outs()
        self.reconnect_when_ready()

        logger.info("\n ... recovering from previous run of GUI \n")

    def closeEvent(self, event):
        if self.my_pop:
            self.my_pop.close()
Exemplo n.º 5
0
class MainWidget(QMainWindow):
    def __init__(self):
        super(MainWidget, self).__init__()

        try:
            with open('bkp.pickle', 'rb') as bkp_in:
                self.uni_controler = pickle.load(bkp_in)

        except:
            self.uni_controler = Runner()

        self.cli_tree_output = TreeShow()
        self.cli_tree_output(self.uni_controler)

        self.cur_html = None
        self.cur_pick = None
        self.cur_json = None

        main_box = QVBoxLayout()

        h_main_splitter = QSplitter()
        h_main_splitter.setOrientation(Qt.Horizontal)

        self.tree_out = TreeNavWidget()
        self.tree_out.clicked[QModelIndex].connect(self.item_clicked)
        self.tree_out.update_me(self.uni_controler.step_list[0],
                                self.uni_controler.current)

        h_main_splitter.addWidget(self.tree_out)

        self.centre_widget = CentreWidget()
        self.centre_widget.run_btn.clicked.connect(self.run_clicked)
        h_main_splitter.addWidget(self.centre_widget)

        self.cli_out = CliOutView()
        self.web_view = WebTab()
        self.img_view = MyImgWin()

        self.my_tabs = QTabWidget()
        self.my_tabs.addTab(self.img_view, "Image View")
        self.my_tabs.addTab(self.cli_out, "CLI Output")
        self.my_tabs.addTab(self.web_view, "Report View")

        h_main_splitter.addWidget(self.my_tabs)

        main_box.addWidget(h_main_splitter)

        self.custom_thread = MyThread()
        self.custom_thread.finished.connect(self.update_after_finished)
        self.custom_thread.str_print_signal.connect(self.cli_out.add_txt)

        self.main_widget = QWidget()
        self.main_widget.setLayout(main_box)
        self.setCentralWidget(self.main_widget)

    def run_clicked(self):
        print "run_clicked"
        print "...currentWidget(ref) =", self.centre_widget.step_param_widg.currentWidget(
        )
        cmd_tmp = self.centre_widget.step_param_widg.currentWidget().command
        print "cmd_tmp =", cmd_tmp
        self.cmd_launch(cmd_tmp)

    def cmd_launch(self, new_cmd):
        self.custom_thread(new_cmd, self.uni_controler, mk_nxt=True)

    def update_after_finished(self):
        self.cli_tree_output(self.uni_controler)
        new_html = self.uni_controler.get_html_report()
        new_img_json = self.uni_controler.get_datablock_path()
        new_ref_pikl = self.uni_controler.get_reflections_path()

        print "\n new_html =", new_html, "\n"
        print " new_img_json =", new_img_json, "\n"
        print " new_ref_pikl =", new_ref_pikl, "\n"

        if (self.cur_html != new_html):
            self.cur_html = new_html
            try:
                self.web_view.update_page(new_html)

            except:
                print "No HTML here"

        if (self.cur_pick != new_ref_pikl):
            self.cur_pick = new_ref_pikl
            self.img_view.ini_reflection_table(self.cur_pick)

        if (self.cur_json != new_img_json):
            self.cur_json = new_img_json
            self.img_view.ini_datablock(self.cur_json)

        tmp_curr = self.uni_controler.step_list[self.uni_controler.current]
        nxt_cmd = get_next_step(tmp_curr)
        cur_success = tmp_curr.success

        if (tmp_curr.command[0] != "reindex"):
            try:
                self.my_pop.close()

            except:
                print "no need to close reindex table"

        if (nxt_cmd == "refine_bravais_settings"):
            if (cur_success == None):
                self.cmd_launch("refine_bravais_settings")

            else:
                self.centre_widget.set_widget("refine")

        elif (nxt_cmd == "reindex"):
            self.my_pop = MyReindexOpts()
            self.my_pop.set_ref(in_json_path=tmp_curr.prev_step.json_file_out)
            self.my_pop.my_inner_table.cellClicked.connect(self.opt_clicked)

        else:
            self.centre_widget.set_widget(nxt_cmd)

        self.tree_out.update_me(self.uni_controler.step_list[0],
                                self.uni_controler.current)

        with open('bkp.pickle', 'wb') as bkp_out:
            pickle.dump(self.uni_controler, bkp_out)

    def opt_clicked(self, row, col):
        re_idx = row + 1
        print "Solution clicked =", re_idx
        cmd_tmp = "reindex solution=" + str(re_idx)
        self.cmd_launch(cmd_tmp)

    def item_clicked(self, it_index):
        print "TreeNavWidget(item_clicked)"
        item = self.tree_out.std_mod.itemFromIndex(it_index)
        lin_num = item.idials_node.lin_num
        print "clicked item lin_num (self.tree_out.std_mod) =", lin_num
        cmd_ovr = "goto " + str(lin_num)
        self.cmd_launch(cmd_ovr)
Exemplo n.º 6
0
    def __init__(self):
        super(MainWidget, self).__init__()
        self.storage_path = sys_arg.directory
        try:
            with open (self.storage_path + "/dui_files/bkp.pickle", "rb") as bkp_in:
                self.idials_runner = pickle.load(bkp_in)

            #TODO sometimes the following error appears
            #Attribute not found
            #'module' object has no attribute 'CommandNode'

        except Exception as e:
            print "str(e) =", str(e)
            print "e.__doc__ =", e.__doc__
            print "e.message =", e.message
            self.idials_runner = Runner()

            try:
                import shutil
                shutil.rmtree(self.storage_path + "/dui_files")

            except:
                print "failed to do \"shutil.rmtree(\"/dui_files\")\""

            os.mkdir(self.storage_path + "/dui_files")

        #This flag makes the behaviour switch (automatic / explicit)
        self.idials_runner.make_next = sys_arg.make_next

        self.cli_tree_output = TreeShow()
        self.cli_tree_output(self.idials_runner)

        self.cur_html = None
        self.cur_pick = None
        self.cur_json = None
        self.cur_log = None
        self.cur_cmd_name = "None"

        main_box = QVBoxLayout()

        h_left_splitter = QSplitter()
        h_left_splitter.setOrientation(Qt.Horizontal)

        self.tree_out = TreeNavWidget()
        '''
        scroll_area_left = QScrollArea()
        scroll_area_left.setWidget(self.tree_out)
        h_left_splitter.addWidget(scroll_area_left)
        '''
        h_left_splitter.addWidget(self.tree_out)


        self.centre_widget = CentreWidget()
        self.centre_widget.get_arg_obj(sys_arg)
        self.run_all = sys_arg.run_all

        h_left_splitter.addWidget(self.centre_widget)

        v_left_splitter = QSplitter()
        v_left_splitter.setOrientation(Qt.Vertical)
        v_left_splitter.addWidget(h_left_splitter)

        self.info_widget = InfoWidget()

        scrollArea = QScrollArea()
        scrollArea.setWidget(self.info_widget)

        v_left_splitter.addWidget(scrollArea)

        h_main_splitter = QSplitter()
        h_main_splitter.setOrientation(Qt.Horizontal)
        h_main_splitter.addWidget(v_left_splitter)

        self.cli_out = CliOutView()
        self.web_view = WebTab()
        self.img_view = MyImgWin()
        self.ext_view = OuterCaller()


        self.output_info_tabs = QTabWidget()
        self.output_info_tabs.addTab(self.img_view, "Image View")
        self.output_info_tabs.addTab(self.cli_out, "Log Text")
        self.output_info_tabs.addTab(self.web_view, "Report View")
        self.output_info_tabs.addTab(self.ext_view, "Reciprocal Lattice Viewer")
        self.view_tab_num = 0
        self.output_info_tabs.currentChanged.connect(self.tab_changed)

        h_main_splitter.addWidget(self.output_info_tabs)

        main_box.addWidget(h_main_splitter)

        self.txt_bar = Text_w_Bar()
        main_box.addWidget(self.txt_bar)

        self.connect_all()

        self.custom_thread = CommandThread()
        self.custom_thread.finished.connect(self.update_after_finished)
        self.custom_thread.str_fail_signal.connect(self.after_failed)
        self.custom_thread.str_print_signal.connect(self.cli_out.add_txt)
        self.custom_thread.str_print_signal.connect(self.txt_bar.setText)

        self.main_widget = QWidget()
        self.main_widget.setLayout(main_box)
        self.setCentralWidget(self.main_widget)

        self.setWindowTitle('CCP4 DUI')
        self.setWindowIcon(QIcon(self.centre_widget.dials_logo_path))


        self.just_reindexed = False
        self.user_stoped = False
        self.reconnect_when_ready()