예제 #1
0
 def _find_ctrl(self, parent, name=None, label=None, wxid=None, pos=None, wx_classname=None):
     try:
         self.find_wx_ctrl(parent, name, label, wxid, pos, wx_classname)
         self.find_win_ctrl(parent, name, label, wxid, pos, wx_classname)
     except Found, ex:
         Logger.add_debug(ex.message)
         return
예제 #2
0
 def describe_wxdialog(self, win, level=0):
     if win is None:
         return
     Logger.newline()
     Logger.bold_header("wx Description\n  Name:             '%s'\n  ClassName:        '%s'\n  Label:            '%s'\n  Nbr of children:  %d" % (win.get_name(), win.get_classname(), win.get_label(), win.get_nbr_of_children()))
     if win.get_nbr_of_children() > 0:
         self.describe_wxdialog_windows(win)
예제 #3
0
 def describe(self, frame):
     try:
         menu_bar = frame.GetMenuBar()
         if menu_bar is not None:
             self.describe_menu_bar(menu_bar)
             Logger.add(" ")
     except AttributeError:
         pass
예제 #4
0
 def _test(self):
     Logger.set_path(self.manuscript.get_log_path())
     Logger.set_log_dialog_descriptions(self.appargs.log_dialog_descriptions())
     Logger.add_debug("Application arguments")
     Logger.add_debug(" ".join(sys.argv))
     Logger.add_section("Manuscript", u"%s" % self.manuscript)
     instructions = Instructions(self.manuscript, self.appargs.timedelay())
     start_app(instructions, self.appargs.program())
예제 #5
0
 def register_dialog(self, win=None):
     if win is None:
         return
     Logger.add_debug("Registering window: %s" % win)
     self.windows.append(win)
     if not self.execution_started:
         Logger.add_instruction("Execution of instructions start")
         self.execution_started = True
         wx.CallLater(TIME_TO_WAIT_BEFORE_CONTINUING_IN_MILLISECONDS, self.execute_next_instruction)
예제 #6
0
 def run(self):
     if self.appargs.investigate():
         self._log_effective_manuscript()
     else:
         try:
             self._test()
         finally:
             Logger.log()
     return not Logger.has_errors()
예제 #7
0
 def wrap(instruction_line, tokens):
     try:
         rv = f(instruction_line, tokens)
         if rv is None:
             raise InstructionSyntaxException("")
         else:
             return rv
     except InstructionSyntaxException:
         Logger.add_error("Invalid instruction: '%s'. Instruction ignored" % instruction_line)
         raise
예제 #8
0
 def find_menu(self, args):
     try:
         win = wx.GetApp().GetTopWindow()
         item_id = self._find_menu_item_id(args)
         if item_id != wx.NOT_FOUND:
             self.item_id = item_id
             raise Found("Menu found")
     except Found, ex:
         Logger.add_debug(ex.message)
         return
예제 #9
0
 def find_win_by_name_or_label(self, name_or_label):
     self.wxctrl = None
     self.winctrl = None
     try:
         if name_or_label is None:
             self.wxctrl = wx.GetApp().GetTopWindow()
             raise Found("Top window")
         for name in name_or_label.split("|"):
             name = name.strip()
             self.find_wx_win(name, name)
             self.find_win_win(name)
     except Found, ex:
         Logger.add_debug(ex.message)
         return
예제 #10
0
 def execute_next_instruction(self):
     try:
         instruction = self._next_instruction()
         instruction._replace_placeholders()
         self._display_instruction_in_popup_window(instruction)
         if isinstance(instruction, AddPlaceholderInstruction):
             delay = 0
         else:
             # TODO: We have some timing problem so we can't set
             #       waiting time to 0. 40 seems to be ok,
             delay = max(40, self.timedelay * 1000)
         Logger.add_debug("Preparing instruction '%s' for execution with delay %d" % (instruction, delay))
         wx.CallLater(delay, self._execute_instruction, instruction)
     except NoMoreInstructionsException:
         Logger.add_instruction("The last instruction has been executed")
예제 #11
0
 def describe_menu(self, menu, name):
     Logger.add(" ")
     Logger.add("   Menu: '%s'    Item count: %d" % (name, menu.MenuItemCount))
     Logger.add("        Id   Label                      Text")
     Logger.add("      ----   ------------------------   ---------------------")
     for item in menu.MenuItems:
         self.describe_menu_item(item)
         if item.SubMenu is not None and item.SubMenu.MenuItemCount > 0:
             self.describe_submenu(item.SubMenu)
