-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard_widget.py
executable file
·97 lines (75 loc) · 3.28 KB
/
board_widget.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import logging
from PySide2 import QtWidgets
from typing import Optional
from forms.ui_board_widget import Ui_BoardWidget
from forms.ui_device_widget import Ui_DeviceWidget
from jh_resource import ResourceBoard, ResourceCPU
from jh_resource import PlatformMgr, ResourceSignals
from flowlayout import FlowLayout
from common_widget import SelectButton, clean_layout
from cpu_edit_widget import CPUEditWidget
from mem_edit_widget import MemEditWidget
import utils
class BoardWidget(QtWidgets.QWidget):
logger = logging.getLogger('BoardWidget')
def __init__(self, parent=None):
super().__init__(parent)
self._ui = Ui_BoardWidget()
self._ui.setupUi(self)
self._board_mem_editor = MemEditWidget()
self._ui.frame_board_mems.layout().addWidget(self._board_mem_editor)
self._board: Optional[ResourceBoard] = None
self._device_layout = FlowLayout(self._ui.frame_devices_items)
self._cpu_editor = CPUEditWidget(self)
self._ui.frame_cpus_content.layout().addWidget(self._cpu_editor)
self._ui.btn_update_from_plt.clicked.connect(self._on_update_from_plt)
self._cpu_editor.cpus_changed.connect(self._on_cpus_changed)
self._board_mem_editor.signal_changed.connect(self._on_board_mems_changed)
ResourceSignals.modified.connect(self._on_rsc_modified)
def set_board(self, board: ResourceBoard):
self._board = board
self._update()
def _update(self):
board = self._board
self._ui.label_model.setText("")
self._ui.label_vendor.setText("")
clean_layout(self._device_layout)
self._cpu_editor.set_cpu_count(0)
self._board_mem_editor.set_regions(list())
if board is None:
return
self._ui.label_model.setText(board.model)
self._ui.label_vendor.setText(board.vendor)
cpu: ResourceCPU = board.parent().cpu()
dev_names = sorted(map(lambda x: x.name(), cpu.devices()))
for dev in dev_names:
w = SelectButton(dev, self)
self._device_layout.addWidget(w)
if dev in board.devices:
w.setChecked(True)
self._cpu_editor.set_cpu_count( cpu.cpu_count() )
self._cpu_editor.set_cpus(board.cpus())
self._board_mem_editor.set_regions(board.ram_regions())
def _on_rsc_modified(self, sender, **kwargs):
if sender is not self._board:
return
self._update()
def _on_update_from_plt(self):
if self._board is None:
return
board: PlatformMgr.Board = PlatformMgr.get_instance().find_board(self._board.name())
if board is None:
self.logger.error(f"can not find board {self._board.name()} from platform")
return
if not self._board.from_dict(board.value):
self.logger.error(f"update board failed.")
return
self._board.set_modified()
def _on_cpus_changed(self):
if self._board is None:
return
self._board.set_cpus(self._cpu_editor.get_cpus())
def _on_board_mems_changed(self):
if self._board is None:
return
self._board.set_ram_regions(self._board_mem_editor.get_value())