|
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="combobox_multicolumn.vala" xml:lang="fr">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">ComboBox (Vala)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="beginner.vala#menu-combo-toolbar"/>
|
|
Packit |
1470ea |
<link type="seealso" xref="combobox.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>Un composant graphique utilisé pour effectuer un choix dans une liste d'éléments</desc>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Luc Rebert,</mal:name>
|
|
Packit |
1470ea |
<mal:email>traduc@rebert.name</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011</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>Alain Lojewski,</mal:name>
|
|
Packit |
1470ea |
<mal:email>allomervan@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011-2012</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>Luc Pionchon</mal:name>
|
|
Packit |
1470ea |
<mal:email>pionchon.luc@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011</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>Bruno Brouard</mal:name>
|
|
Packit |
1470ea |
<mal:email>annoa.b@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011-12</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>Luis Menina</mal:name>
|
|
Packit |
1470ea |
<mal:email>liberforce@freeside.fr</mal:email>
|
|
Packit |
1470ea |
<mal:years>2014</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>ComboBox (two columns)</title>
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/combobox_multicolumn.png"/>
|
|
Packit |
1470ea |
Cette BoiteCombinee affiche votre sélection dans le terminal quand vous la modifiez.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<links type="section"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="code">
|
|
Packit |
1470ea |
<title>Code utilisé pour générer cet exemple</title>
|
|
Packit |
1470ea |
class MyWindow : Gtk.ApplicationWindow {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
string[] file = {"Select", "New", "Open", "Save"};
|
|
Packit |
1470ea |
string[] stock_item = {"","gtk-new", "gtk-open", "gtk-save"};
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
enum Column {
|
|
Packit |
1470ea |
FILE,
|
|
Packit |
1470ea |
STOCK_ITEM
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Constructor */
|
|
Packit |
1470ea |
internal MyWindow (MyApplication app) {
|
|
Packit |
1470ea |
Object (application: app, title: "Welcome to GNOME");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
this.set_default_size (200, -1);
|
|
Packit |
1470ea |
this.border_width = 10;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
Gtk.ListStore liststore = new Gtk.ListStore (2, typeof (string), typeof (string));
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
for (int i = 0; i < file.length; i++){
|
|
Packit |
1470ea |
Gtk.TreeIter iter;
|
|
Packit |
1470ea |
liststore.append (out iter);
|
|
Packit |
1470ea |
liststore.set (iter, Column.FILE, file[i]);
|
|
Packit |
1470ea |
liststore.set (iter, Column.STOCK_ITEM, stock_item[i]);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
Gtk.ComboBox combobox = new Gtk.ComboBox.with_model (liststore);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* CellRenderers render the data. */
|
|
Packit |
1470ea |
Gtk.CellRendererText cell = new Gtk.CellRendererText ();
|
|
Packit |
1470ea |
Gtk.CellRendererPixbuf cell_pb = new Gtk.CellRendererPixbuf ();
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* we pack the cell into the beginning of the combobox, allocating
|
|
Packit |
1470ea |
* no more space than needed;
|
|
Packit |
1470ea |
* first the image, then the text;
|
|
Packit |
1470ea |
* note that it does not matter in which order they are in the model,
|
|
Packit |
1470ea |
* the visualization is decided by the order of the cellrenderers
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
combobox.pack_start (cell_pb, false);
|
|
Packit |
1470ea |
combobox.pack_start (cell, false);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* associate a property of the cellrenderer to a column in the model
|
|
Packit |
1470ea |
* used by the combobox
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
combobox.set_attributes (cell_pb, "stock_id", Column.STOCK_ITEM);
|
|
Packit |
1470ea |
combobox.set_attributes (cell, "text", Column.FILE);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Set the first item in the list to be selected (active). */
|
|
Packit |
1470ea |
combobox.set_active (0);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Connect the 'changed' signal of the combobox
|
|
Packit |
1470ea |
* to the signal handler (aka. callback function).
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
combobox.changed.connect (this.item_changed);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Add the combobox to this window */
|
|
Packit |
1470ea |
this.add (combobox);
|
|
Packit |
1470ea |
combobox.show ();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
void item_changed (Gtk.ComboBox combo) {
|
|
Packit |
1470ea |
if (combo.get_active () !=0) {
|
|
Packit |
1470ea |
print ("You chose " + file [combo.get_active ()] +"\n");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class MyApplication : Gtk.Application {
|
|
Packit |
1470ea |
protected override void activate () {
|
|
Packit |
1470ea |
new MyWindow (this).show ();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
int main (string[] args) {
|
|
Packit |
1470ea |
return new MyApplication ().run (args);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="references">
|
|
Packit |
1470ea |
<title>Références API</title>
|
|
Packit |
1470ea |
Dans cet exemple, les éléments suivants sont utilisés :
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item><link href="http://www.valadoc.org/gtk+-3.0/Gtk.ComboBox.html">GtkComboBox</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://www.valadoc.org/gtk+-3.0/Gtk.ListStore.html">GtkListStore</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://www.valadoc.org/gtk+-3.0/Gtk.CellRendererText.html">GtkCellRendererText</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://www.valadoc.org/gtk+-3.0/Gtk.CellRendererPixbuf.html">GtkCellRendererPixbuf</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/unstable/gtk3-Stock-Items.html">Stock Items</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
</page>
|