将类型提示的Python程序转换为具有少量额外代码的GUI应用程序
项目描述
gooey-quick
将类型提示的Python程序转换为具有少量额外代码的GUI应用程序
目录
快速开始
安装
您可以通过pip安装gooey-quick
pip install gooey-quick
或直接克隆仓库
git clone https://github.com/jacadzaca/gooey_quick.git && ./setup.py
使用
您可以将gooey-quick与您的代码轻松集成,如下所示
import gooey_quick
def some_function_you_want_to_gooeyfiy(
name: str,
repeat_count: int,
):
for _ in range(repeat_count):
print(f'Hello {name}')
if __name__ == '__main__':
gooey_quick.run_gooey(some_function_you_want_to_gooeyfiy)
Gooey全局配置
您可以通过在调用gooey_quick.run_gooey
时设置它们来设置Gooey的全局选项(如下所示)
import gooey_quick
def some_function_you_want_to_gooeyfiy(
name: str,
repeat_count: int,
):
for _ in range(repeat_count):
print(f'Hello {name}')
if __name__ == '__main__':
gooey_quick.run_gooey(
some_function_you_want_to_gooeyfiy,
program_name='Simple demo program',
program_description='A demo program using Gooey and gooey_quick',
)
是什么?
gooey-quick是一个库,它通过方法的签名生成基于Gooey的GUI。
为什么?
许多在办公环境中编写的GUI程序都是简单的Python代码的包装器。手工制作GUI可能很繁琐,而随着程序的增长,处理类似于argparse的界面变得更加令人烦恼(例如,您在Gooey高级布局程序中有6个选项卡)。使用gooey-quick,您应该忘记上述内容,专注于程序的功能。
它是如何工作的?
gooey-quick使用Python内置的typing和introspection功能来分析对象签名,并使用chriskiehl的Gooey生成一个令人惊叹的GUI。
示例
简单的'Flat layout'应用程序
#!/usr/bin/env python3
from enum import Enum
from pathlib import Path
from datetime import date, time
import gooey_quick
class UploadMethod(Enum):
SFTP = 'SFTP'
HTTP = 'HTTP'
def upload_file(
file: Path,
new_filename: str,
chunksize: int,
lattency: float,
upload_date: date,
upload_time: time,
upload_method: UploadMethod,
):
assert type(upload_method) is UploadMethod
return (
f'{file} was uploaded via {upload_method.name} on {upload_date} at '
f'{upload_time} in chunks of size {chunksize} and with lattency of '
f'{lattency}'
)
if __name__ == '__main__':
# gooey_quick.run_gooey has the same return values as the wrapped function
return_value = gooey_quick.run_gooey(
# the first argument is the fucntion you'd like to be converted into a Gooey program
upload_file,
# gooey_quick.run_gooey can be used to set Gooey's global configuration
# see https://github.com/chriskiehl/Gooey#global-configuration for possible options
program_name='Simple upload program',
program_description='A demo program using Gooey and gooey_quick',
)
print(return_value)
以高级模式启动Gooey,有3个不同的选项卡
#!/usr/bin/env python3
from pathlib import Path
from typing import Optional
from datetime import date, datetime
import gooey_quick
def search_history(
history_file: Path,
wanted_phrase: str,
min_occure_date: Optional[date] = None,
max_occure_date: Optional[date] = None,
) -> Optional[tuple[date, str]]:
occurance_date = date(year=2002, month=7, day=22)
the_phrase = "wow you have discovered my secret phrase!"
occurance_in_range = True
if min_occure_date is not None and max_occure_date is not None:
print(f'Looking for {wanted_phrase} from {min_occure_date} to {max_occure_date}...')
occurance_in_range = occurance_date in range(min_occure_date, max_occure_date)
if wanted_phrase in the_phrase and occurance_in_range:
return f'{occurance_date}: {the_phrase}'
def append_to_history(
history_file: Path,
phrase: str,
occurance_date: date = datetime.now().date()
):
return f'Appending {phrase} to {history_file} at {occurance_date}...'
def remove_from_history(
history_file: Path,
phrase: str,
):
return f'Removing {phrase} from {history_file}...'
if __name__ == '__main__':
# when passing a dict to gooey_quick.run_gooey, the keys become
# the tabs descriptions, while the values are the function to
# create the gui from
return_value = gooey_quick.run_gooey(
{
'Add phrase': append_to_history,
'Remove phrase': remove_from_history,
'Search phrases': search_history,
},
# set Gooey's global config as per: https://github.com/chriskiehl/Gooey#layout-customization
navigation='TABBED',
program_name='Gooey subparser layout from function dict',
program_description='Presents how to create a bundeled configuration with gooey_quick',
)
print(return_value)
更多信息请参阅docs/examples/
目录。
打包
项目详情
下载文件
下载您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源分布
gooey-quick-1.0.1.tar.gz (12.2 kB 查看哈希值)
构建分布
gooey_quick-1.0.1-py3-none-any.whl (9.1 kB 查看哈希值)
关闭
gooey-quick-1.0.1.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | dd4fc9e344c2f3210498d5b0ecf90d734309c83d002c866cda5bdf18820cdb7a |
|
MD5 | 7f27b3e8db86603e64e25974732782f1 |
|
BLAKE2b-256 | 64c5eb1f976d46c25b3327aa363646a559d8ca61530fcbcda8fb92798a109b82 |
关闭
gooey_quick-1.0.1-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | fdcee4c14109490df7abc85ff275490140f5bd8bb64916245fdefe88288428e9 |
|
MD5 | 5f053bc444a1d2d54ef21281c0c9684a |
|
BLAKE2b-256 | 689f32791b7cece6507b1cfb03155760bdc423642dd4a2b62d7e3057571ed8cd |