def get_char(self, char, color): log.critical("Generate char %s %s", repr(char), color) try: char_data = self.chars_dict[char] except KeyError: log.log(99, "Error: character %s is not in CHARS_DICT !", repr(char)) # return self._generate_char(char="?", color=color) return self.get_char(char="?", color=color) foreground, background = get_hex_color(color) foreground = "#%s" % foreground background = "#%s" % background img = tkinter.PhotoImage(width=self.width_scaled, height=self.height_scaled) # Fill the character pixels without padding for y, line in enumerate(char_data): for x, bit in enumerate(line): if bit == BACKGROUND_CHAR: color = background else: assert bit == FOREGROUND_CHAR color = foreground img.put(color, (x, y)) # resize the character if self.scale_factor > 1: img = img.zoom(self.scale_factor, self.scale_factor) return img
def get_char(self, char, color): log.critical("Generate char %s %s", repr(char), color) try: char_data = self.chars_dict[char] except KeyError: log.log(99, "Error: character %s is not in CHARS_DICT !", repr(char)) # return self._generate_char(char="?", color=color) return self.get_char(char="?", color=color) foreground, background = get_hex_color(color) foreground = "#%s" % foreground background = "#%s" % background img = tkinter.PhotoImage( width=self.width_scaled, height=self.height_scaled ) # Fill the character pixels without padding for y, line in enumerate(char_data): for x, bit in enumerate(line): if bit == BACKGROUND_CHAR: color = background else: assert bit == FOREGROUND_CHAR color = foreground img.put(color, (x, y)) # resize the character if self.scale_factor > 1: img = img.zoom(self.scale_factor, self.scale_factor) return img
def __init__(self, root): self.rows = 32 self.columns = 16 scale_factor = 2 # scale the complete Display/Characters self.tk_font = TkImageFont(CHARS_DICT, scale_factor) # to generate PhotoImage() self.total_width = self.tk_font.width_scaled * self.rows self.total_height = self.tk_font.height_scaled * self.columns foreground, background = dragon_charmap.get_hex_color( dragon_charmap.NORMAL) self.canvas = tkinter.Canvas( root, width=self.total_width, height=self.total_height, bd=0, # no border highlightthickness=0, # no highlight border # bg="#ff0000", bg="#%s" % background, ) # Contains the map from Display RAM value to char/color: self.charmap = get_charmap_dict() # Cache for the generated Tkinter.PhotoImage() in evry char/color combination: self.image_cache = {} # Tkinter.PhotoImage() IDs for image replace with canvas.itemconfigure(): self.images_map = {} # Create all charachter images on the display and fill self.images_map: self.init_img = self.tk_font.get_char(char="?", color=dragon_charmap.INVERTED) for row in xrange(self.rows + 1): for column in xrange(self.columns + 1): x = self.tk_font.width_scaled * row y = self.tk_font.height_scaled * column image_id = self.canvas.create_image( x, y, image=self.init_img, state="normal", anchor=tkinter.NW # NW == NorthWest ) # log.critical("Image ID: %s at %i x %i", image_id, x, y) self.images_map[(x, y)] = image_id
def __init__(self, root): self.rows = 32 self.columns = 16 scale_factor = 2 # scale the complete Display/Characters self.tk_font = TkImageFont(CHARS_DICT, scale_factor) # to generate PhotoImage() self.total_width = self.tk_font.width_scaled * self.rows self.total_height = self.tk_font.height_scaled * self.columns foreground, background = dragon_charmap.get_hex_color(dragon_charmap.NORMAL) self.canvas = tkinter.Canvas(root, width=self.total_width, height=self.total_height, bd=0, # no border highlightthickness=0, # no highlight border # bg="#ff0000", bg="#%s" % background, ) # Contains the map from Display RAM value to char/color: self.charmap = get_charmap_dict() # Cache for the generated Tkinter.PhotoImage() in evry char/color combination: self.image_cache = {} # Tkinter.PhotoImage() IDs for image replace with canvas.itemconfigure(): self.images_map = {} # Create all charachter images on the display and fill self.images_map: self.init_img = self.tk_font.get_char(char="?", color=dragon_charmap.INVERTED) for row in xrange(self.rows + 1): for column in xrange(self.columns + 1): x = self.tk_font.width_scaled * row y = self.tk_font.height_scaled * column image_id = self.canvas.create_image(x, y, image=self.init_img, state="normal", anchor=tkinter.NW # NW == NorthWest ) # log.critical("Image ID: %s at %i x %i", image_id, x, y) self.images_map[(x, y)] = image_id