def onBrow(self): logger.debug('onBrow - select file') path0 = './' if len(self.list_of_files) > 1: path0 = self.list_of_files[1] path = gu.get_open_fname_through_dialog_box( self, path0, 'Select text file for browser', filter='Text files (*.txt *.dat *.data *.cfg *.npy)\nAll files (*)' ) if path is None or path == '' or path == path0: #logger.debug('Loading is cancelled...') return #logger.info('File selected for browser: %s' % path) if not path in self.list_of_files: self.list_of_files.append(path) self.box_txt.setText(load_textfile(path)) self.setListOfFiles(self.list_of_files[1:]) self.box_file.setCurrentIndex(len(self.list_of_files) - 1) self.setStatus(0, 'Status: browsing selected file')
def save_doc(self): """Saves document metadata and data in files """ logger.debug('In save_doc') wdoce = cp.cmwdbdoceditor if wdoce is None or wdoce.data_nda is None: logger.warning( 'Document editor is not available. Select collection in DB then document in List mode.' ) return doc = wdoce.get_model_dicdoc(discard_id_ts=False) data = wdoce.get_data_nda() prefix = dbu.out_fname_prefix(**doc) control = {'data': True, 'meta': True} resp = qwu.change_check_box_dict_in_popup_menu(control, 'Select and confirm',\ msg='Save current document in file\n%s\nfor types:'%prefix, parent=self.but_add) if resp == 1: logger.info( 'Save document data and metadata in file(s) with prefix: %s' % prefix) dbu.save_doc_and_data_in_file(doc, data, prefix, control) cp.last_selected_fname.setValue('%s.npy' % prefix) else: logger.warning('Command "Save" is cancelled')
def delete_selected_items_docs(self): logger.debug('delete_selected_items_docs') wdocs = cp.cmwdbdocswidg if wdocs is None: logger.warning('Window with a List of documents does not exist?') return msg = 'From db: %s\n col: %s\n delete docs:\n ' % (wdocs.dbname, wdocs.colname) doc_ids = [item.accessibleText() for item in wdocs.selected_items()] msg_recs = ['%s: %s' % (id, dbu.timestamp_id(id)) for id in doc_ids] msg += '\n '.join(msg_recs) logger.info(msg) resp = qwu.confirm_or_cancel_dialog_box(parent=self.but_del, text=msg, title='Confirm or cancel') logger.debug('delete_selected_items_docs response: %s' % resp) if resp: dbu.delete_documents(wdocs.dbname, wdocs.colname, doc_ids) cp.cmwdbdocs.show_documents(wdocs.dbname, wdocs.colname, force_update=True) else: logger.warning('Command "Delete" is cancelled')
def add_rect_to_scene(self, rect, brush=QBrush(), pen=QPen(Qt.yellow, 4, Qt.DashLine)): """Adds rect to scene, returns QWGraphicsRectItem - for interactive stuff""" logger.debug('add_rect_to_scene %s' % qu.info_rect_xywh(rect)) pen.setCosmetic(True) item = QWGraphicsRectItem(rect, parent=None, scene=self.scene()) item.setPen(pen) item.setBrush(brush) return item
def select_doc_widget(self): resp = qwu.select_item_from_popup_menu(cp.list_of_doc_widgets, parent=self) logger.debug('select_doc_widget resp: %s' % resp) if resp is None: return cp.cdb_docw.setValue(resp) cp.cmwdbmain.wdocs.set_docs_widget() self.but_docs.setText('%s %s' % (cp.cdb_docw.value(), cp.char_expand))
def set_selection_mode(self): #logger.debug('set_selection_model') wtree = cp.cmwdbtree if wtree is None: return selected = qwu.select_item_from_popup_menu(wtree.dic_smodes.keys(), title='Select mode',\ default=cp.cdb_selection_mode.value(), parent=self) logger.info('Set selection mode: %s' % selected) if selected is None: return cp.cdb_selection_mode.setValue(selected) wtree.set_selection_mode(selected)
def on_histogram_scene_rect_changed(self, r): x1, y1, x2, y2 = r.getCoords() logger.debug('on_histogram_scene_rect_changed: %s reset image for spectal value in range %.3f:%.3f '%\ (qu.info_rect_xywh(r),y1,y2)) w = cp.ivimageaxes if w is not None: wi = w.wimg rs = wi.scene().sceneRect() # preserve current scene rect wi.set_pixmap_from_arr(wi.arr, set_def=False, amin=y1, amax=y2) wi.set_rect_scene(rs, set_def=False)
def onSave(self): logger.debug('onSave') path = gu.get_save_fname_through_dialog_box(self, self.fname, 'Select file to save', filter='*.txt') if path is None or path == '': return text = str(self.box_txt.toPlainText()) logger.info('Save in file:\n' + text) f = open(path, 'w') f.write(text) f.close()
def select_visible_buttons(self): logger.debug('select_visible_buttons') d = self.buttons_dict() resp = qwu.change_check_box_dict_in_popup_menu(d, 'Select buttons',\ msg='Check visible buttons then click Apply or Cancel', parent=self.but_buts) logger.debug('select_visible_buttons resp: %s' % resp) if resp is None: logger.info('Visible buttons selection is cancelled') return if resp == 1: logger.info('Visible buttons: %s' % str(d)) self.set_buttons_visiable(d) self.set_buttons_config_bitword(d)
def add_doc(self): """Adds document from editor to DB """ logger.debug('In add_doc') wdoce = cp.cmwdbdoceditor if wdoce is None or wdoce.data_nda is None: logger.warning( 'Document is not selected. Select collection in DB then document in List mode.' ) return dicdoc = wdoce.get_model_dicdoc() nda = wdoce.get_data_nda() msg = '\n '.join(['%12s: %s' % (k, v) for k, v in dicdoc.items()]) logger.debug('add_doc \n%s \n%s' % (msg, info_ndarr(nda, 'data n-d array '))) dbnexp = dbu.db_prefixed_name(dicdoc.get('experiment', 'exp_def')) dbndet = dbu.db_prefixed_name(dicdoc.get('detector', 'det_def')) colname = dicdoc.get('detector', None) d = {dbnexp: True, dbndet: True} resp = qwu.change_check_box_dict_in_popup_menu( d, msg='Add constants\nand metadata to DB', parent=self.but_add) logger.debug('add_doc resp: %s' % resp) if resp == 1: if d[dbnexp]: respe = dbu.insert_document_and_data(dbnexp, colname, dicdoc, nda) if d[dbndet]: respd = dbu.insert_document_and_data(dbndet, colname, dicdoc, nda) wdocs = cp.cmwdbdocswidg if wdocs is None: return cp.cmwdbdocs.show_documents(wdocs.dbname, wdocs.colname, force_update=True) else: logger.warning( 'Uploading of calibration constants in DB is cancelled')
def add_db(self): """Adds DB from file """ logger.debug('add_db - Adds DB from file') path0 = '.' path = qwu.get_open_fname_through_dialog_box( self, path0, 'Select file with DB to add', filter='*') if path is None: logger.warning('DB file selection is cancelled') return host = cp.cdb_host.value() port = cp.cdb_port.value() dbname = os.path.basename(path) logger.info('Add DB "%s" from file %s' % (dbname, path)) dbu.importdb(host, port, dbname, path)
def save_db(self): """Saves selected DBs in files """ bdnames = self.selected_db_names() if len(bdnames) == 0: logger.warning( 'DB is not selected. Click on DB(s) before "Save" button.') return logger.debug('In save_db bdnames:\n %s' % '\n '.join(bdnames)) host = cp.cdb_host.value() port = cp.cdb_port.value() path0 = '.' resp = qwu.get_existing_directory_through_dialog_box( self, path0, title='Select directory for DB files') if resp is None: logger.warning('Saving of DBs is cancelled') return for dbname in bdnames: fname = '%s/%s' % (resp, dbname) dbu.exportdb(host, port, dbname, fname) #, **kwa)
def add_rect_to_scene_v1(self, rect, brush=QBrush(), pen=QPen(Qt.yellow, 4, Qt.DashLine)): """Adds rect to scene, returns QGraphicsRectItem""" pen.setCosmetic(True) return self.scene().addRect(rect, pen, brush) def add_test_items_to_scene(self, show_mode=3, colori=Qt.red, colfld=Qt.magenta, **kwa): if show_mode & 1: rs = QRectF(0, 0, 10, 10) self.rsi = self.add_rect_to_scene_v1(rs, pen=QPen(Qt.NoPen), brush=QBrush(colfld)) if show_mode & 2: ror = QRectF(-1, -1, 2, 2) self.rori = self.add_rect_to_scene_v1(ror,\ pen=QPen(Qt.red, 0, Qt.SolidLine),\ brush=QBrush(colori)) if __name__ == "__main__": import sys import psana.graphqt.QWUtils as qu # print_rect sys.exit(qu.msg_on_exit()) # EOF
def delete_selected_items_db_cols(self): wtree = cp.cmwdbtree if wtree is None: logger.warning( 'delete_selected_items_db_cols - CMWDBTree object does not exist?' ) return # dict of pairs {<item-name>: <item-parent-name>} # where <item-parent-name> is None for DB item or DB name for collection item. list_name_parent = [(item.text(), None if item.parent() is None else item.parent().text())\ for item in wtree.selected_items()] if not len(list_name_parent): logger.warning( 'delete_selected_items: selected nothing - nothing to delete...' ) return #for k,v in list_name_parent: # logger.debug(' %s: %s' % (k.ljust(20),v)) # Define del_mode = COLS or DBS if at least one DB is selected del_mode = cp.COLS if all([p is not None for n, p in list_name_parent]) else cp.DBS list_db_names = [] # list of DB names dic_db_cols = {} # dict {DBname: list of collection names} msg = 'Delete %s:\n ' % del_mode if del_mode == cp.DBS: list_db_names = [n for n, p in list_name_parent if p is None] msg += '\n '.join(list_db_names) else: for n, p in list_name_parent: if p not in dic_db_cols: dic_db_cols[p] = [ n, ] else: dic_db_cols[p].append(n) for dbname, lstcols in dic_db_cols.items(): msg += '\nfrom DB: %s\n ' % dbname msg += '\n '.join(lstcols) logger.info(msg) resp = qwu.confirm_or_cancel_dialog_box(parent=self.but_del, text=msg, title='Confirm or cancel') logger.debug('delete_selected_items_db_cols response: %s' % resp) if resp: if del_mode == cp.DBS: dbu.delete_databases(list_db_names) else: dbu.delete_collections(dic_db_cols) # Regenerate tree model self.on_edi_db_filter_finished() else: logger.warning('Command "Delete" is cancelled')
def test_scene_rect_changed_reception(self, rs): qu.print_rect(rs, cmt='FWView.test_scene_rect_changed_reception')
def on_image_scene_rect_changed(self, r): wimg = cp.ivimageaxes.wimg a = wimg.array_in_rect(r) logger.debug('on_image_scene_rect_changed: %s' % qu.info_rect_xywh(r)) #logger.debug('on_image_scene_rect_changed: %s\n %s' % (qu.info_rect_xywh(r), info_ndarr(a, 'selected array in rect', first=0, last=3))) self.set_spectrum_from_arr(a, update_hblimits=False)