Exemplo n.º 1
0
    def click(self, x, y):
        if self.click_by_mouse:
            window_title = self._getWindowTitle()
            try:
                hwin = win32gui.FindWindow('LDPlayerMainFrame', window_title)
                self._subhwin = None

                def winfun(hwnd, lparam):
                    subtitle = win32gui.GetWindowText(hwnd)
                    if subtitle == 'TheRender':
                        self._subhwin = hwnd

                win32gui.EnumChildWindows(hwin, winfun, None)
                ret = win32gui.GetWindowRect(self._subhwin)
                height = ret[3] - ret[1]
                width = ret[2] - ret[0]
                tx = int(x * width / constants.BASE_WIDTH)
                ty = int(y * height / constants.BASE_HEIGHT)
                positon = win32api.MAKELONG(tx, ty)
                win32api.SendMessage(self._subhwin, win32con.WM_LBUTTONDOWN,
                                     win32con.MK_LBUTTON, positon)
                win32api.SendMessage(self._subhwin, win32con.WM_LBUTTONUP,
                                     win32con.MK_LBUTTON, positon)
            except Exception as e:
                print(f"fallback adb click:{e}")
                super().click(x, y)
        else:
            super().click(x, y)
Exemplo n.º 2
0
 def moveWindow(self, hWnd: int):
     """ 移动窗口
     Parameter
     ----------
     hWnd : 窗口句柄
     """
     win32gui.ReleaseCapture()
     win32api.SendMessage(hWnd, win32con.WM_SYSCOMMAND,
                 win32con.SC_MOVE + win32con.HTCAPTION, 0)
Exemplo n.º 3
0
    def moveWindow(hWnd):
        """ 移动窗口

        Parameter
        ----------
        hWnd: int or `sip.voidptr`
            窗口句柄
        """
        win32gui.ReleaseCapture()
        win32api.SendMessage(int(hWnd), win32con.WM_SYSCOMMAND,
                             win32con.SC_MOVE + win32con.HTCAPTION, 0)
Exemplo n.º 4
0
 def moveWindow(hWnd: int):
     win32gui.ReleaseCapture()
     win32api.SendMessage(hWnd, win32con.WM_SYSCOMMAND,
                          win32con.SC_MOVE + win32con.HTCAPTION, 0)
