-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
209 lines (163 loc) · 6.56 KB
/
Copy pathmain.py
File metadata and controls
209 lines (163 loc) · 6.56 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# main.py
#
# Copyright 2020 iwoithe <iwoithe@just42.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
import os
import sys
import json
import ui.about.about as about
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QKeySequence, QIcon
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget,
QHBoxLayout, QMenuBar, QFileDialog,
QTabWidget, QAction)
import ui.utils
from ui.panels.editor import Editor
from ui.panels.groups import Groups
from ui.panels.options import Options
from ui.about.about import AboutDialog
from ui.preferences.preferences import PreferencesDialog
import core.generator as generator
# TODO: Check if a file has been modified and display an asterix
# (*) next to the filename
# TODO: When closing, if a file has been modified, ask if you
# want to save the files
# TODO: Use panes (like Atoms) instead of using QDockWidget
class RandomGroupGenerator(QMainWindow):
settings_file = "data/settings.json"
with open(settings_file) as f:
settings = json.loads(f.read())
def __init__(self):
super().__init__()
self.save_file_path = ''
self.open_files_path = ''
self.import_files_path = ''
self.export_files_path = ''
style = ui.utils.load_style_from_file(os.path.join("data/styles/", self.settings["style"] + ".qss"))
ui.utils.apply_style(style)
self.setup_ui()
def setup_ui(self):
# Editor
self.editor = Editor()
# Groups
self.groups = Groups()
# Options
self.options = Options(self.editor, self.groups, generator)
self.addDockWidget(Qt.LeftDockWidgetArea, self.editor)
self.addDockWidget(Qt.RightDockWidgetArea, self.options)
self.addDockWidget(Qt.RightDockWidgetArea, self.groups)
self.setTabPosition(Qt.AllDockWidgetAreas, QTabWidget.North)
self.setDockOptions(self.AnimatedDocks | self.AllowNestedDocks | self.AllowTabbedDocks | self.GroupedDragging)
self.setWindowTitle("Random Group Generator")
menu_bar = self.create_menu_bar()
self.setMenuBar(menu_bar)
self.setWindowIcon(QIcon("icon.png"))
def create_menu_bar(self):
# Menu Bar
menu_bar = QMenuBar()
# File
action_file = menu_bar.addMenu("&File")
action_file.addAction("New", self.new_file, QKeySequence.New)
action_file.addAction("Open", self.open_files, QKeySequence.Open)
action_file.addAction("Save", self.save_file, QKeySequence.Save)
action_file.addSeparator()
action_file.addAction("Import", self.import_file)
action_file.addAction("Export", self.export_file)
action_file.addSeparator()
action_file.addAction("Quit", self.quit, QKeySequence.Quit)
# Edit
action_edit = menu_bar.addMenu("&Edit")
action_edit.addAction("Preferences", self.show_preferences)
# View
action_view = menu_bar.addMenu("&View")
view_panels = action_view.addMenu("Panels")
view_panels.addAction(self.editor.toggleViewAction())
view_panels.addAction(self.options.toggleViewAction())
view_panels.addAction(self.groups.toggleViewAction())
# Help
action_help = menu_bar.addMenu("&Help")
action_help.addAction("About", self.show_about)
action_help.addAction("About Qt", QApplication.instance().aboutQt)
return menu_bar
def new_file(self):
self.editor.new_file()
def save_file(self):
# Options for the save dialog
options = QFileDialog.Options()
# The variable _ is not used, hence its name
file, _ = QFileDialog.getSaveFileName(self,
"Save File",
self.save_file_path,
"Random Group Generator (*.rgg)", options=options)
if file:
if ('.rgg' in file):
pass
else:
file += ".rgg"
self.save_files_path = file
self.editor.save_file(file)
def open_files(self):
open_files_path = ''
# Options for the open dialog
options = QFileDialog.Options()
# The variable _ is not used, hence its name
files, _ = QFileDialog.getOpenFileNames(self,
"Open File/s", open_files_path,
"Random Group Generator Files (*.rgg)", options=options)
if files:
self.open_files_path = files[0]
self.editor.load_files(files)
def import_file(self):
# Options for the open dialog
options = QFileDialog.Options()
files, type = QFileDialog.getOpenFileNames(self,
"Import File/s", self.import_files_path,
"Comma Seperated Values (*.csv);;Microsoft Excel Spreadsheets (*.xls *.xlsx)",
options=options)
if files:
self.import_files_path = files[0]
self.editor.import_files(files, type)
def export_file(self):
# Options for the open dialog
options = QFileDialog.Options()
file, file_type = QFileDialog.getSaveFileName(self,
"Export Groups", self.export_files_path,
"Comma Seperated Values (*.csv);;Microsoft Excel Spreadsheets (*.xls *.xlsx)",
options=options)
if file:
self.export_files_path = file
self.editor.export_file(self.options.groups_list, file, file_type)
def show_preferences(self):
preferences_dialog = PreferencesDialog(self)
preferences_dialog.exec_()
def show_about(self):
about_dialog = AboutDialog(self)
about_dialog.exec_()
def quit(self):
self.destroy()
if __name__ == '__main__':
app = QApplication(sys.argv)
app.setStyle("fusion")
rgg = RandomGroupGenerator()
rgg.show()
sys.exit(app.exec_())