开源项目解读 —— Self-Operating Computer Framework # 长期主义 # 价值

news2024/9/29 15:31:41

价值:生成主函数业务逻辑函数思维导图,帮助理解,PR到开源项目,希望帮助大家理解IPA工作原理,国内没有好的开源项目,我就来翻译分析解读,给大家抛砖引玉。思维导图用文心一言配合其思维导图插件实现。

目录

整体代码框架 

核心代码逻辑

capture_screen_with_cursor # 用光标捕获屏幕

add_grid_to_image # 给图像配上网格 

keyboard_type# 用于通过程序模拟键盘输入

 search # 模拟在操作系统中搜索文本。具体来说,它会模拟按下“开始”键(在Windows中)或“Command”和“空格”键(在MacOS中),然后输入提供的文本并按下“Enter”键。

 keyboard_type# 用于通过程序模拟键盘输入

 keyboard_type# 用于通过程序模拟键盘输入

业务逻辑

架构-模块


整体代码框架 

核心代码逻辑

capture_screen_with_cursor # 用光标捕获屏幕

def capture_screen_with_cursor(file_path):
    user_platform = platform.system()

    if user_platform == "Windows":
        screenshot = pyautogui.screenshot()
        screenshot.save(file_path)
    elif user_platform == "Linux":
        # Use xlib to prevent scrot dependency for Linux
        screen = Xlib.display.Display().screen()
        size = screen.width_in_pixels, screen.height_in_pixels
        monitor_size["width"] = size[0]
        monitor_size["height"] = size[1]
        screenshot = ImageGrab.grab(bbox=(0, 0, size[0], size[1]))
        screenshot.save(file_path)
    elif user_platform == "Darwin":  # (Mac OS)
        # Use the screencapture utility to capture the screen with the cursor
        subprocess.run(["screencapture", "-C", file_path])
    else:
        print(f"The platform you're using ({user_platform}) is not currently supported")

add_grid_to_image # 给图像配上网格 

