def _check_option(option): if option in COLUMN_OPTIONS: return True raise PyrusticTableException( "The column option -" + option + " doesn't exist. These are legal options for column: " + str(COLUMN_OPTIONS))
def __reset_data(self, data): if not data: return if not self.__titles: raise PyrusticTableException("Please submit titles first !") # check data self.__check_data_row_size(data) # clean listboxes self.clear() self.__insert(0, data)
def __reset_titles(self, titles): if not titles: return if not self.__titles: self.__titles = titles self.__build_table() elif self.__titles and len(titles) == len(self.__titles): for i, title in enumerate(titles): self.__labels_titles_stringvars_cache[i].set(title) else: raise PyrusticTableException("Incorrect length of titles")
def __check_data_row_size(self, data): regular_size = len(self.__titles) - len(self.__hidden_columns) for row in data: if (len(row) - len(self.__hidden_columns)) != regular_size: raise PyrusticTableException("Invalid data size") return True
def __init__(self, master=None, titles=None, data=None, hidden_columns=None, sorting=True, mask=None, select_mode=BROWSE, layout=EQUALLY, orient=BOTH, cnfs=None): """ PARAMETERS: - master: widget parent. Example: an instance of tk.Frame - titles: sequence of titles. Example: ("Name", "Job") - data: sequence of sequences. Each sub-sequence must have same size as titles. Example: ( ("Jack, "Architect"), ("Diana", "Physicist") ) - hidden_columns: sequence of columns to hide. Example: (1, 2) will hide the column at the index 1 and 2. Example: (0, ) will hide only the first column - sorting: boolean, set to True if you want the table to be able to do sorting when user clicks on a column title. Default: True - mask: a callable that will be called at each insertion of line of data in the table. The mask must accept 2 arguments: - index: int, index of the row (line) - data: the sequence of strings to insert at this given row The mask must returns a new data with same length or the same old data - select_mode: selection modes: SINGLE, BROWSE, MULTIPLE and EXTENDED. Default: SINGLE. Selection modes are the same as described in the tk.Listbox's documentation. - layout: EQUALLY or PROPORTIONALLY. Default: EQUALLY - orient: orientation for scrollbars. BOTH or VERTICAL or HORIZONTAL - options: dictionary of widgets options The widgets keys are: BODY, VSB, HSB, CANVAS, FRAME_BACKGROUND, FRAMES_HEADERS, LISTBOXES_COLUMNS, LABELS_SORTING and LABELS_TITLES. Example: Assume that you want to set the BODY's background to black and the horizontal scrollbar's background to red: options = {"BODY": {"background": "red"}, "HSB": {"background": "black"}} """ self.__cnfs = merge_cnfs(None, cnfs, components=("body", VSB, HSB, CANVAS, FRAME_BACKGROUND, FRAMES_HEADERS, LISTBOXES_COLUMNS, LABELS_SORTING, LABELS_TITLES)) super().__init__(master=master, class_="Table", cnf=self.__cnfs["body"], on_build=self.__on_build, on_display=self.__on_display, on_destroy=self.__on_destroy) # check if listboxes options are valid _verify_options(self.__cnfs[LISTBOXES_COLUMNS]) self.__titles_cache = () if titles is None else titles self.__titles = [] self.__data_cache = () if data is None else data self.__data = [] self.__hidden_columns = ( ) if hidden_columns is None else hidden_columns self.__sorting = sorting self.__mask = mask self.__select_mode = select_mode self.__layout = layout self.__orient = orient self.__canvas_options = None self.__frame_background_options = None self.__frames_headers_options = None self.__labels_sorting_options = None self.__labels_titles_options = None self.__listboxes_columns_options = None # misc self.__components = {} self.__cache = None self.__current_sorting = None self.__current_column_index = None self.__current_row_index = None self.__selection_garbage = None self.__selection = None self.__header_clicked_handlers = [] self.__header_event_handlers = {} self.__row_selected_handlers = [] self.__row_event_handlers = {} self.__default_listbox_background = None self.__default_listbox_foreground = None self.__default_listbox_selectbackground = None self.__default_listbox_selectforeground = None # cache for sorting's labels, header's labels and listboxes self.__header_frames_cache = [] self.__labels_sorting_cache = [] self.__labels_titles_cache = [] self.__listboxes_cache = [] # string vars cache self.__labels_sorting_stringvars_cache = [] self.__labels_titles_stringvars_cache = [] # components self.__canvas = None self.__background = None self.__background_id = None self.__vsb = None self.__hsb = None self.__hsb_under_mouse = False # Sorry but the select_mode MULTIPLE is buggy if select_mode == MULTIPLE: raise PyrusticTableException( "Sorry but the selection mode MULTIPLE is buggy") self.__view = self.build()