<html dir="ltr"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body class="" style="text-align:left; direction:ltr;" bgcolor="#ffffff" text="#2e3436" link="#737373" vlink="#2e3436"><div>Hi Axel,</div><div><br></div><div>This is a bit of a guess but I don't see anything in your model that would cause the view to update, so you may need to emit a data changed signal from your model. This should be picked up by the view and update it.</div><div><br></div><div>(It would be useful to see the ui source file, as I presume that's where the view is defined).</div><div><br></div><div>Regards,</div><div>Tony.</div><div><br></div><div>On Sun, 2021-06-20 at 19:41 +0200, Axel Rau wrote:</div><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex">Hi, David and Tony,<div class=""><br class=""></div><div class="">you both are right.</div><div class=""><br class=""></div><div class="">I made some mistakes while stripping down my codebase and while preparing it for the ML.</div><div class="">The posted code does not really show the problem, if corrected as you pointed out, Tony, it runs well.</div><div class="">And yes, I'm using PyCharm as IDE and I have a better structured layout [1].</div><div class=""><br class=""></div><div class="">To show the problem, I attach new versions of both files.</div><div class="">The problem happens, if I start creating and loading more zones by calling</div><div class="">model.loadZones() from the __main__ code in za.py (commented out in the attached version).</div><div class="">The debugger shows return from model.loadZones(), but nothing is displayed then.</div><div class=""><br class=""></div><div class="">I guess, model.loadZones() would better be called from some event code, once I’m using events.</div><div class=""><br class=""></div><div class="">Thanks for your help,</div><div class="">Axel</div><div class=""><br class=""></div><div class="">PS: [1] </div><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"><div></div><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"><div></div><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><div class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div><br class=""><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><div class="">Am 20.06.2021 um 16:01 schrieb Tony Arnold <<a href="mailto:tony.arnold@manchester.ac.uk" class="">tony.arnold@manchester.ac.uk</a>>:</div><br class="Apple-interchange-newline"><div class=""><div style="text-align:left; direction:ltr;" bgcolor="#ffffff" text="#2e3436" link="#737373" vlink="#2e3436" class=""><div class="">Hi Alex,</div><div class=""><br class=""></div><div class="">So the problem is how you reference ZoneModel in za.py. You're referencing it as model.ZoneModel on line 24. You should reference as just ZoneModel.</div><div class=""><br class=""></div><div class="">You also need to import sys in za.py, but that's not too critical unless you want to pass command line parameters into your application.</div><div class=""><br class=""></div><div class="">You also need to import QtCore in model.py as someone else has pointed out.</div><div class=""><br class=""></div><div class="">I've attached the corrected files.</div><div class=""><br class=""></div><div class="">I highly recommend using a suitable development environment which will highlight syntax and other errors dynamically. I would suggest using eric or pycharm.</div><div class=""><br class=""></div><div class="">Regards,</div><div class="">Tony.</div><div class=""><br class=""></div><div class="">On Sat, 2021-06-19 at 15:25 +0200, Axel Rau wrote:</div><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><pre>Hi all,</pre><br class=""><pre>I’m new to qt and pyqt.</pre><br class=""><pre>The test app [1] in one module works fine (mainwindow opens and shows loaded data).</pre><pre>After putting ZoneModel and Zone classes in separate modules (za.py, mode.py)[2], no MainWindow is displayed, just the app icon.</pre><br class=""><pre>What am I doing wrong?</pre><br class=""><pre>Any help appreciated,</pre><pre>Axel</pre><br class=""><pre>[1]</pre><br class=""><pre>from za_main_ui import Ui_mainWindow</pre><pre>from PyQt5 import QtWidgets, QtCore</pre><br class=""><pre>##from PyQt5.QtCore import QModelIndex, Qt</pre><br class=""><pre>import dns.query, dns.resolver, dns.zone, dns.rdataset, dns.rdatatype</pre><pre>import sys</pre><br class=""><pre>windowHeading = 'za - DNS zone admin'</pre><br class=""><pre>class ZoneModel(QtCore.QAbstractTableModel):</pre><pre> def __init__(self, data=[[]], parent=None):</pre><pre> super().__init__(parent)</pre><pre> self.zone = Zone('some.do.main‘)</pre><br class=""><pre> def headerData(self, section: int, orientation: QtCore.Qt.Orientation, role: int):</pre><pre> if role == QtCore.Qt.DisplayRole:</pre><pre> if orientation == QtCore.Qt.Horizontal:</pre><pre> return ['OwnerName', 'TTL', 'Type', 'Rdata'][section]</pre><pre> else:</pre><pre> return None</pre><br class=""><pre> def columnCount(self, parent=None):</pre><pre> return self.zone.columnCount()</pre><br class=""><pre> def rowCount(self, parent=None):</pre><pre> return self.zone.rowCount()</pre><br class=""><pre> def data(self, index: QtCore.QModelIndex, role: int):</pre><pre> if role == QtCore.Qt.DisplayRole:</pre><pre> row = index.row()</pre><pre> col = index.column()</pre><pre> return self.zone.data(row, col)</pre><br class=""><br class=""><pre>class Zone(object):</pre><pre> IP_XFR_NS = '1234:5678:9abc:def::1'</pre><br class=""><pre> def __init__(self, zone_name):</pre><pre> self.zone_name = zone_name</pre><pre> self.z = dns.zone</pre><pre> self.d = [['', '', '', '']]</pre><br class=""><pre> def data(self, row: int, column: int) -> str:</pre><pre> if not self.d:</pre><pre> self.loadZone()</pre><pre> v = self.d[row][column]</pre><pre> if not v: v = ''</pre><pre> return str(v)</pre><br class=""><pre> def loadZone(self):</pre><pre> row = 0</pre><pre> self.z = dns.zone.from_xfr(dns.query.xfr(self.IP_XFR_NS, self.zone_name))</pre><br class=""><pre> for name in self.z.keys():</pre><pre> name = str(name)</pre><pre> if name == '@': name = ''</pre><pre> self.d[row][0] = name</pre><pre> node = self.z[name]</pre><pre> for the_rdataset in node:</pre><pre> self.d[row][1] = str(the_rdataset.ttl)</pre><pre> for rdata in the_rdataset:</pre><pre> self.d[row][2] = dns.rdatatype.to_text(the_rdataset.rdtype)</pre><pre> self.d[row][3] = str(rdata)</pre><pre> row = row + 1</pre><pre> self.d.append(['', '', '', ''])</pre><br class=""><br class=""><pre> def columnCount(self):</pre><pre> if len(self.d) < 2:</pre><pre> self.loadZone()</pre><pre> return len(self.d[0])</pre><br class=""><pre> def rowCount(self):</pre><pre> if len(self.d) < 2:</pre><pre> self.loadZone()</pre><pre> return len(self.d)</pre><br class=""><br class=""><pre>class ZaMainWindow(QtWidgets.QMainWindow,Ui_mainWindow):</pre><pre> def __init__(self):</pre><pre> super(ZaMainWindow,self).__init__()</pre><pre> self.setupUi(self)</pre><br class=""><pre>if __name__ == '__main__':</pre><pre> app = QtWidgets.QApplication(sys.argv)</pre><br class=""><pre> domainZones = {}</pre><pre> ip4Zones = {}</pre><pre> ip6Zones = {}</pre><br class=""><pre> subdomains = {}</pre><pre> ip4Nets = {}</pre><pre> ip6Nets = {}</pre><br class=""><br class=""><br class=""><pre> mw = ZaMainWindow()</pre><pre> model = ZoneModel()</pre><pre> view = mw.maintableView</pre><pre> view.setColumnWidth(0, 200)</pre><pre> view.setColumnWidth(1, 40)</pre><pre> view.setColumnWidth(2, 40)</pre><pre> view.setColumnWidth(3, 400)</pre><pre> hh = view.horizontalHeader()</pre><pre> hh.setStretchLastSection(True)</pre><pre> hh.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)</pre><pre> view.setModel(model)</pre><pre> mw.show()</pre><br class=""><pre> sys.exit(app.exec_())</pre><br class=""><br class=""><br class=""><pre>[2]</pre><pre>za.py:</pre><br class=""><pre>from za_main_ui import Ui_mainWindow</pre><pre>from .model import ZoneModel</pre><pre>from PyQt5 import QtWidgets</pre><br class=""><br class=""><pre>class ZaMainWindow(QtWidgets.QMainWindow,Ui_mainWindow):</pre><pre> def __init__(self):</pre><pre> super(ZaMainWindow,self).__init__()</pre><pre> self.setupUi(self)</pre><br class=""><pre>if __name__ == '__main__':</pre><pre> app = QtWidgets.QApplication(sys.argv)</pre><br class=""><pre> domainZones = {}</pre><pre> ip4Zones = {}</pre><pre> ip6Zones = {}</pre><br class=""><pre> subdomains = {}</pre><pre> ip4Nets = {}</pre><pre> ip6Nets = {}</pre><br class=""><br class=""><br class=""><pre> mw = ZaMainWindow()</pre><pre> model = model.ZoneModel()</pre><pre> view = mw.maintableView</pre><pre> view.setColumnWidth(0, 200)</pre><pre> view.setColumnWidth(1, 40)</pre><pre> view.setColumnWidth(2, 40)</pre><pre> view.setColumnWidth(3, 400)</pre><pre> hh = view.horizontalHeader()</pre><pre> hh.setStretchLastSection(True)</pre><pre> hh.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)</pre><pre> view.setModel(model)</pre><pre> mw.show()</pre><br class=""><pre> sys.exit(app.exec_())</pre><br class=""><pre>model.py:</pre><br class=""><pre>import dns.query, dns.resolver, dns.zone, dns.rdataset, dns.rdatatype</pre><br class=""><pre>windowHeading = 'za - DNS zone admin'</pre><br class=""><pre>class ZoneModel(QtCore.QAbstractTableModel):</pre><pre> def __init__(self, data=[[]], parent=None):</pre><pre> super().__init__(parent)</pre><pre> self.zone = Zone('some.do.main')</pre><br class=""><pre> def headerData(self, section: int, orientation: QtCore.Qt.Orientation, role: int):</pre><pre> if role == QtCore.Qt.DisplayRole:</pre><pre> if orientation == QtCore.Qt.Horizontal:</pre><pre> return ['OwnerName', 'TTL', 'Type', 'Rdata'][section]</pre><pre> else:</pre><pre> return None</pre><br class=""><pre> def columnCount(self, parent=None):</pre><pre> return self.zone.columnCount()</pre><br class=""><pre> def rowCount(self, parent=None):</pre><pre> return self.zone.rowCount()</pre><br class=""><pre> def data(self, index: QtCore.QModelIndex, role: int):</pre><pre> if role == QtCore.Qt.DisplayRole:</pre><pre> row = index.row()</pre><pre> col = index.column()</pre><pre> return self.zone.data(row, col)</pre><br class=""><br class=""><pre>class Zone(object):</pre><pre> IP_XFR_NS = '1234:5678:9abc:def::1‘</pre><br class=""><pre> def __init__(self, zone_name):</pre><pre> self.zone_name = zone_name</pre><pre> self.z = dns.zone</pre><pre> self.d = [['', '', '', '']]</pre><br class=""><pre> def data(self, row: int, column: int) -> str:</pre><pre> if not self.d:</pre><pre> self.loadZone()</pre><pre> v = self.d[row][column]</pre><pre> if not v: v = ''</pre><pre> return str(v)</pre><br class=""><pre> def loadZone(self):</pre><pre> row = 0</pre><pre> self.z = dns.zone.from_xfr(dns.query.xfr(self.IP_XFR_NS, self.zone_name))</pre><br class=""><pre> for name in self.z.keys():</pre><pre> name = str(name)</pre><pre> if name == '@': name = ''</pre><pre> self.d[row][0] = name</pre><pre> node = self.z[name]</pre><pre> for the_rdataset in node:</pre><pre> self.d[row][1] = str(the_rdataset.ttl)</pre><pre> for rdata in the_rdataset:</pre><pre> self.d[row][2] = dns.rdatatype.to_text(the_rdataset.rdtype)</pre><pre> self.d[row][3] = str(rdata)</pre><pre> row = row + 1</pre><pre> self.d.append(['', '', '', ''])</pre><br class=""><br class=""><pre> def columnCount(self):</pre><pre> if len(self.d) < 2:</pre><pre> self.loadZone()</pre><pre> return len(self.d[0])</pre><br class=""><pre> def rowCount(self):</pre><pre> if len(self.d) < 2:</pre><pre> self.loadZone()</pre><pre> return len(self.d)</pre><br class=""><br class=""><br class=""><pre>---</pre><pre>PGP-Key: CDE74120 ☀ computing @ chaos claudius</pre><br class=""></blockquote><div class=""><span class=""><pre>-- </pre><br class=""><div class=""><div class=""><font size="2" class=""><font color="#3366ff" class=""><b class="">Tony Arnold</b> MBCS, CITP | Senior IT Security Analyst | Directorate of IT Services | Office 1, Kilburn Building | The University of Manchester | Manchester M13 9PL | </font><font color="#ff0000" class="">T:</font><font color="#3366ff" class=""> +44 161 275 6093 | </font><font color="#ff0000" class="">M:</font><font color="#3366ff" class=""> +44 773 330 0039</font></font></div></div></span></div></div>
<span id="cid:4BC4A028-8858-47DA-813F-3EBC8E04BE40@in.chaos1.de"><model.py></span><span id="cid:E427D8F3-D7ED-462E-BB59-288EC2DB25D2@in.chaos1.de"><za.py></span></div></blockquote></div><br class=""><div class="">
<div dir="auto" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div dir="auto" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant-ligatures: normal; font-variant-position: normal; font-variant-caps: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">---<br class="">PGP-Key: CDE74120 ☀ computing @ chaos claudius</div></div></div></div></div></div>
</div>
<br class=""></div></blockquote><div><span><pre>-- <br></pre><div><div><font size="2"><font color="#3366ff"><b>Tony Arnold</b> MBCS, CITP | Senior IT Security Analyst | Directorate of IT Services | Office 1, Kilburn Building | The University of Manchester | Manchester M13 9PL | </font><font color="#ff0000">T:</font><font color="#3366ff"> +44 161 275 6093 | </font><font color="#ff0000">M:</font><font color="#3366ff"> +44 773 330 0039</font></font></div></div></span></div></body></html>