My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

auto_build.py 44KB

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