Reorganisation du projet pour séparer le module ECMAScript du reste de l'application.

Merge branch 'rollup-js'
This commit is contained in:
Adsooi 2024-10-09 20:02:53 +02:00
commit 041d4f424e
Signed by: Ad5001
GPG key ID: EF45F9C6AFE20160
256 changed files with 7548 additions and 1993 deletions

27
.gitignore vendored
View file

@ -1,13 +1,19 @@
# Building
build/
dist/
deb_dist/
linux/flatpak/AppDir
linux/flatpak/repo
linux/flatpak/build-dir
linux/flatpak/.flatpak-builder
assets/linux/flatpak/AppDir
assets/linux/flatpak/repo
assets/linux/flatpak/build-dir
assets/linux/flatpak/.flatpak-builder
*.snap
*.spec
*.zip
*.tar.gz
*.spec
*.egg-info/
# Runtime data
**/**.qmlc
**/**.jsc
**/**.pyc
@ -20,16 +26,19 @@ linux/flatpak/.flatpak-builder
.DS_Store
**/.DS_Store
**/__pycache__/
# IDE Data
.ropeproject
.vscode
*.kdev4
.kdev4
.coverage
build
docs/html
.directory
*.lpf
*.lgg
*.spec
*.egg-info/
*.tar.gz
# npm
common/node_modules
common/coverage/
common/.coverage
runtime-pyside6/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/index.mjs*

4
.gitmodules vendored
View file

@ -1,3 +1,3 @@
[submodule "LogarithmPlotter/qml/eu/ad5001/MixedMenu"]
path = LogarithmPlotter/qml/eu/ad5001/MixedMenu
[submodule "runtime-pyside6/LogarithmPlotter/qml/eu/ad5001/MixedMenu"]
path = runtime-pyside6/LogarithmPlotter/qml/eu/ad5001/MixedMenu
url = https://git.ad5001.eu/Ad5001/MixedMenu

View file

@ -1,130 +0,0 @@
/**
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
* Copyright (C) 2021-2024 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/>.
*/
export const NUMBER = 0
export const STRING = "string"
export const BOOLEAN = true
export const OBJECT = {}
export const FUNCTION = () => {
}
export class Interface {
/**
* Checks if the class to check implements the given interface.
* Throws an error if the implementation does not conform to the interface.
* @param {typeof Interface} interface_
* @param {object} classToCheck
* @return {boolean}
*/
static check_implementation(interface_, classToCheck) {
const properties = new interface_()
const interfaceName = interface_.name
const toCheckName = classToCheck.constructor.name
for(const [property, value] of Object.entries(properties))
if(property !== "implement") {
console.log(classToCheck[property], value)
if(!classToCheck.hasOwnProperty(property))
// Check if the property exist
throw new Error(`Property '${property}' (${typeof value}) is present in interface ${interfaceName}, but not in implementation ${toCheckName}.`)
else if((typeof value) !== (typeof classToCheck[property]))
// Compare the types
throw new Error(`Property '${property}' of ${interfaceName} implementation ${toCheckName} is a '${typeof classToCheck[property]}' and not a '${typeof value}'.`)
else if((typeof value) === "object")
// Test type of object.
if(value instanceof Interface)
Interface.check_implementation(value, classToCheck[property])
else if(value.prototype && !(classToCheck[property] instanceof value))
throw new Error(`Property '${property}' of ${interfaceName} implementation ${toCheckName} is not '${value.constructor.name}'.`)
}
}
/**
* Decorator to automatically check if a class conforms to the current interface.
* @param {object} class_
*/
implement(class_) {
Interface.check_implementation(this, class_)
return class_
}
}
export class SettingsInterface extends Interface {
constructor() {
super()
this.width = NUMBER
this.height = NUMBER
this.xmin = NUMBER
this.ymax = NUMBER
this.xzoom = NUMBER
this.yzoom = NUMBER
this.xaxisstep = STRING
this.yaxisstep = STRING
this.xlabel = STRING
this.ylabel = STRING
this.linewidth = NUMBER
this.textsize = NUMBER
this.logscalex = BOOLEAN
this.showxgrad = BOOLEAN
this.showygrad = BOOLEAN
}
}
export class CanvasInterface extends SettingsInterface {
constructor() {
super()
this.imageLoaders = OBJECT
/** @type {function(string): CanvasRenderingContext2D} */
this.getContext = FUNCTION
/** @type {function(rect)} */
this.markDirty = FUNCTION
/** @type {function(string)} */
this.loadImage = FUNCTION
/** @type {function()} */
this.requestPaint = FUNCTION
}
}
export class RootInterface extends Interface {
constructor() {
super()
this.width = NUMBER
this.height = NUMBER
this.updateObjectsLists = FUNCTION
}
}
export class DialogInterface extends Interface {
constructor() {
super()
this.show = FUNCTION
}
}
export class HistoryInterface extends Interface {
constructor() {
super()
this.undo = FUNCTION
this.redo = FUNCTION
this.clear = FUNCTION
this.addToHistory = FUNCTION
this.unserialize = FUNCTION
this.serialize = FUNCTION
}
}

