示例#1
0
    def create_canvas(self, rang, function, size, pos, surface):
        fig = pylab.figure(
            figsize=list(size),  # Inches
            dpi=1,
            facecolor=(
                0.0, 0.0, 0.0, 1.0
            )  # 100 dots per inch, so the resulting buffer is 400x400 pixels
        )
        ax = fig.gca()
        ax.set_axis_off()
        ax.set_facecolor((0.0, 1.0, 0.0, 1.0))
        ax.plot(rang, function, linewidth=100)

        canvas = agg.FigureCanvasAgg(fig)
        canvas.draw()
        s = canvas.get_width_height()
        renderer = canvas.get_renderer()
        raw_data = renderer.tostring_argb()
        id_ = code_generator(6)
        self.requests.append({
            "data": raw_data,
            "size": s,
            "pos": pos,
            "id": id_,
            "surface": surface
        })
        return id_
示例#2
0
    def save_url(self, url):
        code = code_generator(6)
        cursor = self.connection.cursor()
        cursor.execute("""INSERT INTO redirect VALUES ('{}', '{}')""".format(
            code, url))

        self.connection.commit()
        return True, code
示例#3
0
    def render_image(self,
                     image: str,
                     center: tuple,
                     surface,
                     size: tuple = None):
        img = self.get_image(image, center=center, size=size)

        while True:
            id = code_generator(6)
            unique = True
            for request in self.requests:
                if request[0] == id:
                    unique = False

            if unique:
                break

        self.requests.append((id, img, surface))

        return id
示例#4
0
    def render(self,
               text: str,
               x: int,
               y: int,
               surface,
               size=16,
               speed=0.5,
               static=False,
               foreground=(255, 255, 255)):

        while True:
            id = code_generator(6)
            unique = True

            for request in self.requests:
                if request["id"] == id:
                    unique = False

            if unique:
                break

        font = pygame.font.Font(
            dir_path + '/../../../res/fonts/EightBitDragon-anqx.ttf', size)
        self.requests.append({
            "message": text,
            "x": x,
            "y": y,
            "font": font,
            "str": "",
            "progress": 0,
            "speed": speed,
            "static": static,
            "foreground": foreground,
            "id": id,
            "surface": surface
        })

        return id
示例#5
0
 def save_url(self, url):
     code = code_generator(6)
     self.url_map[code] = url
     return True, code
示例#6
0
 def save(self, *args, **kwargs):
     if self.shortcode is None or self.shortcode == "":
         self.shortcode = code_generator()
     super(url_shortURL, self).save(*args, **kwargs)