|
Packit |
1470ea |
|
|
Packit |
1470ea |
<page xmlns="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its" xmlns:xi="http://www.w3.org/2001/XInclude" type="guide" style="task" id="tooltip.vala" xml:lang="de">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">Tooltip (Vala)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="beginner.vala#misc"/>
|
|
Packit |
1470ea |
<link type="seealso" xref="toolbar.vala"/>
|
|
Packit |
1470ea |
<revision version="0.1" date="2013-06-18" status="review"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<credit type="author copyright">
|
|
Packit |
1470ea |
<name>Tiffany Antopolski</name>
|
|
Packit |
1470ea |
<email its:translate="no">tiffany.antopolski@gmail.com</email>
|
|
Packit |
1470ea |
<years>2013</years>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<desc>Add tips to your widgets</desc>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Mario Blättermann</mal:name>
|
|
Packit |
1470ea |
<mal:email>mario.blaettermann@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011, 2013</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>Tooltip</title>
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/tooltip.png"/>
|
|
Packit |
1470ea |
A toolbar with a tooltip (with an image) for a button.
|
|
Packit |
1470ea |
<note>This example builds on the <link xref="toolbar.vala">Toolbar</link> example. </note>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<links type="section"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="code">
|
|
Packit |
1470ea |
<title>Code used to generate this example</title>
|
|
Packit |
1470ea |
/* This is the Window */
|
|
Packit |
1470ea |
class MyWindow : Gtk.ApplicationWindow {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Instance variables belonging to the window */
|
|
Packit |
1470ea |
Gtk.Toolbar toolbar;
|
|
Packit |
1470ea |
Gtk.ToolButton new_button;
|
|
Packit |
1470ea |
Gtk.ToolButton open_button;
|
|
Packit |
1470ea |
Gtk.ToolButton undo_button;
|
|
Packit |
1470ea |
Gtk.ToolButton fullscreen_button;
|
|
Packit |
1470ea |
Gtk.ToolButton leave_fullscreen_button;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Constructor */
|
|
Packit |
1470ea |
internal MyWindow (MyApplication app) {
|
|
Packit |
1470ea |
Object (application: app, title: "Toolbar with Tooltips Example");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
this.set_default_size (400, 200);
|
|
Packit |
1470ea |
var grid = new Gtk.Grid ();
|
|
Packit |
1470ea |
this.add (grid);
|
|
Packit |
1470ea |
grid.show ();
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
create_toolbar ();
|
|
Packit |
1470ea |
toolbar.set_hexpand (true);
|
|
Packit |
1470ea |
grid.attach (toolbar, 0, 0, 1, 1);
|
|
Packit |
1470ea |
toolbar.show ();
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* create the "undo" window action action */
|
|
Packit |
1470ea |
var undo_action = new SimpleAction ("undo", null);
|
|
Packit |
1470ea |
undo_action.activate.connect (undo_callback);
|
|
Packit |
1470ea |
this.add_action (undo_action);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* create the "fullscreen" window action */
|
|
Packit |
1470ea |
var fullscreen_action = new SimpleAction ("fullscreen", null);
|
|
Packit |
1470ea |
fullscreen_action.activate.connect (fullscreen_callback);
|
|
Packit |
1470ea |
this.add_action (fullscreen_action);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Callback for query_tooltip signal */
|
|
Packit |
1470ea |
bool undo_tooltip_callback (int x, int y, bool keyboard_tooltip, Gtk.Tooltip tooltip) {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* set the text for the tooltip */
|
|
Packit |
1470ea |
tooltip.set_text ("Undo your last action");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* set an icon fot the tooltip */
|
|
Packit |
1470ea |
tooltip.set_icon_from_stock("gtk-undo", Gtk.IconSize.MENU);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* show the tooltip */
|
|
Packit |
1470ea |
return true;
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* This function creates the toolbar, its ToolButtons,
|
|
Packit |
1470ea |
* and assigns the actions names to the ToolButtons.*/
|
|
Packit |
1470ea |
void create_toolbar () {
|
|
Packit |
1470ea |
toolbar = new Gtk.Toolbar ();
|
|
Packit |
1470ea |
toolbar.get_style_context ().add_class (Gtk.STYLE_CLASS_PRIMARY_TOOLBAR);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
new_button = new Gtk.ToolButton.from_stock (Gtk.Stock.NEW);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* tooltip with text */
|
|
Packit |
1470ea |
new_button.set_tooltip_text ("Create a new file");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
new_button.is_important = true; //decides whether to show the label
|
|
Packit |
1470ea |
toolbar.add (new_button);
|
|
Packit |
1470ea |
new_button.show ();
|
|
Packit |
1470ea |
new_button.action_name = "app.new";
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
open_button = new Gtk.ToolButton.from_stock (Gtk.Stock.OPEN);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* a tooltip using Pango markup language */
|
|
Packit |
1470ea |
open_button.set_tooltip_markup ("Open an <i>existing</i> file");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
open_button.is_important = true;
|
|
Packit |
1470ea |
toolbar.add (open_button);
|
|
Packit |
1470ea |
open_button.show ();
|
|
Packit |
1470ea |
open_button.action_name = "app.open";
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
undo_button = new Gtk.ToolButton.from_stock (Gtk.Stock.UNDO);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* For a tooltip to have an image, first we must set_has_tooltip to be 'true' */
|
|
Packit |
1470ea |
(undo_button as Gtk.Widget).set_has_tooltip (true);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Connect the query_tooltip signal to the callback */
|
|
Packit |
1470ea |
undo_button.query_tooltip.connect (undo_tooltip_callback);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
undo_button.is_important = true;
|
|
Packit |
1470ea |
toolbar.add (undo_button);
|
|
Packit |
1470ea |
undo_button.show ();
|
|
Packit |
1470ea |
undo_button.action_name = "win.undo";
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
fullscreen_button = new Gtk.ToolButton.from_stock (Gtk.Stock.FULLSCREEN);
|
|
Packit |
1470ea |
fullscreen_button.is_important = true;
|
|
Packit |
1470ea |
toolbar.add (fullscreen_button);
|
|
Packit |
1470ea |
fullscreen_button.show ();
|
|
Packit |
1470ea |
fullscreen_button.action_name = "win.fullscreen";
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
leave_fullscreen_button = new Gtk.ToolButton.from_stock (Gtk.Stock.LEAVE_FULLSCREEN)
|
|
Packit |
1470ea |
;
|
|
Packit |
1470ea |
leave_fullscreen_button.is_important = true;
|
|
Packit |
1470ea |
toolbar.add (leave_fullscreen_button);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
leave_fullscreen_button.action_name = "win.fullscreen";
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
void undo_callback (SimpleAction simple, Variant? parameter) {
|
|
Packit |
1470ea |
print ("You clicked \"Undo\".\n");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
void fullscreen_callback (SimpleAction simple, Variant? parameter) {
|
|
Packit |
1470ea |
if ((this.get_window ().get_state () & Gdk.WindowState.FULLSCREEN) != 0) {
|
|
Packit |
1470ea |
this.unfullscreen ();
|
|
Packit |
1470ea |
leave_fullscreen_button.hide ();
|
|
Packit |
1470ea |
fullscreen_button.show ();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
else {
|
|
Packit |
1470ea |
this.fullscreen ();
|
|
Packit |
1470ea |
fullscreen_button.hide ();
|
|
Packit |
1470ea |
leave_fullscreen_button.show ();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* This is the application */
|
|
Packit |
1470ea |
class MyApplication : Gtk.Application {
|
|
Packit |
1470ea |
protected override void activate () {
|
|
Packit |
1470ea |
new MyWindow (this).show ();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
protected override void startup () {
|
|
Packit |
1470ea |
base.startup ();
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Create the "new" action and add it to the app*/
|
|
Packit |
1470ea |
var new_action = new SimpleAction ("new", null);
|
|
Packit |
1470ea |
new_action.activate.connect (new_callback);
|
|
Packit |
1470ea |
this.add_action (new_action);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Create the "open" action, and add it to the app */
|
|
Packit |
1470ea |
var open_action = new SimpleAction ("open", null);
|
|
Packit |
1470ea |
open_action.activate.connect (open_callback);
|
|
Packit |
1470ea |
this.add_action (open_action);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* You could also add the action to the app menu
|
|
Packit |
1470ea |
* if you wanted to.
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
//var menu = new Menu ();
|
|
Packit |
1470ea |
//menu.append ("New", "app.new");
|
|
Packit |
1470ea |
//this.app_menu = menu;
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
void new_callback (SimpleAction action, Variant? parameter) {
|
|
Packit |
1470ea |
print ("You clicked \"New\".\n");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
void open_callback (SimpleAction action, Variant? parameter) {
|
|
Packit |
1470ea |
print ("You clicked \"Open\".\n");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* The main function creates the application and runs it. */
|
|
Packit |
1470ea |
int main (string[] args) {
|
|
Packit |
1470ea |
return new MyApplication ().run (args);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="references">
|
|
Packit |
1470ea |
<title>API-Referenzen</title>
|
|
Packit |
1470ea |
In this sample we used the following:
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<item><link href="http://www.valadoc.org/gtk+-3.0/Gtk.Tooltip.html">Gtk.Tooltip</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://www.valadoc.org/gtk+-3.0/Gtk.Toolbar.html">Gtk.Toolbar</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://www.valadoc.org/gtk+-3.0/Gtk.Widget.query_tooltip.html">Gtk.Widget.query_tooltip</link> </item>
|
|
Packit |
1470ea |
<item><link href="https://developer.gnome.org/gtk3/3.4/gtk3-Stock-Items.html#GTK-STOCK-UNDO:CAPS">Repertoire-Objekte</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
</page>
|