Example #1
0
 def select_field_on_mouse_move(evt, po_fields, image_panel, table):
     field_before = image_panel.selected_field
     image_panel.set_po_fields(po_fields)
     ImageWithElements.on_mouse_move(image_panel, evt)
     field_after = image_panel.selected_field
     if field_after and field_after != field_before:
         row = po_fields.index(field_after)
         table.select_row(row)
Example #2
0
    def __create_widgets(self):
        sizer = GridBagSizer(5, 5)

        row = 0
        col = 1
        self.bth_reload_img = Button(self, label=u'Reload image')
        self.bth_reload_img.Bind(EVT_BUTTON, self.__load_img)
        sizer.Add(self.bth_reload_img, pos=(row, col), flag=FLAG_ALL_AND_EXPAND)

        col += 1
        self.bth_reload_selectors = Button(self, label=u'Find selectors')
        self.bth_reload_selectors.Bind(EVT_BUTTON, self.__find_selectors)
        sizer.Add(self.bth_reload_selectors, pos=(row, col), flag=FLAG_ALL_AND_EXPAND)
        # third row
        row += 1
        col = 0

        splitter = SplitterWindow(self, style=SP_3D | SP_LIVE_UPDATE)

        self.image_panel = ImageWithElements(splitter)
        self.image_panel.static_bitmap.Bind(EVT_MOTION, self.__on_mouse_move)

        self.table = Table(splitter)
        self.table.Bind(EVT_GRID_SELECT_CELL, self.__on_cell_select)

        splitter.SplitHorizontally(self.image_panel, self.table)
        sizer.Add(splitter, pos=(row, col), span=(1, 3), flag=FLAG_ALL_AND_EXPAND)

        sizer.AddGrowableCol(0, 1)
        sizer.AddGrowableRow(row, 1)

        self.SetSizer(sizer)
Example #3
0
    def __create_widgets(self):
        sizer = self.GetSizer()

        # Next row
        inner_sizer = BoxSizer(HORIZONTAL)
        label = StaticText(self, label=u'Class path:')
        inner_sizer.Add(label, flag=ALL)

        self.cb_class_path = ComboBox(self, style=CB_READONLY)
        self.cb_class_path.Bind(EVT_COMBOBOX, self.__on_load_po_class)
        inner_sizer.Add(self.cb_class_path, 1, flag=FLAG_ALL_AND_EXPAND)

        self.btn_reload = Button(self, label=u'Reload')
        self.btn_reload.Bind(EVT_BUTTON, self.__on_load_po_class)
        inner_sizer.Add(self.btn_reload, flag=ALL)

        self.btn_open_class = Button(self, label=u'Open class')
        self.btn_open_class.Bind(EVT_BUTTON, self.__open_class)
        inner_sizer.Add(self.btn_open_class, flag=ALL)

        row = 0
        sizer.Add(inner_sizer, pos=(row, 0), flag=FLAG_ALL_AND_EXPAND)

        # Next row
        row += 1
        splitter = SplitterWindow(self, style=SP_3D | SP_LIVE_UPDATE)

        self.image_panel = ImageWithElements(splitter)
        self.image_panel.static_bitmap.Bind(EVT_MOTION, self.__on_mouse_move)
        self.image_panel.static_bitmap.Bind(EVT_RIGHT_DOWN, self.__on_right_click)

        self.table_and_test_file_tabs = FieldsTableAndTestFilesTabs(splitter, self)

        splitter.SplitHorizontally(self.image_panel, self.table_and_test_file_tabs)
        sizer.Add(splitter, pos=(row, 0), flag=FLAG_ALL_AND_EXPAND)

        sizer.AddGrowableRow(row, 1)
        sizer.AddGrowableCol(0, 1)
Example #4
0
class EditorTab(Panel):
    def __init__(self, parent):
        Panel.__init__(self, parent)
        sizer = GridBagSizer(5, 5)
        self.SetSizer(sizer)

        self.__cur_po_class = None
        self.__create_widgets()

    def __create_widgets(self):
        sizer = self.GetSizer()

        # Next row
        inner_sizer = BoxSizer(HORIZONTAL)
        label = StaticText(self, label=u'Class path:')
        inner_sizer.Add(label, flag=ALL)

        self.cb_class_path = ComboBox(self, style=CB_READONLY)
        self.cb_class_path.Bind(EVT_COMBOBOX, self.__on_load_po_class)
        inner_sizer.Add(self.cb_class_path, 1, flag=FLAG_ALL_AND_EXPAND)

        self.btn_reload = Button(self, label=u'Reload')
        self.btn_reload.Bind(EVT_BUTTON, self.__on_load_po_class)
        inner_sizer.Add(self.btn_reload, flag=ALL)

        self.btn_open_class = Button(self, label=u'Open class')
        self.btn_open_class.Bind(EVT_BUTTON, self.__open_class)
        inner_sizer.Add(self.btn_open_class, flag=ALL)

        row = 0
        sizer.Add(inner_sizer, pos=(row, 0), flag=FLAG_ALL_AND_EXPAND)

        # Next row
        row += 1
        splitter = SplitterWindow(self, style=SP_3D | SP_LIVE_UPDATE)

        self.image_panel = ImageWithElements(splitter)
        self.image_panel.static_bitmap.Bind(EVT_MOTION, self.__on_mouse_move)
        self.image_panel.static_bitmap.Bind(EVT_RIGHT_DOWN, self.__on_right_click)

        self.table_and_test_file_tabs = FieldsTableAndTestFilesTabs(splitter, self)

        splitter.SplitHorizontally(self.image_panel, self.table_and_test_file_tabs)
        sizer.Add(splitter, pos=(row, 0), flag=FLAG_ALL_AND_EXPAND)

        sizer.AddGrowableRow(row, 1)
        sizer.AddGrowableCol(0, 1)

    def __get_parsed_classes(self, field):
        classes = ParsedPageObjectClass.get_parsed_classes(self.__cur_po_class.file_path)
        if len(classes) > 0 and len(classes[0].methods) == 0:
            classes = []
        classes += [ParsedModule.get_parsed_module(tools)]
        if field:
            classes += ParsedMouseClass.get_parsed_classes()
            classes += ParsedBrowserClass.get_parsed_classes()
        return classes

    def show_content_menu(self, field):
        tabs = self.table_and_test_file_tabs.tabs
        count = tabs.GetPageCount()
        if count > 1:
            selected_tab = tabs.GetPage(tabs.GetSelection())
            if type(selected_tab) in (TestFileUI, PyFileUI):
                file_path = selected_tab.get_file_path()
                txt_ctrl_ui = tabs.GetPage(tabs.GetSelection())
                parsed_classes = self.__get_parsed_classes(field)
                context_menu = FieldContextMenu(field,
                                                parsed_classes,
                                                file_path,
                                                txt_ctrl_ui)
                self.PopupMenu(context_menu)
                context_menu.Destroy()
            else:
                show_dialog(self, u'Please select tab with test file.',
                            u'Tab with test file was not selected')
        else:
            show_dialog(self, u'Please create/open test file.',
                        u'Test file was not created/opened')

    def __on_load_po_class(self, evt):
        path = self.cb_class_path.GetValue()
        if len(path) > 0:
            self.__load_po_class(path)

    def __on_right_click(self, evt):
        field = self.__get_current_field(evt)
        self.show_content_menu(field)

    def __on_mouse_move(self, evt):
        if self.__cur_po_class:
            ImageAndTableHelper.select_field_on_mouse_move(
                evt,
                self.__cur_po_class.fields,
                self.image_panel,
                self.table_and_test_file_tabs.table
            )

    def __get_current_field(self, evt):
        return self.image_panel.get_field(evt.GetPosition())

    def __open_class(self, evt):
        folder = self.GetTopLevelParent().get_root_folder()
        if folder:
            if RootFolder.PO_FOLDER in os.listdir(folder):
                folder = os.path.join(folder, RootFolder.PO_FOLDER)
            dialog = FileDialog(self, defaultDir=folder, wildcard=u'*.py')
            if dialog.ShowModal() == ID_OK:
                self.__load_po_class(dialog.GetPath())
        else:
            show_dialog_path_doesnt_exist(self, folder)

    def __load_po_class(self, path):
        self.table_and_test_file_tabs.table.clear_table()

        if not os.path.exists(path):
            show_dialog_path_doesnt_exist(self, path)
        if not is_correct_python_file(path):
            show_dialog(self, u'File name is incorrect: %s' % path,
                        u'Bad file name')
        else:
            folder = os.path.dirname(path)
            files = [os.path.join(folder, p) for p in os.listdir(folder)
                     if is_correct_python_file(p)]
            self.cb_class_path.Clear()
            self.cb_class_path.AppendItems(files)
            self.cb_class_path.Select(files.index(path))
            try:
                self.__cur_po_class = PageObjectClass.parse_string_to_po_class(read_file(path))
                area = self.__cur_po_class.area
                self.image_panel.set_po_fields(self.__cur_po_class.fields)
                self.image_panel.load_image(self.__cur_po_class.img_path, area)

                self.cb_class_path.SetValue(self.__cur_po_class.file_path)

                self.table_and_test_file_tabs.load_po_class(self.__cur_po_class)
            except Exception:
                self.__cur_po_class = None
                show_error_dialog(self, traceback.format_exc(),
                                  u'Failed to open file %s' % path)
