mirror of
https://github.com/JDM170/SaveWizard
synced 2025-04-20 22:30:42 +07:00
Added simple config editor
Signed-off-by: JDM170 <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -10,6 +10,8 @@
|
|||||||
/main/form.py
|
/main/form.py
|
||||||
/second/__pycache__
|
/second/__pycache__
|
||||||
/second/form.py
|
/second/form.py
|
||||||
|
/config_editor/__pycache__
|
||||||
|
/config_editor/form.py
|
||||||
|
|
||||||
## Ignoring UPX
|
## Ignoring UPX
|
||||||
/upx
|
/upx
|
||||||
|
|||||||
29
build.spec
29
build.spec
@@ -8,8 +8,18 @@ app = Analysis(
|
|||||||
('configs/ets2', 'configs/ets2')
|
('configs/ets2', 'configs/ets2')
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
cfg = Analysis(
|
||||||
|
['init_config_editor.py'],
|
||||||
|
pathex=['.']
|
||||||
|
)
|
||||||
|
|
||||||
|
MERGE(
|
||||||
|
(app, 'SaveWizard', 'SaveWizard'),
|
||||||
|
(cfg, 'SaveWizard_Config_Editor', 'SaveWizard_Config_Editor')
|
||||||
|
)
|
||||||
|
|
||||||
app_pyz = PYZ(app.pure, app.zipped_data)
|
app_pyz = PYZ(app.pure, app.zipped_data)
|
||||||
|
cfg_pyz = PYZ(cfg.pure, cfg.zipped_data)
|
||||||
|
|
||||||
app_exe = EXE(
|
app_exe = EXE(
|
||||||
app_pyz,
|
app_pyz,
|
||||||
@@ -31,3 +41,22 @@ app_coll = COLLECT(
|
|||||||
name='app_build'
|
name='app_build'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
cfg_exe = EXE(
|
||||||
|
cfg_pyz,
|
||||||
|
cfg.scripts,
|
||||||
|
[],
|
||||||
|
exclude_binaries=True,
|
||||||
|
name='SaveWizard_Config_Editor',
|
||||||
|
debug=False,
|
||||||
|
bootloader_ignore_signals=False,
|
||||||
|
strip=False,
|
||||||
|
console=False
|
||||||
|
)
|
||||||
|
cfg_coll = COLLECT(
|
||||||
|
cfg_exe,
|
||||||
|
cfg.binaries,
|
||||||
|
cfg.zipfiles,
|
||||||
|
cfg.datas,
|
||||||
|
strip=False,
|
||||||
|
name='cfg_build'
|
||||||
|
)
|
||||||
|
|||||||
1
config_editor/__init__.py
Normal file
1
config_editor/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# initializing module 'config_editor'
|
||||||
133
config_editor/form.ui
Normal file
133
config_editor/form.ui
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<author>JDM170</author>
|
||||||
|
<class>MainWindow</class>
|
||||||
|
<widget class="QMainWindow" name="MainWindow">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>504</width>
|
||||||
|
<height>374</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>9</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>SaveWizard config editor</string>
|
||||||
|
</property>
|
||||||
|
<property name="dockOptions">
|
||||||
|
<set>QMainWindow::AllowTabbedDocks</set>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralwidget">
|
||||||
|
<widget class="QTextEdit" name="textEdit">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>501</width>
|
||||||
|
<height>351</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>Verdana</family>
|
||||||
|
<pointsize>12</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::NoFrame</enum>
|
||||||
|
</property>
|
||||||
|
<property name="frameShadow">
|
||||||
|
<enum>QFrame::Plain</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenuBar" name="menubar">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>504</width>
|
||||||
|
<height>21</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="defaultUp">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="nativeMenuBar">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<widget class="QMenu" name="menuOptions">
|
||||||
|
<property name="title">
|
||||||
|
<string>Options</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionOpen"/>
|
||||||
|
<addaction name="actionSave"/>
|
||||||
|
<addaction name="actionSave_As"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actionMD5"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actionCloseFile"/>
|
||||||
|
<addaction name="actionExit"/>
|
||||||
|
</widget>
|
||||||
|
<addaction name="menuOptions"/>
|
||||||
|
</widget>
|
||||||
|
<action name="actionOpen">
|
||||||
|
<property name="text">
|
||||||
|
<string>Open</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+O</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionSave">
|
||||||
|
<property name="text">
|
||||||
|
<string>Save</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+S</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionSave_As">
|
||||||
|
<property name="text">
|
||||||
|
<string>Save As</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+Shift+S</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionCloseFile">
|
||||||
|
<property name="text">
|
||||||
|
<string>Close file</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Closing current file</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+W</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionExit">
|
||||||
|
<property name="text">
|
||||||
|
<string>Exit</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionMD5">
|
||||||
|
<property name="text">
|
||||||
|
<string>Copy MD5</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
113
config_editor/script.py
Normal file
113
config_editor/script.py
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from PyQt5.QtCore import Qt
|
||||||
|
from PyQt5.QtGui import QResizeEvent, QCloseEvent, QClipboard
|
||||||
|
from PyQt5.QtWidgets import QMainWindow, QFileDialog, QMessageBox, QApplication
|
||||||
|
from ast import literal_eval
|
||||||
|
from .form import Ui_MainWindow
|
||||||
|
from dataIO import dataIO
|
||||||
|
from util import generate_md5
|
||||||
|
|
||||||
|
|
||||||
|
class EditorWindow(QMainWindow, Ui_MainWindow):
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
QMainWindow.__init__(self, parent, flags=Qt.Window)
|
||||||
|
Ui_MainWindow.__init__(self)
|
||||||
|
self.ui = Ui_MainWindow()
|
||||||
|
self.ui.setupUi(self)
|
||||||
|
|
||||||
|
self.file_path = ""
|
||||||
|
self.win_title = self.tr("{}".format(self.windowTitle()))
|
||||||
|
|
||||||
|
self.ui.textEdit.document().contentsChanged.connect(self.content_changed)
|
||||||
|
|
||||||
|
for action, method in {
|
||||||
|
self.ui.actionOpen: self.open_file,
|
||||||
|
self.ui.actionSave: self.save_file,
|
||||||
|
self.ui.actionSave_As: self.save_as,
|
||||||
|
self.ui.actionMD5: self.copy_hash,
|
||||||
|
self.ui.actionCloseFile: self.close_file,
|
||||||
|
self.ui.actionExit: self.exit
|
||||||
|
}.items():
|
||||||
|
action.triggered.connect(method)
|
||||||
|
|
||||||
|
def resizeEvent(self, event: QResizeEvent):
|
||||||
|
window = self.ui.centralwidget.geometry().getCoords()
|
||||||
|
edit = self.ui.textEdit.geometry().getCoords()
|
||||||
|
self.ui.textEdit.setGeometry(edit[0], edit[1],
|
||||||
|
window[2], window[3]-(self.ui.menubar.size().height()-1))
|
||||||
|
|
||||||
|
def closeEvent(self, event: QCloseEvent):
|
||||||
|
if self.maybe_save():
|
||||||
|
event.accept()
|
||||||
|
else:
|
||||||
|
event.ignore()
|
||||||
|
|
||||||
|
def content_changed(self):
|
||||||
|
self.setWindowModified(self.ui.textEdit.document().isModified())
|
||||||
|
|
||||||
|
def open_file(self):
|
||||||
|
file_path, file_name = QFileDialog.getOpenFileName(parent=self,
|
||||||
|
caption=self.tr("Choose config..."),
|
||||||
|
filter=self.tr("*.json"))
|
||||||
|
if file_path != "":
|
||||||
|
self.file_path = file_path
|
||||||
|
with open(file_path) as f:
|
||||||
|
self.ui.textEdit.setPlainText(f.read())
|
||||||
|
self.setWindowTitle(self.tr("[*]{} - {}".format(file_path, self.win_title)))
|
||||||
|
self.ui.textEdit.document().setModified(False)
|
||||||
|
self.setWindowModified(False)
|
||||||
|
|
||||||
|
def save_file(self):
|
||||||
|
if self.file_path != "":
|
||||||
|
data = literal_eval(self.ui.textEdit.toPlainText())
|
||||||
|
ret = dataIO.save_json(self.file_path, data)
|
||||||
|
if ret:
|
||||||
|
self.ui.textEdit.document().setModified(False)
|
||||||
|
self.setWindowModified(False)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def save_as(self):
|
||||||
|
file_path, file_name = QFileDialog.getSaveFileName(parent=self,
|
||||||
|
caption=self.tr("Select position"),
|
||||||
|
filter=self.tr("*.json"))
|
||||||
|
file_data = literal_eval(self.ui.textEdit.toPlainText())
|
||||||
|
ret = dataIO.save_json(file_path, file_data)
|
||||||
|
if ret:
|
||||||
|
self.file_path = file_path
|
||||||
|
self.setWindowTitle(self.tr("[*]{} - {}".format(file_path, self.win_title)))
|
||||||
|
self.ui.textEdit.document().setModified(False)
|
||||||
|
self.setWindowModified(False)
|
||||||
|
|
||||||
|
def copy_hash(self):
|
||||||
|
if self.maybe_save():
|
||||||
|
result = generate_md5(self.file_path)
|
||||||
|
clip = QApplication.clipboard()
|
||||||
|
QClipboard.setText(clip, result)
|
||||||
|
box = QMessageBox(QMessageBox.Information, "Information", "Hash successfully copied into your clipboard.")
|
||||||
|
box.exec()
|
||||||
|
|
||||||
|
def close_file(self):
|
||||||
|
if self.maybe_save():
|
||||||
|
self.setWindowTitle(self.win_title)
|
||||||
|
self.ui.textEdit.clear()
|
||||||
|
self.file_path = ""
|
||||||
|
|
||||||
|
def exit(self):
|
||||||
|
self.close()
|
||||||
|
|
||||||
|
def maybe_save(self):
|
||||||
|
if not self.ui.textEdit.document().isModified():
|
||||||
|
return True
|
||||||
|
box = QMessageBox.warning(self,
|
||||||
|
self.tr("App"),
|
||||||
|
self.tr("The document has been modified.\nDo you want to save your changes?"),
|
||||||
|
QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel)
|
||||||
|
if box == QMessageBox.Save:
|
||||||
|
return self.save_file()
|
||||||
|
elif box == QMessageBox.Discard:
|
||||||
|
return True
|
||||||
|
elif box == QMessageBox.Cancel:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
12
init_config_editor.py
Normal file
12
init_config_editor.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from sys import argv, exit
|
||||||
|
from PyQt5.QtWidgets import QApplication
|
||||||
|
from config_editor.script import EditorWindow
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app = QApplication(argv)
|
||||||
|
win = EditorWindow()
|
||||||
|
win.show()
|
||||||
|
exit(app.exec())
|
||||||
7
setup.py
7
setup.py
@@ -9,7 +9,8 @@ if platform == 'win32':
|
|||||||
base = 'Win32GUI'
|
base = 'Win32GUI'
|
||||||
|
|
||||||
executables = [
|
executables = [
|
||||||
Executable('init_main_program.py', targetName='SaveWizard.exe', base=base)
|
Executable('init_main_program.py', targetName='SaveWizard.exe', base=base),
|
||||||
|
Executable('init_config_editor.py', targetName='SaveWizard_Config_Editor.exe', base=base)
|
||||||
]
|
]
|
||||||
|
|
||||||
excludes = ['html', 'pydoc_data', 'unittest', 'xml', 'pwd', 'shlex', 'platform', 'webbrowser', 'pydoc', 'tty',
|
excludes = ['html', 'pydoc_data', 'unittest', 'xml', 'pwd', 'shlex', 'platform', 'webbrowser', 'pydoc', 'tty',
|
||||||
@@ -26,7 +27,7 @@ zip_include_packages = [
|
|||||||
# Modules for parsing cfg's
|
# Modules for parsing cfg's
|
||||||
'requests', 'logging', 'certifi', 'chardet', 'idna', 'urllib3',
|
'requests', 'logging', 'certifi', 'chardet', 'idna', 'urllib3',
|
||||||
# Self-written modules
|
# Self-written modules
|
||||||
'parsing', 'choice', 'main', 'second'
|
'parsing', 'choice', 'main', 'second', 'config_editor'
|
||||||
]
|
]
|
||||||
|
|
||||||
include_files = [
|
include_files = [
|
||||||
@@ -51,7 +52,7 @@ options = {
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='SaveWizard',
|
name='SaveWizard',
|
||||||
version='1.2.1',
|
version='1.3',
|
||||||
description='For editing ETS2 sii files',
|
description='For editing ETS2 sii files',
|
||||||
executables=executables,
|
executables=executables,
|
||||||
options=options,
|
options=options,
|
||||||
|
|||||||
Reference in New Issue
Block a user