-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
96 lines (73 loc) · 2.34 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import sys
import logging
from PyQt6.QtWidgets import QApplication, QWidget, QPushButton, QTextEdit, QVBoxLayout
from PyQt6.QtCore import QObject, pyqtSignal, QThread
from PyQt6.QtGui import QIcon
import main
logging.basicConfig(
#filename="logs.log",
encoding="utf-8",
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
level=logging.INFO,
)
logger = logging.getLogger('app')
logger.info(f"Starting the app")
class ConsoleWindowLogHandler(logging.Handler, QObject):
sigLog = pyqtSignal(str)
def __init__(self):
logging.Handler.__init__(self)
QObject.__init__(self)
def emit(self, logRecord):
msg = str(logRecord.getMessage())
self.sigLog.emit(msg)
class MyApp(QWidget):
def __init__(self):
super().__init__()
# Window Properties
self.setWindowTitle("ONs Price Updater")
self.setWindowIcon(QIcon('icon.ico'))
self.resize(600, 600) # width, height
# Widgets
self.button = QPushButton('&Update Google Sheet')
logTextBox = QTextEdit()
logTextBox.setReadOnly(True)
# Layout
layout = QVBoxLayout()
layout.addWidget(self.button)
layout.addWidget(logTextBox)
self.setLayout(layout)
# Connect button
self.button.clicked.connect(self.buttonPressed)
# Thread
self.bee = Worker(self.runScript,())
self.bee.finished.connect(self.restoreUi)
self.bee.terminate()
# Console handler
consoleHandler = ConsoleWindowLogHandler()
consoleHandler.sigLog.connect(logTextBox.append)
logger.addHandler(consoleHandler)
def buttonPressed(self):
self.button.setEnabled(False)
self.bee.start()
def restoreUi(self):
self.button.setEnabled(True)
def runScript(self):
main.main()
class Worker(QThread):
def __init__(self, func, args):
super(Worker, self).__init__()
self.func = func
self.args = args
def run(self):
self.func(*self.args)
app = QApplication(sys.argv) # If we use arguments in the command line
app.setStyleSheet('''
QWidget {
font-size: 20px;
}
QPushButton {
font-size: 20px;
}''') # Apply css
window = MyApp()
window. show()
sys.exit(app.exec())