Implement the Device Info popup

This essentially displays the same information as the simple
test script does with its "getavr()" function:

* device names (long and short)
* location of definition in config file
* device memories
* device variants
This commit is contained in:
Joerg Wunsch
2024-03-24 21:59:23 +01:00
parent 77bcf8693b
commit 9b6fb3cf03
2 changed files with 311 additions and 1 deletions

View File

@@ -69,12 +69,37 @@ def classify_devices():
result['other'].append(p.desc)
return result
def size_to_str(size: int):
if size >= 1024:
return f"{size // 1024} KiB"
return f"{size} B"
def yesno(val: bool):
if val:
return "Y"
return "N"
def avrpart_to_mem(avrpart):
if str(type(avrpart)).find('AVRPART') < 0:
raise Exception(f"wrong argument: {type(avrpart)}, expecting swig_avrdude.AVRPART")
res = []
m = ad.lfirst(avrpart.mem)
while m:
mm = ad.ldata_avrmem((m))
res.append(mm)
m = ad.lnext(m)
return res
from PySide2.QtWidgets import *
from PySide2.QtCore import QFile, QIODevice
from PySide2.QtGui import *
from PySide2.QtCore import *
from ui_adgui import Ui_MainWindow
from ui_about import Ui_About
from ui_device import Ui_Device
from ui_devinfo import Ui_DevInfo
class About(QDialog):
def __init__(self):
@@ -88,6 +113,12 @@ class Device(QDialog):
self.ui = Ui_Device()
self.ui.setupUi(self)
class DevInfo(QDialog):
def __init__(self):
super().__init__()
self.ui = Ui_DevInfo()
self.ui.setupUi(self)
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
@@ -103,6 +134,7 @@ class adgui():
self.window.show()
self.about = About()
self.device = Device()
self.devinfo = DevInfo()
self.window.ui.actionAbout.triggered.connect(self.about.show)
self.window.ui.actionDevice.triggered.connect(self.device.show)
@@ -125,6 +157,7 @@ class adgui():
self.device.ui.avr_de.stateChanged.connect(self.update_device_cb)
self.device.ui.other.stateChanged.connect(self.update_device_cb)
self.device.ui.buttonBox.accepted.connect(self.device_selected)
self.window.ui.actionDevice_Info.triggered.connect(self.devinfo.show)
def log(self, s: str):
self.logstring += s
@@ -165,9 +198,47 @@ class adgui():
for d in self.devices[f]:
self.device.ui.devices.addItem(d)
def update_device_info(self):
p = ad.locate_part(ad.cvar.part_list, self.dev_selected)
if not p:
log(f"Could not find {self.dev_selected} again, confused\n")
return
self.devinfo.ui.label_2.setText(p.desc)
self.devinfo.ui.label_4.setText(p.id)
self.devinfo.ui.label_6.setText(p.config_file)
self.devinfo.ui.label_8.setText(str(p.lineno))
model = QStandardItemModel()
model.setHorizontalHeaderLabels(['Name', 'Size', 'Paged', 'Page Size', '# Pages'])
mm = avrpart_to_mem(p)
row = 0
for m in mm:
model.setItem(row, 0, QStandardItem(m.desc))
sz = QStandardItem(size_to_str(m.size))
sz.setTextAlignment(Qt.AlignRight | Qt.AlignVCenter)
model.setItem(row, 1, sz)
pg = QStandardItem(yesno(m.paged))
pg.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
model.setItem(row, 2, pg)
if m.paged:
sz = QStandardItem(size_to_str(m.page_size))
sz.setTextAlignment(Qt.AlignRight | Qt.AlignVCenter)
model.setItem(row, 3, sz)
pg = QStandardItem(str(m.num_pages))
pg.setTextAlignment(Qt.AlignRight | Qt.AlignVCenter)
model.setItem(row, 4, pg)
row += 1
self.devinfo.ui.tableMemories.setModel(model)
self.devinfo.ui.listVariants.clear()
v = ad.lfirst(p.variants)
while v:
vv = ad.ldata_string(v)
self.devinfo.ui.listVariants.addItem(vv)
v = ad.lnext(v)
def device_selected(self):
self.dev_selected = self.device.ui.devices.currentText()
self.log(f"Selected device: {self.dev_selected}")
self.update_device_info()
self.window.ui.actionDevice_Info.setEnabled(True)

239
src/python/devinfo.ui Normal file
View File

@@ -0,0 +1,239 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DevInfo</class>
<widget class="QDialog" name="DevInfo">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>706</width>
<height>625</height>
</rect>
</property>
<property name="windowTitle">
<string>Device Info</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>320</x>
<y>560</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QWidget" name="gridLayoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>631</width>
<height>51</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="2">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Line:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>File:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_2">
<property name="styleSheet">
<string notr="true">background-color: rgb(255, 255, 255);</string>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="lineWidth">
<number>2</number>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="label_4">
<property name="styleSheet">
<string notr="true">background-color: rgb(255, 255, 255);</string>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="lineWidth">
<number>2</number>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Alias:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_6">
<property name="styleSheet">
<string notr="true">background-color: rgb(255, 255, 255);</string>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="lineWidth">
<number>2</number>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLabel" name="label_8">
<property name="styleSheet">
<string notr="true">background-color: rgb(255, 255, 255);</string>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="lineWidth">
<number>2</number>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="text">
<string>Device:</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QSplitter" name="splitter">
<property name="geometry">
<rect>
<x>20</x>
<y>80</y>
<width>631</width>
<height>421</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="opaqueResize">
<bool>true</bool>
</property>
<property name="handleWidth">
<number>5</number>
</property>
<property name="childrenCollapsible">
<bool>true</bool>
</property>
<widget class="QGroupBox" name="memoryOverview">
<property name="title">
<string>Memory Overview</string>
</property>
<widget class="QTableView" name="tableMemories">
<property name="geometry">
<rect>
<x>0</x>
<y>20</y>
<width>629</width>
<height>241</height>
</rect>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="deviceVariants">
<property name="title">
<string>Device Variants</string>
</property>
<widget class="QListWidget" name="listVariants">
<property name="geometry">
<rect>
<x>0</x>
<y>20</y>
<width>631</width>
<height>141</height>
</rect>
</property>
</widget>
</widget>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DevInfo</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>DevInfo</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>