Replace bare except with except Exception

This commit is contained in:
Jared Miller 2026-02-12 19:54:31 -05:00
parent 6bf4dd60d4
commit addfe0c2e5
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C
32 changed files with 60 additions and 72 deletions

5
art.py
View file

@ -195,7 +195,6 @@ class Art:
"Add a blank frame at the specified index (len+1 to add to end)." "Add a blank frame at the specified index (len+1 to add to end)."
self.frames += 1 self.frames += 1
self.frame_delays.insert(index, delay) self.frame_delays.insert(index, delay)
tiles = self.layers * self.width * self.height
shape = (self.layers, self.height, self.width, 4) shape = (self.layers, self.height, self.width, 4)
fg, bg = 0, 0 fg, bg = 0, 0
if self.app.ui: if self.app.ui:
@ -821,7 +820,6 @@ class Art:
self.app.documents_dir + ART_DIR + os.path.basename(self.filename) self.app.documents_dir + ART_DIR + os.path.basename(self.filename)
) )
self.set_filename(new_path) self.set_filename(new_path)
start_time = time.time()
# cursor might be hovering, undo any preview changes # cursor might be hovering, undo any preview changes
for edit in self.app.cursor.preview_edits: for edit in self.app.cursor.preview_edits:
edit.undo() edit.undo()
@ -870,7 +868,6 @@ class Art:
# MAYBE-TODO: below gives not-so-pretty-printing, find out way to control # MAYBE-TODO: below gives not-so-pretty-printing, find out way to control
# formatting for better output # formatting for better output
json.dump(d, open(self.filename, "w"), sort_keys=True, indent=1) json.dump(d, open(self.filename, "w"), sort_keys=True, indent=1)
end_time = time.time()
self.set_unsaved_changes(False) self.set_unsaved_changes(False)
# self.app.log('saved %s to disk in %.5f seconds' % (self.filename, end_time - start_time)) # self.app.log('saved %s to disk in %.5f seconds' % (self.filename, end_time - start_time))
self.app.log("saved {}".format(self.filename)) self.app.log("saved {}".format(self.filename))
@ -1205,7 +1202,7 @@ class ArtFromDisk(Art):
self.valid = False self.valid = False
try: try:
d = json.load(open(filename)) d = json.load(open(filename))
except: except Exception:
return return
width = d["width"] width = d["width"]
height = d["height"] height = d["height"]

View file

@ -47,7 +47,7 @@ class ArtExporter:
) )
self.app.log(line) self.app.log(line)
self.app.ui.message_line.post_line(line, hold_time=10, error=True) self.app.ui.message_line.post_line(line, hold_time=10, error=True)
except: except Exception:
for line in traceback.format_exc().split("\n"): for line in traceback.format_exc().split("\n"):
self.app.log(line) self.app.log(line)
# store last used export options for "Export last" # store last used export options for "Export last"

View file

@ -57,7 +57,7 @@ class ArtImporter:
try: try:
if self.run_import(in_filename, options): if self.run_import(in_filename, options):
self.success = True self.success = True
except: except Exception:
for line in traceback.format_exc().split("\n"): for line in traceback.format_exc().split("\n"):
self.app.log(line) self.app.log(line)
if not self.success: if not self.success:

View file

@ -90,7 +90,6 @@ class Camera:
m = np.eye(4, 4, dtype=np.float32) m = np.eye(4, 4, dtype=np.float32)
left, bottom = 0, 0 left, bottom = 0, 0
right, top = width, height right, top = width, height
far_z, near_z = -1, 1
x = 2 / (right - left) x = 2 / (right - left)
y = 2 / (top - bottom) y = 2 / (top - bottom)
z = -2 / (self.far_z - self.near_z) z = -2 / (self.far_z - self.near_z)

View file