def add_grid_to_image(original_image_path, new_image_path, grid_interval):
    """
    Add a grid to an image
    """
    # Load the image
    image = Image.open(original_image_path)

    # Create a drawing object
    draw = ImageDraw.Draw(image)

    # Get the image size
    width, height = image.size

    # Reduce the font size a bit
    font_size = int(grid_interval / 10)  # Reduced font size

    # Calculate the background size based on the font size
    bg_width = int(font_size * 4.2)  # Adjust as necessary
    bg_height = int(font_size * 1.2)  # Adjust as necessary

    # Function to draw text with a white rectangle background
    def draw_label_with_background(
        position, text, draw, font_size, bg_width, bg_height
    ):
        # Adjust the position based on the background size
        text_position = (position[0] + bg_width // 2, position[1] + bg_height // 2)
        # Draw the text background
        draw.rectangle(
            [position[0], position[1], position[0] + bg_width, position[1] + bg_height],
            fill="white",
        )
        # Draw the text
        draw.text(text_position, text, fill="black", font_size=font_size, anchor="mm")

    # Draw vertical lines and labels at every `grid_interval` pixels
    for x in range(grid_interval, width, grid_interval):
        line = ((x, 0), (x, height))
        draw.line(line, fill="blue")
        for y in range(grid_interval, height, grid_interval):
            # Calculate the percentage of the width and height
            x_percent = round((x / width) * 100)
            y_percent = round((y / height) * 100)
            draw_label_with_background(
                (x - bg_width // 2, y - bg_height // 2),
                f"{x_percent}%,{y_percent}%",
                draw,
                font_size,
                bg_width,
                bg_height,
            )

    # Draw horizontal lines - labels are already added with vertical lines
    for y in range(grid_interval, height, grid_interval):
        line = ((0, y), (width, y))
        draw.line(line, fill="blue")

    # Save the image with the grid
    image.save(new_image_path)

keyboard_type# 用于通过程序模拟键盘输入

def keyboard_type(text):
    text = text.replace("\\n", "\n")
    for char in text:
        pyautogui.write(char)
    pyautogui.press("enter")
    return "Type: " + text

 search # 模拟在操作系统中搜索文本。具体来说,它会模拟按下“开始”键(在Windows中)或“Command”和“空格”键(在MacOS中),然后输入提供的文本并按下“Enter”键。

def search(text):
    if platform.system() == "Windows":
        pyautogui.press("win")
    elif platform.system() == "Linux":
        pyautogui.press("win")
    else:
        # Press and release Command and Space separately
        pyautogui.keyDown("command")
        pyautogui.press("space")
        pyautogui.keyUp("command")

    time.sleep(1)

    # Now type the text
    for char in text:
        pyautogui.write(char)

    pyautogui.press("enter")
    return "Open program: " + text

 keyboard_type# 用于通过程序模拟键盘输入

def keyboard_type(text):
    text = text.replace("\\n", "\n")
    for char in text:
        pyautogui.write(char)
    pyautogui.press("enter")
    return "Type: " + text

 keyboard_type# 用于通过程序模拟键盘输入

def keyboard_type(text):
    text = text.replace("\\n", "\n")
    for char in text:
        pyautogui.write(char)
    pyautogui.press("enter")
    return "Type: " + text

业务逻辑

架构-模块

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1333564.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

jar 运行清单文件MANIFEST.MF生成定义Main-Class Premain-Class IDEA maven-assembly-plugin

可运行jar文件中的启动清单文件 META-INF/MANIFEST.MF 内容自定义生成 清单文件中的 Main-Class: Premain-Class: Can-Retransform-Classes: 在maven-assembly-plugin插件中的生成配置如下, 注意命名 <archive> <manifest> <mainClass>c…

华为设备VRP系统管理

为了满足企业业务对网络的需求&#xff0c;网络设备中的系统文件需要不断进行升级。另外&#xff0c;网络设备中的配置文件也需要时常进行备份&#xff0c;以防设备故障或其他灾害给业务带来损害。在升级和备份系统文件或配置文件时&#xff0c;经常会使用FTP和TFTP来传输文件。…

浅谈Springboot默认logger函数的使用

目录 前言1. logger日志2. 补充 前言 原先写过一篇logger日志函数的总结&#xff0c;不同的引用来源&#xff1a;java常见log日志的使用方法详细解析 但是为了不引入依赖包&#xff0c;更好的直接使用&#xff0c;总结了如下博文 1. logger日志 Spring Boot使用Spring框架中…

基于阿里云服务网格流量泳道的全链路流量管理(二):宽松模式流量泳道

作者&#xff1a;尹航 在前文基于阿里云服务网格流量泳道的全链路流量管理&#xff08;一&#xff09;&#xff1a;严格模式流量泳道中&#xff0c;我们介绍了使用服务网格 ASM 的严格模式流量泳道进行全链路灰度管理的使用场景。该模式对于应用程序无任何要求&#xff0c;只需…

语法树的画法(根据文法求字符串)

目录 1.语法树的画法 2.语法树的短语 3.直接短语&#xff08;直接到根部&#xff09; 4.素短语 5.句柄 6.算符优先分析句型 1.语法树的画法 文法G[E]:E->EE | E*E | (E) | i ,字符串 ii*i 推导方式有两种最左推导和最右推导&#xff08;推导的技巧就是逐步靠近字符串…

数禾使用 Knative 加速 AI 模型服务部署丨KubeCon China 2023

作者&#xff1a;李鹏&#xff08;阿里云&#xff09;、魏文哲&#xff08;数禾科技&#xff09;&#xff0c; 此文基于 KubeCon China 2023 分享整理 摘要 AI 服务的数据、训练、推理等都需要消耗大量的计算资源以及运维成本&#xff0c;在数禾科技的金融业务场景下&#xf…

LaTex中参考文献引用

一、引用参考文献 这里我们使用的是BibTeX的引用格式&#xff0c;因此文件中应包括两个文件&#xff08;.bib-参考文献 和 .bst-文献格式&#xff09;。 有了这两个文件后&#xff0c;我们在bib文件中创建参考文献&#xff1a;&#xff08;注意&#xff0c;作者的名字是逗号前…

鸿蒙(HarmonyOS)项目方舟框架(ArkUI)之Image图片组件

鸿蒙&#xff08;HarmonyOS&#xff09;项目方舟框架&#xff08;ArkUI&#xff09;之Image图片组件 一、操作环境 操作系统: Windows 10 专业版、IDE:DevEco Studio 3.1、SDK:HarmonyOS 3.1 二、Image组件 Image 用来加载并显示图片的基础组件&#xff0c;它支持从内存、本…

Ps:图框工具

图框工具 Frame Tool是自 Ps 2019 版开始新增的一个工具。 图框 Frame可用于限制图像的显示范围&#xff0c;在设计过程中&#xff0c;还常常可起到占位符的功能。 快捷键&#xff1a;K 使用图框工具&#xff0c;对于快速相册排版、创建某种形式的特效等有一定的帮助。比起使用…

变量的存储类型(storage class)

变量的存储类型(storage class) 对于变量的存储类型&#xff0c;前面遇到过一些疑惑&#xff0c;再简单的在这里说一下。存储类型是指存储变量值的内存类型&#xff0c;它用来决定存储空间的大小。变量的存储类型决定着变量的存储器和作用域。有三个地方可以用于存储变量&#…

java进阶(二)-java小干货

java一些精干知识点分享 2. java小干货2.1循环遍历2.2可变参数2.3 list和数组转化2.3.1 数组转list2.3.2 list转数组 2.4 值传递和地址传递2.4.1值传递2.4.2 地址传递2.4.3易错点总结 2.5 数组数组帮助类Arrays 2.5 基本数据类型和包装类2.5集合2.6文件流2.7java代码块、内部类…

MQ(消息队列)相关知识

1. 什么是mq 消息队列是一种“先进先出”的数据结构 2. 应用场景 其应用场景主要包含以下3个方面 应用解耦 系统的耦合性越高&#xff0c;容错性就越低。以电商应用为例&#xff0c;用户创建订单后&#xff0c;如果耦合调用库存系统、物流系统、支付系统&#xff0c;任何…

python dash 写一个登陆页 4

界面 代码&#xff1a; 这里引入了dash_bootstrap_components 进行界面美化 &#xff0c;要记一些className&#xff0c;也不是原来说的不用写CSS了。 from dash import Dash, html, dcc, callback, Output, Input, State import dash_bootstrap_components as dbcapp Dash(…

Git安装及基本操作

1.安装Git 配置用户 git config --global user.name "用户名" git config --global user.email "邮箱"配置完成后查看配置 git config -l生成SSH秘钥 ssh-keygen -t rsa -C “邮箱” 输入完成后需要按3次Enter键 $ ssh-keygen -t rsa -C "邮箱&quo…

【MySQL学习笔记009】事务

一、事务简介 事务是一组操作的集合&#xff0c;它是一个不可分割的工作单位&#xff0c;事务会把所有的操作作为一个整体一起向系统提交或撤销操作请求&#xff0c;即这些操作要么同时成功&#xff0c;要么同时失败。 二、事务操作 1、操作1 查看/设置事务提交方式 select a…

基于Hexo+GitHub Pages 的个人博客搭建

基于HexoGitHub Pages 的个人博客搭建 步骤一&#xff1a;安装 Node.js 和 Git步骤二&#xff1a;创建Github Pages 仓库步骤二&#xff1a;安装 Hexo步骤三&#xff1a;创建 Hexo 项目步骤四&#xff1a;配置 Hexo步骤五&#xff1a;创建新文章步骤六&#xff1a;生成静态文件…

c语言:从函数中返回指针

return关键词可以从被调函数中返回一个值到主调函数。现在我们尝试让它返回一个指针到主调函数中。 #include <stdio.h> int* func() { int n 100; return &n; } int main() { int* p func(); printf("%d\n", *p); return 0; } 我们在函数 func 中定义…

【FPGA 器件比较】Altera -- Xilinx

比较以下市场前二名的产品线及定位 应用场景XilinxAltera高性能VersalAgilex F/I性能Virtex / Kintex / Artix / Zynq UltraScaleAgilex F/I / Stratix 10中档Virtex / Kintex / Zynq ~ 7 / UltraScaleStratix 10 / Arria 10低成本Artix-7 Sparton-7Cyclone 10 如上表&#x…

sql_lab之sqli中的head头注入,less18

报错注入中的head注入&#xff08;less-18&#xff09; 1.输入用户名和密码123 123显示登录错误 2.输入用户名和密码123’ 123显示登录错误 则证明不是普通报错注入&#xff0c;因为有用户名和密码框&#xff0c;如果不是普通报错注入则尝试head注入 3.用burp进行爆破&#x…

1865_发动机控制器ECU

Grey 全部学习内容汇总&#xff1a; GitHub - GreyZhang/g_ECU_hacking: some learning notes about ECU(engine control unit) hacking. 发动机控制器ECU ECU有多种解释&#xff0c;这里的解释主要是指发动机控制器。这一份笔记&#xff0c;整理了发动机控制器的基本功能以…