Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Wes Turner
ipywidgets and toga* implementations of the ABC demo:

| source: https://github.com/westurner/guidemo

# ipywidgetsdemo/ipywidgets_abc_demo.py (.ipynb)

# # ipywidgets ABC demo
# - Update an output widget with the sum of two input widgets when the
'change' event fires

# In[1]:
# https://ipywidgets.readthedocs.io/en/latest/examples/Using%20Interact.html
# https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20List.html
from ipywidgets import interact
import ipywidgets as widgets
def add(x, y):
return sum((x,y))
widget_x = widgets.IntText(value=0, description='#1')
widget_y = widgets.IntText(value=0, description='#2')
interact(add, x=widget_x, y=widget_y)


# In[2]:
#
https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20Events.html#Registering-callbacks-to-trait-changes-in-the-kernel
from IPython.display import display
from ipywidgets import interact
import ipywidgets as widgets

widget_x = widgets.IntText(value=0, description='#1')
widget_y = widgets.IntText(value=0, description='#2')
widget_sigma = widgets.IntText(value=0, description='sum')

def add_event(event):
widget_sigma.value = sum((widget_x.value, widget_y.value))

widget_x.observe(add_event, names='value')
widget_y.observe(add_event, names='value')

display(widgets.HBox([widget_x, widget_y, widget_sigma]))




# togaabcdemo/app.py

import toga
from toga.style import Pack
from toga.style.pack import COLUMN, ROW


class TogaAbcDemo(toga.App):

def add_numbers(self, widget):
# TODO: validate that n*_input.value are numbers
n1, n2 = self.n1_input.value, self.n2_input.value
n3 = sum(n1, n2) if ((n1 is not None) and (n2 is not None)) else
None
print("%r + %r = %r" % (n1, n2, n3))
self.n3_input.value = n3

def startup(self):
# Create a main window with a name matching the app
self.main_window = toga.MainWindow(title=self.name)

# Create a main content box
main_box = toga.Box()

self.n1_input = toga.TextInput(
placeholder='#1',
on_change=self.add_numbers)
self.n2_input = toga.TextInput(
placeholder='#2',
on_change=self.add_numbers)
self.n3_input = toga.TextInput(
placeholder='Sum',
readonly=True)

main_box.add(self.n1_input)
main_box.add(self.n2_input)
main_box.add(self.n3_input)

# Add the content on the main window
self.main_window.content = main_box

# Show the main window
self.main_window.show()


def main():
return TogaAbcDemo('Toga ABC Demo',
'org.westurner.togaabcdemo.togaabcdemo')



On Fri, Aug 24, 2018 at 4:12 AM Wes Turner  wrote:

>
>
> On Thursday, August 23, 2018, Jonathan Fine  wrote:
>
>> Hi Mike
>>
>> Thank you for your prompt response. You wrote
>>
>> > Maybe we're on different planes?
>> >
>> > I'm talking about 5 lines of Python code to get a custom layout GUI on
>> the screen:
>> >
>> > import PySimpleGUI as sg
>> >
>> > form = sg.FlexForm('Simple data entry form')  # begin with a blank form
>> >
>> > layout = [
>> >   [sg.Text('Please enter your Name, Address, Phone')],
>> >   [sg.Text('Name', size=(15, 1)), sg.InputText('1',
>> key='name')],
>> >   [sg.Text('Address', size=(15, 1)), sg.InputText('2',
>> key='address')],
>> >   [sg.Text('Phone', size=(15, 1)), sg.InputText('3',
>> key='phone')],
>> >   [sg.Submit(), sg.Cancel()]
>> >  ]
>> >
>> > button, values = form.LayoutAndRead(layout)
>>
>> The execution of this code, depends on PySimpleGUI, which in turn depends
>> on tkinter, which is in turn a thin layer on top of Tcl/Tk. And Tcl/Tk
>> provides the GUI layer.
>> (See https://docs.python.org/3/library/tk.html.)
>>
>> I'm suggest that sometimes it may be better to use HTML5 to provide the
>> GUI layer. I pointed to Elm, to show how powerful HTML5 has become.
>>
>
> BeeWare uses Toga (a widget toolkit) and Briefcase (a build tool) to build
> native GUIs and SPA web apps
>
> > Write your apps in Python and release them on iOS, Android, Windows,
> MacOS, Linux, Web, and tvOS using rich, native user interfaces. One
> codebase. Multiple apps.
>
> Briefcase can build Django apps.
>
> https://pybee.org
> https://pybee.org/project/using/
> https://briefcase.readthedocs.io/en/latest/tutorial/tutorial-0.html
> https://toga.readthedocs.io/en/latest/tutorial/tutorial-0.html
>
> It's definitely not a single file module, though.
>
> Bottle is a single file web framework ('microframework'); but it doesn't
> have a widget toolkit.
>
> Web development is not as easy to learn as a simple GUI api for beginners
> (and then learning what to avoid in terms of websec is a lot to learn).
>
> There was a thread about deprecating Tk awhile back. There also I think I
> mentioned that asyncio event loop support would be great for real world
> apps.
>
___
Python-ideas mailing list
Python-ideas@python.org
https

Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Cody Piersall
On Thu, Aug 23, 2018 at 11:59 PM Steve Barnes  wrote:
> There are already 2 ways of turning a python program that uses argparse
> into a GUI, (Gooey for wx & Quicken for QT IIRC), with minimal
> modification. There are a lot of good arguments for teaching people to
> use argparse and to write their code to be able to run from the command
> line but there is not a mechanism that I am aware of for turning
> argparse based code into a TK GUI this might be a fruitful area to look
> at.

I started working on a project that does that a few years ago.  It
requires that you provide a function that takes an argparse.Namespace,
and then it can make a GUI using tkinter.  The code is on GitHub:
https://github.com/codypiersall/cligui.  The license is MIT.

Example script using cligui:

```
# Makes a GUI appear.  How fortunate!
import argparse
import cligui

def get_parser():
"""Create a parser that does all the best things."""
p = argparse.ArgumentParser(description='such a good program')
p.add_argument('infile')
p.add_argument('outfile')
return p

def do_the_best_things(args):
"""This does the best things.

Note: "args" is an argparse.Namespace -- the thing you get back whenever
you call argparse.ArgumentParser().parse_args().
"""
print('got args', args)

def main():
"""This incredible function will make a GUI appear.  Remarkable!"""
p = get_parser()
# call cligui.CliGui with the parser, and a function that takes an
# argparse.Namespace as its argument.
cligui.CliGui(p, do_the_best_things)

if __name__ == '__main__':
main()
```

For background: the goal was to be able to let my less-technical
coworkers use scripts that I had written; but then I got a job
elsewhere and stopped working on this.

Cody
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Greg Ewing

Mike Barnett wrote:

Unsubscribing from this mess.  “Python Ideas” ?


We didn't mean to drive you away! Python discussions have a
tendency to roam far and wide. It doesn't mean we're not
interested in what you have to say.

Any new package is naturally going to invite comparisons with
similar things that have been done before. That's not a bad
thing -- it's always good to see what others have done in
the same field.

Although your package is unlikely to be put into the stdlib
any time soon, it would be a fine thing to have on PyPI,
and I'm sure there are people here willing to help you
develop it. You may just need to be prepared to ignore
some digressions.

--
Greg
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Greg Ewing

Here are some PyGUI versions of the ABC Challenge.

# Modal 

from GUI import ModalDialog, Label, TextField, Row, Column, Grid
from GUI.StdButtons import DefaultButton, CancelButton
from GUI.Alerts import note_alert

a = TextField(width = 100)
b = TextField(width = 100)
c = TextField(width = 100)
buttons = Row([DefaultButton(), CancelButton()])
dlog = ModalDialog(title = "ABC Challenge")
dlog.add(Column([
Grid([
[Label("A"), a],
[Label("B"), b],
[Label("C"), c],
]),
buttons],
padding = (10, 10)))
dlog.shrink_wrap()
if dlog.present():
note_alert("Sum = %s" % (int(a.text) + int(b.text) + int(c.text)))

# Non-Modal --

from GUI import Window, Label, TextField, Grid, application

def update():
try:
c.text = str(int(a.text) + int(b.text))
except ValueError:
c.text = ""

a = TextField(width = 100, text_changed_action = update)
b = TextField(width = 100, text_changed_action = update)
c = TextField(width = 100, editable = False)
win = Window(title = "ABC Challenge")
win.add(
Grid([
[Label("A"), a],
[Label("B"), b],
[Label("A + B"), c],
], padding = (10, 10)))
win.shrink_wrap()
win.show()
application().run()

--
Greg
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Mike Barnett
It’s fascinating just how many packages are being dragged out for examination 
or clobbering other than the one that I asked for assistance/help on.

I see the code of conduct link in the thread.  Perhaps a review would be 
helpful.

Unsubscribing from this mess.  “Python Ideas” ?



@mike

From: Python-ideas  
On Behalf Of Stephan Houben
Sent: Friday, August 24, 2018 9:07 PM
To: Chris Barker 
Cc: Python-Ideas 
Subject: Re: [Python-ideas] A GUI for beginners and experts alike


Op za 25 aug. 2018 02:28 schreef Chris Barker - NOAA Federal via Python-ideas 
mailto:python-ideas@python.org>>:


Too bad all the cool kids are doing web dev these days — hard to get
help with a desktop GUI project :-(

Pywebview seems interesting, uses a platform  webview to put up the UI;

https://github.com/r0x0r/pywebview

But not so newbie-friendly I am afraid...

Stephan


> Pyjamas seems to be something like that:
>
> https://pypi.org/project/Pyjamas/

Or it was 6 years ago :-(

-CHB
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: 
http://python.org/psf/codeofconduct/
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Greg Ewing

Chris Barker - NOAA Federal wrote:

Now that you say that, I think I’m mingling memories — there was
another project that attempted to wrap TKInter, wxPython, QT .. I
always thought that was ill advised.


You're probably thinking of "anygui" (named in the spirit of
"anydbm"). As far as I remember, it never really got off the
ground.


QT might make some sense— you need something on top of X, don’t you?


Linux is currently covered by a Gtk implementation, which
seems to be about as close as you get to a "native" GUI
toolkit on Linux. X-based systems without Gtk are currently
out ofscope -- but contributions are always welcome!

--
Greg
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Stephan Houben
Op za 25 aug. 2018 02:28 schreef Chris Barker - NOAA Federal via
Python-ideas :

>
>
> Too bad all the cool kids are doing web dev these days — hard to get
> help with a desktop GUI project :-(
>

Pywebview seems interesting, uses a platform  webview to put up the UI;

https://github.com/r0x0r/pywebview

But not so newbie-friendly I am afraid...

Stephan


> > Pyjamas seems to be something like that:
> >
> > https://pypi.org/project/Pyjamas/
>
> Or it was 6 years ago :-(
>
> -CHB
> ___
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Chris Barker - NOAA Federal via Python-ideas
> If you're talking about my PyGUI project, using it with
> wPython doesn't really make sense.

Now that you say that, I think I’m mingling memories — there was
another project that attempted to wrap TKInter, wxPython, QT .. I
always thought that was ill advised.

> The goal is to provide exactly one high-quality
> implementation for each platform, with as few layers as
> practicable between the Python API and the platform's native
> GUI facilities.

So kinda like wxWidgets but in Python — which would be nice. wxPython
definitely suffers from its C++ underpinnings.

> Implementations on top
> of wxPython, Qt etc. could probably be created,

QT might make some sense— you need something on top of X, don’t you?

>> I'd also make sure that you CAN "drop down" into the lower level toolkit 
>> fairly smoothly, if you do need something more complex that the basics.
>
> PyGUI provides everything you need to create a custom widget,
> without needing to go down to a lower level.

In that context, I was thinking about the OP’s concept— very high
level, pretty much declarative. It’s going to run into limitations
fast. So there should be s way to customize user interaction.

Too bad all the cool kids are doing web dev these days — hard to get
help with a desktop GUI project :-(

> Pyjamas seems to be something like that:
>
> https://pypi.org/project/Pyjamas/

Or it was 6 years ago :-(

-CHB
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Mike Barnett
Nice Matt!

Thanks for taking the time to code it up!  It’s great to see examples like 
these.

@mike

From: Python-ideas  
On Behalf Of Matthew Einhorn
Sent: Friday, August 24, 2018 7:51 PM
To: python-ideas@python.org
Subject: Re: [Python-ideas] A GUI for beginners and experts alike

Hi Mike

I'm not sure this thread is python-ideas appropriate, but since the challenge 
is out, here it is using Kivy. The code and result is at 
https://gist.github.com/matham/45c4f1fbd8c3fccf6557b3b48356cd50
 (image 
https://gist.githubusercontent.com/matham/45c4f1fbd8c3fccf6557b3b48356cd50/raw/dbbf74f17ad4beab49f022bbf43fcc72ff725084/kivy_gui.png).
 The code is also inlined below.

I wrote it to be one file so I used the string version (load_string) for 
defining the GUI, but the GUI definition could have been written as a separate 
kv file. I could also have written it using pure python, but that is more 
verbose and less intuitive. Also, Kivy works on pretty much all platforms 
(windows, linux, osx, android, ios) and is written in pure python (and cython) 
on top of opengl.

All the best,
Matt

P.S. here's the inlined code:

from kivy.lang import Builder
from kivy.app import runTouchApp

runTouchApp(Builder.load_string('''
#:import Factory kivy.factory.Factory
BoxLayout:
orientation: 'vertical'
padding: "12dp"
spacing: "12dp"
Label:
text: "Please enter 3 numbers"
BoxLayout:
spacing: "10dp"
Entry:
id: a
hint_text: "A"
Entry:
id: b
hint_text: "B"
Entry:
id: c
hint_text: "C"
Label:
text: "The sum is {}".format(a.val + b.val + c.val)


:
input_filter: "float"
val: float(self.text) if self.text else 0
'''))


On Fri, Aug 24, 2018 at 5:28 PM Clément Pit-Claudel 
mailto:cpitclau...@gmail.com>> wrote:
Hi Mike,

Thanks, this code is nice and short.  Is adding 'if button is None: break' to 
the 'Read' version of your code the right way to make it exit when the main 
window is closed? (On my machine it enters an infinite loop after I close the 
main window).

For comparison, I tried doing this with PyGObject.
I created the UI with glade, which auto-generated the attached XML file.  Then 
I had to write the following code (I had never used Glade or PyGObject before, 
so apologies if there are mistakes in the following):

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

def main():
builder = Gtk.Builder()
builder.add_from_file("sum.glade")

get = builder.get_object
a, b, answer, window = get("a"), get("b"), get("answer"), get("window")

def update_sum(_entry):
try:
tanswer = int(a.get_text()) + int(b.get_text())
answer.set_text(str(tanswer))
except ValueError:
pass

a.connect("changed", update_sum)
b.connect("changed", update_sum)
window.connect("destroy", Gtk.main_quit)

window.show_all()
Gtk.main()

if __name__ == '__main__':
main()

Having a visual editor for the UI feels like a plus, and I find the resulting 
XML verbose but acceptably readable.
On the other hand, I like the conciseness of your UI specs.

Cheers,
Clément.

On 2018-08-24 16:38, Mike Barnett wrote:
> I should have mentioned that you need the GitHub version of the code in order 
> to get the keyboard events. Rather than do a pip install you can download 
> this file and put it in your project folder:
>
> https://github.com/MikeTheWatchGuy/PySimpleGUI/blob/master/PySimpleGUI.py
>
> Sorry for any confusion.
>
> I also got a question if this code blocks or is in a spin-loop.   The answer 
> is that the posted version blocks until some kind of form input.  Should you 
> want to turn the program into one that polls instead of blocks,  the loop 
> changes slightly to enable form close detection.  It's basically the same 
> with the Read call being replaced by ReadNonBlocki

Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Chris Barker - NOAA Federal via Python-ideas
while True:
   button, (a,b) = form.Read()
   try:
   answer = int(a) + int(b)
   output.Update(answer)
   except:
   pass


Whoa! You really want people to write their own event loop? That seems like
a bad idea to me.

If you want people to not have to think about events much, maybe look at
traitsui for ideas.

http://docs.enthought.com/traitsui/

-CHB
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Greg Ewing

Chris Barker via Python-ideas wrote:


In fact, there was an effort along these lines a few years back:

http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/

I don't know that it's seen much development lately.


It hasn't, sorry to say. Turns out that writing and maintaining
what is effectively 3 complete GUI toolkits takes a more
copious supply of round tuits than I have at the moment. :-(

In fact, I always thought Pyton_guiu above really suffered from that 
conceptually. For example, if you used pyton-gui with a wxPython back 
end, you had:


A python wrapper around a python wrapper around a C++ wrapper around 
each native toolkit.


If you're talking about my PyGUI project, using it with
wPython doesn't really make sense.

I specifically wanted to avoid the multiple-wrapper problem,
so I decided *not* to wrap any existing cross-platform GUI
toolkit. The goal is to provide exactly one high-quality
implementation for each platform, with as few layers as
practicable between the Python API and the platform's native
GUI facilities.

One result of that is that PyGUI is not really structured as
a "front end" and "back end" with a defined interface between
them. There is generic code and platform-specific code, but
they're fairly closely intertwined. Implementations on top
of wxPython, Qt etc. could probably be created, but I won't be
doing it myself, because it would take a lot of work and
I don't think it would be necessary or desirable.


1)  re-implement widgets with native basic drawing and event handling.
  - this is what QT GTK, and TK do
2) Wrap the native widgets
  - this is what wxWidgets does


PyGUI does (2).

TK is essentially (1), though AIUI, it was originally written for 
X-windows, and the other platform have an X-windows emulation layer, and 
then all the TK code works with that.


Yeah, X Windows is a bit special, because there is no such
thing os a "native" look and feel for widgets on X -- there
have been multiple GUI toolkits for X from the beginning,
each with its own style. So Tk inventing a new one all of
its own wasn't really a bad thing at the time.

I'd also make sure that you CAN "drop down" into the lower level toolkit 
fairly smoothly, if you do need something more complex that the basics.


PyGUI provides everything you need to create a custom widget,
without needing to go down to a lower level.

You could also create a wrapper for a native widget that
PyGUI doesn't already provide, but the techniques for doing
so are currently undocumented and might change between
releases.



Finally -- I'm not sure the desktop is dead, but there is a heck of a 
lot going on in the browser. And if someone could write a simple GUI for 
a desktop app, and then easily prt that to a WebApp -- that would be great.


Pyjamas seems to be something like that:

https://pypi.org/project/Pyjamas/

--
Greg
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Matthew Einhorn
Hi Mike

I'm not sure this thread is python-ideas appropriate, but since the
challenge is out, here it is using Kivy. The code and result is at
https://gist.github.com/matham/45c4f1fbd8c3fccf6557b3b48356cd50 (image
https://gist.githubusercontent.com/matham/45c4f1fbd8c3fccf6557b3b48356cd50/raw/dbbf74f17ad4beab49f022bbf43fcc72ff725084/kivy_gui.png).
The code is also inlined below.

I wrote it to be one file so I used the string version (load_string) for
defining the GUI, but the GUI definition could have been written as a
separate kv file. I could also have written it using pure python, but that
is more verbose and less intuitive. Also, Kivy works on pretty much all
platforms (windows, linux, osx, android, ios) and is written in pure python
(and cython) on top of opengl.

All the best,
Matt

P.S. here's the inlined code:

from kivy.lang import Builder
from kivy.app import runTouchApp

runTouchApp(Builder.load_string('''
#:import Factory kivy.factory.Factory
BoxLayout:
orientation: 'vertical'
padding: "12dp"
spacing: "12dp"
Label:
text: "Please enter 3 numbers"
BoxLayout:
spacing: "10dp"
Entry:
id: a
hint_text: "A"
Entry:
id: b
hint_text: "B"
Entry:
id: c
hint_text: "C"
Label:
text: "The sum is {}".format(a.val + b.val + c.val)


:
input_filter: "float"
val: float(self.text) if self.text else 0
'''))



On Fri, Aug 24, 2018 at 5:28 PM Clément Pit-Claudel 
wrote:

> Hi Mike,
>
> Thanks, this code is nice and short.  Is adding 'if button is None: break'
> to the 'Read' version of your code the right way to make it exit when the
> main window is closed? (On my machine it enters an infinite loop after I
> close the main window).
>
> For comparison, I tried doing this with PyGObject.
> I created the UI with glade, which auto-generated the attached XML file.
> Then I had to write the following code (I had never used Glade or PyGObject
> before, so apologies if there are mistakes in the following):
>
> import gi
> gi.require_version('Gtk', '3.0')
> from gi.repository import Gtk
>
> def main():
> builder = Gtk.Builder()
> builder.add_from_file("sum.glade")
>
> get = builder.get_object
> a, b, answer, window = get("a"), get("b"), get("answer"), get("window")
>
> def update_sum(_entry):
> try:
> tanswer = int(a.get_text()) + int(b.get_text())
> answer.set_text(str(tanswer))
> except ValueError:
> pass
>
> a.connect("changed", update_sum)
> b.connect("changed", update_sum)
> window.connect("destroy", Gtk.main_quit)
>
> window.show_all()
> Gtk.main()
>
> if __name__ == '__main__':
> main()
>
> Having a visual editor for the UI feels like a plus, and I find the
> resulting XML verbose but acceptably readable.
> On the other hand, I like the conciseness of your UI specs.
>
> Cheers,
> Clément.
>
> On 2018-08-24 16:38, Mike Barnett wrote:
> > I should have mentioned that you need the GitHub version of the code in
> order to get the keyboard events. Rather than do a pip install you can
> download this file and put it in your project folder:
> >
> >
> https://github.com/MikeTheWatchGuy/PySimpleGUI/blob/master/PySimpleGUI.py
> >
> > Sorry for any confusion.
> >
> > I also got a question if this code blocks or is in a spin-loop.   The
> answer is that the posted version blocks until some kind of form input.
> Should you want to turn the program into one that polls instead of blocks,
> the loop changes slightly to enable form close detection.  It's basically
> the same with the Read call being replaced by ReadNonBlocking.
> >
> > while True:
> > button, values = form.ReadNonBlocking()
> > if button is None and values is None:
> > break
> > a, b = values
> > try:
> > output.Update(int(a) + int(b))
> > except:
> > pass
> >
> >
> >
> > @mike
> >
> > -Original Message-
> > From: Mike Barnett 
> > Sent: Friday, August 24, 2018 3:36 PM
> > To: Chris Angelico ; Python-Ideas <
> python-ideas@python.org>
> > Subject: RE: [Python-ideas] A GUI for beginners and experts alike
> >
> >
> > So here's my alternative challenge:
> >
> > Take two numbers as inputs. Add them together and display them in a
> third field. Whenever either input is changed, recalculate the output.
> >
> > This requires proper event handling, so it's less likely to create a
> useless one-liner that has no bearing on real-world code.
> >
> > 
> >
> >
> >
> > Sure thing... post yours. I'll go ahead and post mine first.
> >
> > Here's the window this code produces.
> >
> >
> https://user-images.githubusercontent.com/13696193/44604157-02a2ac00-a7b3-11e8-928b-f67c5f2b3961.jpg
> >
> > And here's the code in a more readable form since the email formatting
> sucks.
> >
> https://user-images.githubusercontent.com/13696193/44604220-2cf46980-a7b3-11e8

Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Clément Pit-Claudel
Hi Mike,

Thanks, this code is nice and short.  Is adding 'if button is None: break' to 
the 'Read' version of your code the right way to make it exit when the main 
window is closed? (On my machine it enters an infinite loop after I close the 
main window).

For comparison, I tried doing this with PyGObject.
I created the UI with glade, which auto-generated the attached XML file.  Then 
I had to write the following code (I had never used Glade or PyGObject before, 
so apologies if there are mistakes in the following):

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

def main():
builder = Gtk.Builder()
builder.add_from_file("sum.glade")

get = builder.get_object
a, b, answer, window = get("a"), get("b"), get("answer"), get("window")

def update_sum(_entry):
try:
tanswer = int(a.get_text()) + int(b.get_text())
answer.set_text(str(tanswer))
except ValueError:
pass

a.connect("changed", update_sum)
b.connect("changed", update_sum)
window.connect("destroy", Gtk.main_quit)

window.show_all()
Gtk.main()

if __name__ == '__main__':
main()

Having a visual editor for the UI feels like a plus, and I find the resulting 
XML verbose but acceptably readable.
On the other hand, I like the conciseness of your UI specs.

Cheers,
Clément.

On 2018-08-24 16:38, Mike Barnett wrote:
> I should have mentioned that you need the GitHub version of the code in order 
> to get the keyboard events. Rather than do a pip install you can download 
> this file and put it in your project folder:
> 
> https://github.com/MikeTheWatchGuy/PySimpleGUI/blob/master/PySimpleGUI.py
> 
> Sorry for any confusion.
> 
> I also got a question if this code blocks or is in a spin-loop.   The answer 
> is that the posted version blocks until some kind of form input.  Should you 
> want to turn the program into one that polls instead of blocks,  the loop 
> changes slightly to enable form close detection.  It's basically the same 
> with the Read call being replaced by ReadNonBlocking.
> 
> while True:
> button, values = form.ReadNonBlocking()
> if button is None and values is None:
> break
> a, b = values
> try:
> output.Update(int(a) + int(b))
> except:
> pass
> 
> 
> 
> @mike
> 
> -Original Message-
> From: Mike Barnett  
> Sent: Friday, August 24, 2018 3:36 PM
> To: Chris Angelico ; Python-Ideas 
> Subject: RE: [Python-ideas] A GUI for beginners and experts alike
> 
> 
> So here's my alternative challenge:
> 
> Take two numbers as inputs. Add them together and display them in a third 
> field. Whenever either input is changed, recalculate the output.
> 
> This requires proper event handling, so it's less likely to create a useless 
> one-liner that has no bearing on real-world code.
> 
> 
> 
> 
> 
> Sure thing... post yours. I'll go ahead and post mine first.
> 
> Here's the window this code produces.
> 
> https://user-images.githubusercontent.com/13696193/44604157-02a2ac00-a7b3-11e8-928b-f67c5f2b3961.jpg
> 
> And here's the code in a more readable form since the email formatting sucks.
> https://user-images.githubusercontent.com/13696193/44604220-2cf46980-a7b3-11e8-86c5-ad3051222eaf.jpg
> 
> It's rather, uhm, simple to do
> 
> 
> import PySimpleGUI as gui
> 
> output = gui.Text('')
> 
> layout = [ [gui.Text('Enter 2 numbers')],
>[gui.Text('A'), gui.InputText()],
>[gui.Text('B'), gui.InputText()],
>[gui.Text('Answer = '), output],
>]
> 
> form = gui.FlexForm('Realtime Updates', return_keyboard_events=True)
> form.LayoutAndRead(layout)
> while True:
> button, (a,b) = form.Read()
> try:
> answer = int(a) + int(b)
> output.Update(answer)
> except:
> pass
> 
> 
> @mike
> ___
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
> 



sum.glade
Description: application/glade
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Mike Barnett
I should have mentioned that you need the GitHub version of the code in order 
to get the keyboard events. Rather than do a pip install you can download this 
file and put it in your project folder:

https://github.com/MikeTheWatchGuy/PySimpleGUI/blob/master/PySimpleGUI.py

Sorry for any confusion.

I also got a question if this code blocks or is in a spin-loop.   The answer is 
that the posted version blocks until some kind of form input.  Should you want 
to turn the program into one that polls instead of blocks,  the loop changes 
slightly to enable form close detection.  It's basically the same with the Read 
call being replaced by ReadNonBlocking.

while True:
button, values = form.ReadNonBlocking()
if button is None and values is None:
break
a, b = values
try:
output.Update(int(a) + int(b))
except:
pass



@mike

-Original Message-
From: Mike Barnett  
Sent: Friday, August 24, 2018 3:36 PM
To: Chris Angelico ; Python-Ideas 
Subject: RE: [Python-ideas] A GUI for beginners and experts alike


So here's my alternative challenge:

Take two numbers as inputs. Add them together and display them in a third 
field. Whenever either input is changed, recalculate the output.

This requires proper event handling, so it's less likely to create a useless 
one-liner that has no bearing on real-world code.





Sure thing... post yours. I'll go ahead and post mine first.

Here's the window this code produces.

https://user-images.githubusercontent.com/13696193/44604157-02a2ac00-a7b3-11e8-928b-f67c5f2b3961.jpg

And here's the code in a more readable form since the email formatting sucks.
https://user-images.githubusercontent.com/13696193/44604220-2cf46980-a7b3-11e8-86c5-ad3051222eaf.jpg

It's rather, uhm, simple to do


import PySimpleGUI as gui

output = gui.Text('')

layout = [ [gui.Text('Enter 2 numbers')],
   [gui.Text('A'), gui.InputText()],
   [gui.Text('B'), gui.InputText()],
   [gui.Text('Answer = '), output],
   ]

form = gui.FlexForm('Realtime Updates', return_keyboard_events=True)
form.LayoutAndRead(layout)
while True:
button, (a,b) = form.Read()
try:
answer = int(a) + int(b)
output.Update(answer)
except:
pass


@mike
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Mike Barnett


So here's my alternative challenge:

Take two numbers as inputs. Add them together and display them in a third 
field. Whenever either input is changed, recalculate the output.

This requires proper event handling, so it's less likely to create a useless 
one-liner that has no bearing on real-world code.





Sure thing... post yours. I'll go ahead and post mine first.

Here's the window this code produces.

https://user-images.githubusercontent.com/13696193/44604157-02a2ac00-a7b3-11e8-928b-f67c5f2b3961.jpg

And here's the code in a more readable form since the email formatting sucks.
https://user-images.githubusercontent.com/13696193/44604220-2cf46980-a7b3-11e8-86c5-ad3051222eaf.jpg

It's rather, uhm, simple to do


import PySimpleGUI as gui

output = gui.Text('')

layout = [ [gui.Text('Enter 2 numbers')],
   [gui.Text('A'), gui.InputText()],
   [gui.Text('B'), gui.InputText()],
   [gui.Text('Answer = '), output],
   ]

form = gui.FlexForm('Realtime Updates', return_keyboard_events=True)
form.LayoutAndRead(layout)
while True:
button, (a,b) = form.Read()
try:
answer = int(a) + int(b)
output.Update(answer)
except:
pass


@mike
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Chris Angelico
On Sat, Aug 25, 2018 at 5:13 AM, Mike Barnett  wrote:
> Here we go:
>
> Take 3 numbers as input (A, B, C).  Add them together.  Display the result in 
> a simple pop-up window.
>
> That’s a pretty typical kind of problem for the first few weeks of beginning 
> programming.  Maybe first few days.
>

Do you mean "beginning GUI programming", or are you saying that this
kind of thing should be in someone's first few days of programming
overall? I disagree with the latter; for the first days of a
programmer's basic training, the REPL is ample. No GUI needed, don't
even need input() at that stage. While I would generally teach input()
before any GUI toolkit, the opposite decision is also valid, but
definitely neither is needed right off the bat.

For someone's earliest forays into GUI programming, I would actually
*still* not word the challenge that way. I would keep everything in a
SINGLE window, because that showcases a major strength of a GUI - that
you can interact with it multiple times, rather than being forced into
a linear workflow. So here's my alternative challenge:

Take two numbers as inputs. Add them together and display them in a
third field. Whenever either input is changed, recalculate the output.

This requires proper event handling, so it's less likely to create a
useless one-liner that has no bearing on real-world code.

ChrisA
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Mike Barnett
Yea, software evolves.  Things get layered on top of other things.  It’s kind 
of how software works.


Perhaps the point is getting lost here on my request to comment on the overall 
construct and simplicity.  Let’s try a different approach…

How about a quick example that you code up in your favorite GUI?  Try and make 
it simple enough for a beginner to grasp as much as possible.

Here we go:
Take 3 numbers as input (A, B, C).  Add them together.  Display the result in a 
simple pop-up window.

That’s a pretty typical kind of problem for the first few weeks of beginning 
programming.  Maybe first few days.

Let’s say I want my program to look and work like other windows programs.  I 
want to show my friends, mom and dad that I can write software too.  In this 
example, I would expect that kind of reasoning that would drive a desire for a 
GUI.


@mike

From: Chris Barker 
Sent: Friday, August 24, 2018 1:39 PM
To: Paul Moore 
Cc: Mike Barnett ; Python-Ideas 

Subject: Re: [Python-ideas] A GUI for beginners and experts alike

A couple thoughts:

You're essentially writing a new API on top of tkINter, you could probably have 
multiple "back-ends" -- i.e. be able to use the same code with wxPython or 
PySide behind it.

In fact, there was an effort along these lines a few years back:

http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/

I don't know that it's seen much development lately.

Nope. I don't even have a need for a canvas. But what I have found in the past 
is that *anything* which is a "simple wrapper over X" always ends up in a 
situation where you need some feature from X that the simple wrapper doesn't 
cover, and you're left with the unpalatable choice of whether to omit 
functionality you want to provide, or rewrite your code to use X directly. So 
my question is more about "if you hit a need for something PySimpleGUI doesn't 
cover, what are your options?

This is key -- and one of the real issues around wrapping multiple GUI 
back-ends -- you end up having to do a lot of re-implementation of details.

In fact, I always thought Pyton_guiu above really suffered from that 
conceptually. For example, if you used pyton-gui with a wxPython back end, you 
had:

A python wrapper around a python wrapper around a C++ wrapper around each 
native toolkit.

That's a lot of layers!

So it's probably better to have a simpler stack -- and at the bottom, you 
probably need something with at least some C/C++ in it. And there are two 
options there:

1)  re-implement widgets with native basic drawing and event handling.
  - this is what QT GTK, and TK do
2) Wrap the native widgets
  - this is what wxWidgets does

The advantage of  (1) is that most of your code is the same on all platform, 
widgets behave the same on all platforms, and there is less code to write to 
support a new platform.

The advantage of (2) is that you get more native results -- the widgets ARE 
native. And it's easier to support the first platform -- you aren't writing a 
while GUI toolkit. But there is a lot more wrapper code to write for each new 
platform. And the results ARE going to be a bit platform-dependent in some 
places (though I've found that I need to write very little platform dependent 
code with wx)

TK is essentially (1), though AIUI, it was originally written for X-windows, 
and the other platform have an X-windows emulation layer, and then all the TK 
code works with that.

But the issue with TK is that it's really pretty old and krufty. It's great 
that it comes with the standard library, but now that yu can pip install pySide 
and wxPython, I'd consider working with one of those.

I'd also make sure that you CAN "drop down" into the lower level toolkit fairly 
smoothly, if you do need something more complex that the basics.

Finally -- I'm not sure the desktop is dead, but there is a heck of a lot going 
on in the browser. And if someone could write a simple GUI for a desktop app, 
and then easily prt that to a WebApp -- that would be great.

I'm sure there are toolkits that do maybe it possible to write pure-python, and 
have all the javascript pre-written (Or generated) for you. While its not a 
complete solution, Jupyter Widgets does this within the Jupyter framework, for 
instance.

-CHB












3. It doesn't seem to use native widgets (the buttons have a non-standard look 
on my Windows PC).
The defaults can be easily changed.  The default buttons are the one widget 
that I modify from the system default.  The reason was that the system default 
is a gray button.  It pretty much matches the background.

If you want your buttons to all look like the system default, slip this l

Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Chris Barker via Python-ideas
On Fri, Aug 24, 2018 at 10:07 AM, MRAB  wrote:

> A canvas can contain images, lines and shapes, which is useful for
> diagrams and drawings.


And the TK Canvas is kinda the "killer app" of TK.

-CHB

-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R(206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115   (206) 526-6317   main reception

chris.bar...@noaa.gov
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Chris Barker via Python-ideas
A couple thoughts:

You're essentially writing a new API on top of tkINter, you could probably
have multiple "back-ends" -- i.e. be able to use the same code with
wxPython or PySide behind it.

In fact, there was an effort along these lines a few years back:

http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/

I don't know that it's seen much development lately.

Nope. I don't even have a need for a canvas. But what I have found in the
> past is that *anything* which is a "simple wrapper over X" always ends up
> in a situation where you need some feature from X that the simple wrapper
> doesn't cover, and you're left with the unpalatable choice of whether to
> omit functionality you want to provide, or rewrite your code to use X
> directly. So my question is more about "if you hit a need for something
> PySimpleGUI doesn't cover, what are your options?
>

This is key -- and one of the real issues around wrapping multiple GUI
back-ends -- you end up having to do a lot of re-implementation of details.

In fact, I always thought Pyton_guiu above really suffered from that
conceptually. For example, if you used pyton-gui with a wxPython back end,
you had:

A python wrapper around a python wrapper around a C++ wrapper around each
native toolkit.

That's a lot of layers!

So it's probably better to have a simpler stack -- and at the bottom, you
probably need something with at least some C/C++ in it. And there are two
options there:

1)  re-implement widgets with native basic drawing and event handling.
  - this is what QT GTK, and TK do
2) Wrap the native widgets
  - this is what wxWidgets does

The advantage of  (1) is that most of your code is the same on all
platform, widgets behave the same on all platforms, and there is less code
to write to support a new platform.

The advantage of (2) is that you get more native results -- the widgets ARE
native. And it's easier to support the first platform -- you aren't writing
a while GUI toolkit. But there is a lot more wrapper code to write for each
new platform. And the results ARE going to be a bit platform-dependent in
some places (though I've found that I need to write very little platform
dependent code with wx)

TK is essentially (1), though AIUI, it was originally written for
X-windows, and the other platform have an X-windows emulation layer, and
then all the TK code works with that.

But the issue with TK is that it's really pretty old and krufty. It's great
that it comes with the standard library, but now that yu can pip install
pySide and wxPython, I'd consider working with one of those.

I'd also make sure that you CAN "drop down" into the lower level toolkit
fairly smoothly, if you do need something more complex that the basics.

Finally -- I'm not sure the desktop is dead, but there is a heck of a lot
going on in the browser. And if someone could write a simple GUI for a
desktop app, and then easily prt that to a WebApp -- that would be great.

I'm sure there are toolkits that do maybe it possible to write pure-python,
and have all the javascript pre-written (Or generated) for you. While its
not a complete solution, Jupyter Widgets does this within the Jupyter
framework, for instance.

-CHB












>
>
>> 3. It doesn't seem to use native widgets (the buttons have a non-standard
>> look on my Windows PC).
>> The defaults can be easily changed.  The default buttons are the one
>> widget that I modify from the system default.  The reason was that the
>> system default is a gray button.  It pretty much matches the background.
>>
>> If you want your buttons to all look like the system default, slip this
>> line of code at the top:
>>
>> sg.SetOptions(button_color=sg.COLOR_SYSTEM_DEFAULT)
>>
>
> OK. Personally, I'd argue quite strongly that "match the OS default" is
> the right default for a GUI library, but that's a hugely subjective area,
> and you're never going to please everyone. So do whatever works for you.
>
> Thank you again Paul... I learn something new from every reply 😊
>
>
> No problem - glad it helped.
>
> Paul
>
> ___
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
>


-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R(206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115   (206) 526-6317   main reception

chris.bar...@noaa.gov
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike (Mike Barnett)

2018-08-24 Thread Wes Turner
Accessibility is a very real advantage of Qt solutions.

http://doc.qt.io/qt-5/accessible.html

"""
[...]
applications usable for people with different abilities. It is important to
take different people's needs into account, for example, in case of low
vision, hearing, dexterity, or cognitive problems. Some examples of
accessibility measures are keyboard shortcuts, a high-contrast user
interface that uses specially selected colors and fonts, or support for
assistive tools such as screen readers and braille displays.

A basic checklist that any application should aim for:

- Usability - Usability and user centric design generally lead to more
usable applications, including improvements for people with various
abilities.
- Fonts - Font settings should follow the system/platform. This allows
users to select fonts for readability and increasing the font size.
- Colors - Provide enough contrast and consider the most common cases of
low vision and color blindness. Make sure that the application is usable,
for example, for people with red/green blindness, and don't depend on
colors only.
- Scalable UI - A user interface that works in various sizes and properly
supports different fonts and accommodates size changes.
- Sounds - Do not exclusively rely on sound notifications, provide a visual
alternative when a sound signal is imperative to using the application.
- Spelling - Offer spell checking wherever it makes sense, even when only a
single word is expected.
- Assistive Technology - Support the use of assistive tools (AT). Either
use standard widgets/controls which support ATs out of the box, or make
sure that your custom widgets and controls support accessibility properly.
"""

Does anyone have any experience with building accessible native GUI apps
with something other than Qt?


Most of this a11y (accessibility) information is focused on web apps (that
don't need an installer/updater to quickly respond to security issues):
https://github.com/brunopulis/awesome-a11y

On Friday, August 24, 2018, Chris Barker via Python-ideas <
python-ideas@python.org> wrote:

> On Fri, Aug 24, 2018 at 8:17 AM, Barry Scott 
> wrote:
>
>> > A graphical "hello world" in QT is only half a dozen or less lines of
>> > code in total, so
>> > meets the simplicity requirement.
>>
>> I think 2 lines is simple, 12 is not really simple, is it?
>>
>
> well, if all you need is a single dialog box with  one or two entry
> fields, then yes, 2-4 lines is better than 12-14 lines -- but a lot.
>
> But if you are building an actual application, I'm not sure that the extra
> ten lines of startup code matters at all. And if those ten lines are
> essentially boilerplate that you can copy and paste from somewhere (Or have
> a gui-builder write for you), then even less so.
>
> That's not to say that the GUI toolkit slike wxPython, PySide, pyGTK
> aren't a bit more complex than they need to be, but much of that complex is
> there to support complex needs.
>
> I do think there is a place for tools that make "the easy stuff easy", but
> make sure that the complex stuff is still possible.
>
> -CHB
>
> --
>
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R(206) 526-6959   voice
> 7600 Sand Point Way NE   (206) 526-6329   fax
> Seattle, WA  98115   (206) 526-6317   main reception
>
> chris.bar...@noaa.gov
>
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread MRAB

On 2018-08-24 16:27, Mike Barnett wrote:

Liking the comments Paul!


[snip]

It has the call information about the Text widget and all the others.  Is this 
what you mean by a Signature?

Text(Text,
 scale=(None, None),
 size=(None, None),
 auto_size_text=None,
 font=None,
 text_color=None,
 justification=None)
.

Text - The text that's displayed
size - Element's size
auto_size_text - Bool. Change width to match size of text
font - Font name and size to use
text_color - text color
justification - Justification for the text. String - 'left', 'right', 'center'

Static text is usually called a "label" in the GUIs I've used, including 
tkinter.


[snip]


2. Advanced features - how would I extend it if I have a need that it doesn't 
cover? For example, a canvas object or an image?
I have Images.
Don't have Canvas.  Any particular operations desired for the Canvas Element 
should I have one?

A canvas can contain images, lines and shapes, which is useful for 
diagrams and drawings.



3. It doesn't seem to use native widgets (the buttons have a non-standard look 
on my Windows PC).
The defaults can be easily changed.  The default buttons are the one widget 
that I modify from the system default.  The reason was that the system default 
is a gray button.  It pretty much matches the background.

If you want your buttons to all look like the system default, slip this line of 
code at the top:

sg.SetOptions(button_color=sg.COLOR_SYSTEM_DEFAULT)

Looking at the page on PyPI, those coloured buttons do look odd to me. I 
think the default should be the system default.


Also, I think those buttons labelled "Submit" should be labelled "OK".
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike (Mike Barnett)

2018-08-24 Thread Chris Barker via Python-ideas
On Fri, Aug 24, 2018 at 8:17 AM, Barry Scott  wrote:

> > A graphical "hello world" in QT is only half a dozen or less lines of
> > code in total, so
> > meets the simplicity requirement.
>
> I think 2 lines is simple, 12 is not really simple, is it?
>

well, if all you need is a single dialog box with  one or two entry fields,
then yes, 2-4 lines is better than 12-14 lines -- but a lot.

But if you are building an actual application, I'm not sure that the extra
ten lines of startup code matters at all. And if those ten lines are
essentially boilerplate that you can copy and paste from somewhere (Or have
a gui-builder write for you), then even less so.

That's not to say that the GUI toolkit slike wxPython, PySide, pyGTK aren't
a bit more complex than they need to be, but much of that complex is there
to support complex needs.

I do think there is a place for tools that make "the easy stuff easy", but
make sure that the complex stuff is still possible.

-CHB

-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R(206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115   (206) 526-6317   main reception

chris.bar...@noaa.gov
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Paul Moore
On Fri, 24 Aug 2018 at 16:27, Mike Barnett  wrote:

> 1. More documentation - reference docs specifically.  I don't see
> documentation of the call signature for sg.Text, for example.
>
> A little confused by this one.  There are quite a bit of documentation.
> Did you see the readme on the GitHub and here:
> https://pysimplegui.readthedocs.io/en/latest/


Yes, I saw that.

It has the call information about the Text widget and all the others.


If it does, I didn't spot it. I did say I was skimming - and there's
certainly a good amount of documentation. To some extent, I'm being picky
here because while I like examples, I have found projects in the past that
provide plenty of narrative and examples, but then when you start to want
to do something more complicated, the details and specifics are missing.


>   Is this what you mean by a Signature?
>
> Text(Text,
> scale=(None, None),
> size=(None, None),
> auto_size_text=None,
> font=None,
> text_color=None,
> justification=None)
> .
>
> Text - The text that's displayed
> size - Element's size
> auto_size_text - Bool. Change width to match size of text
> font - Font name and size to use
> text_color - text color
> justification - Justification for the text. String - 'left', 'right',
> 'center'
>

Yes, precisely. Apologies that I missed it.

I don't have all of the newest features in there, like the Update method
> because the doc is for version 2.9 on PyPI.  I don't yet have the latest
> GitHub release in there just yet.  You'll find that information instead on
> the Wiki:
> https://github.com/MikeTheWatchGuy/PySimpleGUI/wiki/PySimpleGUI-Wiki
>
>
> 2. Advanced features - how would I extend it if I have a need that it
> doesn't cover? For example, a canvas object or an image?
> I have Images.
> Don't have Canvas.  Any particular operations desired for the Canvas
> Element should I have one?
>

Nope. I don't even have a need for a canvas. But what I have found in the
past is that *anything* which is a "simple wrapper over X" always ends up
in a situation where you need some feature from X that the simple wrapper
doesn't cover, and you're left with the unpalatable choice of whether to
omit functionality you want to provide, or rewrite your code to use X
directly. So my question is more about "if you hit a need for something
PySimpleGUI doesn't cover, what are your options?


> 3. It doesn't seem to use native widgets (the buttons have a non-standard
> look on my Windows PC).
> The defaults can be easily changed.  The default buttons are the one
> widget that I modify from the system default.  The reason was that the
> system default is a gray button.  It pretty much matches the background.
>
> If you want your buttons to all look like the system default, slip this
> line of code at the top:
>
> sg.SetOptions(button_color=sg.COLOR_SYSTEM_DEFAULT)
>

OK. Personally, I'd argue quite strongly that "match the OS default" is the
right default for a GUI library, but that's a hugely subjective area, and
you're never going to please everyone. So do whatever works for you.

Thank you again Paul... I learn something new from every reply 😊


No problem - glad it helped.

Paul
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Andre Roberge
On Fri, Aug 24, 2018 at 12:42 PM Barry Scott  wrote:

>
>
> On 23 Aug 2018, at 19:49, Mike Barnett  wrote:
>
> Python has dropped the GUI ball, at least for beginners (in my opinion)
>
>
> snip


>
> I think that this is a very interesting project. Having a simple way to do
> GUI's is great for beginners and experienced people.
>
> What I'd suggest is that this would be better if you could extent beyond
> the simple using the underlying toolkit.
> But I'd not use tk as the base I'd use PyQt, IMHO, its the best toolkit
> for building GUIs with python.
>

While I agree that PyQt is better than tkinter, and I even wrote a simple
interface for it (https://github.com/aroberge/easygui_qt), I think that any
"single install, easy to use" GUI toolkit should be based on what's in the
standard library and, for better or for worse, that is tkinter. So I think
that the right choice was made for PySimpleGUI.

André

>
> I'd love to start with the simple and build on top the complex stuff only
> when I need it.
>
> Barry
>
>
>
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike (Mike Barnett)

2018-08-24 Thread Barry Scott



> On 23 Aug 2018, at 23:14, Hugh Fisher  wrote:
> 
>> Date: Thu, 23 Aug 2018 18:49:48 +
>> From: Mike Barnett 
>> 
>> Python has dropped the GUI ball, at least for beginners (in my opinion)
>> 
>> While the Python language is awesomely compact, the GUI code is far from 
>> compact.  Tkinter will create a nice looking GUI, but you've got to be 
>> skilled to use it.  A student in their first week of Python programming is 
>> not going to be working with tkinter.
>> 
>> It would be nice if beginners could double click a .py file and have it 
>> launch straight into a GUI, like most of the programs people are used to 
>> using.
>> 
>> I think I've stumbled onto a framework that could work very well for 
>> creating fairly complex custom-layout GUIs...
> 
> Have you looked at PySide2? It's the latest Python wrapper for the QT
> cross platform
> GUI framework.

Or indeed PyQt5 that works great as a Qt python interface.
Last time I looked PySide2 had a lot of catching up to do to match
PyQt's API coverage.

> A graphical "hello world" in QT is only half a dozen or less lines of
> code in total, so
> meets the simplicity requirement.

I think 2 lines is simple, 12 is not really simple, is it?

> The big drawback of QT  for Python
> until now has
> been building the thing, but now it's on PyPI so "pip install"
> (should) Just Work.

You may have needed to build pySide2 yourself, however
PyQt4 and PyQt5 have been pip installable for a long time.

pip install PyQt5

Barry

___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Barry Scott


> On 23 Aug 2018, at 19:49, Mike Barnett  wrote:
> 
> Python has dropped the GUI ball, at least for beginners (in my opinion)
>  
> While the Python language is awesomely compact, the GUI code is far from 
> compact.  Tkinter will create a nice looking GUI, but you’ve got to be 
> skilled to use it.  A student in their first week of Python programming is 
> not going to be working with tkinter.  
>  
> It would be nice if beginners could double click a .py file and have it 
> launch straight into a GUI, like most of the programs people are used to 
> using.
>  
> I think I’ve stumbled onto a framework that could work very well for creating 
> fairly complex custom-layout GUIs.
>  
> A package was released recently that uses this framework. It’s 
> calledPySimpleGUI .  It is a 
> wrapper for tkinter so that it’ll run on almost any system Python will run 
> on.  There are no other dependencies and it’s a single file so that it can be 
> easily dropped into someone’s project folder for immediate use without 
> messing with pip installs.
>  
> You can read more:
> PySimpleGUI Tutorial 
> PySimpleGUI Cookbook 
> PySimpleGUI Reverence Document 
> A bunch of screenshots 
> 
>  
> I am not seeking fame, recognition, or any other personal gain.  I could care 
> less if my name is associated with this design.  My goal is to get Python off 
> the command line and onto the screen.
>  
> I am, however, making a serious in my attempt to get serious Python community 
> members to weigh in on the best approach for getting acceptance.
>  
> A sizeable user-base is likely a requirement.  Interest has been brisk over 
> the past few weeks with the basic GitHub 
>  stats having made great 
> strides toward the EasyGUI  values.  
> It’s not a competition, but rather a benchmark to check progress.
>  
> Comments, suggestions, pointers in new directions are all welcomed.

I think that this is a very interesting project. Having a simple way to do 
GUI's is great for beginners and experienced people.

What I'd suggest is that this would be better if you could extent beyond the 
simple using the underlying toolkit.
But I'd not use tk as the base I'd use PyQt, IMHO, its the best toolkit for 
building GUIs with python.

I'd love to start with the simple and build on top the complex stuff only when 
I need it.

Barry



>  
> Thank you very much for your time.  I have not been a part of this mailing 
> list in the past, so I hope I’m using it within the guidelines.  Someone 
> pointed me in this direction to get feedback and into the process.
>  
> @mike 
>  
> ___
> Python-ideas mailing list
> Python-ideas@python.org 
> https://mail.python.org/mailman/listinfo/python-ideas 
> 
> Code of Conduct: http://python.org/psf/codeofconduct/ 
> 

___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Mike Barnett
Liking the comments Paul!

Backing up to the beginning, I know I'm far far far away from attempting to 
become a part of stdlib.  However, that does not mean I can't set that as the 
target and begin to understand the path to get there.  My initial post was an 
attempt to understand this path.  I've been getting lots of good information on 
how to get there, what happens where you do get there, etc.  

I like it!!  Thank you for taking the time to both try it and write your 
thoughts.

Answering a couple of specific questions / remarks:
1. More documentation - reference docs specifically.  I don't see documentation 
of the call signature for sg.Text, for example.

A little confused by this one.  There are quite a bit of documentation.  Did 
you see the readme on the GitHub and here:
https://pysimplegui.readthedocs.io/en/latest/
It has the call information about the Text widget and all the others.  Is this 
what you mean by a Signature?

Text(Text,
scale=(None, None),
size=(None, None),
auto_size_text=None,
font=None,
text_color=None,
justification=None)
.

Text - The text that's displayed
size - Element's size
auto_size_text - Bool. Change width to match size of text
font - Font name and size to use
text_color - text color
justification - Justification for the text. String - 'left', 'right', 'center'


I don't have all of the newest features in there, like the Update method 
because the doc is for version 2.9 on PyPI.  I don't yet have the latest GitHub 
release in there just yet.  You'll find that information instead on the Wiki:
https://github.com/MikeTheWatchGuy/PySimpleGUI/wiki/PySimpleGUI-Wiki


2. Advanced features - how would I extend it if I have a need that it doesn't 
cover? For example, a canvas object or an image?
I have Images.  
Don't have Canvas.  Any particular operations desired for the Canvas Element 
should I have one?

3. It doesn't seem to use native widgets (the buttons have a non-standard look 
on my Windows PC).
The defaults can be easily changed.  The default buttons are the one widget 
that I modify from the system default.  The reason was that the system default 
is a gray button.  It pretty much matches the background.

If you want your buttons to all look like the system default, slip this line of 
code at the top:

sg.SetOptions(button_color=sg.COLOR_SYSTEM_DEFAULT)


Thank you again Paul... I learn something new from every reply 😊

@mike

-Original Message-
From: Paul Moore  
Sent: Friday, August 24, 2018 11:13 AM
To: mike_barn...@hotmail.com
Cc: Wes Turner ; Jonathan Fine ; 
Python-Ideas 
Subject: Re: [Python-ideas] A GUI for beginners and experts alike

On Fri, 24 Aug 2018 at 15:53, Mike Barnett  wrote:
> Can a few of you with the vast amount of GUI experience you have, spend 5 
> minutes and run one of the examples?

I don't have a "vast" amount of GUI experience. But nevertheless I gave it a 
go. It took less than 5 minutes (which is good).

> This will get you started:
>
> pip install PySimpleGUI

Worked.

> Then copy and paste a Recipe from the Cookbook.
>
> https://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpysi
> mplegui.readthedocs.io%2Fen%2Flatest%2Fcookbook%2F&data=02%7C01%7C
> %7C854fc59de69e4b1c93bc08d609d41047%7C84df9e7fe9f640afb435
> %7C1%7C0%7C636707203735494935&sdata=2Pc7s%2BsqtF0vOfi55TG0cJRrNb3O
> 7ENRfuFxTjqN1K0%3D&reserved=0

I went for the simple GUI form. It worked pretty much as expected. The code 
looks quite nice.

> For someone with a dev environment running, it’s a 2 minute exercise.  
> It will make for more focused comments. I’m asking that it actually be 
> tried

Agreed, it was simple to use, and pick up a canned example.

> because I don’t think anything like it has been proposed as a GUI framework.

I don't know if that's true, there's a lot of GUI frameworks and I certainly 
can't say I've tried all of them. This looks nice for simple usages, and would 
certainly be useful as a project on PyPI (like it is at the moment). I doubt 
it's mature enough for the stdlib, and I'm certain it's not stable enough (yet) 
for the stdlib - you'll want to make changes, add features, etc, and once it's 
in the stdlib that's going to be a lot harder. What's the rush?

As far as things I think I'd like to see (and these are just off the top of my 
head, I've done nothing more than I said above):

1. More documentation - reference docs specifically. I don't see documentation 
of the call signature for sg.Text, for example.
2. Advanced features - how would I extend it if I have a need that it doesn't 
cover? For example, a canvas object or an image?
3. It doesn't seem to use native widgets (the buttons have a non-standard look 
on my Windows PC).

Don't feel like you need to do anything about these comments - I rarely if ever 
use a GUI library, and I've no idea if I'd use this one in future, but if you 
want "focused comments" beyond "it looks neat and seems like a fine project to 
go onto PyPI, but I 

Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Paul Moore
On Fri, 24 Aug 2018 at 15:53, Mike Barnett  wrote:
> Can a few of you with the vast amount of GUI experience you have, spend 5 
> minutes and run one of the examples?

I don't have a "vast" amount of GUI experience. But nevertheless I
gave it a go. It took less than 5 minutes (which is good).

> This will get you started:
>
> pip install PySimpleGUI

Worked.

> Then copy and paste a Recipe from the Cookbook.
>
> https://pysimplegui.readthedocs.io/en/latest/cookbook/

I went for the simple GUI form. It worked pretty much as expected. The
code looks quite nice.

> For someone with a dev environment running, it’s a 2 minute exercise.  It 
> will make for more focused comments. I’m asking that it actually be tried

Agreed, it was simple to use, and pick up a canned example.

> because I don’t think anything like it has been proposed as a GUI framework.

I don't know if that's true, there's a lot of GUI frameworks and I
certainly can't say I've tried all of them. This looks nice for simple
usages, and would certainly be useful as a project on PyPI (like it is
at the moment). I doubt it's mature enough for the stdlib, and I'm
certain it's not stable enough (yet) for the stdlib - you'll want to
make changes, add features, etc, and once it's in the stdlib that's
going to be a lot harder. What's the rush?

As far as things I think I'd like to see (and these are just off the
top of my head, I've done nothing more than I said above):

1. More documentation - reference docs specifically. I don't see
documentation of the call signature for sg.Text, for example.
2. Advanced features - how would I extend it if I have a need that it
doesn't cover? For example, a canvas object or an image?
3. It doesn't seem to use native widgets (the buttons have a
non-standard look on my Windows PC).

