diff --git a/setup.py b/setup.py index 8e75fe6..0e382a8 100644 --- a/setup.py +++ b/setup.py @@ -38,6 +38,7 @@ def finalize_options(self): def compile_rc(self, qrc_file): import PyQt5 + py_file = os.path.splitext(qrc_file)[0] + "_rc.py" if not distutils.dep_util.newer(qrc_file, py_file): return @@ -53,6 +54,7 @@ def compile_rc(self, qrc_file): def compile_ui(self, ui_file): from PyQt5 import uic + py_file = os.path.splitext(ui_file)[0] + "_ui.py" if not distutils.dep_util.newer(ui_file, py_file): return @@ -61,6 +63,7 @@ def compile_ui(self, ui_file): def compile_ts(self, ts_file): import PyQt5 + qm_file = os.path.splitext(ts_file)[0] + ".qm" if not distutils.dep_util.newer(ts_file, qm_file): return @@ -68,7 +71,9 @@ def compile_ts(self, ts_file): path = origpath.split(os.pathsep) path.append(os.path.dirname(PyQt5.__file__)) os.putenv("PATH", os.pathsep.join(path)) - lr_exe = distutils.spawn.find_executable("lrelease") or distutils.spawn.find_executable("lrelease-qt5") + lr_exe = distutils.spawn.find_executable( + "lrelease" + ) or distutils.spawn.find_executable("lrelease-qt5") if lr_exe is None: self.warn("Unable to find Qt's Linguist lrelease or lrelease-qt5 tools") sys.exit(1) @@ -82,13 +87,13 @@ def run(self): basepath = os.path.join(os.path.dirname(__file__), "src", "m64py", "ui") for dirpath, _, filenames in os.walk(basepath): for filename in filenames: - if filename.endswith('.ts'): + if filename.endswith(".ts"): self.compile_ts(os.path.join(dirpath, filename)) for dirpath, _, filenames in os.walk(basepath): for filename in filenames: - if filename.endswith('.ui'): + if filename.endswith(".ui"): self.compile_ui(os.path.join(dirpath, filename)) - elif filename.endswith('.qrc'): + elif filename.endswith(".qrc"): self.compile_rc(os.path.join(dirpath, filename)) @@ -129,15 +134,18 @@ def remove_files(self): def run_build(self): import PyInstaller.building.build_main + work_path = os.path.join(self.dist_dir, "build") spec_file = os.path.join(self.dist_dir, "m64py.spec") os.environ["BASE_DIR"] = BASE_DIR os.environ["DIST_DIR"] = self.dist_dir - opts = {"distpath": self.dist_dir, - "workpath": work_path, - "clean_build": True, - "upx_dir": None, - "debug": False} + opts = { + "distpath": self.dist_dir, + "workpath": work_path, + "clean_build": True, + "upx_dir": None, + "debug": False, + } PyInstaller.building.build_main.main(None, spec_file, True, **opts) def run_build_dmg(self): @@ -146,11 +154,17 @@ def run_build_dmg(self): subprocess.call(["hdiutil", "create", dst_path, "-srcfolder", src_path]) def set_plist(self): - info_plist = os.path.join(self.dist_dir, "dmg", "M64Py.app", "Contents", "Info.plist") - shutil.copy(os.path.join(self.dist_dir, "m64py.icns"), - os.path.join(self.dist_dir, "dmg", "M64Py.app", "Contents", "Resources")) - shutil.copy(os.path.join(self.dist_dir, "m64py.sh"), - os.path.join(self.dist_dir, "dmg", "M64Py.app", "Contents", "MacOS")) + info_plist = os.path.join( + self.dist_dir, "dmg", "M64Py.app", "Contents", "Info.plist" + ) + shutil.copy( + os.path.join(self.dist_dir, "m64py.icns"), + os.path.join(self.dist_dir, "dmg", "M64Py.app", "Contents", "Resources"), + ) + shutil.copy( + os.path.join(self.dist_dir, "m64py.sh"), + os.path.join(self.dist_dir, "dmg", "M64Py.app", "Contents", "MacOS"), + ) with open(info_plist, "r") as opts: data = opts.read() plist_file = "" @@ -222,13 +236,17 @@ def copy_files(self): rar_dir = os.path.join(os.environ["ProgramFiles(x86)"], "Unrar") if not os.path.isfile(os.path.join(rar_dir, "UnRAR.exe")): tempdir = tempfile.mkdtemp() - urllib.request.urlretrieve("http://www.rarlab.com/rar/unrarw32.exe", - os.path.join(tempdir, "unrar.exe")) + urllib.request.urlretrieve( + "http://www.rarlab.com/rar/unrarw32.exe", + os.path.join(tempdir, "unrar.exe"), + ) subprocess.call([os.path.join(tempdir, "unrar.exe"), "-s"]) shutil.rmtree(tempdir) shutil.copy(os.path.join(rar_dir, "UnRAR.exe"), dest_path) - shutil.copy(os.path.join(rar_dir, "license.txt"), - os.path.join(dest_path, "doc", "unrar-license.txt")) + shutil.copy( + os.path.join(rar_dir, "license.txt"), + os.path.join(dest_path, "doc", "unrar-license.txt"), + ) for file_name in ["AUTHORS", "ChangeLog", "COPYING", "LICENSES", "README.rst"]: shutil.copy(os.path.join(BASE_DIR, file_name), dest_path) @@ -239,23 +257,37 @@ def remove_files(self): for dir_name in ["qml", "translations"]: shutil.rmtree(os.path.join(dest_path, "PyQt5", "Qt", dir_name), True) for file_name in glob.glob(os.path.join(dest_path, "PyQt5", "Qt*.pyd")): - if os.path.basename(file_name) not in ["Qt.pyd", "QtCore.pyd", "QtGui.pyd", "QtWidgets.pyd", "QtOpenGL.pyd"]: + if os.path.basename(file_name) not in [ + "Qt.pyd", + "QtCore.pyd", + "QtGui.pyd", + "QtWidgets.pyd", + "QtOpenGL.pyd", + ]: os.remove(file_name) for file_name in glob.glob(os.path.join(dest_path, "Qt5*.dll")): - if os.path.basename(file_name) not in ["Qt5Core.dll", "Qt5Gui.dll", "Qt5Widgets.dll", "Qt5OpenGL.dll"]: + if os.path.basename(file_name) not in [ + "Qt5Core.dll", + "Qt5Gui.dll", + "Qt5Widgets.dll", + "Qt5OpenGL.dll", + ]: os.remove(file_name) def run_build(self): import PyInstaller.building.build_main + work_path = os.path.join(self.dist_dir, "build") spec_file = os.path.join(self.dist_dir, "m64py.spec") os.environ["BASE_DIR"] = BASE_DIR os.environ["DIST_DIR"] = self.dist_dir - opts = {"distpath": self.dist_dir, - "workpath": work_path, - "clean_build": True, - "upx_dir": None, - "debug": False} + opts = { + "distpath": self.dist_dir, + "workpath": work_path, + "clean_build": True, + "upx_dir": None, + "debug": False, + } PyInstaller.building.build_main.main(None, spec_file, True, **opts) def run_build_installer(self): @@ -266,7 +298,9 @@ def run_build_installer(self): data = iss.read() lines = data.split("\n") for line in lines: - line = line.replace("{ICON}", os.path.realpath(os.path.join(self.dist_dir, "m64py"))) + line = line.replace( + "{ICON}", os.path.realpath(os.path.join(self.dist_dir, "m64py")) + ) line = line.replace("{VERSION}", FRONTEND_VERSION) iss_file += line + "\n" with open(iss_out, "w") as iss: @@ -288,13 +322,17 @@ class BuildZip(BuildExe): description = "Generate a .zip file for distribution" def run_build_zip(self): - os.rename(os.path.join(self.dist_dir, "m64py"), - os.path.join(self.dist_dir, "m64py-{}".format(FRONTEND_VERSION))) - shutil.make_archive(os.path.join(self.dist_dir, - "m64py-{}-portable".format(FRONTEND_VERSION)), - "zip", - self.dist_dir, "m64py-{}".format(FRONTEND_VERSION), - True) + os.rename( + os.path.join(self.dist_dir, "m64py"), + os.path.join(self.dist_dir, "m64py-{}".format(FRONTEND_VERSION)), + ) + shutil.make_archive( + os.path.join(self.dist_dir, "m64py-{}-portable".format(FRONTEND_VERSION)), + "zip", + self.dist_dir, + "m64py-{}".format(FRONTEND_VERSION), + True, + ) @staticmethod def set_config_path(): @@ -311,14 +349,18 @@ def set_config_path(): core.write(core_file) settings_file = "" - settings_path = os.path.join(BASE_DIR, "src", "m64py", "frontend", "settings.py") + settings_path = os.path.join( + BASE_DIR, "src", "m64py", "frontend", "settings.py" + ) with open(settings_path, "r") as core: data = core.read() lines = data.split("\n") for line in lines: if "QSettings(" in line: - line = line.replace("QSettings(\"m64py\", \"m64py\")", - "QSettings(os.path.join(os.getcwd(), \"m64py.ini\"), QSettings.IniFormat)") + line = line.replace( + 'QSettings("m64py", "m64py")', + 'QSettings(os.path.join(os.getcwd(), "m64py.ini"), QSettings.IniFormat)', + ) settings_file += line + "\n" with open(settings_path, "w") as core: core.write(settings_file) @@ -337,8 +379,8 @@ class CleanLocal(setuptools.Command): description = "Clean the local project directory" - wildcards = ['*.py[co]', '*_ui.py', '*_rc.py', '__pycache__', '*.qm'] - excludedirs = ['.git', 'build', 'dist'] + wildcards = ["*.py[co]", "*_ui.py", "*_rc.py", "__pycache__", "*.qm"] + excludedirs = [".git", "build", "dist"] user_options = [] def initialize_options(self): @@ -351,7 +393,9 @@ def _walkpaths(self, path): for root, dirs, files in os.walk(path): for excluded_dir in self.excludedirs: abs_excluded_dir = os.path.join(path, excluded_dir) - if root == abs_excluded_dir or root.startswith(abs_excluded_dir + os.sep): + if root == abs_excluded_dir or root.startswith( + abs_excluded_dir + os.sep + ): continue for a_dir in dirs: file_path = os.path.join(root, a_dir) @@ -359,11 +403,13 @@ def _walkpaths(self, path): yield file_path for a_file in files: file_path = os.path.join(root, a_file) - if any(fnmatch.fnmatch(file_path, pattern) for pattern in self.wildcards): + if any( + fnmatch.fnmatch(file_path, pattern) for pattern in self.wildcards + ): yield file_path def run(self): - for a_path in self._walkpaths('.'): + for a_path in self._walkpaths("."): if os.path.isdir(a_path): shutil.rmtree(a_path) else: @@ -391,22 +437,22 @@ def run(self): author_email="gen2brain@gmail.com", license="GNU GPLv3", url="http://m64py.sourceforge.net", - package_dir={'': "src"}, + package_dir={"": "src"}, packages=["m64py", "m64py.core", "m64py.frontend", "m64py.ui"], scripts=["bin/m64py"], requires=["PyQt5", "PySDL2"], platforms=["Linux", "Windows", "Darwin"], cmdclass={ - 'build': MyBuild, - 'build_dmg': BuildDmg, - 'build_exe': BuildExe, - 'build_qt': BuildQt, - 'build_zip': BuildZip, - 'clean': MyClean, - 'clean_local': CleanLocal + "build": MyBuild, + "build_dmg": BuildDmg, + "build_exe": BuildExe, + "build_qt": BuildQt, + "build_zip": BuildZip, + "clean": MyClean, + "clean_local": CleanLocal, }, data_files=[ ("share/pixmaps", ["xdg/m64py.png"]), ("share/applications", ["xdg/m64py.desktop"]), - ] + ], ) diff --git a/src/m64py/archive.py b/src/m64py/archive.py index fa7f65a..46ef338 100644 --- a/src/m64py/archive.py +++ b/src/m64py/archive.py @@ -27,6 +27,7 @@ try: import rarfile + HAS_RAR = True RAR_CMD = None except ImportError: @@ -35,6 +36,7 @@ try: from py7zlib import Archive7z + HAS_7Z = True LZMA_CMD = None except ImportError: @@ -44,17 +46,19 @@ ZIP, GZIP, BZIP, RAR, LZMA, ROM = range(6) EXT_FILTER = "*.*64 *.zip *.gz *.bz2" -if HAS_RAR or RAR_CMD: EXT_FILTER += " *.rar" -if HAS_7Z or LZMA_CMD: EXT_FILTER += " *.7z" +if HAS_RAR or RAR_CMD: + EXT_FILTER += " *.rar" +if HAS_7Z or LZMA_CMD: + EXT_FILTER += " *.7z" ROM_TYPE = { - b'80371240': 'z64 (native)', - b'37804012': 'v64 (byteswapped)', - b'40123780': 'n64 (wordswapped)' + b"80371240": "z64 (native)", + b"37804012": "v64 (byteswapped)", + b"40123780": "n64 (wordswapped)", } -class Archive(): +class Archive: """Extracts ROM file from archive.""" def __init__(self, filename): @@ -80,7 +84,9 @@ def __init__(self, filename): elif RAR_CMD: self.fd = RarCmd(self.file) else: - raise IOError("rarfile module or rar/unrar is needed for %s." % self.file) + raise IOError( + "rarfile module or rar/unrar is needed for %s." % self.file + ) elif self.filetype == LZMA: if HAS_7Z: self.fd = Archive7z(open(self.file, "rb")) @@ -154,15 +160,15 @@ def get_filetype(self): fd = open(self.file, "rb") magic = fd.read(4) fd.close() - if magic == b'PK\03\04': + if magic == b"PK\03\04": return ZIP - elif magic.startswith(b'\037\213'): + elif magic.startswith(b"\037\213"): return GZIP - elif magic.startswith(b'BZh'): + elif magic.startswith(b"BZh"): return BZIP - elif magic == b'Rar!': + elif magic == b"Rar!": return RAR - elif magic == b'7z\xbc\xaf': + elif magic == b"7z\xbc\xaf": return LZMA elif binascii.hexlify(magic) in ROM_TYPE.keys(): return ROM @@ -181,7 +187,7 @@ def __init__(self, archive): def namelist(self): """Returns list of filenames in archive.""" - proc = Popen([RAR_CMD, 'vb', self.file], stdout=PIPE) + proc = Popen([RAR_CMD, "vb", self.file], stdout=PIPE) lines = [] for name in proc.stdout.readlines(): name = name.decode() @@ -190,8 +196,18 @@ def namelist(self): def extract(self): """Extracts archive to temp dir.""" - cmd = [RAR_CMD, 'x', '-kb', '-p-', '-o-', '-inul', '--', - self.file, self.filename, self.tempdir] + cmd = [ + RAR_CMD, + "x", + "-kb", + "-p-", + "-o-", + "-inul", + "--", + self.file, + self.filename, + self.tempdir, + ] proc = Popen(cmd, stdout=PIPE, stderr=PIPE) out = proc.communicate() if out[1]: @@ -223,22 +239,21 @@ def __init__(self, archive): def namelist(self): """Returns list of filenames in archive.""" - proc = Popen([LZMA_CMD, 'l', self.file], stdout=PIPE) + proc = Popen([LZMA_CMD, "l", self.file], stdout=PIPE) lines = [] for name in proc.stdout.readlines(): name = name.decode() - if '...A' in name: + if "...A" in name: lines.append(name.rstrip(os.linesep)) return [name[53:] for name in lines] def extract(self): """Extracts archive to temp dir.""" - cmd = [LZMA_CMD, 'x', '-o'+self.tempdir, self.file, self.filename] + cmd = [LZMA_CMD, "x", "-o" + self.tempdir, self.file, self.filename] proc = Popen(cmd, stdout=PIPE, stderr=PIPE) out = proc.communicate() if b"Error" in out[0]: - raise IOError("Error extracting file %s: %s." % ( - self.file, out[0])) + raise IOError("Error extracting file %s: %s." % (self.file, out[0])) def read(self, filename=None, size=-1): """Reads data.""" diff --git a/src/m64py/loader.py b/src/m64py/loader.py index 2971d08..5008926 100644 --- a/src/m64py/loader.py +++ b/src/m64py/loader.py @@ -79,7 +79,7 @@ def load(self, path): # of the default RTLD_LOCAL. Without this, you end up with # libraries not being loadable, resulting in "Symbol not found" # errors - if sys.platform == 'darwin': + if sys.platform == "darwin": return ctypes.CDLL(path, ctypes.RTLD_GLOBAL) else: return ctypes.cdll.LoadLibrary(path) @@ -101,9 +101,18 @@ def getpaths(self, libname): def getplatformpaths(self, libname): return [] + class DarwinLibraryLoader(LibraryLoader): - name_formats = ["lib%s.dylib", "lib%s.so", "lib%s.bundle", - "%s.dylib", "%s.framework", "%s.so", "%s.bundle", "%s"] + name_formats = [ + "lib%s.dylib", + "lib%s.so", + "lib%s.bundle", + "%s.dylib", + "%s.framework", + "%s.so", + "%s.bundle", + "%s", + ] def find_library(self, libname): paths = self.getpaths(libname) @@ -145,11 +154,14 @@ def getdirs(self, libname): """ dyld_fallback_library_path = _environ_path("DYLD_FALLBACK_LIBRARY_PATH") if not dyld_fallback_library_path: - dyld_fallback_library_path = [os.path.expanduser('~/lib'), - '/usr/local/lib', '/usr/lib'] + dyld_fallback_library_path = [ + os.path.expanduser("~/lib"), + "/usr/local/lib", + "/usr/lib", + ] dirs = [] - if '/' in libname: + if "/" in libname: dirs.extend(_environ_path("DYLD_LIBRARY_PATH")) else: dirs.extend(_environ_path("LD_LIBRARY_PATH")) @@ -159,15 +171,24 @@ def getdirs(self, libname): dirs.append(".") - dirs.append(os.path.realpath(os.path.join( - os.path.dirname(sys.executable), '..', 'Frameworks'))) + dirs.append( + os.path.realpath( + os.path.join(os.path.dirname(sys.executable), "..", "Frameworks") + ) + ) - dirs.append(os.path.realpath(os.path.join( - os.path.dirname(os.path.abspath(__file__)), '..', 'Frameworks'))) + dirs.append( + os.path.realpath( + os.path.join( + os.path.dirname(os.path.abspath(__file__)), "..", "Frameworks" + ) + ) + ) dirs.extend(dyld_fallback_library_path) return dirs + class PosixLibraryLoader(LibraryLoader): _ld_so_cache = None @@ -180,27 +201,38 @@ def _create_ld_so_cache(self): # We assume the DT_RPATH and DT_RUNPATH binary sections are omitted. directories = [] - for name in ("LD_LIBRARY_PATH", - "SHLIB_PATH", # HPUX - "LIBPATH", # OS/2, AIX - "LIBRARY_PATH", # BE/OS - ): + for name in ( + "LD_LIBRARY_PATH", + "SHLIB_PATH", # HPUX + "LIBPATH", # OS/2, AIX + "LIBRARY_PATH", # BE/OS + ): if name in os.environ: directories.extend(os.environ[name].split(os.pathsep)) directories.extend(self.other_dirs) directories.append(".") try: - directories.extend([dir.strip() for dir in open('/etc/ld.so.conf')]) + directories.extend([dir.strip() for dir in open("/etc/ld.so.conf")]) except IOError: pass - directories.extend(['/lib64', '/lib', '/usr/lib64', '/usr/lib', - '/usr/games/lib64', '/usr/games/lib', '/usr/local/lib', - '/usr/lib/x86_64-linux-gnu', '/usr/lib/i386-linux-gnu']) + directories.extend( + [ + "/lib64", + "/lib", + "/usr/lib64", + "/usr/lib", + "/usr/games/lib64", + "/usr/games/lib", + "/usr/local/lib", + "/usr/lib/x86_64-linux-gnu", + "/usr/lib/i386-linux-gnu", + ] + ) cache = {} - lib_re = re.compile(r'lib(.*)\.s[ol]') + lib_re = re.compile(r"lib(.*)\.s[ol]") for d in directories: try: for path in glob.glob("%s/*.s[ol]*" % d): @@ -241,8 +273,7 @@ def __init__(self, path): self.cdll = ctypes.cdll.LoadLibrary(path) self.windll = ctypes.windll.LoadLibrary(path) except WindowsError: - os.environ['PATH'] = ';'.join( - [os.path.dirname(path), os.environ['PATH']]) + os.environ["PATH"] = ";".join([os.path.dirname(path), os.environ["PATH"]]) path = os.path.basename(path) self.cdll = ctypes.cdll.LoadLibrary(path) self.windll = ctypes.windll.LoadLibrary(path) @@ -256,6 +287,7 @@ def __getattr__(self, name): except AttributeError: raise + class WindowsLibraryLoader(LibraryLoader): name_formats = ["%s.dll", "lib%s.dll", "%slib.dll"] @@ -294,10 +326,11 @@ def getplatformpaths(self, libname): if path: yield path + loaderclass = { - "darwin": DarwinLibraryLoader, - "cygwin": WindowsLibraryLoader, - "win32": WindowsLibraryLoader + "darwin": DarwinLibraryLoader, + "cygwin": WindowsLibraryLoader, + "win32": WindowsLibraryLoader, } loader = loaderclass.get(sys.platform, PosixLibraryLoader)() diff --git a/src/m64py/opts.py b/src/m64py/opts.py index fad21b9..ff1bdc0 100644 --- a/src/m64py/opts.py +++ b/src/m64py/opts.py @@ -18,9 +18,11 @@ from m64py.core.defs import FRONTEND_VERSION -usage = 'usage: %prog ' +usage = "usage: %prog " parser = OptionParser(usage=usage, version="M64Py Version %s" % FRONTEND_VERSION) -parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="show verbose output") +parser.add_option( + "-v", "--verbose", action="store_true", dest="verbose", help="show verbose output" +) opts, args = parser.parse_args() VERBOSE = opts.verbose diff --git a/src/m64py/platform.py b/src/m64py/platform.py index 8c31936..aef0b24 100644 --- a/src/m64py/platform.py +++ b/src/m64py/platform.py @@ -29,25 +29,18 @@ "/usr/games/lib/mupen64plus", "/usr/lib/x86_64-linux-gnu/mupen64plus", "/usr/lib/i386-linux-gnu/mupen64plus", - "." + ".", ] elif sys.platform.startswith("openbsd"): DLL_EXT = ".so" DLL_FILTER = "" DEFAULT_DYNLIB = "libmupen64plus.so" - SEARCH_DIRS = [ - "/usr/local/lib/mupen64plus", - "." - ] + SEARCH_DIRS = ["/usr/local/lib/mupen64plus", "."] elif sys.platform == "darwin": DLL_EXT = ".dylib" DLL_FILTER = ".dylib" DEFAULT_DYNLIB = "libmupen64plus.dylib" - SEARCH_DIRS = [ - "/usr/local/lib/mupen64plus", - "/usr/lib/mupen64plus", - "." - ] + SEARCH_DIRS = ["/usr/local/lib/mupen64plus", "/usr/lib/mupen64plus", "."] elif sys.platform == "win32": DLL_EXT = ".dll" DLL_FILTER = ".dll" diff --git a/src/m64py/ui/imageview.py b/src/m64py/ui/imageview.py index 8025499..6876127 100644 --- a/src/m64py/ui/imageview.py +++ b/src/m64py/ui/imageview.py @@ -17,8 +17,8 @@ from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene from PyQt5.QtCore import Qt, QRectF -class ImageView(QGraphicsView): +class ImageView(QGraphicsView): def __init__(self, parent=None): QGraphicsView.__init__(self, parent) self.setScene(QGraphicsScene()) @@ -27,8 +27,7 @@ def resizeEvent(self, event): size = event.size() for item in self.scene().items(): pixmap = item.pixmap() - pixmap = pixmap.scaled( - size, Qt.KeepAspectRatio, Qt.SmoothTransformation) + pixmap = pixmap.scaled(size, Qt.KeepAspectRatio, Qt.SmoothTransformation) item.setPixmap(pixmap) self.ensureVisible(item) self.centerOn(item) diff --git a/src/m64py/ui/inputbutton.py b/src/m64py/ui/inputbutton.py index 2307c5c..f235d4f 100644 --- a/src/m64py/ui/inputbutton.py +++ b/src/m64py/ui/inputbutton.py @@ -27,8 +27,8 @@ SDL_HAT_DOWN = 0x04 SDL_HAT_LEFT = 0x08 -class InputButton(QPushButton): +class InputButton(QPushButton): def __init__(self, parent=None): QPushButton.__init__(self, parent) self.key = None @@ -39,7 +39,7 @@ def __init__(self, parent=None): def showEvent(self, event): dialog = self.parent.parentWidget().parent() - if hasattr(dialog, 'joystick'): + if hasattr(dialog, "joystick"): self.input = dialog self.joystick = dialog.joystick else: @@ -47,7 +47,6 @@ def showEvent(self, event): self.joystick = dialog.parent().joystick self.connect_signals() - def connect_signals(self): self.joystick.axis_value_changed.connect(self.on_axis_value_changed) self.joystick.button_value_changed.connect(self.on_button_value_changed) @@ -86,7 +85,8 @@ def focusInEvent(self, event): self.setText(self.tr("Press Key")) self.setCheckable(True) self.window().statusLabel.setText( - self.tr("Press Escape to cancel, Backspace to delete.")) + self.tr("Press Escape to cancel, Backspace to delete.") + ) def focusOutEvent(self, event): if self.input.is_joystick: diff --git a/src/m64py/utils.py b/src/m64py/utils.py index b7f6977..6e8b84b 100644 --- a/src/m64py/utils.py +++ b/src/m64py/utils.py @@ -20,6 +20,7 @@ def which(prog): def is_exe(fpath): return os.path.exists(fpath) and os.access(fpath, os.X_OK) + fpath, fname = os.path.split(prog) if fpath: if is_exe(prog): @@ -33,17 +34,16 @@ def is_exe(fpath): def version_split(ver): - return "%d.%d.%d" % ( - ((ver >> 16) & 0xffff), - ((ver >> 8) & 0xff), - ((ver & 0xff))) + return "%d.%d.%d" % (((ver >> 16) & 0xFFFF), ((ver >> 8) & 0xFF), ((ver & 0xFF))) def sl(mot): - return ((mot & 0x000000FF) << 24) |\ - ((mot & 0x0000FF00) << 8) |\ - ((mot & 0x00FF0000) >> 8) |\ - ((mot & 0xFF000000) >> 24) + return ( + ((mot & 0x000000FF) << 24) + | ((mot & 0x0000FF00) << 8) + | ((mot & 0x00FF0000) >> 8) + | ((mot & 0xFF000000) >> 24) + ) def format_tooltip(tooltip): @@ -70,11 +70,10 @@ def format_options(param_help): opts = {} if not param_help: return None - items = re.findall( - "(\d+|[\d,-]+)\s?=\s?([\w/ %-]+)", param_help) + items = re.findall("(\d+|[\d,-]+)\s?=\s?([\w/ %-]+)", param_help) for item in items: key, value = item - if '-' in key[1:] or ',' in key: + if "-" in key[1:] or "," in key: return None else: opts[int(key)] = value