From 935f0dbfc38d6dba481811ed5dcc6d3fdc71a86e Mon Sep 17 00:00:00 2001
From: morkolai <nikolai-mork@live.no>
Date: Mon, 23 Mar 2020 11:12:15 +0100
Subject: [PATCH] =?UTF-8?q?#68=20f=C3=B8rste=20utkast=20av=20hvor=20kodere?=
 =?UTF-8?q?generering=20vises=20i=20gui?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 soitool/main_window.py | 33 ++++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)

diff --git a/soitool/main_window.py b/soitool/main_window.py
index bf2fb3d..79b3744 100644
--- a/soitool/main_window.py
+++ b/soitool/main_window.py
@@ -42,15 +42,16 @@ class MainWindow(QMainWindow):
         self.statusBar()
 
         # Database instance
-        database = Database()
+        self.database = Database()
+
         # Timer for automatic update of codes in CodeBook
         self.timer = QTimer()
         # Interval i set to msec since last 24h update
         self.timer.setInterval(
-            database.seconds_to_next_update(60 * 60 * 24) * 1000
+            self.database.seconds_to_next_update(60 * 60 * 24) * 1000
         )
         self.timer.timeout.connect(
-            lambda: database.update_codebook_auto(self.timer)
+            lambda: self.database.update_codebook_auto(self.timer)
         )
         self.timer.start()
 
@@ -106,6 +107,7 @@ class MainWindow(QMainWindow):
         # Regenerate codebook-codes:
         regenerate_codes = QAction("Nye koder i db", self)
         regenerate_codes.setStatusTip("Nye koder lages tilfeldig")
+        regenerate_codes.triggered.connect(lambda: self.bobo())
         codebook_menu.addAction(regenerate_codes)
 
         # Export codebook as PDF
@@ -179,6 +181,31 @@ class MainWindow(QMainWindow):
             self.tabs.addTab(tab, "Kodebok")
             self.tabs.setCurrentWidget(tab)
 
+    def bobo(self):
+
+        for i in range(self.tabs.count()):
+            if self.tabs.tabText(i) == "Kodebok":
+                self.tabs.setCurrentIndex(i)
+                break
+
+        self.tabs.removeTab(i)
+
+        self.database.update_codebook()
+
+        tab = QWidget()
+        view = CodeBookTableView()
+        row_adder = CodebookRowAdder(view)
+        # Add widgets to layouts
+        vbox = QVBoxLayout()
+        vbox.addWidget(row_adder)
+        vbox.addWidget(view)
+        hbox = QHBoxLayout()
+        hbox.addLayout(vbox)
+        # Set layout, add tab and select tab
+        tab.setLayout(hbox)
+        self.tabs.addTab(tab, "Kodebok")
+        self.tabs.setCurrentWidget(tab)
+
 
 if __name__ == "__main__":
 
-- 
GitLab