Is there a Python library that allows to build user interfaces without writing much code? - python

I am writing editing front ends in Python since several years now, and I am fed up with micromanaging every UI detail of a window or dialog every single time.
Is there a technology that allows me to, say, specify the relations between a GTK+ Glade-designed interface and the tables and records of an SQLite database to do all the middle man work? It should spare me the work of manually writing event handlers, input evaluators and view updates.
The technologies in question are just examples, but I want to stick with Python as far as possible.

Besides the ones already mentioned I can add:
Kiwi
uxpython
pygtk
treethon
I've never used any of them so have no recommendations but, for what it's worth, I have used at least 2 complex programs built directly on pygtk that worked in both Windows and Linux.
I think Kiwi is the only one of these with baked in support for db (through interface with SQLAlchemy, SQLObject, or Storm) but I would be surprised if you couldn't use one of those ORM's inside any of the other frameworks.

PyQt and its models can automate some of these tasks for you (to some amount off course, e.g. filling widgets with data from a database and handling most of the widgets behaviour, buffering etc.).
If you want a more object-oriented approach to handling SQL you could look into an ORM-oriented solution (for example SQLAlchemy).

Dabo is built on top of wxPython, so you may not prefer it, but it's designed to make it easy to tie a GUI to a database, so I'd recommend you check it out if you haven't already. In particular, it's got good facilities for tying widgets to data, and handling a lot of the common cases of GUI development.

wxGlade may help, although I haven't used it myself so I don't speak from experience.
Boa Constructor apparently has a wxPython GUI builder in it, and there is also PythonCard, though development on these two projects seems to have stalled.

Traits might be a good option for you.
http://code.enthought.com/projects/traits/docs/html/TUIUG/index.html
AS simple as it is to map a UI to an object, it doesn't seem too far fetched to incorporate SQLAlchemy for persistence.

There is a good book on wxPython, "wxPython in Action", which can't be said for some of the other solutions. No knock on the others. I've had success developing with wxPython in the past and it comes with a great set of demo applications with source code from which you can borrow liberally.
The best UI designer I found for wxPython applications is a commercial one, Anthemion DialogBlocks. It's by one of the wxPython programmers and is worth the money. Other solutions for UI design include wxGlade (I found it usable but not featureful) and Boa Constructor (haven't used it). Wing IDE might also have one. Stani's Python Editor bundles wxGlade, I believe. There are a lot of other projects that don't really work or are fairly old.
As far as SQL automation goes, as another answerer says, I'd look at SQL alchemy, but the learning curve for a small application might be too much and you'd be better off just going straight to odbc. The best odbc api is the one used by Django, pyodbc.
It's been a while since I developed with these tools, so there may be something newer for each, but at the time these were definitely the best of breed in my opinion.

I had lots of success with wxPython, but that was some years ago now and there may be better new solutions...

Ok this is an unconventional solution but write yourself a code generator. I have done this several times using Mako. So in my case I auto inspect a table which columns it contains and types and generate classes from that. It's more work upfront but does exactly what you want and is reusable in subsequent projects.

Related

Opinions about Enthought Traits/TraitsUI for Python desktop development