Exemplo n.º 5
0
def parseDSFileAndInsert(full_filename, session, importID):
    workDir = os.path.dirname(
        os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
    con_file = os.path.join(workDir, 'init.txt')
    MTI_path = os.path.join(workDir, 'MTIwinGPS.exe')
    out_path = os.path.join(
        workDir, "ecoReleve_import", "Argos",
        os.path.splitext(os.path.basename(full_filename))[0])

    EngData = None
    GPSData = None
    EngDataBis = None
    nb_gps_data = None
    nb_existingGPS = None
    nb_eng = 0
    nb_existingEng = 0

    if not os.path.exists(out_path):
        os.makedirs(out_path)
    try:
        os.remove(con_file)
    except:
        pass

    # Config init.txt for MTI-PArser
    cc = {'full_filename': full_filename}
    cc['out'] = out_path
    cc['ini'] = con_file

    with open(con_file, 'w') as f:
        print('-eng\n-title\n-out\n' + out_path + '\n' + full_filename, file=f)

    # execute MTI-Parser
    args = [MTI_path]
    proc = subprocess.Popen([args[0]])
    hwnd = 0
    while hwnd == 0:
        sleep(0.3)
        hwnd = win32gui.FindWindow(0, "MTI Argos-GPS Parser")

    btnHnd = win32gui.FindWindowEx(hwnd, 0, "Button", "Run")
    win32api.SendMessage(btnHnd, win32con.BM_CLICK, 0, 0)
    filenames = [
        os.path.join(out_path, fn) for fn in next(os.walk(out_path))[2]
    ]
    win32api.SendMessage(hwnd, win32con.WM_CLOSE, 0, 0)

    # kill process Mti-Parser
    pid = proc.pid
    cc['pid'] = pid
    parent = psutil.Process(pid)
    try:
        # or parent.children() for recursive=False
        for child in parent.children(recursive=True):
            child.kill()
        parent.kill()
    except:
        pass

    # process output files
    for filename in filenames:
        fullname = os.path.splitext(os.path.basename(filename))[0]
        ptt = int(fullname[0:len(fullname) - 1])

        if filename.endswith("g.txt"):
            tempG = pd.read_csv(filename,
                                sep='\t',
                                header=0,
                                parse_dates=[0],
                                infer_datetime_format=True)
            tempG['ptt'] = ptt
            try:
                GPSData = GPSData.append(tempG)
            except:
                GPSData = tempG

        if filename.endswith("e.txt"):
            usecols = [
                'txDate', 'pttDate', 'satId', 'activity', 'txCount', 'temp',
                'batt', 'fixTime', 'satCount', 'resetHours', 'fixDays',
                'season', 'shunt', 'mortalityGT', 'seasonalGT'
            ]
            usecolsBis = ['txDate', 'resetHours', 'cycle', 'season']
            tempEng = pd.read_csv(filename,
                                  sep='\t',
                                  parse_dates=[0],
                                  header=None,
                                  skiprows=[0])

            trueCols = usecols
            if len(tempEng.columns) == 17:
                trueCols.append('latestLat')
                trueCols.append('latestLon')

            if len(tempEng.columns) < 5:
                trueCols = usecolsBis

            tempEng.columns = trueCols
            tempEng.loc[:, ('ptt')] = ptt
            try:
                EngData = EngData.append(tempEng)
            except:
                EngData = tempEng

        if filename.endswith("d.txt"):
            usecols = ['txDate', 'temp', 'batt', 'txCount', 'activity']
            tempEng = pd.read_csv(filename,
                                  sep='\t',
                                  parse_dates=[0],
                                  header=None,
                                  skiprows=[0])
            tempEng.columns = usecols
            tempEng['ptt'] = ptt
            tempEng['pttDate'] = tempEng['txDate']
            try:
                EngDataBis = EngDataBis.append(tempEng)
            except:
                EngDataBis = tempEng

    if EngData is not None:
        EngToInsert = checkExistingEng(EngData, session)
        nb_existingEng += EngData.shape[0]
        if EngToInsert.shape[0] != 0:
            # Insert non existing data into DB
            EngToInsert.loc[:, ('FK_Import')] = list(
                itertools.repeat(importID, len(EngToInsert.index)))
            nb_eng += EngToInsert.shape[0]
            EngToInsert.to_sql(ArgosEngineering.__table__.name,
                               session.get_bind(),
                               if_exists='append',
                               schema=dbConfig['sensor_schema'],
                               index=False)

    if EngDataBis is not None:
        EngBisToInsert = checkExistingEng(EngDataBis, session)
        nb_existingEng += EngDataBis.shape[0]
        if EngBisToInsert.shape[0] != 0:
            EngToInsert.loc[:, ('FK_Import')] = list(
                itertools.repeat(importID, len(EngToInsert.index)))
            nb_eng += EngBisToInsert.shape[0]
            # Insert non existing data into DB
            EngBisToInsert.to_sql(ArgosEngineering.__table__.name,
                                  session.get_bind(),
                                  if_exists='append',
                                  schema=dbConfig['sensor_schema'],
                                  index=False)

    if GPSData is not None:
        GPSData = GPSData.replace(["neg alt"], [-999])
        DFToInsert = checkExistingGPS(GPSData, session)
        DFToInsert.loc[:, ('FK_Import')] = list(
            itertools.repeat(importID, len(DFToInsert.index)))
        nb_gps_data = DFToInsert.shape[0]
        nb_existingGPS = GPSData.shape[0] - DFToInsert.shape[0]
        if DFToInsert.shape[0] != 0:
            # Insert non existing data into DB
            DFToInsert.to_sql(ArgosGps.__table__.name,
                              session.get_bind(),
                              if_exists='append',
                              schema=dbConfig['sensor_schema'],
                              index=False)

    os.remove(full_filename)
    shutil.rmtree(out_path)
    message = {
        'inserted gps': nb_gps_data,
        'existing gps': nb_existingGPS,
        'inserted Engineering': nb_eng,
        'existing Engineering': nb_existingEng - nb_eng,
        'inserted argos': 0,
        'existing argos': 0
    }

    nbRows = (nb_existingEng or 0) + (nb_existingGPS or 0) + (nb_gps_data or 0)
    maxDateGPS = GPSData['datetime'].max()
    minDateGPS = GPSData['datetime'].min()
    nbInserted = nb_gps_data + nb_eng
    return message, nbRows, nbInserted, maxDateGPS, minDateGPS
Exemplo n.º 6
0
subMenuHandle = win32gui.GetSubMenu(menuHandle, 0)
# 获得菜单项中的的标志符,注意,分隔符是被编入索引的
# 参数:子菜单句柄 项目索引号
menuItemHandle = win32gui.GetMenuItemID(subMenuHandle, 0)
# 发送消息,加入消息队列,无返回
# 参数:句柄 消息类型 WParam IParam
win32gui.postMessage(subHandle, win32con.WM_COMMAND, menuItemHandle, 0)

# wParam的定义是32位整型,high word就是他的31至16位,low word是它的15至0位。
# 当参数超过两个,wParam和lParam不够用时,可以将wParam就给拆成两个int16来使用。
# 这种时候在python里记得用把HIWORD的常数向左移16位,再加LOWORD,即wParam = HIWORD<<16+LOWORD。

# 下选框内容更改
# 参数:下选框句柄; 消息内容; 参数下选框的哪一个item,以0起始的待选选项的索引;如果该值为-1,将从组合框列表中删除当前选项,并使当前选项为空; 参数
# CB_Handle为下选框句柄,PCB_handle下选框父窗口句柄
if win32api.SendMessage(CB_handle, win32con.CB_SETCURSEL, 1, 0) == 1:
    # 下选框的父窗口命令
    # 参数:父窗口句柄; 命令; 参数:WParam:高位表示类型,低位表示内容;参数IParam,下选框句柄
    # CBN_SELENDOK当用户选择了有效的列表项时发送,提示父窗体处理用户的选择。 LOWORD为组合框的ID. HIWORD为CBN_SELENDOK的值。
    win32api.SendMessage(PCB_handle, win32con.WM_COMMAND, 0x90000, CB_handle)
    # CBN_SELCHANGE当用户更改了列表项的选择时发送,不论用户是通过鼠标选择或是通过方向键选择都会发送此通知。LOWORD为组合框的ID. HIWORD为CBN_SELCHANGE的值。
    win32api.SendMessage(PCB_handle, win32con.WM_COMMAND, 0x10000, CB_handle)

# 设置文本框内容,等窗口处理完毕后返回true。中文需编码成gbk
# 参数:句柄;消息类型;参数WParam,无需使用; 参数IParam,要设置的内容,字符串
win32api.SendMessage(handle, win32con.WM_SETTEXT, 0,
                     os.path.abspath(fgFilePath).encode('gbk'))

# 控件点击确定,处理消息后返回0
# 参数:窗口句柄; 消息类型; 参数WParam HIWORD为0(未使用),LOWORD为控件的ID; 参数IParam  0(未使用),确定控件的句柄
win32api.SendMessage(Mhandle, win32con.WM_COMMAND, 1, confirmBTN_handle)