forked from MarlinFirmware/Marlin
-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚸 Firmware upload destination prompt (using Tk) (MarlinFirmware#24074)
- Loading branch information
1 parent
15b6159
commit c1ff38c
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
buildroot/share/PlatformIO/scripts/upload_prompt_extra_script.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# | ||
# upload_prompt_extra_script.py | ||
# set the output_port | ||
# | ||
from __future__ import print_function | ||
|
||
has_tkinter = False | ||
try: | ||
import sys | ||
if sys.version_info[0] < 3: | ||
import Tkinter as tk | ||
import tkFileDialog as fileDialog | ||
from Tkinter import Tk | ||
else: | ||
import tkinter as tk | ||
from tkinter import Tk | ||
from tkinter import filedialog as fileDialog | ||
has_tkinter = True | ||
except: | ||
pass | ||
|
||
import pioutil | ||
if has_tkinter and pioutil.is_pio_build(): | ||
|
||
Import("env") | ||
|
||
def print_error(e): | ||
print('\nUnable to find destination disk (%s)\n' %( e ) ) | ||
|
||
def before_upload(source, target, env): | ||
# | ||
# Find a disk for upload | ||
# | ||
upload_disk = '' | ||
|
||
root = Tk() # pointing root to Tk() to use it as Tk() in program. | ||
root.withdraw() # Hides small tkinter window. | ||
|
||
root.attributes('-topmost', True) # Opened windows will be active. above all windows despite of selection. | ||
|
||
upload_disk = fileDialog.askdirectory(title="Select the root of your SDCARD") # Returns opened path as str | ||
if not upload_disk: | ||
print_error('Canceled') | ||
return | ||
else: | ||
env.Replace( | ||
UPLOAD_FLAGS="-P$UPLOAD_PORT" | ||
) | ||
env.Replace(UPLOAD_PORT=upload_disk) | ||
print('\nUpload disk: ', upload_disk, '\n') | ||
|
||
env.AddPreAction("upload", before_upload) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters