mirror of
https://github.com/JDM170/SaveWizard
synced 2025-04-20 22:30:42 +07:00
Sort folders by renaming, some code changes
Signed-off-by: JDM170 <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
1
module_config_editor/__init__.py
Normal file
1
module_config_editor/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# initializing module 'config_editor'
|
||||
133
module_config_editor/form.ui
Normal file
133
module_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>
|
||||
112
module_config_editor/script.py
Normal file
112
module_config_editor/script.py
Normal file
@@ -0,0 +1,112 @@
|
||||
#!/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 util
|
||||
|
||||
|
||||
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 place to save file"),
|
||||
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 = util.generate_md5(self.file_path)
|
||||
clip = QApplication.clipboard()
|
||||
QClipboard.setText(clip, result)
|
||||
QMessageBox.information(self, "Information", "Hash successfully copied into your clipboard.")
|
||||
|
||||
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("SaveWizard config editor"),
|
||||
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
|
||||
Reference in New Issue
Block a user