From 489c743a9a4ab9335ebe9ab5dd66041819aea4ec Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Thu, 27 Mar 2025 21:19:45 +0100 Subject: [PATCH] compatibility fix: Python 3.7.3 + PyQt4 (Debian 10) --- gamiki-qt.py | 31 ++++++++++++---------- gamiki/game.py | 24 ++++++++--------- gamiki/library.py | 2 +- gamiki/qt/flow_layout.py | 6 ++--- gamiki/qt/tiles.py | 5 ++-- gamiki/qt/utils.py | 4 +-- gamiki/support/commands.py | 6 +++-- gamiki/support/custom_commands.py | 44 ++++++++++++++----------------- gamiki/support/support.py | 2 +- gamiki/support/support_dos.py | 4 +-- gamiki/support/support_ext.py | 4 +-- gamiki/support/support_gog.py | 4 +-- gamiki/support/support_win.py | 4 +-- gamiki/support/support_win31.py | 4 +-- 14 files changed, 67 insertions(+), 77 deletions(-) diff --git a/gamiki-qt.py b/gamiki-qt.py index 55e5467..97ba1f0 100755 --- a/gamiki-qt.py +++ b/gamiki-qt.py @@ -3,28 +3,27 @@ from sys import argv, stderr, exit try: - from PyQt6.QtGui import QIcon - from PyQt6.QtCore import * + from PyQt6.QtGui import QIcon + from PyQt6.QtCore import * from PyQt6.QtWidgets import * print("Running on PyQt6", file=stderr) except: try: # apt-get install python3-pyqt5 - from PyQt5.QtGui import QIcon - from PyQt5.QtCore import * + from PyQt5.QtGui import QIcon + from PyQt5.QtCore import * from PyQt5.QtWidgets import * print("Running on PyQt5", file=stderr) except: - from PyQt4.QtGui import QIcon + from PyQt4.QtGui import * from PyQt4.QtCore import * - from PyQt4.QtWidgets import * print("Running on PyQt4", file=stderr) from gamiki import Builder, Library from gamiki.qt.utils import start from gamiki.qt.tiles import Grid, List -class MainWindow(QMainWindow): +class MainWindow(QWidget): def __init__(self, centre: QWidget): super().__init__() self.initUi(centre) @@ -34,15 +33,19 @@ class MainWindow(QMainWindow): self.setWindowTitle("Testy window") self.setWindowIcon(QIcon('gamiki.png')) - # Menu - self.menu = self.menuBar() - - ## Menu: File (Exit) - self.file_menu = self.menu.addMenu("File") - exit_action = self.file_menu.addAction("Exit", self.close) + ## Menu + #self.menu = self.menuBar() + # + ### Menu: File (Exit) + #self.file_menu = self.menu.addMenu("File") + #exit_action = self.file_menu.addAction("Exit", self.close) # Central widget: Centre - self.setCentralWidget(centre) + #self.setCentralWidget(centre) + layout = QHBoxLayout() + layout.setContentsMargins(0, 0, 0, 0) + layout.addWidget(centre) + self.setLayout(layout) # Size and visibility self.resize(800, 600) diff --git a/gamiki/game.py b/gamiki/game.py index 0251051..2aa49eb 100644 --- a/gamiki/game.py +++ b/gamiki/game.py @@ -1,19 +1,19 @@ from typing import Optional, Any from pathlib import PurePath, Path -class Game(dict[str, str]): +class Game(dict): """Game object generated from a directory.""" - dir : PurePath = None - name : str = "" - code : str = None - src : str = "" - tags : list[str] = None - desc : str = "" - icon : Path = None # "main" icon - icons : dict[str, Path] = None # all found icons - support : Any = None # should be gamiki.Support - library : Any = None # should be gamiki.Library + dir : PurePath = None + name : str = "" + code : str = None + src : str = "" + tags : list = None + desc : str = "" + icon : Path = None # "main" icon + icons : dict = None # all found icons + support : Any = None # should be gamiki.Support + library : Any = None # should be gamiki.Library def __init__(self, library, dir: PurePath): self.dir = dir @@ -89,7 +89,7 @@ class Game(dict[str, str]): def get_icon(self, key: str) -> PurePath: return self.icons.get(key, self.icon) - def start(self, params: Optional[list[str]] = None): + def start(self, params: list = None): if (self.support == None): raise RuntimeError("Unsupported game was called: " + game.name) diff --git a/gamiki/library.py b/gamiki/library.py index e000e5a..7c60823 100644 --- a/gamiki/library.py +++ b/gamiki/library.py @@ -2,7 +2,7 @@ from pathlib import PurePath from gamiki import Game, Support -class Library(list[Game]): +class Library(list): """Manage a library (a folder) of Games.""" def __init__(self, dir: PurePath): diff --git a/gamiki/qt/flow_layout.py b/gamiki/qt/flow_layout.py index 90ddd80..f2e3ad2 100755 --- a/gamiki/qt/flow_layout.py +++ b/gamiki/qt/flow_layout.py @@ -41,15 +41,15 @@ ############################################################################# try: - from PyQt6.QtCore import * + from PyQt6.QtCore import * from PyQt6.QtWidgets import * except: try: - from PyQt5.QtCore import * + from PyQt5.QtCore import * from PyQt5.QtWidgets import * except: from PyQt4.QtCore import * - from PyQt4.QtWidgets import * + from PyQt4.QtGui import * class FlowLayout(QLayout): diff --git a/gamiki/qt/tiles.py b/gamiki/qt/tiles.py index 7b1da99..55c6143 100755 --- a/gamiki/qt/tiles.py +++ b/gamiki/qt/tiles.py @@ -17,8 +17,7 @@ except: from PyQt5.QtGui import QPixmap except: from PyQt4.QtCore import * - from PyQt4.QtWidgets import * - from PyQt4.QtGui import QPixmap + from PyQt4.QtGui import * from gamiki import Game from gamiki.qt.utils import makeMouseAware @@ -176,7 +175,7 @@ class GridItem(QWidget): class List(QWidget): onClick = pyqtSignal(Game) - def __init__(self, games: list[Game], icon_size: int = 0): + def __init__(self, games: list, icon_size: int = 0): super().__init__() self.games = games diff --git a/gamiki/qt/utils.py b/gamiki/qt/utils.py index e39c26f..001e11e 100644 --- a/gamiki/qt/utils.py +++ b/gamiki/qt/utils.py @@ -7,7 +7,7 @@ except: from PyQt5.QtWidgets import * except: from PyQt4.QtCore import * - from PyQt4.QtWidgets import * + from PyQt4.QtGui import * pool = QThreadPool() def start(startable): @@ -76,7 +76,7 @@ def fixColor(widget: QWidget): for overlay in widget.overlay: setBg(overlay, bg) -def makeMouseAware(self: QWidget, targets: list[QWidget]): +def makeMouseAware(self: QWidget, targets: list): for target in targets: addOverlay(self, target) diff --git a/gamiki/support/commands.py b/gamiki/support/commands.py index 613b7dd..7ff92e2 100644 --- a/gamiki/support/commands.py +++ b/gamiki/support/commands.py @@ -9,7 +9,8 @@ def dosbox(dir: PurePath, link: PurePath) -> int: cmd, env = custom.cmd("dosbox", link, None) if (not cmd): - if (prog := custom.program("dosbox")): + prog = custom.program("dosbox") + if (prog): cmd = [ prog ] else: raise RuntimeError("DosBox not found") @@ -30,7 +31,8 @@ def wine(dir: PurePath) -> int: cmd, env = custom.cmd("wine", wine_bat, wine_prefix) if (not cmd): - if (prog := custom.program("wine")): + prog = custom.program("wine") + if (prog): cmd = [ prog, wine_bat.as_posix() ] env["WINEPREFIX"] = wine_prefix.as_posix() else: diff --git a/gamiki/support/custom_commands.py b/gamiki/support/custom_commands.py index e033557..bbfd764 100644 --- a/gamiki/support/custom_commands.py +++ b/gamiki/support/custom_commands.py @@ -1,12 +1,11 @@ -from typing import Optional from subprocess import run from shutil import which from os import environ from pathlib import PurePath -__programs__: dict[str, Optional[str]] = { } +__programs__: dict = { } -def program(program: str) -> Optional[str]: +def program(program: str) -> str: global __programs__ if (program not in __programs__): @@ -14,31 +13,28 @@ def program(program: str) -> Optional[str]: return __programs__[program] -def cmd ( - prog: str, p1: PurePath, p2: Optional[PurePath] - ) -> (Optional[list[str]], dict[str, str]): +def cmd(prog: str, p1: PurePath, p2: PurePath) -> (list, dict): cmd = None env = environ.copy() - match prog: - case "dosbox": - if (program("app.sh")): - cmd = [ - program("app.sh"),"--wait","dosbox","--link",p1.as_posix() - ] - case "wine": - if (program("launch.sh")): - cmd = [ program("launch.sh"), "wine", "--dlink", p1.as_posix() ] - env["OPTS"] = ( - "-e WINEPREFIX='" + p2.as_posix().replace("'", "\\'") + "'" - ) - case "start_sh": - if (program("launch.sh")): - cmd = [ - program("launch.sh"), "games", "--dlink", p1.as_posix() - ] - env["OPTS"] = "--entrypoint=bash" + if (prog == "dosbox"): + if (program("app.sh")): + cmd = [ + program("app.sh"),"--wait","dosbox","--link",p1.as_posix() + ] + elif (prog == "wine"): + if (program("launch.sh")): + cmd = [ program("launch.sh"), "wine", "--dlink", p1.as_posix() ] + env["OPTS"] = ( + "-e WINEPREFIX='" + p2.as_posix().replace("'", "\\'") + "'" + ) + elif (prog == "start_sh"): + if (program("launch.sh")): + cmd = [ + program("launch.sh"), "games", "--dlink", p1.as_posix() + ] + env["OPTS"] = "--entrypoint=bash" return cmd, env diff --git a/gamiki/support/support.py b/gamiki/support/support.py index b74bbd9..0bc974d 100644 --- a/gamiki/support/support.py +++ b/gamiki/support/support.py @@ -10,7 +10,7 @@ class Support: def supports(self, game: Game) -> bool: return False - def start(self, game: Game, params: Optional[list[str]] = None): + def start(self, game: Game, params: list = None): if (not self.supports(game)): raise RuntimeError("Unsupported game was called: " + game.name) diff --git a/gamiki/support/support_dos.py b/gamiki/support/support_dos.py index 3269ef4..e5d86f5 100644 --- a/gamiki/support/support_dos.py +++ b/gamiki/support/support_dos.py @@ -1,5 +1,3 @@ -from typing import Optional - from gamiki import Game from gamiki.support import Support from gamiki.support.commands import dosbox @@ -13,7 +11,7 @@ class SupportDos(Support): and not game.dir.joinpath("C", "WINDOWS").exists() ) - def start(self, game: Game, params: Optional[list[str]] = None): + def start(self, game: Game, params: list = None): self.running(game) rep = dosbox(game.dir.resolve(), game.dir.resolve()) if (rep != 0): diff --git a/gamiki/support/support_ext.py b/gamiki/support/support_ext.py index 265f05a..483e7c6 100644 --- a/gamiki/support/support_ext.py +++ b/gamiki/support/support_ext.py @@ -1,5 +1,3 @@ -from typing import Optional - from gamiki import Game from gamiki.support import Support from gamiki.support.commands import start_sh @@ -10,7 +8,7 @@ class SupportExt(Support): def supports(self, game: Game): return game.dir.joinpath("start.sh").exists() - def start(self, game: Game, params: Optional[list[str]] = None): + def start(self, game: Game, params: list = None): start = game.dir.resolve().joinpath("start.sh") self.running(game) diff --git a/gamiki/support/support_gog.py b/gamiki/support/support_gog.py index dfeb8be..a980c63 100644 --- a/gamiki/support/support_gog.py +++ b/gamiki/support/support_gog.py @@ -1,5 +1,3 @@ -from typing import Optional - from gamiki import Game from gamiki.support import Support from gamiki.support.commands import start_sh @@ -10,7 +8,7 @@ class SupportGog(Support): def supports(self, game: Game): return game.dir.joinpath("gameinfo").exists() - def start(self, game: Game, params: Optional[list[str]] = None): + def start(self, game: Game, params: list = None): start = game.dir.resolve().joinpath("start.sh") if (not start.exists()): diff --git a/gamiki/support/support_win.py b/gamiki/support/support_win.py index 1a876a4..0a41c3c 100644 --- a/gamiki/support/support_win.py +++ b/gamiki/support/support_win.py @@ -1,5 +1,3 @@ -from typing import Optional - from gamiki import Game from gamiki.support import Support from gamiki.support.commands import wine @@ -10,7 +8,7 @@ class SupportWin(Support): def supports(self, game: Game): return game.dir.joinpath("wine.bat").exists() - def start(self, game: Game, params: Optional[list[str]] = None): + def start(self, game: Game, params: list = None): dir = game.dir.resolve() if (not dir.joinpath("wine.prefix").exists()): diff --git a/gamiki/support/support_win31.py b/gamiki/support/support_win31.py index 11f830b..c0a9aee 100644 --- a/gamiki/support/support_win31.py +++ b/gamiki/support/support_win31.py @@ -1,5 +1,3 @@ -from typing import Optional - from gamiki import Game from gamiki.support import Support from gamiki.support.commands import dosbox @@ -13,7 +11,7 @@ class SupportWin31(Support): and game.dir.joinpath("C", "WINDOWS").exists() ) - def start(self, game: Game, params: Optional[list[str]] = None): + def start(self, game: Game, params: list = None): self.running(game) rep = dosbox(game.dir.resolve(), game.library.dir.resolve()) if (rep != 0): -- 2.27.0