From 9aba3ebf5eaf09d8e96dba6c4e0936b3ba2a4d2a Mon Sep 17 00:00:00 2001 From: Fierelier Date: Sat, 20 Mar 2021 16:01:51 +0100 Subject: [PATCH] Add option to allow opening multiple windows --- BirdyNet.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/BirdyNet.py b/BirdyNet.py index 8344bbf..1aa058a 100644 --- a/BirdyNet.py +++ b/BirdyNet.py @@ -27,6 +27,7 @@ from qtpy.QtMultimedia import QSound import configparser import json import time +browserWindows = [] os.chdir(sp) distro = os.path.splitext(s.rsplit(os.path.sep)[-1])[0] @@ -89,8 +90,10 @@ class browserWindow(QMainWindow): def cCreateElements(self): self.cMenuBar = self.menuBar() - self.cFileMenu = self.cMenuBar.addMenu("File") - self.cViewMenu = self.cMenuBar.addMenu("View") + self.cFileMenu = self.cMenuBar.addMenu("&File") + self.cNewWindowButton = self.cFileMenu.addAction("New &window") + self.cNewWindowButton.triggered.connect(self.cNewWindow) + self.cViewMenu = self.cMenuBar.addMenu("&View") self.cUrlBar = QLineEdit(config["default"]["home"],self) self.cUrlBar.returnPressed.connect(self.cNavigate) @@ -126,6 +129,10 @@ class browserWindow(QMainWindow): self.cHeight = self.height() self.cResizeElements() + def closeEvent(self,event): + browserWindows.remove(self) + event.accept() + def cNavigate(self,event = None): try: #print(prettyJson(parseUrl(self.cUrlBar.text()))) @@ -152,6 +159,11 @@ class browserWindow(QMainWindow): except Exception as e: self.cDoc.cRenderHtml(str(e)) raise + + def cNewWindow(self): + w = browserWindow() + browserWindows.append(w) + w.show() def main(): # load program default addons @@ -183,7 +195,7 @@ def main(): app.setWindowIcon(QtGui.QIcon("assets/BirdyNet-XP.ico")) except Exception as e: print("Could not set window icon: " +print(e)) - window = browserWindow() + browserWindows.append(browserWindow()) sys.exit(app.exec_())