PySimpleGUI / PySimpleGUI/PySimpleGUI

*** NEW FEATURE *** The PySimpleGUI PEP8 interface! For those that hate the camel cased methods....

未关闭
#1,852 0 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

announcements Port - Cross-port
主要语言
Python
星标
13.8k
派生
1.8k
PR 合并指标
30 天内没有已合并 PR

描述

One "problem" with PySimpleGUI is that it's not PEP8 compliant. When it was originally written, PEP8 wasn't part of my vocabulary. Somehow I missed that chapter. I think it was because I was really learning about classes for the first time (first time having to use them for real).

Through the magic of Python, I'm happy to say that ALL of the interfaces in the Elements and all of the functions you call have a PEP8 equivalent now. Notice that I didn't say replaced.

You can use BOTH the "old", "original recipe" way, or the new PEP8 way. I suppose eventually the old way will need to stop being supported, but that's not going to be for a while as all of the docs need to change again, as well as the Demos, etc.

What does this really mean?

It means you can write:
window.FindElement as window.find_element

Combo.Update as Combo.update

Popup as 'popup'

PopupAutoClose as popup_auto_close

Make sense?

This is in release 4.3.0.1 Unreleased on GitHub. We need some runtime on it before sending to PyPI, although I'm tempted to go straight there with it as not many people run right from the GitHub that I'm aware of. Only if I fix a bug or add a new feature do people tend to grab it.

Anyway, it's there. You can stop grumbling in your head if that's what you've been doing. Strangely, it HAS been only in people's heads. Not since the initial release when CamelCase was also used for named parameters that I have heard a complaint about the method names. Or if I do, it's super rare and not made a huge deal of. It's probably because Qt does this too?

It's fully recognized that if this package is to go further mainstream, it needs to look the part of a Python solution for GUIs. If PySimpleGUI is going to claim to be very-pythonic, then gotta be PEP8 compliant from a users point of view. Internally the code is still a mess however :-)

Oh, finally, you will have to do a second jump to get to the definition of a method if you are debugging in an IDE and are looking up the location of the method. The help system and docs continue to show the old naming conventions. They'll get fixed over time... just not yet.

Design Pattern 2B from the cookbook.... old and new ways

import PySimpleGUI as sg

layout = [[sg.Text('Your typed chars appear here:'), sg.Text('', size=(15,1), key='_OUTPUT_')],
          [sg.Input(key='_IN_')],
          [sg.Button('Show'), sg.Button('Exit')]]

window = sg.Window('Window Title', layout)

while True:  # Event Loop
    event, values = window.Read()
    print(event, values)
    if event is None or event == 'Exit':
        break
    if event == 'Show':
        # Update the "output" element to be the value of "input" element
        window.Element('_OUTPUT_').Update(values['_IN_'])

window.Close()

The PEP8 interface way

import PySimpleGUI as sg

layout = [[sg.Text('Your typed chars appear here:'), sg.Text('', size=(15,1), key='_OUTPUT_')],
          [sg.Input(key='_IN_')],
          [sg.Button('Show'), sg.Button('Exit')]]

window = sg.Window('Window Title', layout)
while True:  # Event Loop
    event, values = window.read()
    print(event, values)
    if event in (None, 'Exit'):
        break
    if event == 'Show':
        # Update the "output" element to be the value of "input" element
        window.find_element('_OUTPUT_').update(values['_IN_'])

window.close()

And finally, the PEP8 + New FindElement + New Update.
In the 4.2 release the FindElement was replaced by window[key].

Also in the 4.2 release, you can "call Update" by calling the object. Yes, sounds weird but is awesome in reality

This version is only 1 line change different than the above, but wanted to give a complete version every time.

import PySimpleGUI as sg

layout = [[sg.Text('Your typed chars appear here:'), sg.Text('', size=(15,1), key='_OUTPUT_')],
          [sg.Input(key='_IN_')],
          [sg.Button('Show'), sg.Button('Exit')]]

window = sg.Window('Window Title', layout)
while True:  # Event Loop
    event, values = window.read()
    print(event, values)
    if event in (None, 'Exit'):
        break
    if event == 'Show':
        # Update the "output" element to be the value of "input" element
        window['_OUTPUT_'](values['_IN_'])

window.close()

None of this is documented in the docs yet as they only came to be today and yesterday I think. It's a blur.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

该 issue 未指定任何文件或测试,并说明 PEP8 接口已在 release 4.3.0.1 中实现,而文档和 Demos 仍需更新。首先检查现有文档和 Demos,查找旧 API 示例;当相关示例解释并使用 PEP8 对应项,同时保留此处所述的 legacy 兼容性时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
developer-experience, documentation
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
20/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。