Skip to content

Commit

Permalink
removed duplicate function & added function descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystevens committed Apr 3, 2023
1 parent 511180b commit ad0cf18
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 55 deletions.
59 changes: 33 additions & 26 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----
Expand All @@ -24,6 +25,7 @@
checkbox_vars = []


# update the checkbox/lights based on environment
def update_checkboxes_and_lights():
if not script_enabled:
return
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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 ---------------------------------------
# -------------------- end of license info ---------------------------------------
54 changes: 25 additions & 29 deletions msfs_lights.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from SimConnect import *
from enum import Enum


# ---- See License at bottom of file ----

class AirplaneLights(Enum):
Expand All @@ -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()
Expand All @@ -22,37 +24,31 @@ def is_night():
sm.exit()
return results

# get the airplanes current altitude
def get_airplane_altitude():
sm = SimConnect()
aq = AircraftRequests(sm)
altitude = aq.get("PLANE ALTITUDE")
sm.exit()
return altitude

# check if the plane is on the ground
def is_on_ground():
sm = SimConnect()
aq = AircraftRequests(sm)
on_ground = aq.get("SIM_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)
zulu_time = aq.get("ZULU_TIME")
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)
Expand All @@ -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()
Expand All @@ -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 ---------------------------------------
# -------------------- end of license info ---------------------------------------

0 comments on commit ad0cf18

Please sign in to comment.