def build(source_key, color_scheme, alternatives): key_sequence = [] for i, label in enumerate(alternatives): key = RectKey("_alternative" + str(i)) key.type = KeyCommon.CHAR_TYPE key.labels = {0: label} key.code = label[0] key_sequence.append(key) return LayoutBuilderKeySequence.build(source_key, color_scheme, key_sequence)
def _layout_sequence(sequence): """ Split sequence into lines. """ max_columns = LayoutBuilderAlternatives.MAX_KEY_COLUMNS min_columns = max_columns // 2 add_close = False fill_gaps = True # find the number of columns with the best packing, # i.e. the least number of empty slots. n = len(sequence) if add_close: n += 1 # +1 for close button max_mod = 0 ncolumns = max_columns for i in range(max_columns, min_columns, -1): m = n % i if m == 0: max_mod = m ncolumns = i break if max_mod < m: max_mod = m ncolumns = i # limit to len for the single row case ncolumns = min(n, ncolumns) # cut the input into lines of the newly found optimal length lines = [] line = [] column = 0 for item in sequence: line.append(item) column += 1 if column >= ncolumns: lines.append(line) line = [] column = 0 # append close button if add_close: n = len(line) line.extend([None]*(ncolumns - (n+1))) key = RectKey("_close_") key.labels = {} key.image_filenames = {ImageSlot.NORMAL : "close.svg"} key.type = KeyCommon.BUTTON_TYPE line.append(key) # fill empty slots with dummy buttons if fill_gaps: n = len(line) if n: for i in range(ncolumns - n): key = RectKey("_dummy_") key.sensitive = False line.append(key) if line: lines.append(line) return lines, ncolumns
def _layout_sequence(sequence): """ Split sequence into lines. """ max_columns = LayoutBuilderAlternatives.MAX_KEY_COLUMNS min_columns = max_columns // 2 add_close = False fill_gaps = True # find the number of columns with the best packing, # i.e. the least number of empty slots. n = len(sequence) if add_close: n += 1 # +1 for close button max_mod = 0 ncolumns = max_columns for i in range(max_columns, min_columns, -1): m = n % i if m == 0: max_mod = m ncolumns = i break if max_mod < m: max_mod = m ncolumns = i # limit to len for the single row case ncolumns = min(n, ncolumns) # cut the input into lines of the newly found optimal length lines = [] line = [] column = 0 for item in sequence: line.append(item) column += 1 if column >= ncolumns: lines.append(line) line = [] column = 0 # append close button if add_close: n = len(line) line.extend([None] * (ncolumns - (n + 1))) key = RectKey("_close_") key.labels = {} key.image_filenames = {ImageSlot.NORMAL: "close.svg"} key.type = KeyCommon.BUTTON_TYPE line.append(key) # fill empty slots with dummy buttons if fill_gaps: n = len(line) if n: for i in range(ncolumns - n): key = RectKey("_dummy_") key.sensitive = False line.append(key) if line: lines.append(line) return lines, ncolumns