Final f-string batch

some uses of str.format remain, but converting them would be more trouble than it's worth
This commit is contained in:
Gouvernathor 2024-03-26 21:58:22 +01:00
parent 04f76d2b54
commit f17cffa3ec
9 changed files with 49 additions and 50 deletions

View File

@ -331,15 +331,15 @@ init -1 python:
def get_store_menu_item(self, disabled=False): def get_store_menu_item(self, disabled=False):
if disabled: if disabled:
return gui.menu_item('-{}-'.format(self.name), None, style="disabled") return gui.menu_item(f'-{self.name}-', None, style="disabled")
else: else:
return gui.menu_item('-{}-'.format(self.name), self) return gui.menu_item(f'-{self.name}-', self)
def get_craft_menu_item(self, disabled=False): def get_craft_menu_item(self, disabled=False):
if disabled: if disabled:
return gui.menu_item('-Craft: "{}"-'.format(self.name), self.ingredients, style="disabled") return gui.menu_item(f'-Craft: "{self.name}"-', self.ingredients, style="disabled")
else: else:
return gui.menu_item('-Craft: "{}"-'.format(self.name), self.id) return gui.menu_item(f'-Craft: "{self.name}"-', self.id)
def get_mix_text(self): def get_mix_text(self):
return ">You mix the {i}" + potion_lib.get_name_by_id(self.ingredients[0]) \ return ">You mix the {i}" + potion_lib.get_name_by_id(self.ingredients[0]) \

View File

@ -15,16 +15,16 @@ python early:
return "DirectX" if preferences.renderer == "angle2" else "OpenGL" return "DirectX" if preferences.renderer == "angle2" else "OpenGL"
class stdcol: class stdcol:
PURPLE = '\033[1;35;48m' PURPLE = '\033[1;35;48m'
CYAN = '\033[1;36;48m' CYAN = '\033[1;36;48m'
BOLD = '\033[1;37;48m' BOLD = '\033[1;37;48m'
BLUE = '\033[1;34;48m' BLUE = '\033[1;34;48m'
GREEN = '\033[1;32;48m' GREEN = '\033[1;32;48m'
YELLOW = '\033[1;33;48m' YELLOW = '\033[1;33;48m'
RED = '\033[1;31;48m' RED = '\033[1;31;48m'
BLACK = '\033[1;30;48m' BLACK = '\033[1;30;48m'
UNDERLINE = '\033[4;37;48m' UNDERLINE = '\033[4;37;48m'
END = '\033[1;37;0m' END = '\033[1;37;0m'
if config.developer: if config.developer:
# Debug # Debug
@ -42,7 +42,7 @@ python early:
orphaned.append(i) orphaned.append(i)
if orphaned: if orphaned:
raise Exception("Orphaned compiled scripts detected, please delete them before continuing:\n{}".format(orphaned)) raise Exception(f"Orphaned compiled scripts detected, please delete them before continuing:\n{orphaned}")
detect_orphaned_rpyc_files() detect_orphaned_rpyc_files()
@ -91,7 +91,7 @@ init -2 python:
return Image(file + ".png") return Image(file + ".png")
if config.developer: if config.developer:
raise IOError("Missing image: {}".format(path)) raise IOError(f"Missing image: {path}")
return Image("images/blank.webp") return Image("images/blank.webp")
def missing_label_func(name): def missing_label_func(name):

View File

@ -86,7 +86,7 @@ init python:
elif what == "temp_attr": elif what == "temp_attr":
setattr(node, "temporary_attributes", tuple(contents)) setattr(node, "temporary_attributes", tuple(contents))
else: else:
raise TypeError("Type {!r} is not implemented.".format(what)) raise TypeError(f"Type {what!r} is not implemented.")
def replace_expression(self, expr, val): def replace_expression(self, expr, val):
node = self.node node = self.node
@ -97,14 +97,14 @@ init python:
# We need to make sure not to add quotes # We need to make sure not to add quotes
# to expressions or variables. # to expressions or variables.
if isinstance(val, str): if isinstance(val, str):
val = "\"{}\"".format(val) val = repr(val)
# Insert new expression # Insert new expression
d = self.get_expressions_active(who) d = self.get_expressions_active(who)
d[expr] = val d[expr] = val
# Convert to list of tuples # Convert to list of tuples
# l = [(k, "\"{}\"".format(v)) for k, v in d.items() if not v is None] # This is faster, but not robust enough. # l = [(k, repr(v)) for k, v in d.items() if not v is None] # This is faster, but not robust enough.
l = _list() l = _list()
l2 = _list() l2 = _list()

View File

@ -39,13 +39,13 @@ init python:
if cache_size >= cache_limit: if cache_size >= cache_limit:
if config.developer: if config.developer:
print("Cache limit reached, purging cache... ({}/{})\n{}".format(cache_size, cache_limit, renpy.get_filename_line())) print(f"Cache limit reached, purging cache... ({cache_size}/{cache_limit})\n{renpy.get_filename_line()}")
cache.clear() cache.clear()
if renpy.game.interface is not None: if renpy.game.interface is not None:
if config.developer: if config.developer:
print("Statements limit reached, cleaning textures... ({})\n{}".format(self.limit, renpy.get_filename_line())) print(f"Statements limit reached, cleaning textures... ({self.limit})\n{renpy.get_filename_line()}")
renpy.game.interface.full_redraw = True renpy.game.interface.full_redraw = True
renpy.game.interface.restart_interaction = True renpy.game.interface.restart_interaction = True
@ -144,13 +144,13 @@ python early hide:
# return (_CallException, (self.label, self.args, self.kwargs, self.from_current)) # return (_CallException, (self.label, self.args, self.kwargs, self.from_current))
# class _JumpException(Exception): # class _JumpException(Exception):
# def __init__(self, label): # def __init__(self, label):
# for i in renpy.config._label_callbacks: # for i in renpy.config._label_callbacks:
# i(label) # i(label)
# class _JumpOutException(Exception): # class _JumpOutException(Exception):
# def __init__(self, label): # def __init__(self, label):
# for i in renpy.config._label_callbacks: # for i in renpy.config._label_callbacks:
# i(label) # i(label)

View File

@ -137,7 +137,7 @@ init -1 python:
renpy.lint.report_node = node renpy.lint.report_node = node
has_failed = True has_failed = True
msg = "{!r} requires an integer, or a pre-defined named position, not {!r}".format(key, val) msg = f"{key!r} requires an integer, or a pre-defined named position, not {val!r}"
renpy.lint.report(msg) renpy.lint.report(msg)
# This would require fixing hundreds of calls. Might postpone it... # This would require fixing hundreds of calls. Might postpone it...
@ -161,7 +161,7 @@ init -1 python:
if key == "emote": if key == "emote":
msg = repr(key) msg = repr(key)
fn = "characters/{}/emote/{}.webp".format(SAYERS.get(who), val) fn = f"characters/{SAYERS.get(who)}/emote/{val}.webp"
if not has_failed: if not has_failed:
# Avoid repeating node destination # Avoid repeating node destination

View File