예제 #12
0
 def __init__(self, manuscript, timedelay):
     self.timedelay = timedelay
     self.popup = None
     self.execution_started = False
     self.windows = []
     self.instructions = []
     for line in [
         line for line in manuscript.get_instructions() if not line.startswith("#") and len(line.strip()) > 0
     ]:
         try:
             instruction = parse(line)
         except Exception:
             Logger.add_error("Can't parse instruction: '%s'" % line)
             raise
         if instruction is not None:
             self.instructions.append(instruction)
     collector = []
     for instruction in self.instructions:
         collector.append(instruction.to_unicode())
     Logger.header("Effective Instructions:\n   %s" % "\n   ".join(collector))
예제 #13
0
 def describe_children(self, hwnd):
     Logger.add("    hwnd     Classname                 ScreenPos    Label")
     Logger.add("    -------  ------------------------  ------------ ------------------")
     children = facade.get_children(hwnd)
     for hwnd, class_name, text in children:
         rect = facade.get_window_rect(hwnd)
         Logger.add("   %8d  %-24.24s  (%4d, %4d) '%s'" % (hwnd, class_name, rect[0], rect[1], text))
예제 #14
0
 def _validate_windows(self):
     """Make sure the topmost window in the list self.windows is still
     valid. If not, remove it from the list and continue checking the
     list until the list is exhausted or a valid dialog is found.
     """
     self.windows.reverse()
     while len(self.windows) > 1:
         win = self.windows[0]
         try:
             win.get_label()
             try:
                 if not win.IsShown():
                     self.windows = self.windows[1:]
                 else:
                     break
             except:
                 Logger.add_debug("Window is not visible")
                 break
         except:
             Logger.add_debug("get_window_text fails")
             self.windows = self.windows[1:]
     self.windows.reverse()
예제 #15
0
def run_python_file(args):
        """Run a python file as if it were the main program on the command line.

        `args` is the argument array to present as sys.argv, including the first
        element representing the file being executed.

        Lifted straight from coverage.py by Ned Batchelder

        """
        try:
            # In Py 2.x, the builtins were in __builtin__
            BUILTINS = sys.modules['__builtin__']
        except KeyError:  # pragma: no cover - not worried about Python 3 yet...
            # In Py 3.x, they're in builtins
            BUILTINS = sys.modules['builtins']

        filename = args[0]

        # Create a module to serve as __main__
        old_main_mod = sys.modules['__main__']
        main_mod = imp.new_module('__main__')
        sys.modules['__main__'] = main_mod
        main_mod.__file__ = filename
        main_mod.__builtins__ = BUILTINS

        # Set sys.argv and the first path element properly.
        old_argv = sys.argv
        old_path0 = sys.path[0]
        sys.argv = args
        sys.path[0] = os.path.dirname(filename)

        try:
            sys.stdout = open('outfile.txt', 'w')
            source = open(filename, 'rU').read()
            exec compile(source, filename, "exec") in main_mod.__dict__
        except Exception, ex:
            Logger.add_error("%s" % ex)
            Logger.failure("Exception in application")
예제 #16
0
def get_environment_path(environment_variable, filename):
    try:
        home = os.environ[environment_variable]
        path = os.path.join(home, filename)
        Logger.add_debug("   Path: %s" % path)
        if os.path.exists(path):
            Logger.add_debug("   Found")
            return path
    except:
        pass
    Logger.add_debug("   Not found")
예제 #17
0
 def describe_window(self, hwnd=None):
     if facade.has_win_implementation():
         try:
             nbr_of_children = len(facade.get_children(hwnd))
             if hwnd is None:
                 hwnd = facade.get_active_window()
             rect = facade.get_window_rect(hwnd)
             Logger.bold_header("Window Description \n   hwnd:            %d \n   Classname:       '%s' \n   Label:           '%s'\n   Nbr of children: %d\n   Position:        (%d, %d)\n   Size:            (%d, %d)" % (
                 hwnd, facade.get_classname(hwnd), facade.get_window_text(hwnd), nbr_of_children, rect[0], rect[1], rect[2], rect[3]))
             Logger.header2("Native Description")
             self.describe_children(hwnd)
         except Exception, ex:
             Logger.add_error("Native windows description failed")
