My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

auto_build.py 44KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  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
  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, cpu_label_txt, cpu_a_txt, cpu_b_txt):
  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 = 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_btt' or env_A == 'STM32F103RE_btt':
  498. if env_A == 'STM32F103RE_btt':
  499. get_answer(board_name, 'MCU Type?', 'STM32F103RC', 'STM32F103RE')
  500. if 1 == get_answer_val:
  501. env_A = 'STM32F103RC_btt'
  502. target_env = env_A
  503. if env_A == 'STM32F103RC_btt':
  504. get_answer(board_name, 'RCT6 Flash Size?', '512K', '256K')
  505. if 1 == get_answer_val:
  506. target_env += '_512K'
  507. get_answer(board_name, 'USB Support?', 'USB', 'No USB')
  508. if 1 == get_answer_val:
  509. target_env += '_USB'
  510. else:
  511. invalid_board()
  512. if build_type == 'traceback' and target_env != 'LPC1768_debug_and_upload' and target_env != 'DUE_debug' and Marlin_ver == 2:
  513. print("ERROR - this board isn't setup for traceback")
  514. print('board_name: ', board_name)
  515. print('target_env: ', target_env)
  516. raise SystemExit(0)
  517. return target_env
  518. # end - get_env
  519. # puts screen text into queue so that the parent thread can fetch the data from this thread
  520. if python_ver == 2:
  521. import Queue as queue
  522. else:
  523. import queue as queue
  524. IO_queue = queue.Queue()
  525. #PIO_queue = queue.Queue() not used!
  526. def write_to_screen_queue(text, format_tag='normal'):
  527. double_in = [text, format_tag]
  528. IO_queue.put(double_in, block=False)
  529. #
  530. # send one line to the terminal screen with syntax highlighting
  531. #
  532. # input: unformatted text, flags from previous run
  533. # return: formatted text ready to go to the terminal, flags from this run
  534. #
  535. # This routine remembers the status from call to call because previous
  536. # lines can affect how the current line is highlighted
  537. #
  538. # 'static' variables - init here and then keep updating them from within print_line
  539. warning = False
  540. warning_FROM = False
  541. error = False
  542. standard = True
  543. prev_line_COM = False
  544. next_line_warning = False
  545. warning_continue = False
  546. line_counter = 0
  547. def line_print(line_input):
  548. global warning
  549. global warning_FROM
  550. global error
  551. global standard
  552. global prev_line_COM
  553. global next_line_warning
  554. global warning_continue
  555. global line_counter
  556. # all '0' elements must precede all '1' elements or they'll be skipped
  557. platformio_highlights = [
  558. ['Environment', 0, 'highlight_blue'], ['[SKIP]', 1, 'warning'], ['[IGNORED]', 1, 'warning'], ['[ERROR]', 1, 'error'],
  559. ['[FAILED]', 1, 'error'], ['[SUCCESS]', 1, 'highlight_green']
  560. ]
  561. def write_to_screen_with_replace(text, highlights): # search for highlights & split line accordingly
  562. did_something = False
  563. for highlight in highlights:
  564. found = text.find(highlight[0])
  565. if did_something == True:
  566. break
  567. if found >= 0:
  568. did_something = True
  569. if 0 == highlight[1]:
  570. found_1 = text.find(' ')
  571. found_tab = text.find('\t')
  572. if found_1 < 0 or found_1 > found_tab:
  573. found_1 = found_tab
  574. write_to_screen_queue(text[:found_1 + 1])
  575. for highlight_2 in highlights:
  576. if highlight[0] == highlight_2[0]:
  577. continue
  578. found = text.find(highlight_2[0])
  579. if found >= 0:
  580. found_space = text.find(' ', found_1 + 1)
  581. found_tab = text.find('\t', found_1 + 1)
  582. if found_space < 0 or found_space > found_tab:
  583. found_space = found_tab
  584. found_right = text.find(']', found + 1)
  585. write_to_screen_queue(text[found_1 + 1:found_space + 1], highlight[2])
  586. write_to_screen_queue(text[found_space + 1:found + 1])
  587. write_to_screen_queue(text[found + 1:found_right], highlight_2[2])
  588. write_to_screen_queue(text[found_right:] + '\n')
  589. break
  590. break
  591. if 1 == highlight[1]:
  592. found_right = text.find(']', found + 1)
  593. write_to_screen_queue(text[:found + 1])
  594. write_to_screen_queue(text[found + 1:found_right], highlight[2])
  595. write_to_screen_queue(text[found_right:] + '\n' + '\n')
  596. break
  597. if did_something == False:
  598. r_loc = text.find('\r') + 1
  599. if r_loc > 0 and r_loc < len(text): # need to split this line
  600. text = text.split('\r')
  601. for line in text:
  602. if line != '':
  603. write_to_screen_queue(line + '\n')
  604. else:
  605. write_to_screen_queue(text + '\n')
  606. # end - write_to_screen_with_replace
  607. # scan the line
  608. line_counter = line_counter + 1
  609. max_search = len(line_input)
  610. if max_search > 3:
  611. max_search = 3
  612. beginning = line_input[:max_search]
  613. # set flags
  614. if 0 < line_input.find(': warning: '): # start of warning block
  615. warning = True
  616. warning_FROM = False
  617. error = False
  618. standard = False
  619. prev_line_COM = False
  620. prev_line_COM = False
  621. warning_continue = True
  622. if 0 < line_input.find('Thank you') or 0 < line_input.find('SUMMARY'):
  623. warning = False #standard line found
  624. warning_FROM = False
  625. error = False
  626. standard = True
  627. prev_line_COM = False
  628. warning_continue = False
  629. elif beginning == 'War' or \
  630. beginning == '#er' or \
  631. beginning == 'In ' or \
  632. (beginning != 'Com' and prev_line_COM == True and not(beginning == 'Arc' or beginning == 'Lin' or beginning == 'Ind') or \
  633. next_line_warning == True):
  634. warning = True #warning found
  635. warning_FROM = False
  636. error = False
  637. standard = False
  638. prev_line_COM = False
  639. elif beginning == 'Com' or \
  640. beginning == 'Ver' or \
  641. beginning == ' [E' or \
  642. beginning == 'Rem' or \
  643. beginning == 'Bui' or \
  644. beginning == 'Ind' or \
  645. beginning == 'PLA':
  646. warning = False #standard line found
  647. warning_FROM = False
  648. error = False
  649. standard = True
  650. prev_line_COM = False
  651. warning_continue = False
  652. elif beginning == '***':
  653. warning = False # error found
  654. warning_FROM = False
  655. error = True
  656. standard = False
  657. prev_line_COM = False
  658. elif 0 < line_input.find(': error:') or \
  659. 0 < line_input.find(': fatal error:'): # start of warning /error block
  660. warning = False # error found
  661. warning_FROM = False
  662. error = True
  663. standard = False
  664. prev_line_COM = False
  665. warning_continue = True
  666. elif beginning == 'fro' and warning == True or \
  667. beginning == '.pi' : # start of warning /error block
  668. warning_FROM = True
  669. prev_line_COM = False
  670. warning_continue = True
  671. elif warning_continue == True:
  672. warning = True
  673. warning_FROM = False # keep the warning status going until find a standard line or an error
  674. error = False
  675. standard = False
  676. prev_line_COM = False
  677. warning_continue = True
  678. else:
  679. warning = False # unknown so assume standard line
  680. warning_FROM = False
  681. error = False
  682. standard = True
  683. prev_line_COM = False
  684. warning_continue = False
  685. if beginning == 'Com':
  686. prev_line_COM = True
  687. # print based on flags
  688. if standard == True:
  689. write_to_screen_with_replace(line_input, platformio_highlights) #print white on black with substitutions
  690. if warning == True:
  691. write_to_screen_queue(line_input + '\n', 'warning')
  692. if error == True:
  693. write_to_screen_queue(line_input + '\n', 'error')
  694. # end - line_print
  695. ##########################################################################
  696. # #
  697. # run Platformio #
  698. # #
  699. ##########################################################################
  700. # build platformio run -e target_env
  701. # clean platformio run --target clean -e target_env
  702. # upload platformio run --target upload -e target_env
  703. # traceback platformio run --target upload -e target_env
  704. # program platformio run --target program -e target_env
  705. # test platformio test upload -e target_env
  706. # remote platformio remote run --target upload -e target_env
  707. # debug platformio debug -e target_env
  708. def sys_PIO():
  709. ##########################################################################
  710. # #
  711. # run Platformio inside the same shell as this Python script #
  712. # #
  713. ##########################################################################
  714. global build_type
  715. global target_env
  716. import os
  717. print('build_type: ', build_type)
  718. print('starting platformio')
  719. if build_type == 'build':
  720. # pio_result = os.system("echo -en '\033c'")
  721. pio_result = os.system('platformio run -e ' + target_env)
  722. elif build_type == 'clean':
  723. pio_result = os.system('platformio run --target clean -e ' + target_env)
  724. elif build_type == 'upload':
  725. pio_result = os.system('platformio run --target upload -e ' + target_env)
  726. elif build_type == 'traceback':
  727. pio_result = os.system('platformio run --target upload -e ' + target_env)
  728. elif build_type == 'program':
  729. pio_result = os.system('platformio run --target program -e ' + target_env)
  730. elif build_type == 'test':
  731. pio_result = os.system('platformio test upload -e ' + target_env)
  732. elif build_type == 'remote':
  733. pio_result = os.system('platformio remote run --target program -e ' + target_env)
  734. elif build_type == 'debug':
  735. pio_result = os.system('platformio debug -e ' + target_env)
  736. else:
  737. print('ERROR - unknown build type: ', build_type)
  738. raise SystemExit(0) # kill everything
  739. # stream output from subprocess and split it into lines
  740. #for line in iter(pio_subprocess.stdout.readline, ''):
  741. # line_print(line.replace('\n', ''))
  742. # append info used to run PlatformIO
  743. # write_to_screen_queue('\nBoard name: ' + board_name + '\n') # put build info at the bottom of the screen
  744. # write_to_screen_queue('Build type: ' + build_type + '\n')
  745. # write_to_screen_queue('Environment used: ' + target_env + '\n')
  746. # write_to_screen_queue(str(datetime.now()) + '\n')
  747. # end - sys_PIO
  748. def run_PIO(dummy):
  749. global build_type
  750. global target_env
  751. global board_name
  752. print('build_type: ', build_type)
  753. import subprocess
  754. import sys
  755. print('starting platformio')
  756. if build_type == 'build':
  757. # platformio run -e target_env
  758. # combine stdout & stderr so all compile messages are included
  759. pio_subprocess = subprocess.Popen(
  760. ['platformio', 'run', '-e', target_env], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
  761. )
  762. elif build_type == 'clean':
  763. # platformio run --target clean -e target_env
  764. # combine stdout & stderr so all compile messages are included
  765. pio_subprocess = subprocess.Popen(
  766. ['platformio', 'run', '--target', 'clean', '-e', target_env], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
  767. )
  768. elif build_type == 'upload':
  769. # platformio run --target upload -e target_env
  770. # combine stdout & stderr so all compile messages are included
  771. pio_subprocess = subprocess.Popen(
  772. ['platformio', 'run', '--target', 'upload', '-e', target_env], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
  773. )
  774. elif build_type == 'traceback':
  775. # platformio run --target upload -e target_env - select the debug environment if there is one
  776. # combine stdout & stderr so all compile messages are included
  777. pio_subprocess = subprocess.Popen(
  778. ['platformio', 'run', '--target', 'upload', '-e', target_env], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
  779. )
  780. elif build_type == 'program':
  781. # platformio run --target program -e target_env
  782. # combine stdout & stderr so all compile messages are included
  783. pio_subprocess = subprocess.Popen(
  784. ['platformio', 'run', '--target', 'program', '-e', target_env], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
  785. )
  786. elif build_type == 'test':
  787. #platformio test upload -e target_env
  788. # combine stdout & stderr so all compile messages are included
  789. pio_subprocess = subprocess.Popen(
  790. ['platformio', 'test', 'upload', '-e', target_env], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
  791. )
  792. elif build_type == 'remote':
  793. # platformio remote run --target upload -e target_env
  794. # combine stdout & stderr so all compile messages are included
  795. pio_subprocess = subprocess.Popen(
  796. ['platformio', 'remote', 'run', '--target', 'program', '-e', target_env],
  797. stdout=subprocess.PIPE,
  798. stderr=subprocess.STDOUT
  799. )
  800. elif build_type == 'debug':
  801. # platformio debug -e target_env
  802. # combine stdout & stderr so all compile messages are included
  803. pio_subprocess = subprocess.Popen(
  804. ['platformio', 'debug', '-e', target_env], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
  805. )
  806. else:
  807. print('ERROR - unknown build type: ', build_type)
  808. raise SystemExit(0) # kill everything
  809. # stream output from subprocess and split it into lines
  810. if python_ver == 2:
  811. for line in iter(pio_subprocess.stdout.readline, ''):
  812. line_print(line.replace('\n', ''))
  813. else:
  814. for line in iter(pio_subprocess.stdout.readline, b''):
  815. line = line.decode('utf-8')
  816. line_print(line.replace('\n', ''))
  817. # append info used to run PlatformIO
  818. write_to_screen_queue('\nBoard name: ' + board_name + '\n') # put build info at the bottom of the screen
  819. write_to_screen_queue('Build type: ' + build_type + '\n')
  820. write_to_screen_queue('Environment used: ' + target_env + '\n')
  821. write_to_screen_queue(str(datetime.now()) + '\n')
  822. # end - run_PIO
  823. ########################################################################
  824. import time
  825. import threading
  826. if python_ver == 2:
  827. import Tkinter as tk
  828. import Queue as queue
  829. import ttk
  830. from Tkinter import Tk, Frame, Text, Scrollbar, Menu
  831. #from tkMessageBox import askokcancel this is not used: removed
  832. import tkFileDialog as fileDialog
  833. else:
  834. import tkinter as tk
  835. import queue as queue
  836. from tkinter import ttk, Tk, Frame, Text, Menu
  837. import subprocess
  838. import sys
  839. que = queue.Queue()
  840. #IO_queue = queue.Queue()
  841. class output_window(Text):
  842. # based on Super Text
  843. global continue_updates
  844. continue_updates = True
  845. global search_position
  846. search_position = '' # start with invalid search position
  847. global error_found
  848. error_found = False # are there any errors?
  849. def __init__(self):
  850. self.root = tk.Tk()
  851. self.root.attributes("-topmost", True)
  852. self.frame = tk.Frame(self.root)
  853. self.frame.pack(fill='both', expand=True)
  854. # text widget
  855. #self.text = tk.Text(self.frame, borderwidth=3, relief="sunken")
  856. Text.__init__(self, self.frame, borderwidth=3, relief="sunken")
  857. self.config(tabs=(400, )) # configure Text widget tab stops
  858. self.config(background='black', foreground='white', font=("consolas", 12), wrap='word', undo='True')
  859. #self.config(background = 'black', foreground = 'white', font= ("consolas", 12), wrap = 'none', undo = 'True')
  860. self.config(height=24, width=100)
  861. self.config(insertbackground='pale green') # keyboard insertion point
  862. self.pack(side='left', fill='both', expand=True)
  863. self.tag_config('normal', foreground='white')
  864. self.tag_config('warning', foreground='yellow')
  865. self.tag_config('error', foreground='red')
  866. self.tag_config('highlight_green', foreground='green')
  867. self.tag_config('highlight_blue', foreground='cyan')
  868. self.tag_config('error_highlight_inactive', background='dim gray')
  869. self.tag_config('error_highlight_active', background='light grey')
  870. self.bind_class("Text", "<Control-a>", self.select_all) # required in windows, works in others
  871. self.bind_all("<Control-Shift-E>", self.scroll_errors)
  872. self.bind_class("<Control-Shift-R>", self.rebuild)
  873. # scrollbar
  874. scrb = tk.Scrollbar(self.frame, orient='vertical', command=self.yview)
  875. self.config(yscrollcommand=scrb.set)
  876. scrb.pack(side='right', fill='y')
  877. #self.scrb_Y = tk.Scrollbar(self.frame, orient='vertical', command=self.yview)
  878. #self.scrb_Y.config(yscrollcommand=self.scrb_Y.set)
  879. #self.scrb_Y.pack(side='right', fill='y')
  880. #self.scrb_X = tk.Scrollbar(self.frame, orient='horizontal', command=self.xview)
  881. #self.scrb_X.config(xscrollcommand=self.scrb_X.set)
  882. #self.scrb_X.pack(side='bottom', fill='x')
  883. #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
  884. #self.config(xscrollcommand=scrb_X.set)
  885. #scrb_X.pack(side='bottom', fill='x')
  886. #scrb= tk.Scrollbar(self, orient='vertical', command=self.yview)
  887. #self.config(yscrollcommand=scrb.set)
  888. #scrb.pack(side='right', fill='y')
  889. #self.config(height = 240, width = 1000) # didn't get the size baCK TO NORMAL
  890. #self.pack(side='left', fill='both', expand=True) # didn't get the size baCK TO NORMAL
  891. # pop-up menu
  892. self.popup = tk.Menu(self, tearoff=0)
  893. self.popup.add_command(label='Copy', command=self._copy)
  894. self.popup.add_command(label='Paste', command=self._paste)
  895. self.popup.add_separator()
  896. self.popup.add_command(label='Cut', command=self._cut)
  897. self.popup.add_separator()
  898. self.popup.add_command(label='Select All', command=self._select_all)
  899. self.popup.add_command(label='Clear All', command=self._clear_all)
  900. self.popup.add_separator()
  901. self.popup.add_command(label='Save As', command=self._file_save_as)
  902. self.popup.add_separator()
  903. #self.popup.add_command(label='Repeat Build(CTL-shift-r)', command=self._rebuild)
  904. self.popup.add_command(label='Repeat Build', command=self._rebuild)
  905. self.popup.add_separator()
  906. self.popup.add_command(label='Scroll Errors (CTL-shift-e)', command=self._scroll_errors)
  907. self.popup.add_separator()
  908. self.popup.add_command(label='Open File at Cursor', command=self._open_selected_file)
  909. if current_OS == 'Darwin': # MAC
  910. self.bind('<Button-2>', self._show_popup) # macOS only
  911. else:
  912. self.bind('<Button-3>', self._show_popup) # Windows & Linux
  913. # threading & subprocess section
  914. def start_thread(self, ):
  915. global continue_updates
  916. # create then start a secondary thread to run an arbitrary function
  917. # must have at least one argument
  918. self.secondary_thread = threading.Thread(target=lambda q, arg1: q.put(run_PIO(arg1)), args=(que, ''))
  919. self.secondary_thread.start()
  920. continue_updates = True
  921. # check the Queue in 50ms
  922. self.root.after(50, self.check_thread)
  923. self.root.after(50, self.update)
  924. def check_thread(self): # wait for user to kill the window
  925. global continue_updates
  926. if continue_updates == True:
  927. self.root.after(10, self.check_thread)
  928. def update(self):
  929. global continue_updates
  930. if continue_updates == True:
  931. self.root.after(10, self.update) #method is called every 50ms
  932. temp_text = ['0', '0']
  933. if IO_queue.empty():
  934. if not (self.secondary_thread.is_alive()):
  935. continue_updates = False # queue is exhausted and thread is dead so no need for further updates
  936. else:
  937. try:
  938. temp_text = IO_queue.get(block=False)
  939. except Queue.Empty:
  940. continue_updates = False # queue is exhausted so no need for further updates
  941. else:
  942. self.insert('end', temp_text[0], temp_text[1])
  943. self.see("end") # make the last line visible (scroll text off the top)
  944. # text editing section
  945. def _scroll_errors(self):
  946. global search_position
  947. global error_found
  948. if search_position == '': # first time so highlight all errors
  949. countVar = tk.IntVar()
  950. search_position = '1.0'
  951. search_count = 0
  952. while search_position != '' and search_count < 100:
  953. search_position = self.search("error", search_position, stopindex="end", count=countVar, nocase=1)
  954. search_count = search_count + 1
  955. if search_position != '':
  956. error_found = True
  957. end_pos = '{}+{}c'.format(search_position, 5)
  958. self.tag_add("error_highlight_inactive", search_position, end_pos)
  959. search_position = '{}+{}c'.format(search_position, 1) # point to the next character for new search
  960. else:
  961. break
  962. if error_found:
  963. if search_position == '':
  964. search_position = self.search("error", '1.0', stopindex="end", nocase=1) # new search
  965. else: # remove active highlight
  966. end_pos = '{}+{}c'.format(search_position, 5)
  967. start_pos = '{}+{}c'.format(search_position, -1)
  968. self.tag_remove("error_highlight_active", start_pos, end_pos)
  969. search_position = self.search(
  970. "error", search_position, stopindex="end", nocase=1
  971. ) # finds first occurrence AGAIN on the first time through
  972. if search_position == "": # wrap around
  973. search_position = self.search("error", '1.0', stopindex="end", nocase=1)
  974. end_pos = '{}+{}c'.format(search_position, 5)
  975. self.tag_add("error_highlight_active", search_position, end_pos) # add active highlight
  976. self.see(search_position)
  977. search_position = '{}+{}c'.format(search_position, 1) # point to the next character for new search
  978. def scroll_errors(self, event):
  979. self._scroll_errors()
  980. def _rebuild(self):
  981. #global board_name
  982. #global Marlin_ver
  983. #global target_env
  984. #board_name, Marlin_ver = get_board_name()
  985. #target_env = get_env(board_name, Marlin_ver)
  986. self.start_thread()
  987. def rebuild(self, event):
  988. print("event happened")
  989. self._rebuild()
  990. def _open_selected_file(self):
  991. current_line = self.index('insert')
  992. line_start = current_line[:current_line.find('.')] + '.0'
  993. line_end = current_line[:current_line.find('.')] + '.200'
  994. self.mark_set("path_start", line_start)
  995. self.mark_set("path_end", line_end)
  996. path = self.get("path_start", "path_end")
  997. from_loc = path.find('from ')
  998. colon_loc = path.find(': ')
  999. if 0 <= from_loc and ((colon_loc == -1) or (from_loc < colon_loc)):
  1000. path = path[from_loc + 5:]
  1001. if 0 <= colon_loc:
  1002. path = path[:colon_loc]
  1003. if 0 <= path.find('\\') or 0 <= path.find('/'): # make sure it really contains a path
  1004. open_file(path)
  1005. def _file_save_as(self):
  1006. self.filename = fileDialog.asksaveasfilename(defaultextension='.txt')
  1007. f = open(self.filename, 'w')
  1008. f.write(self.get('1.0', 'end'))
  1009. f.close()
  1010. def copy(self, event):
  1011. try:
  1012. selection = self.get(*self.tag_ranges('sel'))
  1013. self.clipboard_clear()
  1014. self.clipboard_append(selection)
  1015. except TypeError:
  1016. pass
  1017. def cut(self, event):
  1018. try:
  1019. selection = self.get(*self.tag_ranges('sel'))
  1020. self.clipboard_clear()
  1021. self.clipboard_append(selection)
  1022. self.delete(*self.tag_ranges('sel'))
  1023. except TypeError:
  1024. pass
  1025. def _show_popup(self, event):
  1026. '''right-click popup menu'''
  1027. if self.root.focus_get() != self:
  1028. self.root.focus_set()
  1029. try:
  1030. self.popup.tk_popup(event.x_root, event.y_root, 0)
  1031. finally:
  1032. self.popup.grab_release()
  1033. def _cut(self):
  1034. try:
  1035. selection = self.get(*self.tag_ranges('sel'))
  1036. self.clipboard_clear()
  1037. self.clipboard_append(selection)
  1038. self.delete(*self.tag_ranges('sel'))
  1039. except TypeError:
  1040. pass
  1041. def cut(self, event):
  1042. self._cut()
  1043. def _copy(self):
  1044. try:
  1045. selection = self.get(*self.tag_ranges('sel'))
  1046. self.clipboard_clear()
  1047. self.clipboard_append(selection)
  1048. except TypeError:
  1049. pass
  1050. def copy(self, event):
  1051. self._copy()
  1052. def _paste(self):
  1053. self.insert('insert', self.selection_get(selection='CLIPBOARD'))
  1054. def _select_all(self):
  1055. self.tag_add('sel', '1.0', 'end')
  1056. def select_all(self, event):
  1057. self.tag_add('sel', '1.0', 'end')
  1058. def _clear_all(self):
  1059. #'''erases all text'''
  1060. #
  1061. #isok = askokcancel('Clear All', 'Erase all text?', frame=self,
  1062. # default='ok')
  1063. #if isok:
  1064. # self.delete('1.0', 'end')
  1065. self.delete('1.0', 'end')
  1066. # end - output_window
  1067. def main():
  1068. ##########################################################################
  1069. # #
  1070. # main program #
  1071. # #
  1072. ##########################################################################
  1073. global build_type
  1074. global target_env
  1075. global board_name
  1076. board_name, Marlin_ver = get_board_name()
  1077. target_env = get_env(board_name, Marlin_ver)
  1078. # Re-use the VSCode terminal, if possible
  1079. if os.environ.get('PLATFORMIO_CALLER', '') == 'vscode':
  1080. sys_PIO()
  1081. else:
  1082. auto_build = output_window()
  1083. auto_build.start_thread() # executes the "run_PIO" function
  1084. auto_build.root.mainloop()
  1085. if __name__ == '__main__':
  1086. main()