Beispiel #1
0
class TopPanel(wx.Panel):
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent)
        self.imagesPath = os.path.join(".", "images")
        image_open_folder = wx.Image(os.path.join(self.imagesPath, "open-folder.png"),
                                     wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        image_screenShot = wx.Image(os.path.join(self.imagesPath, "screenshot.png"),
                                    wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        image_save = wx.Image(os.path.join(self.imagesPath, "save.png"), wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        image_rotate = wx.Image(os.path.join(self.imagesPath, "rotate.png"), wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        image_recorder = wx.Image(os.path.join(self.imagesPath, "recorder.jpg"), wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
        image_exe = wx.Image(os.path.join(self.imagesPath, "go.png"), wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        topSizer = wx.GridSizer(1, 5, 1, 1)
        self.button_open_folder = wx.BitmapButton(self, -1, image_open_folder, size=(30, 22))
        self.button_screenShot = wx.BitmapButton(self, -1, image_screenShot, size=(30, 22))
        self.button_screenShot.SetToolTip("获取页面截图和布局文件")
        self.Bind(wx.EVT_BUTTON, self.update_screen_shot, self.button_screenShot)
        self.button_save = wx.BitmapButton(self, -1, image_save, size=(30, 22))
        self.button_rotate = wx.BitmapButton(self, -1, image_rotate, size=(30, 22))
        self.Bind(wx.EVT_BUTTON, self.update_after_rotate, self.button_rotate)
        self.exeButton = wx.BitmapButton(self, -1, image_exe, size=(30, 22))
        self.exeButton.Bind(wx.EVT_BUTTON, self.tell_to_do_swipe_or_input)
        self.exeButton.SetToolTip("执行动作")
        self.baseSettings = wx.StaticBox(self, -1, "基本操作")
        self.recordSettings = wx.StaticBox(self, -1, "同步操作")
        self.nodeSettings = wx.StaticBox(self, -1, "节点操作")
        self.operationParasSettings = wx.StaticBox(self, -1, "动作参数设置")
        self.searchBox = wx.TextCtrl(self, -1, size=(100, 22))
        self.searchBtn = wx.Button(self, -1, "搜索", size=(30, 22))
        self.Bind(wx.EVT_BUTTON, self.tell_to_do_search, self.searchBtn)
        b6 = wx.GridSizer(2, 2, 1, 1)
        self.imagesPath = os.path.join(".", "images")
        b1 = wx.StaticBoxSizer(self.baseSettings, wx.HORIZONTAL)
        b2 = wx.StaticBoxSizer(self.recordSettings, wx.HORIZONTAL)
        b3 = wx.StaticBoxSizer(self.nodeSettings, wx.HORIZONTAL)
        b3.Add(self.searchBox, 1, wx.ALL, 1)
        b3.Add(self.searchBtn, 1, wx.ALL, 1)

        self.inputB = wx.StaticBox(self, -1, "输入")
        inputBSizer = wx.StaticBoxSizer(self.inputB, wx.HORIZONTAL)
        b5 = wx.BoxSizer(wx.VERTICAL)
        self.inputContentText = wx.StaticText(self, -1, "内容:", size=(80, 22))
        self.inputContent = wx.TextCtrl(self, -1, value=(""), size=(80, 22))
        self.inputContent.SetToolTip("要对元素输入的内容")

        self.swipeB = wx.StaticBox(self, -1, "滑动")
        swipeBSizer = wx.StaticBoxSizer(self.swipeB, wx.HORIZONTAL)
        swipeBGSizer = wx.GridSizer(2, 2, 10, 10)
        self.swipeStartX = IntC(self, -1, size=(40, 22))
        self.swipeStartX.SetToolTip("滑动起始点横坐标")
        self.swipeStartY = IntC(self, -1, size=(40, 22))
        self.swipeStartY.SetToolTip("滑动起始点纵坐标")
        self.swipeEndX = IntC(self, -1, size=(40, 22))
        self.swipeEndX.SetToolTip("滑动终点横坐标")
        self.swipeEndY = IntC(self, -1, size=(40, 22))
        self.swipeEndY.SetToolTip("滑动终点纵坐标")
        inputBSizer.Add(self.inputContentText, 1, wx.ALL, 1)
        inputBSizer.Add(self.inputContent, 1, wx.ALL, 1)

        swipeBGSizer.Add(self.swipeStartX, 1, wx.ALL, 5)
        swipeBGSizer.Add(self.swipeStartY, 1, wx.ALL, 5)
        swipeBGSizer.Add(self.swipeEndX, 1, wx.ALL, 5)
        swipeBGSizer.Add(self.swipeEndY, 1, wx.ALL, 5)
        swipeBSizer.Add(swipeBGSizer, 1, wx.ALL | wx.EXPAND, 5)
        b5.Add(inputBSizer)
        b5.Add(swipeBSizer, 1, wx.EXPAND)

        b4 = wx.StaticBoxSizer(self.operationParasSettings, wx.HORIZONTAL)
        b4.Add(b5, 1, wx.ALL, 1)

        timeOutList = ["5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15"]
        self.recordTimeOut = wx.ComboBox(self, -1, value="10", choices=timeOutList, style=wx.CB_READONLY)
        self.recordTimeOut.SetToolTip("重新获取页面截图和布局的延时时间")
        self.button_recorder = wx.BitmapButton(self, -1, image_recorder)
        self.button_recorder.SetToolTip("开启/关闭同步模式")

        self.keyboardType = wx.ComboBox(self, -1, value="ADB", choices=["ADB", "ORG"], style=wx.CB_READONLY)
        self.keyboardType.SetToolTip("键盘类型. 输入中文,选择ADB;输入英文或密码时,使用ORG")
        self.Bind(wx.EVT_BUTTON, self.update_record_model, self.button_recorder)
        b1.Add(self.button_open_folder, 1, wx.ALL, 1)
        b1.Add(self.button_screenShot, 1, wx.ALL, 1)
        b1.Add(self.button_save, 1, wx.ALL, 1)
        b1.Add(self.button_rotate, 1, wx.ALL, 1)

        b6.Add(self.recordTimeOut, 1, wx.ALL, 1)
        b6.Add(self.button_recorder, 1, wx.ALL, 1)
        b6.Add(self.keyboardType, 1, wx.ALL, 1)
        b6.Add(self.exeButton, 1, wx.ALL, 1)
        b2.Add(b6)
        opeartionList = ["输入", "滑动"]
        self.OpeartionBox = wx.RadioBox(self, label='动作', choices=opeartionList, majorDimension=1,
                                        style=wx.RA_SPECIFY_ROWS)
        self.OpeartionBox.Bind(wx.EVT_RADIOBOX, self.on_click_operation_option)

        topSizer.Add(b1, 1, wx.EXPAND, 1)
        topSizer.Add(b2, 1, wx.EXPAND, 1)
        topSizer.Add(self.OpeartionBox, 1, wx.ALL, 1)
        topSizer.Add(b4, 1, wx.EXPAND, 1)
        topSizer.Add(b3, 1, wx.EXPAND, 1)
        self.SetSizer(topSizer)
        self.Fit()

    def tell_to_do_swipe_or_input(self, evt):
        operationString = self.OpeartionBox.GetStringSelection()
        inputC = self.inputContent.GetValue()
        sX = self.swipeStartX.GetValue()
        sY = self.swipeStartY.GetValue()
        eX = self.swipeEndX.GetValue()
        eY = self.swipeEndY.GetValue()

        if operationString == "输入":
            if not inputC:
                dlg = wx.MessageDialog(self, u"请检查输入内容", u"输入内容不能为空", wx.OK | wx.ICON_ERROR)
                if dlg.ShowModal() == wx.ID_OK:
                    dlg.Destroy()
            else:
                keyb = self.keyboardType.GetValue()

                wx.CallAfter(pub.sendMessage, "DoSwipeOrInput", msg=inputC + "\n" + keyb)
        else:
            if not sX or not sY or not eX or not eY:
                dlg = wx.MessageDialog(self, u"请检查滑动坐标设置", u"滑动起始点和终点的横纵坐标均不能为空", wx.OK | wx.ICON_ERROR)
                if dlg.ShowModal() == wx.ID_OK:
                    dlg.Destroy()
            else:
                wx.CallAfter(pub.sendMessage, "DoSwipeOrInput", msg="滑动\n%d\n%d\n%d\n%d" % (sX, sY, eX, eY))

    def update_after_rotate(self, evt):
        screenShotPath = os.path.join(os.getcwd(), "screenShot", "screenshot.png")
        img = Image.open(screenShotPath)
        out = img.rotate(90, expand=1)
        out.save(screenShotPath)
        wx.CallAfter(pub.sendMessage, "update", msg=screenShotPath)

    def on_click_operation_option(self, evt):
        print(self.OpeartionBox.GetStringSelection(), ' is clicked from Radio Box')

    def tell_to_do_search(self, evt):
        searchContent = self.searchBox.GetValue()
        wx.CallAfter(pub.sendMessage, "DoSearch", msg=searchContent)

    def update_screen_shot(self, evt):
        bottom_left_panel_size = self.Parent.Parent.bottom_left_panel.GetSize()
        bottom_left_panel_status_bar_size = self.Parent.Parent.bottom_left_panel.statusBar.GetSize()
        current_fit_size = bottom_left_panel_size[0] - 20, \
            bottom_left_panel_size[1] - bottom_left_panel_status_bar_size[1] - 20
        GetNewScreenShotAndDomFileThread(current_fit_size)

    def update_record_model(self, evt):
        global recordStatus
        if recordStatus == "关":
            dlg = wx.MessageDialog(self, u"1. 同步模式下,将不能通过点击页面来定位元素;\n2. 同步模式下将对页面进行模拟人工操作,并生成脚本;\n3. 同步完成后,请关闭同步模式。",
                                   u"确定进入同步模式?", wx.YES_NO | wx.ICON_QUESTION)
            if dlg.ShowModal() == wx.ID_YES:
                recordStatus = "开"
                global recordTimeDelay
                recordTimeDelay = int(self.recordTimeOut.GetValue())
                print("当前设置同步超时为:", recordTimeDelay)
            dlg.Destroy()
        else:
            recordStatus = "关"
        self.Parent.Parent.Parent.update_record_status(recordStatus)