Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ mLRSFlasher is based on Python, and thus needs a full Python3 installation on yo

- Install Python3 on your system, if you don't yet have it. Ensure that Python is in the PATH (the usual Python installation tutorials tell how to check that).
- Download the github repo and ensure you have unpacked it if you downloaded it as zip.
- Run the mLRS_Flasher.py script.
- It may happen that you get a bunch of errors and need to install additional packages. Follow the error messages.
- Run ```mLRS_Flasher.py```.

> [!NOTE]
> - The first launch will take approximately 1 minute as the virtual environment is being created.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe

  • On first launch the start can take approximately 1 minute as a virtual environment is being created and some libraries are installed (don't worry, doesn't affect your system). An internet connection is needed.


### MacOS ###

Expand All @@ -31,13 +33,21 @@ pip install virtualenv
#### Run the Flasher ####

````
./run_mLRS_Flasher_mac.py
Run ```./mLRS_Flasher.py```.
````

> [!NOTE]
> - The first launch will take approximately 1 minute as the virtual environment is being created.
> - If you see a blank screen on the first launch, try closing and running ```./mLRS_Flasher_.py``` again.

### Linux ###

TBD
````
Run ```./mLRS_Flasher.py```.
````

> [!NOTE]
> - The first launch will take approximately 1 minute as the virtual environment is being created.

## Disclaimer ##

Expand Down
File renamed without changes.
40 changes: 40 additions & 0 deletions archive/run_mLRS_Flasher_win.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python
#*******************************************************
# Copyright (c) MLRS project
# GPL3
# https://www.gnu.org/licenses/gpl-3.0.de.html
#*******************************************************
# Win Launcher
#********************************************************

import subprocess
import os

def setup_virtualenv():
"""Creates and sets up a virtual environment using venv."""
# Create virtual environment
subprocess.run(["python", "-m", "venv", "venv"], check=True)
print("Virtual environment created.")

# Upgrade pip
subprocess.run(["venv\\Scripts\\python", "-m", "pip", "install", "--upgrade", "pip"], check=True)
print("Pip upgraded.")

# Install required modules
subprocess.run(["venv\\Scripts\\python", "-m", "pip", "install", "pillow", "requests", "pyserial", "customtkinter", "tk"], check=True)
print("Required modules installed.")

def run_flasher():
"""Runs the mLRS_Flasher.py script within the virtual environment."""
subprocess.run(["venv\\Scripts\\pythonw", "mLRS_Flasher.py"], check=True)
print("mLRS_Flasher.py executed successfully.")

if __name__ == "__main__":
# Check if venv folder exists before running run_flasher
if os.path.isdir("venv"):
print("Virtual environment found, running flasher script...")
run_flasher()
else:
print("Virtual environment not found. Setting up virtual environment...")
setup_virtualenv()
run_flasher()
79 changes: 76 additions & 3 deletions mLRS_Flasher.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
# OlliW @ www.olliw.eu
#************************************************************
# mLRS Flasher Desktop App
# 11. Apr. 2025 001
# 13. Apr. 2025 001
#************************************************************
app_version = '11.04.2025-001'
app_version = '13.04.2025-001'

import os, sys, time
import os, platform, sys, time
import subprocess
import re

Expand All @@ -29,6 +29,69 @@
import apInitPassthru as appassthru
import edgetxInitPassthru as radio

'''
Copy link
Copy Markdown
Owner

@olliw42 olliw42 Apr 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I would like to have the venev section be moved to the last before the if main

--------------------------------------------------
Venv
--------------------------------------------------
'''

def setup_virtualenv_win():
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems to me that the three can be largely slimmed down to essentially only one
if. e.g. one would set a variable
python_exe = os.path.join('venv','Scripts','python') or python_exe = os.path.join('venv','bin','python')
and use that.
Siedeffect is that I btw also very much like using os.path.join better when possible as it really helps to avoid the / vs \ thing.
the functions could have then an argument, or you do it in that function itself

pl don't use """ or ''' for inline comments (I often use that to uncomment blocks and it just makes things screwy)

"""Creates and sets up a virtual environment using venv."""
# Create virtual environment
subprocess.run(["python", "-m", "venv", "venv"], check=True)
print("Virtual environment created.")

# Upgrade pip
subprocess.run(["venv\\Scripts\\python", "-m", "pip", "install", "--upgrade", "pip"], check=True)
print("Pip upgraded.")

# Install required modules
subprocess.run(["venv\\Scripts\\python", "-m", "pip", "install", "pillow", "requests", "pyserial", "customtkinter", "tk"], check=True)
print("Required modules installed.")

def setup_virtualenv_mac():
"""Recursively removes the quarantine attribute from all files in the given directory."""
for root, dirs, files in os.walk(os.getcwd()):
for name in dirs + files:
file_path = os.path.join(root, name)
try:
subprocess.run(["xattr", "-d", "com.apple.quarantine", file_path], check=True, stderr=subprocess.DEVNULL)
print(f"Removed quarantine from: {file_path}")
except subprocess.CalledProcessError:
print(f"Failed to remove quarantine from: {file_path}")

"""Creates and sets up a virtual environment using virtualenv."""
subprocess.run(["virtualenv", "--python=/opt/homebrew/bin/python3", "venv"], check=True)
print("Virtual environment created using Homebrew's Python.")

subprocess.run(["venv/bin/python", "-m", "pip", "install", "--upgrade", "pip"], check=True)
print("Pip upgraded.")

subprocess.run(["venv/bin/python", "-m", "pip", "install", "pillow", "requests", "pyserial", "customtkinter", "tk"], check=True)
print("Required modules installed including Tkinter in virtual environment.")

subprocess.run(["brew", "install", "python-tk"], check=True)
print("python-tk installed via Homebrew.")

def setup_virtualenv_linux():
"""Creates and sets up a virtual environment using venv on Linux."""
# Create virtual environment
subprocess.run(["python3", "-m", "venv", "venv"], check=True)
print("Virtual environment created.")

# Upgrade pip
subprocess.run(["venv/bin/python", "-m", "pip", "install", "--upgrade", "pip"], check=True)
print("Pip upgraded.")

# Install required modules
subprocess.run(["venv/bin/python", "-m", "pip", "install", "pillow", "requests", "pyserial", "customtkinter", "tk"], check=True)
print("Required modules installed.")

'''
--------------------------------------------------
Tools
--------------------------------------------------
'''

ctk.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
#ctk.set_default_color_theme("green")
Expand Down Expand Up @@ -1914,6 +1977,16 @@ def fLuaScript_Download_button_event(self):
#--------------------------------------------------

if __name__ == "__main__":
if os.path.isdir("venv"):
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a if not os.path.dir('venv') is sufficient

(btw I prefer using '' over "" when possible)

print("Virtual environment found, running flasher script...")
else:
if platform.system() == 'Windows':
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we please separate that by os.name == 'posix' and then do the subselection using platform.system()

reason is that in other parts of the code it splices by os.name, want to keep it coherent

setup_virtualenv_win()
elif platform.system() == 'Darwin':
setup_virtualenv_mac()
elif platform.system() == 'Linux':
setup_virtualenv_linux()

app = App()
app.update()
app.after(10,app.after_startup())
Expand Down