@ -75,7 +75,7 @@ init python in cli:
for i, s in enumerate(strings): for i, s in enumerate(strings):
n = round(float(i)/(nstrings)*100) n = round(float(i)/(nstrings)*100)
print("\rGenerating strings for {} ... Total progress:{} % ... Stage 2/2".format(language, n), end="") print(f"\rGenerating strings for {language} ... Total progress:{n} % ... Stage 2/2", end="")
tlfn = renpy.translation.generation.translation_filename(s) tlfn = renpy.translation.generation.translation_filename(s)
@ -96,17 +96,17 @@ init python in cli:
tlfn = os.path.join(renpy.config.gamedir, renpy.config.tl_directory, language, tlfn) tlfn = os.path.join(renpy.config.gamedir, renpy.config.tl_directory, language, tlfn)
f = open_tl_file(tlfn, mode="w") f = open_tl_file(tlfn, mode="w")
f.write(u"translate {} strings:\n".format(language)) f.write(f"translate {language} strings:\n")
f.write(u"\n") f.write("\n")
for s in sl: for s in sl:
original = s.text original = s.text
translation = stl.translate(s.text) # Keeps translated strings translation = stl.translate(s.text) # Keeps translated strings
f.write(u" # {}:{}\n".format(elide_filename(s.filename), s.line)) f.write(f" # {elide_filename(s.filename)}:{s.line}\n")
f.write(u" old \"{}\"\n".format(quote_unicode(original))) f.write(f" old \"{quote_unicode(original)}\"\n")
f.write(u" new \"{}\"\n".format(quote_unicode(translation))) f.write(f" new \"{quote_unicode(translation)}\"\n")
f.write(u"\n") f.write("\n")
def retranslate(): def retranslate():
translator = renpy.game.script.translator translator = renpy.game.script.translator
@ -135,7 +135,7 @@ init python in cli:
for language in translator.languages: for language in translator.languages:
print("\rGenerating dialogues for {} ... Total progress:{} % ... Stage 1/2".format(language, n), end="") print(f"\rGenerating dialogues for {language} ... Total progress:{n} % ... Stage 1/2", end="")
for _, trans in translator.file_translates[filepath]: for _, trans in translator.file_translates[filepath]:
@ -159,9 +159,9 @@ init python in cli:
f = open_tl_file(fp, mode="w") f = open_tl_file(fp, mode="w")
f.write(u"# {}:{}\n".format(trans.filename, trans.linenumber)) f.write(f"# {trans.filename}:{trans.linenumber}\n")
f.write(u"translate {} {}:\n".format(language, trans.identifier.replace(".", "_"))) f.write("translate {} {}:\n".format(language, trans.identifier.replace(".", "_")))
f.write(u"\n") f.write("\n")
for n in trans.block: for n in trans.block:
f.write(u" # " + n.get_code() + "\n") f.write(u" # " + n.get_code() + "\n")
@ -196,7 +196,7 @@ init python in cli:
f.close() f.close()
if args.dry: if args.dry:
print("Removal required: {}".format(filepath)) print(f"Removal required: {filepath}")
else: else:
os.unlink(filepath) os.unlink(filepath)
os.unlink(filepath + "c") os.unlink(filepath + "c")

View File

@ -106,7 +106,7 @@ init python:
current = getattr(store, "version", latest) current = getattr(store, "version", latest)
if current < 1.452: if current < 1.452:
for i in states.dolls: for i in states.dolls:
doll = getattr(store, i) doll = getattr(store, i)
doll._sprite = DefaultQueue() doll._sprite = DefaultQueue()
@ -121,7 +121,7 @@ init python:
# Fix makeup object types inside saved outfits # Fix makeup object types inside saved outfits
if j.has_type("makeup"): if j.has_type("makeup"):
objects = [x.parent.clone() for x in j.group] objects = [x.parent.clone() for x in j.group]
j.group = objects j.group = objects
@ -214,7 +214,7 @@ init python:
delattr(store, "achievements_dict") delattr(store, "achievements_dict")
if current > latest: if current > latest:
raise Exception("Loaded save file is incompatible. (Save Version: {}, Game Version: {})".format(current, latest)) raise Exception(f"Loaded save file is incompatible. (Save Version: {current}, Game Version: {latest})")
if current < latest: if current < latest:
setattr(store, "version", latest) setattr(store, "version", latest)
@ -228,7 +228,7 @@ init python:
def version_logo(): def version_logo():
url = UPDATE_URL url = UPDATE_URL
filename = "logo_{}.webp".format(UPDATE_VER) filename = f"logo_{UPDATE_VER}.webp"
path = os.path.join(config.basedir, "update", filename) path = os.path.join(config.basedir, "update", filename)
# Read file if exists # Read file if exists

View File

