<html dir="ltr"><head></head><body style="text-align:left; direction:ltr;" bgcolor="#ffffff" text="#2e3436" link="#737373" vlink="#2e3436"><div>Hi Alex,</div><div><br></div><div>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><br></div><div>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><br></div><div>You also need to import QtCore in model.py as someone else has pointed out.</div><div><br></div><div>I've attached the corrected files.</div><div><br></div><div>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><br></div><div>Regards,</div><div>Tony.</div><div><br></div><div>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><pre><br></pre><pre>I’m new to qt and pyqt.</pre><pre><br></pre><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><pre><br></pre><pre>What am I doing wrong?</pre><pre><br></pre><pre>Any help appreciated,</pre><pre>Axel</pre><pre><br></pre><pre>[1]</pre><pre><br></pre><pre>from za_main_ui import Ui_mainWindow</pre><pre>from PyQt5 import QtWidgets, QtCore</pre><pre><br></pre><pre>##from PyQt5.QtCore import QModelIndex, Qt</pre><pre><br></pre><pre>import dns.query, dns.resolver, dns.zone, dns.rdataset, dns.rdatatype</pre><pre>import sys</pre><pre><br></pre><pre>windowHeading = 'za - DNS zone admin'</pre><pre><br></pre><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><pre><br></pre><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><pre><br></pre><pre> def columnCount(self, parent=None):</pre><pre> return self.zone.columnCount()</pre><pre><br></pre><pre> def rowCount(self, parent=None):</pre><pre> return self.zone.rowCount()</pre><pre><br></pre><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><pre><br></pre><pre><br></pre><pre>class Zone(object):</pre><pre> IP_XFR_NS = '1234:5678:9abc:def::1'</pre><pre><br></pre><pre> def __init__(self, zone_name):</pre><pre> self.zone_name = zone_name</pre><pre> self.z = dns.zone</pre><pre> self.d = [['', '', '', '']]</pre><pre><br></pre><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><pre><br></pre><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><pre><br></pre><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><pre><br></pre><pre><br></pre><pre> def columnCount(self):</pre><pre> if len(self.d) < 2:</pre><pre> self.loadZone()</pre><pre> return len(self.d[0])</pre><pre><br></pre><pre> def rowCount(self):</pre><pre> if len(self.d) < 2:</pre><pre> self.loadZone()</pre><pre> return len(self.d)</pre><pre><br></pre><pre><br></pre><pre>class ZaMainWindow(QtWidgets.QMainWindow,Ui_mainWindow):</pre><pre> def __init__(self):</pre><pre> super(ZaMainWindow,self).__init__()</pre><pre> self.setupUi(self)</pre><pre><br></pre><pre>if __name__ == '__main__':</pre><pre> app = QtWidgets.QApplication(sys.argv)</pre><pre><br></pre><pre> domainZones = {}</pre><pre> ip4Zones = {}</pre><pre> ip6Zones = {}</pre><pre><br></pre><pre> subdomains = {}</pre><pre> ip4Nets = {}</pre><pre> ip6Nets = {}</pre><pre><br></pre><pre><br></pre><pre><br></pre><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><pre><br></pre><pre> sys.exit(app.exec_())</pre><pre><br></pre><pre><br></pre><pre><br></pre><pre>[2]</pre><pre>za.py:</pre><pre><br></pre><pre>from za_main_ui import Ui_mainWindow</pre><pre>from .model import ZoneModel</pre><pre>from PyQt5 import QtWidgets</pre><pre><br></pre><pre><br></pre><pre>class ZaMainWindow(QtWidgets.QMainWindow,Ui_mainWindow):</pre><pre> def __init__(self):</pre><pre> super(ZaMainWindow,self).__init__()</pre><pre> self.setupUi(self)</pre><pre><br></pre><pre>if __name__ == '__main__':</pre><pre> app = QtWidgets.QApplication(sys.argv)</pre><pre><br></pre><pre> domainZones = {}</pre><pre> ip4Zones = {}</pre><pre> ip6Zones = {}</pre><pre><br></pre><pre> subdomains = {}</pre><pre> ip4Nets = {}</pre><pre> ip6Nets = {}</pre><pre><br></pre><pre><br></pre><pre><br></pre><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><pre><br></pre><pre> sys.exit(app.exec_())</pre><pre><br></pre><pre>model.py:</pre><pre><br></pre><pre>import dns.query, dns.resolver, dns.zone, dns.rdataset, dns.rdatatype</pre><pre><br></pre><pre>windowHeading = 'za - DNS zone admin'</pre><pre><br></pre><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><pre><br></pre><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><pre><br></pre><pre> def columnCount(self, parent=None):</pre><pre> return self.zone.columnCount()</pre><pre><br></pre><pre> def rowCount(self, parent=None):</pre><pre> return self.zone.rowCount()</pre><pre><br></pre><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><pre><br></pre><pre><br></pre><pre>class Zone(object):</pre><pre> IP_XFR_NS = '1234:5678:9abc:def::1‘</pre><pre><br></pre><pre> def __init__(self, zone_name):</pre><pre> self.zone_name = zone_name</pre><pre> self.z = dns.zone</pre><pre> self.d = [['', '', '', '']]</pre><pre><br></pre><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><pre><br></pre><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><pre><br></pre><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><pre><br></pre><pre><br></pre><pre> def columnCount(self):</pre><pre> if len(self.d) < 2:</pre><pre> self.loadZone()</pre><pre> return len(self.d[0])</pre><pre><br></pre><pre> def rowCount(self):</pre><pre> if len(self.d) < 2:</pre><pre> self.loadZone()</pre><pre> return len(self.d)</pre><pre><br></pre><pre><br></pre><pre><br></pre><pre>---</pre><pre>PGP-Key: CDE74120 ☀ computing @ chaos claudius</pre><pre><br></pre></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>