Compare commits
2 commits
a7a430c723
...
c86eed95ca
Author | SHA1 | Date | |
---|---|---|---|
c86eed95ca | |||
3afa9d0c8e |
5 changed files with 21 additions and 98 deletions
|
@ -20,18 +20,15 @@ from time import time
|
|||
|
||||
start_time = time()
|
||||
|
||||
from PySide2.QtWidgets import QApplication, QFileDialog
|
||||
from PySide2.QtQml import QQmlApplicationEngine, qmlRegisterType
|
||||
from PySide2.QtCore import Qt, QObject, Signal, Slot, Property, QTranslator, QLocale, QCoreApplication
|
||||
from PySide2.QtGui import QIcon, QImage, QKeySequence
|
||||
from PySide2 import __version__ as PySide2_version
|
||||
from PySide2.QtWidgets import QApplication
|
||||
from PySide2.QtQml import QQmlApplicationEngine
|
||||
from PySide2.QtCore import QTranslator, QLocale
|
||||
from PySide2.QtGui import QIcon
|
||||
|
||||
from tempfile import mkstemp
|
||||
from os import getcwd, chdir, environ, path, remove, close
|
||||
from platform import release as os_release
|
||||
from json import dumps, loads
|
||||
from sys import platform, argv, version as sys_version, exit
|
||||
from webbrowser import open as openWeb
|
||||
|
||||
# Create the temporary file for saving copied screenshots
|
||||
fd, tmpfile = mkstemp(suffix='.png')
|
||||
|
@ -46,6 +43,7 @@ if path.realpath(path.join(getcwd(), "..")) not in sys_path:
|
|||
|
||||
from LogarithmPlotter import config, native, __VERSION__
|
||||
from LogarithmPlotter.update import check_for_updates
|
||||
from LogarithmPlotter.helper import Helper
|
||||
|
||||
config.init()
|
||||
|
||||
|
@ -62,94 +60,6 @@ def get_linux_theme():
|
|||
# Android
|
||||
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():
|
||||
|
||||
environ["QT_QUICK_CONTROLS_STYLE"] = {
|
||||
|
@ -189,7 +99,8 @@ def run():
|
|||
app.installEventFilter(macOSFileOpenHandler)
|
||||
|
||||
engine = QQmlApplicationEngine()
|
||||
helper = Helper(engine)
|
||||
global tmpfile
|
||||
helper = Helper(pwd, tmpfile)
|
||||
engine.rootContext().setContextProperty("Helper", helper)
|
||||
engine.rootContext().setContextProperty("TestBuild", "--test-build" in argv)
|
||||
engine.rootContext().setContextProperty("StartTime", dep_time)
|
||||
|
@ -205,6 +116,7 @@ def run():
|
|||
print(path.realpath(path.join(getcwd(), "qml", "eu", "ad5001", "LogarithmPlotter", "LogarithmPlotter.qml")))
|
||||
exit(-1)
|
||||
|
||||
# Open the current diagram
|
||||
chdir(pwd)
|
||||
if len(argv) > 0 and path.exists(argv[-1]) and argv[-1].split('.')[-1] in ['lpf']:
|
||||
engine.rootObjects()[0].loadDiagram(argv[-1])
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and repartition functions.
|
||||
* Copyright (C) 2022 Ad5001
|
||||
|
|
|
@ -84,9 +84,11 @@ class Point extends Common.DrawableObject {
|
|||
ctx.font = `${canvas.textsize}px sans-serif`
|
||||
var textSize = ctx.measureText(text).width
|
||||
switch(this.labelPosition) {
|
||||
case 'top':
|
||||
case 'above':
|
||||
canvas.drawVisibleText(ctx, text, canvasX-textSize/2, canvasY-16)
|
||||
break;
|
||||
case 'bottom':
|
||||
case 'below':
|
||||
canvas.drawVisibleText(ctx, text, canvasX-textSize/2, canvasY+16)
|
||||
break;
|
||||
|
@ -96,15 +98,19 @@ class Point extends Common.DrawableObject {
|
|||
case 'right':
|
||||
canvas.drawVisibleText(ctx, text, canvasX+10, canvasY+4)
|
||||
break;
|
||||
case 'top-left':
|
||||
case 'above-left':
|
||||
canvas.drawVisibleText(ctx, text, canvasX-textSize-10, canvasY-16)
|
||||
break;
|
||||
case 'top-right':
|
||||
case 'above-right':
|
||||
canvas.drawVisibleText(ctx, text, canvasX+10, canvasY-16)
|
||||
break;
|
||||
case 'bottom-left':
|
||||
case 'below-left':
|
||||
canvas.drawVisibleText(ctx, text, canvasX-textSize-10, canvasY+16)
|
||||
break;
|
||||
case 'bottom-right':
|
||||
case 'below-right':
|
||||
canvas.drawVisibleText(ctx, text, canvasX+10, canvasY+16)
|
||||
break;
|
||||
|
|
|
@ -69,9 +69,11 @@ class Text extends Common.DrawableObject {
|
|||
case 'center':
|
||||
canvas.drawVisibleText(ctx, this.text, canvasX-textSize/2, canvasY+4)
|
||||
break;
|
||||
case 'top':
|
||||
case 'above':
|
||||
canvas.drawVisibleText(ctx, this.text, canvasX-textSize/2, canvasY-16)
|
||||
break;
|
||||
case 'bottom':
|
||||
case 'below':
|
||||
canvas.drawVisibleText(ctx, this.text, canvasX-textSize/2, canvasY+16)
|
||||
break;
|
||||
|
@ -81,15 +83,19 @@ class Text extends Common.DrawableObject {
|
|||
case 'right':
|
||||
canvas.drawVisibleText(ctx, this.text, canvasX+5, canvasY+4)
|
||||
break;
|
||||
case 'top-left':
|
||||
case 'above-left':
|
||||
canvas.drawVisibleText(ctx, this.text, canvasX-textSize-5, canvasY-16)
|
||||
break;
|
||||
case 'top-right':
|
||||
case 'above-right':
|
||||
canvas.drawVisibleText(ctx, this.text, canvasX+5, canvasY-16)
|
||||
break;
|
||||
case 'bottom-left':
|
||||
case 'below-left':
|
||||
canvas.drawVisibleText(ctx, this.text, canvasX-textSize-5, canvasY+16)
|
||||
break;
|
||||
case 'bottom-right':
|
||||
case 'below-right':
|
||||
canvas.drawVisibleText(ctx, this.text, canvasX+5, canvasY+16)
|
||||
break;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
from PySide2.QtCore import Qt, QRunnable, QThreadPool, QThread, QObject, Signal, QCoreApplication
|
||||
from PySide2.QtCore import QRunnable, QThreadPool, QThread, QObject, Signal, QCoreApplication
|
||||
from urllib.request import urlopen
|
||||
from urllib.error import HTTPError, URLError
|
||||
from sys import argv
|
||||
|
|
Loading…
Reference in a new issue