My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

auto_build.py 44KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  1. #!/usr/bin/env python
  2. #######################################
  3. #
  4. # Marlin 3D Printer Firmware
  5. # Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  6. #
  7. # Based on Sprinter and grbl.
  8. # Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  9. #
  10. # This program is free software: you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation, either version 3 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU General Public License
  21. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. #
  23. #######################################
  24. #######################################
  25. #
  26. # Revision: 2.1.0
  27. #
  28. # Description: script to automate PlatformIO builds
  29. # CLI: python auto_build.py build_option
  30. # build_option (required)
  31. # build executes -> platformio run -e target_env
  32. # clean executes -> platformio run --target clean -e target_env
  33. # upload executes -> platformio run --target upload -e target_env
  34. # traceback executes -> platformio run --target upload -e target_env
  35. # program executes -> platformio run --target program -e target_env
  36. # test executes -> platformio test upload -e target_env
  37. # remote executes -> platformio remote run --target upload -e target_env
  38. # debug executes -> platformio debug -e target_env
  39. #
  40. # 'traceback' just uses the debug variant of the target environment if one exists
  41. #
  42. #######################################
  43. #######################################
  44. #
  45. # General program flow
  46. #
  47. # 1. Scans Configuration.h for the motherboard name and Marlin version.
  48. # 2. Scans pins.h for the motherboard.
  49. # returns the CPU(s) and platformio environment(s) used by the motherboard
  50. # 3. If further info is needed then a popup gets it from the user.
  51. # 4. The OUTPUT_WINDOW class creates a window to display the output of the PlatformIO program.
  52. # 5. A thread is created by the OUTPUT_WINDOW class in order to execute the RUN_PIO function.
  53. # 6. The RUN_PIO function uses a subprocess to run the CLI version of PlatformIO.
  54. # 7. The "iter(pio_subprocess.stdout.readline, '')" function is used to stream the output of
  55. # PlatformIO back to the RUN_PIO function.
  56. # 8. Each line returned from PlatformIO is formatted to match the color coding seen in the
  57. # PlatformIO GUI.
  58. # 9. If there is a color change within a line then the line is broken at each color change
  59. # and sent separately.
  60. # 10. Each formatted segment (could be a full line or a split line) is put into the queue
  61. # IO_queue as it arrives from the platformio subprocess.
  62. # 11. The OUTPUT_WINDOW class periodically samples IO_queue. If data is available then it
  63. # is written to the window.
  64. # 12. The window stays open until the user closes it.
  65. # 13. The OUTPUT_WINDOW class continues to execute as long as the window is open. This allows
  66. # copying, saving, scrolling of the window. A right click popup is available.
  67. #
  68. #######################################
  69. from __future__ import print_function
  70. from __future__ import division
  71. import sys
  72. import os
  73. pwd = os.getcwd() # make sure we're executing from the correct directory level
  74. pwd = pwd.replace('\\', '/')
  75. if 0 <= pwd.find('buildroot/share/atom'):
  76. pwd = pwd[:pwd.find('buildroot/share/atom')]
  77. os.chdir(pwd)
  78. print('pwd: ', pwd)
  79. num_args = len(sys.argv)
  80. if num_args > 1:
  81. build_type = str(sys.argv[1])
  82. else:
  83. print('Please specify build type')
  84. exit()
  85. print('build_type: ', build_type)
  86. print('\nWorking\n')
  87. python_ver = sys.version_info[0] # major version - 2 or 3
  88. print("python version " + str(sys.version_info[0]) + "." + str(sys.version_info[1]) + "." + str(sys.version_info[2]))
  89. import platform
  90. current_OS = platform.system()
  91. #globals
  92. target_env = ''
  93. board_name = ''
  94. from datetime import datetime, date, time
  95. #########
  96. # Python 2 error messages:
  97. # Can't find a usable init.tcl in the following directories ...
  98. # error "invalid command name "tcl_findLibrary""
  99. #
  100. # Fix for the above errors on my Win10 system:
  101. # search all init.tcl files for the line "package require -exact Tcl" that has the highest 8.5.x number
  102. # copy it into the first directory listed in the error messages
  103. # set the environmental variables TCLLIBPATH and TCL_LIBRARY to the directory where you found the init.tcl file
  104. # reboot
  105. #########
  106. ##########################################################################################
  107. #
  108. # popup to get input from user
  109. #
  110. ##########################################################################################
  111. def get_answer(board_name, cpu_label_txt, cpu_a_txt, cpu_b_txt):
  112. if python_ver == 2:
  113. import Tkinter as tk
  114. else:
  115. import tkinter as tk
  116. def CPU_exit_3(): # forward declare functions
  117. CPU_exit_3_()
  118. def got_answer():
  119. got_answer_()
  120. def kill_session():
  121. kill_session_()
  122. root_get_answer = tk.Tk()
  123. root_get_answer.title('')
  124. #root_get_answer.withdraw()
  125. #root_get_answer.deiconify()
  126. root_get_answer.attributes("-topmost", True)
  127. def disable_event():
  128. pass
  129. root_get_answer.protocol("WM_DELETE_WINDOW", disable_event)
  130. root_get_answer.resizable(False, False)
  131. root_get_answer.radio_state = 1 # declare variables used by TK and enable
  132. global get_answer_val
  133. get_answer_val = 2 # return get_answer_val, set default to match radio_state default
  134. radio_state = tk.IntVar()
  135. radio_state.set(get_answer_val)
  136. l1 = tk.Label(text=board_name, fg="light green", bg="dark green",
  137. font="default 14 bold").grid(row=0, columnspan=2, sticky='EW', ipadx=2, ipady=2)
  138. l2 = tk.Label(text=cpu_label_txt).grid(row=1, pady=4, columnspan=2, sticky='EW')
  139. b4 = tk.Radiobutton(
  140. text=cpu_a_txt,
  141. fg="black",
  142. bg="lightgray",
  143. relief=tk.SUNKEN,
  144. selectcolor="green",
  145. variable=radio_state,
  146. value=1,
  147. indicatoron=0,
  148. command=CPU_exit_3
  149. ).grid(row=2, pady=1, ipady=2, ipadx=10, columnspan=2)
  150. b5 = tk.Radiobutton(
  151. text=cpu_b_txt,
  152. fg="black",
  153. bg="lightgray",
  154. relief=tk.SUNKEN,
  155. selectcolor="green",
  156. variable=radio_state,
  157. value=2,
  158. indicatoron=0,
  159. command=CPU_exit_3
  160. ).grid(row=3, pady=1, ipady=2, ipadx=10, columnspan=2) # use same variable but inverted so they will track
  161. b6 = tk.Button(text="Cancel", fg="red", command=kill_session).grid(row=4, column=0, padx=4, pady=4, ipadx=2, ipady=2)
  162. b7 = tk.Button(text="Continue", fg="green", command=got_answer).grid(row=4, column=1, padx=4, pady=4, ipadx=2, ipady=2)
  163. def got_answer_():
  164. root_get_answer.destroy()
  165. def CPU_exit_3_():
  166. global get_answer_val
  167. get_answer_val = radio_state.get()
  168. def kill_session_():
  169. raise SystemExit(0) # kill everything
  170. root_get_answer.mainloop()
  171. # end - get answer
  172. #
  173. # move custom board definitions from project folder to PlatformIO
  174. #
  175. def resolve_path(path):
  176. import os
  177. # turn the selection into a partial path
  178. if 0 <= path.find('"'):
  179. path = path[path.find('"'):]
  180. if 0 <= path.find(', line '):
  181. path = path.replace(', line ', ':')
  182. path = path.replace('"', '')
  183. # get line and column numbers
  184. line_num = 1
  185. column_num = 1
  186. line_start = path.find(':', 2) # use 2 here so don't eat Windows full path
  187. column_start = path.find(':', line_start + 1)
  188. if column_start == -1:
  189. column_start = len(path)
  190. column_end = path.find(':', column_start + 1)
  191. if column_end == -1:
  192. column_end = len(path)
  193. if 0 <= line_start:
  194. line_num = path[line_start + 1:column_start]
  195. if line_num == '':
  196. line_num = 1
  197. if column_start != column_end:
  198. column_num = path[column_start + 1:column_end]
  199. if column_num == '':
  200. column_num = 0
  201. index_end = path.find(',')
  202. if 0 <= index_end:
  203. path = path[:index_end] # delete comma and anything after
  204. index_end = path.find(':', 2)
  205. if 0 <= index_end:
  206. path = path[:path.find(':', 2)] # delete the line number and anything after
  207. path = path.replace('\\', '/')
  208. if 1 == path.find(':') and current_OS == 'Windows':
  209. return path, line_num, column_num # found a full path - no need for further processing
  210. elif 0 == path.find('/') and (current_OS == 'Linux' or current_OS == 'Darwin'):
  211. return path, line_num, column_num # found a full path - no need for further processing
  212. else:
  213. # resolve as many '../' as we can
  214. while 0 <= path.find('../'):
  215. end = path.find('../') - 1
  216. start = path.find('/')
  217. while 0 <= path.find('/', start) and end > path.find('/', start):
  218. start = path.find('/', start) + 1
  219. path = path[0:start] + path[end + 4:]
  220. # this is an alternative to the above - it just deletes the '../' section
  221. # start_temp = path.find('../')
  222. # while 0 <= path.find('../',start_temp):
  223. # start = path.find('../',start_temp)
  224. # start_temp = start + 1
  225. # if 0 <= start:
  226. # path = path[start + 2 : ]
  227. start = path.find('/')
  228. if start != 0: # make sure path starts with '/'
  229. while 0 == path.find(' '): # eat any spaces at the beginning
  230. path = path[1:]
  231. path = '/' + path
  232. if current_OS == 'Windows':
  233. search_path = path.replace('/', '\\') # os.walk uses '\' in Windows
  234. else:
  235. search_path = path
  236. start_path = os.path.abspath('')
  237. # search project directory for the selection
  238. found = False
  239. full_path = ''
  240. for root, directories, filenames in os.walk(start_path):
  241. for filename in filenames:
  242. if 0 <= root.find('.git'): # don't bother looking in this directory
  243. break
  244. full_path = os.path.join(root, filename)
  245. if 0 <= full_path.find(search_path):
  246. found = True
  247. break
  248. if found:
  249. break
  250. return full_path, line_num, column_num
  251. # end - resolve_path
  252. #
  253. # Open the file in the preferred editor at the line & column number
  254. # If the preferred editor isn't already running then it tries the next.
  255. # If none are open then the system default is used.
  256. #
  257. # Editor order:
  258. # 1. Notepad++ (Windows only)
  259. # 2. Sublime Text
  260. # 3. Atom
  261. # 4. System default (opens at line 1, column 1 only)
  262. #
  263. def open_file(path):
  264. import subprocess
  265. file_path, line_num, column_num = resolve_path(path)
  266. if file_path == '':
  267. return
  268. if current_OS == 'Windows':
  269. editor_note = subprocess.check_output('wmic process where "name=' + "'notepad++.exe'" + '" get ExecutablePath')
  270. editor_sublime = subprocess.check_output('wmic process where "name=' + "'sublime_text.exe'" + '" get ExecutablePath')
  271. editor_atom = subprocess.check_output('wmic process where "name=' + "'atom.exe'" + '" get ExecutablePath')
  272. if 0 <= editor_note.find('notepad++.exe'):
  273. start = editor_note.find('\n') + 1
  274. end = editor_note.find('\n', start + 5) - 4
  275. editor_note = editor_note[start:end]
  276. command = file_path, ' -n' + str(line_num), ' -c' + str(column_num)
  277. subprocess.Popen([editor_note, command])
  278. elif 0 <= editor_sublime.find('sublime_text.exe'):
  279. start = editor_sublime.find('\n') + 1
  280. end = editor_sublime.find('\n', start + 5) - 4
  281. editor_sublime = editor_sublime[start:end]
  282. command = file_path + ':' + line_num + ':' + column_num
  283. subprocess.Popen([editor_sublime, command])
  284. elif 0 <= editor_atom.find('atom.exe'):
  285. start = editor_atom.find('\n') + 1
  286. end = editor_atom.find('\n', start + 5) - 4
  287. editor_atom = editor_atom[start:end]
  288. command = file_path + ':' + str(line_num) + ':' + str(column_num)
  289. subprocess.Popen([editor_atom, command])
  290. else:
  291. os.startfile(resolve_path(path)) # open file with default app
  292. elif current_OS == 'Linux':
  293. command = file_path + ':' + str(line_num) + ':' + str(column_num)
  294. index_end = command.find(',')
  295. if 0 <= index_end:
  296. command = command[:index_end] # sometimes a comma magically appears, don't want it
  297. running_apps = subprocess.Popen('ps ax -o cmd', stdout=subprocess.PIPE, shell=True)
  298. (output, err) = running_apps.communicate()
  299. temp = output.split('\n')
  300. def find_editor_linux(name, search_obj):
  301. for line in search_obj:
  302. if 0 <= line.find(name):
  303. path = line
  304. return True, path
  305. return False, ''
  306. (success_sublime, editor_path_sublime) = find_editor_linux('sublime_text', temp)
  307. (success_atom, editor_path_atom) = find_editor_linux('atom', temp)
  308. if success_sublime:
  309. subprocess.Popen([editor_path_sublime, command])
  310. elif success_atom:
  311. subprocess.Popen([editor_path_atom, command])
  312. else:
  313. os.system('xdg-open ' + file_path)
  314. elif current_OS == 'Darwin': # MAC
  315. command = file_path + ':' + str(line_num) + ':' + str(column_num)
  316. index_end = command.find(',')
  317. if 0 <= index_end:
  318. command = command[:index_end] # sometimes a comma magically appears, don't want it
  319. running_apps = subprocess.Popen('ps axwww -o command', stdout=subprocess.PIPE, shell=True)
  320. (output, err) = running_apps.communicate()
  321. temp = output.split('\n')
  322. def find_editor_mac(name, search_obj):
  323. for line in search_obj:
  324. if 0 <= line.find(name):
  325. path = line
  326. if 0 <= path.find('-psn'):
  327. path = path[:path.find('-psn') - 1]
  328. return True, path
  329. return False, ''
  330. (success_sublime, editor_path_sublime) = find_editor_mac('Sublime', temp)
  331. (success_atom, editor_path_atom) = find_editor_mac('Atom', temp)
  332. if success_sublime:
  333. subprocess.Popen([editor_path_sublime, command])
  334. elif success_atom:
  335. subprocess.Popen([editor_path_atom, command])
  336. else:
  337. os.system('open ' + file_path)
  338. # end - open_file
  339. # Get the last build environment
  340. def get_build_last():
  341. env_last = ''
  342. DIR_PWD = os.listdir('.')
  343. if '.pio' in DIR_PWD:
  344. date_last = 0.0
  345. DIR__pioenvs = os.listdir('.pio')
  346. for name in DIR__pioenvs:
  347. if 0 <= name.find('.') or 0 <= name.find('-'): # skip files in listing
  348. continue
  349. DIR_temp = os.listdir('.pio/build/' + name)
  350. for names_temp in DIR_temp:
  351. if 0 == names_temp.find('firmware.'):
  352. date_temp = os.path.getmtime('.pio/build/' + name + '/' + names_temp)
  353. if date_temp > date_last:
  354. date_last = date_temp
  355. env_last = name
  356. return env_last
  357. # Get the board being built from the Configuration.h file
  358. # return: board name, major version of Marlin being used (1 or 2)
  359. def get_board_name():
  360. board_name = ''
  361. # get board name
  362. with open('Marlin/Configuration.h', 'r') as myfile:
  363. Configuration_h = myfile.read()
  364. Configuration_h = Configuration_h.split('\n')
  365. Marlin_ver = 0 # set version to invalid number
  366. for lines in Configuration_h:
  367. if 0 == lines.find('#define CONFIGURATION_H_VERSION 01'):
  368. Marlin_ver = 1
  369. if 0 == lines.find('#define CONFIGURATION_H_VERSION 02'):
  370. Marlin_ver = 2
  371. board = lines.find(' BOARD_') + 1
  372. motherboard = lines.find(' MOTHERBOARD ') + 1
  373. define = lines.find('#define ')
  374. comment = lines.find('//')
  375. if (comment == -1 or comment > board) and \
  376. board > motherboard and \
  377. motherboard > define and \
  378. define >= 0 :
  379. spaces = lines.find(' ', board) # find the end of the board substring
  380. if spaces == -1:
  381. board_name = lines[board:]
  382. else:
  383. board_name = lines[board:spaces]
  384. break
  385. return board_name, Marlin_ver
  386. # extract first environment name found after the start position
  387. # return: environment name and position to start the next search from
  388. def get_env_from_line(line, start_position):
  389. env = ''
  390. next_position = -1
  391. env_position = line.find('env:', start_position)
  392. if 0 < env_position:
  393. next_position = line.find(' ', env_position + 4)
  394. if 0 < next_position:
  395. env = line[env_position + 4:next_position]
  396. else:
  397. env = line[env_position + 4:] # at the end of the line
  398. return env, next_position
  399. # scan pins.h for board name and return the environment(s) found
  400. def get_starting_env(board_name_full, version):
  401. # get environment starting point
  402. if version == 1:
  403. path = 'Marlin/pins.h'
  404. if version == 2:
  405. path = 'Marlin/src/pins/pins.h'
  406. with open(path, 'r') as myfile:
  407. pins_h = myfile.read()
  408. env_A = ''
  409. env_B = ''
  410. env_C = ''
  411. board_name = board_name_full[6:] # only use the part after "BOARD_" since we're searching the pins.h file
  412. pins_h = pins_h.split('\n')
  413. environment = ''
  414. board_line = ''
  415. cpu_A = ''
  416. cpu_B = ''
  417. i = 0
  418. list_start_found = False
  419. for lines in pins_h:
  420. i = i + 1 # i is always one ahead of the index into pins_h
  421. if 0 < lines.find("Unknown MOTHERBOARD value set in Configuration.h"):
  422. break # no more
  423. if 0 < lines.find('1280'):
  424. list_start_found = True
  425. if list_start_found == False: # skip lines until find start of CPU list
  426. continue
  427. board = lines.find(board_name)
  428. comment_start = lines.find('// ')
  429. cpu_A_loc = comment_start
  430. cpu_B_loc = 0
  431. if board > 0: # need to look at the next line for environment info
  432. cpu_line = pins_h[i]
  433. comment_start = cpu_line.find('// ')
  434. env_A, next_position = get_env_from_line(cpu_line, comment_start) # get name of environment & start of search for next
  435. env_B, next_position = get_env_from_line(cpu_line, next_position) # get next environment, if it exists
  436. env_C, next_position = get_env_from_line(cpu_line, next_position) # get next environment, if it exists
  437. break
  438. return env_A, env_B, env_C
  439. # Scan input string for CPUs that users may need to select from
  440. # return: CPU name
  441. def get_CPU_name(environment):
  442. CPU_list = ('1280', '2560', '644', '1284', 'LPC1768', 'DUE')
  443. CPU_name = ''
  444. for CPU in CPU_list:
  445. if 0 < environment.find(CPU):
  446. return CPU
  447. # get environment to be used for the build
  448. # return: environment
  449. def get_env(board_name, ver_Marlin):
  450. def no_environment():
  451. print('ERROR - no environment for this board')
  452. print(board_name)
  453. raise SystemExit(0) # no environment so quit
  454. def invalid_board():
  455. print('ERROR - invalid board')
  456. print(board_name)
  457. raise SystemExit(0) # quit if unable to find board
  458. CPU_question = (('1280', '2560', '1280 or 2560 CPU?'), ('644', '1284', '644 or 1284 CPU?'))
  459. if 0 < board_name.find('MELZI'):
  460. get_answer(
  461. board_name, " Which flavor of Melzi? ", "Melzi (Optiboot bootloader)", "Melzi "
  462. )
  463. if 1 == get_answer_val:
  464. target_env = 'melzi_optiboot'
  465. else:
  466. target_env = 'melzi'
  467. else:
  468. env_A, env_B, env_C = get_starting_env(board_name, ver_Marlin)
  469. if env_A == '':
  470. no_environment()
  471. if env_B == '':
  472. return env_A # only one environment so finished
  473. CPU_A = get_CPU_name(env_A)
  474. CPU_B = get_CPU_name(env_B)
  475. for item in CPU_question:
  476. if CPU_A == item[0]:
  477. get_answer(board_name, item[2], item[0], item[1])
  478. if 2 == get_answer_val:
  479. target_env = env_B
  480. else:
  481. target_env = env_A
  482. return target_env
  483. if env_A == 'LPC1768':
  484. if build_type == 'traceback' or (build_type == 'clean' and get_build_last() == 'LPC1768_debug_and_upload'):
  485. target_env = 'LPC1768_debug_and_upload'
  486. else:
  487. target_env = 'LPC1768'
  488. elif env_A == 'DUE':
  489. target_env = 'DUE'
  490. if build_type == 'traceback' or (build_type == 'clean' and get_build_last() == 'DUE_debug'):
  491. target_env = 'DUE_debug'
  492. elif env_B == 'DUE_USB':
  493. get_answer(board_name, 'DUE Download Port?', '(Native) USB port', 'Programming port')
  494. if 1 == get_answer_val:
  495. target_env = 'DUE_USB'
  496. else:
  497. target_env = 'DUE'
  498. elif env_A == 'STM32F103RC_btt' or env_A == 'STM32F103RE_btt':
  499. if env_A == 'STM32F103RE_btt':
  500. get_answer(board_name, 'MCU Type?', 'STM32F103RC', 'STM32F103RE')
  501. if 1 == get_answer_val:
  502. env_A = 'STM32F103RC_btt'
  503. target_env = env_A
  504. if env_A == 'STM32F103RC_btt':
  505. get_answer(board_name, 'RCT6 Flash Size?', '512K', '256K')
  506. if 1 == get_answer_val:
  507. target_env += '_512K'
  508. get_answer(board_name, 'USB Support?', 'USB', 'No USB')
  509. if 1 == get_answer_val:
  510. target_env += '_USB'
  511. else:
  512. invalid_board()
  513. if build_type == 'traceback' and target_env != 'LPC1768_debug_and_upload' and target_env != 'DUE_debug' and Marlin_ver == 2:
  514. print("ERROR - this board isn't setup for traceback")
  515. print('board_name: ', board_name)
  516. print('target_env: ', target_env)
  517. raise SystemExit(0)
  518. return target_env
  519. # end - get_env
  520. # puts screen text into queue so that the parent thread can fetch the data from this thread
  521. if python_ver == 2:
  522. import Queue as queue
  523. else:
  524. import queue as queue
  525. IO_queue = queue.Queue()
  526. #PIO_queue = queue.Queue() not used!
  527. def write_to_screen_queue(text, format_tag='normal'):
  528. double_in = [text, format_tag]
  529. IO_queue.put(double_in, block=False)
  530. #
  531. # send one line to the terminal screen with syntax highlighting
  532. #
  533. # input: unformatted text, flags from previous run
  534. # return: formatted text ready to go to the terminal, flags from this run
  535. #
  536. # This routine remembers the status from call to call because previous
  537. # lines can affect how the current line is highlighted
  538. #
  539. # 'static' variables - init here and then keep updating them from within print_line
  540. warning = False
  541. warning_FROM = False
  542. error = False
  543. standard = True
  544. prev_line_COM = False
  545. next_line_warning = False
  546. warning_continue = False
  547. line_counter = 0
  548. def line_print(line_input):
  549. global warning
  550. global warning_FROM
  551. global error
  552. global standard
  553. global prev_line_COM
  554. global next_line_warning
  555. global warning_continue
  556. global line_counter
  557. # all '0' elements must precede all '1' elements or they'll be skipped
  558. platformio_highlights = [
  559. ['Environment', 0, 'highlight_blue'], ['[SKIP]', 1, 'warning'], ['[IGNORED]', 1, 'warning'], ['[ERROR]', 1, 'error'],
  560. ['[FAILED]', 1, 'error'], ['[SUCCESS]', 1, 'highlight_green']
  561. ]
  562. def write_to_screen_with_replace(text, highlights): # search for highlights & split line accordingly
  563. did_something = False
  564. for highlight in highlights:
  565. found = text.find(highlight[0])
  566. if did_something == True:
  567. break
  568. if found >= 0:
  569. did_something = True
  570. if 0 == highlight[1]:
  571. found_1 = text.find(' ')
  572. found_tab = text.find('\t')
  573. if found_1 < 0 or found_1 > found_tab:
  574. found_1 = found_tab
  575. write_to_screen_queue(text[:found_1 + 1])
  576. for highlight_2 in highlights:
  577. if highlight[0] == highlight_2[0]:
  578. continue
  579. found = text.find(highlight_2[0])
  580. if found >= 0:
  581. found_space = text.find(' ', found_1 + 1)
  582. found_tab = text.find('\t', found_1 + 1)
  583. if found_space < 0 or found_space > found_tab:
  584. found_space = found_tab
  585. found_right = text.find(']', found + 1)
  586. write_to_screen_queue(text[found_1 + 1:found_space + 1], highlight[2])
  587. write_to_screen_queue(text[found_space + 1:found + 1])
  588. write_to_screen_queue(text[found + 1:found_right], highlight_2[2])
  589. write_to_screen_queue(text[found_right:] + '\n')
  590. break
  591. break
  592. if 1 == highlight[1]:
  593. found_right = text.find(']', found + 1)
  594. write_to_screen_queue(text[:found + 1])
  595. write_to_screen_queue(text[found + 1:found_right], highlight[2])
  596. write_to_screen_queue(text[found_right:] + '\n' + '\n')
  597. break
  598. if did_something == False:
  599. r_loc = text.find('\r') + 1
  600. if r_loc > 0 and r_loc < len(text): # need to split this line
  601. text = text.split('\r')
  602. for line in text:
  603. if line != '':
  604. write_to_screen_queue(line + '\n')
  605. else:
  606. write_to_screen_queue(text + '\n')
  607. # end - write_to_screen_with_replace
  608. # scan the line
  609. line_counter = line_counter + 1
  610. max_search = len(line_input)
  611. if max_search > 3:
  612. max_search = 3
  613. beginning = line_input[:max_search]
  614. # set flags
  615. if 0 < line_input.find(': warning: '): # start of warning block
  616. warning = True
  617. warning_FROM = False
  618. error = False
  619. standard = False
  620. prev_line_COM = False
  621. prev_line_COM = False
  622. warning_continue = True
  623. if 0 < line_input.find('Thank you') or 0 < line_input.find('SUMMARY'):
  624. warning = False #standard line found
  625. warning_FROM = False
  626. error = False
  627. standard = True
  628. prev_line_COM = False
  629. warning_continue = False
  630. elif beginning == 'War' or \
  631. beginning == '#er' or \
  632. beginning == 'In ' or \
  633. (beginning != 'Com' and prev_line_COM == True and not(beginning == 'Arc' or beginning == 'Lin' or beginning == 'Ind') or \
  634. next_line_warning == True):
  635. warning = True #warning found
  636. warning_FROM = False
  637. error = False
  638. standard = False
  639. prev_line_COM = False
  640. elif beginning == 'Com' or \
  641. beginning == 'Ver' or \
  642. beginning == ' [E' or \
  643. beginning == 'Rem' or \
  644. beginning == 'Bui' or \
  645. beginning == 'Ind' or \
  646. beginning == 'PLA':
  647. warning = False #standard line found
  648. warning_FROM = False
  649. error = False
  650. standard = True
  651. prev_line_COM = False
  652. warning_continue = False
  653. elif beginning == '***':
  654. warning = False # error found
  655. warning_FROM = False
  656. error = True
  657. standard = False
  658. prev_line_COM = False
  659. elif 0 < line_input.find(': error:') or \
  660. 0 < line_input.find(': fatal error:'): # start of warning /error block
  661. warning = False # error found
  662. warning_FROM = False
  663. error = True
  664. standard = False
  665. prev_line_COM = False
  666. warning_continue = True
  667. elif beginning == 'fro' and warning == True or \
  668. beginning == '.pi' : # start of warning /error block
  669. warning_FROM = True
  670. prev_line_COM = False
  671. warning_continue = True
  672. elif warning_continue == True:
  673. warning = True
  674. warning_FROM = False # keep the warning status going until find a standard line or an error
  675. error = False
  676. standard = False
  677. prev_line_COM = False
  678. warning_continue = True
  679. else:
  680. warning = False # unknown so assume standard line
  681. warning_FROM = False
  682. error = False
  683. standard = True
  684. prev_line_COM = False
  685. warning_continue = False
  686. if beginning == 'Com':
  687. prev_line_COM = True
  688. # print based on flags
  689. if standard == True:
  690. write_to_screen_with_replace(line_input, platformio_highlights) #print white on black with substitutions
  691. if warning == True:
  692. write_to_screen_queue(line_input + '\n', 'warning')
  693. if error == True:
  694. write_to_screen_queue(line_input + '\n', 'error')
  695. # end - line_print
  696. ##########################################################################
  697. # #
  698. # run Platformio #
  699. # #
  700. ##########################################################################
  701. # build platformio run -e target_env
  702. # clean platformio run --target clean -e target_env
  703. # upload platformio run --target upload -e target_env
  704. # traceback platformio run --target upload -e target_env
  705. # program platformio run --target program -e target_env
  706. # test platformio test upload -e target_env
  707. # remote platformio remote run --target upload -e target_env
  708. # debug platformio debug -e target_env
  709. def sys_PIO():
  710. ##########################################################################
  711. # #
  712. # run Platformio inside the same shell as this Python script #
  713. # #
  714. ##########################################################################
  715. global build_type
  716. global target_env
  717. import os
  718. print('build_type: ', build_type)
  719. print('starting platformio')
  720. if build_type == 'build':
  721. # pio_result = os.system("echo -en '\033c'")
  722. pio_result = os.system('platformio run -e ' + target_env)
  723. elif build_type == 'clean':
  724. pio_result = os.system('platformio run --target clean -e ' + target_env)
  725. elif build_type == 'upload':
  726. pio_result = os.system('platformio run --target upload -e ' + target_env)
  727. elif build_type == 'traceback':
  728. pio_result = os.system('platformio run --target upload -e ' + target_env)
  729. elif build_type == 'program':
  730. pio_result = os.system('platformio run --target program -e ' + target_env)
  731. elif build_type == 'test':
  732. pio_result = os.system('platformio test upload -e ' + target_env)
  733. elif build_type == 'remote':
  734. pio_result = os.system('platformio remote run --target program -e ' + target_env)
  735. elif build_type == 'debug':
  736. pio_result = os.system('platformio debug -e ' + target_env)
  737. else:
  738. print('ERROR - unknown build type: ', build_type)
  739. raise SystemExit(0) # kill everything
  740. # stream output from subprocess and split it into lines
  741. #for line in iter(pio_subprocess.stdout.readline, ''):
  742. # line_print(line.replace('\n', ''))
  743. # append info used to run PlatformIO
  744. # write_to_screen_queue('\nBoard name: ' + board_name + '\n') # put build info at the bottom of the screen
  745. # write_to_screen_queue('Build type: ' + build_type + '\n')
  746. # write_to_screen_queue('Environment used: ' + target_env + '\n')
  747. # write_to_screen_queue(str(datetime.now()) + '\n')
  748. # end - sys_PIO
  749. def run_PIO(dummy):
  750. global build_type
  751. global target_env
  752. global board_name
  753. print('build_type: ', build_type)
  754. import subprocess
  755. import sys
  756. print('starting platformio')
  757. if build_type == 'build':
  758. # platformio run -e target_env
  759. # combine stdout & stderr so all compile messages are included
  760. pio_subprocess = subprocess.Popen(
  761. ['platformio', 'run', '-e', target_env], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
  762. )
  763. elif build_type == 'clean':
  764. # platformio run --target clean -e target_env
  765. # combine stdout & stderr so all compile messages are included
  766. pio_subprocess = subprocess.Popen(
  767. ['platformio', 'run', '--target', 'clean', '-e', target_env], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
  768. )
  769. elif build_type == 'upload':
  770. # platformio run --target upload -e target_env
  771. # combine stdout & stderr so all compile messages are included
  772. pio_subprocess = subprocess.Popen(
  773. ['platformio', 'run', '--target', 'upload', '-e', target_env], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
  774. )
  775. elif build_type == 'traceback':
  776. # platformio run --target upload -e target_env - select the debug environment if there is one
  777. # combine stdout & stderr so all compile messages are included
  778. pio_subprocess = subprocess.Popen(
  779. ['platformio', 'run', '--target', 'upload', '-e', target_env], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
  780. )
  781. elif build_type == 'program':
  782. # platformio run --target program -e target_env
  783. # combine stdout & stderr so all compile messages are included
  784. pio_subprocess = subprocess.Popen(
  785. ['platformio', 'run', '--target', 'program', '-e', target_env], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
  786. )
  787. elif build_type == 'test':
  788. #platformio test upload -e target_env
  789. # combine stdout & stderr so all compile messages are included
  790. pio_subprocess = subprocess.Popen(
  791. ['platformio', 'test', 'upload', '-e', target_env], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
  792. )
  793. elif build_type == 'remote':
  794. # platformio remote run --target upload -e target_env
  795. # combine stdout & stderr so all compile messages are included
  796. pio_subprocess = subprocess.Popen(
  797. ['platformio', 'remote', 'run', '--target', 'program', '-e', target_env],
  798. stdout=subprocess.PIPE,
  799. stderr=subprocess.STDOUT
  800. )
  801. elif build_type == 'debug':
  802. # platformio debug -e target_env
  803. # combine stdout & stderr so all compile messages are included
  804. pio_subprocess = subprocess.Popen(
  805. ['platformio', 'debug', '-e', target_env], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
  806. )
  807. else:
  808. print('ERROR - unknown build type: ', build_type)
  809. raise SystemExit(0) # kill everything
  810. # stream output from subprocess and split it into lines
  811. if python_ver == 2:
  812. for line in iter(pio_subprocess.stdout.readline, ''):
  813. line_print(line.replace('\n', ''))
  814. else:
  815. for line in iter(pio_subprocess.stdout.readline, b''):
  816. line = line.decode('utf-8')
  817. line_print(line.replace('\n', ''))
  818. # append info used to run PlatformIO
  819. write_to_screen_queue('\nBoard name: ' + board_name + '\n') # put build info at the bottom of the screen
  820. write_to_screen_queue('Build type: ' + build_type + '\n')
  821. write_to_screen_queue('Environment used: ' + target_env + '\n')
  822. write_to_screen_queue(str(datetime.now()) + '\n')
  823. # end - run_PIO
  824. ########################################################################
  825. import time
  826. import threading
  827. if python_ver == 2:
  828. import Tkinter as tk
  829. import Queue as queue
  830. import ttk
  831. from Tkinter import Tk, Frame, Text, Scrollbar, Menu
  832. #from tkMessageBox import askokcancel this is not used: removed
  833. import tkFileDialog as fileDialog
  834. else:
  835. import tkinter as tk
  836. import queue as queue
  837. from tkinter import ttk, Tk, Frame, Text, Menu
  838. import subprocess
  839. import sys
  840. que = queue.Queue()
  841. #IO_queue = queue.Queue()
  842. class output_window(Text):
  843. # based on Super Text
  844. global continue_updates
  845. continue_updates = True
  846. global search_position
  847. search_position = '' # start with invalid search position
  848. global error_found
  849. error_found = False # are there any errors?
  850. def __init__(self):
  851. self.root = tk.Tk()
  852. self.root.attributes("-topmost", True)
  853. self.frame = tk.Frame(self.root)
  854. self.frame.pack(fill='both', expand=True)
  855. # text widget
  856. #self.text = tk.Text(self.frame, borderwidth=3, relief="sunken")
  857. Text.__init__(self, self.frame, borderwidth=3, relief="sunken")
  858. self.config(tabs=(400, )) # configure Text widget tab stops
  859. self.config(background='black', foreground='white', font=("consolas", 12), wrap='word', undo='True')
  860. #self.config(background = 'black', foreground = 'white', font= ("consolas", 12), wrap = 'none', undo = 'True')
  861. self.config(height=24, width=100)
  862. self.config(insertbackground='pale green') # keyboard insertion point
  863. self.pack(side='left', fill='both', expand=True)
  864. self.tag_config('normal', foreground='white')
  865. self.tag_config('warning', foreground='yellow')
  866. self.tag_config('error', foreground='red')
  867. self.tag_config('highlight_green', foreground='green')
  868. self.tag_config('highlight_blue', foreground='cyan')
  869. self.tag_config('error_highlight_inactive', background='dim gray')
  870. self.tag_config('error_highlight_active', background='light grey')
  871. self.bind_class("Text", "<Control-a>", self.select_all) # required in windows, works in others
  872. self.bind_all("<Control-Shift-E>", self.scroll_errors)
  873. self.bind_class("<Control-Shift-R>", self.rebuild)
  874. # scrollbar
  875. scrb = tk.Scrollbar(self.frame, orient='vertical', command=self.yview)
  876. self.config(yscrollcommand=scrb.set)
  877. scrb.pack(side='right', fill='y')
  878. #self.scrb_Y = tk.Scrollbar(self.frame, orient='vertical', command=self.yview)
  879. #self.scrb_Y.config(yscrollcommand=self.scrb_Y.set)
  880. #self.scrb_Y.pack(side='right', fill='y')
  881. #self.scrb_X = tk.Scrollbar(self.frame, orient='horizontal', command=self.xview)
  882. #self.scrb_X.config(xscrollcommand=self.scrb_X.set)
  883. #self.scrb_X.pack(side='bottom', fill='x')
  884. #scrb_X = tk.Scrollbar(self, orient=tk.HORIZONTAL, command=self.xview) # tk.HORIZONTAL now have a horizsontal scroll bar BUT... shrinks it to a postage stamp and hides far right behind the vertical scroll bar
  885. #self.config(xscrollcommand=scrb_X.set)
  886. #scrb_X.pack(side='bottom', fill='x')
  887. #scrb= tk.Scrollbar(self, orient='vertical', command=self.yview)
  888. #self.config(yscrollcommand=scrb.set)
  889. #scrb.pack(side='right', fill='y')
  890. #self.config(height = 240, width = 1000) # didn't get the size baCK TO NORMAL
  891. #self.pack(side='left', fill='both', expand=True) # didn't get the size baCK TO NORMAL
  892. # pop-up menu
  893. self.popup = tk.Menu(self, tearoff=0)
  894. self.popup.add_command(label='Copy', command=self._copy)
  895. self.popup.add_command(label='Paste', command=self._paste)
  896. self.popup.add_separator()
  897. self.popup.add_command(label='Cut', command=self._cut)
  898. self.popup.add_separator()
  899. self.popup.add_command(label='Select All', command=self._select_all)
  900. self.popup.add_command(label='Clear All', command=self._clear_all)
  901. self.popup.add_separator()
  902. self.popup.add_command(label='Save As', command=self._file_save_as)
  903. self.popup.add_separator()
  904. #self.popup.add_command(label='Repeat Build(CTL-shift-r)', command=self._rebuild)
  905. self.popup.add_command(label='Repeat Build', command=self._rebuild)
  906. self.popup.add_separator()
  907. self.popup.add_command(label='Scroll Errors (CTL-shift-e)', command=self._scroll_errors)
  908. self.popup.add_separator()
  909. self.popup.add_command(label='Open File at Cursor', command=self._open_selected_file)
  910. if current_OS == 'Darwin': # MAC
  911. self.bind('<Button-2>', self._show_popup) # macOS only
  912. else:
  913. self.bind('<Button-3>', self._show_popup) # Windows & Linux
  914. # threading & subprocess section
  915. def start_thread(self, ):
  916. global continue_updates
  917. # create then start a secondary thread to run an arbitrary function
  918. # must have at least one argument
  919. self.secondary_thread = threading.Thread(target=lambda q, arg1: q.put(run_PIO(arg1)), args=(que, ''))
  920. self.secondary_thread.start()
  921. continue_updates = True
  922. # check the Queue in 50ms
  923. self.root.after(50, self.check_thread)
  924. self.root.after(50, self.update)
  925. def check_thread(self): # wait for user to kill the window
  926. global continue_updates
  927. if continue_updates == True:
  928. self.root.after(10, self.check_thread)
  929. def update(self):
  930. global continue_updates
  931. if continue_updates == True:
  932. self.root.after(10, self.update) #method is called every 50ms
  933. temp_text = ['0', '0']
  934. if IO_queue.empty():
  935. if not (self.secondary_thread.is_alive()):
  936. continue_updates = False # queue is exhausted and thread is dead so no need for further updates
  937. else:
  938. try:
  939. temp_text = IO_queue.get(block=False)
  940. except Queue.Empty:
  941. continue_updates = False # queue is exhausted so no need for further updates
  942. else:
  943. self.insert('end', temp_text[0], temp_text[1])
  944. self.see("end") # make the last line visible (scroll text off the top)
  945. # text editing section
  946. def _scroll_errors(self):
  947. global search_position
  948. global error_found
  949. if search_position == '': # first time so highlight all errors
  950. countVar = tk.IntVar()
  951. search_position = '1.0'
  952. search_count = 0
  953. while search_position != '' and search_count < 100:
  954. search_position = self.search("error", search_position, stopindex="end", count=countVar, nocase=1)
  955. search_count = search_count + 1
  956. if search_position != '':
  957. error_found = True
  958. end_pos = '{}+{}c'.format(search_position, 5)
  959. self.tag_add("error_highlight_inactive", search_position, end_pos)
  960. search_position = '{}+{}c'.format(search_position, 1) # point to the next character for new search
  961. else:
  962. break
  963. if error_found:
  964. if search_position == '':
  965. search_position = self.search("error", '1.0', stopindex="end", nocase=1) # new search
  966. else: # remove active highlight
  967. end_pos = '{}+{}c'.format(search_position, 5)
  968. start_pos = '{}+{}c'.format(search_position, -1)
  969. self.tag_remove("error_highlight_active", start_pos, end_pos)
  970. search_position = self.search(
  971. "error", search_position, stopindex="end", nocase=1
  972. ) # finds first occurrence AGAIN on the first time through
  973. if search_position == "": # wrap around
  974. search_position = self.search("error", '1.0', stopindex="end", nocase=1)
  975. end_pos = '{}+{}c'.format(search_position, 5)
  976. self.tag_add("error_highlight_active", search_position, end_pos) # add active highlight
  977. self.see(search_position)
  978. search_position = '{}+{}c'.format(search_position, 1) # point to the next character for new search
  979. def scroll_errors(self, event):
  980. self._scroll_errors()
  981. def _rebuild(self):
  982. #global board_name
  983. #global Marlin_ver
  984. #global target_env
  985. #board_name, Marlin_ver = get_board_name()
  986. #target_env = get_env(board_name, Marlin_ver)
  987. self.start_thread()
  988. def rebuild(self, event):
  989. print("event happened")
  990. self._rebuild()
  991. def _open_selected_file(self):
  992. current_line = self.index('insert')
  993. line_start = current_line[:current_line.find('.')] + '.0'
  994. line_end = current_line[:current_line.find('.')] + '.200'
  995. self.mark_set("path_start", line_start)
  996. self.mark_set("path_end", line_end)
  997. path = self.get("path_start", "path_end")
  998. from_loc = path.find('from ')
  999. colon_loc = path.find(': ')
  1000. if 0 <= from_loc and ((colon_loc == -1) or (from_loc < colon_loc)):
  1001. path = path[from_loc + 5:]
  1002. if 0 <= colon_loc:
  1003. path = path[:colon_loc]
  1004. if 0 <= path.find('\\') or 0 <= path.find('/'): # make sure it really contains a path
  1005. open_file(path)
  1006. def _file_save_as(self):
  1007. self.filename = fileDialog.asksaveasfilename(defaultextension='.txt')
  1008. f = open(self.filename, 'w')
  1009. f.write(self.get('1.0', 'end'))
  1010. f.close()
  1011. def copy(self, event):
  1012. try:
  1013. selection = self.get(*self.tag_ranges('sel'))
  1014. self.clipboard_clear()
  1015. self.clipboard_append(selection)
  1016. except TypeError:
  1017. pass
  1018. def cut(self, event):
  1019. try:
  1020. selection = self.get(*self.tag_ranges('sel'))
  1021. self.clipboard_clear()
  1022. self.clipboard_append(selection)
  1023. self.delete(*self.tag_ranges('sel'))
  1024. except TypeError:
  1025. pass
  1026. def _show_popup(self, event):
  1027. '''right-click popup menu'''
  1028. if self.root.focus_get() != self:
  1029. self.root.focus_set()
  1030. try:
  1031. self.popup.tk_popup(event.x_root, event.y_root, 0)
  1032. finally:
  1033. self.popup.grab_release()
  1034. def _cut(self):
  1035. try:
  1036. selection = self.get(*self.tag_ranges('sel'))
  1037. self.clipboard_clear()
  1038. self.clipboard_append(selection)
  1039. self.delete(*self.tag_ranges('sel'))
  1040. except TypeError:
  1041. pass
  1042. def cut(self, event):
  1043. self._cut()
  1044. def _copy(self):
  1045. try:
  1046. selection = self.get(*self.tag_ranges('sel'))
  1047. self.clipboard_clear()
  1048. self.clipboard_append(selection)
  1049. except TypeError:
  1050. pass
  1051. def copy(self, event):
  1052. self._copy()
  1053. def _paste(self):
  1054. self.insert('insert', self.selection_get(selection='CLIPBOARD'))
  1055. def _select_all(self):
  1056. self.tag_add('sel', '1.0', 'end')
  1057. def select_all(self, event):
  1058. self.tag_add('sel', '1.0', 'end')
  1059. def _clear_all(self):
  1060. #'''erases all text'''
  1061. #
  1062. #isok = askokcancel('Clear All', 'Erase all text?', frame=self,
  1063. # default='ok')
  1064. #if isok:
  1065. # self.delete('1.0', 'end')
  1066. self.delete('1.0', 'end')
  1067. # end - output_window
  1068. def main():
  1069. ##########################################################################
  1070. # #
  1071. # main program #
  1072. # #
  1073. ##########################################################################
  1074. global build_type
  1075. global target_env
  1076. global board_name
  1077. board_name, Marlin_ver = get_board_name()
  1078. target_env = get_env(board_name, Marlin_ver)
  1079. # Re-use the VSCode terminal, if possible
  1080. if os.environ.get('PLATFORMIO_CALLER', '') == 'vscode':
  1081. sys_PIO()
  1082. else:
  1083. auto_build = output_window()
  1084. auto_build.start_thread() # executes the "run_PIO" function
  1085. auto_build.root.mainloop()
  1086. if __name__ == '__main__':
  1087. main()