使用PySimpleGUI和psgtray的热键管理器
项目描述
psghotkey
PySimpleGUI应用程序
Windows热键工具
TBD
功能
- 完整的热键管理器
- 演示如何将系统托盘集成到您的应用程序中
- 热键的复杂文档字符串格式化示例应用程序
安装
使用PyPI上的PIP
PySimpleGUI产品的最新官方版本可在PyPI上找到。要从PyPI安装演示应用程序,请使用以下命令
如果您在计算机上使用python
命令调用Python(Windows)
python -m pip install --upgrade psghotkey
如果您在计算机上使用python3
命令调用Python(Linux,Mac)
python3 -m pip install --upgrade psghotkey
使用GitHub上的PIP
您还可以通过pip安装PySimpleGUI GitHub账户中的应用程序。GitHub版本包含修复的bug和尚未发布到PyPI的新程序/功能。要从该存储库直接pip安装:
如果您在计算机上使用python
命令调用Python(Windows)
python -m pip install --upgrade https://github.com/PySimpleGUI/psghotkey/zipball/main
如果您在计算机上使用python3
命令调用Python(Linux,Mac)
python3 -m pip install --upgrade https://github.com/PySimpleGUI/psghotkey/zipball/main
使用方法
安装完成后,在命令行中键入以下内容以启动psghotkey:
psghotkey
使用的软件包
该项目使用以下pip可安装的软件包
- PySimpleGUI
- psgtray
- keyboard
Mash-up
该项目是某些PySimpleGUI演示程序和一个名为pingmote的程序的组合。该pingmote项目是键盘处理器的起源。非常感谢@dchen327提供的代码和灵感。
系统托盘代码来自psgtray。psgtray软件包是PySimpleGUI的tkinter端的重要附加组件,它使您能够在系统托盘中运行应用程序。
文档字符串工具
最初需要热键的原因是方便启动几个简单的在剪贴板上操作的小工具。它们都读取剪贴板,查找文档字符串,修改文档字符串,并将结果保存回剪贴板。
思路是按照以下步骤进行工作流程:
- 将带有文档字符串的文本复制到剪贴板
- 按下热键以调用文档字符串工具之一
- 将修改后的剪贴板粘贴到代码中
AlignDocstrings.py
该程序读取文档字符串并将描述和类型对齐。它假定文档字符串的格式是PySimpleGUI项目使用的格式。
示例是最容易展示它做了什么的办法。
输入
这是剪贴板上的输入
def execute_py_file(pyfile, parms=None, cwd=None, interpreter_command=None, wait=False, pipe_output=False):
"""
Executes a Python file.
The interpreter to use is chosen based on this priority order:
1. interpreter_command paramter
2. global setting "-python command-"
3. the interpreter running running PySimpleGUI
:param pyfile: the file to run
:type pyfile: (str)
:param parms: parameters to pass on the command line
:type parms: (str)
:param cwd: the working directory to use
:type cwd: (str)
:param interpreter_command: the command used to invoke the Python interpreter
:type interpreter_command: (str)
:param wait: the working directory to use
:type wait: (bool)
:param pipe_output: If True then output from the subprocess will be piped. You MUST empty the pipe by calling execute_get_results or your subprocess will block until no longer full
:type pipe_output: (bool)
:return: Popen object
:rtype: (subprocess.Popen) | None
"""
输出
这是留在剪贴板上的结果
def execute_py_file(pyfile, parms=None, cwd=None, interpreter_command=None, wait=False, pipe_output=False):
"""
Executes a Python file.
The interpreter to use is chosen based on this priority order:
1. interpreter_command paramter
2. global setting "-python command-"
3. the interpreter running running PySimpleGUI
:param pyfile: the file to run
:type pyfile: (str)
:param parms: parameters to pass on the command line
:type parms: (str)
:param cwd: the working directory to use
:type cwd: (str)
:param interpreter_command: the command used to invoke the Python interpreter
:type interpreter_command: (str)
:param wait: the working directory to use
:type wait: (bool)
:param pipe_output: If True then output from the subprocess will be piped. You MUST empty the pipe by calling execute_get_results or your subprocess will block until no longer full
:type pipe_output: (bool)
:return: Popen object
:rtype: (subprocess.Popen) | None
"""
AddTypesToDocstring.py
PyCharm会自动为您创建文档字符串。在函数定义之后,如果您输入"""
,则它将使用函数定义中找到的参数填充文档字符串。这是一个很棒的功能。
但是……这些文档字符串的格式不是PySimpleGUI文档创建工具(特别是调用引用)使用的2行格式。此实用程序只需在文档字符串中添加type
和rtype
行。像其他文档字符串工具一样,它以剪贴板作为输入,并将结果放置在剪贴板上。
输入
def execute_py_file(pyfile, parms=None, cwd=None, interpreter_command=None, wait=False, pipe_output=False):
"""
:param pyfile:
:param parms:
:param cwd:
:param interpreter_command:
:param wait:
:param pipe_output:
:return:
"""
输出
此实用程序仅在剪贴板上留下文档字符串。剪贴板前后任何其他文本都被移除。如您所见,区别在于每个param
行都有一个匹配的type
行,而return
有一个匹配的rtype
。
"""
:param pyfile:
:type pyfile:
:param parms:
:type parms:
:param cwd:
:type cwd:
:param interpreter_command:
:type interpreter_command:
:param wait:
:type wait:
:param pipe_output:
:type pipe_output:
:return:
:rtype:
"""
仅限Windows(很可能)
psgtray
在Windows上运行最佳,并在此项目中使用。尚未在Linux或Mac上尝试。
改进的机会
在此项目中投入的时间不多。这是我为自己编写的某些个人实用工具,然后意识到也许其他人也希望扩展他们的IDE或进行其他热键操作。
在此项目中,键盘处理程序在底层钩入,以便所有按键都会传递到程序。很可能keyboard
包有一个更高效且更高级的接口,但没有使用。
"Satisfice"是我在最近发现的一个词,并意识到它与我的原型代码相匹配。这是一种相当蹩脚的代码,因为它旨在在特定的系统上完成特定的任务,而不是以通用方式设计。这是“第一版”代码……原始、简单、可工作,但不超过这些。但是,至少它应该在您的系统上运行,假设您能够运行psgtray和PySimpleGUI。
希望您能在这里找到一些有用的东西,帮助您创建自己的工具,使您更有效率。
许可权 & 版权
版权所有 2023-2024 PySimpleSoft, Inc. 和/或其许可方。
这是一个免费使用的“实用工具”,并受 PySimpleGUI 许可协议的许可,协议副本包含在 license.txt 文件中,也可在 https://pysimplegui.com/eula 上找到。
请参阅许可协议的第1.2节,了解此实用工具的使用,有关任何问题请访问 https://pysimplegui.com/faq。
贡献
我们很高兴收到描述错误报告和功能请求的问题!如果您的问题报告与安全漏洞有关,请不要提交公开问题,而是请通过issues@PySimpleGUI.com与我们联系。
我们不接受(也不希望收到)用户创建或第三方代码的贡献,包括补丁、拉取请求或包含在提交问题中的代码片段。请勿向我们发送此类代码!错误报告和功能请求不应包含任何源代码。
如果您仍然向我们提交任何用户创建或第三方代码,(1) 您将授予我们有关该代码的所有权利和所有权;以及 (2) 在任何此类转让不充分有效的情况下,您特此授予我们一项免版税、永久性、不可撤销、全球性、无限期、可再许可、可转让的许可,根据其中或与之相关的所有知识产权权利,以我们选择的方式利用代码,包括将其纳入 PySimpleGUI 以及根据我们自行决定的任何条款重新分发。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源分发
构建分发
psghotkey-5.0.0.tar.gz 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | ff4b88ed51aebbe5166502aae3c8d75095aa80dee4e6d5736f8cba5622de978b |
|
MD5 | 8d744afff7fbff25b65939858fddbf16 |
|
BLAKE2b-256 | 0dca8c0740b1501489716f3437cf94e848f4abca8c1e4b943f20b422286d5910 |
psghotkey-5.0.0-py3-none-any.whl 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | 99b732c61480dad1b25b2a6a513fd5a4497914f672a8893e9ea63baa5d29366a |
|
MD5 | 989c001eddcf0196c194dcaa74840313 |
|
BLAKE2b-256 | fe7bf371b1679617acbb110a085ad13488d3556ebc26186f868af72351a95976 |