My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

auto_build.py 43KB

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