Have pyinstaller always load the whole cliff module #3
4 changed files with 56 additions and 15 deletions
|
@ -15,6 +15,7 @@ class State(enum.Enum):
|
|||
STARTED = 2
|
||||
DONE = 3
|
||||
|
||||
|
||||
class Concat(dcc.doom_base.Wad):
|
||||
def get_parser(self, prog_name):
|
||||
parser = super().get_parser(prog_name)
|
||||
|
@ -49,7 +50,11 @@ class Concat(dcc.doom_base.Wad):
|
|||
# Presumably fixable, but it's easier to just make one graph per video
|
||||
# and mux everything together at the end.
|
||||
# TODO: Support UDoom in literally any way.
|
||||
d2maps = [str(x).zfill(2) for x in range(1,16)] + ["31","32"] + [str(x) for x in range(16,31)]
|
||||
d2maps = (
|
||||
[str(x).zfill(2) for x in range(1, 16)]
|
||||
+ ["31", "32"]
|
||||
+ [str(x) for x in range(16, 31)]
|
||||
)
|
||||
state = State.NOT_STARTED
|
||||
for idx in d2maps:
|
||||
if idx == parsed_args.start_map:
|
||||
|
|
|
@ -61,17 +61,17 @@ class ConfigBase(object):
|
|||
return self._doom.joinpath(self._dsda)
|
||||
|
||||
|
||||
def AddCommonArgs(parser):
|
||||
parser.add_argument(
|
||||
"--doom", default=pathlib.Path.home().joinpath("doom"))
|
||||
parser.add_argument("--config-name", default="config.toml")
|
||||
return parser
|
||||
def get_parser_func(toc):
|
||||
def add_common_args(self, prog_name):
|
||||
parser = super(toc, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"--doom", default=pathlib.Path.home().joinpath("doom"))
|
||||
parser.add_argument("--config-name", default="config.toml")
|
||||
return parser
|
||||
return add_common_args
|
||||
|
||||
|
||||
class Base(cliff.command.Command, ConfigBase):
|
||||
def get_parser(self, prog_name):
|
||||
return AddCommonArgs(super().get_parser(prog_name))
|
||||
|
||||
def run(self, parsed_args):
|
||||
super().init_base(parsed_args)
|
||||
super().finalize()
|
||||
|
@ -79,12 +79,13 @@ class Base(cliff.command.Command, ConfigBase):
|
|||
|
||||
|
||||
class ListerBase(cliff.lister.Lister, ConfigBase):
|
||||
def get_parser(self, prog_name):
|
||||
return AddCommonArgs(super().get_parser(prog_name))
|
||||
|
||||
def run(self, parsed_args):
|
||||
super().init_base(parsed_args)
|
||||
super().finalize()
|
||||
self.formatter = self._formatter_plugins[parsed_args.formatter].obj
|
||||
columns, data = self.take_action(parsed_args)
|
||||
return self.produce_output(parsed_args, columns, data)
|
||||
|
||||
|
||||
for toc in (Base, ListerBase):
|
||||
toc.get_parser = get_parser_func(toc)
|
||||
|
|
38
dcc/text.py
38
dcc/text.py
|
@ -1,11 +1,13 @@
|
|||
import dcc.config
|
||||
import dcc.doom_base
|
||||
import sys
|
||||
import textwrap
|
||||
import wand.drawing
|
||||
import wand.image
|
||||
|
||||
|
||||
def draw_text(self, img, text, font_size=64):
|
||||
def draw_text(self, img, text, font_size=64, wrap_dist=0.75):
|
||||
textlines = text.splitlines()
|
||||
with wand.drawing.Drawing() as draw:
|
||||
draw.font = self.thumbnail_font
|
||||
draw.font_size = font_size
|
||||
|
@ -13,11 +15,41 @@ def draw_text(self, img, text, font_size=64):
|
|||
draw.stroke_color = wand.color.Color(self.thumbnail_text_stroke)
|
||||
draw.stroke_width = font_size * 5 / 32
|
||||
draw.text_interline_spacing = -font_size / 4
|
||||
draw.text(5, int(draw.font_size) + 5, text)
|
||||
|
||||
target_width = wrap_dist * img.width
|
||||
|
||||
def eval_metrics(txt):
|
||||
metrics = draw.get_font_metrics(img, wrapped_text, True)
|
||||
return (metrics.text_width, metrics.text_height)
|
||||
|
||||
for idx, wrapped_text in enumerate(textlines):
|
||||
while True:
|
||||
width, height = eval_metrics(wrapped_text)
|
||||
if width <= target_width:
|
||||
break
|
||||
columns = len(wrapped_text)
|
||||
while columns > 0:
|
||||
columns -= 1
|
||||
wrapped_text = '\n'.join(
|
||||
textwrap.wrap(wrapped_text, columns)
|
||||
)
|
||||
wrapped_width, _ = eval_metrics(wrapped_text)
|
||||
if wrapped_width <= target_width:
|
||||
break
|
||||
if columns == 0:
|
||||
raise Exception(
|
||||
"couldn't calculate text wrapping; "
|
||||
+ f"final attempt was {wrapped_text}"
|
||||
)
|
||||
textlines[idx] = wrapped_text
|
||||
|
||||
wrapped_text = '\n'.join(textlines)
|
||||
|
||||
draw.text(5, int(draw.font_size) + 5, wrapped_text)
|
||||
draw(img)
|
||||
draw.stroke_color = wand.color.Color("none")
|
||||
draw.stroke_width = 0
|
||||
draw.text(5, int(draw.font_size)+5, text)
|
||||
draw.text(5, int(draw.font_size)+5, wrapped_text)
|
||||
draw(img)
|
||||
|
||||
|
||||
|
|
|
@ -28,3 +28,6 @@ dcc = "dcc.main:main"
|
|||
|
||||
[tool.poetry-pyinstaller-plugin.scripts]
|
||||
dcc = { source = "dcc/main.py", type = "onefile" }
|
||||
|
||||
[tool.poetry-pyinstaller-plugin.collect]
|
||||
all = ["cliff"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue