def tablprocess(): """ здесь собсно обрабатывается запрос на генерацию табулатуры из кода """ Logger.clear() session_id = request.get_cookie('beaker.session.id') if session_id is None: Logger.log('no session from your side') return template('index', output=session_id, log_records=Logger.get(), name='', typer='', code='') name = request.forms.get('name') or '' typer = request.forms.get('typer') or '' code = request.forms.get('code') or '' share = request.forms.get('share') or '' request.session['name'] = name request.session['typer'] = typer request.session['code'] = code request.session['share'] = share lines = map(lambda x: x.strip(), code.split("\n")) TablMaker.process(lines, name, 'output/' + session_id + '.png') if share == 'on': library.add_tabl(typer, name, code, session_id) return template('index', output=session_id, log_records=Logger.get(), name=name, typer=typer, code=code, share=share)
def draw(self, stave_image): for trip in self._triplets: #trip.print_explode() if trip.start is None or trip.final is None: Logger.log('triplet not complete') continue with Drawing() as draw, Color('black') as color: draw.stroke_width = 1 draw.stroke_color = color draw.line((trip.start.get_line_offset() + 0, Config.draw_center - 18), (trip.final.get_line_offset() + 5, Config.draw_center - 18)) draw.line((trip.start.get_line_offset() + 0, Config.draw_center - 18), (trip.start.get_line_offset() + 0, Config.draw_center - 14)) draw.line((trip.final.get_line_offset() + 5, Config.draw_center - 18), (trip.final.get_line_offset() + 5, Config.draw_center - 14)) draw.draw(stave_image) trip_file = Config.static_unit_dir + 'figure_3.png' trip_mark = Image(filename=trip_file) stave_image.composite(trip_mark, trip.start.get_line_offset() + 6, Config.draw_center - 26)
def draw(self, stave_image): for item in self._ligas: #item.print_explode() if item.finish is None: Logger.log("liga is not finished: " + str(self._ligas.index(item))) continue if item.direction is None: if item.start.get_stave_offset() > Config.draw_center: item.direction = 'down' if item.start.get_stave_offset() < Config.draw_center: item.direction = 'up' if item.start.get_stave_offset() == Config.draw_center: if item.finish.get_stave_offset() > Config.draw_center: item.direction = 'down' if item.finish.get_stave_offset() < Config.draw_center: item.direction = 'up' if item.finish.get_stave_offset() == Config.draw_center: item.direction = 'up' (p0_x, p0_y, p1_x, p1_y, p2_x, p2_y, p3_x, p3_y) = [0] * 8 p0_x = item.start.get_line_offset() + 4 p3_x = item.finish.get_line_offset() - 1 p1_x = p0_x + (p3_x-p0_x) / 3 p2_x = p3_x - (p3_x-p0_x) / 3 if item.direction == 'down': p0_y = item.start.get_stave_offset() + 5 p3_y = item.finish.get_stave_offset() + 5 p1_y = p0_y + (p3_y-p0_y) / 3 + (p3_x-p0_x) / 3 p2_y = p3_y - (p3_y-p0_y) / 3 + (p3_x-p0_x) / 3 if item.direction == 'up': p0_y = item.start.get_stave_offset() - 4 p3_y = item.finish.get_stave_offset() - 4 p1_y = p0_y + (p3_y-p0_y) / 3 - (p3_x-p0_x) / 3 p2_y = p3_y - (p3_y-p0_y) / 3 - (p3_x-p0_x) / 3 with Drawing() as draw: draw.fill_color = Color('transparent') draw.stroke_color = Color('black') draw.bezier(((p0_x, p0_y), (p1_x, p1_y), (p2_x, p2_y), (p3_x, p3_y))) draw.draw(stave_image)
from wand.image import Image check = 'tr t34 c4 d4 e4' result = LineMaker.process(check) result.save(filename='test.png') check = 'tr [!down (!up b8 a8 ) ]' result = LineMaker.process(check) result.save(filename='test.png') check = 'tr varc c4 d4 e4 novar' result = LineMaker.process(check) result.save(filename='test_mark.png') check = ['tr t34 c4 d4 e4', 'tr f4 g4 a4'] result = TablMaker.process(check, 'test', 'test2.png') check = 'tr c0#' result = LineMaker.process(check) result.save(filename='test_empty.png') check = 'tr 333 c1 d1 e1' result = LineMaker.process(check) result.save(filename='test_trip.png') from service.logger import Logger Logger.log('foobar') print(Logger.get())