I'm looking for opinions and experiences about using Traits / TraitsUI / enaml for Python desktop development.
The documentation and the Enthought support looks promising, so I wanted to know real first-hand experiences of developers using this stack.
Update:
My main focus of interest is to migrate old several desktop database
applications: CRUD / querying / reporting. Then, I'm particulary
interested in the data access layer: now, I'm using PosgtreSQL and
peewee (a minimalistic ORM):
Is there any built in or side-project support for SQL databases?
If so, is there any ORM support? (I suppose SqlAlchemy is the 'standard' here)
I first started using Traits and TraitsUI to build GUI's as a postdoc researcher in Mechanical Engineering. My previous experience with building GUI's was with MATLAB's GUIDE, and I found TraitsUI to be very straightforward and easy to get started with by comparison. TraitsUI has a very linear progression of progress versus effort, and for the limited amount of GUI building I did with it, it was more than sufficient.
As a professional developer (full disclosure: I work at Enthought), my perspective has shifted somewhat. First, it is important to make the distinction between Traits (the typing, validation, notification, and dependency system) and TraitsUI (the GUI layer built into and based on Traits). I use Traits all the time, and it undergirds a lot of the code I write. Particularly for its dependency and notification utilities, I consider it to be invaluable.
It doesn't take too long, however, to start bumping into the limitations of TraitsUI for application building. As I mentioned before, TraitsUI is sufficient for small- to mid-sized applications, but it gets difficult to create more-complex layouts, and we were spending a lot of time wrestling with TraitsUI to produce larger, more involved and flexible application interfaces.
That led to the more-or-less blank-slate development of Enaml. Enaml uses a constraints-based layout system at its core and integrates with Traits. From the outset, it addresses the layout weaknesses of TraitsUI. Every one of us that has used both systems prefers Enaml, and we consider it the tool of choice for GUI-building moving forward. The level of control and flexibility to lay out GUI's is remarkable --there are some nifty demos to check out in the repo.
That said, there is a slightly (but only slightly) steeper initial learning curve since it is helpful to have a grasp of certain concepts such as MVC separation from the outset. An experienced developer would see the value in this right away, but it might be more of a hurdle for a new user with a science or engineering background. It is only a slight hurdle, though, and easily cleared. Also, while the feature set is nearly complete, there are still a few holes. There is steady progress on filling them in, but Enaml is technically still in beta.
Overall, if you are trying to decide which tool set to learn, my recommendation is to learn Enaml. It's what we are and will be using going forward.
[UPDATE - Jan 2018]
Since this answer continues to get views and generate conversations, an update on this opinion is long-since overdue, the first answer dating from late 2012. Enaml has largely been the work of one main developer. When he left Enthought in early 2013, he forked the enaml repository and started developing it in the nucleic/enaml repository. We (Enthought) decided not to develop a competing fork and introduced a thin interface library enthought/traits-enaml to provide ongoing compatibility with changes in nucleic/enaml. Around the same time, we also introduced enthought/qt_binder to provide easy access to low-level Qt widgets in the Traits/TraitsUI framework which provided much of the same kind of layout flexibility that Enaml provided.
Now Traits/TraitsUI is the stack we use for most application GUI building. We continue to maintain and develop Traits, TraitsUI, and the other libraries in the Enthought Tool Suite (Chaco, Kiva, Envisage, etc) in Python 2 and 3, and they continue to meet our needs, especially in the enthought/envisage pluggable-application framework.
My amended recommendation is if you want to build a rich-client application (not a web app, that is) in Python, I would say to learn Traits and TraitsUI.
Disclaimer: I work as a developer and trainer at Enthought.
To answer the secondary part of the question, there isn't any ORM or database support baked-in to Traits, so you'd have to roll your own. This is largely because Traits was developed to support scientific application development, rather than enterprise app development (but that is is why Traits does have NumPy support backed in).
There's an unfortunate awkwardness caused by the fact that most ORMs (such as SQLAlchemy, Django's ORM, and I see Peewee as well) and Traits both use declarative-style interfaces and metaclasses to make defining object structures very easy, but at the downside of not playing very nicely together. If you want to avoid an explicit bridging layer then you need to have a solid understanding of both Traits and the ORM.
If I were developing this sort of app, I'd probably end up avoiding the use of the ORM and writing directly from traits to the DBAPI layer, possibly defining some custom trait types for this purpose (eg. Property trait factories whose fget and fset execute database queries).
All of that said, and admitting to my bias in favour of Enthought's technologies, there are some tools out there which may be more suited to sitting simple CRUD UIs on top of a database. One possibility is Dabo, but there are others out there such as Camelot.

Framework for paint program

I've decided to start working on a personal project, attempting to develop a cross platform, MSPaint like app. Oddly enough, I find mspaint is one of the applications I miss the most on Linux or OS X, so I want to try to make something similar. Tuxpaint, mtpaint, gpaint, etc. are all old and inactive and ugly. I don't want to make GIMP, just the basics, similar in features to MS Paint.
I'm thinking of doing it in python with the pygtk toolkit, but I was interested to hear your suggestions. Would C/C++ be a better choice, or even C# (gasp!) with mono? How about using Qt as opposed to GTK, or maybe some other fancy library I don't know about (Please, not FLTK!). I'd be curious to hear your thoughts.
Thanks!
Qt's canvas object (or its newer replacement QGraphicsView) can do pretty cool things. Whether you choose C++ or python is a matter of personal choice, as Qt is supported in both languages. For a simple project like this I'd choose python because killer performance is not much of an issue, and it will be much easier to write.
Another thing to look into is making this app web based with HTML5's canvas object and Javascript. It can be surprisingly robust, and anything that can be put on the cloud is a win in most cases.
If you decide to go with Python (which would be my choice because it's such a simple language), then TkInter is considered the de-facto standard GUI package. That link should send you to some excellent starting references for TkInter, although I also really like Not_a_Golfer's suggestion of an HTML5 web-app.
Short: You can use both, no third party library is guaranteed to be distributed with all major distributions.
Long:
Gtk+ vs. Qt
What do you want incorporate into your application. If it is just selecting a brush, selecting color you could pretty much use any gui toolkit.
If you are going to run it as a web-based tool, Gtk+ has an html5 backend renderer (I don't know about Qt)
A sidenote:
I recommend to use the toolkit's native programming language (gtk+ C, Qt C++) - if you don't, you will suffer from delays with bugfixes, generally more bugs and delayed releases, though for that case it shouldn't really matter.
Everything else boils down to personal preferences and there already exist some questions to tackling that issue.
if you are using qt,you can use QtitanRibbon

Python Web/UI Options

We are in the process of standing up a UI on top of a python system. This is all throw away code, so we want something quick, yet presentable.
We will have a couple of "interfaces" but they will be of two types. One will be control, it will basically be sitting on top of a python thread, and accepting requests from the user.
The other will be more of a display screen that will need to be able to display images, and some classic "grid views" of text to the user.
We pretty much know we could* do all of this in HTML but wasn't sure what would be the best way to interact with the core python code?
Anyone know of a good UI python presentation layer? Since we know we can do all of this in HTML/Jquery pretty quickly, we are also open to suggestions on how to integrate this with a web server..
Any suggestions? Really interested in finding out if there is any way to use python as the back end to a webserver.
Let me know if you all need more information.
I like wxPython. The demo application is excellent and lets you browse, tweak and re-run the code right in the demo.
We have found the DJango meets our needs. It is a pretty slick mvc style python web stack. Really is easy to use, and very quick to develop in. I will say that the ORM layer is a little young so it is hard to do some simple queries, but luckly since this is throw away code we can just use native sql.
Tkinter is probably going to be the solution you can use quickest. Its API is simple and straight-forward, and you probably already have it installed.
As the other 2 classic Python GUI options have been given already, I feel duty bound to suggest PyQt :)
Using QT Designer I've found it much simpler than TKInter to get some basic GUIs up and running. Build your GUI up in a WYSIWYG way, then hook it up to the back-end logic. I've also found that the large amount of C++ help on QT available on the interent usually translates more or less directly across to PyQt. The resources available for TKInter are IMO pretty obtuse, and simply stop as soon as you want to do anything more interesting than Hello World. YMMV.
The Rapid GUI Programming with Python and QT book is a fantastic resource. Had me programming real applications in no time.

Looking for advice on how to develop applets for Gnome / Ubuntu

I am a linux (mostly ubuntu) user with a reasonable understanding of how the system works (although I am certainly not a linux guru!). In the past I have developed small cross-platform desktop applications in python/GTK and I delivered them to clients as self-contained filetrees, so that the only dependencies were Python itself and GTK.
Now I would like to develop a small applet for ubuntu, that I would like to release under GPL 2 or 3.
In particular these are the new steps I know I must learn in order to achieve my goal (it is very possible there are a few more that I am unaware of, though!):
Integrating with gnome: I want my application to be available as an applet in the taskbar.
Using D-bus: In particular I want my applet to use the new osd-notification framework for ubuntu, but communication with other applets is also a possible feature for a second iteration.
Packaging: I would like to setup a public PPA as soon as the application will reach alpha stage, but I also would like to use dependencies from existing packages in the official repos, rather than include the libraries again in my own package.
Of course official documentation will be my first source of knowledge, but - basing my judgment on the very useful answers that I received on another topic here on SO - I decided to turn to the SO community to collect additional advice like for example:
Are there additional steps to those I outlined before, that I have to learn in order to be able to implement my project?
Based on your own experience, would you advise me to learn those steps in advance (as the knowledge of those will influence my way of coding the core functionality) or would you consider integration with gnome / d-bus and packaging as "higher encapsulating levels" that can be added on top of core functionality afterwards (note: D-bus will be used at first just for pushing data. Input data will be retrieved with a webservice)?
Would you advise me to separate my application in two packages (back-end and front-end) or to keep it together in a single package?,
Do you know of any useful resource that you would advise me to look at, for learning any of the things that I have to?
Are you aware of any common "beginner's mistakes" that I should be aware of?
These questions are not meant to be exhaustive, though: if you feel that I am missing something from the general picture, you are more than welcomed to point me in the right direction!
PS: Should I have failed in explaining my final goal, take a look at project hamster: what I want to achieve is similar in terms of user interface (meaning: the applet should display the status and clicking on it should open the application itself, from which you could both configure the applet and perform various operations).
Well, you list python, so you'll want to have pynotify in your arsenal. It wraps DBus, and gives you a direct api for manipulating the osd-notification system.
>>> import pynotify
>>> pynotify.init("Lil' Applet")
True
>>> note = pynotify.Notification(
... pynotify.get_app_name(),
... "Lil' Applet wants you to know something's up.",
... "/usr/share/icons/Human/48x48/status/dialog-information.png")
>>> note.show()
True
This displays a notification that looks like this:
[ ] **Lil' Applet**
[ICON]
[ ] Lil' Applet wants you to know something's up.
As you already know, your first and best friend will be the code written by others - copy, paste, dissect, understand.
Luckily there are a few projects that do what you intend to achieve.
I can recommend conduit's code as a prime reference how to do things in a clean fashion. I think they also have stuff on dbus. Others to keep an eye on, would be deskbar-applet, hamster (heh), and any other app you remember having feature X. Sometimes it might require some C code deciphering though (like the applet button bit - i suggest you better take it from hamster as i was having some major time getting the thing straight)
Then the "devhelp" app will be of great assistance - it allows you to read and search in man pages fast and easy. Make sure that you also have the -doc packages for all the modules you intend to use.
For user interface i strongly suggest using glade, as that will allow you to change interface later much easier. Where you can't use glade - add and alignment box and add the widget in the box in the code.
There certainly will be quirks and things that you will learn the hard way. Should not be too hard though!
The packaging, especially the autotools will be bit of a struggle, but you will get it right. For how to do debians (and from there to PPA), you can dig in the hamster's repository history. There was once a "debian" folder.
I would suggest to start small - see if you can get a window. Then put a button on it.
You don't have to do it "right" the first time. For first time it will be ok, if something works at all.
As for the separation - i would not bother about it until you get there. Splitting up into two parts and have a core, should not be too hard later. But that all depends on your priorities.
Last thing - getting friends who know the field helps too. And one way to get new friends, is by taking part in other projects, heh.
There are some very good recommendations here already, but let me suggest that you develop your applet not so much "for Ubuntu" as "for Gnome". It doesn't take much extra effort to also make RPM packages for distributions such as Fedora, and Arch Linux packages, to name two examples. There is one major disadvantage though -- to stay compatible with Debian stable you have to stick to ancient versions of GTK and GLib, or at least make any functionality depending on newer versions optional. It's painful, but apparently Debian stable users appreciate it.
I'd also suggest setting up a source code management system somewhere as early as possible. You may not be worried about your disk crashing, but sometimes it saves you a lot of trouble just to be able to revert everything you did since the last commit.
Here's the link to the documentation on the official Gnome Panel Applet library. I don't know if it has Python bindings or not.
When I asked this question two years ago Ubuntu and Gnome were much closer to each other than they are today. At present (end of 2011) gnome adopted the gnome-shell, while Canonical decided to develop their very own UI (unity)...
Part of the tension that brought to the split specifically involved libappindicator, which makes the way I formulated this question (and probably part of the answers) obsolete.
Besides, there is now AskUbuntu on stack exchange, that would probably be a much better forum to ask about ubuntu-specific question.

What are the benefits of using Python for web programming?

What makes Python stand out for use in web development? What are some examples of highly successful uses of Python on the web?
Django is, IMHO, one of the major benefits of using Python. Model your domain, code your classes, and voila, your ORM is done, and you can focus on the UI. Add in the ease of templating with the built-in templating language (or one of many others you can use as well), and it becomes very easy to whip up effective web applications in no time. Throw in the built-in admin interface, and it's a no-brainer.
Certainly one successful use of Python on the web is Google App Engine. Site authors write code in (a slightly restricted subset of) Python, which is then executed by the App Engine servers in a distributed and scalable manner.
Quotes about Python:
"Python is fast enough for our site
and allows us to produce maintainable
features in record times, with a
minimum of developers," said Cuong Do,
Software Architect, YouTube.com.
YouTube uses a lot of Python and is probably the best example of a Python success story.
A great example of a Django success story is the Washington Post, who recently shared a big list of applications they have developed:
http://push.cx/2009/washington-post-update
www.lawrence.com and www.ljworld.com are two of the first sites to use Django (before it was even open source).
djangositeoftheweek.com has a bunch of good case studies.
www.everyblock.com is another great example.
Finally, http://www.djangosites.org/ links to nearly 2,000 other Django powered sites.
Short anwser: the diversity of tools readily available and freedom of choice.
This sounds like a simple question but which it really isn't. While Python is very good for web development and this has been shown by the, oh so famous, Google App Engine, Plone and Django. One has to point out that the development way in Python requires a lot more from the developer than PHP but it gives a lot more to the mix as well.
The entry level on actually producing something is higher. This is because there are bunch of different tools for doing web development with Python. Choosing the web development framework can be a hard decision for an inexperienced developer.
Having a lot of different tools is a two edged sword. To some extent it brings you the freedom of choice to pick the one you might want but then again how do you really know which one is good for what you're doing. This brings me to my point. Python stands out from the mass by not having a standard or de facto web development library. While this is pretty much against the principle of having only one simple way of doing on thing it also brings us a wide variety of different tools with different kind of design choices. At first this might feel very frustrating because it would be so much easier if somebody had made the choice for you but now that you're left to make the choice you actually might have to think about what you're doing and what would fit. ...or you might just end up picking one and blowing your head off after you've realized that you made the wrong choice. Anyway you end up, you've made the choice and no one else.
Furthermore,
Python is both strong in web and in data analytics and machine learning. For example scikit, sci-py and numpy are very strong. In some cases, it can be very interesting to have the both elements on the same server.
For example http://rankmytweet.com uses this a lot.
trac(bug tracker) and moinmoin(wiki) are too web based python tools that I find invaluable.
GNU Mailman is another project written in python that is widely successful.
As many have pointed out, Django is a great reason to use Python...so in order to figure out why Python is great for web development, the best bet is to look at why it is a good language to build a framework like Django.
IMHO Python combines the cleanest, or at least one of the cleanest, metaprogramming models of any language with a very pure object orientation. This not only makes it possible to write extremely general abstractions that are easy to use, but also allows the abstractions to combine relatively cleanly with others. This is harder to do in languages that take a code-generation based approach to metaprogramming (e.g. Ruby).
Dynamic languages are in general good for web apps because the speed of development. Python in particular has two advantages over most of them:
"batteries included" means lots of available libraries
Django. For me this is the only reason why i use Python instead of Lua (which i like a lot more).
Besides the frameworks...
Python's pervasive support for Unicode should make i18n much smoother.
A sane namespace system makes debugging much nicer, because it's typically easier to find where things are defined.
Python's inability to function as a standalone templating language should discourage the mixture of HTML with model code
Great standard library
Other examples of Python sites are Reddit and YouTube.

Categories

Resources