@ -30,7 +30,7 @@ init python in studio:
fp, fn = os.path.split(f) fp, fn = os.path.split(f)
fn, ext = os.path.splitext(fn) fn, ext = os.path.splitext(fn)
expression = os.path.split(fp)[1] expression = os.path.split(fp)[1]
if part in ("cheeks", "tears"): if part in ("cheeks", "tears"):
expressions = d.setdefault(charname, _dict()).setdefault(part, _list((False,))) expressions = d.setdefault(charname, _dict()).setdefault(part, _list((False,)))
@ -203,7 +203,7 @@ screen studio():
$ bg_blur = studio.choices["background"]["blur"] $ bg_blur = studio.choices["background"]["blur"]
$ bg_matrix = bg_hue*bg_saturation*bg_brightness $ bg_matrix = bg_hue*bg_saturation*bg_brightness
$ bg_image = studio.choices["background"]["list"][studio.choices["background"]["image"]] $ bg_image = studio.choices["background"]["list"][studio.choices["background"]["image"]]
$ bg_image = "images/rooms/_bg_/{}.webp".format(bg_image) $ bg_image = f"images/rooms/_bg_/{bg_image}.webp"
$ bg = Transform(bg_image, matrixcolor=bg_matrix, blur=bg_blur) $ bg = Transform(bg_image, matrixcolor=bg_matrix, blur=bg_blur)
$ ov_hue = HueMatrix(studio.choices["overlay"]["hue"]) $ ov_hue = HueMatrix(studio.choices["overlay"]["hue"])
@ -214,9 +214,8 @@ screen studio():
$ ov_matrix = ov_hue*ov_saturation*ov_brightness $ ov_matrix = ov_hue*ov_saturation*ov_brightness
$ ov_image = studio.choices["overlay"]["list"][studio.choices["overlay"]["image"]] $ ov_image = studio.choices["overlay"]["list"][studio.choices["overlay"]["image"]]
if not ov_image is None: if ov_image is not None:
$ ov_image = "images/rooms/overlays/{}.webp".format(ov_image) $ ov = Transform(f"images/rooms/overlays/{ov_image}.webp", matrixcolor=ov_matrix, blur=ov_blur, alpha=ov_alpha)
$ ov = Transform(ov_image, matrixcolor=ov_matrix, blur=ov_blur, alpha=ov_alpha)
else: else:
$ ov = None $ ov = None
@ -337,7 +336,7 @@ screen studio():
selected v[1] text_color ("#009900" if active else "#f9d592") selected v[1] text_color ("#009900" if active else "#f9d592")
text_hover_color "#fff" text_hover_color "#fff"
text_first_indent 20 text_first_indent 20
background Transform("interface/icons/head/{}.webp".format(k), size=(16, 16), offset=(22, 3)) background Transform(f"interface/icons/head/{k}.webp", size=(16, 16), offset=(22, 3))
vbox: vbox:
align (1.0, 1.0) align (1.0, 1.0)

View File

@ -777,7 +777,7 @@ screen wardrobe_menuitem(xx, yy):
pos (12, 108) pos (12, 108)
for subcategory in category_items.keys(): for subcategory in category_items.keys():
$ icon = lock_wardrobe_icon("interface/wardrobe/icons/{}.webp".format(subcategory)) $ icon = lock_wardrobe_icon(f"interface/wardrobe/icons/{subcategory}.webp")
button: button:
focus_mask None focus_mask None
@ -830,7 +830,7 @@ screen wardrobe_outfit_menuitem(xx, yy):
pos (8, 108) pos (8, 108)
for subcategory in category_items.keys(): for subcategory in category_items.keys():
$ icon = lock_wardrobe_icon("interface/wardrobe/icons/{}.webp".format(subcategory)) $ icon = lock_wardrobe_icon(f"interface/wardrobe/icons/{subcategory}.webp")
$ action = Return(["subcategory", subcategory]) $ action = Return(["subcategory", subcategory])
if subcategory == "schedule" and not get_character_scheduling(states.active_girl): if subcategory == "schedule" and not get_character_scheduling(states.active_girl):
@ -903,7 +903,7 @@ screen wardrobe_schedule_menuitem(item):
spacing 0 spacing 0
for i in wardrobe_outfit_schedule: for i in wardrobe_outfit_schedule:
$ boolean = "" if item.schedule[i] else "Not " $ boolean = "" if item.schedule[i] else "Not "
$ caption = "{}worn during the {}".format(boolean, i) if i in ("day", "night") else "{}worn in {} weather".format(boolean, i) $ caption = f"{boolean}worn during the {i}" if i in ("day", "night") else f"{boolean}worn in {i} weather"
textbutton i: textbutton i:
style gui.theme("dropdown") style gui.theme("dropdown")
tooltip caption tooltip caption