def _create_layout(source_key, color_scheme, lines, ncolumns): context = source_key.context frame_width = LayoutBuilderKeySequence._calc_frame_width(context) nrows = len(lines) spacing = (1, 1) # calc canvas size rect = source_key.get_canvas_border_rect() layout_canvas_rect = Rect( frame_width, frame_width, rect.w * ncolumns + spacing[0] * (ncolumns - 1), rect.h * nrows + spacing[1] * (nrows - 1)) # subdive into logical rectangles for the keys layout_rect = context.canvas_to_log_rect(layout_canvas_rect) key_rects = layout_rect.subdivide(ncolumns, nrows, *spacing) # create keys, slots for empty labels are skipped keys = [] for i, line in enumerate(lines): for j, item in enumerate(line): slot = i * ncolumns + j if item: # control item? key = item key.set_border_rect(key_rects[slot]) key.group = "alternatives" key.color_scheme = color_scheme keys.append(key) item = LayoutPanel() item.border = 0 item.set_items(keys) layout = LayoutRoot(item) layout.fit_inside_canvas(layout_canvas_rect) return layout, frame_width
def _create_layout(source_key, color_scheme, lines, ncolumns): context = source_key.context frame_width = LayoutBuilderKeySequence._calc_frame_width(context) nrows = len(lines) spacing = (1, 1) # calc canvas size rect = source_key.get_canvas_border_rect() layout_canvas_rect = Rect(frame_width, frame_width, rect.w * ncolumns + spacing[0] * (ncolumns - 1), rect.h * nrows + spacing[1] * (nrows - 1)) # subdive into logical rectangles for the keys layout_rect = context.canvas_to_log_rect(layout_canvas_rect) key_rects = layout_rect.subdivide(ncolumns, nrows, *spacing) # create keys, slots for empty labels are skipped keys = [] for i, line in enumerate(lines): for j, item in enumerate(line): slot = i * ncolumns + j if item: # control item? key = item key.set_border_rect(key_rects[slot]) key.group = "alternatives" key.color_scheme = color_scheme keys.append(key) item = LayoutPanel() item.border = 0 item.set_items(keys) layout = LayoutRoot(item) layout.fit_inside_canvas(layout_canvas_rect) return layout, frame_width
def build(source_key, color_scheme, layout): context = source_key.context frame_width = LayoutBuilder._calc_frame_width(context) layout = LayoutRoot(layout) layout.update_log_rect() log_rect = layout.get_border_rect() canvas_rect = Rect(frame_width, frame_width, log_rect.w * context.scale_log_to_canvas_x(1.0), log_rect.h * context.scale_log_to_canvas_y(1.0)) layout.fit_inside_canvas(canvas_rect) return layout, frame_width
def load(self, vk, layout_filename, color_scheme): """ Load layout root file. """ self._system_layout, self._system_variant = \ self._get_system_keyboard_layout(vk) _logger.info("current system keyboard layout(variant): '{}'" \ .format(self._get_system_layout_string())) layout = self._load(vk, layout_filename, color_scheme, os.path.dirname(layout_filename)) if layout: # purge attributes only used during loading for item in layout.iter_items(): item.templates = None item.keysym_rules = None # enable caching layout = LayoutRoot(layout) return layout