Don't feel like you need to do anything about these comments - I
rarely if ever use a GUI library, and I've no idea if I'd use this one
in future, but if you want "focused comments" beyond "it looks neat
and seems like a fine project to go onto PyPI, but I don't think it's
necessarily something that should go in the stdlib", then those were
what I thought of off the cuff.

Hope this is useful,
Paul
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Wes Turner
On Friday, August 24, 2018, Terry Reedy  wrote:

> On 8/24/2018 4:12 AM, Wes Turner wrote:
>
> There was a thread about deprecating Tk awhile back.
>>
>
> That was an intentionally annoying troll post, not a serious proposal.
> Please don't refer to it as if it were.


stdlib inclusion entails years of support commitment, backwards
incompatibility, waiting for a Python release to occur, and withstanding
phd-level challenges.


>
> asyncio event loop support would be great for real world apps.
>>
>
> This is unclear.  Any app that wants to use asyncio can import it.


> Easily using async and await *without* using asyncio is a different matter.


asyncio support is only so useful when the GUI widget toolkit blocks
(doesn't use async or await


>
> --
> Terry Jan Reedy
>
> ___
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Mike Barnett
I saw this list prior to writing PySimpleGUI.  My goal is for this architecture 
to be on that list down the road.  Don’t care if it’s this package, only that 
something similar exist and is known in the community.

There is a gaping hole between command line and a simple GUI on the screen.  
It’s a huge chasm.

Here’s a fun Python-like way of using the package.   You can collapse a custom 
form down to a single line of (readable) code.

button, (filename,) = sg.FlexForm('Get filename example'). 
LayoutAndRead([[sg.Text('Filename')], [sg.Input(), sg.FileBrowse()], [sg.OK(), 
sg.Cancel()] ])

Or maybe break it up:

button, (filename,) = sg.FlexForm('Get filename example').LayoutAndRead(

[[sg.Text('Filename')],
 [sg.Input(), 
sg.FileBrowse()],
 [sg.OK(), 
sg.Cancel()]])


Can a few of you with the vast amount of GUI experience you have, spend 5 
minutes and run one of the examples?
This will get you started:

pip install PySimpleGUI


Then copy and paste a Recipe from the Cookbook.
https://pysimplegui.readthedocs.io/en/latest/cookbook/

For someone with a dev environment running, it’s a 2 minute exercise.  It will 
make for more focused comments. I’m asking that it actually be tried because I 
don’t think anything like it has been proposed as a GUI framework.




@mike

From: Wes Turner 
Sent: Friday, August 24, 2018 4:17 AM
To: Jonathan Fine 
Cc: Mike Barnett ; python-ideas@python.org
Subject: Re: [Python-ideas] A GUI for beginners and experts alike

https://docs.python-guide.org/scenarios/gui/
 lists a bunch of great GUI projects for Python.

https://github.com/realpython/python-guide/blob/master/docs/scenarios/gui.rst


___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Terry Reedy

On 8/24/2018 4:12 AM, Wes Turner wrote:


There was a thread about deprecating Tk awhile back.


That was an intentionally annoying troll post, not a serious proposal. 
Please don't refer to it as if it were.



asyncio event loop support would be great for real world apps.


This is unclear.  Any app that wants to use asyncio can import it.

Easily using async and await *without* using asyncio is a different matter.

--
Terry Jan Reedy

___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Wes Turner
https://docs.python-guide.org/scenarios/gui/ lists a bunch of great GUI
projects for Python.

https://github.com/realpython/python-guide/blob/master/docs/scenarios/gui.rst

On Friday, August 24, 2018, Wes Turner  wrote:

>
>
> On Thursday, August 23, 2018, Jonathan Fine  wrote:
>
>> Hi Mike
>>
>> Thank you for your prompt response. You wrote
>>
>> > Maybe we're on different planes?
>> >
>> > I'm talking about 5 lines of Python code to get a custom layout GUI on
>> the screen:
>> >
>> > import PySimpleGUI as sg
>> >
>> > form = sg.FlexForm('Simple data entry form')  # begin with a blank form
>> >
>> > layout = [
>> >   [sg.Text('Please enter your Name, Address, Phone')],
>> >   [sg.Text('Name', size=(15, 1)), sg.InputText('1',
>> key='name')],
>> >   [sg.Text('Address', size=(15, 1)), sg.InputText('2',
>> key='address')],
>> >   [sg.Text('Phone', size=(15, 1)), sg.InputText('3',
>> key='phone')],
>> >   [sg.Submit(), sg.Cancel()]
>> >  ]
>> >
>> > button, values = form.LayoutAndRead(layout)
>>
>> The execution of this code, depends on PySimpleGUI, which in turn depends
>> on tkinter, which is in turn a thin layer on top of Tcl/Tk. And Tcl/Tk
>> provides the GUI layer.
>> (See https://docs.python.org/3/library/tk.html.)
>>
>> I'm suggest that sometimes it may be better to use HTML5 to provide the
>> GUI layer. I pointed to Elm, to show how powerful HTML5 has become.
>>
>
> BeeWare uses Toga (a widget toolkit) and Briefcase (a build tool) to build
> native GUIs and SPA web apps
>
> > Write your apps in Python and release them on iOS, Android, Windows,
> MacOS, Linux, Web, and tvOS using rich, native user interfaces. One
> codebase. Multiple apps.
>
> Briefcase can build Django apps.
>
> https://pybee.org
> https://pybee.org/project/using/
> https://briefcase.readthedocs.io/en/latest/tutorial/tutorial-0.html
> https://toga.readthedocs.io/en/latest/tutorial/tutorial-0.html
>
> It's definitely not a single file module, though.
>
> Bottle is a single file web framework ('microframework'); but it doesn't
> have a widget toolkit.
>
> Web development is not as easy to learn as a simple GUI api for beginners
> (and then learning what to avoid in terms of websec is a lot to learn).
>
> There was a thread about deprecating Tk awhile back. There also I think I
> mentioned that asyncio event loop support would be great for real world
> apps.
>
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Wes Turner
On Thursday, August 23, 2018, Jonathan Fine  wrote:

> Hi Mike
>
> Thank you for your prompt response. You wrote
>
> > Maybe we're on different planes?
> >
> > I'm talking about 5 lines of Python code to get a custom layout GUI on
> the screen:
> >
> > import PySimpleGUI as sg
> >
> > form = sg.FlexForm('Simple data entry form')  # begin with a blank form
> >
> > layout = [
> >   [sg.Text('Please enter your Name, Address, Phone')],
> >   [sg.Text('Name', size=(15, 1)), sg.InputText('1', key='name')],
> >   [sg.Text('Address', size=(15, 1)), sg.InputText('2',
> key='address')],
> >   [sg.Text('Phone', size=(15, 1)), sg.InputText('3',
> key='phone')],
> >   [sg.Submit(), sg.Cancel()]
> >  ]
> >
> > button, values = form.LayoutAndRead(layout)
>
> The execution of this code, depends on PySimpleGUI, which in turn depends
> on tkinter, which is in turn a thin layer on top of Tcl/Tk. And Tcl/Tk
> provides the GUI layer.
> (See https://docs.python.org/3/library/tk.html.)
>
> I'm suggest that sometimes it may be better to use HTML5 to provide the
> GUI layer. I pointed to Elm, to show how powerful HTML5 has become.
>

BeeWare uses Toga (a widget toolkit) and Briefcase (a build tool) to build
native GUIs and SPA web apps

> Write your apps in Python and release them on iOS, Android, Windows,
MacOS, Linux, Web, and tvOS using rich, native user interfaces. One
codebase. Multiple apps.

Briefcase can build Django apps.

https://pybee.org
https://pybee.org/project/using/
https://briefcase.readthedocs.io/en/latest/tutorial/tutorial-0.html
https://toga.readthedocs.io/en/latest/tutorial/tutorial-0.html

It's definitely not a single file module, though.

Bottle is a single file web framework ('microframework'); but it doesn't
have a widget toolkit.

Web development is not as easy to learn as a simple GUI api for beginners
(and then learning what to avoid in terms of websec is a lot to learn).

There was a thread about deprecating Tk awhile back. There also I think I
mentioned that asyncio event loop support would be great for real world
apps.
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] Does jargon make learning more difficult?

2018-08-24 Thread Greg Ewing

Stephen J. Turnbull wrote:

Abe Dillon writes:

 > That's interesting. So the parser can see one token past, for instance;
 > what would be the end of an expression, see "if", and know to expand the
 > AST?

Yes, if you want to think about it that way.


For understanding what kinds of things an LL parser can parse,
it helps to have gone through the exercise of implementing a
recursive descent parser.

The classic way to do that is to write a function for each
production in the grammar. E.g. if you have a production

   expr ::= term ['+' expr]

then you would write a function structured like this:

   def parse_expr():
  parse_term()
  if current_token == '+':
 next_token()
 parse_expr()

What other stuff you do in it depends on what you want the
parser to accomplish. If you want it to build a parse tree,
you could do something like this:

   def parse_expr():
  result = parse_term()
  if current_token == '+':
 next_token()
 operand2 = parse_expr()
 result = BinopNode(result, operand2)
  return result


I don't think of
it in terms of the parser knowing "where" it is in the program, but
rather in terms of whether it can do more work on the AST with the
token (or EOF) in hand.


Not so much where it is in the program, but where it is in
the *grammar*. For example, if parse_term() gets called,
it knows it must be looking at the beginning of a term. If
the current token is not one of the ones that can begin a
term, then there is a syntax error.

The fact that a recursive descent parser always knows where
it is in the grammar is useful, because it can be used to
produce helpful error messages. For example, if it gets
stuck in parse_term() it can say something like "I was
expecting a term here, but this token doesn't look like
the beginning of a term."

Unfortunately, Python's parser doesn't seem to make much
use of this. :-(


If you think of expressions having their own subparser, the model is a
little more subtle.  I think of the subparsers as being coroutines


That's kind of the way an LR parser works. An LR parser is
more powerful than an LL parser, because it can effectively
explore several possible parsings in parallel until one
of them succeeds. But I don't think Python uses an LR
parser, because its grammar is required to be LL(1).

If you're interested in this stuff, I recommend either taking
a computer science course or reading a good book about the
theory of parsing. It will bring a lot of these concepts
into sharp focus.

--
Greg
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/