Snapcraft building.

This commit is contained in:
Adsooi 2021-08-01 00:49:44 +02:00
parent 10fa30e2aa
commit 39d41d56de
No known key found for this signature in database
GPG key ID: 9C87C7D3A69E6BBE
9 changed files with 482 additions and 3 deletions

View file

@ -0,0 +1,157 @@
"""
* 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/>.
"""
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
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):
from . import __VERSION__
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(), "logarithmplotter.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__":
run()

View file

@ -0,0 +1,131 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="24.0px"
height="24.0px"
viewBox="0 0 24.0 24.0"
version="1.1"
id="SVGRoot"
sodipodi:docname="logplotter.svg"
inkscape:version="1.0.1 (3bc2e813f5, 2021-09-07)">
<title
id="title836">LogarithmPlotter Icon v1.0</title>
<defs
id="defs833" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="22.627417"
inkscape:cx="23.950814"
inkscape:cy="5.6122612"
inkscape:document-units="px"
inkscape:current-layer="layer1"
inkscape:document-rotation="0"
showgrid="true"
inkscape:window-width="1920"
inkscape:window-height="1011"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1">
<inkscape:grid
type="xygrid"
id="grid1403" />
</sodipodi:namedview>
<metadata
id="metadata836">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title>LogarithmPlotter Icon v1.0</dc:title>
<cc:license
rdf:resource="http://creativecommons.org/licenses/by-nc-sa/4.0/" />
<dc:date>2021</dc:date>
<dc:creator>
<cc:Agent>
<dc:title>Ad5001</dc:title>
</cc:Agent>
</dc:creator>
<dc:rights>
<cc:Agent>
<dc:title>(c) Ad5001 2021 - All rights reserved</dc:title>
</cc:Agent>
</dc:rights>
</cc:Work>
<cc:License
rdf:about="http://creativecommons.org/licenses/by-nc-sa/4.0/">
<cc:permits
rdf:resource="http://creativecommons.org/ns#Reproduction" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#Distribution" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Notice" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Attribution" />
<cc:prohibits
rdf:resource="http://creativecommons.org/ns#CommercialUse" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#ShareAlike" />
</cc:License>
</rdf:RDF>
</metadata>
<g
inkscape:groupmode="layer"
id="layer2"
inkscape:label="Bg">
<rect
style="fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect1546"
width="24"
height="24"
x="0"
y="0"
ry="3" />
</g>
<g
inkscape:label="Calque 1"
inkscape:groupmode="layer"
id="layer1">
<rect
style="fill:#000000;fill-rule:evenodd;stroke-width:19.304;stroke-opacity:0"
id="rect1410"
width="22"
height="2"
x="1"
y="19" />
<rect
style="fill:#000000;fill-rule:evenodd;stroke-width:19.3041;stroke-opacity:0"
id="rect1412"
width="2"
height="22"
x="9"
y="1" />
<path
style="fill:none;fill-rule:evenodd;stroke:#ff0000;stroke-width:1.95063;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path1529"
sodipodi:type="arc"
sodipodi:cx="1"
sodipodi:cy="1"
sodipodi:rx="20.024685"
sodipodi:ry="18.024683"
sodipodi:start="0"
sodipodi:end="1.5707963"
sodipodi:arc-type="arc"
d="M 21.024685,1 A 20.024685,18.024683 0 0 1 1,19.024683"
sodipodi:open="true" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 4 KiB

View file

@ -72,13 +72,13 @@ ApplicationWindow {
}
TabButton {
text: qsTr("Settings")
icon.name: 'preferences-system'
icon.name: 'preferences-system-symbolic'
icon.color: sysPalette.windowText
//height: 24
}
TabButton {
text: qsTr("History")
icon.name: 'history'
icon.name: 'view-history'
icon.color: sysPalette.windowText
//height: 24
}

View file

@ -0,0 +1 @@
../../../../../logarithmplotter.svg