From 95eaad329246398910ed2ecedc04d7512f0b6bab Mon Sep 17 00:00:00 2001 From: Lukáš Růžička Date: Jul 03 2020 11:28:03 +0000 Subject: Fix interpreter errors and connect to messagebox. --- diff --git a/interpreter.py b/interpreter.py index 60808c7..f451807 100644 --- a/interpreter.py +++ b/interpreter.py @@ -162,6 +162,7 @@ class Interpreter: def draw_needle_area(self, area, input_file, needled_file, lang): """ Takes the needle are and draws a rectangle on the saved needle and saves it under a new name 'stepXX.png' to enable activity illustration using the pngs. """ + #FIXME: Here the needle json file should be created. if lang == "openqa": shutil.copy(input_file, needled_file) else: @@ -394,12 +395,15 @@ class Interpreter: def translate(self, lang): """ Translates actions into various output formats to make a nice report. """ - mbox = messages.Messagebox() + mbox = messages.Messagebox(lang) + + if lang == "html": + report_lines = ["", "", "
    "] if not self.human_report: - report_lines = [mbox.title(lang), "Error! No report has been found."] + report_lines.append("Error! No report has been found.") else: - report_lines = [mbox.title(lang)] + report_lines.append(mbox.title()) # Read the events from the simplified and cleaned dictionary. events = list(self.human_report.keys()) # Make sure the keys are sorted chronologically. @@ -422,7 +426,6 @@ class Interpreter: pass # If this event is a click. if 'click' in data['action']: - print(data['action']) # Read the needle area of the click. area = data['needle-area'] # Take the screenshot and needle it (see the method for further info). @@ -433,18 +436,23 @@ class Interpreter: key = data['text'] if key == "Ħ": key = "shift" - prefix = mbox.combo_prefix(key, lang) + prefix = mbox.combo_prefix(key) + if not prefix: + if lang == "md": + prefix = "1. " + elif lang == "html": + prefix = "
  1. " if 'double' in data['action']: - suffix = mbox.double_click(button, position, nfname, lang) + suffix = mbox.double_click(button, position, nfname) else: - suffix = mbox.click(button, position, nfname, lang) + suffix = mbox.click(button, position, nfname) line = prefix + suffix # If this event is a scroll, read more info related to scrolling. elif 'scroll' in data['action']: steps = data['steps'] direction = data['direction'] # And use a different info string. - line = "{}. Scroll mouse in **{}** step(s) to the **{}**.".format(numbering, steps, direction) + line = mbox.scroll(steps, direction) # If this is a dragging action elif 'drag' in data['action']: # Read drag related info @@ -461,9 +469,14 @@ class Interpreter: key = data['text'] if key == "Ħ": key = "shift" - prefix = "Press the **{}** key and".format(data['text']) - line = "{}. {} Click with **{}** button at position *{}*, drag the mouse to position \ -*{}* and release the button. See `{}` for the area defined by the action.".format(numbering, prefix, button, start, position, nfname) + prefix = mbox.combo_prefix(key) + if not prefix: + if lang == "md": + prefix = "1. " + elif lang == "html": + prefix = "
  2. " + suffix = mbox.drag(button, start, end, nfname) + line = prefix + suffix # If the previous choices were not valid, something very weird must have happened, # like extraterrestrians have kidnapped the world or something. This should never happen. else: @@ -483,30 +496,34 @@ class Interpreter: shutil.copy(after, f"{nfname}.png") # If more than just the modifier is pressed, some text exists, use it. if text and text == "Ħ": - line = "{}. Press the **shift** modifier key.".format(numbering) + line = mbox.keypress(text, "modifier", hold=False) elif text: - line = "{}. Press the **{}** key combination. See `{}` for a \ -screen suggested to assert.".format(numbering, text, nfname) + line = mbox.keypress(text, "combination", hold=False, needle=nfname) elif 'hold' in data['action']: - line = "{}. Press and hold the **{}** modifier key.".format(numbering, text) + line = mbox.keypress(text, "modifier", hold=True) # If only the one modifier is pressed, than report it as a single key. else: - line = "{}. Press the **{}** modifier key. See `{}` for a screen suggested to assert.".format(numbering, key, nfname) + line = mbox.keypress(key, "modifier", hold=False, needle=nfname) # If one of the special keys is pressed, report it. elif 'special' in data['action'] or 'tab' in data['action']: shutil.copy(after, f"{nfname}.png") - line = "{}. Press the **{}** key. See `{}` for a screen suggested to assert".format(numbering, key, nfname) + line = mbox.keypress(key, needle=nfname) # If a normal key is pressed. elif 'key_pressed' == data['action']: - line = "{}. Press the **{}** key." + line = mbox.keypress(key) else: # This should never happen. line = f"""{numbering}. Do something with the keyboard, but I am not sure what. """ # If typing has produced some output, report it here. - elif 'type' in data['action']: + if 'type' in data['action']: text = data['text'] - line = f"""{numbering}. Type *{text}*. """ + line = mbox.type(text) report_lines.append(line) + if lang == "html": + report_lines.append("
") + report_lines.append("") + report_lines.append("") + return report_lines