13 ms·
Guietta – Python module to create simple GUIs
- toyg 6y ago_ is typically used to i18n strings with gettext, it seems like poor naming for a layout-related function like a spacer. Apart from that, this seems to be a wrapper on top of PySide/QT to speed up development of basic forms. I don't find it particularly attractive, I have a feeling one will have to drop into QT as soon as requirements get slightly complex. Then again, if it gets more people to approach QT and desktop GUIs in general, it's welcome.
- BareNakedCoder 6y agofrom guietta import _ as z
- alfiopuglisi 6y agoI realized too late that _ is used for i18n. Well, 10 minutes late maybe, but I had already completed the first test GUI and it looked so nice that I could not turn back :) If you have ideas for an alternative syntax, I am all ears.
- mkl 6y agoHow about __? That matches the magic __ in __a__.
- alfiopuglisi 6y agoIf you look in the tutorial, there is also a ___ (three underscores) magic widget for special layouts :) I can see the difference between one and three, but between two and three it becomes difficult :)
- deleted 6y ago[deleted]
- adamnemecek 6y agoI don't want to shit on anyone's work but there are so many wrappers around qt, gtk and the others. I wish more people were writing guis frm scratch as opposed to wrapped the same old shit.
- pg-gadfly 6y agoAnd why is that? Would bringing water into your house by a bucket also be a great idea? Unlikely, unless it serves another, non-obvious point.
- ptx 6y agoPerhaps it would, if the plumbing takes up most of the space in your apartment and requires complicated maintenance.
- mrmonkeyman 6y agoI agree. Qt is a massive overkill. There is - IMO - a resurgence of stuff being made from first principles instead of wrapping the same old turd again and again. For example https://github.com/Immediate-Mode-UI/Nuklear https://github.com/Immediate-Mode-UI/Nuklear. It just makes sense to have variety and it can be eye opening to see a 1MB header based solution adequately solving this problem of simple UIs without invoking the 1000lbs gorilla that is Qt.
- A4ET8a8uTh0 6y agoSome are better than others and sometimes you want something really quick and simple.
- HelloNurse 6y agoThis project explores an extreme niche in original ways, which is the whole point of adding to the existing "so many wrappers". And regarding the "same old shit", you'll be entitled to spit on mature frameworks when your GUI from scratch supports screen readers, 3D acceleration and printing with the same API on Windows, Linux and OSX.
- Okkef 6y agoEvery time I see something like this I think back to the glorious days of Borland Delphi with it's beautiful drag&drop GUI builder.
- colde 6y agoYou don't even have to go back that far. XAML and C# developed with Visual Studio and Expression Blend is a fantastic experience, it almost makes me wish Silverlight was still around.
- tonyedgecombe 6y agoIt's much heavier than what we had with Delphi/VB, it feels like wading through treacle in comparison.
- pjmlp 6y agoWe still have, Delphi might not be loved by younger generations, but it is still around for those that care. Same applies to C++ Builder, which MS still hasn't been able to match. C++/CX was the closest we got on VS, but then politics killed it.
- GordonS 6y agoWinForms in Visual Studio is fast enough, but working with WPF and XAML certainly used to be painfully, painfully slow! Visual Studio would grind to a halt and memory usage would go through the roof. In fairness, I haven't done any Windows desktop development for some time, so the XAML designer might be less crap nowadays.
- canistel 6y agoLazarus(open source and cross platform) is there, alive and thriving, actively developed and used. https://www.lazarus-ide.org/ https://www.lazarus-ide.org/
- langitbiru 6y ago
- galacticdessert 6y agoBased on the very limited documentation it seems to follow a similar approach to PySinpleGUI https://github.com/PySimpleGUI/PySimpleGUI https://github.com/PySimpleGUI/PySimpleGUI PySimpleGUI is indeed simple and quick, not very elegant but useful for small utilities.
- alfiopuglisi 6y agoYes, I was inspired by PySimpleGUI (and say as much in the introduction: https://guietta.readthedocs.io/en/latest/intro.html https://guietta.readthedocs.io/en/latest/intro.html ). But I felt that PySimpleGUI did not go far enough in making things simple. It also supports multiple backends, so that may be a reason to keep things more structured. Guietta is just a thin wrapper over QT.
- sradman 6y agoWell done. Both Guietta and PySimpleGUI surprised me by implementing an Internal DSL for Python. Both leverage Python's List literals to define a GUI grid layout. PySimpleGUI uses nested Lists to define the grid with a .WidgetType() style method used in each slot. Guietta starts with a Builder Factory method with List literal varargs (one List arg per grid row). Instead of .WidgetType() wrappers, Guietta infers widget type based on List element type and string formatting rules. The resulting column aligned code has the visual look and feel of a grid/table and makes it very readable. The choice of Qt-only seems reasonable. There is probably a category of DSLs that try to mimic a grid/table layout rather than a natural language DSL (many Ruby style Internal DSLs). This is definitely the style I use for SQL DDL, using a strict grid-like layout for the column constraints and moving the verbose parts (like CHECK constraints) to the table constraints section at the end.
- app4soft 6y ago> Guietta is just a thin wrapper over QT. So, any pro'n'cons in comparison to PyQt?
- dr_zoidberg 6y ago
- samanator 6y agoI love how the imports in https://github.com/alfiopuglisi/guietta/blob/master/guietta/guietta.py https://github.com/alfiopuglisi/guietta/blob/master/guietta/... are ordered from shortest to longest. Makes them look like stairs! Very aesthetically pleasing :). Might take that up in my next project.
- teekert 6y agoSomeone once told that that is the way to do it and so I always do (this is not how I normally operate ;)). There is no practical use though I think. But, it looks nice :) Kind of like a phonebook starting with companies like AAAGarden, now you want your module name to be short to get to the top ;) Edit: Found some discussion on this topic: https://stackoverflow.com/questions/20762662/whats-the-correct-way-to-sort-python-import-x-and-from-x-import-y-statement https://stackoverflow.com/questions/20762662/whats-the-corre...
- skocznymroczny 6y agoSome of Python linters enforce such style. If you enable pylint or black I think they do that by default.
- diarrhea 6y agoblack sorts alphabetically, with standard lib first, then 3rd party imports, and user/local imports last. Blocks are separated by a blank line. `from ..` imports come after `import ..`. Especially the alphabetic ordering is important in my view. Makes parsing/reading and spotting duplicates much easier. It is also PEP8 style [0]. For all these reasons, I think the pyramid style is awful in comparison. 0: https://www.python.org/dev/peps/pep-0008/#imports https://www.python.org/dev/peps/pep-0008/#imports
- StavrosK 6y agoBlack doesn't sort imports at all.
- 6y ago
- iwangulenko 6y agosweet! will this run on mac? edit: tried: "UnboundLocalError: local variable 'loader' referenced before assignment Fatal Python error: could not initialize part 2 ... 'python script.py' terminated by signal SIGABRT (Abort)" :(
- toyg 6y agoThat smells of poor QT programming rather than anything to do with macOS.
- alfiopuglisi 6y agoHello, author here. I have tested Guietta on two different macs (mine and a coworker's) and it worked in both cases. There is no variable called 'loader' in Guietta's source code. Are you trying the example in the github readme, or a custom script? Which MacOS version? If you wrote your own script.py, could you please copy it into a github issue?
- rembicilious 6y agoGreat idea! Tkinter always looks a little dated and PyQT is more than my brain wants to deal with when I need a simple GUI.
- toyg 6y ago> Tkinter always looks a little dated "A little"... it's straight outta the '90s. I am as nostalgic as anyone but even I don't particularly long for that æsthetic.
- draven 6y agoThat was my first thought, this could be handy to hack small utilities. I think Tk widgets are themable.
- TazeTSchnitzel 6y ago> Tkinter always looks a little dated It doesn't have to, it supports theming and there are even themes that use the native GUI. e.g. https://wiki.tcl-lang.org/page/List+of+ttk+Themes https://wiki.tcl-lang.org/page/List+of+ttk+Themes (search for “native”)
- asicsp 6y agoIt says MIT license. I'm not so good with comprehending licensing terms. PySide2 [0] is under >GNU Library or Lesser General Public License (LGPL), Other/Proprietary License (LGPL) So, is it okay for Guietta to be MIT? [0] https://pypi.org/project/PySide2/ https://pypi.org/project/PySide2/
- phoe-krk 6y agoAFAIK a library that uses LGPL3 modules without any modification is allowed to be licensed differently, provided that the final product allows the LGPL3 modules to be recompiled and/or swapped for others and that the source for the LGPL3 modules is provided.
- asicsp 6y agoThanks. I'm still confused though. If I create an application using Guietta, do I have to follow MIT or LGPL3 terms?
- phoe-krk 6y agoYou can follow whatever terms you desire for your application as long as you fulfill the requirements of the licenses of all modules that you use. In case of MIT, it is attribution; in case of LGPL3, you need to make the source of the LGPL3 module available and you need to make it possible for the user to swap the compiled module you ship for their own version of that module.
- alfiopuglisi 6y agoThanks for the heads up. I confess that I did not look deeply into library licenses while setting up the project. I will add a note about PySide2 being LGPL in the readme.
- 72deluxe 6y agoLooks very simple to write, although as others have said why not use a GUI to build the UI, eg. wxFormBuilder which has outputs to Python/PHP/C++ ? Thought I'd mention that as it might be something useful to others.
- markussss 6y agoThis looks great. I have previously written a small GUI application with Qt where it's just a slider and a text label, and when the value of the slider is changed, a command is ran and the label updated. In quickly hacked together Python/Qt, it's 71 lines. It seems like I can cut that down quite a lot by using this. I will have to test it. Thanks!
- alfiopuglisi 6y agoIf you get around to test it, I would love to hear the results :)
- milansuk 6y agoNice work. I have one out of curiosity question. In the example, there is the button called 'Calculate' and then action define in "gui.Calculate" block. But what if the name of the button was 'Calculate it'(with the space between words)? The action header would be gui.'Calculate it'?
- alfiopuglisi 6y agoHello, Guietta author here. For most widgets, the name is derived from the widget text removing all non-alphanumeric characters. So in your example it would become gui.Calculateit It is also possible to set a custom name using a tuple syntax (widget, 'name'). Like this: (['Calculate'], 'myname')
- marczellm 6y agoI wrote a XML/YAML based declarative wrapper around tkinter once: https://github.com/marczellm/tkpf https://github.com/marczellm/tkpf
- raghavtoshniwal 6y agoThis is so timely! I am teaching CS to some high-schoolers and they just got introduced to Python, I want to hook them by getting them to make something that they can play around with. Could use this there :D Somehow, it feels like, CS education is getting both easier as new low friction tools are being made available each day and getting harder because the sheer complexity and number of things to know to really understand anything at all the levels of abstractions is getting more complicated.
- gljiva 6y agoAs a former high-school student who has done many little projects with tkinter at that time, I would recommend against dumping tkinter altogether for several reasons: - with higher complexity comes higher versatility. I liked how it enabled me to be creative - there are two well-written reference websites for learning it easily despite complexity (and that's important if you want your students to like/learn to read the docs) - the tkinter being shipped with Python meant quite a lot to me However, the reason I did that many projects is that part of my class wasn't really into programming, so if you think that learning and using this will be significantly easier than tkinter basics, go with it, but I would recommend leaving tkinter at least as an option for "those who want to know more", i.e. students who are considering studying CS.
- GeorgeTirebiter 6y agoWhat are the URLs for those two well-written references you mention? Thank you.
- smt88 6y agoHonestly I would advise against this for beginning coders. It's very "magical" -- there's no easy way to see how the text translates into a UI. It gives them no additional understanding of GUIs at all, really. Whenever you encounter a new programming topic for the first time, it helps a lot if you encounter it in a fairly universal format. I'm not sure about Python, but in most languages, there are simple GUI libraries that accomplish both of your goals: exciting students with interactive programs and helping them more deeply understand how GUIs are usually built and maintained.
- maddyboo 6y agoIf you want to present GUIs from shell scripts, I highly recommend zenity and/or yad: https://gitlab.gnome.org/GNOME/zenity https://gitlab.gnome.org/GNOME/zenity https://github.com/v1cont/yad https://github.com/v1cont/yad
- Abishek_Muthian 6y agoWould have loved few examples of GUI on the project repo like in the OP repo (or) I didn't see where I should have been looking.
- maddyboo 6y agoI agree, there should be some screenshots in the READMEs. Here are some example uses of yad with screenshots: https://sanana.kiev.ua/index.php/yad https://sanana.kiev.ua/index.php/yad
- riffraff 6y agoThis might not be obvious, but the name appears to be a pun in Italian on the name Giulietta (Juliet), known for cars and for the shakespearean play. It made me chuckle a bit :)
- alfiopuglisi 6y agoGuietta author here. In fact I am Italian, but the name is just a diminutive of "GUI" - in Italian it sounds something like "small and cute GUI". I have a friend called Giulia and she initially thought that it was dedicated to her :)
- galacticdessert 6y agoI initially thought you were the enthusiastic owner of an Alfa Romeo Giulietta :)
- oflannabhra 6y agoI was expecting it to be a play on goetta, a type of sausage.
- yellowapple 6y agoIs including arbitrary Qt widgets doable (whether now or in the future)? A lot of my use cases for PyQt5 revolve around QWebEngineView; would be great to be able to throw that widget into a Guietta layout with the extra buttons and such I'd be using around it.
- alfiopuglisi 6y agoYes, any QWidget instance can be used directly in the layout. If then you want to reference it, the best option is to use the tuple syntax to assign it a name: (widget, 'name'). Check the slider example out (slider.py), it does exactly this.
- nottorp 6y agoBut is it safe to go near Qt any more?
- IshKebab 6y agoHonestly this looks hacky and "magical". E.g. what makes 'result' different from 'Enter numbers:'? Is PyQt really that difficult?
- alfiopuglisi 6y ago'result' and 'Enter numbers:' are exactly the same thing - two QT labels. The example code just changes the first one's text. If you run the code, you'll see it by yourself. PyQt is not really difficult, just boring. And a bit of magic was indeed the intended effect :)
- als0 6y agoCool project, some questions. In the README, Quit is a button but doesn't appear to be consistent with the syntax of other buttons like ['Calculate']. Is there a reason for this? Also, how do you bind buttons to functions?
- alfiopuglisi 6y agoQuit is a built-in class, because is very common. There are also Yes, No, Ok and Cancel builtins. You could do the same writing ['Quit'] and binding it a function that quits the program. Binding is done using QT's signals/slots mechanism under the hood, and can be done in several ways: - using the 'with' statement as in the example, but this is often limited - using an events layer, that is, a replica of the GUI layout, with a callable for each widget that you want to bind. - using the @gui.auto decorator on a function: it will try to guess. All this is described in the tutorial: https://guietta.readthedocs.io/en/latest/tutorial.html https://guietta.readthedocs.io/en/latest/tutorial.html , chapter "GUI actions"
- Bomberus 6y agoDoes it support reactive data binding? Like: https://github.com/Bomberus/LayoutX https://github.com/Bomberus/LayoutX
- alfiopuglisi 6y agoNo, you have to manually update widgets assigning them their new value (strings, and for labels also lists and dicts). I will think about such a feature but I have no experience with such dynamic frameworks :)
- Bomberus 6y agoShouldn't be too hard. For example you could use: https://github.com/ReactiveX/RxPY https://github.com/ReactiveX/RxPY. Then your central state is assigned to a Subject and all widgets have an reference to an observer. As soon as the central state value changes, the callback in the observer is triggered and you can fire the update method for the widget using the central state value.
- shepardrtc 6y agoThis is just what I was looking for! I developed a very simple (and slightly similar) TUI library, but I need to at some point move to a GUI, and this is perfect for it. Thank you!
- mindv0rtex 6y agoFor not too elaborate GUIs in Python, I think TraitsUI is a really neat library: https://github.com/enthought/traitsui https://github.com/enthought/traitsui
- panic 6y agoI love how the buttons, since they're written as a string in an array, actually look like ASCII art buttons. Cool stuff!
- cafard 6y agoYears ago, I really liked PythonCard, but the last time I looked it seemed to have been abandoned.
- Perseids 6y agoSlightly off topic: Does somebody have a recommendation of a toolkit or library for simple data entry and display with Python? Basically I want to replace Excel/Calc for mostly tabular data, because I hate the programming and data access model (e.g. instead of writing B$8 or sum(A9:A23) I would like to have map/reduce function with reasonable variable names). But the presentation and entry speed is much better with spreadsheet software, than when using some ad-hoc plain text format for simple parsing with python.
- hobls 6y agoThat's really neat. It reminds me of generating a CLI based on docstring, which is another pattern that I like a lot.
- manifoldgeo 6y agoAre you by chance talking about docopt? I love that tool! http://docopt.org/ http://docopt.org/
- hobls 6y agoYep! I love it for simple projects.
- goostavos 6y agoYou can also generate an entire GUI from CLI Args! https://github.com/chriskiehl/Gooey https://github.com/chriskiehl/Gooey ^_^
- carapace 6y agoI once made a simple little GUI generator based on effbot's "Generating Tkinter User Interfaces from XML"[1][2]. I added a tiny parser (written with SPARK[3]) that converted a simple DSL to XML (technically an ElementTree object, the actual XML isn't serialized/emitted at any point) which is then "realized" as a tree of Tkinter widgets with event callbacks. [1] https://www.effbot.org/zone/element-tkinter.htm https://www.effbot.org/zone/element-tkinter.htm [2] https://github.com/calroc/pygoo https://github.com/calroc/pygoo [3] http://pages.cpsc.ucalgary.ca/~aycock/spark/ http://pages.cpsc.ucalgary.ca/~aycock/spark/ "Scanning, Parsing, and Rewriting Kit"
- mkchoi212 6y agoThis feels like markdown but for GUIs. Love the simplicity and look forward to see what kind of interfaces people come up with!
- zubairq 6y agoAs the author of another open source GUI builder tool (https://github.com/zubairq/pilot https://github.com/zubairq/pilot) I think that the simplicity of tools like Guietta really make it easy to play around and build things fast, so I like it
- user5994461 6y ago>>> from guietta import _, Gui, Quit I am not looking forward to taking over projects using that framework abusing underscore and double underscore magic variables. The underscore "_" is a pseudo reserved variable in python. It is used in assignments like year,month,_ = readdate() to discard the return value and disable the lint warning about it.
- codethief 6y agoCouldn't you simply do something like >>> from guietta import _ as underscore to fix this?
- user5994461 6y agoAfter spending inordinate amounts of time debugging obscure side effect caused by "import as" and "from import". I'd reject that "from import as" on sight in code review.
- detaro 6y agoAny hints towards what kind of issues those cause? I could see some around relative imports, or something else?
- user5994461 6y agoLet's say you write a module httpclient doing this: from ssl import sslsocket import httplib as hlib You can think of the code above as remapping and/or duplicating the whole library it's importing. Python imports involve complex local and global states (I don't pretend to understand most of it). One direct effect on usage is that users of the library can call "httpclient.sslsocket" and "httpclient.hlib" as if they were provided by the library (the author certainly didn't mean to). This creates problem down the line when the author try to change the internal dependency, and this extends to other code also doing "import httpclient.sslsocket as sslsocket", creating problematic hidden dependencies. More generally, this affects all import dependent features, like reload(module), mock, sys content, etc... imports are looked up and tracked by full path which doesn't always work as expected when paths are hot patched as above. I used to work in a python shop (millions of line in total across the organization). Regularly had the problem with interns and new graduates abusing imports as above (sometimes even trying to change the existing imports because they though this was the better syntax). Then they couldn't pass their own tests (every new module must have a test) and asked for help after few hours of trying. Changing to a normal "import xxx" solved the problem. It's not always clear what was the exact issue, except side effects due to imports.
- blackrock 6y agoClever. Cute for a simple little program. But will quickly devolve into a morass if you need to do anything beyond a simple grid.