|
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="menubutton.js" xml:lang="el">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">MenuButton (JavaScript)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="beginner.js#buttons"/>
|
|
Packit |
1470ea |
<revision version="0.1" date="2012-07-18" status="draft"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<credit type="author copyright">
|
|
Packit |
1470ea |
<name>Anna Zacchi</name>
|
|
Packit |
1470ea |
<email its:translate="no">azzurroverde@gmail.com</email>
|
|
Packit |
1470ea |
<years>2012</years>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<desc>Ένα γραφικό στοιχείο που εμφανίζει ένα μενού όταν πατηθεί</desc>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Ελληνική μεταφραστική ομάδα GNOME</mal:name>
|
|
Packit |
1470ea |
<mal:email>team@gnome.gr</mal:email>
|
|
Packit |
1470ea |
<mal:years>2012-2015</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Δημήτρης Σπίγγος</mal:name>
|
|
Packit |
1470ea |
<mal:email>dmtrs32@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2012, 2013</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Μαρία Θουκιδίδου</mal:name>
|
|
Packit |
1470ea |
<mal:email>marablack3@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2014</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Θάνος Τρυφωνίδης</mal:name>
|
|
Packit |
1470ea |
<mal:email>tomtryf@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2014, 2015</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>MenuButton</title>
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/menubutton.png"/>
|
|
Packit |
1470ea |
Το γραφικό στοιχείο GtkMenuButton χρησιμοποιείται για την εμφάνιση ενός μενού όταν πατιέται. Αυτό το μενού μπορεί να δοθεί είτε ως GtkMenu, ή ως ένα αποσπασμένο GMenuModel. Το γραφικό στοιχείο GtkMenuButton μπορεί να κρατήσει οποιοδήποτε θυγατρικό γραφικό στοιχείο. Δηλαδή, μπορεί να κρατήσει σχεδόν κάθε άλλο τυπικό GtkWidget. Το πιο συχνά χρησιμοποιούμενο θυγατρικό είναι το παρεχόμενο GtkArrow.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<note>Χρειάζεται να τρέξετε το GNOME 3.6 ή μεταγενέστερο για να δουλέψει το MenuButton. </note>
|
|
Packit |
1470ea |
#!/usr/bin/gjs
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
imports.gi.versions.Gtk = '3.0';
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
const Gio = imports.gi.Gio;
|
|
Packit |
1470ea |
const GLib = imports.gi.GLib;
|
|
Packit |
1470ea |
const Gtk = imports.gi.Gtk;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class Application {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
//create the application
|
|
Packit |
1470ea |
constructor() {
|
|
Packit |
1470ea |
this.application = new Gtk.Application({
|
|
Packit |
1470ea |
application_id: 'org.example.myapp',
|
|
Packit |
1470ea |
flags: Gio.ApplicationFlags.FLAGS_NONE
|
|
Packit |
1470ea |
});
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
//connect to 'activate' and 'startup' signals to the callback functions
|
|
Packit |
1470ea |
this.application.connect('activate', this._onActivate.bind(this));
|
|
Packit |
1470ea |
this.application.connect('startup', this._onStartup.bind(this));
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
//create the UI (in this case it's just the ApplicationWindow)
|
|
Packit |
1470ea |
_buildUI() {
|
|
Packit |
1470ea |
this._window = new Gtk.ApplicationWindow({ application: this.application,
|
|
Packit |
1470ea |
window_position: Gtk.WindowPosition.CENTER,
|
|
Packit |
1470ea |
title: "MenuButton Example" });
|
|
Packit |
1470ea |
this._window.set_default_size(600, 400);
|
|
Packit |
1470ea |
this.grid = new Gtk.Grid();
|
|
Packit |
1470ea |
this._window.add(this.grid);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
this._menuButton = new Gtk.MenuButton();
|
|
Packit |
1470ea |
this.grid.attach(this._menuButton, 0, 0, 1, 1 );
|
|
Packit |
1470ea |
this.menu = Gtk.Menu.new_from_model(this.menuModel);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
this.menu.show();
|
|
Packit |
1470ea |
this._menuButton.set_menu_model (this.menuModel);
|
|
Packit |
1470ea |
this._menuButton.set_size_request(80, 35);
|
|
Packit |
1470ea |
this._menuButton.show();
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
this._window.show_all();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
_showNew() {
|
|
Packit |
1470ea |
print("You clicked \"New\"");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
_showAbout() {
|
|
Packit |
1470ea |
print("You clicked \"About\"");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
//create the menu items and connect the signals to the callback functions.
|
|
Packit |
1470ea |
_initMenus() {
|
|
Packit |
1470ea |
let newAction = new Gio.SimpleAction({ name: 'new' });
|
|
Packit |
1470ea |
newAction.connect('activate', () => { this._showNew(); });
|
|
Packit |
1470ea |
this.application.add_action(newAction);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
let aboutAction = new Gio.SimpleAction({ name: 'about' });
|
|
Packit |
1470ea |
aboutAction.connect('activate', () => { this._showAbout(); });
|
|
Packit |
1470ea |
this.application.add_action(aboutAction);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
let quitAction = new Gio.SimpleAction({ name: 'quit' });
|
|
Packit |
1470ea |
quitAction.connect('activate', () => { this._window.destroy(); });
|
|
Packit |
1470ea |
this.application.add_action(quitAction);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
this.menuModel = new Gio.Menu();
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
this.menuItemNew = Gio.MenuItem.new("New", 'app.new');
|
|
Packit |
1470ea |
this.menuItemAbout = Gio.MenuItem.new("About", 'app.about');
|
|
Packit |
1470ea |
this.fileMenuItem = Gio.MenuItem.new("Other", null);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
this.menuModel.append_item(this.menuItemNew);
|
|
Packit |
1470ea |
this.menuModel.append_item(this.menuItemAbout);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
//submenu
|
|
Packit |
1470ea |
this.subMenu = new Gio.Menu();
|
|
Packit |
1470ea |
this.fileMenuItem.set_submenu(this.subMenu);
|
|
Packit |
1470ea |
this.menuItemQuit = Gio.MenuItem.new("Quit", 'app.quit');
|
|
Packit |
1470ea |
this.subMenu.append_item(this.menuItemQuit);
|
|
Packit |
1470ea |
this.menuModel.append_item(this.fileMenuItem);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
//callback function for 'activate' signal
|
|
Packit |
1470ea |
_onActivate() {
|
|
Packit |
1470ea |
this._window.present();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
//callback function for 'startup' signal
|
|
Packit |
1470ea |
_onStartup() {
|
|
Packit |
1470ea |
//You must call _initMenus() before calling _buildUI().
|
|
Packit |
1470ea |
this._initMenus();
|
|
Packit |
1470ea |
this._buildUI();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
};
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
//run the application
|
|
Packit |
1470ea |
let app = new Application();
|
|
Packit |
1470ea |
app.application.run(ARGV);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
Σε αυτό το παράδειγμα χρησιμοποιήσαμε τα παρακάτω:
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/3.5/gtk3-GtkMenuButton.html">MenuButton</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</page>
|