File: entry.js.page

package info (click to toggle)
gnome-devel-docs 3.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 28,808 kB
  • sloc: xml: 101,979; sh: 625; makefile: 380; ansic: 340; cpp: 131; python: 80
file content (63 lines) | stat: -rw-r--r-- 2,458 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?xml version="1.0" encoding="utf-8"?>
<page xmlns="http://projectmallard.org/1.0/" type="guide" style="task" id="entry.js" xml:lang="el">
  <info>
  <link type="guide" xref="beginner.js#entry"/>
    <revision version="0.1" date="2012-02-19" status="stub"/>

    <credit type="author copyright">
      <name>Susanna Huhtanen</name>
      <email>ihmis.suski@gmail.com</email>
      <years>2012</years>
    </credit>

    <desc>How to make an entry widget and connect its contents to a label</desc>
  </info>

  <title>Entry widget</title>
  
  <media type="image" mime="image/png" src="media/entry.png"/>
  <p>This an entry widget. An entry widget is a container that you can type in to. </p>
  
      <code mime="text/javascript" style="numbered"><![CDATA[
#!/usr/bin/gjs
Gtk = imports.gi.Gtk;
Gtk.init(null, 0);

myW = new Gtk.Window({type: Gtk.WindowType.TOPLEVEL});
myW.title = "Entry";
myW.connect("destroy", function(){Gtk.main_quit()});
grid = new Gtk.Grid();
myW.add(grid);

//create the entry widget
var entry = new Gtk.Entry();
entry.set_placeholder_text("Write something here");
entry.set_width_chars(50);
//create the first label
var label = new Gtk.Label({label: "Entry widget: "});
//create the button for connecting
var connectionbutton = new Gtk.Button({label: "Click to update label"});
//create the label for updating the entrys information
this.resultlabel = new Gtk.Label({
  label: "Entry contents go here after the click"
});
//create a connection between the button and the result label
connectionbutton.connect("clicked", function(widget, event) {
  //getting the text from the entry widget and updating the label
  var whatWasTyped = entry.get_text();
  this.resultlabel.set_text(whatWasTyped); 
});

grid.attach(label, 1, 1, 1, 1);
grid.attach_next_to(entry,label,1,1,1);
grid.attach_next_to(connectionbutton,label,3,1,1);
grid.attach_next_to(resultlabel,entry,3,1,1);myW.show_all();
Gtk.main();]]></code>
<p>In this sample we use the following widgets:
<link href="http://www.roojs.com/seed/gir-1.2-gtk-3.0/gjs/Gtk.Window.html">Gtk.Window</link>, 
<link href="http://www.roojs.com/seed/gir-1.2-gtk-3.0/gjs/Gtk.Grid.html">Gtk.Grid</link>, 
<link href="http://www.roojs.com/seed/gir-1.2-gtk-3.0/gjs/Gtk.Entry.html">Gtk.Entry</link>, 
<link href="http://www.roojs.com/seed/gir-1.2-gtk-3.0/gjs/Gtk.Label.html">Gtk.Label</link>, 
<link href="http://www.roojs.com/seed/gir-1.2-gtk-3.0/gjs/Gtk.Button.html">Gtk.Button</link>.</p>

</page>