-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
87 lines (67 loc) · 2.67 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
from __future__ import annotations
import fire
import os
import sys
import platform
import signal
import util
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtCore import Qt, QTimer, QObject
import logging
class App(QObject):
def __init__(self):
super().__init__()
self.ace_editor_window = None
self.main_window = None
self.output_window = None
self.code = None
self.code_path = None
def save_code(self, code=None, file_path=None):
if file_path is None or file_path is False:
file_path = self.code_path
with open(file_path, 'w') as file:
if code is not None:
file.write(code)
else:
file.write(self.code)
def start(self, file_path=None, code_file_path=None, debug=False):
from main_window import MainWindow
from output_window import OutputWindow
from ace_editor import AceEditorWindow
self.code_path = code_file_path
os.environ['QTWEBENGINE_CHROMIUM_FLAGS'] = '--disable-gpu'
util.init_logging_config(debug=debug)
app = QtWidgets.QApplication(sys.argv)
main_window = MainWindow()
main_window.show()
main_window.open_excel(file_path)
self.main_window = main_window
ace_editor_window = AceEditorWindow(app=self, debug=debug)
ace_editor_window.show()
output_window = OutputWindow(main_window=main_window, app=self)
output_window.show()
self.output_window = output_window
self.ace_editor_window = ace_editor_window
self.ace_editor_window.activateWindow()
self.ace_editor_window.browser.setFocus()
self.timer = QTimer()
self.timer.start(500) # You may change this if you wish.
self.timer.timeout.connect(lambda: None) # Let the interpreter run each 500 ms.
# Register the signal handler for Ctrl+C
signal.signal(signal.SIGINT, util.signal_handler)
sys.exit(app.exec_())
def init_editor(self, file_path=None):
if file_path is None:
file_path = self.code_path
with open(file_path, 'r') as file:
self.code = file.read()
self.ace_editor_window.set_editor_text(self.code)
def windows_hidpi_support():
if platform.system() == "Windows":
QtCore.QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
QtGui.QGuiApplication.setAttribute(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
def main(file_path='./config/data.xls', code_file_path="./config/code", debug=False):
App().start(file_path, code_file_path, debug)
if __name__ == "__main__":
windows_hidpi_support()
fire.Fire(main)