Mods
This commit is contained in:
parent
f2c6ecb1e0
commit
4b8c6e52de
|
@ -0,0 +1,71 @@
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from PySide6.QtWidgets import QWidget
|
||||||
|
from PySide6.QtGui import QKeyEvent # type: ignore
|
||||||
|
|
||||||
|
from .window import Window
|
||||||
|
|
||||||
|
class Filter:
|
||||||
|
@staticmethod
|
||||||
|
def get_value() -> str:
|
||||||
|
return Window.filter.text().lower().strip()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def filter(event: QKeyEvent | None = None) -> None:
|
||||||
|
value = Filter.get_value()
|
||||||
|
|
||||||
|
for i in range(Window.view.count()):
|
||||||
|
item = Window.view.itemAt(i)
|
||||||
|
text = Filter.get_filter_text(item)
|
||||||
|
hide = True
|
||||||
|
|
||||||
|
for txt in text:
|
||||||
|
if value in txt:
|
||||||
|
hide = False
|
||||||
|
break
|
||||||
|
|
||||||
|
if hide:
|
||||||
|
item.widget().hide()
|
||||||
|
else:
|
||||||
|
item.widget().show()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_filter_text(item: QWidget) -> list[str]:
|
||||||
|
text = []
|
||||||
|
layout = item.widget().layout()
|
||||||
|
|
||||||
|
for i in range(layout.count()):
|
||||||
|
widget = layout.itemAt(i).widget()
|
||||||
|
|
||||||
|
if not widget:
|
||||||
|
continue
|
||||||
|
|
||||||
|
name = widget.objectName()
|
||||||
|
|
||||||
|
if name != "view_right":
|
||||||
|
continue
|
||||||
|
|
||||||
|
layout2 = widget.layout()
|
||||||
|
|
||||||
|
for j in range(layout2.count()):
|
||||||
|
wid = layout2.itemAt(j).widget()
|
||||||
|
|
||||||
|
if not wid:
|
||||||
|
continue
|
||||||
|
|
||||||
|
name = wid.objectName()
|
||||||
|
|
||||||
|
if not name:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if (name == "view_title") or (name == "view_message"):
|
||||||
|
text.append(wid.text().lower())
|
||||||
|
|
||||||
|
return text
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def check() -> None:
|
||||||
|
value = Filter.get_value()
|
||||||
|
|
||||||
|
if value:
|
||||||
|
Filter.filter()
|
|
@ -8,7 +8,6 @@ from PySide6.QtWidgets import QHBoxLayout # type: ignore
|
||||||
from PySide6.QtWidgets import QVBoxLayout
|
from PySide6.QtWidgets import QVBoxLayout
|
||||||
from PySide6.QtWidgets import QLabel
|
from PySide6.QtWidgets import QLabel
|
||||||
from PySide6.QtWidgets import QWidget
|
from PySide6.QtWidgets import QWidget
|
||||||
from PySide6.QtGui import QKeyEvent # type: ignore
|
|
||||||
from PySide6.QtGui import QPixmap
|
from PySide6.QtGui import QPixmap
|
||||||
from PySide6.QtCore import QTimer
|
from PySide6.QtCore import QTimer
|
||||||
|
|
||||||
|
@ -57,7 +56,7 @@ class Game:
|
||||||
container.addWidget(image_label)
|
container.addWidget(image_label)
|
||||||
container.addSpacing(Config.space_1)
|
container.addSpacing(Config.space_1)
|
||||||
container.addWidget(right_container)
|
container.addWidget(right_container)
|
||||||
Game.add_view_container(container)
|
Game.add_container(container)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def add_message(
|
def add_message(
|
||||||
|
@ -73,10 +72,12 @@ class Game:
|
||||||
container.addWidget(image_label)
|
container.addWidget(image_label)
|
||||||
container.addSpacing(Config.space_1)
|
container.addSpacing(Config.space_1)
|
||||||
container.addWidget(right_container)
|
container.addWidget(right_container)
|
||||||
Game.add_view_container(container)
|
Game.add_container(container)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def add_view_container(container: QHBoxLayout) -> None:
|
def add_container(container: QHBoxLayout) -> None:
|
||||||
|
from .filter import Filter
|
||||||
|
|
||||||
root = QWidget()
|
root = QWidget()
|
||||||
root.setContentsMargins(0, 0, 0, 0)
|
root.setContentsMargins(0, 0, 0, 0)
|
||||||
container.setContentsMargins(0, 0, 0, 0)
|
container.setContentsMargins(0, 0, 0, 0)
|
||||||
|
@ -91,6 +92,8 @@ class Game:
|
||||||
elif item.layout():
|
elif item.layout():
|
||||||
Window.delete_layout(item.layout())
|
Window.delete_layout(item.layout())
|
||||||
|
|
||||||
|
Filter.check()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def make_right_container(title: str, message: str) -> QWidget:
|
def make_right_container(title: str, message: str) -> QWidget:
|
||||||
root = QWidget()
|
root = QWidget()
|
||||||
|
@ -249,56 +252,3 @@ class Game:
|
||||||
Window.play_audio(path)
|
Window.play_audio(path)
|
||||||
|
|
||||||
Game.playing_song = not Game.playing_song
|
Game.playing_song = not Game.playing_song
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def filter(event: QKeyEvent) -> None:
|
|
||||||
value = Window.filter.text().lower().strip().lower()
|
|
||||||
|
|
||||||
for i in range(Window.view.count()):
|
|
||||||
item = Window.view.itemAt(i)
|
|
||||||
text = Game.get_filter_text(item)
|
|
||||||
hide = True
|
|
||||||
|
|
||||||
for txt in text:
|
|
||||||
if value in txt:
|
|
||||||
hide = False
|
|
||||||
break
|
|
||||||
|
|
||||||
if hide:
|
|
||||||
item.widget().hide()
|
|
||||||
else:
|
|
||||||
item.widget().show()
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_filter_text(item: QWidget) -> list[str]:
|
|
||||||
text = []
|
|
||||||
layout = item.widget().layout()
|
|
||||||
|
|
||||||
for i in range(layout.count()):
|
|
||||||
widget = layout.itemAt(i).widget()
|
|
||||||
|
|
||||||
if not widget:
|
|
||||||
continue
|
|
||||||
|
|
||||||
name = widget.objectName()
|
|
||||||
|
|
||||||
if name != "view_right":
|
|
||||||
continue
|
|
||||||
|
|
||||||
layout2 = widget.layout()
|
|
||||||
|
|
||||||
for j in range(layout2.count()):
|
|
||||||
wid = layout2.itemAt(j).widget()
|
|
||||||
|
|
||||||
if not wid:
|
|
||||||
continue
|
|
||||||
|
|
||||||
name = wid.objectName()
|
|
||||||
|
|
||||||
if not name:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if (name == "view_title") or (name == "view_message"):
|
|
||||||
text.append(wid.text().lower())
|
|
||||||
|
|
||||||
return text
|
|
||||||
|
|
|
@ -188,6 +188,7 @@ class Window:
|
||||||
def add_buttons() -> None:
|
def add_buttons() -> None:
|
||||||
from .ants import Ants
|
from .ants import Ants
|
||||||
from .game import Game
|
from .game import Game
|
||||||
|
from .filter import Filter
|
||||||
|
|
||||||
root = QWidget()
|
root = QWidget()
|
||||||
container = QHBoxLayout()
|
container = QHBoxLayout()
|
||||||
|
@ -220,7 +221,7 @@ class Window:
|
||||||
Window.filter.setFixedWidth(120)
|
Window.filter.setFixedWidth(120)
|
||||||
Window.filter.setPlaceholderText("Filter")
|
Window.filter.setPlaceholderText("Filter")
|
||||||
Window.filter.mousePressEvent = lambda e: Window.to_top()
|
Window.filter.mousePressEvent = lambda e: Window.to_top()
|
||||||
Window.filter.keyReleaseEvent = lambda e: Game.filter(e)
|
Window.filter.keyReleaseEvent = lambda e: Filter.filter(e)
|
||||||
|
|
||||||
container.addWidget(btn_hatch)
|
container.addWidget(btn_hatch)
|
||||||
container.addWidget(btn_terminate)
|
container.addWidget(btn_terminate)
|
||||||
|
|
Loading…
Reference in New Issue