1
0
Fork 0
mirror of synced 2024-07-03 05:31:23 +12:00
Rare/rare/components/tabs/games/game_widgets/icon_game_widget.py
loathingKernel 1721677e33 GameWidget: Implement reactive and interactive labels
The `status_label` displays what is currently going on with the game.
It reflects the current operation running on it or if it requires special
attention (update, needs verification etc)

The `tooltip_label` displays hover information such as what happens
if a part of the widget is clicked or in the case of the launch button if
the game can run (without version check, offline etc)

The context menu on the widgets will be updated and populated according
to the installation state of the game. Since the context menu was revised
the shortcut creation code was revised too to make it more compact.

the `create_desktop_link` and `get_rare_executable` functions are moved
from `rare.utils.misc` to `rare.utils.paths` to avoid cyclical imports and
better grouping. Two functions are added, `desktop_link_path` to uniformly
calculate the path of the shortcut and `desktop_links_supported` which
checks if Rare supports creating shortcuts on the current platform.
`desktop_links_supported` should be used as safeguard before `desktop_link_path`.

Desktop links are currently untested on Windows but if `shortcut.Description`
works as expected, it should be good to go.
2023-02-07 13:41:59 +02:00

63 lines
2 KiB
Python

from logging import getLogger
from typing import Optional
from PyQt5.QtCore import QEvent
from rare.models.game import RareGame
from rare.shared.image_manager import ImageSize
from .game_widget import GameWidget
from .icon_widget import IconWidget
logger = getLogger("IconGameWidget")
class IconGameWidget(GameWidget):
def __init__(self, rgame: RareGame, parent=None):
super().__init__(rgame, parent)
self.setObjectName(f"{rgame.app_name}")
self.setFixedSize(ImageSize.Display)
self.ui = IconWidget()
self.ui.setupUi(self)
self.ui.title_label.setText(self.rgame.app_title)
self.ui.launch_btn.clicked.connect(self._launch)
self.ui.launch_btn.setVisible(self.rgame.is_installed)
self.ui.install_btn.clicked.connect(self._install)
self.ui.install_btn.setVisible(not self.rgame.is_installed)
self.ui.launch_btn.setEnabled(self.rgame.can_launch)
self.update_state()
# lk: "connect" the buttons' enter/leave events to this widget
self.installEventFilter(self)
self.ui.launch_btn.installEventFilter(self)
self.ui.install_btn.installEventFilter(self)
def enterEvent(self, a0: Optional[QEvent] = None) -> None:
if a0 is not None:
a0.accept()
self.ui.enterAnimation(self)
def leaveEvent(self, a0: Optional[QEvent] = None) -> None:
if a0 is not None:
a0.accept()
self.ui.leaveAnimation(self)
# def sync_finished(self, app_name):
# if not app_name == self.rgame.app_name:
# return
# super().sync_finished(app_name)
# self.leaveEvent(None)
# def game_finished(self, app_name, error):
# if app_name != self.rgame.app_name:
# return
# self.game_running = False
# self.leaveEvent(None)
#
# def game_started(self, app_name):
# if app_name == self.rgame.app_name:
# self.game_running = True
# self.leaveEvent(None)