From 39d41d56de1b54a252a6ac8dca5d5152e62dec78 Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Sun, 1 Aug 2021 00:49:44 +0200 Subject: [PATCH] Snapcraft building. --- .gitignore | 1 + LogarithmPlotter/logarithmplotter.py | 157 +++++++++++++++++ LogarithmPlotter/logarithmplotter.svg | 131 ++++++++++++++ .../LogarithmPlotter/LogarithmPlotter.qml | 4 +- .../icons/logarithmplotter.svg | 1 + MANIFEST.in | 2 +- linux/logarithmplotter-local.desktop | 15 ++ .../launcher/launch-logarithmplotter | 14 ++ snapcraft.yaml | 160 ++++++++++++++++++ 9 files changed, 482 insertions(+), 3 deletions(-) create mode 100644 LogarithmPlotter/logarithmplotter.py create mode 100644 LogarithmPlotter/logarithmplotter.svg create mode 120000 LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/icons/logarithmplotter.svg create mode 100644 linux/logarithmplotter-local.desktop create mode 100755 linux/snapcraft/launcher/launch-logarithmplotter create mode 100644 snapcraft.yaml diff --git a/.gitignore b/.gitignore index 9baea95..e3c74a2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ build/ dist/ +*.snap *.spec *.zip **/**.qmlc diff --git a/LogarithmPlotter/logarithmplotter.py b/LogarithmPlotter/logarithmplotter.py new file mode 100644 index 0000000..4f6e88d --- /dev/null +++ b/LogarithmPlotter/logarithmplotter.py @@ -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 . +""" + +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() + diff --git a/LogarithmPlotter/logarithmplotter.svg b/LogarithmPlotter/logarithmplotter.svg new file mode 100644 index 0000000..89b2b1b --- /dev/null +++ b/LogarithmPlotter/logarithmplotter.svg @@ -0,0 +1,131 @@ + + + LogarithmPlotter Icon v1.0 + + + + + + + + image/svg+xml + + LogarithmPlotter Icon v1.0 + + 2021 + + + Ad5001 + + + + + (c) Ad5001 2021 - All rights reserved + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml index 0325339..9cb34dc 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml @@ -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 } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/icons/logarithmplotter.svg b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/icons/logarithmplotter.svg new file mode 120000 index 0000000..0497bab --- /dev/null +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/icons/logarithmplotter.svg @@ -0,0 +1 @@ +../../../../../logarithmplotter.svg \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in index 2221cdb..c281f02 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ recursive-include LogarithmPlotter/qml *.qml *.js *.qdoc qmldir *.svg *.md LICENSE include LogarithmPlotter/ *.svg -include . *.md LICENSE + diff --git a/linux/logarithmplotter-local.desktop b/linux/logarithmplotter-local.desktop new file mode 100644 index 0000000..33d6f72 --- /dev/null +++ b/linux/logarithmplotter-local.desktop @@ -0,0 +1,15 @@ +[Desktop Entry] +Version=1.0 +Type=Application +Name=LogarithmPlotter +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 /home/ad5001/Apps/LogarithmPlotter//run.py %f +Icon=logarithmplotter +MimeType=application/x-logarithm-plot; +Terminal=false +StartupNotify=false +Categories=Math diff --git a/linux/snapcraft/launcher/launch-logarithmplotter b/linux/snapcraft/launcher/launch-logarithmplotter new file mode 100755 index 0000000..bda53ea --- /dev/null +++ b/linux/snapcraft/launcher/launch-logarithmplotter @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# This is the maintainence launcher for the snap, make necessary runtime environment changes to make the snap work here. You may also insert security confinement/deprecation/obsoletion notice of the snap here. + +set \ + -o errexit \ + -o errtrace \ + -o nounset \ + -o pipefail + +# GTK theme integration (we have Qt fetch the GTK theme mirroring the host Qt theme...) +#export QT_QPA_PLATFORMTHEME=kde + +# Finally run the next part of the command chain +exec "${@}" diff --git a/snapcraft.yaml b/snapcraft.yaml new file mode 100644 index 0000000..9d632ab --- /dev/null +++ b/snapcraft.yaml @@ -0,0 +1,160 @@ +name: logarithmplotter +version: '0.0.1' +summary: 2D plotter software to make BODE plots, sequences and repartition functions. +description: | + LogarithmPlotter is, as it's name suggests, a plotter made with logarithm scales in mind. With an object system similar to [Geogebra](https://geogebra.org)'s, it allows dynamic creation of plots with very few limitations. + It's primary use is to quickly create [asymptotic Bode Diagrams/plots](https://en.wikipedia.org/wiki/Bode_plot), but it's extensible nature and ability to switch to non-logarithmic scales allow it to create other things with it, like sequences or statistical repartition functions. +confinement: strict +base: core20 +grade: devel +icon: LogarithmPlotter/logarithmplotter.svg + +plugs: + #gnome-3-38-2004: + # interface: content + # target: gnome-platform + # default-provider: gnome-3-38-2004:gnome-3-38-2004 + gtk-3-themes: + default-provider: gtk-common-themes:gtk-3-themes + interface: content + target: $SNAP/data-dir/themes + sound-themes: + default-provider: gtk-common-themes:sound-themes + interface: content + target: $SNAP/data-dir/sounds + icon-themes: + default-provider: gtk-common-themes:icon-themes + interface: content + target: $SNAP/data-dir/icons + +parts: + #desktop-gtk3: # This one fixes the cursor issue without having anything else interfering. + # build-packages: + # - build-essential + # - libgtk-3-dev + # make-parameters: + # - FLAVOR=gtk3 + # plugin: make + # source: https://github.com/ubuntu/snapcraft-desktop-helpers.git + # source-subdir: gtk + # stage-packages: + # - libxkbcommon0 + # - ttf-ubuntu-font-family + # - dmz-cursor-theme + # - light-themes + # - adwaita-icon-theme + # - gnome-themes-standard + # - shared-mime-info + # - libgtk-3-0 + # - libgdk-pixbuf2.0-0 + # - libglib2.0-bin + # - libgtk-3-bin + # - unity-gtk3-module + # - libappindicator3-1 + # - locales-all + # - xdg-user-dirs + # - ibus-gtk3 + # - libibus-1.0-5 + # - fcitx-frontend-gtk3 + # - libgtk2.0-0 + launchers: + source: linux/snapcraft/launcher/ + plugin: dump + organize: + '*': bin/ + linuxfiles: + source: linux/ + plugin: dump + organize: + logarithmplotter.desktop: usr/share/applications/logarithmplotter.desktop + x-logarithm-plot.xml: usr/share/mime/packages/x-logarithm-plot.xml + application-x-logarithm-plot.svg: usr/share/mime/packages/application-x-logarithm-plot.svg + logarithmplotter: + plugin: python + source: . + stage-packages: + - breeze-icon-theme + # Additional dependencies + - libxcomposite1 + - libxcursor1 + - libxi6 + - libxrandr2 + - libxtst6 + - libasound2 + - libatk1.0-0 + - libcairo-gobject2 + - libcairo2 + - libgtk-3-0 + - libgdk-pixbuf2.0-0 + - libegl1 + - libglu1-mesa + - libgl1-mesa-dri + - libgl1-mesa-glx + - libx11-xcb1 + - libxdamage1 + - libcups2 + - libdrm2 + - libgstreamer-plugins-base1.0-0 + - libgstreamer1.0-0 + - libnspr4 + - libnss3 + - libodbc1 + - libpango-1.0-0 + - libpangocairo-1.0-0 + - libpq5 + - libpulse-mainloop-glib0 + - libpulse0 + - libspeechd2 + - libwayland-client0 + - libwayland-cursor0 + - libwayland-egl1 + - libwayland-server0 + - libxcb-dri3-0 + - libxcb-glx0 + - libxcb-icccm4 + - libxcb-image0 + - libxcb-keysyms1 + - libxcb-randr0 + - libxcb-shape0 + - libxcb-sync1 + - libxcb-util1 + - libxcb-xfixes0 + - libxcb-xinerama0 + - libxcb-xkb1 + - libxkbcommon-x11-0 + - libxkbcommon0 + - libxcb-render-util0 + - libdouble-conversion3 + - libpcre2-16-0 + snapcraft-preload: # Fixes error related to multiprocessing on python. + source: https://github.com/sergiusens/snapcraft-preload.git + plugin: cmake + cmake-parameters: + - -DCMAKE_INSTALL_PREFIX=/ + build-packages: + - on amd64: + - gcc-multilib + - g++-multilib + stage-packages: + - lib32stdc++6 + +apps: + logarithmplotter: + common-id: eu.ad5001.LogarithmPlotter + desktop: usr/share/applications/logarithmplotter.desktop + command: bin/logarithmplotter + command-chain: + #- bin/desktop-launch + - bin/snapcraft-preload + - bin/launch-logarithmplotter + plugs: + - desktop + - desktop-legacy + - wayland + - x11 + #- gnome-3-38-2004 + - gsettings # Theme access for wayland + - home # Storing configuration. + - opengl # Rendering + - removable-media # Opening files +