summaryrefslogtreecommitdiffstats
path: root/Widgets
diff options
context:
space:
mode:
Diffstat (limited to 'Widgets')
-rw-r--r--Widgets/Dashboard.py62
-rw-r--r--Widgets/HVACPage.py58
-rw-r--r--Widgets/ICPage.py71
-rw-r--r--Widgets/SteeringCtrlPage.py67
-rw-r--r--Widgets/settings.py65
5 files changed, 193 insertions, 130 deletions
diff --git a/Widgets/Dashboard.py b/Widgets/Dashboard.py
index e7e17a6..8b6a11f 100644
--- a/Widgets/Dashboard.py
+++ b/Widgets/Dashboard.py
@@ -14,12 +14,18 @@
limitations under the License.
"""
+from PyQt5 import QtCore, QtGui, QtWidgets
+from extras.FeedKuksa import FeedKuksa
import os
import sys
from PyQt5 import uic
-from PyQt5 import QtWidgets
+from PyQt5 import QtWidgets
+from PyQt5.QtWidgets import *
+from PyQt5.QtSvg import *
from PyQt5.QtCore import pyqtSignal
-from PyQt5 import QtCore, QtGui
+from PyQt5.QtGui import QIcon
+from PyQt5 import QtCore
+from PyQt5 import QtSvg
current_dir = os.path.dirname(os.path.abspath(__file__))
@@ -27,14 +33,11 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.dirname(current_dir))
-from extras.FeedKuksa import FeedKuksa
Form, Base = uic.loadUiType(os.path.join(current_dir, "../ui/Dashboard.ui"))
# ========================================
-from PyQt5 import QtCore, QtGui, QtWidgets
-from PyQt5.QtCore import pyqtSignal
class Dashboard(Base, Form):
"""
@@ -64,33 +67,34 @@ class Dashboard(Base, Form):
self.feed_kuksa = FeedKuksa()
Dashboard_tiles = (self.DB_IC_Tile,
- self.DB_HVAC_Tile,
- self.DB_Steering_Tile,
- self.DB_Settings_Tile)
+ self.DB_HVAC_Tile,
+ self.DB_Steering_Tile,
+ self.DB_Settings_Tile)
DashboardTiles = QtWidgets.QButtonGroup(self)
-
+
DashboardTiles.buttonClicked.connect(self.tile_clicked)
for i, tile in enumerate(Dashboard_tiles):
- self.set_icon(tile, 55)
+ self.set_icon(tile, 90)
DashboardTiles.addButton(tile)
- def set_icon(self, tile, size):
- """
- Sets the icon for the given tile.
-
- Parameters:
- - tile: The tile for which the icon needs to be set.
- - size: The size of the icon.
- """
+ def set_icon(self, tile, icon_size):
try:
- icon = tile.icon()
- if icon.availableSizes():
- pixmap = icon.pixmap(icon.availableSizes()[0])
- scaled_pixmap = pixmap.scaled(size, size, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)
- tile.setIcon(QtGui.QIcon(scaled_pixmap))
- tile.setIconSize(QtCore.QSize(size, size))
+ if tile == self.DB_IC_Tile:
+ file = ":/Carbon_Icons/carbon_icons/meter.svg"
+ if tile == self.DB_HVAC_Tile:
+ file = ":/Carbon_Icons/carbon_icons/windy--strong.svg"
+ if tile == self.DB_Steering_Tile:
+ file = ":/Images/Images/steering-wheel.svg"
+ if tile == self.DB_Settings_Tile:
+ file = ":/Carbon_Icons/carbon_icons/settings.svg"
+ getsize = QtSvg.QSvgRenderer(file)
+ svg_widget = QtSvg.QSvgWidget(file)
+ svg_widget.setFixedSize(getsize.defaultSize()*2)
+ svg_widget.setStyleSheet("background-color: transparent;")
+ tile.setIcon(QIcon(svg_widget.grab()))
+ tile.setIconSize(QtCore.QSize(icon_size, icon_size))
except Exception as e:
print(f"Failed to set icon: {e}")
@@ -110,4 +114,12 @@ class Dashboard(Base, Form):
elif tile == self.DB_Settings_Tile:
self.parent().setCurrentIndex(4)
- self.tileClickedSignal.emit() \ No newline at end of file
+ self.tileClickedSignal.emit()
+
+
+if __name__ == '__main__':
+ import sys
+ app = QApplication(sys.argv)
+ w = Dashboard()
+ w.show()
+ sys.exit(app.exec_()) \ No newline at end of file
diff --git a/Widgets/HVACPage.py b/Widgets/HVACPage.py
index 312f82b..56d7f8b 100644
--- a/Widgets/HVACPage.py
+++ b/Widgets/HVACPage.py
@@ -14,6 +14,7 @@
limitations under the License.
"""
+from extras.FeedKuksa import FeedKuksa
import os
import sys
from PyQt5 import uic
@@ -25,12 +26,12 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.dirname(current_dir))
-from extras.FeedKuksa import FeedKuksa
Form, Base = uic.loadUiType(os.path.join(current_dir, "../ui/HVAC.ui"))
# ========================================
+
class HVAC_Paths():
def __init__(self):
self.leftTemp = "Vehicle.Cabin.HVAC.Station.Row1.Left.Temperature"
@@ -38,9 +39,10 @@ class HVAC_Paths():
self.rightTemp = "Vehicle.Cabin.HVAC.Station.Row1.Right.Temperature"
self.rightFanSpeed = "Vehicle.Cabin.HVAC.Station.Row1.Right.FanSpeed"
- # temperatureList contains values from 32 to 16
+ # temperatureList contains values from 32 to 16
self.temperatureList = [str(i) + "°C" for i in range(32, 15, -1)]
+
class HVACWidget(Base, Form):
"""
A widget for controlling HVAC settings.
@@ -58,42 +60,52 @@ class HVACWidget(Base, Form):
super(self.__class__, self).__init__(parent)
self.setupUi(self)
-
+
self.HVAC = HVAC_Paths()
self.feed_kuksa = FeedKuksa()
-
+
self.leftTempList = self.findChild(QListWidget, "leftTempList")
self.leftTempList.addItems(self.HVAC.temperatureList)
self.leftTempList.setCurrentRow(0)
self.leftTempList.itemClicked.connect(self.leftTempListClicked)
- self.leftTempList.itemSelectionChanged.connect(self.leftTempListClicked)
+ self.leftTempList.itemSelectionChanged.connect(
+ self.leftTempListClicked)
self.leftTempList.wheelEvent = lambda event: None
self.rightTempList = self.findChild(QListWidget, "rightTempList")
self.rightTempList.addItems(self.HVAC.temperatureList)
self.rightTempList.setCurrentRow(0)
self.rightTempList.itemClicked.connect(self.rightTempListClicked)
- self.rightTempList.itemSelectionChanged.connect(self.rightTempListClicked)
+ self.rightTempList.itemSelectionChanged.connect(
+ self.rightTempListClicked)
self.rightTempList.wheelEvent = lambda event: None
self.leftTempUp = self.findChild(QPushButton, "leftTempUp")
- self.leftTempUp.clicked.connect(lambda: self.leftTempList.setCurrentRow(self.leftTempList.currentRow() - 1))
+ self.leftTempUp.clicked.connect(
+ lambda: self.leftTempList.setCurrentRow(self.leftTempList.currentRow() - 1))
self.leftTempDown = self.findChild(QPushButton, "leftTempDown")
- self.leftTempDown.clicked.connect(lambda: self.leftTempList.setCurrentRow(self.leftTempList.currentRow() + 1))
+ self.leftTempDown.clicked.connect(
+ lambda: self.leftTempList.setCurrentRow(self.leftTempList.currentRow() + 1))
self.rightTempUp = self.findChild(QPushButton, "rightTempUp")
- self.rightTempUp.clicked.connect(lambda: self.rightTempList.setCurrentRow(self.rightTempList.currentRow() - 1))
+ self.rightTempUp.clicked.connect(
+ lambda: self.rightTempList.setCurrentRow(self.rightTempList.currentRow() - 1))
self.rightTempDown = self.findChild(QPushButton, "rightTempDown")
- self.rightTempDown.clicked.connect(lambda: self.rightTempList.setCurrentRow(self.rightTempList.currentRow() + 1))
+ self.rightTempDown.clicked.connect(
+ lambda: self.rightTempList.setCurrentRow(self.rightTempList.currentRow() + 1))
- self.leftFanSpeed_slider = self.findChild(QSlider, "leftFanSpeed_slider")
- self.leftFanSpeed_slider.valueChanged.connect(self.leftFanSpeed_sliderChanged)
+ self.leftFanSpeed_slider = self.findChild(
+ QSlider, "leftFanSpeed_slider")
+ self.leftFanSpeed_slider.valueChanged.connect(
+ self.leftFanSpeed_sliderChanged)
- self.rightFanSpeed_slider = self.findChild(QSlider, "rightFanSpeed_slider")
- self.rightFanSpeed_slider.valueChanged.connect(self.rightFanSpeed_sliderChanged)
+ self.rightFanSpeed_slider = self.findChild(
+ QSlider, "rightFanSpeed_slider")
+ self.rightFanSpeed_slider.valueChanged.connect(
+ self.rightFanSpeed_sliderChanged)
def leftTempListClicked(self):
"""
@@ -101,10 +113,7 @@ class HVACWidget(Base, Form):
Sends the selected temperature value to the feed_kuksa object.
"""
- item = self.leftTempList.currentItem()
- self.leftTempList.scrollToItem(item, 1)
- self.feed_kuksa.send_values(self.HVAC.leftTemp, item.text()[:-2])
- print(item.text())
+ self.setTemperature(self.leftTempList, self.HVAC.leftTemp)
def rightTempListClicked(self):
"""
@@ -112,10 +121,14 @@ class HVACWidget(Base, Form):
Sends the selected temperature value to the feed_kuksa object.
"""
- item = self.rightTempList.currentItem()
- self.rightTempList.scrollToItem(item, 1)
- self.feed_kuksa.send_values(self.HVAC.rightTemp, item.text()[:-2])
- print(item.text())
+ self.setTemperature(self.rightTempList, self.HVAC.rightTemp)
+
+ def setTemperature(self, list_widget, path):
+ item = list_widget.currentItem()
+ if item is not None:
+ list_widget.scrollToItem(item, 1)
+ self.feed_kuksa.send_values(path, item.text()[:-2])
+ print(item.text())
def leftFanSpeed_sliderChanged(self):
"""
@@ -137,6 +150,7 @@ class HVACWidget(Base, Form):
self.feed_kuksa.send_values(self.HVAC.rightFanSpeed, str(value))
print(value)
+
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
diff --git a/Widgets/ICPage.py b/Widgets/ICPage.py
index 2d11cdf..d4d6592 100644
--- a/Widgets/ICPage.py
+++ b/Widgets/ICPage.py
@@ -14,6 +14,7 @@
limitations under the License.
"""
+from extras.FeedKuksa import FeedKuksa
import os
import sys
from PyQt5 import uic, QtCore, QtWidgets
@@ -24,6 +25,7 @@ import time
from PyQt5.QtWidgets import QWidget
from qtwidgets import AnimatedToggle
import threading
+import logging
current_dir = os.path.dirname(os.path.abspath(__file__))
@@ -31,7 +33,6 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.dirname(current_dir))
-from extras.FeedKuksa import FeedKuksa
Form, Base = uic.loadUiType(os.path.join(current_dir, "../ui/IC.ui"))
@@ -65,9 +66,9 @@ class ICWidget(Base, Form):
"""
super(self.__class__, self).__init__(parent)
self.setupUi(self)
-
+
self.IC = IC_Paths()
- #self.vehicle_simulator = VehicleSimulator(self)
+ # self.vehicle_simulator = VehicleSimulator(self)
self.feed_kuksa = FeedKuksa()
self.feed_kuksa.start()
@@ -142,8 +143,10 @@ class ICWidget(Base, Form):
"""
speed = int(self.Speed_slider.value())
self.Speed_monitor.display(speed)
- try: self.feed_kuksa.send_values(self.IC.speed, str(speed), 'value')
- except Exception as e: print(e)
+ try:
+ self.feed_kuksa.send_values(self.IC.speed, str(speed), 'value')
+ except Exception as e:
+ logging.error(f"Error sending values to kuksa {e}")
def update_RPM_monitor(self):
"""
@@ -151,24 +154,31 @@ class ICWidget(Base, Form):
"""
rpm = int(self.RPM_slider.value())
self.RPM_monitor.display(rpm)
- try: self.feed_kuksa.send_values(self.IC.engineRPM, str(rpm), 'value')
- except Exception as e: print(e)
+ try:
+ self.feed_kuksa.send_values(self.IC.engineRPM, str(rpm), 'value')
+ except Exception as e:
+ logging.error(f"Error sending values to kuksa {e}")
def update_coolantTemp_monitor(self):
"""
Updates the coolant temperature monitor with the current coolant temperature value.
"""
coolantTemp = int(self.coolantTemp_slider.value())
- try: self.feed_kuksa.send_values(self.IC.coolantTemp, str(coolantTemp), 'value')
- except Exception as e: print(e)
+ try:
+ self.feed_kuksa.send_values(
+ self.IC.coolantTemp, str(coolantTemp), 'value')
+ except Exception as e:
+ logging.error(f"Error sending values to kuksa {e}")
def update_fuelLevel_monitor(self):
"""
Updates the fuel level monitor with the current fuel level value.
"""
fuelLevel = int(self.fuelLevel_slider.value())
- try: self.feed_kuksa.send_values(self.IC.fuelLevel, str(fuelLevel))
- except Exception as e: print(e)
+ try:
+ self.feed_kuksa.send_values(self.IC.fuelLevel, str(fuelLevel))
+ except Exception as e:
+ logging.error(f"Error sending values to kuksa {e}")
def hazardBtnClicked(self):
"""
@@ -192,13 +202,12 @@ class ICWidget(Base, Form):
self.leftIndicatorBtn.setChecked(self.hazardBtn.isChecked())
self.rightIndicatorBtn.setChecked(self.hazardBtn.isChecked())
- try:
+ try:
self.feed_kuksa.send_values(self.IC.leftIndicator, value)
self.feed_kuksa.send_values(self.IC.rightIndicator, value)
self.feed_kuksa.send_values(self.IC.hazard, value)
except Exception as e:
- print(e)
-
+ logging.error(f"Error sending values to kuksa {e}")
def leftIndicatorBtnClicked(self):
"""
@@ -219,8 +228,10 @@ class ICWidget(Base, Form):
painter.end()
self.leftIndicatorBtn.setIcon(QIcon(leftIndicatorIcon))
- try: self.feed_kuksa.send_values(self.IC.leftIndicator, value)
- except Exception as e: print(e)
+ try:
+ self.feed_kuksa.send_values(self.IC.leftIndicator, value)
+ except Exception as e:
+ logging.error(f"Error sending values to kuksa {e}")
def rightIndicatorBtnClicked(self):
"""
@@ -241,11 +252,10 @@ class ICWidget(Base, Form):
painter.end()
self.rightIndicatorBtn.setIcon(QIcon(rightIndicatorIcon))
- try:
+ try:
self.feed_kuksa.send_values(self.IC.rightIndicator, value)
except Exception as e:
- print(e)
-
+ logging.error(f"Error sending values to kuksa {e}")
def accelerationBtnPressed(self):
"""
@@ -309,9 +319,9 @@ class ICWidget(Base, Form):
self.reverseBtn: "-1",
self.neutralBtn: "0"
}
-
+
checked_button = self.driveGroupBtns.checkedButton()
-
+
if checked_button in gear_mapping:
gear_value = gear_mapping[checked_button]
self.accelerationBtn.setEnabled(True)
@@ -320,10 +330,11 @@ class ICWidget(Base, Form):
try:
self.feed_kuksa.send_values(self.IC.selectedGear, gear_value)
except Exception as e:
- print(e)
+ logging.error(f"Error sending values to kuksa {e}")
else:
print("Unknown button checked!")
+
class AccelerationFns():
def calculate_speed(time, acceleration) -> int:
# acceleration = 60 / 5 # acceleration from 0 to 60 in 5 seconds
@@ -353,7 +364,8 @@ class AccelerationFns():
engine_rpm = wheel_rps * gear_ratios[current_gear - 1] * 60
return int(engine_rpm)
-
+
+
class VehicleSimulator(QObject):
# Define signals for updating speed and rpm
speed_changed = pyqtSignal(int)
@@ -399,11 +411,11 @@ class VehicleSimulator(QObject):
self.brake(40, 2000, 4)
self.accelerate(90, 3000, 5)
self.brake(1, 650, 5)
-
+
# Ensure reset is called when not in cruise mode
if not self.running:
self.reset()
-
+
time.sleep(5)
def accelerate(self, target_speed, target_rpm, duration):
@@ -432,19 +444,19 @@ class VehicleSimulator(QObject):
self.rpm_changed.emit(int(self.engine_speed))
time.sleep(1 / self.freq)
- def increase(self, bycruise = True):
+ def increase(self, bycruise=True):
if self.CRUISEACTIVE:
target_speed = self.vehicle_speed + 5
target_rpm = self.engine_speed * 1.1
self.accelerate(target_speed, target_rpm, 2, bycruise)
- def decrease(self, bycruise = True):
+ def decrease(self, bycruise=True):
if self.CRUISEACTIVE:
target_speed = self.vehicle_speed - 5
target_rpm = self.engine_speed * 0.9
self.brake(target_speed, target_rpm, 2, bycruise)
- def resume(self, bycruise = True):
+ def resume(self, bycruise=True):
target_speed = self.CRUISESPEED
target_rpm = self.CRUISERPM
current_speed = self.get_vehicle_speed()
@@ -453,8 +465,9 @@ class VehicleSimulator(QObject):
else:
self.brake(target_speed, target_rpm, 2, bycruise)
+
if __name__ == '__main__':
app = QApplication(sys.argv)
w = ICWidget()
w.show()
- sys.exit(app.exec_()) \ No newline at end of file
+ sys.exit(app.exec_())
diff --git a/Widgets/SteeringCtrlPage.py b/Widgets/SteeringCtrlPage.py
index de3585d..a610f9b 100644
--- a/Widgets/SteeringCtrlPage.py
+++ b/Widgets/SteeringCtrlPage.py
@@ -14,6 +14,9 @@
limitations under the License.
"""
+from . import settings
+import extras.FeedCAN as feed_can
+from extras.FeedKuksa import FeedKuksa
import os
import sys
from PyQt5 import uic
@@ -25,78 +28,78 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.dirname(current_dir))
-from extras.FeedKuksa import FeedKuksa
-import extras.FeedCAN as feed_can
-from . import settings
-Form, Base = uic.loadUiType(os.path.join(current_dir, "../ui/SteeringControls.ui"))
+Form, Base = uic.loadUiType(os.path.join(
+ current_dir, "../ui/SteeringControls.ui"))
# ========================================
+
class Steering_Paths():
def __init__(self):
self.switches = {
"VolumeUp": {
- "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.VolumeUp",
+ "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.VolumeUp",
"CAN": "021#FFFFFFFF40000000"},
"VolumeDown": {
- "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.VolumeDown",
+ "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.VolumeDown",
"CAN": "021#FFFFFFFF10000000"},
"VolumeMute": {
- "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.VolumeMute",
+ "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.VolumeMute",
"CAN": "021#FFFFFFFF01000000"},
"Mode": {
- "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.Mode",
+ "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.Mode",
"CAN": "021#FFFFFFFF20000000"},
"NextTrack": {
- "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.Next",
+ "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.Next",
"CAN": "021#FFFFFFFF08000000"},
"PreviousTrack": {
- "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.Previous",
+ "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.Previous",
"CAN": "021#FFFFFFFF80000000"},
"Info": {
- "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.Info",
+ "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.Info",
"CAN": "021#FFFFFFFF02000000"},
"PhoneCall": {
- "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.PhoneCall",
+ "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.PhoneCall",
"CAN": "021#FFFFFFFF00010000"},
"PhoneHangup": {
- "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.PhoneHangup",
+ "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.PhoneHangup",
"CAN": "021#FFFFFFFF00020000"},
"Voice": {
- "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.Voice",
+ "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.Voice",
"CAN": "021#FFFFFFFF00040000"},
"LaneDeparture": {
- "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.LaneDepartureWarning",
+ "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.LaneDepartureWarning",
"CAN": "021#FFFFFFFF00000001"},
"Horn": {
- "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.Horn",
+ "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.Horn",
"CAN": "021#FFFFFFFF00000080"},
"CruiseEnable": {
- "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.CruiseEnable",
+ "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.CruiseEnable",
"CAN": "021#FFFFFFFF00008000"},
"CruiseSet": {
- "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.CruiseSet",
+ "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.CruiseSet",
"CAN": "021#FFFFFFFF00001000"},
"CruiseResume": {
- "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.CruiseResume",
+ "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.CruiseResume",
"CAN": "021#FFFFFFFF00004000"},
"CruiseCancel": {
- "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.CruiseCancel",
+ "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.CruiseCancel",
"CAN": "021#FFFFFFFF00000800"},
"CruiseLimit": {
- "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.CruiseLimit",
+ "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.CruiseLimit",
"CAN": "021#FFFFFFFF00000200"},
"CruiseDistance": {
- "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.CruiseDistance",
+ "Kuksa": "Vehicle.Cabin.SteeringWheel.Switches.CruiseDistance",
"CAN": "021#FFFFFFFF00000100"}
}
-
+
+
class SteeringCtrlWidget(Base, Form):
def __init__(self, parent=None):
super(self.__class__, self).__init__(parent)
self.setupUi(self)
-
+
self.Steering = Steering_Paths()
self.feed_kuksa = FeedKuksa()
self.settings = settings
@@ -113,9 +116,9 @@ class SteeringCtrlWidget(Base, Form):
self.NextTrack,
self.PreviousTrack,
self.Info,
- self.PhoneCall,
+ self.PhoneCall,
self.PhoneHangup,
- self.Voice,
+ self.Voice,
self.LaneDeparture,
self.Horn,
self.CruiseEnable,
@@ -136,16 +139,20 @@ class SteeringCtrlWidget(Base, Form):
button_clicked = button.objectName()
signal_type = settings.Steering_Signal_Type
if signal_type == "Kuksa":
- self.feed_kuksa.send_values(self.Steering.switches[button_clicked]["Kuksa"], "1")
- self.feed_kuksa.send_values(self.Steering.switches[button_clicked]["Kuksa"], "0")
+ self.feed_kuksa.send_values(
+ self.Steering.switches[button_clicked]["Kuksa"], "1")
+ self.feed_kuksa.send_values(
+ self.Steering.switches[button_clicked]["Kuksa"], "0")
elif signal_type == "CAN":
- feed_can.send_can_signal(self.Steering.switches[button_clicked]["CAN"])
+ feed_can.send_can_signal(
+ self.Steering.switches[button_clicked]["CAN"])
# Making sure button state goes back to off
feed_can.send_can_signal("021#FFFFFFFF00000000")
+
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
w = SteeringCtrlWidget()
w.show()
- sys.exit(app.exec_()) \ No newline at end of file
+ sys.exit(app.exec_())
diff --git a/Widgets/settings.py b/Widgets/settings.py
index a7820fc..f1eed41 100644
--- a/Widgets/settings.py
+++ b/Widgets/settings.py
@@ -13,6 +13,8 @@
# limitations under the License.
+from extras import config
+import extras.Kuksa_Instance as kuksa_instance
import os
import sys
import time
@@ -31,8 +33,6 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.dirname(current_dir))
-import extras.Kuksa_Instance as kuksa_instance
-from extras import config
Form, Base = uic.loadUiType(os.path.join(
current_dir, "../ui/Settings_Window.ui"))
@@ -41,12 +41,14 @@ Form, Base = uic.loadUiType(os.path.join(
Steering_Signal_Type = "Kuksa"
+
def create_animated_toggle():
return AnimatedToggle(
checked_color="#4BD7D6",
pulse_checked_color="#00ffff",
)
+
class settings(Base, Form):
"""
A class representing the settings widget of the AGL Demo Control Panel.
@@ -61,14 +63,14 @@ class settings(Base, Form):
- refreshBtn: A QPushButton object representing the refresh button.
- startClientBtn: A QPushButton object representing the start client button.
"""
-
+
def __init__(self, parent=None):
"""
Initializes the settings widget of the AGL Demo Control Panel.
"""
super(self.__class__, self).__init__(parent)
self.setupUi(self)
-
+
self.SSL_toggle = create_animated_toggle()
self.Protocol_toggle = create_animated_toggle()
self.CAN_Kuksa_toggle = create_animated_toggle()
@@ -79,11 +81,13 @@ class settings(Base, Form):
list_of_configs = config.get_list_configs()
default_config_name = config.get_default_config()
- self.List_Configs_ComboBox = self.findChild(QComboBox, "List_Configs_ComboBox")
+ self.List_Configs_ComboBox = self.findChild(
+ QComboBox, "List_Configs_ComboBox")
self.List_Configs_ComboBox.setItemDelegate(QStyledItemDelegate())
self.List_Configs_ComboBox.addItems(list_of_configs)
self.List_Configs_ComboBox.setCurrentText(default_config_name)
- self.List_Configs_ComboBox.currentTextChanged.connect(lambda: self.set_settings(self.List_Configs_ComboBox.currentText()))
+ self.List_Configs_ComboBox.currentTextChanged.connect(
+ lambda: self.set_settings(self.List_Configs_ComboBox.currentText()))
self.IPAddrInput = self.findChild(QLineEdit, "IPAddrInput")
self.PortInput = self.findChild(QLineEdit, "PortInput")
@@ -99,16 +103,18 @@ class settings(Base, Form):
self.reconnectBtn.clicked.connect(self.reconnectClient)
self.SSL_toggle.clicked.connect(self.toggleSSL)
self.CAN_Kuksa_toggle.clicked.connect(self.toggle_CAN_Kuksa)
-
+
Frame_GS = self.findChild(QWidget, "frame_general_settings")
Frame_PS = self.findChild(QWidget, "frame_page_settings")
GS_layout = Frame_GS.layout()
PS_layout = Frame_PS.layout()
-
+
GS_layout.replaceWidget(self.place_holder_toggle_1, self.SSL_toggle)
- GS_layout.replaceWidget(self.place_holder_toggle_2, self.Protocol_toggle)
- PS_layout.replaceWidget(self.place_holder_toggle_3, self.CAN_Kuksa_toggle)
-
+ GS_layout.replaceWidget(
+ self.place_holder_toggle_2, self.Protocol_toggle)
+ PS_layout.replaceWidget(
+ self.place_holder_toggle_3, self.CAN_Kuksa_toggle)
+
self.place_holder_toggle_1.deleteLater()
self.place_holder_toggle_2.deleteLater()
self.place_holder_toggle_3.deleteLater()
@@ -121,7 +127,8 @@ class settings(Base, Form):
self.set_instance()
if self.client is not None:
self.startClientBtn.setStyleSheet("border: 1px solid red;")
- self.startClientBtn.setIcon(QtGui.QIcon(":/Carbon_Icons/carbon_icons/stop.svg"))
+ self.startClientBtn.setIcon(QtGui.QIcon(
+ ":/Carbon_Icons/carbon_icons/stop.svg"))
self.startClientBtn.setText("Stop Client")
else:
self.startClientBtn.setChecked(False)
@@ -131,9 +138,9 @@ class settings(Base, Form):
self.client.stop()
self.startClientBtn.setStyleSheet("border: 1px solid green;")
- self.startClientBtn.setIcon(QtGui.QIcon(":/Carbon_Icons/carbon_icons/play.svg"))
+ self.startClientBtn.setIcon(QtGui.QIcon(
+ ":/Carbon_Icons/carbon_icons/play.svg"))
self.startClientBtn.setText("Start Client")
-
def toggleSSL(self):
"""
@@ -150,7 +157,8 @@ class settings(Base, Form):
if (self.CAN_Kuksa_toggle.isChecked()):
# check if can0 is available
try:
- can_bus = can.interface.Bus(channel='can0', bustype='socketcan_native')
+ can_bus = can.interface.Bus(
+ channel='can0', bustype='socketcan_native')
can_bus.shutdown()
Steering_Signal_Type = "CAN"
except:
@@ -193,13 +201,15 @@ class settings(Base, Form):
if (self.client is None):
self.connectionStatus.setText('Not Connected')
self.connectionLogo.setStyleSheet("background-color: red")
- self.connectionLogo.setPixmap(QtGui.QPixmap(":/Carbon_Icons/carbon_icons/connection-signal--off.svg"))
+ self.connectionLogo.setPixmap(QtGui.QPixmap(
+ ":/Carbon_Icons/carbon_icons/connection-signal--off.svg"))
return None
if (self.client.checkConnection() == True):
self.connectionStatus.setText('Connected')
self.connectionLogo.setStyleSheet("background-color: green")
- self.connectionLogo.setPixmap(QtGui.QPixmap(":/Carbon_Icons/carbon_icons/connection-signal.svg"))
+ self.connectionLogo.setPixmap(QtGui.QPixmap(
+ ":/Carbon_Icons/carbon_icons/connection-signal.svg"))
self.client.start()
return True
@@ -207,7 +217,8 @@ class settings(Base, Form):
self.client.stop()
self.connectionStatus.setText('Disconnected')
self.connectionLogo.setStyleSheet("background-color: yellow")
- self.connectionLogo.setPixmap(QtGui.QPixmap(":/Carbon_Icons/carbon_icons/connection-signal--off.svg"))
+ self.connectionLogo.setPixmap(QtGui.QPixmap(
+ ":/Carbon_Icons/carbon_icons/connection-signal--off.svg"))
return False
except:
pass
@@ -240,7 +251,8 @@ class settings(Base, Form):
text = widget.text()
if text:
if os.path.exists(text):
- widget.setStyleSheet("border: 1px solid #4BD7D6 ; /* light blue */")
+ widget.setStyleSheet(
+ "border: 1px solid #4BD7D6 ; /* light blue */")
if key:
self.new_config[key] = text
else:
@@ -248,18 +260,19 @@ class settings(Base, Form):
else:
widget.setStyleSheet("border: 1px solid red;")
return None
-
+
new_config = {}
new_config["ip"] = self.IPAddrInput.text()
new_config["port"] = self.PortInput.text()
new_config["protocol"] = self.get_protocol()
new_config["insecure"] = not self.SSL_toggle.isChecked()
- new_config["tls_server_name"] = self.TLS_Server_Name.text() if self.Protocol_toggle.isChecked() else None
+ new_config["tls_server_name"] = self.TLS_Server_Name.text(
+ ) if self.Protocol_toggle.isChecked() else None
validate_and_set_style(self, self.CA_File, "cacertificate")
validate_and_set_style(self, self.Auth_Token)
return new_config
-
+
def set_settings(self, config_name):
"""
Reloads the parameters of settings widget.
@@ -272,11 +285,14 @@ class settings(Base, Form):
self.IPAddrInput.setText(self.kuksa_config["ip"])
self.PortInput.setText(self.kuksa_config["port"])
self.SSL_toggle.setChecked(not self.kuksa_config["insecure"])
- self.Protocol_toggle.setChecked(self.kuksa_config["protocol"] == 'grpc')
+ self.Protocol_toggle.setChecked(
+ self.kuksa_config["protocol"] == 'grpc')
self.CA_File.setText(self.kuksa_config["cacertificate"])
- self.TLS_Server_Name.setText(self.kuksa_config["tls_server_name"] if self.kuksa_config["tls_server_name"] is not None else "")
+ self.TLS_Server_Name.setText(
+ self.kuksa_config["tls_server_name"] if self.kuksa_config["tls_server_name"] is not None else "")
self.Auth_Token.setText(self.kuksa_token)
+
class RefreshThread(QThread):
def __init__(self, settings):
QThread.__init__(self)
@@ -286,6 +302,7 @@ class RefreshThread(QThread):
time.sleep(2)
self.settings.refreshStatus()
+
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)