Skip to content

Commit

Permalink
test: fix playing tests in CI
Browse files Browse the repository at this point in the history
Refactor to avoid doing any Qt thing in the global namespace.
  • Loading branch information
truenicoco committed Jan 9, 2025
1 parent c3f9593 commit eb3e77f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 38 deletions.
8 changes: 1 addition & 7 deletions hh_creator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import locale
import sys

from PyQt5 import QtWidgets

locale.setlocale(locale.LC_ALL, "")

__version__ = "NO_VERSION"

app = QtWidgets.QApplication(sys.argv)
locale.setlocale(locale.LC_ALL, "")
5 changes: 3 additions & 2 deletions hh_creator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@

from hh_creator import __version__
from hh_creator.main_window import MainWindow
from hh_creator.util import init_sounds


def main():
app = QtWidgets.QApplication.instance()

parser = ArgumentParser()

parser.add_argument(
Expand All @@ -35,6 +34,7 @@ def main():
),
)

app = QtWidgets.QApplication(sys.argv)
args = parser.parse_args(app.arguments()[1:])
# noinspection PyArgumentList
logging.basicConfig(
Expand All @@ -48,6 +48,7 @@ def main():
)
logging.info("Starting HH Creator version %s", __version__)

init_sounds()
window = MainWindow()
app.main_window = window
sys.exit(app.exec())
Expand Down
26 changes: 15 additions & 11 deletions hh_creator/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
class TextItem(QtWidgets.QGraphicsTextItem):
n_decimals = 1

_fontstr = None

def __init__(
self,
postfix="",
Expand All @@ -29,7 +31,9 @@ def __init__(
**kwa,
):
super().__init__(*a, **kwa)
font = QtGui.QFont(_fontstr, point_size, weight, italic)
if self._fontstr is None:
_load_font()
font = QtGui.QFont(self._fontstr, point_size, weight, italic)
self.setFont(font)
self.setDefaultTextColor(QtGui.QColor(color))
self.set_center(0, 0)
Expand Down Expand Up @@ -187,14 +191,14 @@ def mousePressEvent(self, event: QtWidgets.QGraphicsSceneMouseEvent):
self.content = dialog.widgets["lineEdit"].text()


log = logging.getLogger(__name__)
def _load_font():
_id = QtGui.QFontDatabase.addApplicationFont(str(RESOURCE_PATH / "Lato-Black.ttf"))
_fontstr = QtGui.QFontDatabase.applicationFontFamilies(_id)
try:
TextItem._fontstr = _fontstr[0]
except IndexError:
log.warning("Could not load Lato font file for some reason")
TextItem._fontstr = "Lato"

FILE_NAME = RESOURCE_PATH / "Lato-Black.ttf"
_id = QtGui.QFontDatabase.addApplicationFont(str(FILE_NAME))
_fontstr = QtGui.QFontDatabase.applicationFontFamilies(_id)
try:
_fontstr = _fontstr[0]
except IndexError:
log.warning("Could not load Lato font file for some reason")
_fontstr = "Lato"
_FONT = QtGui.QFont(_fontstr, 30, 100, False)

log = logging.getLogger(__name__)
41 changes: 23 additions & 18 deletions hh_creator/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,24 +148,29 @@ def amount_format(x, n_decimals=3):
BLINDS = [ActionType.SB, ActionType.BB, ActionType.STRADDLE]


_sounds = {
f.stem: QtMultimedia.QSound(str(f))
for f in (RESOURCE_PATH / "sounds").glob("*.wav")
}

sounds = {
ActionType.BET: _sounds["bet"],
ActionType.RAISE: _sounds["bet"],
ActionType.CHECK: _sounds["check"],
ActionType.CALL: _sounds["call"],
ActionType.FOLD: _sounds["fold"],
ActionType.BB: _sounds["bet"],
ActionType.ANTE: _sounds["bet"],
ActionType.STRADDLE: _sounds["bet"],
"street": _sounds["street"],
"call_closing": _sounds["call_closing"],
}

def init_sounds():
_sounds = {
f.stem: QtMultimedia.QSound(str(f))
for f in (RESOURCE_PATH / "sounds").glob("*.wav")
}

sounds.update(
{
ActionType.BET: _sounds["bet"],
ActionType.RAISE: _sounds["bet"],
ActionType.CHECK: _sounds["check"],
ActionType.CALL: _sounds["call"],
ActionType.FOLD: _sounds["fold"],
ActionType.BB: _sounds["bet"],
ActionType.ANTE: _sounds["bet"],
ActionType.STRADDLE: _sounds["bet"],
"street": _sounds["street"],
"call_closing": _sounds["call_closing"],
}
)


sounds = {}

amount_validator = AmountValidatorWithBounds(0)
int_validator = QtGui.QIntValidator()

0 comments on commit eb3e77f

Please sign in to comment.