@ -25,10 +25,8 @@ class CharacterSetLord:
): ):
return return
self.last_check = self.app.get_elapsed_time() self.last_check = self.app.get_elapsed_time()
changed = None
for charset in self.app.charsets: for charset in self.app.charsets:
if charset.has_updated(): if charset.has_updated():
changed = charset.filename
# reload data and image even if only one changed # reload data and image even if only one changed
try: try:
success = charset.load_char_data() success = charset.load_char_data()
@ -45,7 +43,7 @@ class CharacterSetLord:
), ),
True, True,
) )
except: except Exception:
self.app.log( self.app.log(
"CharacterSetLord: failed reloading {}".format( "CharacterSetLord: failed reloading {}".format(
charset.filename charset.filename

View file

@ -387,7 +387,6 @@ class Cursor:
else: else:
self.tool_sprite.texture = ui.selected_tool.get_icon_texture() self.tool_sprite.texture = ui.selected_tool.get_icon_texture()
# scale same regardless of screen resolution # scale same regardless of screen resolution
aspect = self.app.window_height / self.app.window_width
scale_x = self.tool_sprite.texture.width / self.app.window_width scale_x = self.tool_sprite.texture.width / self.app.window_width
scale_x *= self.icon_scale_factor * self.app.ui.scale scale_x *= self.icon_scale_factor * self.app.ui.scale
self.tool_sprite.scale_x = scale_x self.tool_sprite.scale_x = scale_x

View file

@ -132,7 +132,7 @@ class ConvertImageOptionsDialog(ImportOptionsDialog):
# colors: int between 2 and 256 # colors: int between 2 and 256
try: try:
int(self.field_texts[3]) int(self.field_texts[3])
except: except Exception:
return False, self.invalid_color_error return False, self.invalid_color_error
colors = int(self.field_texts[3]) colors = int(self.field_texts[3])
if colors < 2 or colors > 256: if colors < 2 or colors > 256:
@ -140,7 +140,7 @@ class ConvertImageOptionsDialog(ImportOptionsDialog):
# % scale: >0 float # % scale: >0 float
try: try:
float(self.field_texts[8]) float(self.field_texts[8])
except: except Exception:
return False, self.invalid_scale_error return False, self.invalid_scale_error
if float(self.field_texts[8]) <= 0: if float(self.field_texts[8]) <= 0:
return False, self.invalid_scale_error return False, self.invalid_scale_error

View file

@ -39,7 +39,7 @@ class ImageSequenceConverter:
self.current_frame_converter = image_convert.ImageConverter( self.current_frame_converter = image_convert.ImageConverter(
self.app, self.image_filenames[0], self.art, self.bicubic_scale, self self.app, self.image_filenames[0], self.art, self.bicubic_scale, self
) )
except: except Exception:
self.fail() self.fail()
return return
if not self.current_frame_converter.init_success: if not self.current_frame_converter.init_success:

View file

@ -19,7 +19,7 @@ class EDSCIIImportOptionsDialog(ImportOptionsDialog):
# valid widths: any >=0 int # valid widths: any >=0 int
try: try:
int(self.field_texts[0]) int(self.field_texts[0])
except: except Exception:
return False, self.invalid_width_error return False, self.invalid_width_error
if int(self.field_texts[0]) < 0: if int(self.field_texts[0]) < 0:
return False, self.invalid_width_error return False, self.invalid_width_error

View file

@ -44,7 +44,7 @@ class PNGExportOptionsDialog(ExportOptionsDialog):
# scale factor: >0 int # scale factor: >0 int
try: try:
int(self.field_texts[0]) int(self.field_texts[0])
except: except Exception:
return False, self.invalid_scale_error return False, self.invalid_scale_error
if int(self.field_texts[0]) <= 0: if int(self.field_texts[0]) <= 0:
return False, self.invalid_scale_error return False, self.invalid_scale_error

View file

@ -113,7 +113,7 @@ class PNGSetExportOptionsDialog(ExportOptionsDialog):
# scale factor: >0 int # scale factor: >0 int
try: try:
int(self.field_texts[0]) int(self.field_texts[0])
except: except Exception:
return False, self.invalid_scale_error return False, self.invalid_scale_error
if int(self.field_texts[0]) <= 0: if int(self.field_texts[0]) <= 0:
return False, self.invalid_scale_error return False, self.invalid_scale_error

View file

@ -701,7 +701,6 @@ class GameObject:
front_name = "{}_{}".format(art_state_name, FACINGS[GOF_FRONT]) front_name = "{}_{}".format(art_state_name, FACINGS[GOF_FRONT])
left_name = "{}_{}".format(art_state_name, FACINGS[GOF_LEFT]) left_name = "{}_{}".format(art_state_name, FACINGS[GOF_LEFT])
right_name = "{}_{}".format(art_state_name, FACINGS[GOF_RIGHT]) right_name = "{}_{}".format(art_state_name, FACINGS[GOF_RIGHT])
back_name = "{}_{}".format(art_state_name, FACINGS[GOF_BACK])
has_front = front_name in self.arts has_front = front_name in self.arts
has_left = left_name in self.arts has_left = left_name in self.arts
has_right = right_name in self.arts has_right = right_name in self.arts
@ -859,7 +858,6 @@ class GameObject:
force_z += grav_z * self.mass force_z += grav_z * self.mass
# friction / drag # friction / drag
friction = self.get_friction() friction = self.get_friction()
speed = math.sqrt(vel_x**2 + vel_y**2 + vel_z**2)
force_x -= friction * self.mass * vel_x force_x -= friction * self.mass * vel_x
force_y -= friction * self.mass * vel_y force_y -= friction * self.mass * vel_y
force_z -= friction * self.mass * vel_z force_z -= friction * self.mass * vel_z

View file

@ -1123,7 +1123,7 @@ class GameWorld:
try: try:
d = json.load(open(filename)) d = json.load(open(filename))
# self.app.log('Loading game state %s...' % filename) # self.app.log('Loading game state %s...' % filename)
except: except Exception:
self.app.log("Couldn't load game state from {}".format(filename)) self.app.log("Couldn't load game state from {}".format(filename))
# self.app.log(sys.exc_info()) # self.app.log(sys.exc_info())
return return

View file

@ -39,7 +39,6 @@ class FlowerObject(GameObject):
# set random seed based on date, a different flower each day # set random seed based on date, a different flower each day
t = time.localtime() t = time.localtime()
year, month, day = t.tm_year, t.tm_mon, t.tm_mday year, month, day = t.tm_year, t.tm_mon, t.tm_mday
weekday = t.tm_wday # 0 = monday
date = year * 10000 + month * 100 + day date = year * 10000 + month * 100 + day
if self.seed_includes_time: if self.seed_includes_time:
date += t.tm_hour * 0.01 + t.tm_min * 0.0001 + t.tm_sec * 0.000001 date += t.tm_hour * 0.01 + t.tm_min * 0.0001 + t.tm_sec * 0.000001

View file

@ -50,7 +50,7 @@ class ImageConverter:
self.sequence_converter = sequence_converter self.sequence_converter = sequence_converter
try: try:
self.src_img = Image.open(self.image_filename).convert("RGB") self.src_img = Image.open(self.image_filename).convert("RGB")
except: except Exception:
return return
# if we're part of a sequence, app doesn't need handle directly to us # if we're part of a sequence, app doesn't need handle directly to us
if not self.sequence_converter: if not self.sequence_converter:

View file

@ -129,7 +129,6 @@ def export_animation(app, art, out_filename, bg_color=None, loop=True):
output_img.write(b) output_img.write(b)
output_img.write(b";") output_img.write(b";")
output_img.close() output_img.close()
output_format = "Animated GIF"
# app.log('%s exported (%s)' % (out_filename, output_format)) # app.log('%s exported (%s)' % (out_filename, output_format))
@ -155,7 +154,6 @@ def export_still_image(app, art, out_filename, crt=True, scale=1, bg_color=None)
return False return False
output_img = art.palette.get_palettized_image(src_img, i_transp[:3]) output_img = art.palette.get_palettized_image(src_img, i_transp[:3])
output_img.save(out_filename, "PNG", transparency=0) output_img.save(out_filename, "PNG", transparency=0)
output_format = "8-bit palettized w/ transparency"
# app.log('%s exported (%s)' % (out_filename, output_format)) # app.log('%s exported (%s)' % (out_filename, output_format))
return True return True

View file

@ -37,7 +37,7 @@ class PaletteLord:
self.app.log( self.app.log(
"PaletteLord: success reloading {}".format(palette.filename) "PaletteLord: success reloading {}".format(palette.filename)
) )
except: except Exception:
self.app.log( self.app.log(
"PaletteLord: failed reloading {}".format(palette.filename), "PaletteLord: failed reloading {}".format(palette.filename),
True, True,
@ -170,7 +170,7 @@ class Palette:
out_img = src_img.convert("RGB") out_img = src_img.convert("RGB")
# Image.putpalette needs a flat tuple :/ # Image.putpalette needs a flat tuple :/
colors = [] colors = []
for i, color in enumerate(self.colors): for color in self.colors:
# ignore alpha for palettized image output # ignore alpha for palettized image output
for channel in color[:-1]: for channel in color[:-1]:
colors.append(channel) colors.append(channel)
@ -179,7 +179,7 @@ class Palette:
colors[0:3] = transparent_color colors[0:3] = transparent_color
# PIL will fill out <256 color palettes with bogus values :/ # PIL will fill out <256 color palettes with bogus values :/
while len(colors) < MAX_COLORS * 3: while len(colors) < MAX_COLORS * 3:
for i in range(3): for _ in range(3):
colors.append(0) colors.append(0)
# palette for PIL must be exactly 256 colors # palette for PIL must be exactly 256 colors
colors = colors[: 256 * 3] colors = colors[: 256 * 3]

View file

@ -49,7 +49,7 @@ if version.parse(Image.__version__) > version.parse("10.0.0"):
pdoc_available = False pdoc_available = False
try: try:
pdoc_available = True pdoc_available = True
except: except Exception:
pass pass
# submodules - set here so cfg file can modify them all easily # submodules - set here so cfg file can modify them all easily
@ -222,11 +222,11 @@ class Application:
try: try:
sdl2.SDL_SetHint(sdl2.SDL_HINT_VIDEODRIVER, b"wayland") sdl2.SDL_SetHint(sdl2.SDL_HINT_VIDEODRIVER, b"wayland")
sdl2.ext.init() sdl2.ext.init()
except: except Exception:
try: try:
sdl2.SDL_SetHint(sdl2.SDL_HINT_VIDEODRIVER, b"x11") sdl2.SDL_SetHint(sdl2.SDL_HINT_VIDEODRIVER, b"x11")
sdl2.ext.init() sdl2.ext.init()
except: except Exception:
sdl2.ext.init() sdl2.ext.init()
winpos = sdl2.SDL_WINDOWPOS_UNDEFINED winpos = sdl2.SDL_WINDOWPOS_UNDEFINED
screen_width, screen_height = self.get_desktop_resolution() screen_width, screen_height = self.get_desktop_resolution()
@ -278,11 +278,11 @@ class Application:
# report GL vendor, version, GLSL version etc # report GL vendor, version, GLSL version etc
try: try:
gpu_vendor = GL.glGetString(GL.GL_VENDOR).decode("utf-8") gpu_vendor = GL.glGetString(GL.GL_VENDOR).decode("utf-8")
except: except Exception:
gpu_vendor = "[couldn't detect vendor]" gpu_vendor = "[couldn't detect vendor]"
try: try:
gpu_renderer = GL.glGetString(GL.GL_RENDERER).decode("utf-8") gpu_renderer = GL.glGetString(GL.GL_RENDERER).decode("utf-8")
except: except Exception:
gpu_renderer = "[couldn't detect renderer]" gpu_renderer = "[couldn't detect renderer]"
self.log(" GPU: {} - {}".format(gpu_vendor, gpu_renderer)) self.log(" GPU: {} - {}".format(gpu_vendor, gpu_renderer))
try: try:
@ -291,7 +291,7 @@ class Application:
if not gl_ver: if not gl_ver:
gl_ver = GL.glGetString(GL.GL_VERSION, ctypes.c_int(0)) gl_ver = GL.glGetString(GL.GL_VERSION, ctypes.c_int(0))
gl_ver = gl_ver.decode("utf-8") gl_ver = gl_ver.decode("utf-8")
except: except Exception:
gl_ver = "[couldn't detect GL version]" gl_ver = "[couldn't detect GL version]"
self.log(" OpenGL detected: {}".format(gl_ver)) self.log(" OpenGL detected: {}".format(gl_ver))
# GL 1.1 doesn't even habla shaders, quit if we fail GLSL version check # GL 1.1 doesn't even habla shaders, quit if we fail GLSL version check
@ -301,7 +301,7 @@ class Application:
glsl_ver = GL.glGetString( glsl_ver = GL.glGetString(
GL.GL_SHADING_LANGUAGE_VERSION, ctypes.c_int(0) GL.GL_SHADING_LANGUAGE_VERSION, ctypes.c_int(0)
) )
except: except Exception:
self.log("GLSL support not detected, " + self.compat_fail_message) self.log("GLSL support not detected, " + self.compat_fail_message)
self.should_quit = True self.should_quit = True
return return
@ -335,7 +335,7 @@ class Application:
if not self.run_if_opengl_incompatible: if not self.run_if_opengl_incompatible:
self.should_quit = True self.should_quit = True
return return
except: except Exception:
# can't get a firm number out of reported GLSL version string :/ # can't get a firm number out of reported GLSL version string :/
pass pass
# detect max texture size # detect max texture size
@ -441,10 +441,10 @@ class Application:
# textured background renderable # textured background renderable
self.bg_texture = UIBGTextureRenderable(self) self.bg_texture = UIBGTextureRenderable(self)
# init onion skin # init onion skin
for i in range(self.onion_show_frames): for _ in range(self.onion_show_frames):
renderable = OnionTileRenderable(self, self.ui.active_art) renderable = OnionTileRenderable(self, self.ui.active_art)
self.onion_renderables_prev.append(renderable) self.onion_renderables_prev.append(renderable)
for i in range(self.onion_show_frames): for _ in range(self.onion_show_frames):
renderable = OnionTileRenderable(self, self.ui.active_art) renderable = OnionTileRenderable(self, self.ui.active_art)
self.onion_renderables_next.append(renderable) self.onion_renderables_next.append(renderable)
# set camera bounds based on art size # set camera bounds based on art size
@ -731,7 +731,7 @@ class Application:
self.converter_modules[basename] = m self.converter_modules[basename] = m
except Exception as e: except Exception as e:
self.log_import_exception(e, basename) self.log_import_exception(e, basename)
for k, v in m.__dict__.items(): for v in m.__dict__.values():
if type(v) is not type: if type(v) is not type:
continue continue
# don't add duplicates # don't add duplicates
@ -924,7 +924,7 @@ class Application:
if self.get_elapsed_time() - self.last_time > 1000: if self.get_elapsed_time() - self.last_time > 1000:
self.last_time = self.get_elapsed_time() self.last_time = self.get_elapsed_time()
updates = (self.get_elapsed_time() - self.last_time) / self.timestep updates = (self.get_elapsed_time() - self.last_time) / self.timestep
for i in range(int(updates)): for _ in range(int(updates)):
if self.game_mode: if self.game_mode:
self.gw.pre_update() self.gw.pre_update()
self.gw.update() self.gw.update()
@ -1152,7 +1152,7 @@ class Application:
# fail gracefully if pdoc not found # fail gracefully if pdoc not found
try: try:
import pdoc import pdoc
except: except Exception:
self.log("pdoc module needed for documentation generation not found.") self.log("pdoc module needed for documentation generation not found.")
return return
for module_name in AUTOGEN_DOC_MODULES: for module_name in AUTOGEN_DOC_MODULES:
@ -1223,7 +1223,7 @@ def get_paths():
# so just try and fail :[ # so just try and fail :[
try: try:
os.mkdir(new_dir) os.mkdir(new_dir)
except: except Exception:
pass pass
return config_dir, documents_dir, cache_dir return config_dir, documents_dir, cache_dir
@ -1283,7 +1283,7 @@ def get_app():
try: try:
exec(cfg_line) exec(cfg_line)
new_cfg_lines.append(cfg_line + "\n") new_cfg_lines.append(cfg_line + "\n")
except: except Exception:
# find line with "Error", ie the exception name, log that # find line with "Error", ie the exception name, log that
error_lines = traceback.format_exc().split("\n") error_lines = traceback.format_exc().split("\n")
error = "[an unknown error]" error = "[an unknown error]"

View file

@ -101,6 +101,7 @@ class TileRenderable:
def __str__(self): def __str__(self):
"for debug purposes, return a concise unique name" "for debug purposes, return a concise unique name"
i = 0
for i, r in enumerate(self.art.renderables): for i, r in enumerate(self.art.renderables):
if r is self: if r is self:
break break

View file

@ -492,7 +492,7 @@ class CollisionRenderable(WorldLineRenderable):
def get_circle_points(radius, steps=24): def get_circle_points(radius, steps=24):
angle = 0 angle = 0
points = [(radius, 0)] points = [(radius, 0)]
for i in range(steps): for _ in range(steps):
angle += math.radians(360 / steps) angle += math.radians(360 / steps)
x = math.cos(angle) * radius x = math.cos(angle) * radius
y = math.sin(angle) * radius y = math.sin(angle) * radius

View file

@ -149,7 +149,7 @@ class Shader:
new_shader = shaders.compileShader(new_shader_source, shader_type) new_shader = shaders.compileShader(new_shader_source, shader_type)
# TODO: use try_compile_shader instead here, make sure exception passes thru ok # TODO: use try_compile_shader instead here, make sure exception passes thru ok
self.sl.app.log("ShaderLord: success reloading {}".format(file_to_reload)) self.sl.app.log("ShaderLord: success reloading {}".format(file_to_reload))
except: except Exception:
self.sl.app.log("ShaderLord: failed reloading {}".format(file_to_reload)) self.sl.app.log("ShaderLord: failed reloading {}".format(file_to_reload))
return return
# recompile program with new shader # recompile program with new shader

1
ui.py
View file

@ -287,6 +287,7 @@ class UI:
) )
def set_active_art_by_filename(self, art_filename): def set_active_art_by_filename(self, art_filename):
i = 0
for i, art in enumerate(self.app.art_loaded_for_edit): for i, art in enumerate(self.app.art_loaded_for_edit):
if art_filename == art.filename: if art_filename == art.filename:
break break

View file

@ -105,7 +105,7 @@ class NewArtDialog(BaseFileDialog):
def is_valid_dimension(self, dimension, max_dimension): def is_valid_dimension(self, dimension, max_dimension):
try: try:
dimension = int(dimension) dimension = int(dimension)
except: except Exception:
return False return False
return 0 < dimension <= max_dimension return 0 < dimension <= max_dimension
@ -420,13 +420,13 @@ class ResizeArtDialog(UIDialog):
return False, self.invalid_height_error return False, self.invalid_height_error
try: try:
int(self.field_texts[2]) int(self.field_texts[2])
except: except Exception:
return False, self.invalid_start_error return False, self.invalid_start_error
if not 0 <= int(self.field_texts[2]) < self.ui.active_art.width: if not 0 <= int(self.field_texts[2]) < self.ui.active_art.width:
return False, self.invalid_start_error return False, self.invalid_start_error
try: try:
int(self.field_texts[3]) int(self.field_texts[3])
except: except Exception:
return False, self.invalid_start_error return False, self.invalid_start_error
if not 0 <= int(self.field_texts[3]) < self.ui.active_art.height: if not 0 <= int(self.field_texts[3]) < self.ui.active_art.height:
return False, self.invalid_start_error return False, self.invalid_start_error
@ -435,7 +435,7 @@ class ResizeArtDialog(UIDialog):
def is_valid_dimension(self, dimension, max_dimension): def is_valid_dimension(self, dimension, max_dimension):
try: try:
dimension = int(dimension) dimension = int(dimension)
except: except Exception:
return False return False
return 0 < dimension <= max_dimension return 0 < dimension <= max_dimension
@ -477,7 +477,7 @@ class AddFrameDialog(UIDialog):
def is_valid_frame_index(self, index): def is_valid_frame_index(self, index):
try: try:
index = int(index) index = int(index)
except: except Exception:
return False return False
if index < 1 or index > self.ui.active_art.frames + 1: if index < 1 or index > self.ui.active_art.frames + 1:
return False return False
@ -486,7 +486,7 @@ class AddFrameDialog(UIDialog):
def is_valid_frame_delay(self, delay): def is_valid_frame_delay(self, delay):
try: try:
delay = float(delay) delay = float(delay)
except: except Exception:
return False return False
return delay > 0 return delay > 0
@ -627,7 +627,7 @@ class AddLayerDialog(UIDialog):
return False, self.name_exists_error return False, self.name_exists_error
try: try:
z = float(self.field_texts[1]) z = float(self.field_texts[1])
except: except Exception:
return False, self.invalid_z_error return False, self.invalid_z_error
return True, None return True, None
@ -685,7 +685,7 @@ class SetLayerZDialog(UIDialog):
def is_input_valid(self): def is_input_valid(self):
try: try:
z = float(self.field_texts[0]) z = float(self.field_texts[0])
except: except Exception:
return False, self.invalid_z_error return False, self.invalid_z_error
return True, None return True, None
@ -726,7 +726,7 @@ class PaletteFromFileDialog(UIDialog):
def valid_colors(self, colors): def valid_colors(self, colors):
try: try:
c = int(colors) c = int(colors)
except: except Exception:
return False return False
return 2 <= c <= 256 return 2 <= c <= 256
@ -767,7 +767,7 @@ class SetCameraZoomDialog(UIDialog):
def is_input_valid(self): def is_input_valid(self):
try: try:
zoom = float(self.field_texts[0]) zoom = float(self.field_texts[0])
except: except Exception:
return False, self.invalid_zoom_error return False, self.invalid_zoom_error
if zoom <= 0: if zoom <= 0:
return False, self.invalid_zoom_error return False, self.invalid_zoom_error
@ -799,7 +799,7 @@ class OverlayImageOpacityDialog(UIDialog):
def is_input_valid(self): def is_input_valid(self):
try: try:
opacity = float(self.field_texts[0]) opacity = float(self.field_texts[0])
except: except Exception:
return False, self.invalid_opacity_error return False, self.invalid_opacity_error
if opacity <= 0 or opacity > 100: if opacity <= 0 or opacity > 100:
return False, self.invalid_opacity_error return False, self.invalid_opacity_error

View file

@ -326,7 +326,7 @@ class ConsoleUI(UIElement):
self.history_file = open(self.history_filename) self.history_file = open(self.history_filename)
try: try:
self.command_history = self.history_file.readlines() self.command_history = self.history_file.readlines()
except: except Exception:
self.command_history = [] self.command_history = []
self.history_file = open(self.history_filename, "a") self.history_file = open(self.history_filename, "a")
else: else:
@ -562,16 +562,16 @@ class ConsoleUI(UIElement):
# set some locals for easy access from eval # set some locals for easy access from eval
ui = self.ui ui = self.ui
app = ui.app app = ui.app
camera = app.camera _camera = app.camera
art = ui.active_art _art = ui.active_art
player = app.gw.player _player = app.gw.player
sel = ( _sel = (
None None
if len(app.gw.selected_objects) == 0 if len(app.gw.selected_objects) == 0
else app.gw.selected_objects[0] else app.gw.selected_objects[0]
) )
world = app.gw _world = app.gw
hud = app.gw.hud _hud = app.gw.hud
# special handling of assignment statements, eg x = 3: # special handling of assignment statements, eg x = 3:
# detect strings that pattern-match, send them to exec(), # detect strings that pattern-match, send them to exec(),
# send all other strings to eval() # send all other strings to eval()

View file

@ -108,7 +108,7 @@ class UIDialog(UIElement):
self.buttons = [self.confirm_button, self.other_button, self.cancel_button] self.buttons = [self.confirm_button, self.other_button, self.cancel_button]
# populate fields with text # populate fields with text
self.field_texts = [] self.field_texts = []
for i, field in enumerate(self.fields): for i in range(len(self.fields)):
self.field_texts.append(self.get_initial_field_text(i)) self.field_texts.append(self.get_initial_field_text(i))
# field cursor starts on # field cursor starts on
self.active_field = 0 self.active_field = 0

View file

@ -474,7 +474,7 @@ class EditListPanel(GamePanel):
def list_rooms_and_objects(self): def list_rooms_and_objects(self):
items = self.list_rooms() items = self.list_rooms()
# prefix room names with "ROOM:" # prefix room names with "ROOM:"
for i, item in enumerate(items): for item in items:
item.name = "ROOM: {}".format(item.name) item.name = "ROOM: {}".format(item.name)
items += self.list_objects() items += self.list_objects()
return items return items

View file

@ -177,8 +177,6 @@ class UIElement:
elif move_x > 0: elif move_x > 0:
self.ui.menu_bar.next_menu() self.ui.menu_bar.next_menu()
return return
old_idx = self.keyboard_nav_index
new_idx = self.keyboard_nav_index + move_y
self.keyboard_nav_index += move_y self.keyboard_nav_index += move_y
if not self.support_scrolling: if not self.support_scrolling:
# if button list starts at >0 Y, use an offset # if button list starts at >0 Y, use an offset

View file

@ -264,11 +264,11 @@ class ImageChooserItem(BaseFileChooserItem):
# may not be a valid image file # may not be a valid image file
try: try:
img = Image.open(self.name) img = Image.open(self.name)
except: except Exception:
return return
try: try:
img = img.convert("RGBA") img = img.convert("RGBA")
except: except Exception:
# (probably) PIL bug: some images just crash! return None # (probably) PIL bug: some images just crash! return None
return return
img = img.transpose(Image.FLIP_TOP_BOTTOM) img = img.transpose(Image.FLIP_TOP_BOTTOM)

View file

@ -436,7 +436,7 @@ class GameRoomMenuData(PulldownMenuData):
if len(item.label) + 1 > longest_line: if len(item.label) + 1 > longest_line:
longest_line = len(item.label) + 1 longest_line = len(item.label) + 1
# cap at max allowed line length # cap at max allowed line length
for room_name, room in app.gw.rooms.items(): for room_name in app.gw.rooms:
class TempMenuItemClass(GameModePulldownMenuItem): class TempMenuItemClass(GameModePulldownMenuItem):
pass pass

View file

@ -31,7 +31,7 @@ class EditObjectPropertyDialog(UIDialog):
def is_input_valid(self): def is_input_valid(self):
try: try:
self.fields[0].type(self.field_texts[0]) self.fields[0].type(self.field_texts[0])
except: except Exception:
return False, "" return False, ""
return True, None return True, None

View file

@ -485,7 +485,7 @@ class ToolPopup(UIElement):
try: try:
if button.tool_name == tool.name: if button.tool_name == tool.name:
tool_button = button tool_button = button
except: except Exception:
pass pass
tool_button.y = y + i tool_button.y = y + i
if tool == self.ui.selected_tool: if tool == self.ui.selected_tool:

View file

@ -217,7 +217,7 @@ def world_to_screen(app, world_x, world_y, world_z):
viewport = (0, 0, app.window_width, app.window_height) viewport = (0, 0, app.window_width, app.window_height)
try: try:
x, y, z = GLU.gluProject(world_x, world_y, world_z, vm, pjm, viewport) x, y, z = GLU.gluProject(world_x, world_y, world_z, vm, pjm, viewport)
except: except Exception:
x, y, z = 0, 0, 0 x, y, z = 0, 0, 0
app.log("GLU.gluProject failed!") app.log("GLU.gluProject failed!")
# does Z mean anything here? # does Z mean anything here?