예제 #18
0
 def _get_current_window(self):
     Logger.add_debug("self.windows: %s" % self.windows)
     self._validate_windows()
     Logger.add_debug("self.windows: %s" % self.windows)
     try:
         current_window = self.windows[-1]
     except:
         current_window = None
     # MessageBox windows seems to to return ok on get_window_text(win.hwnd)
     # even though the dialog is closed!
     # So we remove it here because the only thing you can do is clicking a
     # a button and thereafter the dialog is closed.
     if current_window.messagebox:
         del (self.windows[-1])
     Logger.add_debug("current_window: %s" % current_window)
     return current_window
예제 #19
0
 def Destroy(self, *args, **kw):
     self.shown = False
     Logger.add_result("Dialog '%s' closed" % self.GetLabel())
     wxTextEntryDialog.Destroy(self, *args, **kw)
예제 #20
0
 def Destroy(self, *args, **kw):
     self.shown = False
     Logger.add_close(self)
     wxPageSetupDialog.Destroy(self, *args, **kw)
예제 #21
0
 def Destroy(self, *args, **kw):
     self.shown = False
     Logger.add_result("Dialog '%s' closed" % self.GetLabel())
     wxSingleChoiceDialog.Destroy(self, *args, **kw)
예제 #22
0
 def ShowModal(self):
     self._shown = True
     Logger.add_open(self)
     self.call_when_win_shows(self._explore_and_register)
     return super(FileDialog, self).ShowModal()
예제 #23
0
 def Hide(self):
     self._shown = False
     Logger.add_close(self)
     super(Frame, self).Hide()
예제 #24
0
 def Destroy(self, *args, **kw):
     Logger.add("Destroy called")
     self._shown = False
     Logger.add_close(self)
     wxFrame.Destroy(self, *args, **kw)
예제 #25
0
 def add_placeholder(self):
     Logger.add_placeholder(self.arg(1), self.arg(2))
예제 #26
0
 def Destroy(self, *args, **kw):
     self._shown = False
     Logger.add_close(self)
     wxDialog.Destroy(self, *args, **kw)
예제 #27
0
 def _execute_instruction(self, instruction):
     Logger.add_instruction(instruction)
     current_window = self._get_current_window()
     instruction.execute(self, current_window)
예제 #28
0
 def ShowModal(self, *args, **kw):
     self.shown = True
     Logger.add_result("Dialog opened")
     wx.CallLater(TIME_TO_WAIT_FOR_DIALOG_TO_SHOW_IN_MILLISECONDS,
                  self._register_and_explore)
     super(CubeColourDialog, self).ShowModal(*args, **kw)
예제 #29
0
 def Destroy(self, *args, **kw):
     self.shown = False
     Logger.add_result("Dialog '%s' closed" % self.GetLabel())
     wxCubeColourDialog.Destroy(self, *args, **kw)
예제 #30
0
 def PrintDialog(self, *args, **kw):
     self._shown = True
     Logger.add_open(self)
     self.call_when_win_shows(self._explore_and_register)
     super(Printer, self).PrintDialog(*args, **kw)
     self._shown = False
예제 #31
0
def start_app(myinstructions, path):
    global instructions
    instructions = myinstructions
    Logger.bold_header("Starting application %s" % os.path.basename(path))
    wrap_wx_classes()
    run_python_file([path, ])
예제 #32
0
 def select_listbox_item(self, classname):
     try:
         self._select_listbox_item(classname)
     except NotFoundException:
         Logger.failure(self.result_message("NOT Found"))
예제 #33
0
 def Destroy(self, *args, **kw):
     self._shown = False
     Logger.add_close(self)
     wxDirDialog.Destroy(self, *args, **kw)
예제 #34
0
def find_path(manuscript, paths):
    Logger.add_debug("Searching data as given: %s" % manuscript)
    if os.path.exists(manuscript):
        Logger.add_debug("   Found")
        return manuscript
    Logger.add_debug("   Not found")
    Logger.add_debug("Searching data with given paths")
    if len(paths) == 0:
        Logger.add_debug("   No paths given")
    for path in paths:
        Logger.add_debug("   Path: %s" % os.path.join(path, manuscript))
        if os.path.exists(os.path.join(path, manuscript)):
            Logger.add_debug("   Found")
            return os.path.join(path, manuscript)
        Logger.add_debug("   Not found")
    Logger.add_debug("Searching data with environment var paths")
    for envar in ["USER_HOME", "AUTOPILOT_HOME"]:
        path = get_environment_path(envar, manuscript)
        if path is not None:
            return path
예제 #35
0
 def ShowModal(self):
     self.shown = True
     Logger.add_open(self)
     self.call_when_win_shows(self._explore_and_register)
     super(PageSetupDialog, self).ShowModal()