Example #5
0
class SelectorFinderTab(Panel):
    def __init__(self, parent):
        Panel.__init__(self, parent)

        self.main_frame = self.GetTopLevelParent()
        self.po_fields = None

        self.__create_widgets()

    def __create_widgets(self):
        sizer = GridBagSizer(5, 5)

        row = 0
        col = 1
        self.bth_reload_img = Button(self, label=u'Reload image')
        self.bth_reload_img.Bind(EVT_BUTTON, self.__load_img)
        sizer.Add(self.bth_reload_img, pos=(row, col), flag=FLAG_ALL_AND_EXPAND)

        col += 1
        self.bth_reload_selectors = Button(self, label=u'Find selectors')
        self.bth_reload_selectors.Bind(EVT_BUTTON, self.__find_selectors)
        sizer.Add(self.bth_reload_selectors, pos=(row, col), flag=FLAG_ALL_AND_EXPAND)
        # third row
        row += 1
        col = 0

        splitter = SplitterWindow(self, style=SP_3D | SP_LIVE_UPDATE)

        self.image_panel = ImageWithElements(splitter)
        self.image_panel.static_bitmap.Bind(EVT_MOTION, self.__on_mouse_move)

        self.table = Table(splitter)
        self.table.Bind(EVT_GRID_SELECT_CELL, self.__on_cell_select)

        splitter.SplitHorizontally(self.image_panel, self.table)
        sizer.Add(splitter, pos=(row, col), span=(1, 3), flag=FLAG_ALL_AND_EXPAND)

        sizer.AddGrowableCol(0, 1)
        sizer.AddGrowableRow(row, 1)

        self.SetSizer(sizer)

    def __update_table(self):
        if self.po_fields:
            self.table.load_data(self.po_fields)

    def __on_mouse_move(self, evt):
        ImageAndTableHelper.select_field_on_mouse_move(
            evt,
            self.po_fields,
            self.image_panel,
            self.table
        )

    def __on_cell_select(self, evt):
        self.table.selected_row = evt.GetRow()
        self.image_panel.draw_selected_field(self.table.get_selected_data(), True)
        evt.Skip()

    def __load_img(self, evt=None):
        browser = self.main_frame.get_browser()
        if browser:
            img_path = browser.save_screenshot(self.main_frame.get_tmp_dir())
            self.image_panel.load_image(img_path)
            self.main_frame.set_url(browser.get_current_url())

    def __find_selectors(self, evt):
        browser = self.main_frame.get_browser()
        if browser:
            url = self.main_frame.get_url()
            if not StringUtils.is_url_correct(url):
                show_dialog(self, u'Bad url: %s' % url, u'Bad url')
            else:
                dialog = DialogWithText(self, 'Finding selectors...')
                handler = WxTextCtrlHandler(dialog.txt_ctrl)
                logger = Logger(log_to_console=False, handler=handler)

                dialog.Show()

                generator = PageObjectGenerator(browser, logger)

                def find_selectors():
                    dialog.btn_ok.Disable()
                    self.po_fields = generator.get_all_po_fields(url, None)
                    logger.info(u'DONE')
                    self.__update_table()
                    dialog.btn_ok.Enable()

                thread = Thread(target=find_selectors)
                thread.setDaemon(True)
                thread.start()