Skip to content

Commit

Permalink
Fixing all linter errors
Browse files Browse the repository at this point in the history
Using flake8
  • Loading branch information
ImanolBarba committed Jul 9, 2023
1 parent ca8c50e commit d4e5d0a
Show file tree
Hide file tree
Showing 8 changed files with 501 additions and 430 deletions.
73 changes: 36 additions & 37 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import ps2mc
import wx
from functools import partial
import time
from io import BytesIO
import struct
import sys
import os

_SCCS_ID = "@(#) mymc gui.py 1.9 23/07/06 19:35:21\n"


Expand All @@ -26,15 +26,15 @@


try:
import ctypes
import ctypes # noqa: F401
import mymcicon
D3DXVECTOR3 = mymcicon.D3DXVECTOR3
D3DXVECTOR4 = mymcicon.D3DXVECTOR4
D3DXVECTOR4_ARRAY3 = mymcicon.D3DXVECTOR4_ARRAY3

def mkvec4arr3(l):
def mkvec4arr3(length):
return D3DXVECTOR4_ARRAY3(*[D3DXVECTOR4(*vec)
for vec in l])
for vec in length])
except ImportError:
mymcicon = None

Expand Down Expand Up @@ -172,7 +172,7 @@ def _update_dirtable(self, mc, dir):
continue
dirname = "/" + ent[8]
s = mc.get_icon_sys(dirname)
if s == None:
if s is None:
continue
a = ps2save.unpack_icon_sys(s)
size = mc.dir_size(dirname)
Expand All @@ -181,7 +181,7 @@ def _update_dirtable(self, mc, dir):

def update_dirtable(self, mc):
self.dirtable = []
if mc == None:
if mc is None:
return
dir = mc.dir_open("/")
try:
Expand Down Expand Up @@ -346,7 +346,7 @@ def append_menu_options(self, win, menu):
def __init__(self, parent, focus):
self.failed = False
wx.Window.__init__(self, parent)
if mymcicon == None:
if mymcicon is None:
self.failed = True
return
r = mymcicon.init_icon_renderer(focus.GetHandle(),
Expand All @@ -367,7 +367,7 @@ def __init__(self, parent, focus):
self.Bind(wx.EVT_CONTEXT_MENU, self.evt_context_menu)

def __del__(self):
if mymcicon != None:
if mymcicon is not None:
mymcicon.delete_icon_renderer()

def update_menu(self, menu):
Expand All @@ -383,7 +383,7 @@ def load_icon(self, icon_sys, icon):
if self.failed:
return

if icon_sys == None or icon == None:
if icon_sys is None or icon is None:
r = mymcicon.load_icon(None, 0, None, 0)
else:
r = mymcicon.load_icon(icon_sys, len(icon_sys),
Expand Down Expand Up @@ -498,15 +498,15 @@ def error_box(self, msg):
def mc_error(self, value, filename=None):
"""Display a message box for EnvironmentError exeception."""

if filename == None:
if filename is None:
filename = getattr(value, "filename")
if filename == None:
if filename is None:
filename = self.mcname
if filename == None:
if filename is None:
filename = "???"

strerror = getattr(value, "strerror", None)
if strerror == None:
if strerror is None:
strerror = "unknown error"

return self.error_box(filename + ": " + strerror)
Expand All @@ -518,7 +518,7 @@ def __init__(self, parent, title, mcname=None):
self.icon_win = None

size = (750, 350)
if mymcicon == None:
if mymcicon is None:
size = (500, 350)
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=size)

Expand Down Expand Up @@ -580,7 +580,7 @@ def __init__(self, parent, title, mcname=None):
self.evt_dirlist_item_focused,
self.evt_dirlist_select,
self.config)
if mcname != None:
if mcname is not None:
self.open_mc(mcname)
else:
self.refresh()
Expand All @@ -590,14 +590,14 @@ def __init__(self, parent, title, mcname=None):
sizer.AddSpacer(5)

icon_win = None
if mymcicon != None:
if mymcicon is not None:
icon_win = icon_window(panel, self)
if icon_win.failed:
icon_win.Destroy()
icon_win = None
self.icon_win = icon_win

if icon_win == None:
if icon_win is None:
self.info1 = None
self.info2 = None
else:
Expand Down Expand Up @@ -633,17 +633,17 @@ def __init__(self, parent, title, mcname=None):

self.Show(True)

if self.mc == None:
if self.mc is None:
self.evt_cmd_open()

