Skip to content

Commit

Permalink
feat: 添加adb端口查询
Browse files Browse the repository at this point in the history
  • Loading branch information
Night-stars-1 committed Feb 5, 2025
1 parent d064431 commit c371157
Show file tree
Hide file tree
Showing 12 changed files with 210 additions and 151 deletions.
17 changes: 16 additions & 1 deletion app/components/button_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def __init__(self, title: str, header: QWidget = None, parent=None):
self.flowLayout.setVerticalSpacing(12)

self.vBoxLayout.addWidget(self.titleLabel)
self.vBoxLayout.addWidget(header)
if header:
self.vBoxLayout.addWidget(header)
self.vBoxLayout.addLayout(self.flowLayout, 1)

self.titleLabel.setObjectName("viewTitleLabel")
Expand All @@ -83,3 +84,17 @@ def addSampleCard(self, icon, title, content, func, routekey=None):
card = SampleCard(icon, title, content, func, routekey, self)
self.flowLayout.addWidget(card)
return card

def removeAllSampleCards(self):
"""删除所有卡片"""
for i in reversed(range(self.flowLayout.count())):
item = self.flowLayout.itemAt(i)
if item is not None:
widget = item.widget()
if widget is not None:
self.flowLayout.removeWidget(widget)
widget.setParent(None)
widget.deleteLater()

