diff --git a/main.py b/main.py index e666641..1429306 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,8 @@ from tkinter import ttk import ttkbootstrap as ttks from enum import Enum, auto -from msfs_lights import AirplaneLights, get_airplane_light_values, set_airplane_light_value, get_airplane_altitude, is_night, is_on_ground +from msfs_lights import AirplaneLights, get_airplane_light_values, set_airplane_light_value, get_airplane_altitude, \ + is_night, is_on_ground import logging # ---- See License at bottom of file ---- @@ -24,6 +25,7 @@ checkbox_vars = [] +# update the checkbox/lights based on environment def update_checkboxes_and_lights(): if not script_enabled: return @@ -34,6 +36,7 @@ def update_checkboxes_and_lights(): taxi_lights_enabled = is_on_ground() and is_night() altitude = get_airplane_altitude() + # this line does not work need to change the comparison landing_lights_enabled = altitude < 10000 and not is_night() and not is_on_ground() set_airplane_light_value(AirplaneLights.CABIN, cabin_lights_enabled) @@ -42,12 +45,13 @@ def update_checkboxes_and_lights(): for i, light in enumerate(AirplaneLights): checkbox_vars[i].set(light_values[light.name]) - - checkbox_vars[AirplaneLights.LANDING.value].set(landing_lights_enabled) + checkbox_vars[AirplaneLights.LANDING.value].set(landing_lights_enabled) # Schedule the next update in 1000 ms (1 second) root.after(1000, update_checkboxes_and_lights) + +# used to turn the script on & off def toggle_script(): global script_enabled script_enabled = not script_enabled @@ -57,12 +61,15 @@ def toggle_script(): if script_enabled: update_checkboxes_and_lights() + +# create checkbox grid def create_checkbox_grid(root): row, column = 0, 0 for light in AirplaneLights: chk_var = tk.BooleanVar() checkbox_vars.append(chk_var) - chk = ttk.Checkbutton(root, text=light.name, variable=chk_var, command=lambda var=chk_var: on_checkbox_click(var)) + chk = ttk.Checkbutton(root, text=light.name, variable=chk_var, + command=lambda var=chk_var: on_checkbox_click(var)) chk.grid(row=row, column=column, padx=5, pady=5, sticky="w") column += 1 @@ -72,11 +79,12 @@ def create_checkbox_grid(root): global toggle_button toggle_button = ttk.Button(root, text="Enable Script", command=toggle_script) - toggle_button.grid(row=row+1, column=1, pady=10, sticky="w") + toggle_button.grid(row=row + 1, column=1, pady=10, sticky="w") copyright_label = ttk.Label(root, text="Copyright 2023 - Jeremy Stevens", font=("Arial", 8)) - copyright_label.grid(row=row+2, column=1, pady=(0, 5), sticky="w") + copyright_label.grid(row=row + 2, column=1, pady=(0, 5), sticky="w") +# main entry point def main(): global root root = tk.Tk() @@ -88,33 +96,32 @@ def main(): create_checkbox_grid(root) root.mainloop() + if __name__ == "__main__": main() - - # --------- license info ---------------------------------------------------# -#MIT License +# MIT License -#Copyright (c) 2023 - Jeremy Stevens +# Copyright (c) 2023 - Jeremy Stevens -#Permission is hereby granted, free of charge, to any person obtaining a copy -#of this software and associated documentation files (the "Software"), to deal -#in the Software without restriction, including without limitation the rights -#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -#copies of the Software, and to permit persons to whom the Software is -#furnished to do so, subject to the following conditions: +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: -#The above copyright notice and this permission notice shall be included in all -#copies or substantial portions of the Software. +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. -#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -#SOFTWARE. +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. -# -------------------- end of license info --------------------------------------- \ No newline at end of file +# -------------------- end of license info --------------------------------------- diff --git a/msfs_lights.py b/msfs_lights.py index 4a6256a..4e43de0 100644 --- a/msfs_lights.py +++ b/msfs_lights.py @@ -1,6 +1,7 @@ from SimConnect import * from enum import Enum + # ---- See License at bottom of file ---- class AirplaneLights(Enum): @@ -14,6 +15,7 @@ class AirplaneLights(Enum): RUNWAY_TURN_OFF = "RUNWAY TURN OFF LIGHTS" RECOGNITION = "RECOGNITION LIGHTS" + # get IS_NIGHT from simconnect def is_night(): sm = SimConnect() @@ -22,6 +24,7 @@ def is_night(): sm.exit() return results +# get the airplanes current altitude def get_airplane_altitude(): sm = SimConnect() aq = AircraftRequests(sm) @@ -29,6 +32,7 @@ def get_airplane_altitude(): sm.exit() return altitude +# check if the plane is on the ground def is_on_ground(): sm = SimConnect() aq = AircraftRequests(sm) @@ -36,7 +40,7 @@ def is_on_ground(): sm.exit() return on_ground - +# get time in Zulu * not used but leaving it for now * def get_msfs_time_of_day(): sm = SimConnect() aq = AircraftRequests(sm) @@ -44,15 +48,7 @@ def get_msfs_time_of_day(): sm.exit() return zulu_time - -def get_airplane_altitude(): - sm = SimConnect() - aq = AircraftRequests(sm) - altitude = aq.get("PLANE_ALTITUDE") - sm.exit() - return altitude - - +# set the airplane lights ON/OFF def set_airplane_light_value(light: AirplaneLights, value: bool): sm = SimConnect() aq = AircraftRequests(sm) @@ -75,7 +71,7 @@ def set_airplane_light_value(light: AirplaneLights, value: bool): aq.set("LIGHT RECOGNITION ON", int(value)) sm.exit() - +# get the airplanes lights value (ON/OFF) def get_airplane_light_values(): # Establish a connection to the simulator sm = SimConnect() @@ -91,26 +87,26 @@ def get_airplane_light_values(): # --------- license info ---------------------------------------------------# -#MIT License +# MIT License -#Copyright (c) 2023 - Jeremy Stevens +# Copyright (c) 2023 - Jeremy Stevens -#Permission is hereby granted, free of charge, to any person obtaining a copy -#of this software and associated documentation files (the "Software"), to deal -#in the Software without restriction, including without limitation the rights -#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -#copies of the Software, and to permit persons to whom the Software is -#furnished to do so, subject to the following conditions: +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: -#The above copyright notice and this permission notice shall be included in all -#copies or substantial portions of the Software. +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. -#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -#SOFTWARE. +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. -# -------------------- end of license info --------------------------------------- \ No newline at end of file +# -------------------- end of license info ---------------------------------------