def _close_mc(self):
if self.mc != None:
if self.mc is not None:
try:
self.mc.close()
except EnvironmentError as e:
self.mc_error(e)
self.mc = None
if self.f != None:
if self.f is not None:
try:
self.f.close()
except EnvironmentError as e:
Expand All @@ -661,10 +661,10 @@ def refresh(self):

mc = self.mc

self.toolbar.EnableTool(self.ID_CMD_IMPORT, mc != None)
self.toolbar.EnableTool(self.ID_CMD_IMPORT, mc is not None)
self.toolbar.EnableTool(self.ID_CMD_EXPORT, False)

if mc == None:
if mc is None:
status = "No memory card image"
else:
free = mc.get_free_space() / 1024
Expand All @@ -675,15 +675,15 @@ def refresh(self):
def open_mc(self, filename):
self._close_mc()
self.statusbar.SetStatusText("", 1)
if self.icon_win != None:
if self.icon_win is not None:
self.icon_win.load_icon(None, None)

f = None
try:
f = open(filename, "r+b")
mc = ps2mc.ps2mc(f)
except EnvironmentError as e:
if f != None:
if f is not None:
f.close()
self.mc_error(e, filename)
self.SetTitle(self.title)
Expand All @@ -697,16 +697,16 @@ def open_mc(self, filename):
self.refresh()

def evt_menu_open(self, event):
self.import_menu_item.Enable(self.mc != None)
selected = self.mc != None and len(self.dirlist.selected) > 0
self.import_menu_item.Enable(self.mc is not None)
selected = self.mc is not None and len(self.dirlist.selected) > 0
self.export_menu_item.Enable(selected)
self.delete_menu_item.Enable(selected)
self.ascii_menu_item.Check(self.config.get_ascii())
if self.icon_win != None:
if self.icon_win is not None:
self.icon_win.update_menu(self.icon_menu)

def evt_dirlist_item_focused(self, event):
if self.icon_win == None:
if self.icon_win is None:
return

mc = self.mc
Expand All @@ -732,7 +732,7 @@ def evt_dirlist_item_focused(self, event):
self.icon_win.load_icon(icon_sys, icon)

def evt_dirlist_select(self, event):
self.toolbar.EnableTool(self.ID_CMD_IMPORT, self.mc != None)
self.toolbar.EnableTool(self.ID_CMD_IMPORT, self.mc is not None)
self.toolbar.EnableTool(self.ID_CMD_EXPORT,
len(self.dirlist.selected) > 0)

Expand All @@ -745,14 +745,14 @@ def evt_cmd_open(self, event=None):
if fn == "":
return
self.open_mc(fn)
if self.mc != None:
if self.mc is not None:
dirname = os.path.dirname(fn)
if os.path.isabs(dirname):
self.config.set_memcard_dir(dirname)

def evt_cmd_export(self, event):
mc = self.mc
if mc == None:
if mc is None:
return

selected = self.dirlist.selected
Expand Down Expand Up @@ -851,7 +851,7 @@ def _do_import(self, fn):
self.error_box(fn + ": Save file already present.")

def evt_cmd_import(self, event):
if self.mc == None:
if self.mc is None:
return

dir = self.config.get_savefile_dir("")
Expand All @@ -862,7 +862,7 @@ def evt_cmd_import(self, event):
"|All files|*.*"),
style=(wx.FD_OPEN | wx.FD_MULTIPLE
| wx.FD_FILE_MUST_EXIST))
if fd == None:
if fd is None:
return
r = fd.ShowModal()
if r == wx.ID_CANCEL:
Expand All @@ -876,15 +876,15 @@ def evt_cmd_import(self, event):
except EnvironmentError as e:
self.mc_error(e, fn)

if success != None:
if success is not None:
dir = os.path.dirname(success)
if os.path.isabs(dir):
self.config.set_savefile_dir(dir)
self.refresh()

def evt_cmd_delete(self, event):
mc = self.mc
if mc == None:
if mc is None:
return

selected = self.dirlist.selected
Expand Down Expand Up @@ -931,7 +931,6 @@ def run(filename=None):
"""Display a GUI for working with memory card images."""

wx_app = wx.App()
frame = gui_frame(None, "mymc", filename)
return wx_app.MainLoop()


Expand All @@ -954,7 +953,7 @@ def run(filename=None):
# for o in gc.garbage:
# if type(o) == ps2mc.ps2mc_file:
# for m in dir(o):
# if getattr(o, m) == None:
# if getattr(o, m) is None:
# continue
# if (m == "__del__"
# or m == "__class__"
Expand Down
Loading

0 comments on commit d4e5d0a

Please sign in to comment.