PySimpleGUI spells: "Good riddance gtkdialog"

Locked
User avatar
wiak
Posts: 3627
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 56 times
Been thanked: 994 times
Contact:

PySimpleGUI spells: "Good riddance gtkdialog"

Post by wiak »

Despite writing many a program (such as Precord) using gtkdialog (with bash), I have been advocating/searching for some other better way to write small utility/apps and yad, for example, is often too limiting. So I wrote some threads about using iup with Lua elsewhere, and that is actually pretty excellent, except the script has to be in Lua or in C language, neither of which probably appeal to most here.

Bash is well known here, but honesty, it is pretty awful as an application program language (ok so we have all become used to it and love it - but it is awful actually outside of its intended usage domain - system admin shell-scripting...).

For user-friendly GUI utility apps what would be really good would be to use Python, since most all distros come with Python installed out-of-the-box, or should. Anyway, all the distros I use do have Python installed since I rely on cherrytree notepad, which is written in Python (ver 3.xx nowadays). But what GUI framework to use???

PySimpleGUI

Python GUI For Humans - Transforms tkinter, Qt, Remi, WxPython into portable people-friendly Pythonic interfaces

Actually, it has been around for a few years now and remains actively developed with many contributors so no need to struggle with pretty much unsupported gtkdialog...

Okay so at last here is a really simply GUI framework that as far as I can see is really simply to code with and is actually multi-GUI-framework capable, the typical tkinter, but also PyQt5 (subset) and others can be used with it. Wow... Okay so you need to learn the basics of Python - but plenty of simple basic Python tutorials out there to get started. Indeed my 9 year old kid is learning Python the past few days (comes from 'Scratch' programming background) and has already mastered most basic syntax including loops and selections and functions - enough to get on with the following:

https://pysimplegui.readthedocs.io/en/l ... ers-manual

https://pysimplegui.readthedocs.io/en/l ... g-the-gist

Wow, isn't that simple!!! So let's move on from old gtkdialog, it has had its day - For a start I may even recode old Precord via PySimpleGUI now... and cross-platform of course (since Python...).

https://pysimplegui.readthedocs.io/en/latest/cookbook/

For WDL_Arch64 you can find PySimpleGUI in the AUR:PySimpleGUI is different than most projects on GitHub. It is licensed using the "Open Source License" LGPL3. However, the coding and development of the project is not "open source".

https://aur.archlinux.org/packages/python-pysimplegui/

And for the Raspberry Pi enthusiasts:

Because PySimpleGUI is compatible back to Python 3.4, it is capable of creating a GUI for your Raspberry Pi projects. It works particularly well when paired with a touchscreen. You can also use PySimpleGUIWeb to control your Pi if it doesn't have a monitor attached.

Furthermore, it is perfect for the sort of things Puppy crowd use gtkdialog for - frontend GUI for commandline programs:

The "GUI Gap" mentioned earlier can be easily solved using PySimpleGUI. You don't even need to have the source code to the program you wish to add a GUI onto. A "front-end" GUI is one that collects information that is then passed to a command-line application.

Front-end GUIs are a fantastic way for a programmer to distribute an application that users were reluctant to use previously because they didn't feel comfortable using a command-line interface. These GUIs are your only choice for command-line programs that you don't have access to the source code for.

This example is a front-end for a program called "Jump Cutter". The parameters are collected via the GUI, a command-line is constructed using those parameters, and then the command is executed with the output from the command-line program being routed to the GUI interface. In this example, you can see in yellow the command that was executed.

Looking forward to the Brave New World where we guys stop wasting our hundreds of hours on bash/gtkdialog/yad... And its but a small step to move on even from PySimpleGUI into more sophisticated PyQt5, WXpython or Tkinter programming later... in fact I think you can create and use functions written that way via PySimpleGUI but I have only just started looking at it so not sure about that yet.

NOTE: Also came across an online programming environment called "Trinket" that I believe you can practice with:
https://pysimplegui.trinket.io/demo-pro ... ui-program
But I found Trinket 'run' a bit slow (and result GUI tiny even if you use Trinket Menu to increase its fonts - alas doesn't effect GUI size...). So best just install PySimpleGUI along with Python and so on on your local system I feel.

LICENSE NOTE:

PySimpleGUI is different than most projects on GitHub. It is licensed using the "Open Source License" LGPL3. However, the coding and development of the project is not "open source".

Well, that's a pity really. But seems to be "open source" really anyway, so I don't quite understand the license qualification as yet: https://github.com/PySimpleGUI/PySimpleGUI On further checking, I think the author just means he does not accept pull requests to his own developments (which is fine) - the code is however open source and you can make forks of it from Github if you wish.

Attachments
PySimpleGUI.png
PySimpleGUI.png (188.89 KiB) Viewed 1821 times
FrontEndToCMDlineUtility.png
FrontEndToCMDlineUtility.png (98.74 KiB) Viewed 1821 times

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

User avatar
wiak
Posts: 3627
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 56 times
Been thanked: 994 times
Contact:

Re: PySimpleGUI spells: "Good riddance gtkdialog"

Post by wiak »

Well, PySimpleGUI is pretty simple (and probably a bit limited - but nice nevertheless).

But maybe you'll find this one better:

https://kivy.org/#home

Looks like a really easy way to lay things out. However, Kivy is basically drawing using OpenGL whereas PySimpleGUI is using GUI Frameworks such as PyQt, Tkinter, Wxwidgets and so on (so PySimpleGUI a bit more like using gtkdialog):

https://kivy.org/doc/stable/gettingstarted/rules.html

https://kivy.org/#gallery

Main thing is: Use Python - it's probably on your system!!!

Install python-kivy on WDL_Arch64:

Code: Select all

pacman -Sy python-kivy

Hello world first example as an executable script (remember to chmod +x):

Code: Select all

#!/usr/bin/env python

import kivy
kivy.require('1.0.6') # replace with your current kivy version !

from kivy.app import App
from kivy.uix.label import Label


class MyApp(App):

    def build(self):
        return Label(text='Hello world')


if __name__ == '__main__':
    MyApp().run()

You can add buttons in there, and so on, too. Or a drawing canvas and make a 'very' simple paint program (screenshot I made after using it is attached):

Code: Select all

#!/usr/bin/env python

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.graphics import Color, Ellipse


class MyPaintWidget(Widget):

    def on_touch_down(self, touch):
        with self.canvas:
            Color(1, 1, 0)
            d = 30.
            Ellipse(pos=(touch.x - d / 2, touch.y - d / 2), size=(d, d))


class MyPaintApp(App):

    def build(self):
        return MyPaintWidget()


if __name__ == '__main__':
    MyPaintApp().run()

Above just paints dots. Better version that includes 'Lines' can be found at bottom of this linked page (and one version showing use of a "Clear drawing" Button widget):

https://kivy.org/doc/stable/tutorials/firstwidget.html

However, though kivy is substantially more powerful, for just simple GUI frontends for commandline programs, PySimpleGUI is much much simpler and I'd still recommend you practice with that one first.

wiak

Attachments
paint_py.png
paint_py.png (31.55 KiB) Viewed 1761 times

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

User avatar
BarryK
Posts: 2273
Joined: Tue Dec 24, 2019 1:04 pm
Has thanked: 93 times
Been thanked: 564 times

Re: PySimpleGUI spells: "Good riddance gtkdialog"

Post by BarryK »

Thanks for reporting about Kivy, very interesting.

I have just briefly looked at kivy.org, it looks like you can create an app that will run on any OS, including phones.

Clarity
Posts: 3273
Joined: Fri Jul 24, 2020 10:59 pm
Has thanked: 1349 times
Been thanked: 438 times

Re: PySimpleGUI spells: "Good riddance gtkdialog"

Post by Clarity »

Saw this in a review

PySimpleGUI is a dream." "I have been writing Python programs for about 4 or 5 months now. Up until this week I never had luck with any UI libraries like Tkinter, Qt, Kivy. I went from not even being able to load a window in Tkinter reliably to making a loading screen, and full program in one night with PySimpleGUI."

FYI

User avatar
wiak
Posts: 3627
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 56 times
Been thanked: 994 times
Contact:

Re: PySimpleGUI spells: "Good riddance gtkdialog"

Post by wiak »

Yes, PySimpleGUI is really easy to use (yet surprisingly powerful compared to the likes of gtkdialog and actually much tidier/easier more flexible, it turns out, to make GUI layouts). Like I said, my nine year old son has been learning a few simple basics of plain Python so today I introduced him to PySimpleGUI and (having spent long time with Scratch programming) he is finding it very easy, and wrote his own very simply 'calculator' program using PySimpleGUI (no keypad, but uses GUI text input for the numbers and arithmetic operator and multiline output boxes for the result). I had simply shown him a basic demo of using text input box and a Button and then pointed him to the Widget reference page (available widget descriptions/details are in left menu bar of below page):

https://pysimplegui.readthedocs.io/en/l ... reference/

I also mentioned having found a page full of demos on github, such as (slightly modified by me...):

https://github.com/PySimpleGUI/PySimple ... _Stdout.py

Code: Select all

#!/usr/bin/env python
import PySimpleGUI as sg
"""
    Demo program that reroutes stdout.
    Type something in the input box and click Print
    Whatever you typed is "printed" using a standard print statement
    Use the Multiline Element in your window layout to reroute stdout
    You will see the output of the print in the Multiline Element in the center of the window
"""
layout = [
    [sg.Text('Type something in input field and click print')],
    [sg.Input()],
    [sg.Multiline(reroute_stdout = True)],
    [sg.Button('Print'), sg.Button('Exit')]NOTE: I wouldn't bother learning Python 2.x since Python 3.x dominates now. I haven't checked as yet, which, if any, of above links are Python 3 correct. Sometimes there are syntax differences.
]
# Demo example actually used [sg.Output()], instead of more flexible [sg.Multiline(reroute_stdout = True)],
# Refer to: https://pysimplegui.readthedocs.io/en/latest/call%20reference/
window = sg.Window('Reroute stdout', layout)
while True:     # Event Loop
    event, values = window.read()
    print('You typed: ', values[0])
    if event == sg.WIN_CLOSED or event == 'Exit': # if user closes window or clicks Exit
        break
window.close()

the above simple Demo_Stdout.py linked example showed him how to use an Output box (Element) for stdout instead of just using terminal for outputs. In practice, modified the online demo to instead use element "Multiline(reroute_stdout = True)" since that gives more scope than Output() (lots of parameters he can adjust, such as background and foreground colour and widget size and so on). Note that argument "reroute_stdout = True" makes print statement output go to the Multiline Element (Widget) rather than NOTE: I wouldn't bother learning Python 2.x since Python 3.x dominates now. I haven't checked as yet, which, if any, of above links are Python 3 correct. Sometimes there are syntax differences.to a program start up terminal. In practice we now just click on filename.py in Filemanager to run it like any other executable program.

If you are a gtkdialog expert you might find the following PySimpleGUI example a good way to get up to speed quick: https://github.com/PySimpleGUI/PySimple ... lements.py

My son tells me that the method of laying out the GUI elements in PySimpleGUI uses Python 'lists', which I understand as being like arrays. I am presuming you can use lists inside lists for infinitely complex box-like layouts - way simpler than the horrible, easy to mess up, pseudo-xml tags used in gtkdialog.

I'm just leaving him to it now - he already knows far more than me about using PySimpleGUI (and Python). I note PySimpleGUI also contains a "Canvas" element so he can do drawings or make games with the help of that.

Once he has mastered PySimpleGUI (and Python itself) more thoroughly I'll introduce him to alternative, more complex Python GUI framework kivy (though PySimpleGUI pretty good anyway). He only knows very basic shell commandline stuff, so I won't be bothering introducing him to gtkdialog at all. I'd rather he mastered something like Python rather than much bash at this stage - he uses WDL_Arch64 as his desktop distro, and does a fair amount at the commandline so expertise in using bash will pretty much come natNOTE: I wouldn't bother learning Python 2.x since Python 3.x dominates now. I haven't checked as yet, which, if any, of above links are Python 3 correct. Sometimes there are syntax differences.NOTE: I wouldn't bother learning Python 2.x since Python 3.x dominates now. I haven't checked as yet, which, if any, of above links are Python 3 correct. Sometimes there are syntax differences.urally over time.. kids absorb everything at speeds that makes me feel dumb.

For those of us, who also want to use shell commands, the following may be of interest:

https://linuxhandbook.com/execute-shell-command-python/

However, a lot of the time, the way we do things in bash is better done using pure Python. For example, if you are used to using sed, yes, you could execute sed from python, but recommended would be to use Python itself to do what you typically use sed (or awk) for. Which is what is said here:

https://askubuntu.com/questions/747450/ ... hon-scriptNOTE: I wouldn't bother learning Python 2.x since Python 3.x dominates now. I haven't checked as yet, which, if any, of above links are Python 3 correct. Sometimes there are syntax differences.

More to learn, I know, but makes sense to use the power of the language you are coding in rather than resort to external call tricks. Python way more powerful than bash/sed/awk for string handling - in fact, what can you not do in Python (once you know Python...). But of course, you can mix the two - at least that is a start.

As a part-time programmer, here are a few links that will no doubt prove useful to myself later when it comes to programming in Python the kinds of simple utility apps I'm used to programming in bash/gtkdialog and so on:

https://www.digitalocean.com/community/ ... n-python-3
https://medium.com/explorations-in-pyth ... 3bba3e6dc3
https://lyceum-allotments.github.io/201 ... and-pipes/
https://www.geeksforgeeks.org/python-os-pipe-method/
https://www.python-course.eu/pipes.php
https://github.com/kkroening/ffmpeg-python/issues/190
https://helloacm.com/execute-external-p ... thon-ways/

https://stackoverflow.com/questions/557 ... able-names
https://askubuntu.com/questions/1179001 ... hon-script
https://stackoverflow.com/questions/339 ... d-argument
https://iq.opengenus.org/pass-by-reference-python/
https://www.digitalocean.com/community/ ... n-python-3

Yeah, well my 9 year old knows nothing about the extra links above and doesn't need to at this stage - though he does need to know what stdin, stdout and stderr are.

NOTE: I wouldn't bother learning Python 2.x since Python 3.x dominates now. I haven't checked as yet, which, if any, of above links are Python 3 correct. Sometimes there are syntax differences and I think "subprocess module" is Python 3 only (my reading of digitalocean links above)

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

User avatar
wiak
Posts: 3627
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 56 times
Been thanked: 994 times
Contact:

Re: PySimpleGUI spells: "Good riddance gtkdialog"

Post by wiak »

Just given a minor update from my kid so thought I'd post it. He has only been playing with Python for a few days so no expert, but clearly knows more than I do. He made a program icon calc.png somehow or other, but I haven't uploaded that:

Code: Select all

#!/usr/bin/env python
# Simple Calculator
import PySimpleGUI as sg

sg.theme('Reddit')   # Add a touch of color
# All the stuff inside your window.
layout = [  [sg.Text('Simple Calculator')],
            [sg.Text('Enter a number:'), sg.InputText()],
            [sg.Text('Enter another number:'), sg.InputText()],
            [sg.Text('Enter a valid operator: * + - ^  / '), sg.InputText()],
            [sg.Multiline(reroute_stdout = True)],
            [sg.Button('Answer'), sg.Button('Cancel')] ]

# Create the Window
window = sg.Window("Simple Calculator", icon='/mnt/sda1/python_stuff/calc.png').Layout(layout)
# Event Loop to process "events" and get the "values" of the inputs
while True:
    event, values = window.read()
    if event == sg.WIN_CLOSED or event == 'Cancel': # if user closes window or clicks cancel
        break
    if values[2] == '+':
        result = float(values[0]) + float(values[1])
    elif values[2] == '-':
        result = float(values[0]) - float(values[1])
    elif values[2] == '*':
        result = float(values[0]) * float(values[1])
    elif values[2] == '/':
        result = float(values[0]) / float(values[1])
    elif values[2] == '^':
        result = pow(float(values[0]), float(values[1]))
    else:
        result = 'Invaild Operator.'
    print(values[0] + ' ' + values[2] + ' ' + values[1] + ' = ', result)

window.close()

By the way, I only use geany in my own quick attempts, but my nine year old prefers using something he found in Arch repos called pycharm whilst developing! ;-) :

Code: Select all

# pacman -Ss pycharm
community/pycharm-community-edition 2021.1.3-1
    Python IDE for Professional Developers

It isn't me who typed "Invaild" wrong.

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

User avatar
wiak
Posts: 3627
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 56 times
Been thanked: 994 times
Contact:

Re: PySimpleGUI spells: "Good riddance gtkdialog"

Post by wiak »

Thought my 9 year old had become bored with his Python programming experiments and moved back to simply playing minecraft and/or minetest games and so on. However, today he was very excited to call me over to see the new project he was working on - hacking some code he found on a tutorial to make a local chat/messaging system in a Python GUI. Turns out, to my surprised, he was using kivy rather than the PySimpleGUI that I thought he'd find easier.

He is no prodigy, but simply introduced at a young age to programming. For a youngster like that, programming soon becomes like a natural language. Learning anything new for me is really quite painful and I struggle to become confident, but for him, it is all just like primary school work. No-one needed to teach him any object-oriented coding principles - he just seems to understand it all naturally - seems obvious to him to "include' new libraries of objects and use them and learn the internal 'methods' each object can provide and their 'properties'. Yes, I know enough to appreciate roughly what is going on in the code he is hacking at - but, for me, it is a learned-with-difficulty sort of experience, whereas it is clearly all just obvious to him... Because of that, he seems to have no problem modifying such code to mould it to do what he wants - whereas I'd spend ages thinking/analysing it, reading object-related docs trying to see what I could do - he just takes a few minutes and hacks around with what is there and the result just works. No prodigy, really not, just the usual amazing thing about young kids - they become naturalised to early-language experiences so just becomes an extension of how their minds thereafter work. Scarey really - I begin to feel stupid in comparison. He can't do bash - has no interest in it aside from the commandline knowledge he discovers by himself he needs, and nothing more. But he mastered installing programs from Arch AUR entirely by himself and without any helper programs - goodness knows how - it can be quite tricky since involved some manual dependency fetching usually... Also, he decided all by himself to prefer autologging in as 'normal user' rather than 'root user' because AUR Installs require normal user login environment to install and use several of the games he thus installed. Then he installed Python programming environments I had never heard of, and uses these for his kivy (and PySimpleGUI work). No bash/gtkdialog interest at all - and that is frankly good - old stuff like that sticks us in the mud and we never develop our programming skills beyond it otherwise - my wee 9 year old, would pick up bash in a day or two if it interested him, but I doubt he'd think much of gtkdialog compared to what he can already do in Python (and previously done in Javascript, and Scratch kids programming environment before that).

