Skip to content

Commit

Permalink
Merge pull request #16 from poul1x/feature/device-select-pane
Browse files Browse the repository at this point in the history
DeviceSelectPane
  • Loading branch information
poul1x authored Feb 8, 2025
2 parents fbbd1c0 + b53e20b commit 4a741c3
Show file tree
Hide file tree
Showing 40 changed files with 1,655 additions and 619 deletions.
34 changes: 34 additions & 0 deletions galog/app/app_state.py
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]
7 changes: 0 additions & 7 deletions galog/app/components/capture_pane/__init__.py

This file was deleted.

53 changes: 0 additions & 53 deletions galog/app/components/capture_pane/body.py

This file was deleted.

133 changes: 0 additions & 133 deletions galog/app/components/capture_pane/pane.py

This file was deleted.

5 changes: 5 additions & 0 deletions galog/app/components/device_select_pane/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .pane import DeviceSelectPane

__all__ = [
"DeviceSelectPane",
]
27 changes: 27 additions & 0 deletions galog/app/components/device_select_pane/button_bar.py
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)
96 changes: 96 additions & 0 deletions galog/app/components/device_select_pane/data_model.py
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
Loading

0 comments on commit 4a741c3

Please sign in to comment.