Skip to content
Snippets Groups Projects
Commit 3b707314 authored by morkolai's avatar morkolai
Browse files

#52 Fått timer til å fungere, db oppdateres nå på hensiktsmessig tid

parent d48deb3e
No related branches found
No related tags found
1 merge request!27#52 Automatisk oppdatering av kodebok basert på tid
......@@ -51,6 +51,11 @@ class Database:
self.fill_tables()
print("Tables filled with data.")
# Initiates timer that triggers CodeBook update
self.timer = QTimer()
self.timer.setInterval(self.seconds_to_next_update())
self.timer.timeout.connect(self.update_codebook_auto)
self.conn.row_factory = sqlite3.Row # Enables row['columnName']
def create_tables(self):
......@@ -234,11 +239,11 @@ class Database:
def update_codebook_auto(self):
"""
Update Codebook if it is less than 10 sec til next update.
"""
print("Running update_codebook_auto")
Update Codebook if needed and set new time for timer.
"""
if self.seconds_to_next_update() < 10:
self.update_codebook()
self.timer.setInterval(self.seconds_to_next_update())
def add_code_to(self, word, mode="ascii"):
"""
......@@ -282,4 +287,4 @@ class Database:
self.conn.execute(stmt, (code, word))
db = Database()
DB = Database()
......@@ -8,9 +8,8 @@ import os
from enum import Enum
from PySide2.QtWidgets import QMainWindow, QApplication, QTabWidget, QAction
from PySide2.QtGui import QIcon
from PySide2.QtCore import QTimer
from soitool.soi_workspace_widget import SOIWorkspaceWidget
from soitool.database import db
from soitool.database import DB
class ModuleType(Enum):
......@@ -29,11 +28,8 @@ class MainWindow(QMainWindow):
self.setWindowTitle("SOI-tool")
self.statusBar()
# Updateds CodeBook if needed every minute
self.timer = QTimer(self)
self.timer.setInterval(60000)
self.timer.timeout.connect(db.update_codebook_auto)
self.timer.start()
# Start Qtimer that triggers db update
DB.timer.start()
# flytt ut til egen funksjon, for setup av menubar
menu = self.menuBar()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment