class MainWidget(QMainWindow): def __init__(self): super(MainWidget, self).__init__() self.super_parent = self print "\n MainWidget(ID) =", self.winId(), "\n" print "sys.argv =", sys.argv, "\n" ini_template_path = None if (len(sys.argv) > 1): ini_template_path = str(sys.argv[1]) print "must import with template:", ini_template_path, "\n" if (os.path.exists("dials.state")): old_state_str = find_state_str() os.rename("dials.state", old_state_str) else: do_continue = check_previous_runs() if (do_continue == False): sys.exit() # This flag will define the layout orientation of the left side # area of the GUI and therefore needs to be taking into account when # the rest of the GUI gets build self.embedded_reindex = False buttons_widget = QWidget() #buttons_widget.setStyleSheet("background-color: solid gray") buttons_widget.setStyleSheet("background-color: lightgray") v_left_box = QHBoxLayout() self.step_param_widg = QStackedWidget() my_lst = StepList(parent=self) label_lst, self.widg_lst, icon_lst, self.command_lst = my_lst() #My_style = Qt.ToolButtonStyle(Qt.ToolButtonTextUnderIcon) self.setWindowTitle('DUI/idials') self.btn_lst = [] for pos, step_data in enumerate(label_lst): print "pos = ", pos #new_btn = QToolButton(self) new_btn = QPushButton(self) new_btn.setToolTip(step_data) new_btn.setIcon(icon_lst[pos]) new_btn.setIconSize(QSize(38, 38)) new_btn.par_wig = self.widg_lst[pos] new_btn.command = self.command_lst[pos] #new_btn.setText(step_data) #new_btn.setToolButtonStyle(My_style) #new_btn.setFont(QFont("Monospace", 10, QFont.Bold)) new_btn.clicked.connect(self.btn_clicked) v_left_box.addWidget(new_btn) self.step_param_widg.addWidget(new_btn.par_wig) self.btn_lst.append(new_btn) if (self.embedded_reindex): self.reindex_tool = MyReindexOpts(self) self.step_param_widg.addWidget(self.reindex_tool) else: self.reindex_tool = None self.tmp_reindex_widg = TmpRedinexWidget(self) self.step_param_widg.addWidget(self.tmp_reindex_widg) idials_gui_path = os.environ["IDIALS_GUI_PATH"] dials_logo_path = str(idials_gui_path + "/resources/DIALS_Logo_smaller_centred.png") buttons_widget.setLayout(v_left_box) self._refrech_btn_look() self.btn_stop = QPushButton("\n Stop \n", self) #self.btn_stop.setContentsMargins(QMargins(0,0,0,0)) self.btn_stop.setIcon(QIcon.fromTheme("process-stop")) self.btn_go = QPushButton('\n Run \'\n', self) self.btn_go.setIcon(QIcon(dials_logo_path)) self.btn_go.setIconSize(QSize(80, 48)) self.btn_go.clicked.connect(self.btn_go_clicked) self.btn_stop.clicked.connect(self.btn_stop_clicked) self.idials_widget = IdialsInnerrWidget(self, dials_logo_path) self.idials_widget.rtime_txt_on = True self.grayed_out_buttons = True # Deprecated #self.next_step_on = True centre_widget = CentreWidget(self) centre_widget(buttons_widget, self.btn_stop, self.btn_go, self.step_param_widg) v_control_splitter = QSplitter() ''' v_control_splitter.setOrientation(Qt.Horizontal) v_control_splitter.addWidget(self.idials_widget) v_control_splitter.addWidget(centre_widget) ''' if (self.embedded_reindex): v_control_splitter.setOrientation(Qt.Vertical) v_control_splitter.addWidget(centre_widget) v_control_splitter.addWidget(self.idials_widget) else: v_control_splitter.setOrientation(Qt.Horizontal) v_control_splitter.addWidget(self.idials_widget) v_control_splitter.addWidget(centre_widget) h_main_splitter = QSplitter() h_main_splitter.setOrientation(Qt.Horizontal) self.output_wg = outputs_widget(self) self.txt_out = self.output_wg.in_txt_out control_p_info_splitt = QSplitter() control_p_info_splitt.setOrientation(Qt.Vertical) self.info_widget = InfoWidget(self) control_p_info_splitt.addWidget(v_control_splitter) scrollArea = QScrollArea() scrollArea.setWidget(self.info_widget) control_p_info_splitt.addWidget(scrollArea) #scrollArea = QScrollArea() #scrollArea.setWidget(self.scrollable_widget) h_main_splitter.addWidget(control_p_info_splitt) h_main_splitter.addWidget(self.output_wg) main_box = QVBoxLayout() main_box.setContentsMargins(QMargins(0, 0, 0, 0)) main_box.setSpacing(0) main_box.addWidget(h_main_splitter) self.bottom_bar_n_info = Text_w_Bar(self) main_box.addWidget(self.bottom_bar_n_info) self.running = False menubar = self.menuBar() fileMenu = menubar.addMenu('File') fileMenu.addAction("&Import...", self.openFile, "Ctrl+I") fileMenu.addAction("E&xit", self.quit, "Ctrl+Q") configMenu = menubar.addMenu('config') #configMenu.addAction("T&oggle real time text", self.togle_text_rt, "Ctrl+T") configMenu.addAction("Real time log text in Pbar", self.togle_text_rt) configMenu.addAction("Automatic gray out buttons", self.togle_gray_out) #Deprecated #configMenu.addAction("Automatic go to next step", self.togle_auto_next_step) #starting where it left before ini_index = self.idials_widget.controller.get_current().index print "self.idials_widget.controller.get_current().index =", ini_index if (ini_index == 0): print "\n Running for first time in this dir \n" self._gray_unwanted() #TODO Think a bit if you are going a bit #back and forward with the next line self.idials_widget.update_info() else: print "\n Already run at least one command here \n" self.idials_widget.goto(ini_index) if (ini_template_path != None): print "\n\n Time to import with template:" print ini_template_path, "\n" self.widg_lst[0].templ_lin.setText(ini_template_path) self.idials_widget.change_mode("import") self._refresh_stacked_widget(self.widg_lst[0]) self.btn_go_clicked() Deprecated = ''' self.widg_lst[0].done_import = True ''' self.main_widget = QWidget() self.main_widget.setLayout(main_box) self.setCentralWidget(self.main_widget) def openFile(self): print "openFile" if (self.running == False): my_sender = self.btn_lst[0] # this is not the only place where _active_btn gets called self._active_btn(my_sender) def _refrech_btn_look(self): for btn in self.btn_lst: btn.setStyleSheet("background-color: lightgray") def _refresh_stacked_widget(self, new_widget): self.step_param_widg.setCurrentWidget(new_widget) self._refrech_btn_look() self.current_widget = new_widget try: self.current_widget() print "controller.get_current().success =", self.idials_widget.controller.get_current( ).success except: print "\n no __call__ in ", self.current_widget, "\n" def _active_btn(self, my_sender): self.idials_widget.change_mode(my_sender.command) self._refresh_stacked_widget(my_sender.par_wig) my_sender.setStyleSheet("background-color: lightblue") self.btn_go.setText(str(my_sender.command)) try: my_sender.par_wig.sipler_widget.set_max_nproc() print "\n Tunning nproc to maximum \n" except: print "\n This step runs as fas as it can with nproc = 1 \n" try: self.mtz_name = build_mtz_str( self.info_widget.all_data.tmpl_str) + ".mtz" except: self.mtz_name = "hkl_out.mtz" try: my_sender.par_wig.sipler_widget.mtz_name_lin.setText(self.mtz_name) except: print "failed to update mtz_name" def _find_next(self, current_command=None): if (current_command == "index" or current_command == "reindex" or current_command == "integrate"): cmd_next = "refine" elif (current_command == "clean"): cmd_next = "import" else: cmd_next = None for pos, cmd in enumerate(self.command_lst): if (cmd == current_command): cmd_next = self.command_lst[pos + 1] return cmd_next def _gray_unwanted(self): for btn in self.btn_lst: btn.setEnabled(True) if (self.grayed_out_buttons == True): current_command = self.idials_widget.controller.get_current().name print "current_command =", current_command cmd_next = self._find_next(current_command) for btn in self.btn_lst: print btn.command if (btn.command == cmd_next): btn.setEnabled(True) else: btn.setEnabled(False) def mtz_name_changed(self, new_value): self.mtz_name = str(new_value) #self.widg_lst[ ... ] .sipler_widget.mtz_name_lin.setText(self.mtz_name) def param_changed(self, new_par_str): print "\n MainWidget, param_changed, new_par_str =", new_par_str self.idials_widget.change_parameter(new_par_str) def reset_param(self): self.idials_widget.param_reset() def btn_clicked(self): if (self.running == False): my_sender = self.sender() # this is not the only place where _active_btn gets called self._active_btn(my_sender) def btn_stop_clicked(self): if (self.running == True): #self._gray_unwanted() self.idials_widget.stop_clicked() self.running = False def btn_go_clicked(self): print "self.running =", self.running print "self.idials_widget.failed =", self.idials_widget.failed print "...controller.get_current().success", self.idials_widget.controller.get_current( ).success if (self.running == False and self.idials_widget.failed == None): self._gray_unwanted() self.idials_widget.run_clicked() self.running = True else: self.idials_widget.failed = None def update_after_command_end(self): self.bottom_bar_n_info.end_motion() self.bottom_bar_n_info.setText("Done") print "controller.get_current().success =", self.idials_widget.controller.get_current( ).success self.running = False current_command = self.idials_widget.controller.get_current().name print "\n\n current_command ==", current_command, "\n\n" if (self.idials_widget.controller.get_current().success == True): update_GUI = True try: repr_path = self.idials_widget.controller.get_report() self.update_report(repr_path) except: print "Not supposed to update report" if (current_command == "clean"): print "\n <<< NO success on import yet >>> \n" elif (current_command == "refine_bravais_settings"): self.pop_reindex_gui() elif (current_command == "index"): self.idials_widget.change_mode("refine_bravais_settings") print "\n running << refine_bravais_settings >> \n" update_GUI = False self.btn_go_clicked() elif (current_command == "reindex"): print "Time to shrink back reindex GUI" if (not (self.embedded_reindex)): self.reindex_tool.close() self.reindex_tool = None elif (current_command == "integrate"): print "mtz OUT =", self.mtz_name self.idials_widget.change_mode("export") self.idials_widget.change_parameter("mtz.hklout=" + self.mtz_name) self.btn_go_clicked() elif (current_command != "export"): print "Time to update html << report >>" if (update_GUI == True): self._gray_unwanted() self._update_img() #TODO Think a bit if you are going a bit #back and forward with the next line self.idials_widget.update_info() self.check_next(current_command) else: print "\n\n something went WRONG \n" #TODO show in the GUI that something went WRONG def check_next(self, current_command="clean"): print "\n check_next(self)" print "current_command =", current_command, "\n" Deprecated = ''' print "self.next_step_on =", self.next_step_on if( self.next_step_on == True ): ''' if (current_command == "clean"): print "self.idials_widget.failed =", self.idials_widget.failed print "...controller.get_current().success", self.idials_widget.controller.get_current( ).success if (self.idials_widget.failed == None): self.btn_go_clicked() else: print "\n\n Failed to import \n\n" else: next_command = self._find_next(current_command) print "next_command =", next_command, "\n" for btn in self.btn_lst: print btn.command if (btn.command == next_command): self._active_btn(btn) def jump(self, new_url=None): #TODO cmd_name does not have any use any more if (self.running == False): if new_url != None: self.update_report(new_url) if (self.idials_widget.controller.get_current().name == "refine_bravais_settings"): self.pop_reindex_gui() else: if (not (self.embedded_reindex)): if (self.reindex_tool != None): self.reindex_tool.close() self.reindex_tool = None self.check_next( self.idials_widget.controller.get_current().name) self._gray_unwanted() self._update_img() def opt_picked(self, opt_num): if (self.running == False): print "\n opt_num =", opt_num, " \n" self.idials_widget.change_mode("reindex") str_par = "solution=" + str(opt_num) print "\n change_parameter =", str_par, "\n" self.idials_widget.change_parameter(str_par) if (self.old_opnum == opt_num): print "\n Supposed to run reindex NOW \n" self.btn_go_clicked() self.old_opnum = opt_num def pop_reindex_gui(self): print " <<< Time to show the table " sumr_path = self.idials_widget.controller.get_summary() if (self.embedded_reindex): self.step_param_widg.setCurrentWidget(self.reindex_tool) self.reindex_tool.set_ref(parent=self, in_json_path=sumr_path) else: self.reindex_tool = MyReindexOpts() self.step_param_widg.setCurrentWidget(self.tmp_reindex_widg) self.reindex_tool.set_ref(parent=self, in_json_path=sumr_path) self.btn_go.setText("reindex") def _update_img(self): print "attempting to update imgs" json_file_path = None refl_pikl_path = None try: json_file_path = str( self.idials_widget.controller.get_current().datablock) print "\n images from:", json_file_path, "\n" except: print "\n <<< trying deeper search for datablock.json" try: #current = self.controller.get_current() #previous = current.parent current = self.idials_widget.controller.get_current() for times in xrange(50): previous = current.parent if (str(previous.name) == "import"): print "found <<< import >>> " json_file_path = str(previous.datablock) print "\n images from:", json_file_path, "\n\n" break else: print "tmp step = ", current.name current = previous except: print "<<< failed to find datablock.json >>>" try: refl_pikl_path = self.idials_widget.controller.get_current( ).reflections except: print "failed to find << refl_pikl_path >>" self.output_wg.img_view.ini_datablock(json_file_path) self.output_wg.img_view.ini_reflection_table(refl_pikl_path) to_work_on_in_the_future = ''' try: exp_json_path = self.idials_widget.controller.get_current().experiments print "exp_json_path =", exp_json_path except: print "failed to find << exp_json_path >>" ''' def update_report(self, report_path): print "\n MainWidget update report with:", report_path self.output_wg.web_view.update_page(report_path) def togle_text_rt(self): print "self.idials_widget.rtime_txt_on =", self.idials_widget.rtime_txt_on if (self.idials_widget.rtime_txt_on == True): self.idials_widget.rtime_txt_on = False else: self.idials_widget.rtime_txt_on = True print "self.idials_widget.rtime_txt_on =", self.idials_widget.rtime_txt_on def togle_gray_out(self): print "self.grayed_out_buttons =", self.grayed_out_buttons if (self.grayed_out_buttons == True): self.grayed_out_buttons = False else: self.grayed_out_buttons = True print "self.grayed_out_buttons =", self.grayed_out_buttons self._gray_unwanted() def quit(self): print "quit" self.closeEvent(QCloseEvent) def closeEvent(self, event): try: self.reindex_tool.close() self.reindex_tool = None except: print "no need to close reindex tool" self.close() def start_pbar_motion(self): self.bottom_bar_n_info.setText("Running") self.bottom_bar_n_info.start_motion() def update_pbar_text(self, rtime_text): if (len(rtime_text) > 3): self.bottom_bar_n_info.setText(rtime_text) def togle_auto_next_step(self): #TODO remove this eventually Deprecated = '''
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)
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()
class MainWidget(QMainWindow): 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() def connect_all(self): self.setCursor(Qt.ArrowCursor) self.tree_clickable = True self.tree_out.clicked[QModelIndex].connect(self.node_clicked) self.centre_widget.repeat_btn.clicked.connect(self.rep_clicked) self.centre_widget.run_btn.clicked.connect(self.run_clicked) self.centre_widget.stop_btn.clicked.connect(self.stop_clicked) self.centre_widget.user_changed.connect(self.cmd_changed_by_user) self.centre_widget.update_command_lst.connect( self.update_low_level_command_lst) self.centre_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.centre_widget.repeat_btn.setEnabled(False) self.centre_widget.run_btn.setEnabled(False) self.centre_widget.stop_btn.setEnabled(True) self.centre_widget.gray_outs_all() self.centre_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.centre_widget.repeat_btn.setEnabled(False) self.centre_widget.stop_btn.setEnabled(False) self.centre_widget.run_btn.setEnabled(False) #self.centre_widget.run_btn.setText(" . ") if(self.user_stoped == True): self.idials_runner.current_node.success = None if(self.idials_runner.current_node.success == None): self.centre_widget.run_btn.setEnabled(True) self.centre_widget.step_param_widg.currentWidget().my_widget.activate_me() tmp_off = ''' txt_cap = self.idials_runner.current_node.command_lst[0] if(txt_cap == None): txt_cap = " ? " self.centre_widget.run_btn.setText(txt_cap) ''' else: if(self.idials_runner.current_node.command_lst[0] != "export"): self.centre_widget.repeat_btn.setEnabled(True) self.centre_widget.step_param_widg.currentWidget().my_widget.gray_me_out() if(self.idials_runner.current_node.command_lst[0] == "reindex"): self.centre_widget.run_btn.setEnabled(False) self.centre_widget.repeat_btn.setEnabled(False) self.check_gray_outs() self.user_stoped = False self.update_nav_tree() def tab_changed(self, num): self.view_tab_num = num update_info(self) def update_low_level_command_lst(self, command_lst): print "self.idials_runner.current_node.command_lst =", self.idials_runner.current_node.command_lst print " command_lst =", command_lst if(self.idials_runner.current_node.success == True and self.idials_runner.make_next == True): self.rep_clicked() self.idials_runner.current_node.command_lst = command_lst self.reconnect_when_ready() def cmd_changed_by_user(self, my_label): print "cmd_changed_by_user()" tmp_curr = self.idials_runner.current_node if(self.idials_runner.make_next == False and tmp_curr.success == True): self.cmd_exe(["mkchi"]) self.idials_runner.current_node.command_lst = [str(my_label)] self.centre_widget.step_param_widg.currentWidget().my_widget.reset_par() self.cmd_exe(["clean"]) elif(tmp_curr.success == None): self.idials_runner.current_node.command_lst = [str(my_label)] self.reconnect_when_ready() def cmd_changed_by_any(self): tmp_curr_widg = self.centre_widget.step_param_widg.currentWidget() self.cur_cmd_name = tmp_curr_widg.my_widget.command_lst[0] self.reconnect_when_ready() def rep_clicked(self): print "rep_clicked" self.cmd_exe(["mksib"]) self.cmd_exe(["clean"]) self.check_gray_outs() def stop_clicked(self): print "\n\n <<< Stop clicked >>> \n\n" #TODO fix spelling on << dials_command >> pr_to_kill = self.idials_runner.current_node.dials_command.my_pid print "self.idials_runner.current_node.dials_command.my_pid =", pr_to_kill self.user_stoped = True kill_w_child(pr_to_kill) 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().my_widget.command_lst print "cmd_tmp =", cmd_tmp 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 theading run_me = True if(new_cmd[0] == "integrate"): print "\n Time to check if an old \".mtz\" file will be replaced \n" mtz_name = str(self.centre_widget.widg_lst[5].my_widget. sipler_widget.mtz_name_lin.text()) print "mtz_name =", mtz_name if(os.path.isfile(mtz_name)): print "\n\n the file IS about to be there \n\n" mesg_text = "\n Overwrite existing file, or change file name below" new_text, ok = QInputDialog.getText(self, "Confirm Name of Output MTZ file", mesg_text , text=str(mtz_name)) if ok: run_me = True self.centre_widget.widg_lst[5].my_widget.sipler_widget.mtz_name_lin.setText(new_text) else: run_me = False else: print "the \".mtz\" file is NOT going to be replaced " if(run_me == True): 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): update_info(self) self.txt_bar.end_motion() self.just_reindexed = False if(self.idials_runner.make_next == True): tmp_curr = self.idials_runner.current_node.prev_step nxt_cmd = get_next_step(tmp_curr) print "get_next_step(tmp_curr) =", nxt_cmd if(nxt_cmd != "reindex" and tmp_curr.success == True): self.centre_widget.set_widget(nxt_cmd = nxt_cmd) self.idials_runner.current_node.command_lst[0] = nxt_cmd else: tmp_curr = self.idials_runner.current_node if(tmp_curr.command_lst[0] == "refine_bravais_settings" and tmp_curr.success == True): if(self.idials_runner.make_next == False): self.idials_runner.run(command = ["mkchi"], ref_to_class = None) self.idials_runner.current_node.command_lst[0] = "reindex" elif(tmp_curr.command_lst[0] == "reindex" and tmp_curr.success == True): self.just_reindexed = True try: self.my_pop.close() except: print "no need to close reindex table" elif(tmp_curr.command_lst[0] == "integrate" and tmp_curr.success == True): if(self.idials_runner.make_next == False): self.idials_runner.run(command = ["mkchi"], ref_to_class = None) mtz_name = str(self.centre_widget.widg_lst[5].my_widget. sipler_widget.mtz_name_lin.text()) print "MTZ name =", mtz_name mtz_export_par = "mtz.hklout=" + mtz_name self.cmd_launch(["export", mtz_export_par]) if(tmp_curr.command_lst[0] != "refine_bravais_settings" and tmp_curr.command_lst[0] != "integrate" and self.run_all == True): self.run_clicked() self.check_reindex_pop() self.check_gray_outs() self.reconnect_when_ready() with open(self.storage_path + "/dui_files/bkp.pickle", "wb") as bkp_out: pickle.dump(self.idials_runner, bkp_out) def check_gray_outs(self): tmp_curr = self.idials_runner.current_node if(tmp_curr.success != True): tmp_curr = tmp_curr.prev_step 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", "integrate"] , "integrate" : [None] , "export" : [None] , "None" : [None] } #TODO Consider if it worth using this dictionary instead of the function get_next_item() lst_nxt = cmd_connects[str(tmp_curr.command_lst[0])] self.centre_widget.gray_outs_from_lst(lst_nxt) def check_reindex_pop(self): tmp_curr = self.idials_runner.current_node if(tmp_curr.command_lst[0] == "reindex" and self.just_reindexed == False): try: 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.opt_signal.connect(self.opt_dobl_clicked) except Exception as my_err: print "str(my_err) =", str(my_err) print "my_err.__doc__ =", my_err.__doc__ print "my_err.message =", my_err.message if(str(my_err)[0:36] == '[Errno 2] No such file or directory:'): print "\n interrupted refine_bravais_settings \n" #TODO find an elegant way to interrupt and remove nodes else: try: self.my_pop.close() except: print "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) tmp_cur_nod = self.idials_runner.current_node if(self.idials_runner.make_next == False and len(tmp_cur_nod.next_step_list) == 0 and tmp_cur_nod.success == True): nod_ref = tmp_cur_nod else: nod_ref = tmp_cur_nod.prev_step try: self.check_gray_outs(nod_ref) except: print "failed to << check_gray_outs() >>" update_pbar_msg(self) def after_failed(self): print "\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: print err_lin print "curr_step.lin_num =", curr_step.lin_num err_log_file_out = self.storage_path + "/dui_files" + os.sep + str(curr_step.lin_num) + "_err_out.log" print "err_log_file_out =", 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 print "Solution clicked =", re_idx cmd_tmp = "reindex solution=" + str(re_idx) self.cmd_launch(cmd_tmp) def node_clicked(self, it_index): print "it_index =", it_index if(self.tree_clickable == True): #TODO Think of a more robust way to "disconnect" ... next line try: self.centre_widget.update_command_lst.disconnect( self.update_low_level_command_lst) except: print "<< update_low_level_command_lst >> already disconnected" print "TreeNavWidget(node_clicked)" item = self.tree_out.std_mod.itemFromIndex(it_index) prn_lst_lst_cmd(item.idials_node) 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_exe(cmd_ovr) self.centre_widget.set_widget(nxt_cmd = item.idials_node.command_lst[0], curr_step = self.idials_runner.current_node) self.check_reindex_pop() update_info(self) self.check_gray_outs() self.reconnect_when_ready() self.centre_widget.update_command_lst.connect( self.update_low_level_command_lst) def closeEvent(self, event): try: self.my_pop.close() except: print "no need to close reindex table"