From cdcf451e445d02970fbd8db1b97ae2f0b8fb7281 Mon Sep 17 00:00:00 2001 From: Fabrice Salvaire Date: Mon, 24 Dec 2018 04:05:15 +0100 Subject: [PATCH] enabled pyterate --- .gitignore | 1 + examples/annotate-gcode.py | 37 ------------------- examples/gcode/annotate-gcode.py | 62 ++++++++++++++++++++++++++++++++ examples/index.rst | 7 ++++ tools/make-examples | 15 ++++++++ 5 files changed, 85 insertions(+), 37 deletions(-) delete mode 100644 examples/annotate-gcode.py create mode 100644 examples/gcode/annotate-gcode.py create mode 100644 examples/index.rst create mode 100755 tools/make-examples diff --git a/.gitignore b/.gitignore index 2e04976..7a6d703 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ __pycache__ doc/sphinx/build/ doc/sphinx/source/api/ +doc/sphinx/source/examples/ lextab.py parser.out diff --git a/examples/annotate-gcode.py b/examples/annotate-gcode.py deleted file mode 100644 index 99cfcc9..0000000 --- a/examples/annotate-gcode.py +++ /dev/null @@ -1,37 +0,0 @@ -#################################################################################################### - -"""Example to show how to annote a G-code program. -""" - -#################################################################################################### - -from pathlib import Path - -from PythonicGcodeMachine.Gcode.Rs274 import GcodeParser, gcodes, letters - -#################################################################################################### - -program_filename = 'mill-example-1.ngc' - -programs_directory = Path(__file__).parent.joinpath('programs') -program_path = programs_directory.joinpath(program_filename) -with open(program_path, 'r') as fh: - lines = fh.readlines() - if lines[0].startswith(';'): - lines = lines[1:] - -parser = GcodeParser() -program = parser.parse_lines(lines) - -meaning_format = ' {:5}: {}' -for line in program: - print() - print(line.ansi_str()) - for word in line.iter_on_word(): - if word.letter in 'GM': - meaning = gcodes[str(word)].meaning - print(meaning_format.format(str(word), meaning)) - else: - letter = word.letter - meaning = letters[letter].meaning - print(meaning_format.format(letter, meaning)) diff --git a/examples/gcode/annotate-gcode.py b/examples/gcode/annotate-gcode.py new file mode 100644 index 0000000..60ddcc3 --- /dev/null +++ b/examples/gcode/annotate-gcode.py @@ -0,0 +1,62 @@ +#?################################################################################################## +#?# +#?# PythonicGcodeMachine - @licence_header_description@ +#?# Copyright (C) 2018 Fabrice Salvaire +#?# +#?# This program is free software: you can redistribute it and/or modify +#?# it under the terms of the GNU General Public License as published by +#?# the Free Software Foundation, either version 3 of the License, or +#?# (at your option) any later version. +#?# +#?# This program is distributed in the hope that it will be useful, +#?# but WITHOUT ANY WARRANTY; without even the implied warranty of +#?# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#?# GNU General Public License for more details. +#?# +#?# You should have received a copy of the GNU General Public License +#?# along with this program. If not, see . +#?# +#?################################################################################################## + +#################################################################################################### + +#r# +#r# ================================================== +#r# Example to show how to annotate a G-code program +#r# ================================================== +#r# + +#################################################################################################### + +from pathlib import Path + +from PythonicGcodeMachine.Gcode.Rs274 import GcodeParser, gcodes, letters + +#################################################################################################### + +program_filename = 'mill-example-1.ngc' + +programs_directory = Path(__file__).parents[1].joinpath('programs') +program_path = programs_directory.joinpath(program_filename) +with open(program_path, 'r') as fh: + lines = fh.readlines() + if lines[0].startswith(';'): + lines = lines[1:] + +parser = GcodeParser() +program = parser.parse_lines(lines) + +meaning_format = ' {:5}: {}' +for line in program: + print() + # print(line.ansi_str()) # Fixme: pyterate + print(str(line)) + for word in line.iter_on_word(): + if word.letter in 'GM': + meaning = gcodes[str(word)].meaning + print(meaning_format.format(str(word), meaning)) + else: + letter = word.letter + meaning = letters[letter].meaning + print(meaning_format.format(letter, meaning)) +#o# diff --git a/examples/index.rst b/examples/index.rst new file mode 100644 index 0000000..d99e629 --- /dev/null +++ b/examples/index.rst @@ -0,0 +1,7 @@ +.. -*- Mode: rst -*- + +.. _examples-page: + +========== + Examples +========== diff --git a/tools/make-examples b/tools/make-examples new file mode 100755 index 0000000..43aa9a4 --- /dev/null +++ b/tools/make-examples @@ -0,0 +1,15 @@ +#! /usr/bin/bash + +# Regenerate from scratch +# examples=doc/sphinx/source/examples +# rm -rf ${examples} + +echo +echo Generate RST examples files +MusicaLogLevel=WARNING pyterate # --force + +echo +echo Run Sphinx +pushd doc/sphinx/ +./make-html # --clean +popd -- GitLab