-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
114 lines (90 loc) · 2.96 KB
/
main.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import *
from PyQt6.QtGui import QIcon, QFont
from sys import argv
from limeinfo import LiMEInfo
from limeeditor import LiMEEditorWin
import yaml, io, os
from limeproject import LiMEProject
app = QApplication(argv)
try:
configHandle = io.open("config.yaml")
config = yaml.safe_load(configHandle)
print("CONFIG: " + str(config))
configHandle.close()
except FileNotFoundError:
print("ERROR: config not found")
except yaml.YAMLError as e:
print(f"ERROR: invalid config ({repr(e)})")
class LiMEInitWin(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle(LiMEInfo.createTitle())
self.setFixedSize(300, 200)
self.setWindowIcon(QIcon("logo.png"))
layout = QVBoxLayout()
welcomeTxt = QLabel("Welcome to LiME")
welcomeTxt.setAlignment(Qt.AlignmentFlag.AlignCenter)
f = QFont(welcomeTxt.font())
f.setPointSize(18)
welcomeTxt.setFont(f)
layout.addWidget(welcomeTxt)
newProjBtn = QPushButton("New project")
newProjBtn.clicked.connect(self.newProj)
layout.addWidget(newProjBtn)
openProjBtn = QPushButton("Open project")
openProjBtn.clicked.connect(self.openProj)
layout.addWidget(openProjBtn)
centralWidget = QWidget()
centralWidget.setLayout(layout)
self.setCentralWidget(centralWidget)
def newProj(self):
self.projProps = LiMEInitProjPropsWin(self)
self.projProps.show()
def openProj(self):
dirSelection = QFileDialog(self)
dirSelection.setFileMode(QFileDialog.FileMode.Directory)
if dirSelection.exec() == 0: return
directory = dirSelection.selectedFiles()[0]
projName = directory.split("/")[-1]
if LiMEProject.formProjDir(projName) != directory + "/":
msg = QMessageBox()
msg.setWindowTitle(LiMEInfo.createTitle("Error"))
msg.setText(f"Project isn't in the projects folder.")
msg.exec()
return
self.editor = LiMEEditorWin.create(projName)
if not self.editor: return
self.editor.show()
self.editor.setFocus()
self.hide()
class LiMEInitProjPropsWin(QMainWindow):
def __init__(self, parent: QWidget):
super().__init__(parent)
self.setWindowTitle(LiMEInfo.createTitle("Project properties"))
self.setFixedSize(350, 150)
self.setWindowIcon(QIcon("logo.png"))
label1 = QLabel("Name:", self)
label1.move(8, 6)
label2 = QLabel("Author:", self)
label2.move(8, 38)
self.nameInput = QLineEdit("New Project", self)
self.nameInput.move(64, 8)
self.nameInput.resize(350-72, 28)
self.authorInput = QLineEdit(os.getlogin(), self)
self.authorInput.move(64, 40)
self.authorInput.resize(350-72, 28)
self.createBtn = QPushButton("Create", self)
self.createBtn.move(350-100, 150-32)
self.createBtn.resize(96, 28)
self.createBtn.clicked.connect(lambda _: self.complete())
def complete(self):
self.editor = LiMEEditorWin.create(self.nameInput.text(), self.authorInput.text())
if not self.editor: return
self.editor.show()
self.editor.setFocus()
self.hide()
self.parentWidget().hide()
win = LiMEInitWin()
win.show()
app.exec()