def paint_cell(self, drawing_context: DrawingContext.DrawingContext, rect: Geometry.IntRect, style: typing.Set[str]) -> None: # disabled (default is enabled) # checked, partial (default is unchecked) # hover, active (default is none) drawing_context.text_baseline = "middle" drawing_context.text_align = "center" drawing_context.fill_style = "#000" drawing_context.fill_text(self.__text, rect.center.x, rect.center.y) overlay_color = None if "disabled" in style: overlay_color = "rgba(255, 255, 255, 0.5)" else: if "active" in style: overlay_color = "rgba(128, 128, 128, 0.5)" elif "hover" in style: overlay_color = "rgba(128, 128, 128, 0.1)" drawing_context.fill_style = "#444" drawing_context.fill() drawing_context.stroke_style = "#444" drawing_context.stroke() if overlay_color: rect_args = rect[0][1], rect[0][0], rect[1][1], rect[1][0] drawing_context.begin_path() drawing_context.rect(*rect_args) drawing_context.fill_style = overlay_color drawing_context.fill()
def _repaint_visible(self, drawing_context: DrawingContext.DrawingContext, visible_rect: Geometry.IntRect) -> None: canvas_bounds = self.canvas_bounds if self.__delegate and canvas_bounds: item_width = canvas_bounds.width item_height = self.__item_height with drawing_context.saver(): items = self.__delegate.items max_index = len(items) top_visible_row = visible_rect.top // item_height bottom_visible_row = visible_rect.bottom // item_height for index in range(top_visible_row, bottom_visible_row + 1): if 0 <= index < max_index: rect = Geometry.IntRect(origin=Geometry.IntPoint(y=index * item_height, x=0), size=Geometry.IntSize(width=item_width, height=item_height)) if rect.intersects_rect(visible_rect): is_selected = self.__selection.contains(index) if is_selected: with drawing_context.saver(): drawing_context.begin_path() drawing_context.rect(rect.left, rect.top, rect.width, rect.height) drawing_context.fill_style = "#3875D6" if self.focused else "#DDD" drawing_context.fill() self.__delegate.paint_item(drawing_context, items[index], rect, is_selected) if index == self.__drop_index: with drawing_context.saver(): drop_border_width = 2.5 rect_in = rect.to_float_rect().inset(drop_border_width / 2, drop_border_width / 2).to_int_rect() drawing_context.begin_path() drawing_context.rect(rect_in.left, rect_in.top, rect_in.width, rect_in.height) drawing_context.line_width = drop_border_width drawing_context.stroke_style = "rgba(56, 117, 214, 0.8)" drawing_context.stroke()
def _repaint(self, drawing_context: DrawingContext.DrawingContext) -> None: """Repaint the canvas item. This will occur on a thread.""" canvas_size = self.canvas_size if canvas_size: # draw background if self.background_color: with drawing_context.saver(): drawing_context.begin_path() drawing_context.move_to(0, 0) drawing_context.line_to(canvas_size.width, 0) drawing_context.line_to(canvas_size.width, canvas_size.height) drawing_context.line_to(0, canvas_size.height) drawing_context.close_path() drawing_context.fill_style = self.background_color drawing_context.fill() # draw the data, if any if (self.data is not None and len(self.data) > 0): # draw the histogram itself with drawing_context.saver(): drawing_context.begin_path() binned_data = Image.rebin_1d(self.data, int(canvas_size.width), self.__retained_rebin_1d) if int(canvas_size.width) != self.data.shape[0] else self.data for i in range(canvas_size.width): drawing_context.move_to(i, canvas_size.height) drawing_context.line_to(i, canvas_size.height * (1 - binned_data[i])) drawing_context.line_width = 1 drawing_context.stroke_style = "#444" drawing_context.stroke()
def _repaint_visible(self, drawing_context: DrawingContext.DrawingContext, visible_rect: Geometry.IntRect) -> None: canvas_size = self.canvas_size if self.__delegate and canvas_size and canvas_size.height > 0 and canvas_size.width > 0: item_size = self.__calculate_item_size(canvas_size) items = self.__delegate.items if self.__delegate else list() item_count = len(items) items_per_row = max(1, int(canvas_size.width / item_size.width) if self.wrap else item_count) items_per_column = max(1, int(canvas_size.height / item_size.height) if self.wrap else item_count) with drawing_context.saver(): top_visible_row = visible_rect.top // item_size.height bottom_visible_row = visible_rect.bottom // item_size.height left_visible_column = visible_rect.left // item_size.width right_visible_column = visible_rect.right // item_size.width for row in range(top_visible_row, bottom_visible_row + 1): for column in range(left_visible_column, right_visible_column + 1): if self.direction == Direction.Row: index = row * items_per_row + column else: index = row + column * items_per_column if 0 <= index < item_count: rect = Geometry.IntRect(origin=Geometry.IntPoint(y=row * item_size.height, x=column * item_size.width), size=Geometry.IntSize(width=item_size.width, height=item_size.height)) if rect.intersects_rect(visible_rect): is_selected = self.__selection.contains(index) if is_selected: with drawing_context.saver(): drawing_context.begin_path() drawing_context.rect(rect.left, rect.top, rect.width, rect.height) drawing_context.fill_style = "#3875D6" if self.focused else "#BBB" drawing_context.fill() self.__delegate.paint_item(drawing_context, items[index], rect, is_selected)
def _repaint(self, drawing_context: DrawingContext.DrawingContext) -> None: super()._repaint(drawing_context) if self.active: with drawing_context.saver(): drawing_context.begin_path() drawing_context.round_rect(2, 2, 6, 6, 3) drawing_context.fill_style = "rgba(0, 255, 0, 0.80)" drawing_context.fill()
def paint_cell(self, drawing_context: DrawingContext.DrawingContext, rect: Geometry.IntRect, style: typing.Set[str]) -> None: # style: "disabled" (default is enabled) margin_rect = rect.inset(4, 4) drawing_context.begin_path() drawing_context.rect(margin_rect.left, margin_rect.top, margin_rect.width, margin_rect.height) drawing_context.fill_style = "#BBB" drawing_context.fill() inset_rect = margin_rect.inset(4, 4) drawing_context.begin_path() drawing_context.rect(inset_rect.left, inset_rect.top, inset_rect.width, inset_rect.height) drawing_context.close_path() drawing_context.fill_style = self.__color drawing_context.fill() drawing_context.begin_path() drawing_context.move_to(inset_rect.right, inset_rect.top) drawing_context.line_to(inset_rect.right, inset_rect.bottom) drawing_context.line_to(inset_rect.left, inset_rect.bottom) drawing_context.close_path() drawing_context.fill_style = DrawingContext.color_without_alpha( self.__color) drawing_context.fill() drawing_context.begin_path() drawing_context.rect(inset_rect.left, inset_rect.top, inset_rect.width, inset_rect.height) drawing_context.stroke_style = "#454545" drawing_context.stroke() if "disabled" in style: drawing_context.begin_path() drawing_context.rect(margin_rect.left, margin_rect.top, margin_rect.width, margin_rect.height) drawing_context.fill_style = "rgba(255, 255, 255, 0.5)" drawing_context.fill()
def _repaint(self, drawing_context: DrawingContext.DrawingContext) -> None: canvas_size = self.canvas_size if not canvas_size: return with drawing_context.saver(): center_x = int(canvas_size.width * 0.5) center_y = int(canvas_size.height * 0.5) drawing_context.begin_path() text_base = 4 if sys.platform == "win32" else 6 drawing_context.begin_path() drawing_context.rect(0, 0, canvas_size.width, canvas_size.height) if self.enabled: if self.__mouse_inside: if self.__mouse_pressed: if self.fill_style_pressed: drawing_context.fill_style = self.fill_style_pressed drawing_context.fill() if self.border_style_pressed: drawing_context.stroke_style = self.border_style_pressed drawing_context.stroke() else: if self.fill_style_hover: drawing_context.fill_style = self.fill_style_hover drawing_context.fill() if self.border_style_hover: drawing_context.stroke_style = self.border_style_hover drawing_context.stroke() drawing_context.begin_path() drawing_context.text_align = "center" drawing_context.text_baseline = "bottom" drawing_context.fill_style = self.stroke_style drawing_context.fill_text(self.__char, center_x, center_y + text_base)
def _repaint(self, drawing_context: DrawingContext.DrawingContext) -> None: super()._repaint(drawing_context) # canvas size canvas_size = self.canvas_size if canvas_size: focused_style = "#3876D6" # TODO: platform dependent if self.active: with drawing_context.saver(): drawing_context.begin_path() drawing_context.round_rect(2, 2, 6, 6, 3) drawing_context.fill_style = "rgba(0, 255, 0, 0.80)" drawing_context.fill() if self.__dropping: with drawing_context.saver(): drawing_context.begin_path() drawing_context.rect(0, 0, canvas_size.width, canvas_size.height) drawing_context.fill_style = "rgba(255, 0, 0, 0.10)" drawing_context.fill() if self.focused: stroke_style = focused_style drawing_context.begin_path() drawing_context.rect(2, 2, canvas_size.width - 4, canvas_size.height - 4) drawing_context.line_join = "miter" drawing_context.stroke_style = stroke_style drawing_context.line_width = 4.0 drawing_context.stroke()
def _repaint(self, drawing_context: DrawingContext.DrawingContext) -> None: super()._repaint(drawing_context) with self.__drawing_context_lock: drawing_context.add(self.__drawing_context) if self.__display_frame_rate_id: Utility.fps_tick("display_" + self.__display_frame_rate_id) if self.__display_frame_rate_id: fps = Utility.fps_get("display_" + self.__display_frame_rate_id) fps2 = Utility.fps_get("frame_" + self.__display_frame_rate_id) fps3 = Utility.fps_get("update_" + self.__display_frame_rate_id) canvas_bounds = self.canvas_bounds if canvas_bounds: with drawing_context.saver(): font = "normal 11px serif" text_pos = canvas_bounds.top_right + Geometry.IntPoint( y=0, x=-100) drawing_context.begin_path() drawing_context.move_to(text_pos.x, text_pos.y) drawing_context.line_to(text_pos.x + 120, text_pos.y) drawing_context.line_to(text_pos.x + 120, text_pos.y + 60) drawing_context.line_to(text_pos.x, text_pos.y + 60) drawing_context.close_path() drawing_context.fill_style = "rgba(255, 255, 255, 0.6)" drawing_context.fill() drawing_context.font = font drawing_context.text_baseline = "middle" drawing_context.text_align = "left" drawing_context.fill_style = "#000" drawing_context.fill_text("display:" + fps, text_pos.x + 8, text_pos.y + 10) drawing_context.fill_text("frame:" + fps2, text_pos.x + 8, text_pos.y + 30) drawing_context.fill_text("update:" + fps3, text_pos.x + 8, text_pos.y + 50)
def _repaint(self, drawing_context: DrawingContext.DrawingContext) -> None: """Repaint the canvas item. This will occur on a thread.""" # canvas size canvas_size = self.canvas_size if canvas_size: left = self.display_limits[0] right = self.display_limits[1] # draw left display limit if left > 0.0: with drawing_context.saver(): drawing_context.begin_path() drawing_context.move_to(left * canvas_size.width, 1) drawing_context.line_to(left * canvas_size.width, canvas_size.height - 1) drawing_context.line_width = 2 drawing_context.stroke_style = "#000" drawing_context.stroke() # draw right display limit if right < 1.0: with drawing_context.saver(): drawing_context.begin_path() drawing_context.move_to(right * canvas_size.width, 1) drawing_context.line_to(right * canvas_size.width, canvas_size.height - 1) drawing_context.line_width = 2 drawing_context.stroke_style = "#FFF" drawing_context.stroke() # draw border with drawing_context.saver(): drawing_context.begin_path() drawing_context.move_to(0, canvas_size.height) drawing_context.line_to(canvas_size.width, canvas_size.height) drawing_context.line_width = 1 drawing_context.stroke_style = "#444" drawing_context.stroke()
def _repaint(self, drawing_context: DrawingContext.DrawingContext) -> None: canvas_size = self.canvas_size if canvas_size: with drawing_context.saver(): drawing_context.begin_path() drawing_context.move_to(0, 1) drawing_context.line_to(0, canvas_size.height) drawing_context.line_to(canvas_size.width, canvas_size.height) drawing_context.line_to(canvas_size.width, 1) drawing_context.close_path() gradient = drawing_context.create_linear_gradient( canvas_size.width, canvas_size.height, 0, 0, 0, canvas_size.height) gradient.add_color_stop(0, self.__start_header_color) gradient.add_color_stop(1, self.__end_header_color) drawing_context.fill_style = gradient drawing_context.fill() with drawing_context.saver(): drawing_context.begin_path() # line is adjust 1/2 pixel down to align to pixel boundary drawing_context.move_to(0, 0.5 + self.__top_offset) drawing_context.line_to(canvas_size.width, 0.5 + self.__top_offset) drawing_context.stroke_style = self.__top_stroke_style drawing_context.stroke() with drawing_context.saver(): drawing_context.begin_path() # line is adjust 1/2 pixel down to align to pixel boundary drawing_context.move_to(0, canvas_size.height - 0.5) drawing_context.line_to(canvas_size.width, canvas_size.height - 0.5) drawing_context.stroke_style = self.__bottom_stroke_style drawing_context.stroke() if self.__side_stroke_style: with drawing_context.saver(): drawing_context.begin_path() # line is adjust 1/2 pixel down to align to pixel boundary drawing_context.move_to(0.5, 1.5) drawing_context.line_to(0.5, canvas_size.height - 0.5) drawing_context.move_to(canvas_size.width - 0.5, 1.5) drawing_context.line_to(canvas_size.width - 0.5, canvas_size.height - 0.5) drawing_context.stroke_style = self.__side_stroke_style drawing_context.stroke() if self.__display_close_control: with drawing_context.saver(): drawing_context.begin_path() close_box_left = canvas_size.width - (20 - 7) close_box_right = canvas_size.width - (20 - 13) close_box_top = canvas_size.height // 2 - 3 close_box_bottom = canvas_size.height // 2 + 3 drawing_context.move_to(close_box_left, close_box_top) drawing_context.line_to(close_box_right, close_box_bottom) drawing_context.move_to(close_box_left, close_box_bottom) drawing_context.line_to(close_box_right, close_box_top) drawing_context.line_width = 1.5 drawing_context.line_cap = "round" drawing_context.stroke_style = self.__control_style drawing_context.stroke() with drawing_context.saver(): drawing_context.font = self.__font drawing_context.text_align = 'left' drawing_context.text_baseline = 'bottom' drawing_context.fill_style = '#888' drawing_context.fill_text( self.label, 8, canvas_size.height - self.__text_offset) with drawing_context.saver(): drawing_context.font = self.__font drawing_context.text_align = 'center' drawing_context.text_baseline = 'bottom' drawing_context.fill_style = '#000' drawing_context.fill_text( self.title, canvas_size.width // 2, canvas_size.height - self.__text_offset)