Skip to content

Commit

Permalink
Merge pull request #7 from Night-stars-1/dev
Browse files Browse the repository at this point in the history
feat: 添加每日界面,未实装
  • Loading branch information
Night-stars-1 authored Apr 10, 2024
2 parents 6e9c360 + c188a21 commit c81f3bc
Show file tree
Hide file tree
Showing 48 changed files with 426 additions and 483 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ logs/
gui/
examples/
test.*
config.json
config*
10 changes: 9 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,13 @@
"source.organizeImports": "explicit"
},
},
"isort.args":["--profile", "black"],
"isort.args": [
"--profile",
"black"
],
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
}
4 changes: 4 additions & 0 deletions app/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
qconfig,
)

from core import adb


class Language(Enum):
"""Language enumeration"""
Expand Down Expand Up @@ -52,6 +54,8 @@ class Config(QConfig):
# uuid
uuid = ConfigItem("Global", "uuid", "", None)
goodsType = ConfigItem("Global", "goodsType", False, BoolValidator())
adbPath = ConfigItem("Global", "adbPath", "resources\\lib\\adb", None)
adbOrder = ConfigItem("Global", "adbOrder", "127.0.0.1:7555", None)

# main window
micaEnabled = ConfigItem("MainWindow", "MicaEnabled", isWin11(), BoolValidator())
Expand Down
6 changes: 5 additions & 1 deletion app/common/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
"""

from PyQt5.QtCore import QThread

from core.exceptions import StopExecution

from .config import cfg


class Worker(QThread):
def __init__(self, func, stop, parent=None):
super(Worker, self).__init__(parent)
Expand All @@ -16,7 +20,7 @@ def __init__(self, func, stop, parent=None):

def run(self):
try:
self.func()
self.func(cfg.adbOrder.value, cfg.adbPath.value)
except StopExecution:
pass

Expand Down
50 changes: 50 additions & 0 deletions app/components/line_edit_card.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
Author: Night-stars-1 nujj1042633805@gmail.com
Date: 2024-04-07 23:54:39
LastEditTime: 2024-04-10 01:11:23
LastEditors: Night-stars-1 nujj1042633805@gmail.com
"""
from typing import Optional, Union

from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtGui import QIcon
from qfluentwidgets import SettingCard, FluentIconBase, LineEdit, PasswordLineEdit, ConfigItem
from qfluentwidgets import qconfig


class LineEditCard(SettingCard):
""" card with a push button """

text_change = pyqtSignal()

def __init__(self, icon: Union[str, QIcon, FluentIconBase], holderText: str, title: str, default: str = "", content=None, parent=None, isPassword=False):
"""
Parameters
----------
text: str
the text of push button
icon: str | QIcon | FluentIconBase
the icon to be drawn
title: str
the title of card
content: str
the content of card
parent: QWidget
parent widget
"""
super().__init__(icon, title, content, parent)

if isPassword:
self.lineEdit = PasswordLineEdit(self)
else:
self.lineEdit = LineEdit(self)
self.lineEdit.setText(default)
self.lineEdit.setPlaceholderText(holderText)

self.hBoxLayout.addWidget(self.lineEdit, 0, Qt.AlignRight)
self.hBoxLayout.addSpacing(16)

