PEP 8 compliance.
This commit is contained in:
parent
3f1dad2b43
commit
b54b865977
1 changed files with 36 additions and 20 deletions
|
@ -4,27 +4,43 @@ import numpy as np
|
||||||
import wand.color
|
import wand.color
|
||||||
import wand.image
|
import wand.image
|
||||||
|
|
||||||
|
|
||||||
class Extract(dcc.config.base):
|
class Extract(dcc.config.base):
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super().get_parser(prog_name)
|
parser = super().get_parser(prog_name)
|
||||||
parser.add_argument('wad')
|
parser.add_argument('wad')
|
||||||
parser.add_argument('lump')
|
parser.add_argument('lump')
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
wads = sorted(self.pwads.joinpath(self.wad).glob('*.wad', case_sensitive=False), reverse=True)
|
wads = sorted(
|
||||||
|
self.pwads.joinpath(self.wad).glob('*.wad', case_sensitive=False),
|
||||||
|
reverse=True
|
||||||
|
)
|
||||||
|
|
||||||
for w in wads:
|
for w in wads:
|
||||||
try:
|
try:
|
||||||
# TODO: handle anything other than graphics.
|
# TODO: handle anything other than graphics.
|
||||||
wad = omg.WadIO(w)
|
wad = omg.WadIO(w)
|
||||||
gl = omg.Graphic(wad.read(parsed_args.lump))
|
gl = omg.Graphic(wad.read(parsed_args.lump))
|
||||||
# With no arguments, convert() changes a paletted image to an RGB one.
|
# With no arguments, convert() changes a paletted image to an
|
||||||
with wand.image.Image.from_array(np.array(gl.to_Image().convert())) as img:
|
# RGB one.
|
||||||
img.transparent_color(wand.color.Color("#ff00ff"), 0.0)
|
with wand.image.Image.from_array(
|
||||||
img.save(filename=self.output.joinpath(parsed_args.wad).joinpath(parsed_args.lump + ".png"))
|
np.array(gl.to_Image().convert())
|
||||||
return
|
) as img:
|
||||||
except Exception as e:
|
img.transparent_color(wand.color.Color("#ff00ff"), 0.0)
|
||||||
print("Wad {} likely has no lump {} (exception {}).".format(w, parsed_args.lump, e))
|
img.save(
|
||||||
|
filename=self.output.joinpath(parsed_args.wad)
|
||||||
|
.joinpath(parsed_args.lump + ".png")
|
||||||
|
)
|
||||||
|
return
|
||||||
|
except Exception as e:
|
||||||
|
print(
|
||||||
|
f"Wad {w} likely has no lump {parsed_args.lump}"
|
||||||
|
+ f"(exception {e})."
|
||||||
|
)
|
||||||
|
|
||||||
print("Lump {} not found in any wad in {}".format(parsed_args.lump, parsed_args.wad))
|
print(
|
||||||
|
"Lump {parsed_args.lump} not found in any wad in"
|
||||||
|
+ f"{parsed_args.wad}"
|
||||||
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue