compatibility fix: Python 3.7.3 + PyQt4 (Debian 10)
authorNiki Roo <niki@nikiroo.be>
Thu, 27 Mar 2025 20:19:45 +0000 (21:19 +0100)
committerNiki Roo <niki@nikiroo.be>
Thu, 27 Mar 2025 20:19:45 +0000 (21:19 +0100)
14 files changed:
gamiki-qt.py
gamiki/game.py
gamiki/library.py
gamiki/qt/flow_layout.py
gamiki/qt/tiles.py
gamiki/qt/utils.py
gamiki/support/commands.py
gamiki/support/custom_commands.py
gamiki/support/support.py
gamiki/support/support_dos.py
gamiki/support/support_ext.py
gamiki/support/support_gog.py
gamiki/support/support_win.py
gamiki/support/support_win31.py

index 55e54673cac014cbcf13fb7ca76718f58a3b7eb5..97ba1f07def72c131b8a27fbab88562e3f35750b 100755 (executable)
@@ -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)
index 0251051f01ef2cf0850fa7183cd778eaeac27bfb..2aa49eb6e79735e6598027d39759e7029250dde1 100644 (file)
@@ -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)
         
index e000e5a9bdfe6f87c74a75a06dcbe9ba33e100c7..7c608231d7bd363a7227b831ac47f9fb892a068c 100644 (file)
@@ -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):
index 90ddd805df4a0cbfafd429b93e66635a1347558f..f2e3ad24ff74b67e2771ce88992857e178206f3d 100755 (executable)
 #############################################################################
 
 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):
 
index 7b1da99ccffaa08dc3257c03ef00f8c67873ec48..55c6143f2f7c11bba0cf32cca36cb42d889e8fdb 100755 (executable)
@@ -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
index e39c26f5e9906781a18912e2824c386b4869df8e..001e11e2584af141d2782158825fa50d6a5c9c77 100644 (file)
@@ -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)
     
index 613b7dd759eda0191e6660d2e88e64bb68d75d9d..7ff92e2acdf5f7c434b293dc02ce0c8898319fe6 100644 (file)
@@ -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:
index e03355798e281ddff59bc85dfafe0ae878048266..bbfd764dffeef66ae69406c622f182af20ed21da 100644 (file)
@@ -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
 
index b74bbd9a02dcc2d8db4c1536f7c795b4f6b8cfda..0bc974d100fab77bf7a33e57502e612002998b34 100644 (file)
@@ -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)
 
index 3269ef4bb67951422926f82d5688e383cb46783d..e5d86f57ee13dc3ca9030c5ab08b261072239a4a 100644 (file)
@@ -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):
index 265f05a2f94cd5329d68b504e996ed6830bb25a6..483e7c6d877ccd3a3a1c50a97e3fa485927eca71 100644 (file)
@@ -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)
index dfeb8be7287d4aa0f4d71eff2f186a4d0a66e3c8..a980c63242a1b51909ada34386b64a377ec7b777 100644 (file)
@@ -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()):
index 1a876a4b2daf6195ef1855f7a793da8a4828dfe1..0a41c3c0f94684facd16a4166965dd0d1f64a0e6 100644 (file)
@@ -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()):
index 11f830b8d3c13fa463ab788804a4e7c58106819c..c0a9aeedbcba7620164655312bacd78617ad040f 100644 (file)
@@ -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):