def simple_api_item_widget(): r""" Very simple example of basic APIItemWidget widget with CustomAPI CommandLine: python -m wbia.guitool.api_item_widget --test-simple_api_item_widget python -m wbia.guitool.api_item_widget --test-simple_api_item_widget --show Example: >>> # ENABLE_DOCTEST >>> # xdoctest: +REQUIRES(--gui) >>> from wbia.guitool.api_item_widget import * # NOQA >>> import wbia.guitool as gt >>> gt.ensure_qapp() # must be ensured before any embeding >>> wgt = simple_api_item_widget() >>> # xdoctest: +REQUIRES(--show) >>> ut.quit_if_noshow() >>> wgt.show() >>> gt.qtapp_loop(wgt, frequency=100) """ import wbia.guitool as gt gt.ensure_qapp() col_getter_dict = { 'col1': [1, 2, 3], 'col2': ['a', 'b', 'c'], 'col3': ['e', 'f', 'g'], } sortby = 'col1' # col_display_role_func_dict = { # 'col1': lambda x: 'banana %d' % ((x * 100 % 23)), # } api = gt.CustomAPI( col_getter_dict=col_getter_dict, # col_display_role_func_dict=col_display_role_func_dict, editable_colnames=['col3'], sortby=sortby, ) headers = api.make_headers(tblnice='Simple Example') wgt = gt.APIItemWidget() wgt.change_headers(headers) # gt.qtapp_loop(qwin=wgt, ipy=ipy, frequency=loop_freq) # for testing wgt.menubar = gt.newMenubar(wgt) wgt.menuFile = wgt.menubar.newMenu('Dev') def wgt_embed(wgt): view = wgt.view # NOQA import utool utool.embed() ut.inject_func_as_method(wgt, wgt_embed) wgt.menuFile.newAction(triggered=wgt.wgt_embed) return wgt
def simple_api_tree_widget(): r""" Minimal example of a tree based api widget CommandLine: python -m wbia.guitool.api_item_widget --test-simple_api_tree_widget python -m wbia.guitool.api_item_widget --test-simple_api_tree_widget --show Example: >>> # ENABLE_DOCTEST >>> # xdoctest: +REQUIRES(--gui) >>> from wbia.guitool.api_item_widget import * # NOQA >>> import wbia.guitool >>> guitool.ensure_qapp() # must be ensured before any embeding >>> wgt = simple_api_tree_widget() >>> # xdoctest: +REQUIRES(--show) >>> ut.quit_if_noshow() >>> wgt.show() >>> guitool.qtapp_loop(wgt, frequency=100) """ guitool.ensure_qapp() col_name_list = ['name', 'num_annots', 'annots'] col_getter_dict = { 'name': ['fred', 'sue', 'tom', 'mary', 'paul'], 'num_annots': [2, 1, 3, 5, 1], } # make consistent data grouped_data = [ [col_getter_dict['name'][index] + '-' + str(i) for i in range(num)] for index, num in enumerate(col_getter_dict['num_annots']) ] flat_data, reverse_list = ut.invertible_flatten1(grouped_data) col_getter_dict['annots'] = flat_data iders = [list(range(len(col_getter_dict['name']))), reverse_list] col_level_dict = { 'name': 0, 'num_annots': 0, 'annots': 1, } sortby = 'name' api = guitool.CustomAPI( col_name_list=col_name_list, col_getter_dict=col_getter_dict, sortby=sortby, iders=iders, col_level_dict=col_level_dict, ) headers = api.make_headers(tblnice='Tree Example') wgt = guitool.APIItemWidget(view_class=APITreeView) wgt.change_headers(headers) # guitool.qtapp_loop(qwin=wgt, ipy=ipy, frequency=loop_freq) return wgt
def testdata_tree_view(): r""" CommandLine: python -m wbia.guitool.api_tree_view testdata_tree_view python -m wbia.guitool.api_tree_view testdata_tree_view --show Example: >>> # DISABLE_DOCTEST >>> # xdoctest: +REQUIRES(--gui) >>> import wbia.guitool as gt >>> from wbia.guitool.api_tree_view import * # NOQA >>> wgt = testdata_tree_view() >>> view = wgt.view >>> rows = view.selectedRows() >>> print('rows = %r' % (rows,)) >>> # xdoctest: +REQUIRES(--show) >>> ut.quit_if_noshow() >>> gt.qtapp_loop(qwin=wgt) """ import wbia.guitool as gt gt.ensure_qapp() col_name_list = ['name', 'num_annots', 'annots'] col_getter_dict = { 'name': ['fred', 'sue', 'tom', 'mary', 'paul'], 'num_annots': [2, 1, 3, 5, 1], } # make consistent data grouped_data = [[ col_getter_dict['name'][index] + '-' + str(i) for i in range(num) ] for index, num in enumerate(col_getter_dict['num_annots'])] flat_data, reverse_list = ut.invertible_flatten1(grouped_data) col_getter_dict['annots'] = flat_data iders = [list(range(len(col_getter_dict['name']))), reverse_list] col_level_dict = { 'name': 0, 'num_annots': 0, 'annots': 1, } sortby = 'name' api = gt.CustomAPI( col_name_list=col_name_list, col_getter_dict=col_getter_dict, sortby=sortby, iders=iders, col_level_dict=col_level_dict, ) headers = api.make_headers(tblnice='Tree Example') wgt = gt.APIItemWidget(view_class=APITreeView) wgt.change_headers(headers) wgt.menubar = gt.newMenubar(wgt) wgt.menuFile = wgt.menubar.newMenu('Dev') def wgt_embed(wgt): view = wgt.view # NOQA import utool utool.embed() ut.inject_func_as_method(wgt, wgt_embed) wgt.menuFile.newAction(triggered=wgt.wgt_embed) return wgt
def simple_thumbnail_widget(): r""" Very simple example to test thumbnails CommandLine: python -m wbia.guitool.api_thumb_delegate --test-simple_thumbnail_widget --show --verbthumb python -m wbia.guitool.api_thumb_delegate --test-simple_thumbnail_widget --show --tb Example: >>> # GUI_DOCTEST >>> # xdoctest: +REQUIRES(--gui) >>> from wbia.guitool.api_thumb_delegate import * # NOQA >>> import wbia.guitool >>> guitool.ensure_qapp() # must be ensured before any embeding >>> wgt = simple_thumbnail_widget() >>> ut.quit_if_noshow() >>> wgt.show() >>> guitool.qtapp_loop(wgt, frequency=100) """ from wbia import guitool guitool.ensure_qapp() col_name_list = ['rowid', 'image_name', 'thumb'] col_types_dict = { 'thumb': 'PIXMAP', } guitool_test_thumbdir = ut.ensure_app_resource_dir('guitool', 'thumbs') ut.delete(guitool_test_thumbdir) ut.ensuredir(guitool_test_thumbdir) import vtool as vt from os.path import join # imgname_list = sorted(ut.TESTIMG_URL_DICT.keys()) imgname_list = ['carl.jpg', 'lena.png', 'patsy.jpg'] imgname_list += ['doesnotexist.jpg'] num_imgs = list(range(len(imgname_list))) # num_imgs = list(range(500)) def thread_func(would_be, id_): from vtool.fontdemo import get_text_test_img get_text_test_img(id_) def thumb_getter(id_, thumbsize=128): """ Thumb getters must conform to thumbtup structure """ if id_ not in imgname_list: return { 'fpath': id_ + '.jpg', 'thread_func': thread_func, 'main_func': lambda: (id_, ), } # print(id_) if id_ == 'doesnotexist.jpg': return None img_path = None img_size = (100, 100) else: img_path = ut.grab_test_imgpath(id_, verbose=False) img_size = vt.open_image_size(img_path) thumb_path = join(guitool_test_thumbdir, ut.hashstr(str(img_path)) + '.jpg') if id_ == 'carl.jpg': bbox_list = [(10, 10, 200, 200)] theta_list = [0] elif id_ == 'lena.png': # bbox_list = [(10, 10, 200, 200)] bbox_list = [None] theta_list = [None] else: bbox_list = [] theta_list = [] interest_list = [False] thumbtup = (thumb_path, img_path, img_size, bbox_list, theta_list, interest_list) # print('thumbtup = %r' % (thumbtup,)) return thumbtup # return None def imgname_getter(rowid): if rowid < len(imgname_list): return imgname_list[rowid] else: return str(rowid) col_getter_dict = { 'rowid': num_imgs, 'image_name': imgname_getter, 'thumb': thumb_getter, } col_ider_dict = { 'thumb': 'image_name', } col_setter_dict = {} editable_colnames = [] sortby = 'rowid' def get_thumb_size(): return 128 # get_thumb_size = lambda: 128 # NOQA col_width_dict = {} col_bgrole_dict = {} api = guitool.CustomAPI( col_name_list, col_types_dict, col_getter_dict, col_bgrole_dict, col_ider_dict, col_setter_dict, editable_colnames, sortby, get_thumb_size, True, col_width_dict, ) headers = api.make_headers(tblnice='Utool Test Images') wgt = guitool.APIItemWidget() wgt.change_headers(headers) wgt.resize(600, 400) # guitool.qtapp_loop(qwin=wgt, ipy=ipy, frequency=loop_freq) return wgt
def simple_thumbnail_widget(): r""" Very simple example to test thumbnails CommandLine: python -m wbia.guitool.api_item_model --test-simple_thumbnail_widget --show Example: >>> # ENABLE_DOCTEST >>> # xdoctest: +REQUIRES(--gui) >>> import wbia.guitool as guitool >>> from wbia.guitool.api_item_model import * # NOQA >>> guitool.ensure_qapp() # must be ensured before any embeding >>> wgt = simple_thumbnail_widget() >>> ut.quit_if_noshow() >>> wgt.show() >>> guitool.qtapp_loop(wgt, frequency=100, init_signals=True) """ import wbia.guitool as guitool guitool.ensure_qapp() col_name_list = ['rowid', 'image_name', 'thumb'] col_types_dict = { 'thumb': 'PIXMAP', } def thumb_getter(id_, thumbsize=128): """ Thumb getters must conform to thumbtup structure """ # logger.info(id_) return ut.grab_test_imgpath(id_) # return None col_getter_dict = { 'rowid': [1, 2, 3], 'image_name': ['lena.png', 'carl.jpg', 'patsy.jpg'], 'thumb': thumb_getter, } col_ider_dict = { 'thumb': 'image_name', } col_setter_dict = {} editable_colnames = [] sortby = 'rowid' def get_thumb_size(): return 128 col_width_dict = {} col_bgrole_dict = {} api = guitool.CustomAPI( col_name_list, col_types_dict, col_getter_dict, col_bgrole_dict, col_ider_dict, col_setter_dict, editable_colnames, sortby, get_thumb_size, True, col_width_dict, ) headers = api.make_headers(tblnice='Simple Example') wgt = guitool.APIItemWidget() wgt.change_headers(headers) # guitool.qtapp_loop(qwin=wgt, ipy=ipy, frequency=loop_freq) return wgt
def make_review_api(ibs, cm_list, review_cfg, qreq_=None): """ Builds columns which are displayable in a ColumnListTableWidget CommandLine: python -m wbia.gui.id_review_api --test-test_review_widget --show python -m wbia.gui.id_review_api --test-make_review_api Example: >>> # ENABLE_DOCTEST >>> from wbia.gui.id_review_api import * # NOQA >>> import wbia >>> import wbia.guitool as gt >>> from wbia.gui import id_review_api >>> cm_list, qreq_ = wbia.main_helpers.testdata_cmlist() >>> tblname = 'chipmatch' >>> name_scoring = False >>> ranks_top = 5 >>> review_cfg = dict(ranks_top=ranks_top, name_scoring=name_scoring) >>> review_api = make_review_api(qreq_.ibs, cm_list, review_cfg, qreq_=qreq_) >>> print('review_api = %r' % (review_api,)) """ # TODO: Add in timedelta to column info if ut.VERBOSE: logger.info('[inspect] make_review_api') review_edges = get_review_edges(cm_list, ibs=ibs, review_cfg=review_cfg) # Get extra info (qaids, daids, scores, ranks) = review_edges RES_THUMB_TEXT = 'ResThumb' # NOQA QUERY_THUMB_TEXT = 'querythumb' MATCH_THUMB_TEXT = 'MatchThumb' col_name_list = [ 'result_index', 'score', REVIEWED_STATUS_TEXT, ] if review_cfg.get('show_chips', True): col_name_list += [ MATCHED_STATUS_TEXT, QUERY_THUMB_TEXT, ] col_name_list += [ RES_THUMB_TEXT, 'qaid', 'aid', 'rank', 'timedelta', 'dnGt', 'qnGt', 'tags', 'qname', 'name', ] col_types_dict = dict([ ('qaid', int), ('aid', int), ('dnGt', int), ('qnGt', int), ('timedelta', float), # ('review', 'BUTTON'), (MATCHED_STATUS_TEXT, str), (REVIEWED_STATUS_TEXT, str), (QUERY_THUMB_TEXT, 'PIXMAP'), (RES_THUMB_TEXT, 'PIXMAP'), ('qname', str), ('name', str), ('score', float), ('rank', int), ('truth', bool), ('opt', int), ('result_index', int), ]) timedelta_list = np.array( ut.take_column( ibs.get_unflat_annots_timedelta_list(list(zip(qaids, daids))), 0)) # TODO: make a display role # timediff_list = [ut.get_posix_timedelta_str(t, year=True, approx=True) for t in (timedelta_list * 60 * 60)] def get_pair_tags(edge): aid1, aid2 = edge assert not ut.isiterable(aid1), 'aid1=%r, aid2=%r' % (aid1, aid2) assert not ut.isiterable(aid2), 'aid1=%r, aid2=%r' % (aid1, aid2) am_rowids = ibs.get_annotmatch_rowid_from_undirected_superkey([aid1], [aid2]) tag_text = ibs.get_annotmatch_tag_text(am_rowids)[0] if tag_text is None: tag_text = '' return str(tag_text) col_getter_dict = dict([ ('qaid', np.array(qaids)), ('aid', np.array(daids)), ('dnGt', ibs.get_annot_num_groundtruth), ('qnGt', ibs.get_annot_num_groundtruth), ('timedelta', np.array(timedelta_list)), # ('review', lambda rowid: get_buttontup), (MATCHED_STATUS_TEXT, partial(get_match_status, ibs)), (REVIEWED_STATUS_TEXT, partial(get_reviewed_status, ibs)), (QUERY_THUMB_TEXT, ibs.get_annot_chip_thumbtup), (RES_THUMB_TEXT, ibs.get_annot_chip_thumbtup), ('qname', ibs.get_annot_names), ('name', ibs.get_annot_names), ('score', np.array(scores)), ('rank', np.array(ranks)), ('result_index', np.arange(len(ranks))), ('tags', get_pair_tags), # lambda aid_pair: ibs.get_annotmatch_tag_text(ibs.get_annotmatch_rowid_from_undirected_superkey(ut.ensure_iterable(aid_pair[0]), ut.ensure_iterable(aid_pair[1])))[0]), # ('truth', truths), # ('opt', opts), ]) # default is 100 col_width_dict = { 'score': 75, REVIEWED_STATUS_TEXT: 75, MATCHED_STATUS_TEXT: 75, 'rank': 42, 'qaid': 42, 'aid': 42, 'result_index': 42, 'qname': 60, 'name': 60, 'dnGt': 50, 'timedelta': 75, 'tags': 75, 'qnGt': 50, } USE_MATCH_THUMBS = 1 if USE_MATCH_THUMBS: def get_match_thumbtup( ibs, qaid2_cm, qaids, daids, index, qreq_=None, thumbsize=(128, 128), match_thumbtup_cache={}, ): daid = daids[index] qaid = qaids[index] cm = qaid2_cm[qaid] assert cm.qaid == qaid, 'aids do not aggree' OLD = False if OLD: fpath = ensure_match_img( ibs, cm, daid, qreq_=qreq_, match_thumbtup_cache=match_thumbtup_cache, ) if isinstance(thumbsize, int): thumbsize = (thumbsize, thumbsize) thumbtup = ( ut.augpath(fpath, 'thumb_%d,%d' % thumbsize), fpath, thumbsize, [], [], ) return thumbtup else: # Hacky new way of drawing fpath, func, func2 = make_ensure_match_img_nosql_func( qreq_, cm, daid) # match_thumbdir = ibs.get_match_thumbdir() # match_thumb_fname = get_match_thumb_fname(cm, daid, qreq_) # fpath = ut.unixjoin(match_thumbdir, match_thumb_fname) thumbdat = { 'fpath': fpath, 'thread_func': func, 'main_func': func2, # 'args': (ibs, cm, daid), # 'kwargs': dict(qreq_=qreq_, # match_thumbtup_cache=match_thumbtup_cache) } return thumbdat col_name_list.insert(col_name_list.index('qaid'), MATCH_THUMB_TEXT) col_types_dict[MATCH_THUMB_TEXT] = 'PIXMAP' # col_types_dict[MATCH_THUMB_TEXT] = CustomMatchThumbDelegate qaid2_cm = {cm.qaid: cm for cm in cm_list} get_match_thumbtup_ = partial( get_match_thumbtup, ibs, qaid2_cm, qaids, daids, qreq_=qreq_, match_thumbtup_cache={}, ) col_getter_dict[MATCH_THUMB_TEXT] = get_match_thumbtup_ col_bgrole_dict = { MATCHED_STATUS_TEXT: partial(get_match_status_bgrole, ibs), REVIEWED_STATUS_TEXT: partial(get_reviewed_status_bgrole, ibs), } # TODO: remove ider dict. # it is massively unuseful col_ider_dict = { MATCHED_STATUS_TEXT: ('qaid', 'aid'), REVIEWED_STATUS_TEXT: ('qaid', 'aid'), 'tags': ('qaid', 'aid'), QUERY_THUMB_TEXT: ('qaid'), RES_THUMB_TEXT: ('aid'), 'dnGt': ('aid'), 'qnGt': ('qaid'), 'qname': ('qaid'), 'name': ('aid'), } col_setter_dict = { 'qname': ibs.set_annot_names, 'name': ibs.set_annot_names } editable_colnames = ['truth', 'notes', 'qname', 'name', 'opt'] sortby = 'score' def get_thumb_size(): return ibs.cfg.other_cfg.thumb_size col_display_role_func_dict = { 'timedelta': ut.partial(ut.get_posix_timedelta_str, year=True, approx=2), } if not review_cfg.get('show_chips', True): del col_getter_dict[QUERY_THUMB_TEXT] del col_getter_dict[RES_THUMB_TEXT] del col_types_dict[RES_THUMB_TEXT] del col_types_dict[QUERY_THUMB_TEXT] del col_ider_dict[RES_THUMB_TEXT] del col_ider_dict[QUERY_THUMB_TEXT] # del col_bgrole_dict[RES_THUMB_TEXT] # del col_bgrole_dict[QUERY_THUMB_TEXT] # Insert info into dict review_api = gt.CustomAPI( col_name_list=col_name_list, col_types_dict=col_types_dict, col_getter_dict=col_getter_dict, col_bgrole_dict=col_bgrole_dict, col_ider_dict=col_ider_dict, col_setter_dict=col_setter_dict, editable_colnames=editable_colnames, col_display_role_func_dict=col_display_role_func_dict, sortby=sortby, get_thumb_size=get_thumb_size, sort_reverse=True, col_width_dict=col_width_dict, ) # review_api.review_edges = review_edges return review_api