View file

@ -1,174 +0,0 @@
/**
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
* Copyright (C) 2021-2024 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/>.
*/
import * as Polyfill from "../lib/expr-eval/polyfill.mjs"
export const CONSTANTS = {
"π": Math.PI,
"pi": Math.PI,
"inf": Infinity,
"infinity": Infinity,
"∞": Infinity,
"e": Math.E
};
export const CONSTANTS_LIST = Object.keys(CONSTANTS);
export const FUNCTIONS = {
// The functions commented are the one either not implemented
// in the parser, or not to be used for autocompletion.
// Unary operators
//'+': Number,
//'-': (x) => -x,
//'!'
// Other operations
'length': (s) => Array.isArray(s) ? s.length : String(s).length,
// Boolean functions
'not': (x) => !x,
// Math functions
'abs': Math.abs,
'acos': Math.acos,
'acosh': Math.acosh,
'asin': Math.asin,
'asinh': Math.asinh,
'atan': Math.atan,
'atan2': Math.atan2,
'atanh': Math.atanh,
'cbrt': Math.cbrt,
'ceil': Math.ceil,
//'clz32': Math.clz32,
'cos': Math.cos,
'cosh': Math.cosh,
'exp': Math.exp,
'expm1': Math.expm1,
'floor': Math.floor,
//'fround': Math.fround,
'hypot': Math.hypot,
//'imul': Math.imul,
'lg': Math.log10,
'ln': Math.log,
'log': Math.log,
'log10': Math.log10,
'log1p': Math.log1p,
'log2': Math.log2,
'max': Math.max,
'min': Math.min,
'pow': Math.log2,
'random': Math.random,
'round': Math.round,
'sign': Math.sign,
'sin': Math.sin,
'sinh': Math.sinh,
'sqrt': Math.sqrt,
'tan': Math.tan,
'tanh': Math.tanh,
'trunc': Math.trunc,
// Functions in expr-eval, ported here.
'fac': Polyfill.factorial,
'gamma': Polyfill.gamma,
'Γ': Polyfill.gamma,
'roundTo': (x, exp) => Number(x).toFixed(exp),
// 'map': Polyfill.arrayMap,
// 'fold': Polyfill.arrayFold,
// 'filter': Polyfill.arrayFilter,
// 'indexOf': Polyfill.indexOf,
// 'join': Polyfill.arrayJoin,
// Integral & derivative (only here for autocomplete).
'integral': () => 0, // TODO: Implement
'derivative': () => 0,
}
export const FUNCTIONS_LIST = Object.keys(FUNCTIONS);
export class P {
// Parameter class.
constructor(type, name = '', optional = false, multipleAllowed = false) {
this.name = name
this.type = type
this.optional = optional
this.multipleAllowed = multipleAllowed
}
toString() {
let base_string = this.type
if(this.name !== '')
base_string = `${this.name}: ${base_string}`
if(this.multipleAllowed)
base_string += '...'
if(!this.optional)
base_string = `<${base_string}>`
else
base_string = `[${base_string}]`
return base_string
}
}
export let string = new P('string')
export let bool = new P('bool')
export let number = new P('number')
export let array = new P('array')
export const FUNCTIONS_USAGE = {
'length': [string],
'not': [bool],
// Math functions
'abs': [number],
'acos': [number],
'acosh': [number],
'asin': [number],
'asinh': [number],
'atan': [number],
'atan2': [number],
'atanh': [number],
'cbrt': [number],
'ceil': [number],
//'clz32': [number],
'cos': [number],
'cosh': [number],
'exp': [number],
'expm1': [number],
'floor': [number],
//'fround': [number],
'hypot': [number],
//'imul': [number],
'lg': [number],
'ln': [number],
'log': [number],
'log10': [number],
'log1p': [number],
'log2': [number],
'max': [number, number, new P('numbers', '', true, true)],
'min': [number, number, new P('numbers', '', true, true)],
'pow': [number, new P('number', 'exp')],
'random': [number, number],
'round': [number],
'sign': [number],
'sin': [number],
'sinh': [number],
'sqrt': [number],
'tan': [number],
'tanh': [number],
'trunc': [number],
// Functions in expr-eval, ported here.
'fac': [number],
'gamma': [number],
'Γ': [number],
'roundTo': [number, new P('number')],
// Function manipulation
'derivative': [new P('f'), new P('string', 'var', true), number],
'integral': [new P('from'), new P('to'), new P('f'), new P('string', 'var', true)],
}