54 changes: 54 additions & 0 deletions app/components/settings/line_edit_setting_card.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""
Author: Night-stars-1 nujj1042633805@gmail.com
Date: 2024-04-07 23:54:39
LastEditTime: 2024-04-10 01:11:23
LastEditors: Night-stars-1 nujj1042633805@gmail.com
"""
from typing import Union

from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtGui import QIcon
from qfluentwidgets import SettingCard, FluentIconBase, LineEdit, PasswordLineEdit, ConfigItem
from qfluentwidgets import qconfig

class LineEditSettingCard(SettingCard):
""" Setting card with a push button """

text_change = pyqtSignal()

def __init__(self, configItem: ConfigItem, holderText: str, icon: Union[str, QIcon, FluentIconBase], title: str, content=None, parent=None, isPassword=False):
"""
Parameters
----------
text: str
the text of push button
icon: str | QIcon | FluentIconBase
the icon to be drawn
title: str
the title of card
content: str
the content of card
parent: QWidget
parent widget
"""
super().__init__(icon, title, content, parent)
self.configItem = configItem

if isPassword:
self.lineEdit = PasswordLineEdit(self)
else:
self.lineEdit = LineEdit(self)
self.lineEdit.setText(qconfig.get(self.configItem))
self.lineEdit.setPlaceholderText(holderText)

self.lineEdit.textChanged.connect(self.textChanged)
self.hBoxLayout.addWidget(self.lineEdit, 0, Qt.AlignRight)
self.hBoxLayout.addSpacing(16)
#self.button.clicked.connect(self.clicked)

def textChanged(self, text):
qconfig.set(self.configItem, text)
84 changes: 84 additions & 0 deletions app/view/daily_task_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
"""
Author: Night-stars-1 nujj1042633805@gmail.com
Date: 2024-04-10 22:54:08
LastEditTime: 2024-04-10 22:56:06
LastEditors: Night-stars-1 nujj1042633805@gmail.com
"""

from loguru import logger
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QLabel, QWidget
from qfluentwidgets import CheckBox, ExpandLayout
from qfluentwidgets import FluentIcon as FIF
from qfluentwidgets import ScrollArea, SettingCardGroup

from ..common.style_sheet import StyleSheet

DAILYTASKS = [
"今日首次登录",
"获得5场战斗胜利",
"完成1个治安任务",
"在休息区的黑月商店购买1次桦石",
"成功抬价3次",
"完成1个商会订单",
"通过交易赚到20000铁盟币",
"单笔交易利润达到30000 铁盟币",
"行驶200KM",
"行驶300KM",
"成功砍价1次",
"成功抬价1次",
"通过交易赚到50000铁盟币",
"通过交易赚到100000铁盟币",
]


class DailyTaskInterface(ScrollArea):
"""每日任务 interface"""

def __init__(self, parent=None):
super().__init__(parent=parent)
self.scrollWidget = QWidget(self)
self.expandLayout = ExpandLayout(self.scrollWidget)

# label
self.settingLabel = QLabel("每日任务", self)

self.__initWidget()

def loadSamples(self):
"""load samples"""
# basic input samples
self.configGroup = SettingCardGroup("施工中...", self.scrollWidget)

for daily_task_name in DAILYTASKS:
self.configGroup.addSettingCard(
CheckBox(
text=daily_task_name,
parent=self.configGroup,
)
)

def __initWidget(self):
self.resize(1000, 800)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setViewportMargins(0, 80, 0, 20)
self.setWidget(self.scrollWidget)
self.setWidgetResizable(True)
self.setObjectName("DailyTaskInterface")

# initialize style sheet
self.scrollWidget.setObjectName("scrollWidget")
self.settingLabel.setObjectName("settingLabel")
StyleSheet.SETTING_INTERFACE.apply(self)

# initialize layout
self.loadSamples()
self.__initLayout()

def __initLayout(self):
self.settingLabel.move(36, 30)

# add setting card group to layout
self.expandLayout.setSpacing(28)
self.expandLayout.setContentsMargins(36, 10, 36, 0)
self.expandLayout.addWidget(self.configGroup)
13 changes: 6 additions & 7 deletions app/view/home_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class HomeInterface(ScrollArea):

def __init__(self, parent=None):
super().__init__(parent=parent)
self.workers: Dict[str, Worker] = {} # 用于存储活动的 Worker 实例
self.workers: Worker = None # 用于存储活动的 Worker 实例

self.banner = BannerWidget(self)
self.view = QWidget(self)
Expand Down Expand Up @@ -126,15 +126,14 @@ def _run(self):
self.run.titleLabel.setText("停止")
from main import main, stop

worker = Worker(main, stop)
self.workers["run"] = worker
worker.finished.connect(lambda: self.on_worker_finished(worker))
worker.start()
self.workers = Worker(main, stop)
self.workers.finished.connect(lambda: self.on_worker_finished(self.workers))
self.workers.start()
else:
self.workers["run"].stop()
self.workers.stop()

def on_worker_finished(self, worker: Worker):
# 线程完成时调用
self.run.titleLabel.setText("运行")
worker.deleteLater() # 安全删除Worker对象
del self.workers["run"]
self.workers = None
6 changes: 5 additions & 1 deletion app/view/main_window.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Author: Night-stars-1 nujj1042633805@gmail.com
Date: 2024-04-02 19:27:03
LastEditTime: 2024-04-08 13:10:44
LastEditTime: 2024-04-10 13:47:36
LastEditors: Night-stars-1 nujj1042633805@gmail.com
"""

Expand All @@ -19,6 +19,8 @@
SplashScreen,
)

from app.view.daily_task_interface import DailyTaskInterface

from ..common import resource # 图标数据
from ..common.config import cfg
from ..common.icon import FluentIconBase
Expand All @@ -42,6 +44,7 @@ def __init__(self):
self.tajInterface = TajInterface(self)
self.loggerInterface = LoggerInterface(self)
self.settingInterface = SettingInterface(self)
self.daily_task_interface = DailyTaskInterface(self)

self.connectSignalToSlot()

Expand All @@ -58,6 +61,7 @@ def initNavigation(self):
self.addSubInterface(self.homeInterface, FIF.HOME, "Home")
self.addSubInterface(self.tajInterface, FIF.AIRPLANE, "铁安局")
self.addSubInterface(self.loggerInterface, FIF.ALIGNMENT, "日志")
self.addSubInterface(self.daily_task_interface, FIF.CALENDAR, "每日任务")

# add custom widget to bottom
self.addSubInterface(
Expand Down
19 changes: 17 additions & 2 deletions app/view/setting_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from PyQt5.QtCore import Qt, QStandardPaths
from PyQt5.QtWidgets import QWidget, QLabel

from app.components.line_edit_setting_card import LineEditSettingCard

from ..components.settings.line_edit_setting_card import LineEditSettingCard
from ..common.config import cfg
from ..common.style_sheet import StyleSheet

Expand Down Expand Up @@ -48,6 +47,20 @@ def __init__(self, parent=None):
"商品请求测试",
self.musicInThisPCGroup
)
self.adbPathCard = LineEditSettingCard(
cfg.adbPath,
"ADB路径",
FIF.PALETTE,
"ADB程序路径",
parent=self.musicInThisPCGroup
)
self.adbOrderCard = LineEditSettingCard(
cfg.adbOrder,
"ADB地址",
FIF.PALETTE,
"ADB地址",
parent=self.musicInThisPCGroup
)
self.__initWidget()

def __initWidget(self):
Expand All @@ -74,6 +87,8 @@ def __initLayout(self):
self.musicInThisPCGroup.addSettingCard(self.goodsTypeCard)
self.musicInThisPCGroup.addSettingCard(self.uuidCard)
self.musicInThisPCGroup.addSettingCard(self.testCard)
self.musicInThisPCGroup.addSettingCard(self.adbPathCard)
self.musicInThisPCGroup.addSettingCard(self.adbOrderCard)

# add setting card group to layout
self.expandLayout.setSpacing(28)
Expand Down
Loading

0 comments on commit c81f3bc

Please sign in to comment.