「GTK/開発」の版間の差分
ナビゲーションに移動
検索に移動
Kusakata.bot2 (トーク | 投稿記録) (Pkg/AUR テンプレートの更新) |
Kusanaginoturugi (トーク | 投稿記録) (fix en page link) |
||
| (2人の利用者による、間の9版が非表示) | |||
| 1行目: | 1行目: | ||
[[Category:ウィジェットツールキット]] |
[[Category:ウィジェットツールキット]] |
||
[[Category:開発]] |
[[Category:開発]] |
||
| − | [[en:GTK |
+ | [[en:GTK/Development]] |
== シンプルなメッセージダイアログアプリ == |
== シンプルなメッセージダイアログアプリ == |
||
| 8行目: | 8行目: | ||
以下の例ではシンプルに "Hello world" をメッセージダイアログに表示します。 |
以下の例ではシンプルに "Hello world" をメッセージダイアログに表示します。 |
||
| − | ===Ada=== |
+ | === Ada === |
* 依存パッケージ: {{AUR|gtkada}} |
* 依存パッケージ: {{AUR|gtkada}} |
||
| 35行目: | 35行目: | ||
}} |
}} |
||
| − | ===Bash=== |
+ | === Bash === |
*依存パッケージ: {{Pkg|zenity}} |
*依存パッケージ: {{Pkg|zenity}} |
||
{{hc|hello_world.sh|<nowiki>#!/bin/bash |
{{hc|hello_world.sh|<nowiki>#!/bin/bash |
||
zenity --info --title='Hello world!' --text='This is an example dialog.'</nowiki>}} |
zenity --info --title='Hello world!' --text='This is an example dialog.'</nowiki>}} |
||
| − | ===BASIC=== |
+ | === BASIC === |
* 依存パッケージ: {{Pkg|gtk3}} |
* 依存パッケージ: {{Pkg|gtk3}} |
||
| 55行目: | 55行目: | ||
}} |
}} |
||
| − | ===Boo=== |
+ | === Boo === |
*依存パッケージ: {{Pkg|gtk-sharp-3}} ({{AUR|boo}}) |
*依存パッケージ: {{Pkg|gtk-sharp-3}} ({{AUR|boo}}) |
||
*ビルドするのに必要なパッケージ: {{AUR|boo}} |
*ビルドするのに必要なパッケージ: {{AUR|boo}} |
||
| 67行目: | 67行目: | ||
Hello.Run()</nowiki>}} |
Hello.Run()</nowiki>}} |
||
| − | ===C=== |
+ | === C === |
*依存パッケージ: {{Pkg|gtk3}} |
*依存パッケージ: {{Pkg|gtk3}} |
||
*ビルド: {{Ic|gcc -o hello_world `pkg-config --cflags --libs gtk+-3.0` hello_world.c}} |
*ビルド: {{Ic|gcc -o hello_world `pkg-config --cflags --libs gtk+-3.0` hello_world.c}} |
||
| 78行目: | 78行目: | ||
}</nowiki>}} |
}</nowiki>}} |
||
| − | ===C++=== |
+ | === C++ === |
*依存パッケージ: {{Pkg|gtkmm3}} |
*依存パッケージ: {{Pkg|gtkmm3}} |
||
*ビルド: {{Ic|g++ -o hello_world `pkg-config --cflags --libs gtkmm-3.0` hello_world.cc}} |
*ビルド: {{Ic|g++ -o hello_world `pkg-config --cflags --libs gtkmm-3.0` hello_world.cc}} |
||
| 91行目: | 91行目: | ||
}</nowiki>}} |
}</nowiki>}} |
||
| − | ===C#=== |
+ | === C# === |
*依存パッケージ: {{Pkg|gtk-sharp-3}} |
*依存パッケージ: {{Pkg|gtk-sharp-3}} |
||
*ビルド: {{ic|mcs -pkg:gtk-sharp-3.0 hello_world.cs}} |
*ビルド: {{ic|mcs -pkg:gtk-sharp-3.0 hello_world.cs}} |
||
| 105行目: | 105行目: | ||
}</nowiki>}} |
}</nowiki>}} |
||
| − | === |
+ | === Clojure === |
| − | * 依存パッケージ: {{ |
+ | * 依存パッケージ: {{AUR|java-gnome}}, {{Pkg|leiningen}} |
| + | * 実行: {{ic|lein run}} |
||
| − | * ビルドするのに必要なパッケージ: {{AUR|cobra}} |
||
| + | |||
| − | * ビルド: {{ic|cobra -c hello_world}} |
||
| + | {{hc|project.clj|<nowiki> |
||
| − | * 実行: {{ic|mono hello_world.exe}} |
||
| + | (defproject hello-world "0.1.0-SNAPSHOT" |
||
| − | {{hc|hello_world.cobra|2= |
||
| + | :main hello-world.core |
||
| − | @args -pkg:gtk-sharp-3.0 |
||
| + | :dependencies [[org.clojure/clojure "1.10.3"]] |
||
| − | use Gtk |
||
| + | :resource-paths ["/usr/share/java/gtk.jar"]) |
||
| + | </nowiki>}} |
||
| + | |||
| + | {{hc|src/hello_world/core.clj|2= |
||
| + | (ns hello-world.core |
||
| + | (:import [org.gnome.gtk Gtk InfoMessageDialog])) |
||
| + | |||
| + | (defonce gtk-init (Gtk/init (make-array String 0))) |
||
| + | |||
| + | (defn -main [] |
||
| + | (doto (InfoMessageDialog. nil "Hello world!" "This is an example dialog.").run)) |
||
| + | }} |
||
| + | |||
| + | === Crystal === |
||
| + | |||
| + | * 依存パッケージ: {{Pkg|gtk3}} |
||
| + | * ビルドするのに必要なパッケージ: {{Pkg|crystal}}, [https://github.com/jhass/crystal-gobject#readme crystal-gobject] |
||
| + | * ビルド: {{ic|crystal build hello_world.cr}} |
||
| + | {{hc|hello_world.cr|2= |
||
| + | require "gobject/gtk/autorun" |
||
| + | dialog = Gtk::MessageDialog.new text: "Hello world!", message_type: :info, buttons: :ok, secondary_text: "This is an example dialog." |
||
| − | class HelloWorld |
||
| + | dialog.on_response do |
||
| − | def main |
||
| + | Gtk.main_quit |
||
| − | Application.init |
||
| + | end |
||
| − | hello = MessageDialog(nil, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, "Hello world!") |
||
| + | dialog.show |
||
| − | hello.secondaryText = "This is an example dialog." |
||
| − | hello.run |
||
}} |
}} |
||
| − | ===D=== |
+ | === D === |
* 依存パッケージ: {{Pkg|gtkd}} |
* 依存パッケージ: {{Pkg|gtkd}} |
||
| 140行目: | 159行目: | ||
}} |
}} |
||
| − | ===F#=== |
+ | === F# === |
* 依存パッケージ: {{Pkg|gtk-sharp-3}} |
* 依存パッケージ: {{Pkg|gtk-sharp-3}} |
||
| 155行目: | 174行目: | ||
</nowiki>}} |
</nowiki>}} |
||
| − | ===Fortran=== |
+ | === Fortran === |
* 依存パッケージ: {{AUR|gtk-3-fortran-git}} |
* 依存パッケージ: {{AUR|gtk-3-fortran-git}} |
||
| 176行目: | 195行目: | ||
</nowiki>}} |
</nowiki>}} |
||
| − | ===Genie=== |
+ | === Genie === |
*依存パッケージ: {{Pkg|gtk3}} |
*依存パッケージ: {{Pkg|gtk3}} |
||
*ビルドするのに必要なパッケージ: {{Pkg|vala}} |
*ビルドするのに必要なパッケージ: {{Pkg|vala}} |
||
| 188行目: | 207行目: | ||
Hello.run ()</nowiki>}} |
Hello.run ()</nowiki>}} |
||
| − | ===Go=== |
+ | === Go === |
* 依存パッケージ: {{Pkg|gtk3}} |
* 依存パッケージ: {{Pkg|gtk3}} |
||
| 207行目: | 226行目: | ||
}} |
}} |
||
| − | ===Groovy=== |
+ | === Groovy === |
* 依存パッケージ: {{Pkg|groovy}}, {{AUR|java-gnome}} |
* 依存パッケージ: {{Pkg|groovy}}, {{AUR|java-gnome}} |
||
| 220行目: | 239行目: | ||
}} |
}} |
||
| − | ===Haskell=== |
+ | === Haskell === |
* 依存パッケージ: {{Pkg|gtk3}} |
* 依存パッケージ: {{Pkg|gtk3}} |
||
| 235行目: | 254行目: | ||
}} |
}} |
||
| − | ===IronPython=== |
+ | === IronPython === |
* 依存パッケージ: {{Pkg|gtk-sharp-3}}, {{AUR|ironpython}} |
* 依存パッケージ: {{Pkg|gtk-sharp-3}}, {{AUR|ironpython}} |
||
| 249行目: | 268行目: | ||
}} |
}} |
||
| − | ===Java=== |
+ | === Java === |
*依存パッケージ: {{AUR|java-gnome}} |
*依存パッケージ: {{AUR|java-gnome}} |
||
*ビルドするのに必要なパッケージ: java-environment |
*ビルドするのに必要なパッケージ: java-environment |
||
| 268行目: | 287行目: | ||
}</nowiki>}} |
}</nowiki>}} |
||
| − | ===JavaScript=== |
+ | === JavaScript === |
*依存パッケージ: {{Pkg|gtk3}}, {{Pkg|gjs}} |
*依存パッケージ: {{Pkg|gtk3}}, {{Pkg|gjs}} |
||
{{hc|hello_world.js|<nowiki>#!/usr/bin/gjs |
{{hc|hello_world.js|<nowiki>#!/usr/bin/gjs |
||
| 279行目: | 298行目: | ||
Hello.run()</nowiki>}} |
Hello.run()</nowiki>}} |
||
| − | ===JRuby=== |
+ | === JRuby === |
* 依存パッケージ: {{AUR|java-gnome}}, {{Pkg|jruby}} |
* 依存パッケージ: {{AUR|java-gnome}}, {{Pkg|jruby}} |
||
| 295行目: | 314行目: | ||
}} |
}} |
||
| − | === |
+ | === Julia === |
| + | |||
| + | * 依存パッケージ: {{Pkg|julia}}, [https://juliagraphics.github.io/Gtk.jl/latest/ Gtk.jl] |
||
| + | * 実行: {{ic|1=julia hello_world.jl}} |
||
| + | {{hc|hello_world.jl|2= |
||
| + | using Gtk |
||
| + | info_dialog("Hello world!\n\nThis is an example dialog.") |
||
| + | }} |
||
| + | |||
| + | === Jython === |
||
* 依存パッケージ: {{AUR|java-gnome}}, {{Pkg|jython}} |
* 依存パッケージ: {{AUR|java-gnome}}, {{Pkg|jython}} |
||
| 306行目: | 334行目: | ||
}} |
}} |
||
| − | === |
+ | === Kotlin === |
| + | |||
| + | * 依存パッケージ: {{AUR|java-gnome}} |
||
| + | * ビルドするのに必要なパッケージ: {{Pkg|kotlin}} |
||
| + | * ビルド: {{ic|kotlinc -cp /usr/share/java/gtk.jar HelloWorld.kt -include-runtime -d HelloWorld.jar}} |
||
| + | * 実行: {{ic|java -cp /usr/share/java/gtk.jar:HelloWorld.jar HelloWorldKt}} |
||
| + | |||
| + | {{hc|HelloWorld.kt|2= |
||
| + | import org.gnome.gtk.* |
||
| + | |||
| + | fun main(args : Array<String>) { |
||
| + | Gtk.init(args); |
||
| + | val Hello = InfoMessageDialog(null, "Hello world!", "This is an example dialog."); |
||
| + | Hello.run(); |
||
| + | } |
||
| + | }} |
||
| + | |||
| + | === Lua === |
||
* 依存パッケージ: {{Pkg|gtk3}}, {{Pkg|lua-lgi}} |
* 依存パッケージ: {{Pkg|gtk3}}, {{Pkg|lua-lgi}} |
||
| 321行目: | 366行目: | ||
}} |
}} |
||
| − | ===Nemerle=== |
+ | === Nemerle === |
* 依存パッケージ: {{Pkg|gtk-sharp-3}} |
* 依存パッケージ: {{Pkg|gtk-sharp-3}} |
||
| 339行目: | 384行目: | ||
}} |
}} |
||
| − | === |
+ | === OCaml === |
| + | |||
| + | * 依存パッケージ: {{Pkg|gtk3}} |
||
| + | * ビルドするのに必要なパッケージ: {{Pkg|lablgtk3}} |
||
| + | * ビルド: {{ic|ocamlopt -I +lablgtk3 lablgtk3.cmxa hello_world.ml -o hello_world}} |
||
| + | {{hc|hello_world.ml|2= |
||
| + | let main () = |
||
| + | GMain.init (); |
||
| + | let hello = GWindow.message_dialog ~message:"Hello world!" ~message_type:`INFO ~buttons:GWindow.Buttons.ok () in |
||
| + | hello#set_secondary_text("This is an example dialog."); |
||
| + | hello#run () |
||
| + | |||
| + | let _ = main () |
||
| + | }} |
||
| + | |||
| + | === Pascal === |
||
* 依存パッケージ: {{Pkg|gtk3}} |
* 依存パッケージ: {{Pkg|gtk3}} |
||
| 357行目: | 417行目: | ||
}} |
}} |
||
| − | ===Perl=== |
+ | === Perl === |
*依存パッケージ: {{Pkg|perl-gtk3}} |
*依存パッケージ: {{Pkg|perl-gtk3}} |
||
{{hc|hello_world.pl|<nowiki>#!/usr/bin/perl |
{{hc|hello_world.pl|<nowiki>#!/usr/bin/perl |
||
| 365行目: | 425行目: | ||
$hello->run;</nowiki>}} |
$hello->run;</nowiki>}} |
||
| − | === |
+ | === Prolog === |
| + | |||
| + | * 依存パッケージ: {{AUR|plgi}} |
||
| + | * 実行: {{ic|swipl hello_world.pl}} |
||
| + | {{hc|hello_world.pl|2= |
||
| + | :- use_module(library(plgi)). |
||
| + | :- plgi_use_namespace('Gtk'). |
||
| + | |||
| + | main :- |
||
| + | g_object_new('GtkMessageDialog', |
||
| + | ['message-type'='GTK_MESSAGE_INFO', |
||
| + | 'buttons'='GTK_BUTTONS_OK', |
||
| + | 'text'='Hello world!', |
||
| + | 'secondary-text'='This is an example dialog.'], |
||
| + | Dialog), |
||
| + | gtk_dialog_run(Dialog, _), |
||
| + | halt. |
||
| + | :- main. |
||
| + | }} |
||
| + | |||
| + | === Python === |
||
*依存パッケージ: {{Pkg|gtk3}}, {{Pkg|python-gobject}} (Python 2 の場合 {{Pkg|python2-gobject}}) |
*依存パッケージ: {{Pkg|gtk3}}, {{Pkg|python-gobject}} (Python 2 の場合 {{Pkg|python2-gobject}}) |
||
{{hc|hello_world.py|2= |
{{hc|hello_world.py|2= |
||
| 377行目: | 457行目: | ||
Hello.run()}} |
Hello.run()}} |
||
| − | ===Ruby=== |
+ | === Ruby === |
* 依存パッケージ: {{Pkg|gtk3}}, {{AUR|ruby-gir_ffi-gtk}} |
* 依存パッケージ: {{Pkg|gtk3}}, {{AUR|ruby-gir_ffi-gtk}} |
||
| 401行目: | 481行目: | ||
}} |
}} |
||
| − | ===Rust=== |
+ | === Rust === |
[http://gtk-rs.org/ Gtk-rs] を使用。 |
[http://gtk-rs.org/ Gtk-rs] を使用。 |
||
| 433行目: | 513行目: | ||
}} |
}} |
||
| − | ===Scala=== |
+ | === Scala === |
* 依存パッケージ: {{AUR|java-gnome}} ({{Pkg|scala}}) |
* 依存パッケージ: {{AUR|java-gnome}} ({{Pkg|scala}}) |
||
| 452行目: | 532行目: | ||
}} |
}} |
||
| − | ===Vala=== |
+ | === Vala === |
*依存パッケージ: {{Pkg|gtk3}} |
*依存パッケージ: {{Pkg|gtk3}} |
||
*ビルドするのに必要なパッケージ: {{Pkg|vala}} |
*ビルドするのに必要なパッケージ: {{Pkg|vala}} |
||
| 466行目: | 546行目: | ||
}</nowiki>}} |
}</nowiki>}} |
||
| − | ===Visual Basic |
+ | === Visual Basic === |
*依存パッケージ: {{Pkg|gtk-sharp-3}} |
*依存パッケージ: {{Pkg|gtk-sharp-3}} |
||
*ビルドするのに必要なパッケージ: {{AUR|mono-basic}} |
*ビルドするのに必要なパッケージ: {{AUR|mono-basic}} |
||
| 485行目: | 565行目: | ||
End Sub |
End Sub |
||
End Class</nowiki>}} |
End Class</nowiki>}} |
||
| + | |||
| + | == 参照 == |
||
| + | |||
| + | * [https://developer.gnome.org/ GNOME Developer Center] |
||
| + | * [https://developer.gnome.org/gtk3/stable/ GTK 3 リファレンスマニュアル] |
||
| + | * [https://developer.gnome.org/gtkmm-tutorial/stable/ gtkmm 3 チュートリアル] |
||
2023年9月2日 (土) 21:20時点における最新版
目次
- 1 シンプルなメッセージダイアログアプリ
- 1.1 Ada
- 1.2 Bash
- 1.3 BASIC
- 1.4 Boo
- 1.5 C
- 1.6 C++
- 1.7 C#
- 1.8 Clojure
- 1.9 Crystal
- 1.10 D
- 1.11 F#
- 1.12 Fortran
- 1.13 Genie
- 1.14 Go
- 1.15 Groovy
- 1.16 Haskell
- 1.17 IronPython
- 1.18 Java
- 1.19 JavaScript
- 1.20 JRuby
- 1.21 Julia
- 1.22 Jython
- 1.23 Kotlin
- 1.24 Lua
- 1.25 Nemerle
- 1.26 OCaml
- 1.27 Pascal
- 1.28 Perl
- 1.29 Prolog
- 1.30 Python
- 1.31 Ruby
- 1.32 Rust
- 1.33 Scala
- 1.34 Vala
- 1.35 Visual Basic
- 2 参照
シンプルなメッセージダイアログアプリ
GObject-Introspection やバインディングを使うことで多くのプログラミング言語で簡単に GTK+ 3 のメッセージダイアログを作ることができます、また bash を使うこともできます。
以下の例ではシンプルに "Hello world" をメッセージダイアログに表示します。
Ada
hello_world.adb
with Gtk.Main;
with Gtk.Dialog; use Gtk.Dialog;
with Gtk.Message_Dialog; use Gtk.Message_Dialog;
procedure hello_world is
Dialog : Gtk_Message_Dialog;
Response : Gtk_Response_Type;
begin
Gtk.Main.Init;
Gtk_New (Dialog => Dialog,
Parent => null,
Flags => 0,
The_Type => Message_Info,
Buttons => Buttons_OK,
Message => "Hello world!");
Format_Secondary_Markup (Dialog, "This is an example dialog.");
Response := Run (Dialog);
end hello_world;
Bash
- 依存パッケージ: zenity
hello_world.sh
#!/bin/bash zenity --info --title='Hello world!' --text='This is an example dialog.'
BASIC
- 依存パッケージ: gtk3
- ビルドするのに必要なパッケージ: freebasic-gnomeheadersAUR
- ビルド:
fbc hello_world.bas
hello_world.bas
#include "Gir/Gtk-3.0.bi" Dim As GtkWidget Ptr hello gtk_init (cast(gint ptr, @__fb_argc__), @__fb_argv__) hello = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Hello world!") gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (hello), "This is an example dialog.") gtk_dialog_run (GTK_DIALOG (hello))
Boo
- 依存パッケージ: gtk-sharp-3 (booAUR)
- ビルドするのに必要なパッケージ: booAUR
- ビルド:
booc hello_world.boo - 実行:
mono hello_world.exe(もしくはbooi hello_world.boo)
hello_world.boo
import Gtk from "gtk-sharp" Application.Init() Hello = MessageDialog(null, DialogFlags.Modal, MessageType.Info, ButtonsType.Close, "Hello world!") Hello.SecondaryText = "This is an example dialog." Hello.Run()
C
- 依存パッケージ: gtk3
- ビルド:
gcc -o hello_world `pkg-config --cflags --libs gtk+-3.0` hello_world.c
hello_world.c
#include <gtk/gtk.h>
void main (int argc, char *argv[]) {
gtk_init (&argc, &argv);
GtkWidget *hello = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Hello world!");
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (hello), "This is an example dialog.");
gtk_dialog_run(GTK_DIALOG (hello));
}
C++
- 依存パッケージ: gtkmm3
- ビルド:
g++ -o hello_world `pkg-config --cflags --libs gtkmm-3.0` hello_world.cc
hello_world.cc
#include <gtkmm/main.h>
#include <gtkmm/messagedialog.h>
int main(int argc, char *argv[]) {
Gtk::Main kit(argc, argv);
Gtk::MessageDialog Hello("Hello world!", false, Gtk::MESSAGE_INFO, Gtk::BUTTONS_OK);
Hello.set_secondary_text("This is an example dialog.");
Hello.run();
return 0;
}
C#
- 依存パッケージ: gtk-sharp-3
- ビルド:
mcs -pkg:gtk-sharp-3.0 hello_world.cs - 実行:
mono hello_world.exe
hello_world.cs
using Gtk;
public class HelloWorld {
static void Main() {
Application.Init ();
MessageDialog Hello = new MessageDialog (null, DialogFlags.Modal, MessageType.Info, ButtonsType.Close, "Hello world!");
Hello.SecondaryText="This is an example dialog.";
Hello.Run ();
}
}
Clojure
- 依存パッケージ: java-gnomeAUR, leiningen
- 実行:
lein run
project.clj
(defproject hello-world "0.1.0-SNAPSHOT" :main hello-world.core :dependencies [[org.clojure/clojure "1.10.3"]] :resource-paths ["/usr/share/java/gtk.jar"])
src/hello_world/core.clj
(ns hello-world.core (:import [org.gnome.gtk Gtk InfoMessageDialog])) (defonce gtk-init (Gtk/init (make-array String 0))) (defn -main [] (doto (InfoMessageDialog. nil "Hello world!" "This is an example dialog.").run))
Crystal
- 依存パッケージ: gtk3
- ビルドするのに必要なパッケージ: crystal, crystal-gobject
- ビルド:
crystal build hello_world.cr
hello_world.cr
require "gobject/gtk/autorun" dialog = Gtk::MessageDialog.new text: "Hello world!", message_type: :info, buttons: :ok, secondary_text: "This is an example dialog." dialog.on_response do Gtk.main_quit end dialog.show
D
hello_world.d
import gtk.Main;
import gtk.MessageDialog;
void main(string[] args)
{
Main.init(args);
MessageDialog dialog = new MessageDialog(null, GtkDialogFlags.MODAL, MessageType.INFO, ButtonsType.OK, "Hello world!");
dialog.run();
}
F#
- 依存パッケージ: gtk-sharp-3
- ビルドするのに必要なパッケージ: fsharpAUR
- ビルド:
fsharpc -r:gtk-sharp.dll -I:/usr/lib/mono/gtk-sharp-3.0/ hello_world.fs - 実行:
mono hello_world.exe
hello_world.fs
open Gtk Application.Init() let Hello = new MessageDialog(null, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, "Hello world!") Hello.SecondaryText <- "This is an example dialog." Hello.Run() |> ignore
Fortran
- 依存パッケージ: gtk-3-fortran-gitAUR
- ビルドするのに必要なパッケージ: gcc-fortran
- ビルド:
gfortran -o hello_world $(pkg-config --cflags --libs gtk-3-fortran) hello_world.f90
hello_world.f90
program hello_world use gtk_hl use gtk, only: gtk_init integer(c_int) :: resp character(40), dimension(2) :: msg call gtk_init() msg(1) ="Hello world!" msg(2) = "This is an example dialog." resp = hl_gtk_message_dialog_show(msg, GTK_BUTTONS_OK, type=GTK_MESSAGE_INFO) end program hello_world
Genie
hello_world.gs
uses
Gtk
init
Gtk.init (ref args)
var Hello=new MessageDialog (null, Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "Hello world!")
Hello.format_secondary_text ("This is an example dialog.")
Hello.run ()
Go
- 依存パッケージ: gtk3
- ビルドするのに必要なパッケージ: gotk3-gitAUR
- ビルド:
go build hello_world.go - (もしくは実行:
go run hello_world.go)
hello_world.go
package main
import ("github.com/conformal/gotk3/gtk")
func main() {
gtk.Init(nil)
dialog := gtk.MessageDialogNew(nil, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, "Hello world!")
dialog.FormatSecondaryText("This is an example notification.")
dialog.Run()
}
Groovy
- 依存パッケージ: groovy, java-gnomeAUR
- ビルド:
groovyc -cp /usr/share/java/gtk.jar HelloWorld.groovy && jar cfe HelloWorld.jar HelloWorld HelloWorld.class - 実行:
java -cp /usr/share/groovy/embeddable/groovy-all.jar:/usr/share/java/gtk.jar:HelloWorld.jar HelloWorldまたはgroovy -cp /usr/share/java/gtk.jar HelloWorld.groovy
HelloWorld.groovy
import org.gnome.gtk.* Gtk.init() def Hello = new InfoMessageDialog(null, "Hello world!", "This is an example dialog.") Hello.run()
Haskell
- 依存パッケージ: gtk3
- ビルドするのに必要なパッケージ: haskell-gtk[リンク切れ: 置換パッケージ: haskell-gtk3]
- ビルド:
ghc hello_world
hello_world.hs
import Graphics.UI.Gtk
main = do
initGUI
dialog <- messageDialogNew Nothing [DialogModal] MessageInfo ButtonsOk "Hello world!"
messageDialogSetSecondaryText dialog "This is an example dialog."
_res <- dialogRun dialog
return 0
IronPython
- 依存パッケージ: gtk-sharp-3, ironpythonAUR
- 実行:
ipy hello_world.py
hello_world.py
import clr
clr.AddReference('gtk-sharp')
import Gtk
Gtk.Application.Init()
Hello = Gtk.MessageDialog (None, Gtk.DialogFlags.Modal, Gtk.MessageType.Info, Gtk.ButtonsType.Ok, "Hello world!")
Hello.SecondaryText="This is an example dialog."
Hello.Run()
Java
- 依存パッケージ: java-gnomeAUR
- ビルドするのに必要なパッケージ: java-environment
- ビルド:
mkdir HelloWorld && javac -classpath /usr/share/java/gtk.jar -d HelloWorld HelloWorld.java - 実行:
java -classpath /usr/share/java/gtk.jar:HelloWorld HelloWorld
HelloWorld.java
import org.gnome.gtk.Gtk;
import org.gnome.gtk.Dialog;
import org.gnome.gtk.InfoMessageDialog;
public class HelloWorld
{
public static void main(String[] args) {
Gtk.init(args);
Dialog Hello = new InfoMessageDialog(null, "Hello world!", "This is an example dialog.");
Hello.run();
}
}
JavaScript
hello_world.js
#!/usr/bin/gjs
Gtk = imports.gi.Gtk
Gtk.init(null, null)
Hello = new Gtk.MessageDialog({type: Gtk.MessageType.INFO,
buttons: Gtk.ButtonsType.OK,
text: "Hello world!",
"secondary-text": "This is an example dialog."})
Hello.run()
JRuby
- 依存パッケージ: java-gnomeAUR, jruby
- ビルド:
jrubyc hello_world.rb && jar cfe hello_world.jar hello_world hello_world.class - 実行:
java -cp /opt/jruby/lib/jruby.jar:hello_world.jar hello_worldまたはjruby hello_world.rb
hello_world.rb
require '/usr/share/java/gtk.jar' import Java::OrgGnomeGtk::Gtk import Java::OrgGnomeGtk::Dialog import Java::OrgGnomeGtk::InfoMessageDialog Gtk.init(nil) Hello = InfoMessageDialog.new(nil, "Hello world!", "This is an example dialog.") Hello.run
Julia
hello_world.jl
using Gtk
info_dialog("Hello world!\n\nThis is an example dialog.")
Jython
- 依存パッケージ: java-gnomeAUR, jython
- 実行:
jython -Dpython.path=/usr/share/java/gtk.jar hello_world.py
hello_world.py
from org.gnome.gtk import Gtk, InfoMessageDialog Gtk.init(None) Hello=InfoMessageDialog(None, "Hello world!", "This is an example dialog.") Hello.run()
Kotlin
- 依存パッケージ: java-gnomeAUR
- ビルドするのに必要なパッケージ: kotlin
- ビルド:
kotlinc -cp /usr/share/java/gtk.jar HelloWorld.kt -include-runtime -d HelloWorld.jar - 実行:
java -cp /usr/share/java/gtk.jar:HelloWorld.jar HelloWorldKt
HelloWorld.kt
import org.gnome.gtk.*
fun main(args : Array<String>) {
Gtk.init(args);
val Hello = InfoMessageDialog(null, "Hello world!", "This is an example dialog.");
Hello.run();
}
Lua
hello_world.lua
#!/usr/bin/env lua
lgi = require 'lgi'
Gtk = lgi.require('Gtk')
Gtk.init()
Hello=Gtk.MessageDialog {message_type = Gtk.MessageType.INFO,
buttons = Gtk.ButtonsType.OK,
text = "Hello world!",
secondary_text = "This is an example dialog."}
Hello:run()
Nemerle
- 依存パッケージ: gtk-sharp-3
- ビルドするのに必要なパッケージ: nemerleAUR
- ビルド:
ncc -pkg:gtk-sharp-3.0 -out:hello_world.exe hello_world.n - 実行:
mono hello_world.exe
hello_world.n
using Gtk;
public class HelloWorld {
static Main() : void {
Application.Init ();
def Hello = MessageDialog (null, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, "Hello world!");
Hello.SecondaryText = "This is an example dialog.";
_ = Hello.Run ();
}
}
OCaml
- 依存パッケージ: gtk3
- ビルドするのに必要なパッケージ: lablgtk3
- ビルド:
ocamlopt -I +lablgtk3 lablgtk3.cmxa hello_world.ml -o hello_world
hello_world.ml
let main () =
GMain.init ();
let hello = GWindow.message_dialog ~message:"Hello world!" ~message_type:`INFO ~buttons:GWindow.Buttons.ok () in
hello#set_secondary_text("This is an example dialog.");
hello#run ()
let _ = main ()
Pascal
- 依存パッケージ: gtk3
- ビルドするのに必要なパッケージ: fpc, Gtk+3.0 bindings
- ビルド:
fpc hello_world
hello_world.pas
program hello_world; uses Math, Gtk3; var dialog: PGtkWidget; begin SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]); gtk_init(@argc, @argv); dialog := gtk_message_dialog_new(nil, GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, '%s', ['Hello world!']); gtk_message_dialog_format_secondary_text(PGtkMessageDialog(dialog), '%s', ['This is an example dialog.']); gtk_dialog_run(PGtkDialog(dialog)); end.
Perl
- 依存パッケージ: perl-gtk3
hello_world.pl
#!/usr/bin/perl
use Gtk3 -init;
my $hello = Gtk3::MessageDialog->new (undef, 'modal', 'info', 'ok', "Hello world!");
$hello->set ('secondary-text' => 'This is an example dialog.');
$hello->run;
Prolog
- 依存パッケージ: plgiAUR
- 実行:
swipl hello_world.pl
hello_world.pl
:- use_module(library(plgi)).
:- plgi_use_namespace('Gtk').
main :-
g_object_new('GtkMessageDialog',
['message-type'='GTK_MESSAGE_INFO',
'buttons'='GTK_BUTTONS_OK',
'text'='Hello world!',
'secondary-text'='This is an example dialog.'],
Dialog),
gtk_dialog_run(Dialog, _),
halt.
:- main.
Python
- 依存パッケージ: gtk3, python-gobject (Python 2 の場合 python2-gobject)
hello_world.py
#!/usr/bin/env python
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
Gtk.init(None)
Hello=Gtk.MessageDialog(None, Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "Hello world!")
Hello.format_secondary_text("This is an example dialog.")
Hello.run()
Ruby
- 依存パッケージ: gtk3, ruby-gir_ffi-gtkAUR
hello_world.rb
#!/usr/bin/env ruby require 'gir_ffi-gtk3' Gtk.init Hello = Gtk::MessageDialog.new nil, :modal, :info, :ok, "Hello world!" Hello.secondary_text = "This is an example dialog." Hello.run
- 依存パッケージ: ruby-gtk3
hello_world.rb
#!/usr/bin/env ruby
require 'gtk3'
Gtk.init
Hello = Gtk::MessageDialog.new(:type => :info,
:buttons_type => :ok,
:message => "Hello world!")
Hello.secondary_text = "This is an example dialog."
Hello.run
Rust
Gtk-rs を使用。
Cargo.toml
[package] name = "hello_world" version = "0.1.0" [dependencies] gtk = "^0"
src/main.rs
extern crate gtk;
use gtk::prelude::*;
use gtk::{ButtonsType, DialogFlags, MessageType, MessageDialog, Window};
fn main() {
let _ = gtk::init();
MessageDialog::new(None::<&Window>,
DialogFlags::empty(),
MessageType::Info,
ButtonsType::Ok,
"Hello world!").run();
}
Scala
- 依存パッケージ: java-gnomeAUR (scala)
- ビルドするのに必要なパッケージ: scala
- ビルド:
scalac -cp /usr/share/java/gtk.jar -d HelloWorld.jar HelloWorld.scala - 実行:
java -cp /usr/share/java/gtk.jar:HelloWorld.jar HelloWorldまたはscala -cp /usr/share/java/gtk.jar HelloWorld.scala
HelloWorld.scala
import org.gnome.gtk._
object HelloWorld {
def main(args: Array[String]) {
Gtk.init(args)
var hello = new InfoMessageDialog(null, "Hello world!", "This is an example dialog.")
hello.run()
}
}
Vala
hello_world.vala
using Gtk;
public class HelloWorld {
static void main (string[] args) {
Gtk.init (ref args);
var Hello=new MessageDialog (null, Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "Hello world!");
Hello.format_secondary_text ("This is an example dialog.");
Hello.run ();
}
}
Visual Basic
- 依存パッケージ: gtk-sharp-3
- ビルドするのに必要なパッケージ: mono-basicAUR
- ビルド:
vbnc -r:/usr/lib/mono/gtk-sharp-3.0/gtk-sharp.dll hello_world.vb - 実行:
mono hello_world.exe
hello_world.vb
Imports Gtk Public Class Hello Inherits MessageDialog Public Sub New MyBase.New(Me, DialogFlags.Modal, MessageType.Info, ButtonsType.Close, "Hello world!") Me.SecondaryText = "This is an example dialog." End Sub Public Shared Sub Main Application.Init Dim Dialog As New Hello Dialog.Run End Sub End Class