예제 #36
0
def scan(text):

    global _tab_count
    global _print_unknown_only
    global _first_char_on_line
    global _col

    prevcol = 1
    _tab_count = 0
    _col = 0

    text = text.strip()
    nbr_of_chars = len(text)
    i = 0
    nbr_of_unkown = 0
    tokens = []
    _first_char_on_line = ' '

    while i < nbr_of_chars:
        lexeme = u"unknown"
        typename = "Unknown"
        token = UNKNOWN
        subid = None

        # Comment
        if i == 0 and text[i] == '#':
            lexeme = text.decode("utf-8")
            typename = "Comment"
            token = Token(KEYWORD, text, ID_COMMENT, col=0)
            tokens.append(token)
            return tokens

        # Space
        elif text[i] == ' ':
            lexeme = u" "
            typename = "Space"
            token = SPACE

        # Tab
        elif text[i] == '\t':
            lexeme = u" "
            typename = "Tab"
            token = TAB
            _tab_count = _tab_count + 1

        # Left Parenthesis
        elif text[i] == '(':
            lexeme = u"("
            typename = "Left Parenthesis"
            token = LP

        # Right Parenthesis
        elif text[i] == ')':
            lexeme = u")"
            typename = "Right Parenthesis"
            token = RP

        elif text[i] == '=':
            lexeme = u"="
            typename = "Equal sign"
            token = EQ

        elif text[i] == '+':
            lexeme = u"+"
            typename = "Plus sign"
            token = PLUS

        elif text[i] == ',':
            lexeme = u","
            typename = "Comma"
            token = COMMA

        elif text[i] == '|':
            lexeme = u"|"
            typename = "Or"
            token = OR

        elif text[i] == '"':
            lexeme, token, subid, i = _parse_string(text, i)
            typename = "String"
            _col = i + 1

        elif text[i] == "'":
            lexeme, token, subid, i = _parse_string(text, i)
            typename = "String"
            _col = i + 1

        elif text[i].isalnum() or text[i] in ID_SPECIAL_CHARS:
            lexeme, token, subid, i = _parse_identifier(text, i)
            typename = "Identifier"
            _col = i + 1

        # Unknown token
        else:
            if text[i].isspace():
                lexeme = u" "
                typename = "Space"
                token = SPACE
            else:
                nbr_of_unkown = nbr_of_unkown + 1
                lexeme = u"%c" % text[i]

        i += 1
        _col += 1

        # Print result
        if _print_unknown_only:
            if (token == UNKNOWN):
                msg = "%d %d %s %s" % (i, token, typename, lexeme)
                Logger.add_error(msg)

        if typename != "Space":
            token = Token(token, lexeme, subid, col=prevcol)
            tokens.append(token)
        prevcol = _col

    if nbr_of_unkown > 0:
        msg = "Nbr of unknown tokens encountered = %d" % nbr_of_unkown
        Logger.add_error(msg)

    return tokens
예제 #37
0
 def ShowModal(self, *args, **kw):
     self.shown = True
     Logger.add_result("Dialog opened")
     wx.CallLater(TIME_TO_WAIT_FOR_DIALOG_TO_SHOW_IN_MILLISECONDS, self._register_and_explore)
     super(TextEntryDialog, self).ShowModal(*args, **kw)
예제 #38
0
 def ShowModal(self):
     Logger.add_result("MessageDialog opened")
     wx.CallLater(TIME_TO_WAIT_FOR_DIALOG_TO_SHOW_IN_MILLISECONDS,
                  self._explore, MessageDialog.listener)
     return super(MessageDialog, self).ShowModal()
예제 #39
0
 def _log_effective_manuscript(self):
     Logger.set_path(self.manuscript.get_log_path())
     Logger.add_section("Manuscript", u"%s" % self.manuscript)
예제 #40
0
 def execute(self, manuscript, win):
     self.wrapper_win = win
     manuscript.execute_next_instruction()
     Logger.add_debug("Executing instruction '%s'" % (self))
     self._execute()
예제 #41
0
 def Destroy(self, *args, **kw):
     self.shown = False
     Logger.add_result("Dialog '%s' closed" % self.GetLabel())
     wxMultiChoiceDialog.Destroy(self, *args, **kw)
예제 #42
0
 def __init__(self, *args, **kw):
     Wrapper.__init__(self)
     Logger.add_result("AboutBox opened")
     wx.CallLater(TIME_TO_WAIT_FOR_DIALOG_TO_SHOW_IN_MILLISECONDS,
                  self._explore_and_register)
     wxAboutBox(*args, **kw)
