diff options
author | suchinton2001 <suchinton.2001@gmail.com> | 2023-07-22 18:39:14 +0530 |
---|---|---|
committer | suchinton2001 <suchinton.2001@gmail.com> | 2023-09-07 18:31:07 +0530 |
commit | db9f586a19fed7bcd04be3596fc30dc53f61b1db (patch) | |
tree | 476d86c085137779f47ee6b409e3a8aaac68991d /extras | |
parent | f9b00b992d88edc0e9c31de809a1a981139c4fde (diff) |
Upload progress on AGL demo control panel in one batch
AGL Demo Control Panel is a PyQt5 application used to simulate CAN bus signals using Kuksa.val
v1: Initial commit
v2: Remove unused assets
v3: Add Opensans fonts, remove un-used styles and add Lisences as attributions
v4:
- Remove Opensans fonts, default to Dejavu fonts
- Replace feather icons with carbon icons.
- Reusing AGL demo app assests for HVAC and Steering wheel inputs.
v5: Remove assets/Images/Lisences.md attribution file
Signed-off-by: suchinton2001 <suchinton.2001@gmail.com>
Change-Id: I1529495deff6fc27eacb92f7a29c4f71f8c8d5d9
Diffstat (limited to 'extras')
-rw-r--r-- | extras/FeedKuksa.py | 55 | ||||
-rw-r--r-- | extras/Kuksa_Instance.py | 65 | ||||
-rw-r--r-- | extras/UI_Handeler.py | 81 | ||||
-rw-r--r-- | extras/config.py | 14 |
4 files changed, 215 insertions, 0 deletions
diff --git a/extras/FeedKuksa.py b/extras/FeedKuksa.py new file mode 100644 index 0000000..d75bda0 --- /dev/null +++ b/extras/FeedKuksa.py @@ -0,0 +1,55 @@ +""" + Copyright 2023 Suchinton Chakravarty + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +""" + +import time +from PyQt5.QtCore import QThread +from . import Kuksa_Instance as kuksa_instance + +class FeedKuksa(QThread): + def __init__(self, parent=None): + QThread.__init__(self,parent) + self.stop_flag = False + self.set_instance() + + def run(self): + print("Starting thread") + self.set_instance() + while not self.stop_flag: + self.send_values() + + def stop(self): + self.stop_flag = True + print("Stopping thread") + + def set_instance(self): + self.kuksa = kuksa_instance.KuksaClientSingleton.get_instance() + self.client = self.kuksa.get_client() + + def send_values(self, Path=None, Value=None, Attribute=None): + if self.client is not None: + if self.client.checkConnection() is True: + + if Attribute is not None: + self.client.setValue(Path, Value, Attribute) + else: + self.client.setValue(Path, Value) + else: + print("Could not connect to Kuksa") + self.set_instance() + else: + print("Kuksa client is None, try reconnecting") + time.sleep(2) + self.set_instance()
\ No newline at end of file diff --git a/extras/Kuksa_Instance.py b/extras/Kuksa_Instance.py new file mode 100644 index 0000000..a36ae2c --- /dev/null +++ b/extras/Kuksa_Instance.py @@ -0,0 +1,65 @@ +from typing import Optional +import kuksa_client as kuksa +import threading +import time + +from extras import config + +class KuksaClientSingleton: + __instance: Optional["KuksaClientSingleton"] = None + __lock = threading.Lock() + + @staticmethod + def get_instance() -> "KuksaClientSingleton": + if KuksaClientSingleton.__instance is None: + with KuksaClientSingleton.__lock: + if KuksaClientSingleton.__instance is None: + KuksaClientSingleton.__instance = KuksaClientSingleton() + return KuksaClientSingleton.__instance + + def __init__(self): + if KuksaClientSingleton.__instance is not None: + raise Exception("This class is a singleton!") + else: + + self.default_Config = config.KUKSA_CONFIG + self.token = config.TOKEN_PATH + + try: + self.client = kuksa.KuksaClientThread(self.default_Config) + self.client.authorize(self.token) + time.sleep(2) + if self.client.checkConnection() == False: + self.client = None + except Exception as e: + print(e) + + + KuksaClientSingleton.__instance = self + + def reconnect_client(self, new_Config, new_Token): + if self.client is not None: + self.client.stop() + self.client = kuksa.KuksaClientThread(new_Config) + self.client.authorize(new_Token) + return self.client + + def get_client(self): + return self.client + + def get_config(self): + return self.default_Config + + def get_token(self): + return self.token + + def get_status(self): + if self.client is not None: + return self.client.checkConnection() + else: + return False + + def __del__(self): + if self.client is not None: + self.client.stop() + return None diff --git a/extras/UI_Handeler.py b/extras/UI_Handeler.py new file mode 100644 index 0000000..d591766 --- /dev/null +++ b/extras/UI_Handeler.py @@ -0,0 +1,81 @@ +from main import * +from PyQt5.QtCore import QPropertyAnimation +from PyQt5 import QtCore, QtWidgets +from PyQt5.QtGui import QPixmap, QPainter +from PyQt5.QtCore import QTimeLine +from PyQt5.QtWidgets import QWidget, QStackedWidget, QPushButton +from functools import partial + +class UI_Handeler(MainWindow): + def toggleNavigationBar(self, maxWidth, enable): + if enable: + width = self.leftMenuSubContainer.width() + maxExtend = maxWidth + standard = 80 + + if width == 80: + widthExtended = maxExtend + else: + widthExtended = standard + + self.animation = QPropertyAnimation(self.leftMenuSubContainer, b"minimumWidth") + self.animation.setDuration(400) + self.animation.setStartValue(width) + self.animation.setEndValue(widthExtended) + self.animation.setEasingCurve(QtCore.QEasingCurve.InOutQuart) + self.animation.start() + + # animate switching pages for QstackedWidget with the animation being a fade in and out + def animateSwitch(self, index): + self.fader_widget = FaderWidget(self.stackedWidget.currentWidget(), self.stackedWidget.widget(index)) + self.stackedWidget.setCurrentIndex(index) + + # add window resizing to the UI + def toggleMaximized(self): + if self.isMaximized(): + self.showNormal() + else: + self.showMaximized() + + # move the window by dragging the header + def moveWindow(self, event): + + if event.buttons() == QtCore.Qt.LeftButton: + self.move(self.pos() + event.globalPos() - self.clickPosition) + self.clickPosition = event.globalPos() + event.accept() + + # get the position of the mouse when clicked + def mousePressEvent(self, event): + self.clickPosition = event.globalPos() + event.accept() + + # get the position of the mouse when released + def mouseReleaseEvent(self, event): + self.clickPosition = None + event.accept() + +class FaderWidget(QWidget): + def __init__(self, old_widget, new_widget): + QWidget.__init__(self, new_widget) + self.old_pixmap = QPixmap(new_widget.size()) + old_widget.render(self.old_pixmap) + self.pixmap_opacity = 1.0 + self.timeline = QTimeLine() + self.timeline.valueChanged.connect(self.animate) + self.timeline.finished.connect(self.close) + self.timeline.setDuration(250) + self.timeline.start() + self.resize(new_widget.size()) + self.show() + + def paintEvent(self, event): + painter = QPainter() + painter.begin(self) + painter.setOpacity(self.pixmap_opacity) + painter.drawPixmap(0, 0, self.old_pixmap) + painter.end() + + def animate(self, value): + self.pixmap_opacity = 1.0 - value + self.repaint()
\ No newline at end of file diff --git a/extras/config.py b/extras/config.py new file mode 100644 index 0000000..5056cc3 --- /dev/null +++ b/extras/config.py @@ -0,0 +1,14 @@ +import os +import platform + +python_version = "python" + platform.python_version_tuple()[0] + "." + platform.python_version_tuple()[1] + +KUKSA_CONFIG = { + "ip": 'localhost', + "port": "8090", + 'protocol': 'ws', + 'insecure': False, +} + +TOKEN_PATH = os.path.join(os.path.expanduser("~"), + f".local/lib/{python_version}/site-packages/kuksa_certificates/jwt/super-admin.json.token")
\ No newline at end of file |