コード例 #1
0
ファイル: inspect_gui.py プロジェクト: byteyoo/ibeis
 def parse_column_tuples(self, col_name_list, col_types_dict, col_getters_dict,
                         col_bgrole_dict, col_ider_dict, col_setter_dict,
                         editable_colnames, sortby, sort_reverse=True):
     # Unpack the column tuples into names, getters, and types
     self.col_name_list = col_name_list
     self.col_type_list = [col_types_dict.get(colname, str) for colname in col_name_list]
     self.col_getter_list = [col_getters_dict.get(colname, str) for colname in col_name_list]  # First col is always a getter
     # Get number of rows / columns
     self.nCols = len(self.col_getter_list)
     self.nRows = 0 if self.nCols == 0 else len(self.col_getter_list[0])  # FIXME
     # Init iders to default and then overwite based on dict inputs
     self.col_ider_list = utool.alloc_nones(self.nCols)
     for colname, ider_colnames in six.iteritems(col_ider_dict):
         col = self.col_name_list.index(colname)
         # Col iders might have tuple input
         ider_cols = utool.uinput_1to1(self.col_name_list.index, ider_colnames)
         col_ider  = utool.uinput_1to1(lambda c: partial(self.get, c), ider_cols)
         self.col_ider_list[col] = col_ider
     # Init setters to data, and then overwrite based on dict inputs
     self.col_setter_list = list(self.col_getter_list)
     for colname, col_setter in six.iteritems(col_setter_dict):
         col = self.col_name_list.index(colname)
         self.col_setter_list[col] = col_setter
     # Init bgrole_getters to None, and then overwrite based on dict inputs
     self.col_bgrole_getter_list = [col_bgrole_dict.get(colname, None) for colname in self.col_name_list]
     # Mark edtiable columns
     self.col_edit_list = [name in editable_colnames for name in col_name_list]
     # Mark the sort column index
     if utool.is_str(sortby):
         self.col_sort_index = self.col_name_list.index(sortby)
     else:
         self.col_sort_index = sortby
     self.col_sort_reverse = sort_reverse
コード例 #2
0
ファイル: inspect_gui.py プロジェクト: byteyoo/ibeis
 def _infer_index(self, column, row):
     """ returns the row based on the columns iders.
     This is the identity for the default ider """
     ider_ = self.col_ider_list[column]
     if ider_ is None:
         return row
     return utool.uinput_1to1(lambda func: func(row), ider_)
コード例 #3
0
 def _infer_index(self, column, row):
     """
     returns the row based on the columns iders.
     This is the identity for the default ider
     """
     ider_ = self.col_ider_list[column]
     if ider_ is None:
         return row
     iderfunc = lambda func_: func_(row)
     return ut.uinput_1to1(iderfunc, ider_)
コード例 #4
0
ファイル: api_item_widget.py プロジェクト: Erotemic/guitool
    def parse_column_tuples(self,
                            col_name_list,
                            col_types_dict,
                            col_getter_dict,
                            col_bgrole_dict,
                            col_ider_dict,
                            col_setter_dict,
                            editable_colnames,
                            sortby,
                            sort_reverse=True,
                            strict=False,
                            **kwargs):
        """
        parses simple lists into information suitable for making guitool headers
        """
        # Unpack the column tuples into names, getters, and types
        if not strict:
            # slopply colname definitions
            flag_list = [colname in col_getter_dict for colname in col_name_list]
            if not all(flag_list):
                invalid_colnames = ut.compress(col_name_list, ut.not_list(flag_list))
                print('[api_item_widget] Warning: colnames=%r have no getters' % (invalid_colnames,))
                col_name_list = ut.compress(col_name_list, flag_list)
            # sloppy type inference
            for colname in col_name_list:
                getter_ = col_getter_dict[colname]
                if colname not in col_types_dict:
                    type_ = ut.get_homogenous_list_type(getter_)
                    if type_ is not None:
                        col_types_dict[colname] = type_
        # sloppy kwargs.
        # FIXME: explicitly list col_nice_dict
        col_nice_dict = kwargs.get('col_nice_dict', {})
        self.col_nice_list = [col_nice_dict.get(name, name) for name in col_name_list]

        self.col_name_list = col_name_list
        self.col_type_list = [col_types_dict.get(colname, str) for colname in col_name_list]
        self.col_getter_list = [col_getter_dict.get(colname, str) for colname in col_name_list]  # First col is always a getter
        # Get number of rows / columns
        self.nCols = len(self.col_getter_list)
        self.nRows = 0 if self.nCols == 0 else len(self.col_getter_list[0])  # FIXME
        # Init iders to default and then overwite based on dict inputs
        self.col_ider_list = ut.alloc_nones(self.nCols)
        for colname, ider_colnames in six.iteritems(col_ider_dict):
            try:
                col = self.col_name_list.index(colname)
                # Col iders might have tuple input
                ider_cols = ut.uinput_1to1(self.col_name_list.index, ider_colnames)
                col_ider  = ut.uinput_1to1(lambda c: partial(self.get, c), ider_cols)
                self.col_ider_list[col] = col_ider
                del col_ider
                del ider_cols
                del col
                del colname
            except Exception as ex:
                ut.printex(ex, keys=['colname', 'ider_colnames', 'col', 'col_ider', 'ider_cols'])
                raise
        # Init setters to data, and then overwrite based on dict inputs
        self.col_setter_list = list(self.col_getter_list)
        for colname, col_setter in six.iteritems(col_setter_dict):
            col = self.col_name_list.index(colname)
            self.col_setter_list[col] = col_setter
        # Init bgrole_getters to None, and then overwrite based on dict inputs
        self.col_bgrole_getter_list = [col_bgrole_dict.get(colname, None) for colname in self.col_name_list]
        # Mark edtiable columns
        self.col_edit_list = [name in editable_colnames for name in col_name_list]
        # Mark the sort column index
        if ut.is_str(sortby):
            self.col_sort_index = self.col_name_list.index(sortby)
        else:
            self.col_sort_index = sortby
        self.col_sort_reverse = sort_reverse
コード例 #5
0
    def parse_column_tuples(self,
                            col_name_list,
                            col_types_dict,
                            col_getter_dict,
                            col_bgrole_dict,
                            col_ider_dict,
                            col_setter_dict,
                            editable_colnames,
                            sortby,
                            sort_reverse=True,
                            strict=False,
                            **kwargs):
        """
        parses simple lists into information suitable for making guitool headers
        """
        # Unpack the column tuples into names, getters, and types
        if not strict:
            # slopply colname definitions
            flag_list = [
                colname in col_getter_dict for colname in col_name_list
            ]
            if not all(flag_list):
                invalid_colnames = ut.compress(col_name_list,
                                               ut.not_list(flag_list))
                print(
                    '[api_item_widget] Warning: colnames=%r have no getters' %
                    (invalid_colnames, ))
                col_name_list = ut.compress(col_name_list, flag_list)
            # sloppy type inference
            for colname in col_name_list:
                getter_ = col_getter_dict[colname]
                if colname not in col_types_dict:
                    type_ = ut.get_homogenous_list_type(getter_)
                    if type_ is not None:
                        col_types_dict[colname] = type_
        # sloppy kwargs.
        # FIXME: explicitly list col_nice_dict
        col_nice_dict = kwargs.get('col_nice_dict', {})
        self.col_nice_list = [
            col_nice_dict.get(name, name) for name in col_name_list
        ]

        self.col_name_list = col_name_list
        self.col_type_list = [
            col_types_dict.get(colname, str) for colname in col_name_list
        ]
        self.col_getter_list = [
            col_getter_dict.get(colname, str) for colname in col_name_list
        ]  # First col is always a getter
        # Get number of rows / columns
        self.nCols = len(self.col_getter_list)
        self.nRows = 0 if self.nCols == 0 else len(
            self.col_getter_list[0])  # FIXME
        # Init iders to default and then overwite based on dict inputs
        self.col_ider_list = ut.alloc_nones(self.nCols)
        for colname, ider_colnames in six.iteritems(col_ider_dict):
            try:
                col = self.col_name_list.index(colname)
                # Col iders might have tuple input
                ider_cols = ut.uinput_1to1(self.col_name_list.index,
                                           ider_colnames)
                col_ider = ut.uinput_1to1(lambda c: partial(self.get, c),
                                          ider_cols)
                self.col_ider_list[col] = col_ider
                del col_ider
                del ider_cols
                del col
                del colname
            except Exception as ex:
                ut.printex(ex,
                           keys=[
                               'colname', 'ider_colnames', 'col', 'col_ider',
                               'ider_cols'
                           ])
                raise
        # Init setters to data, and then overwrite based on dict inputs
        self.col_setter_list = list(self.col_getter_list)
        for colname, col_setter in six.iteritems(col_setter_dict):
            col = self.col_name_list.index(colname)
            self.col_setter_list[col] = col_setter
        # Init bgrole_getters to None, and then overwrite based on dict inputs
        self.col_bgrole_getter_list = [
            col_bgrole_dict.get(colname, None)
            for colname in self.col_name_list
        ]
        # Mark edtiable columns
        self.col_edit_list = [
            name in editable_colnames for name in col_name_list
        ]
        # Mark the sort column index
        if ut.is_str(sortby):
            self.col_sort_index = self.col_name_list.index(sortby)
        else:
            self.col_sort_index = sortby
        self.col_sort_reverse = sort_reverse