My only wish is that one day he will be willing to learn how to also maintain and help develop WeeDog Linux - I suspect that will be easy for him in the future and he will take these developments to a whole new level if he ever bothers - he does use WDL_Arch64 (since that's what I provided him with on his computer) and he likes it a lot, but it is just a distro to him - wouldn't surprise me at all if he suddenly replaced it with Manjaro or something else entirely. Doubt it would be Puppy though - his communication app programming already involved multi-users and login permissions and he yabbers away to me about IP addresses, sockets, and AF_INET streams involved in his send/recv functions. It's a weird experience to listen to his discourse - I look at his recent Python programs and it is so similar to the C programming I once did in a research group involving fine-tuning of TCP/IP protocols - that's first I ever heard of AF_INET and yet my 9 year old uses such terms as if they are everyday primary school playground talk.

As for his chat/messaging program - he emailed me his server.py and client.py scripts so that he could test out a local LAN comms session with me. Wow, it works... and I've had him explain the functions to me and really he understands all of the code... nice GUI too - he understands exactly how that kivy stuff works too... Eat your hats gents. Time you stepped up to the plate and moved beyond bash/gtkdialog/yad alone - even the 9 year olds are becoming 'better' than us old stuck-in-the-past hats... Actually, I finally moved to autologging in as user weedog instead of user root too... Admittedly, I arranged WDL_Arch64 build to make weedog member of sudo group and wheel group in such a way that no sudo password needs entered. Main first trick to making admin as simple as it always was when was always root user is to start pcmanfm as root whenever doing major admin tasks. Second trick to get over issue that normal user normally only has write permissions to /home/'normal user' directory is to give that user permissions to own area on /mnt/sdaX (or wherever non-save persistence /mnt/home is on distro). After that it is just as convenient as being logged in all the time as root really, but with several advantages (such as AUR install working and Chromium working and the increasing number other apps that don't 'like' running as root user). That is, when I want to do system admin work I simply open a terminal and enter command:

Code: Select all

sudo pcmanfm

Any work done in there is then as root user anyway...

And, I created directory out of save persistence folder on my WDL_Arch64 system at /mnt/sdaX/weedog and gave user weedog ownership of that whole area (for downloads from browsers or whatever storage needs...):

Code: Select all

sudo chown -R weedog:weedog /mnt/sdaX/weedog

Furthermore, I have VirtualGL auto-available on all my family's WDL_Arch64 builds along with tightvnc server and viewer and ssh server/client. Owing to the wonders of systemd, I auto-start vncserver sessions for myself on all the family machines, so I regularly remotely run some programs/apps on any one of them (and have it configured to return full openbox/tint2 normal WDL_Arch64 desktop to me via vncviewer), which is good since some of these machines have tons of RAM and fast CPUs and my own old 2008 HP Elitebook 2530p has very limited resources... Thank goodness for multi-user system distro, and also that I can become very familiar with systemd use - I'd hate to go back to messy rc.d sysVinit system scripts to hack away at trying to make similar system work so seamlessly as it does now - everything so easy with systemd: once the ultra-simple unit files are built (easily/quickly) all I needed to memorise was how to use systemctl program. i.e.:

Code: Select all

sudo systemctl <enable|disable|start|stop|restart|status> unit_service_filename

