Adding main tests (note: full main app may not be completely tested though)
This commit is contained in:
parent
4a5756f24d
commit
a9e47dbc17
7 changed files with 194 additions and 37 deletions
|
@ -1,20 +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/>.
|
||||
"""
|
||||
if __name__ == "__main__":
|
||||
from .logarithmplotter import run
|
||||
run()
|
|
@ -48,16 +48,31 @@ from LogarithmPlotter.util.helper import Helper
|
|||
from LogarithmPlotter.util.latex import Latex
|
||||
from LogarithmPlotter.util.js import PyJSValue
|
||||
|
||||
LINUX_THEMES = { # See https://specifications.freedesktop.org/menu-spec/latest/onlyshowin-registry.html
|
||||
"COSMIC": "Basic",
|
||||
"GNOME": "Basic",
|
||||
"GNOME-Classic": "Basic",
|
||||
"GNOME-Flashback": "Basic",
|
||||
"KDE": "Fusion",
|
||||
"LXDE": "Basic",
|
||||
"LXQt": "Fusion",
|
||||
"MATE": "Fusion",
|
||||
"TDE": "Fusion",
|
||||
"Unity": "Basic",
|
||||
"XFCE": "Basic",
|
||||
"Cinnamon": "Fusion",
|
||||
"Pantheon": "Basic",
|
||||
"DDE": "Basic",
|
||||
"EDE": "Fusion",
|
||||
"Endless": "Basic",
|
||||
"Old": "Fusion",
|
||||
}
|
||||
|
||||
|
||||
def get_linux_theme() -> str:
|
||||
des = {
|
||||
"KDE": "Fusion",
|
||||
"gnome": "Basic",
|
||||
"lxqt": "Fusion",
|
||||
"mate": "Fusion",
|
||||
}
|
||||
if "XDG_SESSION_DESKTOP" in environ:
|
||||
if environ["XDG_SESSION_DESKTOP"] in des:
|
||||
return des[environ["XDG_SESSION_DESKTOP"]]
|
||||
if environ["XDG_SESSION_DESKTOP"] in LINUX_THEMES:
|
||||
return LINUX_THEMES[environ["XDG_SESSION_DESKTOP"]]
|
||||
return "Fusion"
|
||||
else:
|
||||
# Android
|
||||
|
@ -77,18 +92,18 @@ def get_platform_qt_style(os) -> str:
|
|||
def register_icon_directories() -> None:
|
||||
icon_fallbacks = QIcon.fallbackSearchPaths()
|
||||
base_icon_path = path.join(getcwd(), "qml", "eu", "ad5001", "LogarithmPlotter", "icons")
|
||||
icon_fallbacks.append(path.realpath(path.join(base_icon_path, "common")))
|
||||
icon_fallbacks.append(path.realpath(path.join(base_icon_path, "objects")))
|
||||
icon_fallbacks.append(path.realpath(path.join(base_icon_path, "history")))
|
||||
icon_fallbacks.append(path.realpath(path.join(base_icon_path, "settings")))
|
||||
icon_fallbacks.append(path.realpath(path.join(base_icon_path, "settings", "custom")))
|
||||
paths = [["common"], ["objects"], ["history"], ["settings"], ["settings", "custom"]]
|
||||
for p in paths:
|
||||
icon_fallbacks.append(path.realpath(path.join(base_icon_path, *p)))
|
||||
QIcon.setFallbackSearchPaths(icon_fallbacks)
|
||||
|
||||
|
||||
def create_qapp() -> QApplication:
|
||||
app = QApplication(argv)
|
||||
app.setApplicationName("LogarithmPlotter")
|
||||
app.setDesktopFileName("eu.ad5001.LogarithmPlotter.desktop")
|
||||
app.setApplicationDisplayName("LogarithmPlotter")
|
||||
app.setApplicationVersion(f"v{__VERSION__}")
|
||||
app.setDesktopFileName("eu.ad5001.LogarithmPlotter")
|
||||
app.setOrganizationName("Ad5001")
|
||||
app.styleHints().setShowShortcutsInContextMenus(True)
|
||||
app.setWindowIcon(QIcon(path.realpath(path.join(getcwd(), "logarithmplotter.svg"))))
|
||||
|
@ -101,8 +116,10 @@ def install_translation(app: QApplication) -> QTranslator:
|
|||
# Check if lang is forced.
|
||||
forcedlang = [p for p in argv if p[:7] == "--lang="]
|
||||
locale = QLocale(forcedlang[0][7:]) if len(forcedlang) > 0 else QLocale()
|
||||
if translator.load(locale, "lp", "_", path.realpath(path.join(getcwd(), "i18n"))):
|
||||
app.installTranslator(translator)
|
||||
if not translator.load(locale, "lp", "_", path.realpath(path.join(getcwd(), "i18n"))):
|
||||
# Load default translation
|
||||
translator.load(QLocale("en"), "lp", "_", path.realpath(path.join(getcwd(), "i18n")))
|
||||
app.installTranslator(translator)
|
||||
return translator
|
||||
|
||||
|
||||
|
@ -145,7 +162,7 @@ def run():
|
|||
latex = Latex(tempdir)
|
||||
engine, js_globals = create_engine(helper, latex, dep_time)
|
||||
|
||||
if len(engine.rootObjects()) == 0: # No root objects loaded
|
||||
if len(engine.rootObjects()) == 0: # No root objects loaded
|
||||
print("No root object", path.realpath(path.join(getcwd(), "qml")))
|
||||
exit(-1)
|
||||
|
||||
|
|
|
@ -48,11 +48,11 @@ class PyJSValue:
|
|||
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, PyJSValue):
|
||||
return self.qjs_value.equals(other.qjs_value)
|
||||
return self.qjs_value.strictlyEquals(other.qjs_value)
|
||||
elif isinstance(other, QJSValue):
|
||||
return self.qjs_value.equals(other)
|
||||
return self.qjs_value.strictlyEquals(other)
|
||||
elif type(other) in (int, float, str, bool):
|
||||
return self.qjs_value.equals(QJSValue(other))
|
||||
return self.qjs_value.strictlyEquals(QJSValue(other))
|
||||
else:
|
||||
return False
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue