https://wiki.archlinux.org/api.php?action=feedcontributions&user=Zshang&feedformat=atomArchWiki - User contributions [en]2024-03-29T15:25:48ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=GTK&diff=336307GTK2014-09-20T03:55:11Z<p>Zshang: the return type of main function in C should be int instead of void</p>
<hr />
<div>[[Category:Widget Toolkits]]<br />
[[cs:GTK+]]<br />
[[de:GTK+]]<br />
[[es:Improve GTK Application Looks]]<br />
[[it:GTK+]]<br />
[[ja:GTK+]]<br />
[[uk:GTK+]]<br />
[[zh-CN:GTK+]]<br />
{{Related articles start}}<br />
{{Related|Uniform Look for Qt and GTK Applications}}<br />
{{Related|Qt}}<br />
{{Related|GNU Project}}<br />
{{Related articles end}}<br />
From the [http://www.gtk.org GTK+ website]:<br />
:''GTK+, or the GIMP Toolkit, 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 tools to complete application suites.''<br />
<br />
GTK+, The GIMP Toolkit, was initially made by the [[GNU Project]] for the [[GIMP]] but is now a very popular toolkit with bindings for many languages. This article will explore the tools used to configure the GTK+ theme, style, icon, font and font size, and also detail manual configuration.<br />
<br />
== Configuration programs ==<br />
<br />
These GUI programs allow theme selection and at least customising of a font. They generally overwrite the {{ic|~/.gtkrc-2.0}} file.<br />
<br />
* {{Pkg|lxappearance}}: A configuration tool from the [[LXDE]] project, which does not require any other parts of LXDE or other desktop environment. More flexible customisation than the other programs.<br />
* {{Pkg|gtk-chtheme}}<br />
* {{Pkg|gtk-theme-switch2}}<br />
* {{Pkg|gtk2_prefs}}<br />
<br />
{{Note|As {{ic|~/.gtkrc-2.0}} and other user theme files are not read by other accounts, the custom theme will not apply to [[Running_X_apps_as_root|X applications run as root]]. Possible solutions include:<br />
* Create symlinks, e.g<br />
# ln -s /home/USER/.gtkrc-2.0 /root/.gtkrc-2.0<br />
* Adjust the theme as root<br />
# gksu lxappearance<br />
* Use a settings daemon (this is what most desktop environments do). A desktop-agnostic variant using [http://standards.freedesktop.org/xsettings-spec/xsettings-spec-0.5.html XSETTINGS] is available in the [[AUR]] under {{aur|xsettingsd-git}}.<br />
}}<br />
<br />
See also [[Uniform Look for Qt and GTK Applications#Changing styles in each toolkit]].<br />
<br />
== Themes ==<br />
<br />
=== GTK+ 1.x ===<br />
<br />
There are loads of GTK+ 1.x themes in the [[AUR]]: [https://aur.archlinux.org/packages.php?K=gtk-theme search for gtk-theme]. A good start is {{AUR|gtk-smooth-engine}}.<br />
<br />
Most major [[Desktop environment|desktop environments]] provide tools to configure the GTK+ theme, icons, font and font size.<br />
<br />
Alternatively, use {{Pkg|gtk-theme-switch2}}. Run it with the {{ic|switch}} command.<br />
<br />
=== GTK+ 2.x ===<br />
<br />
There are loads of GTK+ 2.x themes in the [[AUR]]: [https://aur.archlinux.org/packages.php?K=gtk2-theme search for gtk2-theme]. A good start is {{Pkg|gtk-engines}} which includes the popular ''Clearlooks'' theme.<br />
<br />
Most major [[Desktop environment|desktop environments]] provide tools to configure the GTK+ theme, icons, font and font size.<br />
<br />
Alternatively, GTK+ settings can be configured manually by editing {{ic|~/.gtkrc-2.0}}. A list of GTK+ settings can be found in the [http://library.gnome.org/devel/gtk/stable/GtkSettings.html GNOME library]. To manually change the GTK+ theme, icons, font and font size, add the following to {{ic|~/.gtkrc-2.0}}:<br />
<br />
{{hc|~/.gtkrc-2.0|2=<br />
gtk-icon-theme-name = "[name-of-icon-theme]"<br />
gtk-theme-name = "[name-of-theme]"<br />
gtk-font-name = "[font-name] [size]"<br />
}}<br />
<br />
For example:<br />
<br />
{{hc|~/.gtkrc-2.0|2=<br />
gtk-icon-theme-name = "Tango"<br />
gtk-theme-name = "Murrine-Gray"<br />
gtk-font-name = "DejaVu Sans 8"<br />
}}<br />
<br />
{{Note|The above example requires the packages {{Pkg|ttf-dejavu}}, {{Pkg|tangerine-icon-theme}}, {{Pkg|gtk-engine-murrine}} from the [[official repositories]], and {{AUR|gtk-theme-murrine-collection}} from the AUR.}}<br />
<br />
Another example:<br />
<br />
{{hc|~/.gtkrc-2.0|2=<br />
# GTK theme<br />
include "/usr/share/themes/Clearlooks/gtk-2.0/gtkrc"<br />
<br />
# Font<br />
style "myfont" {<br />
font_name = "DejaVu Sans 8"<br />
}<br />
widget_class "*" style "myfont"<br />
gtk-font-name = "DejaVu Sans 8"<br />
<br />
# Icon theme<br />
gtk-icon-theme-name = "Tango"<br />
<br />
# Toolbar style<br />
gtk-toolbar-style = GTK_TOOLBAR_ICONS<br />
}}<br />
<br />
{{Note|<br />
* The icon theme name is the name defined in the theme's index file, ''not'' the name of its directory.<br />
* Valid toolbar styles are {{ic|GTK_TOOLBAR_ICONS}}, {{ic|GTK_TOOLBAR_TEXT}}, {{ic|GTK_TOOLBAR_BOTH}}, and {{ic|GTK_TOOLBAR_BOTH_HORIZ}}.<br />
* If you edit your {{ic|.gtkrc-2.0}} file, only newly started applications will display the changes.<br />
}}<br />
<br />
=== GTK+ 3.x ===<br />
<br />
A good start is {{Pkg|gnome-themes-standard}} which includes the popular ''Adwaita'' theme.<br />
<br />
If selected style has both GTK+ 2.x and GTK+ 3.x themes, they will be used. If selected style has only GTK+ 2.x theme, it will be used for GTK+ 2.x applications and (ugly) defaults will be used for GTK+ 3.x applications. If selected style has only GTK+ 3.x theme, it will be used for GTK+ 3.x applications and (ugly) defaults will be used for GTK+ 2.x applications. Thus for uniform UI appearance and best experience one can use style that has both GTK+ 2.x and GTK+ 3.x themes.<br />
<br />
Most major [[Desktop environment|desktop environments]] provide tools to configure the GTK+ theme, icons, font and font size. If you use [[GNOME]], use GNOME Tweak Tool: install {{Pkg|gnome-tweak-tool}}. If you use [[Xfce]], use the Appearance tool: go to ''Settings > Appearance''. <br />
<br />
An alternative without huge dependencies is {{Pkg|lxappearance}}.<br />
<br />
If you prefer not to install a theme manager at all, your theme can be set manually in {{ic|$XDG_CONFIG_HOME/gtk-3.0/settings.ini}} (this is usually {{ic|~/.config/gtk-3.0/settings.ini}}). An example {{ic|settings.ini}} file:<br />
{{hc|$XDG_CONFIG_HOME/gtk-3.0/settings.ini|2=<br />
[Settings]<br />
gtk-application-prefer-dark-theme = false<br />
gtk-theme-name = Zukitwo<br />
gtk-fallback-icon-theme = gnome<br />
gtk-icon-theme-name = [icon theme name]<br />
gtk-font-name = [font name] [font size]<br />
<br />
}}<br />
<br />
A full example of a custom theme as converted from GTK+ 2.x to GTK+ 3.x by {{Pkg|lxappearance}}:<br />
<br />
{{hc|$XDG_CONFIG_HOME/gtk-3.0/settings.ini|2=<br />
[Settings] <br />
gtk-theme-name=TraditionalOk<br />
gtk-icon-theme-name=Fog<br />
gtk-font-name=Luxi Sans 12<br />
gtk-cursor-theme-name=mate<br />
gtk-cursor-theme-size=24<br />
gtk-toolbar-style=GTK_TOOLBAR_BOTH_HORIZ<br />
gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR<br />
gtk-button-images=1<br />
gtk-menu-images=1<br />
gtk-enable-event-sounds=0<br />
gtk-enable-input-feedback-sounds=0<br />
gtk-xft-antialias=1<br />
gtk-xft-hinting=1<br />
gtk-xft-hintstyle=hintslight<br />
gtk-xft-rgba=rgb<br />
}}<br />
<br />
If it still does not change, delete old {{ic|gtk-3.0}} folder in {{ic|$XDG_CONFIG_HOME}} and copy {{ic|gtk-3.0}} folder from /path/to/theme to {{ic|$XDG_CONFIG_HOME}}. Example: <br />
<br />
$ rm -r ~/.config/gtk-3.0/<br />
$ cp -r /usr/share/themes/Zukitwo/gtk-3.0/ ~/.config/ <br />
<br />
<br />
After this, you need to set the same theme in your DE's appearance configuration tool. There are only a few themes which provide a uniform look for GTK+ 3.x and GTK+ 2.x apps. A few examples:<br />
#Adwaita (part of {{Pkg|gnome-themes-standard}})<br />
#Clearlooks-Phenix (AUR: {{AUR|clearlooks-phenix-gtk-theme}})<br />
#Newlooks for GTK+ 3 and Clearlooks for GTK+ 2<br />
#Zukitwo ({{Aur|zukitwo-themes}})<br />
#Elegant Brit<br />
#Atolm<br />
#Hope<br />
#OMG<br />
<br />
{{Note|<br />
* Some themes may require {{Pkg|librsvg}} to display correctly, but not all specify it as a dependency. Try installing it if the chosen theme looks broken.<br />
* There probably are other themes. Some of these themes are available in the AUR. Also, some of them are not usable as-is for displaying a GTK+ 2.x panel (light text over light background), so you need to use the provided [http://i.imgur.com/QmeyN.png panel background].<br />
}}<br />
<br />
You could find what themes installed on your system have both an GTK+ 2.x and GTK+ 3.x version by using this command (does not work with names containing spaces):<br />
find $(find ~/.themes /usr/share/themes/ -wholename "*/gtk-3.0" | sed -e "s/^\(.*\)\/gtk-3.0$/\1/")\<br />
-wholename "*/gtk-2.0" | sed -e "s/.*\/\(.*\)\/gtk-2.0/\1"/<br />
<br />
=== GTK+ and Qt ===<br />
<br />
If you have GTK+ and Qt (KDE) applications on your desktop then you know that their looks do not blend well. If you wish to make your GTK+ styles match your Qt styles please read [[Uniform Look for Qt and GTK Applications]].<br />
<br />
=== GTK+ and HTML with Broadway ===<br />
The GDK Broadway backend provides support for displaying GTK+ applications in a web browser, using HTML5 and web sockets. <br />
[https://developer.gnome.org/gtk3/3.8/gtk-broadway.html]<br />
<br />
When using broadwayd, specify the display number to use, prefixed with a colon, similar to X. The default display number is 1.<br />
<br />
$ display_number&#61;:5<br />
Start it.<br />
$ broadwayd $display_number <br />
<br />
Port Used on default<br />
port &#61; 8080 + ($display_number - 1)<br />
<br />
Point your browser to http://localhost:port<br />
<br />
To Start apps<br />
<br />
$ GDK_BACKEND&#61;broadway BROADWAY_DISPLAY&#61;$display_number ''<<app>>''<br />
<br />
Alternatively can set address and port<br />
<br />
$ broadwayd --port $port_number --address $address $display_number<br />
<br />
== Configuration file ==<br />
<br />
{{Note|See the [http://library.gnome.org/devel/gtk/stable/GtkSettings.html#GtkSettings.properties ''GtkSettings'' properties] in the GTK+ programming reference manual for the full list of GTK configuration options.}}<br />
<br />
The purpose of this section is to collect GTK+ configuration settings which can e.g. be used within one's GTK+ configuration files.<br />
<br />
There are two relevant locations for GTK+ configuration files (which are in an ini format) : $XDG_CONFIG_HOME/gtk-3.0/ (usually ~/.config/gtk-3.0/) and /etc/gtk-3.0/. The former is reserved for user wide settings, and the latter for system wide settings. <br />
<br />
=== Enabling Customizable Keyboard Shortcuts ===<br />
<br />
You can customize your GTK+ applications' keyboard shortcuts (those are called ''accelerators'' in GTK+ terminology) by hovering your mouse over a menu item and pressing your desired key combination. However, this feature is disabled by default. To enable it, set <br />
gtk-can-change-accels = 1<br />
<br />
=== Speed up your GNOME menu ===<br />
<br />
This setting controls the delay between you pointing the mouse at a menu and that menu opening in GNOME. Change this to a setting you prefer. I guess the number is in milliseconds, e.g. 250 being a quarter of a second.<br />
gtk-menu-popup-delay = 0<br />
<br />
=== Reduce widget sizes ===<br />
<br />
If you have a small screen or you just do not like big icons and widgets, you can resize things easily. <br />
To have icons without text in toolbars, use<br />
gtk-toolbar-style = GTK_TOOLBAR_ICONS<br />
To use smaller icons, use a line like this:<br />
gtk-icon-sizes = "panel-menu=16,16:panel=16,16:gtk-menu=16,16:gtk-large-toolbar=16,16\<br />
:gtk-small-toolbar=16,16:gtk-button=16,16"<br />
Or to remove icons from buttons completely:<br />
gtk-button-images = 0<br />
You can also remove icons from menus:<br />
gtk-menu-images = 0<br />
<br />
There is some more tweaking to do in your themes gtkrc like explained [http://martin.ankerl.com/2008/10/10/how-to-make-a-compact-gnome-theme/ here] and there's another [http://gnome-look.org/content/show.php/Simple+eGTK?content=119812 theme] that does it all.<br />
<br />
== Troubleshooting ==<br />
<br />
=== Client-side decorations ===<br />
<br />
GTK 3.12 introduced [http://blogs.gnome.org/mclasen/2013/12/05/client-side-decorations-in-themes/ client-side decorations], which move the title-bar away from the window manager. This only works correctly in [[GNOME]]. Other environments may suffer from [http://redmine.audacious-media-player.org/boards/1/topics/1135 double title-bars] or no title-bar at all. Some [[Xorg#List_of_composite_managers|composite managers]] also [https://github.com/chjj/compton/issues/189 conflict].<br />
<br />
{{AUR|gtk3-noforcedcsd}} from the [[AUR]] disables client-side decorations through the {{ic|GTK_DISABLE_CSD}} variable.<br />
<br />
=== Enable cedilla ç/Ç instead of ć/Ć ===<br />
<br />
When you select the keyboard layout "U.S., alternative international" in Settings --> Keyboard --> Layout to enable accents, the typical combination for the cedilla ' + c results in ć instead of ç.<br />
<br />
To change this suffice edit files gtk.immodules for gtk-2.0 and immodules.cache for gtk-3.0 in line that contains "cedilla" adding both "en" in the list "az:ca:co:fr:gv:oc:pt:sq:tr:wa" but in alphabetical order, staying that way in /etc/gtk-2.0/gtk.immodules<br />
<br />
"/usr/lib/gtk-2.0/2.10.0/immodules/im-cedilla.so"<br />
"cedilla" "Cedilla" "gtk20" "/usr/share/locale" "az:ca:co:en:fr:gv:oc:pt:sq:tr:wa"<br />
<br />
and this in /usr/lib/gtk-3.0/3.0.0/immodules.cache<br />
<br />
"/usr/lib/gtk-3.0/3.0.0/immodules/im-cedilla.so"<br />
"cedilla" "Cedilla" "gtk30" "/usr/share/locale" "az:ca:co:en:fr:gv:oc:pt:sq:tr:wa"<br />
<br />
Then, do<br />
<br />
# echo "export GTK_IM_MODULE=cedilla" >> /etc/environment<br />
<br />
Done. Simply just close and reopen the gtk programs like gedit.<br />
<br />
== Development ==<br />
<br />
When writing a start-from-scratch GTK+ 3 program with C, it's necessary to add CFLAGS for ''gcc'':<br />
$ gcc -g -Wall $(pkg-config --cflags --libs gtk+-3.0) -o base base.c<br />
-g and -Wall parameters are not necessary since they are only for verbose debugging outputs.<br />
You may try out the official [http://developer.gnome.org/gtk-tutorial/stable/c39.html#SEC-HELLOWORLD Hello World example].<br />
<br />
=== Write a simple message dialog app ===<br />
<br />
You can write your own GTK+ 3 message dialog easily in many programming languages through GObject-Introspection or bindings, or you can simply use bash.<br />
<br />
The following examples display a simple "Hello world" in a message dialog.<br />
<br />
'''Ada'''<br />
<br />
* Dependency: {{AUR|gtkada}} from AUR<br />
* Makedependency: {{Pkg|gcc-ada}}<br />
* Build with: {{ic|gnatmake hello_world `gtkada-config`}}<br />
<br />
{{hc|hello_world.adb|2=<br />
with Gtk.Main;<br />
with Gtk.Dialog; use Gtk.Dialog;<br />
with Gtk.Message_Dialog; use Gtk.Message_Dialog;<br />
<br />
procedure hello_world is<br />
Dialog : Gtk_Message_Dialog;<br />
Response : Gtk_Response_Type;<br />
begin<br />
Gtk.Main.Init;<br />
Gtk_New (Dialog => Dialog,<br />
Parent => null,<br />
Flags => 0,<br />
The_Type => Message_Info,<br />
Buttons => Buttons_OK,<br />
Message => "Hello world!");<br />
Format_Secondary_Markup (Dialog, "This is an example dialog.");<br />
Response := Run (Dialog);<br />
end hello_world;<br />
}}<br />
<br />
'''Bash'''<br />
<br />
* Dependency: {{Pkg|zenity}}<br />
{{hc|hello_world.sh|2=<br />
#!/bin/bash<br />
zenity --info --title='Hello world!' --text='This is an example dialog.'<br />
}}<br />
<br />
'''Boo'''<br />
<br />
* Dependency: {{Pkg|gtk-sharp-3}} (and {{Pkg|boo}})<br />
* Makedependency: {{Pkg|boo}}<br />
* Build with: {{ic|booc hello_world.boo}}<br />
* Run with: {{ic|mono hello_world.exe}} (or {{ic|booi hello_world.boo}})<br />
<br />
{{hc|hello_world.boo|2=<br />
import Gtk from "gtk-sharp"<br />
Application.Init()<br />
Hello = MessageDialog(null, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, "Hello world!")<br />
Hello.SecondaryText = "This is an example dialog."<br />
Hello.Run()<br />
}}<br />
<br />
'''C'''<br />
<br />
* Dependency: {{Pkg|gtk3}}<br />
* Build with: {{ic|gcc -o hello_world $(pkg-config --cflags --libs gtk+-3.0) hello_world.c}}<br />
{{hc|hello_world.c|2=<br />
#include <gtk/gtk.h><br />
int main (int argc, char *argv[]) {<br />
gtk_init (&argc, &argv);<br />
GtkWidget *hello = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Hello world!");<br />
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (hello), "This is an example dialog.");<br />
gtk_dialog_run(GTK_DIALOG (hello));<br />
return 0;<br />
}<br />
}}<br />
<br />
'''C++'''<br />
<br />
* Dependency: {{Pkg|gtkmm3}}<br />
* Build with: {{ic|g++ -o hello_world $(pkg-config --cflags --libs gtkmm-3.0) hello_world.cc}}<br />
{{hc|hello_world.cc|2=<br />
#include <gtkmm/main.h><br />
#include <gtkmm/messagedialog.h><br />
int main(int argc, char *argv[]) {<br />
Gtk::Main kit(argc, argv);<br />
Gtk::MessageDialog Hello("Hello world!", false, Gtk::MESSAGE_INFO, Gtk::BUTTONS_OK);<br />
Hello.set_secondary_text("This is an example dialog.");<br />
Hello.run();<br />
}<br />
}}<br />
<br />
'''C#'''<br />
<br />
* Dependency: {{Pkg|gtk-sharp-3}}<br />
* Build with: {{ic|mcs -pkg:gtk-sharp-3.0 hello_world.cs}}<br />
* Run with: {{ic|mono hello_world.exe}}<br />
{{hc|hello_world.cs|2=<br />
using Gtk;<br />
public class HelloWorld {<br />
static void Main() {<br />
Application.Init ();<br />
MessageDialog Hello = new MessageDialog (null, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, "Hello world!");<br />
Hello.SecondaryText="This is an example dialog.";<br />
Hello.Run ();<br />
}<br />
}<br />
}}<br />
<br />
'''Cobra'''<br />
<br />
* Dependency: {{Pkg|gtk-sharp-3}}<br />
* Makedependency: {{AUR|cobra}} from AUR<br />
* Build with: {{ic|cobra -c hello_world}}<br />
* Run with: {{ic|mono hello_world.exe}}<br />
{{hc|hello_world.cobra|2=<br />
@args -pkg:gtk-sharp-3.0<br />
use Gtk<br />
<br />
class HelloWorld<br />
def main<br />
Application.init<br />
hello = MessageDialog(nil, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, "Hello world!")<br />
hello.secondaryText = "This is an example dialog."<br />
hello.run<br />
}}<br />
<br />
'''D'''<br />
<br />
* Dependency: {{AUR|gtkd}} from AUR<br />
* Makedependency: {{Pkg|dmd}}<br />
* Build with: {{ic|dmd hello_world $(pkg-config --cflags --libs gtkd-2)}}<br />
{{hc|hello_world.d|2=<br />
import gtk.Main;<br />
import gtk.MessageDialog;<br />
<br />
void main(string[] args)<br />
{<br />
Main.init(args);<br />
MessageDialog dialog = new MessageDialog(null, GtkDialogFlags.MODAL, MessageType.INFO, ButtonsType.OK, "Hello world!");<br />
dialog.run();<br />
}<br />
}}<br />
<br />
'''F#'''<br />
<br />
* Dependency: {{Pkg|gtk-sharp-3}}<br />
* Makedependency: {{AUR|fsharp}} from AUR<br />
* Build with: {{ic|fsharpc -r:gtk-sharp.dll -I:/usr/lib/mono/gtk-sharp-3.0/}}<br />
* Run with: {{ic|mono hello_world.exe}}<br />
<br />
{{hc|hello_world.fs|<nowiki><br />
open Gtk<br />
Application.Init()<br />
let Hello = new MessageDialog(null, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, "Hello world!")<br />
Hello.SecondaryText <- "This is an example dialog."<br />
Hello.Run() |> ignore<br />
</nowiki>}}<br />
<br />
'''Fortran'''<br />
<br />
* Dependency: {{AUR|gtk-3-fortran-git}} from AUR<br />
* Makedependency: {{Pkg|gcc-fortran}}<br />
* Build with: {{ic|gfortran hello_world.f90 -o hello_world $(pkg-config --cflags --libs gtk-3-fortran)}}<br />
<br />
{{hc|hello_world.f90|<nowiki><br />
program hello_world<br />
use gtk_hl<br />
use gtk, only: gtk_init<br />
<br />
integer(c_int) :: resp<br />
character(40), dimension(2) :: msg<br />
<br />
call gtk_init()<br />
msg(1) ="Hello world!"<br />
msg(2) = "This is an example dialog."<br />
resp = hl_gtk_message_dialog_show(msg, GTK_BUTTONS_OK, type=GTK_MESSAGE_INFO)<br />
end program hello_world<br />
</nowiki>}}<br />
<br />
'''Genie'''<br />
<br />
* Dependency: {{Pkg|gtk3}}<br />
* Makedependency: {{Pkg|vala}}<br />
* Build with: {{ic|valac --pkg gtk+-3.0 hello_world.gs}}<br />
{{hc|hello_world.gs|2=<br />
uses <br />
Gtk<br />
init<br />
Gtk.init (ref args)<br />
var Hello=new MessageDialog (null, Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "Hello world!")<br />
Hello.format_secondary_text ("This is an example dialog.")<br />
Hello.run ()<br />
}}<br />
<br />
'''Go'''<br />
<br />
* Dependency: {{Pkg|gtk3}}<br />
* Makedependency: {{AUR|gotk3-git}} from AUR<br />
* Build with: {{ic|go build hello_world.go}}<br />
* (Or run with: {{ic|go run hello_world.go}})<br />
<br />
{{hc|hello_world.go|2=<br />
package main<br />
import ("github.com/conformal/gotk3/gtk")<br />
<br />
func main() {<br />
gtk.Init(nil)<br />
dialog := gtk.MessageDialogNew(nil, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, "Hello world!")<br />
dialog.FormatSecondaryText("This is an example notification.")<br />
dialog.Run()<br />
}<br />
}}<br />
<br />
'''Groovy'''<br />
<br />
* Dependencies: {{Pkg|groovy}}, {{AUR|java-gnome}} from AUR<br />
* Build with: {{ic|groovyc -cp /usr/share/java/gtk.jar HelloWorld.groovy && jar cfe HelloWorld.jar HelloWorld HelloWorld.class}}<br />
* Run with: {{ic|java -cp /usr/share/groovy/embeddable/groovy-all.jar:/usr/share/java/gtk.jar:HelloWorld.jar HelloWorld}} (or {{ic|groovy -cp /usr/share/java/gtk.jar HelloWorld.groovy}})<br />
<br />
{{hc|HelloWorld.groovy|2=<br />
import org.gnome.gtk.*<br />
Gtk.init()<br />
def Hello = new InfoMessageDialog(null, "Hello world!", "This is an example dialog.")<br />
Hello.run()<br />
}}<br />
<br />
'''Haskell'''<br />
<br />
* Dependency: {{Pkg|gtk3}}<br />
* Makedependency: {{AUR|haskell-gtk3}} from AUR<br />
* Build with: {{ic|ghc hello_world}}<br />
{{hc|hello_world.hs|2=<br />
import Graphics.UI.Gtk<br />
<br />
main = do<br />
initGUI<br />
dialog <- messageDialogNew Nothing [DialogModal] MessageInfo ButtonsOk "Hello world!"<br />
messageDialogSetSecondaryText dialog "This is an example dialog."<br />
_res <- dialogRun dialog<br />
return 0<br />
}}<br />
<br />
'''Java'''<br />
<br />
* Dependency: {{AUR|java-gnome}} from AUR<br />
* Makedependency: java-environment<br />
* Build with: {{ic|javac -cp /usr/share/java/gtk.jar HelloWorld.java && jar cfe HelloWorld.jar HelloWorld HelloWorld.class}}<br />
* Run with: {{ic|java -cp /usr/share/java/gtk.jar:HelloWorld.jar HelloWorld}}<br />
<br />
{{hc|HelloWorld.java|2=<br />
import org.gnome.gtk.Gtk;<br />
import org.gnome.gtk.Dialog;<br />
import org.gnome.gtk.InfoMessageDialog;<br />
<br />
public class HelloWorld {<br />
public static void main(String[] args) {<br />
Gtk.init(args);<br />
Dialog Hello = new InfoMessageDialog(null, "Hello world!", "This is an example dialog.");<br />
Hello.run();<br />
}<br />
}<br />
}}<br />
<br />
'''JavaScript'''<br />
<br />
* Dependencies: {{Pkg|gtk3}}, {{Pkg|gjs}} (works also with {{Pkg|seed}})<br />
{{hc|hello_world.js|2=<br />
#!/usr/bin/gjs<br />
const Gtk = imports.gi.Gtk<br />
Gtk.init(null, null)<br />
var Hello = new Gtk.MessageDialog({type: Gtk.MessageType.INFO,<br />
buttons: Gtk.ButtonsType.OK,<br />
text: "Hello world!",<br />
"secondary-text": "This is an example dialog."})<br />
Hello.run()<br />
}}<br />
<br />
'''Lua'''<br />
<br />
* Dependencies: {{Pkg|gtk3}}, {{Pkg|lua-lgi}}<br />
{{hc|hello_world.lua|2=<br />
#!/usr/bin/lua<br />
lgi = require 'lgi'<br />
Gtk = lgi.require('Gtk')<br />
Gtk.init()<br />
Hello=Gtk.MessageDialog {message_type = Gtk.MessageType.INFO,<br />
buttons = Gtk.ButtonsType.OK,<br />
text = "Hello world!",<br />
secondary_text = "This is an example dialog."}<br />
Hello:run()<br />
}}<br />
<br />
'''Pascal'''<br />
<br />
* Dependency: {{Pkg|gtk3}}<br />
* Makedependencies: {{Pkg|fpc}}, [http://wiki.freepascal.org/Gtk+3 Gtk+3.0 bindings]<br />
* Build with: {{ic|fpc hello_world}}<br />
{{hc|hello_world.pas|2=<br />
program hello_world;<br />
uses Math, Gtk3;<br />
var dialog: PGtkWidget;<br />
begin<br />
SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]);<br />
gtk_init(@argc, @argv);<br />
dialog := gtk_message_dialog_new(nil, GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, '%s', ['Hello world!']);<br />
gtk_message_dialog_format_secondary_text(PGtkMessageDialog(dialog), '%s', ['This is an example dialog.']);<br />
gtk_dialog_run(PGtkDialog(dialog));<br />
end.<br />
}}<br />
<br />
'''Perl'''<br />
<br />
* Dependency: {{AUR|perl-gtk3}} from AUR<br />
{{hc|hello_world.pl|2=<br />
#!/usr/bin/perl<br />
use Gtk3 -init;<br />
my $hello = Gtk3::MessageDialog->new (undef, 'modal', 'info', 'ok', "Hello world!");<br />
$hello->set ('secondary-text' => 'This is an example dialog.');<br />
$hello->run;<br />
}}<br />
<br />
'''Python'''<br />
<br />
* Dependencies: {{Pkg|gtk3}}, {{Pkg|python-gobject}}<br />
{{hc|hello_world.py|2=<br />
#!/usr/bin/python<br />
from gi.repository import Gtk<br />
Gtk.init(None)<br />
Hello=Gtk.MessageDialog(None, Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "Hello world!")<br />
Hello.format_secondary_text("This is an example dialog.")<br />
Hello.run()<br />
}}<br />
<br />
'''Ruby'''<br />
<br />
* Dependency: {{Pkg|ruby-gtk3}}<br />
{{hc|hello_world.rb|2=<br />
#!/usr/bin/ruby<br />
require 'gtk3'<br />
Gtk.init<br />
Hello = Gtk::MessageDialog.new(:type => :info,<br />
:buttons_type => :ok,<br />
:message => "Hello world!")<br />
Hello.secondary_text = "This is an example dialog."<br />
Hello.run<br />
}}<br />
<br />
'''Scala'''<br />
<br />
* Dependency: {{AUR|java-gnome}} from AUR (and {{Pkg|scala}})<br />
* Makedependency: {{Pkg|scala}}<br />
* Build with: {{ic|scalac -cp /usr/share/java/gtk.jar -d HelloWorld.jar HelloWorld.scala}}<br />
* Run with: {{ic|java -cp /usr/share/java/gtk.jar:HelloWorld.jar HelloWorld}} (or {{ic|scala -cp /usr/share/java/gtk.jar HelloWorld.scala}})<br />
<br />
{{hc|HelloWorld.scala|2=<br />
import org.gnome.gtk._<br />
<br />
object HelloWorld {<br />
def main(args: Array[String]) {<br />
Gtk.init(args)<br />
var hello = new InfoMessageDialog(null, "Hello world!", "This is an example dialog.")<br />
hello.run()<br />
}<br />
}<br />
}}<br />
<br />
'''Vala'''<br />
<br />
* Dependency: {{Pkg|gtk3}}<br />
* Makedependency: {{Pkg|vala}}<br />
* Build with: {{ic|valac --pkg gtk+-3.0 hello_world.vala}}<br />
{{hc|hello_world.vala|2=<br />
using Gtk;<br />
public class HelloWorld {<br />
static void main (string[] args) {<br />
Gtk.init (ref args);<br />
var Hello=new MessageDialog (null, Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "Hello world!");<br />
Hello.format_secondary_text ("This is an example dialog.");<br />
Hello.run ();<br />
}<br />
}<br />
}}<br />
<br />
'''Visual Basic .NET'''<br />
<br />
* Dependency: {{Pkg|gtk-sharp-3}}<br />
* Makedependency: {{Pkg|mono-basic}}<br />
* Build with: {{ic|vbnc -r:/usr/lib/mono/gtk-sharp-3.0/gio-sharp.dll -r:/usr/lib/mono/gtk-sharp-3.0/glib-sharp.dll -r:/usr/lib/mono/gtk-sharp-3.0/gtk-sharp.dll hello_world.vb}}<br />
* Run with: {{ic|mono hello_world.exe}}<br />
<br />
{{hc|hello_world.vb|2=<br />
Imports Gtk<br />
Public Class Hello<br />
Inherits MessageDialog<br />
Public Sub New<br />
MyBase.New(Me, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, "Hello world!")<br />
Me.SecondaryText = "This is an example dialog."<br />
End Sub<br />
Public Shared Sub Main<br />
Application.Init<br />
Dim Dialog As New Hello<br />
Dialog.Run<br />
End Sub<br />
End Class<br />
}}<br />
<br />
== See also ==<br />
<br />
* [http://www.gtk.org/ The official GTK+ website]<br />
* [[Wikipedia:GTK+|Wikipedia article about GTK+]]<br />
* [http://developer.gnome.org/gtk-tutorial/stable/ GTK+ 2.0 Tutorial]<br />
* [http://developer.gnome.org/gtk3/stable/ GTK+ 3 Reference Manual]<br />
* [http://developer.gnome.org/gtkmm-tutorial/stable/ gtkmm Tutorial]<br />
* [http://developer.gnome.org/gtkmm/stable/ gtkmm Reference Manual]</div>Zshang