예제 #43
0
def scan(text):

    global _tab_count
    global _print_unknown_only
    global _first_char_on_line
    global _col

    prevcol = 1
    _tab_count = 0
    _col = 0

    text = text.strip()
    nbr_of_chars = len(text)
    i = 0
    nbr_of_unkown = 0
    tokens = []
    _first_char_on_line = ' '

    while i < nbr_of_chars:
        lexeme = u"unknown"
        typename = "Unknown"
        token = UNKNOWN
        subid = None

        # Comment
        if i == 0 and text[i] == '#':
            lexeme = text.decode("utf-8")
            typename = "Comment"
            token = Token(KEYWORD, text, ID_COMMENT, col=0)
            tokens.append(token)
            return tokens

        # Space
        elif text[i] == ' ':
            lexeme = u" "
            typename = "Space"
            token = SPACE

        # Tab
        elif text[i] == '\t':
            lexeme = u" "
            typename = "Tab"
            token = TAB
            _tab_count = _tab_count + 1

        # Left Parenthesis
        elif text[i] == '(':
            lexeme = u"("
            typename = "Left Parenthesis"
            token = LP

        # Right Parenthesis
        elif text[i] == ')':
            lexeme = u")"
            typename = "Right Parenthesis"
            token = RP

        elif text[i] == '=':
            lexeme = u"="
            typename = "Equal sign"
            token = EQ

        elif text[i] == '+':
            lexeme = u"+"
            typename = "Plus sign"
            token = PLUS

        elif text[i] == ',':
            lexeme = u","
            typename = "Comma"
            token = COMMA

        elif text[i] == '|':
            lexeme = u"|"
            typename = "Or"
            token = OR

        elif text[i] == '"':
            lexeme, token, subid, i = _parse_string(text, i)
            typename = "String"
            _col = i + 1

        elif text[i] == "'":
            lexeme, token, subid, i = _parse_string(text, i)
            typename = "String"
            _col = i + 1

        elif text[i].isalnum() or text[i] in ID_SPECIAL_CHARS:
            lexeme, token, subid, i = _parse_identifier(text, i)
            typename = "Identifier"
            _col = i + 1

        # Unknown token
        else:
            if text[i].isspace():
                lexeme = u" "
                typename = "Space"
                token = SPACE
            else:
                nbr_of_unkown = nbr_of_unkown + 1
                lexeme = u"%c" % text[i]

        i += 1
        _col += 1

        # Print result
        if _print_unknown_only:
            if (token == UNKNOWN):
                msg = "%d %d %s %s" % (i, token, typename, lexeme)
                Logger.add_error(msg)

        if typename != "Space":
            token = Token(token, lexeme, subid, col=prevcol)
            tokens.append(token)
        prevcol = _col

    if nbr_of_unkown > 0:
        msg = "Nbr of unknown tokens encountered = %d" % nbr_of_unkown
        Logger.add_error(msg)

    return tokens
예제 #44
0
 def Show(self, *args, **kw):
     self._shown = True
     Logger.add_open(self)
     self.call_when_win_shows(self._explore_and_register)
     super(PreviewFrame, self).Show(*args, **kw)
예제 #45
0
 def Destroy(self, *args, **kw):
     self._shown = False
     Logger.add_close(self)
     wxPreviewFrame.Destroy(self, *args, **kw)
예제 #46
0
 def PrintDialog(self, *args, **kw):
     self._shown = True
     Logger.add_open(self)
     self.call_when_win_shows(self._explore_and_register)
     super(Printer, self).PrintDialog(*args, **kw)
     self._shown = False
예제 #47
0
 def describe_wxdialog_windows(self, win, level=0):
     msg = ""
     if len(win.Children) == 0:
         return
     margin = "%*.*s" % (level * 3, level * 3, "")
     if level > 0:
         Logger.add(" ")
         Logger.add("   %sClassName: %s" % (margin, win.ClassName))
     Logger.add("   %sId    Classname                Label                     Name" % margin)
     Logger.add("   %s----  ------------------------ ------------------------  ----------------" % margin)
     try:
         for child in win.Children:
             child_id = child.GetId()
             msg = "   %s%4d  %-24.24s %-24.24s  '%s'" % (margin, child_id, child.GetClassName(), child.GetLabel(), child.GetName())
             Logger.add(msg)
             self.describe_wxdialog_windows(child, level + 1)
     except AttributeError:
         Logger.add("   No children exists")
     except Exception, ex:
         pass
예제 #48
0
 def __init__(self, msg):
     Logger.add_error(msg)