📚 The CoCalc Library - books, templates and other resources
License: OTHER
#!/usr/bin/env python1#2# Copyright 2019 the original author or authors.3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15#16import pygame17from cmath import isclose18from vqe_playground.utils.colors import WHITE, BLACK19from vqe_playground.utils.fonts import *202122class MatrixLabel(pygame.sprite.Sprite):23"""Displays a label on the headers of a matrix"""24def __init__(self, label, width, height):25pygame.sprite.Sprite.__init__(self)26self.label = label27self.width = width28self.height = height2930self.image = None31self.rect = None32# self.background_color = WHITE33self.background_color = BLACK34self.font_color = BLACK35self.font = ARIAL_363637self.draw_matrix_label()3839def draw_matrix_label(self):40self.image = pygame.Surface([self.width, self.height])41self.image.convert()42self.image.fill(WHITE)43self.rect = self.image.get_rect()4445text_surface = self.font.render(self.label, False, BLACK)46text_xpos = (self.rect.width - text_surface.get_rect().width) / 247text_ypos = (self.rect.height - text_surface.get_rect().height) / 248self.image.blit(text_surface, (text_xpos, text_ypos))49505152