This article, the second in a three-part series titled “GTK+ fundamentals,” introduces you to programming with GTK+. It analyzes a sample GTK+ application written in C, then shows that same application written in Python and C#. Finally, it discusses some useful tools that can help you develop better applications faster with GTK+.
I’ve always wanted to learn some GUI programming with GTK+. I’ve just never had the time to. Maybe reading this will spark my motivation.
Another decent (and more extensive) tutorial for using GTK+-2.0 can be found on GTK’s own site at http://www.gtk.org/tutorial/
If you want to learn GTK+ programming, and want to make it as easy as possible, you might consider http://gtk.php.net/ PHP-GTK.
I’ve used PHP 4/GTK 1.3 to write a large (80,000 line) application used to generate compliance paperwork for schools. It works well, and I can often edit the source code to a *running* program and see the result right away.
To hide the sources in distribution, I use ioncube encoder.
Why do GTK apps look so out-of-place in Windows?
Becuase they’re using a different toolkit. Now, let me ask you this, why do Apple apps look so out-of-place in Windows? With their Aqua scrollbars, and all.
Hmm … did I mention Apple? No, I’m pretty sure I didn’t.
Anyway, using a different toolkit is no excuse. QT Windows apps look fine. So again, why do GTK apps look so out-of-place?
Because GTK+ is a toolkit on its own, it does not use the Windows toolkit in any way to get the look copied (similar to what toolkits do on OSX, where they can use the “Appearance Manager” API). wxWidgets and Qt do that on both Windows and OSX and so they feel more native. GTK has chosen not to do so and relies on the abilities of a Windows-like theme to make the look similar to Windows’. But a flat out answer to your troll-baiting question is: it was a design decision from Day 1. And it was probably easier to implement it this way.
Easier? So what? Are the GTK devs lazy?
If it means the difference between a decent toolkit that looks good in an OS used on 90% of the world’s desktop computers, and a decent toolkit that looks out of place and causes some people to choose not to use GTK-based apps because of their appearance, then the choice is obvious.
Gtk is cross-platform because it is open source, so it can theoretically be ported to every platform. It is not cross-platform because this would be its primary purpose or anything. Most Gtk developers don’t even work on the Windows port, this is done by people who happen to be interested in this. Your flaming attempts just make you look silly and have nothing to do with this news story anyway.
That’s because porting to Windows (and probably from sometimes) is a nightmare.
Of course, if you can assume services for unix (hence the posix libraries) then it’d be easy; but that’s out of the question for most GTK applications.
If it means the difference between a decent toolkit that looks good in an OS used on 90% of the world’s desktop computers, and a decent toolkit that looks out of place and causes some people to choose not to use GTK-based apps because of their appearance, then the choice is obvious.
I think GTK apps like Inkscape look much nicer on Windows than native Windows apps. It is all in the eye of the beholder.
If I understand correctly, Qt doesn’t actually use Windows widgets, it uses XP’s style engine to draw the widgets ( http://doc.trolltech.com/4.0/qwindowsxpstyle.html#details ), which gives them a native look that follows the theme etc. That is, assuming you are using Qt’s XP theme.
But AFAICT, the same is true for GTK if you use GTK-Wimp ( http://gtk-wimp.sourceforge.net ).
So, is there a technical difference between what the Windows XP theme for Qt does and what GTK-Wimp does?
wxWidgets and Qt do that on both Windows and OSX and so they feel more native.
Qt does emulation which strikes a balance between native look and feel and maintainability, with the extremely complex differences you can get between supporting each platform natively. SWT has a lot of experience with this.
But a flat out answer to your troll-baiting question is: it was a design decision from Day 1. And it was probably easier to implement it this way.
That’s a bit of a problem for a cross-platform toolkit, isn’t it?
it’s about theme not the code!
>it’s about theme not the code!
You are wrong. It is about the code. GTK does not use Windows’ widgets directly like other ported toolkits do. It was easier for the developers to do it this way. A theme can only help the situation so much.
You don’t have to mention Apple. It was an example to counter your little theory that only GTK+ apps look out-of-place in Windows.
Every app looks out of place in Windows, Microsoft apps included (hint: WMP). QT apps look out of place as well, you just don’t take into account the fact that design-wise, KDE apps (which use Qt) are much closer to Windows than GNOME is.
Whoa whoa, don’t put words in my mouth. I didn’t say that ONLY GTK apps look out-of-place. That was your assumption.
And no, every app does not look out of place on Windows. Apple apps are even designed to look like Windows Luna/Classic, so that’s a moot point. Microsoft’s poor consistency with regards to Office/Media Player are something that I wish was corrected, but you can’t have everything.
GTK apps, on the other hand, DO attempt to look like Windows, but do it poorly.
Let’s name Windows programs that don’t maintain a default look and feel:
WMP
iTuns
MSN Messenger
GTK Programs
Trillian
Winamp
Opera!
(Firefox can, with skins, but blends in by default)
Microsoft isn’t out to have a completely thorough look and feel; and they haven’t gotten it. Spending valuable time trying to make it seem that way would be largely purposeless for gtk developers.
WIMP looks close enough to the default XP that most users who aren’t looking won’t notice. So, 90% of that 90% doesn’t care .
If you want a consistent look and feel you’re never going to get it from Redmond. They’re adding more power for developers to go toward per-application look and feel all the time. WPF is a huge step forward in this. Setting your own widget sizes, and even completely rewiring how things like list views look (the media center in vista, with the boxes, IIRC that’s a list view).
I know you don’t like it, but pretty non-standard looks sell to non-technical consumers. People who aren’t going to stare at their screen for 6 hours don’t mind different themes. It may not even be a bad idea, I imagine it could help people identify different programs more easily.
So, your different look complaint is completely bunk. I know a lot of people want a consistent look; but you aren’t going to get it from Redmond anymore.
Most “standard” applications look alike. Trillian, WMP, and iTunes are designed to appeal to a huge crowd of non-technical users, so I don’t expect to get consistency there.
But when it comes to other applications, like WinRAR, Notepad, QuickSFV, Explorer, and so on, they all follow the Windows Classic look. GTK apps also try to follow the Windows Classic look, but look out of place.
If you don’t like it, don’t use it. What’s your big problem?!
The big problem in windows is that the standard widget toolkit is quite not good enough for most uses. Microsoft themselves don’t use the native widgets in at least IE and Office: http://blogs.msdn.com/oldnewthing/archive/2005/02/11/371042.aspx
They do use the theming api to render them (just what QT does), but they still have to reimplement their behavior completly so that they work like the native controls.
Not good enough for most uses?
Care to provide evidence of that statement? IE is a special case and does not count as evidence of “most uses”.
Well, anything remotely complex if you don’t want to write by hand tons of stuff that would be taken care of by any remotely decent toolkit. I can’t provide you with specific examples other than stuff I worked on.
I’m talking about native win32 controls, just to be sure we’re on the same page.
Even for simple things, you can get better performances by using something else. I remember a small 3rd party application for the anarchy online game which was written using win32 controls. The code was uneccesarily complicated, the app was slow.
I rewrote it with a very simple gui toolkit that relied only on a few gdi calls to render its stuff and it was way faster.
I could also mention MFC, as I’m currently maintaining a big MFC application. It’s not pretty by any stretch of the imagination, and you have to do a lot of stupid tricks to work around the limitations.
Don’t even get me started on automatic layout, or rather the lack thereof.
By the way, counting IE a a special case is ridiculous. KHTML is not considered a special case in the KDE/Qt world, for instance.
If it is a special case, then it clearly means that the win32 toolkit doesn’t scale well for complex applications.
You forgot Office, by the way – It is mentioned by a microsoft guy in the comments of that blog I posted.
Is it a special case too ? Because by that logic we could consider every application to be special anyway.
I agree, IE is not a special case. You can access Trident from anywhere, even VB6 can control a Trident widget.
Gtk actually doesn’t have an html renderer, gtkhtml is still a seperate package. Although, TMK, it’s a proper GTK widget.
MORB, can you explain what you mean by “native win32” controls? Is this verse winforms? I don’t know a great deal about the currunt com-unistic state of Windows programming .
Uh, what you linked to did not talk about Office, but talked about IE, and how it *IS* a special case.
Rim shot?
In the comments.
Specifically, these two:
http://blogs.msdn.com/oldnewthing/archive/2005/02/11/371042.aspx#37…
http://blogs.msdn.com/oldnewthing/archive/2005/02/11/371042.aspx#37…
You don’t link to an article as a way of proving your point when the actual content in question is a comment left by a user.
And no, every app does not look out of place on Windows. Apple apps are even designed to look like Windows Luna/Classic, so that’s a moot point. Microsoft’s poor consistency with regards to Office/Media Player are something that I wish was corrected, but you can’t have everything.
I agree. Only 99.9% apps on Windows look out of space. Calculator and Notepad follow HIG as they should.
Then again why does my OSX look like a color palette without any taste in colors? 5 different toolkits. Counting only Apple ones. Counting others. Wow. My desktop looks almost like average vegetable soup.
Again why do Windows.Forms look different than basic common controls? And why isn’t fancy look working trough all WinXP and all applications.
So here on WinXP desktop I have for example WinXP, Firefox, Thunderbird, AVG, WMP, Pinacle burning software, MSN, Office 2003, Eclipse, Photoshop. Not even two of them are consistant (except Firefox and Thunderbird). Hell would probably froze if at least half of apps would support even basic Window Color.
GTK apps, on the other hand, DO attempt to look like Windows, but do it poorly.
WRONG!!!!
Talking about Wimp or Gtk here? Wimp is separate project that tries to do what you say. Gtk isn’t. Read the fine print and then try to be funny.
http://gtk-wimp.sourceforge.net/
GTK-Wimp (“Windows impersonator”) is a GTK+ theme that integrates well with the Microsoft Windows desktop environment. GTK-Wimp was created by Raymond Penners, based upon code from Redmond95 by Owen Taylor and Nativewin by Evan Martin. It is now maintained by Dominic Lachowicz.
http://gtk.org/
GTK+ is a multi-platform toolkit for creating graphical user interfaces. Offering a complete set of widgets, GTK+ is suitable for projects ranging from small one-off projects to complete application suites.
Have you ever looked at yourself at all? Please look at the mirror now! You will finally notice … that.. actually… you are the poo itself! You look so out-of-place among us. Why is that? Do troll NO MORE. It makes you not-respectful/worthless person in this society.
Back to the topic, It seems the programming in GTK+ easier than I thought after quick look at the article. However, for this kind of development, I feel like OOP makes much more sense than non-OOP.
Back to the topic, It seems the programming in GTK+ easier than I thought after quick look at the article. However, for this kind of development, I feel like OOP makes much more sense than non-OOP.
It is OOP, the C-syntax just makes it look awkward. As the article shows, you can easily use Gtk with an object oriented language like Python or C# (and C++ of course).
Because they neglected to deliever the WIMP theme with their GTK+ runtimes.
Once that’s been accomplished, GTK+ apps don’t look out of place on Windows–they only *feel* out of place.
i like GTK on linux or win… better than java and that ugly stuff….
well QT still has some licensing issues on windows and I had a lot of problem getting it setup and working along with pyQT due to the different versions… There is a unofficial FREE winQT port and and a official NC (non commercial) port but none seem to like the pyQT I was trying to use to build some pyQT apps…
I find gtk to be simple and have no problems on either platform…
A GPL version of Qt4 is available for every platform (including Windows) at this page: http://www.trolltech.com/download/opensource.html
If the GPL isn’t good enough, then you have to pay. But it should be good enough for open-source, and if you don’t want to write open-source (e.g. you want your users to pay) I don’t see why you shouldn’t expect to pay yourself.
PyQt hasn’t caught up with Qt4 yet, but when it does no-one will have any troubles. Until then, you can still use C++.
Personally I find Qt to be a lot easier than GTK. It’s important not to confuse “licensing issues” with actual development.
yea i think I mentioned that….
So you do a lot of QT and in particular pyQT developing on windows and have no troubles?
Please give me a step by step of your setup and let me know which python you use, which QT and which pyQT I would be very interested. When I do it my QT NC version always looks for the NC pyQT matchign version or some such and then it seems to overlook my python2.4 install and so forth…
Oh, I am mostly just trying to get some apps compiled and am having lots of problems…in fact I gave up!
Come on get real. GTK apps don’t stick out that much in Windows. I installed Gimp2 on all our labs windows xp boxes and nobody has said anything about how it looks. They are just happy to be able to edit their photos for free. Not everything has to have gel buttons on it or brushed metal to make it work well.
Edited 2006-01-12 03:43
For the look, yeah. WIMP does a great job. As for the feel… For example, the Save dialog is completely foreign. The redraw speed isn’t typical of the other applications, either.
Of course, it doesn’t remove its merits nor its usefulness. The possibility of using a powerful application for manipulating your pictures at no charge is nothing to sneeze at. Still, it doesn’t feel completely at home. That said, it would probably need a new UI just for Windows and I don’t believe the port maintainers are interested…
Agreed. With the WMP theme, gtk+ on windows looks pretty good. At least it uses native fonts, unlike the still butt-ugly Swing.
Agreed. With the WMP theme, gtk+ on windows looks pretty good. At least it uses native fonts, unlike the still butt-ugly Swing.
Yeah – though in the win port of Gnumeric you can choose if you want the WMP or GTK theme, I prefer it with the GTK look. But I guess that’s the way I am used to seeing it.
The Swing fonts look worst on Linux/GTK especially with that disgusting parody of a GTK theme (I switch it back to metal if I can). Thank god for SWT, it gets the fonts right on both Windows and GTK and looks nice on both.
well poo, more often then not I disagree with you, however on this issue, I do agree with you, gtk apps look horrable in windows, I’ve run gaim and gimp in windows in the past and it looks nasty, I don’t care because I haven’t run Windows in quite some time on any of my machines but most people do run windows and they do care.
I’ll be honest, I tend to lean towards qt for a lot of things but this is not why I say these things about gtk, I try to be very objective, and from my point of view gtk does not fit well into the windows api.
PyQt hasn’t caught up with Qt4 yet, but when it does no-one will have any troubles. Until then, you can still use C++.
But it’s getting there, while I was reading your post this message appeared on the PyQt mailinglist:-)
“You can find a binary package of a current snapshot of PyQt4 GPL for Windows
at http://www.riverbankcomputing.com/Downloads/PyQt4/“
Ah common, and look closer, notepad, winrar, winzip, powerarchiver, office, outlook look definitely not the same. Each of these apps have different toolbars, different size of icons, different menus, some are flat some are more 3D. On my win2000 machine, some apps have xp style menus, some don’t, some apps use the File, Edit, View .. Help menu system some don’t. Sometimes the difference between a VC app and a delphi app is far greater then notepad <-> gtk / Qt app.
I think that the bigger problem here is not how apps LOOK like but that they all WORK in a different way. Most gtk+ programs have a connection to gnome, which WORKS a *little* different than windows.
You forgot the apps that have colored icons by default, and those that appear gray and are colored when you point your mouse other them. There are so much examples.
Windows users that talk about inconsistency in other OS than Windows are zealots : the pot that call the kettle black. Everyone of them with some sense admit it, even on this thread, but they are quick to find excuses and dismiss what they found so important seconds before : talk about hypocrisis.
Currently, I have to use 2 Windows OS at work (NT4 and XP SP2), and you can bet no app look the same, and I have Wordpad, Outlook, Firefox and Explorer opened !!! Fonts are different, widgets are different, behaviour is different, size and design of icons are different, … And they dare talk about consistency !! On the XP SP2 it’s even worse.
I think that the bigger problem here is not how apps LOOK like but that they all WORK in a different way. Most gtk+ programs have a connection to gnome, which WORKS a *little* different than windows
The major problem is Windows zealots actually.
You say Gnome works a little different than Windows, I say it works a LOT different.
Gnome apps are consistent, Gnome apps are integrated, Gnome apps work right (well sort of), Windows apps don’t.
There still are basic things that don’t work on Windows : the application bar (which for example, shrinks itself at each reboot when in vertical position, or does not disappear automatically sometimes), the multi file selection (order still wrong when you paste), the install/remove that does not work, … The inconsistent things have been listed already.
I have other examples of how Gnome works a lot different : simple click is usable, files copied have their size updated in real time, theme is consistent not per app, session works, input methods are consistent, virtual desktops works, multisession exists and is powerful, email clients never infect you, …
Windows power users should stop these Windows zealots that give a bad reputation to their OS (there I said it).
These complaints were true, but as soon as Gnome 2.0 came out (with pango, gobject, gconf, gnome-vfs, …) to address all of these, the complaints should have stopped, cause at least Gnome devs tried to do sth about these problems. MS did not do that for Windows till then, but you never hear a complaint from the zealot.
I would like to point out that the average user just flat out doesnt care if an application looks different.
Take Limewire for instance. I have asked MANY people if the different color scheme and controls bother them and most people didnt even pay attention/notice it till i brought it up. THe rest simply didnt care.
If the app is easy to use, the look and feel (at the trivial color scheme and button style) is absolutely the lease important factor for the average user.
Basically when these discussion arise it just shows that the average geek is long out of touch with the average USER.
I would like to point out that the average user just flat out doesnt care if an application looks different
That’s my experience too. Actually, I never saw a user complain about that, except Windows zealots of course.
If the app is easy to use, the look and feel is absolutely the lease important factor for the average user
I’d go as far as saying even if the app is not easy to use, people will use the app without complaining, especially if that’s all they know about/can afford. I used to do fansubs on Windows, and had to battle through a lot of hard to use apps and the crappy OS to get something done, but I never complained about inconsistency, I was at least getting work done, and that’s what count.
Basically when these discussion arise it just shows that the average geek is long out of touch with the average USER
I don’t think so, I think Windows zealots are out of touch. It has been showed time and again that geeks don’t mind these things. Gnome 1.0 was heavily criticised as a geek desktop because of that.
“I would like to point out that the average user just flat out doesnt care if an application looks different.”
I’d agree, but make an exception for the gimp. Aside from the internet, I’ve never met a person who didn’t have to overcome an initial revulsion at its gui. I’m not trying to overstate the case either. Most artists I’ve shown it too really were right next to the point of cringing when I showed it to them.
Not really trying to put down the gimp, so much as just state amazement at how a single program can break so many expectations.
The gtkembedded object from Mozilla gives your gtk program the most 3wc compliant browser there is for you to easily hook to your hardware events, a whole big can of whoop-ass for embedded linux. I easily created browser javascript function hooks for a mag card reader and bar code scanner with it, endless possibilities available. GTK+ rocks.