Ensuring properties are different when they're edited, + linux installation editions*.
*in preparation for snapcraft. - Moving application launch to it's separate file - Removing "install_after_setup" script because it's redundant with setup.py. - Fixed issue with xdg-icon-resource not being able to install svg files. - Better prefix handling in setup.py - Adding logarithmplotter.svg to import files - Adding weight for mime-type not to be overloaded by text/plain. - Using more appropriate properties for desktop files. Also: - Fixed reference link in MacOS plist file.
This commit is contained in:
parent
ee15835dbb
commit
10fa30e2aa
14 changed files with 86 additions and 197 deletions
|
@ -16,142 +16,8 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
from PySide2.QtWidgets import QApplication, QFileDialog
|
||||
from PySide2.QtQml import QQmlApplicationEngine, qmlRegisterType
|
||||
from PySide2.QtCore import Qt, QObject, Signal, Slot, Property
|
||||
from PySide2.QtGui import QIcon, QImage, QKeySequence
|
||||
from PySide2 import __version__ as PySide2_version
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
from platform import release as os_release
|
||||
from json import dumps, loads
|
||||
from sys import platform, argv, version as sys_version
|
||||
import webbrowser
|
||||
|
||||
__VERSION__ = "0.0.1.dev0"
|
||||
|
||||
tempfile = tempfile.mkstemp(suffix='.png')[1]
|
||||
pwd = os.getcwd()
|
||||
|
||||
def get_linux_theme():
|
||||
des = {
|
||||
"KDE": "Flat",
|
||||
"gnome": "default",
|
||||
"lxqt": "fusion",
|
||||
"mate": "fusion",
|
||||
}
|
||||
if "XDG_SESSION_DESKTOP" in os.environ:
|
||||
return des[os.environ["XDG_SESSION_DESKTOP"]] if os.environ["XDG_SESSION_DESKTOP"] in des else "fusion"
|
||||
else:
|
||||
# Android
|
||||
return "Material"
|
||||
|
||||
class Helper(QObject):
|
||||
|
||||
@Slot(str, str)
|
||||
def write(self, filename, filedata):
|
||||
os.chdir(pwd)
|
||||
if os.path.exists(os.path.dirname(os.path.realpath(filename))):
|
||||
if filename.split(".")[-1] == "lpf":
|
||||
# Add header to file
|
||||
filedata = "LPFv1" + filedata
|
||||
f = open(os.path.realpath(filename), 'w', -1, 'utf8')
|
||||
f.write(filedata)
|
||||
f.close()
|
||||
os.chdir(os.path.dirname(os.path.realpath(__file__)))
|
||||
|
||||
@Slot(str, result=str)
|
||||
def load(self, filename):
|
||||
os.chdir(pwd)
|
||||
data = '{}'
|
||||
if os.path.exists(os.path.realpath(filename)):
|
||||
f = open(os.path.realpath(filename), 'r', -1, 'utf8')
|
||||
data = f.read()
|
||||
f.close()
|
||||
try:
|
||||
if data[:5] == "LPFv1":
|
||||
# V1 version of the file
|
||||
data = data[5:]
|
||||
elif data[0] == "{" and "type" in loads(data) and loads(data)["type"] == "logplotv1":
|
||||
pass
|
||||
else:
|
||||
raise Exception("Invalid LogarithmPlotter file.")
|
||||
except Exception as e: # If file can't be loaded
|
||||
from PySide2.QtWidgets import QMessageBox
|
||||
QMessageBox.warning(None, 'LogarithmPlotter', 'Could not open file "{}":\n{}'.format(filename, e), QMessageBox.Ok) # Cannot parse file
|
||||
else:
|
||||
QMessageBox.warning(None, 'LogarithmPlotter', 'Could not open file: "{}"\nFile does not exist.'.format(filename), QMessageBox.Ok) # Cannot parse file
|
||||
os.chdir(os.path.dirname(os.path.realpath(__file__)))
|
||||
return data
|
||||
|
||||
@Slot(result=str)
|
||||
def gettmpfile(self):
|
||||
global tempfile
|
||||
return tempfile
|
||||
|
||||
@Slot()
|
||||
def copyImageToClipboard(self):
|
||||
global tempfile
|
||||
clipboard = QApplication.clipboard()
|
||||
clipboard.setImage(QImage(tempfile))
|
||||
|
||||
@Slot(result=str)
|
||||
def getVersion(self):
|
||||
return __VERSION__
|
||||
|
||||
@Slot(result=str)
|
||||
def getDebugInfos(self):
|
||||
"""
|
||||
Returns the version info about Qt, PySide2 & Python
|
||||
"""
|
||||
return "Built with PySide2 (Qt) v{} and python v{}".format(PySide2_version, sys_version.split("\n")[0])
|
||||
|
||||
@Slot(str)
|
||||
def openUrl(self, url):
|
||||
webbrowser.open(url)
|
||||
|
||||
def run():
|
||||
os.chdir(os.path.dirname(os.path.realpath(__file__)))
|
||||
|
||||
os.environ["QT_QUICK_CONTROLS_STYLE"] = {
|
||||
"linux": get_linux_theme(),
|
||||
"freebsd": get_linux_theme(),
|
||||
"win32": "universal" if os_release == "10" else "fusion",
|
||||
"cygwin": "fusion",
|
||||
"darwin": "default"
|
||||
}[platform]
|
||||
|
||||
icon_fallbacks = QIcon.fallbackSearchPaths();
|
||||
icon_fallbacks.append(os.path.realpath(os.path.join(os.getcwd(), "qml", "eu", "ad5001", "LogarithmPlotter", "icons")))
|
||||
icon_fallbacks.append(os.path.realpath(os.path.join(os.getcwd(), "qml", "eu", "ad5001", "LogarithmPlotter", "icons", "settings")))
|
||||
icon_fallbacks.append(os.path.realpath(os.path.join(os.getcwd(), "qml", "eu", "ad5001", "LogarithmPlotter", "icons", "settings", "custom")))
|
||||
QIcon.setFallbackSearchPaths(icon_fallbacks);
|
||||
|
||||
app = QApplication(argv)
|
||||
app.setApplicationName("LogarithmPlotter")
|
||||
app.setOrganizationName("Ad5001")
|
||||
app.setWindowIcon(QIcon(os.path.realpath(os.path.join(os.getcwd(), "..", "logplotter.svg"))))
|
||||
engine = QQmlApplicationEngine()
|
||||
helper = Helper()
|
||||
engine.rootContext().setContextProperty("Helper", helper)
|
||||
engine.rootContext().setContextProperty("TestBuild", "--test-build" in argv)
|
||||
|
||||
engine.addImportPath(os.path.realpath(os.path.join(os.getcwd(), "qml")))
|
||||
engine.load(os.path.realpath(os.path.join(os.getcwd(), "qml", "eu", "ad5001", "LogarithmPlotter", "LogarithmPlotter.qml")))
|
||||
|
||||
os.chdir(pwd)
|
||||
if len(argv) > 0 and os.path.exists(argv[-1]) and argv[-1].split('.')[-1] in ['json', 'lgg', 'lpf']:
|
||||
engine.rootObjects()[0].loadDiagram(argv[-1])
|
||||
os.chdir(os.path.dirname(os.path.realpath(__file__)))
|
||||
|
||||
if not engine.rootObjects():
|
||||
print("No root object")
|
||||
exit(-1)
|
||||
exit_code = app.exec_()
|
||||
|
||||
os.remove(tempfile)
|
||||
exit(exit_code)
|
||||
|
||||
if __name__ == "__main__":
|
||||
from .logarithmplotter import run
|
||||
run()
|
||||
|
|
|
@ -1,4 +1,20 @@
|
|||
from .run import run
|
||||
|
||||
"""
|
||||
* LogarithmPlotter - Create graphs with logarithm scales.
|
||||
* Copyright (C) 2021 Ad5001
|
||||
*
|
||||
* 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 3 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, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
if __name__ == "__main__":
|
||||
from .logarithmplotter import run
|
||||
run()
|
||||
|
|
|
@ -29,7 +29,7 @@ D.Dialog {
|
|||
|
||||
Image {
|
||||
id: logo
|
||||
source: "../../../../../logplotter.svg"
|
||||
source: "icons/logarithmplotter.svg"
|
||||
sourceSize.width: 64
|
||||
sourceSize.height: 64
|
||||
width: 64
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
import QtQml 2.12
|
||||
import QtQuick.Controls 2.12
|
||||
import QtQuick.Layouts 1.15
|
||||
import QtQuick.Layouts 1.12
|
||||
import QtQuick 2.12
|
||||
import "js/objects.js" as Objects
|
||||
|
||||
|
|
|
@ -237,8 +237,10 @@ ListView {
|
|||
icon: "icons/settings/custom/label.svg"
|
||||
currentIndex: model.indexOf(objEditor.obj.labelContent)
|
||||
onActivated: function(newIndex) {
|
||||
Objects.currentObjects[objEditor.objType][objEditor.objIndex].labelContent = model[newIndex]
|
||||
objectListList.update()
|
||||
if(model[newIndex] != objEditor.obj.labelContent) {
|
||||
objEditor.obj.labelContent = model[newIndex]
|
||||
objectListList.update()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -282,14 +284,16 @@ ListView {
|
|||
'string': () => newValue,
|
||||
'number': () => parseFloat(newValue)
|
||||
}[modelData[1]]()
|
||||
history.addToHistory(new HistoryLib.EditedProperty(
|
||||
objEditor.obj.name, objEditor.objType, modelData[0],
|
||||
objEditor.obj[modelData[0]], newValue
|
||||
))
|
||||
//Objects.currentObjects[objEditor.objType][objEditor.objIndex][modelData[0]] = newValue
|
||||
objEditor.obj[modelData[0]] = newValue
|
||||
Objects.currentObjects[objEditor.objType][objEditor.objIndex].update()
|
||||
objectListList.update()
|
||||
// Ensuring old and new values are different to prevent useless adding to history.
|
||||
if(objEditor.obj[modelData[0]] != newValue) {
|
||||
history.addToHistory(new HistoryLib.EditedProperty(
|
||||
objEditor.obj.name, objEditor.objType, modelData[0],
|
||||
objEditor.obj[modelData[0]], newValue
|
||||
))
|
||||
objEditor.obj[modelData[0]] = newValue
|
||||
Objects.currentObjects[objEditor.objType][objEditor.objIndex].update()
|
||||
objectListList.update()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -345,14 +349,13 @@ ListView {
|
|||
objEditor.obj.name, objEditor.objType, modelData[0],
|
||||
objEditor.obj[modelData[0]], selectedObj
|
||||
))
|
||||
//Objects.currentObjects[objEditor.objType][objEditor.objIndex][modelData[0]] = selectedObj
|
||||
objEditor.obj[modelData[0]] = selectedObj
|
||||
} else {
|
||||
} else if(model[newIndex] != objEditor.obj[modelData[0]]) {
|
||||
// Ensuring new property is different to not add useless history entries.
|
||||
history.addToHistory(new HistoryLib.EditedProperty(
|
||||
objEditor.obj.name, objEditor.objType, modelData[0],
|
||||
objEditor.obj[modelData[0]], model[newIndex]
|
||||
))
|
||||
//Objects.currentObjects[objEditor.objType][objEditor.objIndex][modelData[0]] = model[newIndex]
|
||||
objEditor.obj[modelData[0]] = model[newIndex]
|
||||
}
|
||||
// Refreshing
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
|
||||
recursive-include LogarithmPlotter/qml *.qml *.js *.qdoc qmldir *.svg *.md LICENSE
|
||||
include LogarithmPlotter/ *.svg
|
||||
include . *.md LICENSE
|
||||
|
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |
|
@ -1,29 +0,0 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# AccountFree - Browse and use online services, free of account.
|
||||
# Copyright (C) 2021 Ad5001 <mail@ad5001.eu>
|
||||
#
|
||||
# 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
APPROOT="$(cd -P "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
echo "Adding desktop file..."
|
||||
xdg-desktop-menu install "$APPROOT/linux/logarithmplotter.desktop"
|
||||
echo "Installing mime-type..."
|
||||
xdg-mime install "$APPROOT/linux/x-logarithm-plot.xml"
|
||||
echo "Installing icons..."
|
||||
xdg-icon-resource install --context mimetypes --novendor "$APPROOT/logplotterfile.svg" "application-x-logarithm-plot"
|
||||
xdg-icon-resource install --context apps --novendor "$APPROOT/logplotter.svg" "logarithmplotter"
|
||||
update-mime-database ~/.local/share/mime/
|
||||
update-icon-caches ~/.local/share/icons/hicolor
|
|
@ -16,6 +16,7 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# This script installs the desktop file & mime type for development environment, linking it directly to run.py.
|
||||
|
||||
APPROOT="$(cd -P "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
echo "Adding desktop file..."
|
||||
|
@ -24,7 +25,12 @@ xdg-desktop-menu install "$APPROOT/linux/logarithmplotter-local.desktop"
|
|||
echo "Installing mime-type..."
|
||||
xdg-mime install "$APPROOT/linux/x-logarithm-plot.xml"
|
||||
echo "Installing icons..."
|
||||
xdg-icon-resource install --context mimetypes --novendor "$APPROOT/logplotterfile.svg" "application-x-logarithm-plot"
|
||||
xdg-icon-resource install --context apps --novendor "$APPROOT/logplotter.svg" "logarithmplotter"
|
||||
mkdir -p ~/.local/share/icons/hicolor/scalable/mimetypes
|
||||
cp "$APPROOT/linux/application-x-logarithm-plot.svg" ~/.local/share/icons/hicolor/scalable/mimetypes/application-x-logarithm-plot.svg
|
||||
mkdir -p ~/.local/share/icons/hicolor/scalable/apps
|
||||
cp "$APPROOT/logplotter.svg" ~/.local/share/icons/hicolor/scalable/apps/logarithmplotter.svg
|
||||
# xdg-icon-resource does not work with SVG yet. See https://bugs.launchpad.net/ubuntu/+source/xdg-utils/+bug/790449.
|
||||
#xdg-icon-resource install --context mimetypes --novendor "$APPROOT/linux/application-x-logarithm-plot.svg" "application-x-logarithm-plot"
|
||||
#xdg-icon-resource install --context apps --novendor "$APPROOT/logplotter.svg" "logarithmplotter"
|
||||
update-mime-database ~/.local/share/mime/
|
||||
update-icon-caches ~/.local/share/icons/hicolor
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
Version=1.0
|
||||
Type=Application
|
||||
Name=LogarithmPlotter
|
||||
Comment=2D plotter software to make BODE diagrams, sequences and repartition functions.
|
||||
Comment[fr]=Logiciel de traçage 2D pour les diagrammes de BODE, les suites et les fonctions de répartition.
|
||||
GenericName=2D plotter software
|
||||
GenericName[fr]=Logiciel de traçage 2D
|
||||
Comment=Create BODE diagrams, sequences and repartition functions.
|
||||
Comment[fr]=Créer des diagrammes de BODE, des suites et des fonctions de répartition.
|
||||
|
||||
Exec=/usr/bin/python3 ROOTFOLDER/run.py %f
|
||||
Icon=logarithmplotter
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
<comment xml:lang="fr">Fichier Graphe Logarithmique</comment>
|
||||
<icon name="application-x-logarithm-plot"/>
|
||||
<glob-deleteall/>
|
||||
<glob pattern="*.json"/>
|
||||
<glob pattern="*.lgg"/>
|
||||
<glob pattern="*.lpf"/>
|
||||
<glob weight="60" pattern="*.json"/>
|
||||
<glob weight="60" pattern="*.lgg"/>
|
||||
<glob weight="60" pattern="*.lpf"/>
|
||||
</mime-type>
|
||||
</mime-info>
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
<key>UTTypeIdentifier</key>
|
||||
<string>eu.ad5001.x-logarithm-plot</string>
|
||||
<key>UTTypeReferenceURL</key>
|
||||
<string>https://git.ad5001.eu/Ad5001/LogarithmicPlotter/wiki/LogarithmPlotter-file-format-v1.0</string>
|
||||
<string>https://git.ad5001.eu/Ad5001/LogarithmPlotter/wiki/LogarithmPlotter-file-format-v1.0</string>
|
||||
<key>UTTypeDescription</key>
|
||||
<string>Logarithm Plot File</string>
|
||||
<key>UTTypeIconFile</key>
|
||||
|
|
4
run.py
4
run.py
|
@ -1,7 +1,7 @@
|
|||
|
||||
def run():
|
||||
import LogarithmPlotter
|
||||
LogarithmPlotter.run()
|
||||
from LogarithmPlotter import logarithmplotter
|
||||
logarithmplotter.run()
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
|
|
35
setup.py
35
setup.py
|
@ -22,6 +22,19 @@ import sys
|
|||
|
||||
current_dir = os.path.realpath(os.path.dirname(os.path.realpath(__file__)))
|
||||
|
||||
if "PREFIX" not in os.environ and sys.platform == 'linux':
|
||||
if "XDG_DATA_HOME" in os.environ:
|
||||
os.environ["PREFIX"] = os.environ["XDG_DATA_HOME"]
|
||||
else :
|
||||
try:
|
||||
# Checking if we have permission to write to root.
|
||||
from os import makedirs, rmdir
|
||||
makedirs("/usr/share/applications/test")
|
||||
rmdir("/usr/share/applications/test")
|
||||
os.environ["PREFIX"] = "/usr/share"
|
||||
except:
|
||||
os.environ["PREFIX"] = os.environ["home"] + "/local/share"
|
||||
|
||||
from LogarithmPlotter import __VERSION__ as pkg_version
|
||||
|
||||
CLASSIFIERS = """
|
||||
|
@ -49,7 +62,7 @@ def read_file(file_name):
|
|||
return data
|
||||
|
||||
def package_data():
|
||||
pkg_data = []
|
||||
pkg_data = ["logarithmplotter.svg"]
|
||||
for d,folders,files in os.walk("LogarithmPlotter/qml"):
|
||||
d = d[17:]
|
||||
pkg_data += [os.path.join(d, f) for f in files]
|
||||
|
@ -57,10 +70,20 @@ def package_data():
|
|||
|
||||
data_files = []
|
||||
if sys.platform == 'linux':
|
||||
data_files.append(('/usr/share/applications/', ['linux/logarithmplotter.desktop']))
|
||||
data_files.append(('/usr/share/mime/packages/', ['linux/x-logarithm-plot.xml']))
|
||||
data_files.append(('/usr/share/icons/hicolor/scalable/mimetypes/', ['linux/application-x-logarithm-plot.svg']))
|
||||
data_files.append(('/usr/share/icons/hicolor/scalable/apps/', ['logplotter.svg']))
|
||||
data_files.append((os.environ["PREFIX"] + '/applications/', ['linux/logarithmplotter.desktop']))
|
||||
data_files.append((os.environ["PREFIX"] + '/mime/packages/', ['linux/x-logarithm-plot.xml']))
|
||||
data_files.append((os.environ["PREFIX"] + '/icons/hicolor/scalable/mimetypes/', ['linux/application-x-logarithm-plot.svg']))
|
||||
data_files.append((os.environ["PREFIX"] + '/icons/hicolor/scalable/apps/', ['logplotter.svg']))
|
||||
if len(sys.argv) > 1 and sys.argv[1] == "install":
|
||||
from shutil import copyfile
|
||||
os.makedirs(os.environ["PREFIX"] + '/applications/', exist_ok=True)
|
||||
os.makedirs(os.environ["PREFIX"] + '/mime/packages/', exist_ok=True)
|
||||
os.makedirs(os.environ["PREFIX"] + '/icons/hicolor/scalable/mimetypes/', exist_ok=True)
|
||||
os.makedirs(os.environ["PREFIX"] + '/icons/hicolor/scalable/apps/', exist_ok=True)
|
||||
copyfile(current_dir + '/linux/logarithmplotter.desktop', os.environ["PREFIX"] + '/applications/logarithmplotter.desktop')
|
||||
copyfile(current_dir + '/linux/x-logarithm-plot.xml', os.environ["PREFIX"] + '/mime/packages/x-logarithm-plot.xml')
|
||||
copyfile(current_dir + '/linux/application-x-logarithm-plot.svg', os.environ["PREFIX"] + '/icons/hicolor/scalable/mimetypes/application-x-logarithm-plot.svg')
|
||||
copyfile(current_dir + '/logplotter.svg', os.environ["PREFIX"] + '/icons/hicolor/scalable/apps/logplotter.svg')
|
||||
|
||||
setuptools.setup(
|
||||
install_requires=["PySide2"],
|
||||
|
@ -90,7 +113,7 @@ setuptools.setup(
|
|||
data_files = data_files,
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'logarithmplotter = LogarithmPlotter:run',
|
||||
'logarithmplotter = LogarithmPlotter.logarithmplotter:run',
|
||||
],
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue