コード例 #1
0
    def update(self, value=None):
        text = Text(value or self.text.get())

        ratio = 0
        match = None

        for template in self.app.template_service.all():
            _ratio, path = template.match(str(text).lower())
            if _ratio > ratio:
                ratio = _ratio
                log.info("Matched at %s: %s - %s", ratio, template, path)
                match = template, Text(path)

        if match:
            domain = self.app.image_service.create(*match)
            image = Image.open(domain.path)
            old_size = image.size
            max_size = self.root.winfo_width(), self.root.winfo_height()
            ratio = min(max_size[0] / old_size[0], max_size[1] / old_size[1])
            new_size = [int(s * ratio * 0.9) for s in old_size]
            image = image.resize(new_size, Image.ANTIALIAS)
            self._image = ImageTk.PhotoImage(image)
            self.label.configure(image=self._image)

            self.clear()

        self.restart(update=True, clear=False)
コード例 #2
0
def main():
    logging.info("Generating sample images...")

    app = create_app(ProdConfig)

    with app.app_context():

        for template in app.template_service.all():
            app.image_service.create(template, Text("_"))
            app.image_service.create(template, Text("_/_"))
            app.image_service.create(template, template.sample_text)
コード例 #3
0
    def test_2_slashes(self):
        text = Text("foo/bar/qux")

        assert "FOO" == text.top
        assert "BAR" == text.bottom
        assert "QUX" == text.get_line(2)
        assert "" == text.get_line(3)
コード例 #4
0
def main():
    log.info("Generating sample images...")

    app = create_app(ProdConfig)

    with app.app_context():

        for template in app.template_service.all():
            for text in [Text("_"), template.sample_text]:
                for watermark in ["", "memegen.link"]:
                    app.image_service.create(template, text,
                                             watermark=watermark)
コード例 #5
0
def run():
    app = create_app(ProductionConfig)
    with app.app_context():

        options = []
        for template in app.template_service.all():
            for text in [Text("_"), template.sample_text]:
                for watermark in ["", "memegen.link"]:
                    options.append((template, text, watermark))

        print(f"Generating {len(options)} sample images...")
        for template, text, watermark in options:
            app.image_service.create(template, text, watermark=watermark)
コード例 #6
0
 def test_lines_strip_spaces(self):
     text = Text("  hello  World /    ")
     assert ["HELLO  WORLD"] == text.lines
コード例 #7
0
 def test_lines_ignore_capital_after_sep(self):
     text = Text("hello-World")
     assert ["HELLO WORLD"] == text.lines
コード例 #8
0
 def test_empty_is_falsey(self):
     assert False is bool(Text())
コード例 #9
0
 def test_init_0_slashes(self):
     text = Text("foo")
     assert "FOO" == text.top
     assert "" == text.bottom
コード例 #10
0
 def test_path_with_a_single_underscore(self):
     text = Text(" _     ")
     assert "_" == text.path
コード例 #11
0
 def test_path_with_case_changes(self):
     text = Text("withCaseChanges/InIT")
     assert "with-case-changes/in-it" == text.path
コード例 #12
0
 def test_path_with_dashes(self):
     text = Text("with-dashes/in-it")
     assert "with-dashes/in-it" == text.path
コード例 #13
0
 def test_lines_split_underscore_as_spaces(self):
     text = Text("hello_world")
     assert ["HELLO WORLD"] == text.lines
コード例 #14
0
 def test_init_1_slash(self):
     text = Text("foo/bar")
     assert "FOO" == text.top
     assert "BAR" == text.bottom
     assert "" == text.get_line(2)
コード例 #15
0
    def test_no_space_after_apostrophe(self):
        text = Text("that'd be great")

        assert ["THAT'D BE GREAT"] == text.lines
コード例 #16
0
    def test_ignore_capital_after_apostrophe(self):
        text = Text("Y'ALL")

        assert ["Y'ALL"] == text.lines
コード例 #17
0
    def test_case_ignored_after_space(self):
        text = Text("HELLO WORLD")

        assert ["HELLO WORLD"] == text.lines
コード例 #18
0
    def test_split_dash_as_spaces(self):
        text = Text("hello-world")

        assert ["HELLO WORLD"] == text.lines
コード例 #19
0
 def test_only_spaces_is_falsey(self):
     assert False is bool(Text("_/_/_"))
コード例 #20
0
 def test_duplicate_capitals_treated_as_spaces(self):
     text = Text("IWantTHISPattern_to-Work")
     assert ["I WANT THIS PATTERN TO WORK"] == text.lines
コード例 #21
0
 def test_path(self):
     text = Text("hello/World")
     assert "hello/world" == text.path
コード例 #22
0
 def test_lines_split_underscore_as_spaces_ignores_case(self):
     text = Text("HELLO WORLD")
     assert ["HELLO WORLD"] == text.lines
コード例 #23
0
 def test_path_with_underscores(self):
     text = Text("with_underscores/in_it")
     assert "with-underscores/in-it" == text.path
コード例 #24
0
 def test_lines_split_case_as_spaces(self):
     text = Text("helloWorld")
     assert ["HELLO WORLD"] == text.lines
コード例 #25
0
 def test_path_strips_spaces(self):
     text = Text("  with  spaces/  in it   / ")
     assert "with--spaces/in-it" == text.path
コード例 #26
0
 def test_lines_keep_spaces(self):
     text = Text("hello world")
     assert ["HELLO WORLD"] == text.lines
コード例 #27
0
 def test_path_with_duplicate_capitals(self):
     text = Text("IWantTHISPattern_to-Work")
     assert "i-want-this-pattern-to-work" == text.path
コード例 #28
0
 def test_lines_ignore_initial_capital(self):
     text = Text("HelloWorld")
     assert ["HELLO WORLD"] == text.lines
コード例 #29
0
 def test_init_none(self):
     text = Text()
     assert "" == text.top
     assert "" == text.bottom
コード例 #30
0
 def test_content_is_truthy(self):
     assert True is bool(Text("Hello, world!"))