View file

@ -15,9 +15,19 @@
You can find more screenshots on the [app's website](https://apps.ad5001.eu/logarithmplotter/).
## Run
## Build & Run
You can simply run LogarithmPlotter using `python3 run.py`.
First, you'll need to install all the required dependencies:
- [Python 3](https://python.org) with [poetry](https://python-poetry.org/), setup a virtual environment, go to the `runtime-pyside6` directory, and call
`poetry install`.
- [npm](https://npmjs.com) (or [yarn](https://yarnpkg.com/)), go to the `common` directory, and run `npm install` (or `yarn install`).
You can simply run LogarithmPlotter using `python3 run.py`. It automatically compiles the language files (requires
`lrelease` to be installed and in path), and the JavaScript modules.
If you do not wish do recompile the files again on every run, you can use the build script (`scripts/build.sh`) and run
`python3 build/runtime-pyside6/LogarithmPlotter/logarithmplotter.py`.
In order to test translations, you can use the `--lang=<lang code>` commandline option to force the locale.
@ -27,26 +37,20 @@ In order to test translations, you can use the `--lang=<lang code>` commandline
All scripts noted here can be found in the `scripts` directory.
You can generate installers for LogarithmPlotter after installing all the dependencies:
For all builds, you will need [Python 3](https://python.org) with [poetry](https://python-poetry.org/), and
`poetry install --with packaging`.
You can generate installers for LogarithmPlotter after installing all the dependencies.
- Windows installer:
- Run the `build-windows.bat` script (or `build-wine.sh` if you're cross-compiling with wine on Linux) to build an
exe for LogarithmPlotter.
- You also need [NSIS](https://nsis.sourceforge.io/Main_Page) (Linux users can install
the [nsis](https://pkgs.org/download/nsis) package).
- Run the `package-windows.bat` script (or `package-wine.sh`if you're cross-compiling on Linux). You will find a
logarithmplotter-setup.exe installer in the dist/logarithmplotter/ folder.
- Windows installer (crosscompiling from Linux):
- Run `build-wine.sh` (requires wine) to build an exe for LogarithmPlotter in build/runtime-pyside6/dist.
- You also need [NSIS](https://nsis.sourceforge.io/Main_Page) (the [nsis](https://pkgs.org/download/nsis) package is available on linux).
- Run the `package-wine.sh` script. You will find a logarithmplotter-setup.exe installer in the build/runtime-pyside6/dist/logarithmplotter/ folder.
- MacOS Archive creator installer:
- Run the `build-macosx.sh` script to build an .app for LogarithmPlotter which can be found in the dist directory.
- Run the `build-macosx.sh` script to build an .app for LogarithmPlotter which can be found in the build/runtime-pyside6/dist directory.
- Run the `package-macosx.sh` script. You will find a LogarithmPlotter-v&lt;version&gt;-setup.dmg installer in the
dist/ folder.
build/runtime-pyside6/build/pysdist/ folder.
- Linux packages:
- To build and install the flatpak, you
need [flatpak-builder](https://docs.flatpak.org/en/latest/flatpak-builder.html) installed.
- To build the snap, you need [snapcraft](https://snapcraft.io) installed.
- Run `package-linux.sh`.
- Run `package-deb.sh`. It will create an DSC and a DEB in build/runtime-pyside6/deb_dist/
- Run `scripts/build.sh` followed by `snapcraft`. It .snap file in the root directory.
- See [the flatpak repo](https://github.com/Ad5001/eu.ad5001.LogarithmPlotter) for instrutions on how to build the flatpak.
## Contribute

View file

@ -19,15 +19,20 @@ replace() {
sed -i "s/${from}/${to}/g" "$file"
}
rm ../qml/eu/ad5001/LogarithmPlotter/js/index.mjs # Remove index which should not be scanned
files=$(find .. -name *.mjs)
for file in $files; do
echo "Moving '$file' to '${file%.*}.js'..."
mv "$file" "${file%.*}.js"
# Replacements to make it valid js
replace "${file%.*}.js" "^import" "/*import"
replace "${file%.*}.js" "^export *" "/*export *"
replace "${file%.*}.js" '.mjs"$' '.mjs"*/'
replace "${file%.*}.js" "^export default" "/*export default*/"
replace "${file%.*}.js" "^export" "/*export*/"
replace "${file%.*}.js" "async " "/*async */"
replace "${file%.*}.js" "await" "/*await */"
done
echo "----------------------------"
@ -38,7 +43,6 @@ lupdate -extensions js,qs,qml,py -recursive .. -ts lp_*.ts
for lp in *.ts; do
echo "Replacing locations in $lp..."
for file in $files; do
echo " > Replacing for file $file..."
replace "$lp" "${file%.*}.js" "$file"
done
done
@ -47,8 +51,11 @@ for file in $files; do
echo "Moving '${file%.*}.js' to '$file'..."
mv "${file%.*}.js" "$file"
# Resetting changes
replace "$file" "^/*import" "import"
replace "$file" '.mjs"*/$' '.mjs"'
replace "$file" "^/*export default*/" "export default"
replace "$file" "/*await */" "await"
replace "$file" "/*async */" "async "
replace "$file" "^/*export*/" "export"
replace "$file" "^/*export default*/" "export default"
replace "$file" "^/*import" "import"
replace "$file" "^/*export" "export"
replace "$file" '.mjs"*/$' '.mjs"'
done

View file

Before

Width:  |  Height:  |  Size: 198 B

After

Width:  |  Height:  |  Size: 198 B

View file

Before

Width:  |  Height:  |  Size: 1 KiB

After

Width:  |  Height:  |  Size: 1 KiB

View file

Before

Width:  |  Height:  |  Size: 289 B

After

Width:  |  Height:  |  Size: 289 B

View file

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

Before

Width:  |  Height:  |  Size: 620 B

After

Width:  |  Height:  |  Size: 620 B

View file

Before

Width:  |  Height:  |  Size: 261 B

After

Width:  |  Height:  |  Size: 261 B

View file

Before

Width:  |  Height:  |  Size: 251 B

After

Width:  |  Height:  |  Size: 251 B

View file

Before

Width:  |  Height:  |  Size: 550 B

After

Width:  |  Height:  |  Size: 550 B

View file

Before

Width:  |  Height:  |  Size: 273 B

After

Width:  |  Height:  |  Size: 273 B

View file

Before

Width:  |  Height:  |  Size: 696 B

After

Width:  |  Height:  |  Size: 696 B

View file

Before

Width:  |  Height:  |  Size: 270 B

After

Width:  |  Height:  |  Size: 270 B

View file

Before

Width:  |  Height:  |  Size: 370 B

After

Width:  |  Height:  |  Size: 370 B

View file

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View file

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

View file

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

View file

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View file

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View file

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

View file

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View file

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

View file

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

View file

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

View file

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View file

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View file

Before

Width:  |  Height:  |  Size: 2 KiB

After

Width:  |  Height:  |  Size: 2 KiB

View file

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View file

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

View file

Before

Width:  |  Height:  |  Size: 675 B

After

Width:  |  Height:  |  Size: 675 B

View file

Before

Width:  |  Height:  |  Size: 414 B

After

Width:  |  Height:  |  Size: 414 B

View file

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View file

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View file

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View file

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View file

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View file

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View file

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View file

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View file

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View file

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View file

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View file

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

View file

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

View file

@ -3,9 +3,9 @@ Source: logarithmplotter
Version: 0.6.0
Architecture: all
Maintainer: Ad5001 <mail@ad5001.eu>
Depends: python3, python3-pip, python3-pyside6-essentials (>= 6.7.0), python3-pyside6-addons (>= 6.7), texlive-latex-base, dvipng
Depends: python3 (>= 3.9), python3-pip, python3-pyside6-essentials (>= 6.7.0), python3-pyside6-addons (>= 6.7), texlive-latex-base, dvipng
Build-Depends: debhelper (>=11~), dh-python, dpkg-dev (>= 1.16.1~), python-setuptools, python3-all-dev (>=3.9)
Build-Depends: debhelper (>=11~), dh-python, dpkg-dev (>= 1.16.1~), python-setuptools
Section: science
Priority: optional
Homepage: https://apps.ad5001.eu/logarithmplotter/

View file

@ -0,0 +1 @@
python3 (>= 3.9), python3-pip, python3-pyside6-essentials (>= 6.7.0), texlive-latex-base, dvipng

View file

Before

Width:  |  Height:  |  Size: 1.7 MiB

After

Width:  |  Height:  |  Size: 1.7 MiB

View file

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View file

Before

Width:  |  Height:  |  Size: 856 B

After

Width:  |  Height:  |  Size: 856 B

View file

Before

Width:  |  Height:  |  Size: 5 KiB

After

Width:  |  Height:  |  Size: 5 KiB

View file

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Some files were not shown because too many files have changed in this diff Show more