def set_title(self, title: str):
self.titleLabel.setText(title)
28 changes: 18 additions & 10 deletions app/components/settings/custom_adb_setting_card.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding:utf-8
from typing import Union
from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtGui import QIcon, QColor
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import (
QWidget,
QLabel,
Expand Down Expand Up @@ -33,14 +33,11 @@ def __init__(
self.configItem = configItem
self.customConfigItem = customConfigItem
self.defaultItem = "Custom"
self.customItem = qconfig.get(configItem)

self.choiceLabel = QLabel(self)
self.radioWidget = QWidget(self.view)
self.radioLayout = QVBoxLayout(self.radioWidget)
self.defaultRadioButton = RadioButton(
"自定义ADB端口", self.radioWidget
)
self.defaultRadioButton = RadioButton("自定义ADB端口", self.radioWidget)
self.defaultRadioButton.setProperty("option", self.defaultItem)
self.defaultRadioButton.setChecked(self.configItem.value == self.defaultItem)
# self.customRadioButton = RadioButton(self.tr("Custom color"), self.radioWidget)
Expand All @@ -50,13 +47,12 @@ def __init__(
self.buttonGroup.addButton(button)
self.radioLayout.addWidget(button)
button.setProperty("option", option)
button.setChecked(option == self.configItem.value)
# button.setChecked(option == self.configItem.value)

self.customItemWidget = QWidget(self.view)
self.customItemLayout = QHBoxLayout(self.customItemWidget)
self.customLabel = QLabel("自定义ADB端口", self.customItemWidget)
self.chooseItemLineEdit = LineEdit(self.customItemWidget)
self.chooseItemLineEdit.setText(self.customConfigItem.value)

self.__initLayout()

Expand All @@ -68,7 +64,7 @@ def __initLayout(self):
self.radioLayout.setContentsMargins(48, 18, 0, 18)
self.buttonGroup.addButton(self.defaultRadioButton)
self.radioLayout.addWidget(self.defaultRadioButton)

self.radioLayout.setSizeConstraint(QVBoxLayout.SetMinimumSize)

self.customItemLayout.setContentsMargins(48, 18, 44, 18)
Expand All @@ -84,18 +80,27 @@ def __initLayout(self):
self.__initWidget()

def __initWidget(self):
if self.defaultItem == self.customItem:
customItem = qconfig.get(self.configItem)
# 更新ADB端口输入状态
if self.defaultItem == customItem:
self.chooseItemLineEdit.setEnabled(True)
else:
self.chooseItemLineEdit.setEnabled(False)

# 更新模拟器选项
for button in self.buttonGroup.buttons():
option = button.property("option")
button.setChecked(option == self.configItem.value)

self.choiceLabel.setText(self.buttonGroup.checkedButton().text())
self.choiceLabel.adjustSize()

self.chooseItemLineEdit.setObjectName("chooseColorButton")

self.buttonGroup.buttonClicked.connect(self.__onRadioButtonClicked)
self.chooseItemLineEdit.textChanged.connect(self.__onChooseItemTextChanged)
# adb端口文本
self.chooseItemLineEdit.setText(self.customConfigItem.value)

def __onRadioButtonClicked(self, button: RadioButton):
"""radio button clicked slot"""
Expand All @@ -113,3 +118,6 @@ def __onRadioButtonClicked(self, button: RadioButton):

def __onChooseItemTextChanged(self, text):
qconfig.set(self.customConfigItem, text)

def update(self):
self.__initWidget()
73 changes: 73 additions & 0 deletions app/view/adb_data_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""
Author: Night-stars-1 nujj1042633805@gmail.com
Date: 2024-04-10 22:54:08
LastEditTime: 2025-02-05 18:42:29
LastEditors: Night-stars-1 nujj1042633805@gmail.com
"""

from PyQt5.QtWidgets import QWidget, QVBoxLayout
from qfluentwidgets import ScrollArea
from functools import partial

from app.components.button_card import ButtonCardView
from core.adb.adb_port import get_all_port

from app.common.config import cfg
from app.common.style_sheet import StyleSheet
from app.common.worker import Worker
from core.model.config import config
from app.common.config import qconfig

class ADBDataInterface(ScrollArea):
"""ADB端口信息扫描 interface"""

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

self.vBoxLayout = QVBoxLayout(self.scrollWidget)

self.__initWidget()

def __initWidget(self):
self.setViewportMargins(0, 20, 0, 20)
self.setWidget(self.scrollWidget)
self.setWidgetResizable(True)
self.setObjectName("ADBDataInterface")

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

# initialize layout
self.loadSamples()

def showEvent(self, event):
"""当切换到该页面时,触发这个事件"""
super().showEvent(event)
self.basicInputView.removeAllSampleCards()
self.basicInputView.set_title("加载中...")
self.worker = Worker(get_all_port, get_all_port)
self.worker.result.connect(self.update_adb)
self.worker.start()

def loadSamples(self):
"""load samples"""
self.basicInputView = ButtonCardView("加载中...", parent=self.scrollWidget)

self.vBoxLayout.addWidget(self.basicInputView)

def update_adb(self, data: dict[str, str]):
self.basicInputView.set_title("ADB信息")
for name, port in data.items():
self.basicInputView.addSampleCard(
icon=":/gallery/images/controls/Button.png",
title=name,
content=f"127.0.0.1:{port}",
func=partial(self.set_port, port),
)

def set_port(self, port: str):
qconfig.set(cfg.adbPort, port)
qconfig.set(cfg.emulatorType, "Custom")

2 changes: 1 addition & 1 deletion app/view/home_interface.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:12:22
LastEditTime: 2024-12-28 01:00:05
LastEditTime: 2025-02-05 17:46:18
LastEditors: Night-stars-1 nujj1042633805@gmail.com
"""

Expand Down
8 changes: 4 additions & 4 deletions 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-12-27 23:59:46
LastEditTime: 2025-02-05 17:31:12
LastEditors: Night-stars-1 nujj1042633805@gmail.com
"""

Expand Down Expand Up @@ -37,7 +37,7 @@
from .logger_interface import LoggerInterface
from .setting_interface import SettingInterface
from .taj_interface import TajInterface
from .this_road_that_interface import ThisRoadThatInterface
from .adb_data_interface import ADBDataInterface


class MainWindow(MSFluentWindow):
Expand All @@ -56,7 +56,7 @@ def __init__(self):
self.daily_task_interface = DailyTaskInterface(self)
self.running_business_interface = RunningBusinessInterface(self)
self.two_run_business_interface = TwoRunBusinessInterface(self)
self.this_road_that_interface = ThisRoadThatInterface(self)
self.adb_data_interface = ADBDataInterface(self)

self.connectSignalToSlot()

Expand All @@ -78,7 +78,7 @@ def initNavigation(self):
self.addSubInterface(self.daily_task_interface, FIF.CALENDAR, "每日任务")
self.addSubInterface(self.running_business_interface, FIF.TRAIN, "跑商配置")
self.addSubInterface(self.two_run_business_interface, FIF.TRAIN, "端点跑商")
self.addSubInterface(self.this_road_that_interface, FIF.TRAIN, "我建我路")
self.addSubInterface(self.adb_data_interface, FIF.TRAIN, "ADB信息")

# add custom widget to bottom
self.addSubInterface(
Expand Down
8 changes: 7 additions & 1 deletion app/view/setting_interface.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-07 23:14:47
LastEditTime: 2024-07-09 17:55:56
LastEditTime: 2025-02-05 18:41:58
LastEditors: Night-stars-1 nujj1042633805@gmail.com
"""

Expand Down Expand Up @@ -124,3 +124,9 @@ def __initLayout(self):
self.expandLayout.setSpacing(28)
self.expandLayout.setContentsMargins(36, 10, 36, 0)
self.expandLayout.addWidget(self.musicInThisPCGroup)

def showEvent(self, event):
"""当切换到该页面时,触发这个事件"""
super().showEvent(event)
# 刷新adb设置
self.adbOrderCard.update()
123 changes: 0 additions & 123 deletions app/view/this_road_that_interface.py

This file was deleted.

Loading

0 comments on commit c371157

Please sign in to comment.