Signed-off-by: JDM170 <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
2020-08-05 19:19:49 +07:00
parent 1b940572db
commit d3cdecda90
22 changed files with 345 additions and 0 deletions

14
.gitignore vendored Normal file
View File

@@ -0,0 +1,14 @@
## Ignoring PyCharm settings
/.idea
## Ignoring Python complied files
/__pycache__
/main/__pycache__
/main/form.py
## Ignoring build from cx_Freeze
/prog_build
## Ignoring build files from PyInstaller
/build
/dist

12
__init__.py Normal file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from sys import argv, exit
from PyQt5.QtWidgets import QApplication
from main.script import MainWindow
if __name__ == '__main__':
app = QApplication(argv)
win = MainWindow()
win.show()
exit(app.exec())

1
compile_cx-freeze.bat Normal file
View File

@@ -0,0 +1 @@
python setup.py build

13
convert_ui_to_py.bat Normal file
View File

@@ -0,0 +1,13 @@
cls
@echo off
title Form converter
:SETUP
echo Enter form name to convert into .py (without .ui):
echo Type 'exit' to exit
set/p "name=> "
if %name%==exit goto EXIT
pyuic5 %name%.ui -o %name%.py
goto SETUP
:EXIT

BIN
dlls/imageformats/qgif.dll Normal file

Binary file not shown.

BIN
dlls/imageformats/qicns.dll Normal file

Binary file not shown.

BIN
dlls/imageformats/qico.dll Normal file

Binary file not shown.

BIN
dlls/imageformats/qjpeg.dll Normal file

Binary file not shown.

BIN
dlls/imageformats/qsvg.dll Normal file

Binary file not shown.

BIN
dlls/imageformats/qtga.dll Normal file

Binary file not shown.

BIN
dlls/imageformats/qtiff.dll Normal file

Binary file not shown.

BIN
dlls/imageformats/qwbmp.dll Normal file

Binary file not shown.

BIN
dlls/imageformats/qwebp.dll Normal file

Binary file not shown.

BIN
dlls/platforms/qminimal.dll Normal file

Binary file not shown.

Binary file not shown.

BIN
dlls/platforms/qwebgl.dll Normal file

Binary file not shown.

BIN
dlls/platforms/qwindows.dll Normal file

Binary file not shown.

Binary file not shown.

1
main/__init__.py Normal file
View File

@@ -0,0 +1 @@
# initializing module 'main'

128
main/form.ui Normal file
View File

@@ -0,0 +1,128 @@
<?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>
<family>Times New Roman</family>
<pointsize>12</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="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>Generate and copy MD5</string>
</property>
</action>
</widget>
<resources/>
<connections/>
</ui>

134
main/script.py Normal file
View File

@@ -0,0 +1,134 @@
#!/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 json import dump, load, decoder
from hashlib import md5
from .form import Ui_MainWindow
class MainWindow(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]-25)
def closeEvent(self, event: QCloseEvent):
if self.maybe_save():
event.accept()
else:
event.ignore()
@staticmethod
def save_handler(path, data):
with open(path, encoding="utf-8", mode="w") as f:
dump(data, f, indent=4, sort_keys=True, separators=(",", " : "))
try:
with open(path, encoding="utf-8") as f:
load(f)
except decoder.JSONDecodeError:
return False
return True
@staticmethod
def generate_md5(fn):
hash_md5 = md5()
try:
with open(fn, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
except FileNotFoundError:
return False
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 = self.save_handler(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 = self.save_handler(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 = self.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

42
setup.py Normal file
View File

@@ -0,0 +1,42 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from sys import platform
from cx_Freeze import setup, Executable
base = None
if platform == 'win32':
base = 'Win32GUI'
executables = [Executable('__init__.py', targetName='config_editor.exe', base=base)]
excludes = ['html', 'pydoc_data', 'unittest', 'xml', 'pwd', 'shlex', 'platform', 'webbrowser', 'pydoc', 'tty',
'inspect', 'doctest', 'plistlib', 'subprocess', 'bz2', '_strptime', 'dummy_threading', 'selectors',
'select', 'http', 'email', 'datetime', 'calendar', 'urllib', 'posixpath', 'tempfile', 'shutil', 'copy',
'stringprep', 'socket']
includes = ['pkgutil', 'PyQt5.sip']
zip_include_packages = ['collections', 'encodings', 'importlib', 'json', 'hashlib', 'ast', 'PyQt5', 'main']
include_files = ['dlls/imageformats', 'dlls/platforms', 'dlls/styles']
options = {
'build_exe': {
'excludes': excludes,
'includes': includes,
'include_msvcr': True,
'build_exe': 'prog_build',
'include_files': include_files,
'zip_include_packages': zip_include_packages,
}
}
setup(
name='SaveWizard Config Editor',
version='1.0',
description='For editing configs from SaveWizard',
executables=executables,
options=options,
requires=['PyQt5'],
)