Compare commits
No commits in common. "c86eed95ca7c388b717c7f14bbe0c6e33c40d07d" and "a7a430c7236d27a2d3fba609d1c2f899b1ef461b" have entirely different histories.
c86eed95ca
...
a7a430c723
5 changed files with 98 additions and 21 deletions
|
@ -20,15 +20,18 @@ from time import time
|
||||||
|
|
||||||
start_time = time()
|
start_time = time()
|
||||||
|
|
||||||
from PySide2.QtWidgets import QApplication
|
from PySide2.QtWidgets import QApplication, QFileDialog
|
||||||
from PySide2.QtQml import QQmlApplicationEngine
|
from PySide2.QtQml import QQmlApplicationEngine, qmlRegisterType
|
||||||
from PySide2.QtCore import QTranslator, QLocale
|
from PySide2.QtCore import Qt, QObject, Signal, Slot, Property, QTranslator, QLocale, QCoreApplication
|
||||||
from PySide2.QtGui import QIcon
|
from PySide2.QtGui import QIcon, QImage, QKeySequence
|
||||||
|
from PySide2 import __version__ as PySide2_version
|
||||||
|
|
||||||
from tempfile import mkstemp
|
from tempfile import mkstemp
|
||||||
from os import getcwd, chdir, environ, path, remove, close
|
from os import getcwd, chdir, environ, path, remove, close
|
||||||
from platform import release as os_release
|
from platform import release as os_release
|
||||||
|
from json import dumps, loads
|
||||||
from sys import platform, argv, version as sys_version, exit
|
from sys import platform, argv, version as sys_version, exit
|
||||||
|
from webbrowser import open as openWeb
|
||||||
|
|
||||||
# Create the temporary file for saving copied screenshots
|
# Create the temporary file for saving copied screenshots
|
||||||
fd, tmpfile = mkstemp(suffix='.png')
|
fd, tmpfile = mkstemp(suffix='.png')
|
||||||
|
@ -43,7 +46,6 @@ if path.realpath(path.join(getcwd(), "..")) not in sys_path:
|
||||||
|
|
||||||
from LogarithmPlotter import config, native, __VERSION__
|
from LogarithmPlotter import config, native, __VERSION__
|
||||||
from LogarithmPlotter.update import check_for_updates
|
from LogarithmPlotter.update import check_for_updates
|
||||||
from LogarithmPlotter.helper import Helper
|
|
||||||
|
|
||||||
config.init()
|
config.init()
|
||||||
|
|
||||||
|
@ -60,6 +62,94 @@ def get_linux_theme():
|
||||||
# Android
|
# Android
|
||||||
return "Material"
|
return "Material"
|
||||||
|
|
||||||
|
class Helper(QObject):
|
||||||
|
|
||||||
|
def __init__(self, engine: QQmlApplicationEngine):
|
||||||
|
QObject.__init__(self)
|
||||||
|
self.engine = engine;
|
||||||
|
|
||||||
|
@Slot(str, str)
|
||||||
|
def write(self, filename, filedata):
|
||||||
|
chdir(pwd)
|
||||||
|
if path.exists(path.dirname(path.realpath(filename))):
|
||||||
|
if filename.split(".")[-1] == "lpf":
|
||||||
|
# Add header to file
|
||||||
|
filedata = "LPFv1" + filedata
|
||||||
|
f = open(path.realpath(filename), 'w', -1, 'utf8')
|
||||||
|
f.write(filedata)
|
||||||
|
f.close()
|
||||||
|
chdir(path.dirname(path.realpath(__file__)))
|
||||||
|
|
||||||
|
@Slot(str, result=str)
|
||||||
|
def load(self, filename):
|
||||||
|
chdir(pwd)
|
||||||
|
data = '{}'
|
||||||
|
from PySide2.QtWidgets import QMessageBox
|
||||||
|
if path.exists(path.realpath(filename)):
|
||||||
|
f = open(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
|
||||||
|
QMessageBox.warning(None, 'LogarithmPlotter', QCoreApplication.translate('main','Could not open file "{}":\n{}').format(filename, e), QMessageBox.Ok) # Cannot parse file
|
||||||
|
else:
|
||||||
|
QMessageBox.warning(None, 'LogarithmPlotter', QCoreApplication.translate('main','Could not open file: "{}"\nFile does not exist.').format(filename), QMessageBox.Ok) # Cannot parse file
|
||||||
|
chdir(path.dirname(path.realpath(__file__)))
|
||||||
|
return data
|
||||||
|
|
||||||
|
@Slot(result=str)
|
||||||
|
def gettmpfile(self):
|
||||||
|
global tmpfile
|
||||||
|
return tmpfile
|
||||||
|
|
||||||
|
@Slot()
|
||||||
|
def copyImageToClipboard(self):
|
||||||
|
global tmpfile
|
||||||
|
clipboard = QApplication.clipboard()
|
||||||
|
clipboard.setImage(QImage(tmpfile))
|
||||||
|
|
||||||
|
@Slot(result=str)
|
||||||
|
def getVersion(self):
|
||||||
|
return __VERSION__
|
||||||
|
|
||||||
|
@Slot(str, result=str)
|
||||||
|
def getSetting(self, namespace):
|
||||||
|
return config.getSetting(namespace)
|
||||||
|
|
||||||
|
@Slot(str, result=bool)
|
||||||
|
def getSettingBool(self, namespace):
|
||||||
|
return config.getSetting(namespace)
|
||||||
|
|
||||||
|
@Slot(str, str)
|
||||||
|
def setSetting(self, namespace, value):
|
||||||
|
return config.setSetting(namespace, value)
|
||||||
|
|
||||||
|
@Slot(str, bool)
|
||||||
|
def setSettingBool(self, namespace, value):
|
||||||
|
return config.setSetting(namespace, value)
|
||||||
|
|
||||||
|
@Slot(str)
|
||||||
|
def setLanguage(self, new_lang):
|
||||||
|
config.setSetting("language", new_lang)
|
||||||
|
|
||||||
|
@Slot(result=str)
|
||||||
|
def getDebugInfos(self):
|
||||||
|
"""
|
||||||
|
Returns the version info about Qt, PySide2 & Python
|
||||||
|
"""
|
||||||
|
return QCoreApplication.translate('main',"Built with PySide2 (Qt) v{} and python v{}").format(PySide2_version, sys_version.split("\n")[0])
|
||||||
|
|
||||||
|
@Slot(str)
|
||||||
|
def openUrl(self, url):
|
||||||
|
openWeb(url)
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
|
|
||||||
environ["QT_QUICK_CONTROLS_STYLE"] = {
|
environ["QT_QUICK_CONTROLS_STYLE"] = {
|
||||||
|
@ -99,8 +189,7 @@ def run():
|
||||||
app.installEventFilter(macOSFileOpenHandler)
|
app.installEventFilter(macOSFileOpenHandler)
|
||||||
|
|
||||||
engine = QQmlApplicationEngine()
|
engine = QQmlApplicationEngine()
|
||||||
global tmpfile
|
helper = Helper(engine)
|
||||||
helper = Helper(pwd, tmpfile)
|
|
||||||
engine.rootContext().setContextProperty("Helper", helper)
|
engine.rootContext().setContextProperty("Helper", helper)
|
||||||
engine.rootContext().setContextProperty("TestBuild", "--test-build" in argv)
|
engine.rootContext().setContextProperty("TestBuild", "--test-build" in argv)
|
||||||
engine.rootContext().setContextProperty("StartTime", dep_time)
|
engine.rootContext().setContextProperty("StartTime", dep_time)
|
||||||
|
@ -116,7 +205,6 @@ def run():
|
||||||
print(path.realpath(path.join(getcwd(), "qml", "eu", "ad5001", "LogarithmPlotter", "LogarithmPlotter.qml")))
|
print(path.realpath(path.join(getcwd(), "qml", "eu", "ad5001", "LogarithmPlotter", "LogarithmPlotter.qml")))
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
# Open the current diagram
|
|
||||||
chdir(pwd)
|
chdir(pwd)
|
||||||
if len(argv) > 0 and path.exists(argv[-1]) and argv[-1].split('.')[-1] in ['lpf']:
|
if len(argv) > 0 and path.exists(argv[-1]) and argv[-1].split('.')[-1] in ['lpf']:
|
||||||
engine.rootObjects()[0].loadDiagram(argv[-1])
|
engine.rootObjects()[0].loadDiagram(argv[-1])
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and repartition functions.
|
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and repartition functions.
|
||||||
* Copyright (C) 2022 Ad5001
|
* Copyright (C) 2022 Ad5001
|
||||||
|
|
|
@ -84,11 +84,9 @@ class Point extends Common.DrawableObject {
|
||||||
ctx.font = `${canvas.textsize}px sans-serif`
|
ctx.font = `${canvas.textsize}px sans-serif`
|
||||||
var textSize = ctx.measureText(text).width
|
var textSize = ctx.measureText(text).width
|
||||||
switch(this.labelPosition) {
|
switch(this.labelPosition) {
|
||||||
case 'top':
|
|
||||||
case 'above':
|
case 'above':
|
||||||
canvas.drawVisibleText(ctx, text, canvasX-textSize/2, canvasY-16)
|
canvas.drawVisibleText(ctx, text, canvasX-textSize/2, canvasY-16)
|
||||||
break;
|
break;
|
||||||
case 'bottom':
|
|
||||||
case 'below':
|
case 'below':
|
||||||
canvas.drawVisibleText(ctx, text, canvasX-textSize/2, canvasY+16)
|
canvas.drawVisibleText(ctx, text, canvasX-textSize/2, canvasY+16)
|
||||||
break;
|
break;
|
||||||
|
@ -98,19 +96,15 @@ class Point extends Common.DrawableObject {
|
||||||
case 'right':
|
case 'right':
|
||||||
canvas.drawVisibleText(ctx, text, canvasX+10, canvasY+4)
|
canvas.drawVisibleText(ctx, text, canvasX+10, canvasY+4)
|
||||||
break;
|
break;
|
||||||
case 'top-left':
|
|
||||||
case 'above-left':
|
case 'above-left':
|
||||||
canvas.drawVisibleText(ctx, text, canvasX-textSize-10, canvasY-16)
|
canvas.drawVisibleText(ctx, text, canvasX-textSize-10, canvasY-16)
|
||||||
break;
|
break;
|
||||||
case 'top-right':
|
|
||||||
case 'above-right':
|
case 'above-right':
|
||||||
canvas.drawVisibleText(ctx, text, canvasX+10, canvasY-16)
|
canvas.drawVisibleText(ctx, text, canvasX+10, canvasY-16)
|
||||||
break;
|
break;
|
||||||
case 'bottom-left':
|
|
||||||
case 'below-left':
|
case 'below-left':
|
||||||
canvas.drawVisibleText(ctx, text, canvasX-textSize-10, canvasY+16)
|
canvas.drawVisibleText(ctx, text, canvasX-textSize-10, canvasY+16)
|
||||||
break;
|
break;
|
||||||
case 'bottom-right':
|
|
||||||
case 'below-right':
|
case 'below-right':
|
||||||
canvas.drawVisibleText(ctx, text, canvasX+10, canvasY+16)
|
canvas.drawVisibleText(ctx, text, canvasX+10, canvasY+16)
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -69,11 +69,9 @@ class Text extends Common.DrawableObject {
|
||||||
case 'center':
|
case 'center':
|
||||||
canvas.drawVisibleText(ctx, this.text, canvasX-textSize/2, canvasY+4)
|
canvas.drawVisibleText(ctx, this.text, canvasX-textSize/2, canvasY+4)
|
||||||
break;
|
break;
|
||||||
case 'top':
|
|
||||||
case 'above':
|
case 'above':
|
||||||
canvas.drawVisibleText(ctx, this.text, canvasX-textSize/2, canvasY-16)
|
canvas.drawVisibleText(ctx, this.text, canvasX-textSize/2, canvasY-16)
|
||||||
break;
|
break;
|
||||||
case 'bottom':
|
|
||||||
case 'below':
|
case 'below':
|
||||||
canvas.drawVisibleText(ctx, this.text, canvasX-textSize/2, canvasY+16)
|
canvas.drawVisibleText(ctx, this.text, canvasX-textSize/2, canvasY+16)
|
||||||
break;
|
break;
|
||||||
|
@ -83,19 +81,15 @@ class Text extends Common.DrawableObject {
|
||||||
case 'right':
|
case 'right':
|
||||||
canvas.drawVisibleText(ctx, this.text, canvasX+5, canvasY+4)
|
canvas.drawVisibleText(ctx, this.text, canvasX+5, canvasY+4)
|
||||||
break;
|
break;
|
||||||
case 'top-left':
|
|
||||||
case 'above-left':
|
case 'above-left':
|
||||||
canvas.drawVisibleText(ctx, this.text, canvasX-textSize-5, canvasY-16)
|
canvas.drawVisibleText(ctx, this.text, canvasX-textSize-5, canvasY-16)
|
||||||
break;
|
break;
|
||||||
case 'top-right':
|
|
||||||
case 'above-right':
|
case 'above-right':
|
||||||
canvas.drawVisibleText(ctx, this.text, canvasX+5, canvasY-16)
|
canvas.drawVisibleText(ctx, this.text, canvasX+5, canvasY-16)
|
||||||
break;
|
break;
|
||||||
case 'bottom-left':
|
|
||||||
case 'below-left':
|
case 'below-left':
|
||||||
canvas.drawVisibleText(ctx, this.text, canvasX-textSize-5, canvasY+16)
|
canvas.drawVisibleText(ctx, this.text, canvasX-textSize-5, canvasY+16)
|
||||||
break;
|
break;
|
||||||
case 'bottom-right':
|
|
||||||
case 'below-right':
|
case 'below-right':
|
||||||
canvas.drawVisibleText(ctx, this.text, canvasX+5, canvasY+16)
|
canvas.drawVisibleText(ctx, this.text, canvasX+5, canvasY+16)
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from PySide2.QtCore import QRunnable, QThreadPool, QThread, QObject, Signal, QCoreApplication
|
from PySide2.QtCore import Qt, QRunnable, QThreadPool, QThread, QObject, Signal, QCoreApplication
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
from urllib.error import HTTPError, URLError
|
from urllib.error import HTTPError, URLError
|
||||||
from sys import argv
|
from sys import argv
|
||||||
|
|
Loading…
Reference in a new issue