-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from poul1x/feature/device-select-pane
DeviceSelectPane
- Loading branch information
Showing
40 changed files
with
1,655 additions
and
619 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from dataclasses import dataclass | ||
from enum import Enum, auto | ||
from typing import Optional | ||
|
||
|
||
class RunAppAction(int, Enum): | ||
StartApp = 0 | ||
StartAppDebug = auto() | ||
DoNotStartApp = auto() | ||
|
||
|
||
@dataclass | ||
class AdbServerSettings: | ||
ipAddr: str | ||
port: int | ||
|
||
|
||
@dataclass | ||
class LastSelectedDevice: | ||
serial: str | ||
displayName: str | ||
|
||
|
||
@dataclass | ||
class LastSelectedPackage: | ||
name: str | ||
action: RunAppAction | ||
|
||
|
||
@dataclass | ||
class AppState: | ||
adb: AdbServerSettings | ||
lastSelectedDevice: Optional[LastSelectedDevice] | ||
lastSelectedPackage: Optional[LastSelectedPackage] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .pane import DeviceSelectPane | ||
|
||
__all__ = [ | ||
"DeviceSelectPane", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from PyQt5.QtCore import Qt | ||
from PyQt5.QtWidgets import QHBoxLayout, QPushButton, QSizePolicy, QWidget | ||
|
||
|
||
class ButtonBar(QWidget): | ||
def __init__(self, parent: QWidget): | ||
super().__init__(parent) | ||
self.setObjectName("BottomButtonBar") | ||
self.setAttribute(Qt.WA_StyledBackground) | ||
self.initUserInterface() | ||
|
||
def initUserInterface(self): | ||
layout = QHBoxLayout() | ||
layout.setAlignment(Qt.AlignRight | Qt.AlignVCenter) | ||
layout.setContentsMargins(0, 0, 0, 0) | ||
|
||
self.selectButton = QPushButton("Select") | ||
self.selectButton.setEnabled(False) | ||
self.selectButton.setProperty("name", "select") | ||
self.selectButton.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) | ||
layout.addWidget(self.selectButton) | ||
|
||
self.cancelButton = QPushButton("Cancel") | ||
self.cancelButton.setProperty("name", "cancel") | ||
self.cancelButton.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) | ||
layout.addWidget(self.cancelButton) | ||
self.setLayout(layout) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
from enum import Enum, auto | ||
from typing import Optional | ||
|
||
from PyQt5.QtCore import QModelIndex, QObject, QSortFilterProxyModel, Qt | ||
from PyQt5.QtGui import QStandardItem, QStandardItemModel | ||
|
||
|
||
class Columns(int, Enum): | ||
serial = 0 | ||
displayName = auto() | ||
cpuArch = auto() | ||
osName = auto() | ||
apiLevels = auto() | ||
|
||
|
||
class DataModel(QStandardItemModel): | ||
def __init__(self, parent): | ||
super().__init__(0, len(Columns), parent) | ||
self.setHorizontalHeaderLabels( | ||
[ | ||
"Device Serial", | ||
"Device Name", | ||
"CPU Arch", | ||
"OS Info", | ||
"API Levels", | ||
] | ||
) | ||
|
||
def addValidDevice( | ||
self, | ||
deviceSerial: str, | ||
deviceName: str, | ||
osInfo: str, | ||
cpuArch: str, | ||
apiLevels: str, | ||
): | ||
itemSerial = QStandardItem(deviceSerial) | ||
itemSerial.setData(True, Qt.UserRole) | ||
|
||
self.appendRow( | ||
[ | ||
itemSerial, | ||
QStandardItem(deviceName), | ||
QStandardItem(cpuArch), | ||
QStandardItem(osInfo), | ||
QStandardItem(apiLevels), | ||
] | ||
) | ||
|
||
def addInvalidDevice( | ||
self, | ||
deviceSerial: str, | ||
errorMessage: str, | ||
): | ||
itemSerial = QStandardItem(deviceSerial) | ||
itemSerial.setData(False, Qt.UserRole) | ||
|
||
self.appendRow( | ||
[ | ||
itemSerial, | ||
QStandardItem(errorMessage), | ||
] | ||
) | ||
|
||
item = self.item(self.rowCount() - 1, Columns.serial) | ||
item.setData(False, Qt.UserRole) | ||
|
||
def removeAllDevices(self): | ||
self.removeRows(0, self.rowCount()) | ||
|
||
def setEmptyDeviceList(self): | ||
self.removeAllDevices() | ||
|
||
item = QStandardItem("¯\_(ツ)_/¯") | ||
item.setSelectable(False) | ||
item.setEnabled(False) | ||
item.setData(Qt.AlignCenter, Qt.TextAlignmentRole) | ||
self.appendRow(item) | ||
|
||
def findDeviceRowBySerial(self, serial: str): | ||
items = self.findItems(serial, Qt.MatchExactly, Columns.serial) | ||
return items[0].row() if items else -1 | ||
|
||
|
||
class FilterModel(QSortFilterProxyModel): | ||
def __init__(self, parent: Optional[QObject] = None): | ||
super().__init__(parent) | ||
self.setFilterCaseSensitivity(Qt.CaseInsensitive) | ||
|
||
def filterAcceptsRow(self, sourceRow: int, sourceParent: QModelIndex): | ||
regex = self.filterRegExp() | ||
sourceModel = self.sourceModel() | ||
assert isinstance(sourceModel, DataModel) | ||
serial = sourceModel.index(sourceRow, Columns.serial, sourceParent).data() | ||
name = sourceModel.index(sourceRow, Columns.displayName, sourceParent).data() | ||
return regex.indexIn(serial) != -1 or regex.indexIn(name) != -1 |
Oops, something went wrong.