If you really insist on continuing to avoid mastering systemd (which most all Linux has adopted...) then at least use something a bit less ancient/messy than sysVinit - for example, runit (as used in Void Linux) is pretty nice (nevertheless becoming confident with systemd is important overall nowadays, as is getting out of the bash/gtkdialog/yad rut is important for aspiring developers and the likes of me too).

Saving time for all the many things I want to do is the most important requirement of my system builds for me; I simply no longer have time to spend my computing days continually hacking old systems to try and get them to work the way I want them to. Systemd is a great help to reduce that mess and especially when all these vnc/ssh related facilities are auto-configured in my personal builds of full multi-user capable WDL_Arch64. Certainly I don't care how much hard disk space the distro uses - fact is it uses as little RAM and CPU as any little pup and I have tons of hard disk space available even on the oldest of these machines; even my biggest WDL builds with all bells and whistles and huge apps installed end up requiring only a few GB of hard disk storage - many a pup user ends up needing just as much HD space for all their bolt on sfs addons I think... (I certainly used to).

wiak

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

User avatar
wiak
Posts: 3627
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 56 times
Been thanked: 994 times
Contact:

Re: PySimpleGUI spells: "Good riddance gtkdialog"

Post by wiak »

My goodness... just discovered he uses either Pycharm or Sublime Text4 for his python development editors... Geany not good enough??????!

Installed them from Arch AUR apparently. Out of control...

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

Locked

Return to “Programming”