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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
|
<?xml version="1.0" encoding="utf-8"?>
<page xmlns="http://projectmallard.org/1.0/" type="topic" id="image-viewer.js" xml:lang="el">
<info>
<link type="guide" xref="index#js"/>
<desc>A little bit more than a simple "Hello world" application - write an image viewer in GTK. Includes an introduction to the JavaScript language.</desc>
<revision pkgversion="0.1" version="0.1" date="2011-03-19" status="review"/>
<credit type="author">
<name>Jonh Wendell</name>
<email>jwendell@gnome.org</email>
</credit>
<credit type="author">
<name>Johannes Schmid</name>
<email>jhs@gnome.org</email>
</credit>
</info>
<title>1 Image Viewer</title>
<synopsis>
<p>Σε αυτόν τον οδηγό θα φτιάξουμε μια πολύ απλή εφαρμογή σε GTK η οποία φορτώνει και εμφανίζει μια εικόνα. Θα μάθετε πως:</p>
<list>
<item><p>Write a basic GTK user interface in JavaScript</p></item>
<item><p>Να αντιμετωπίζετε γεγονότα συνδέοντας σήματα με το χειριστή σημάτων (signals handlers)</p></item>
<item><p>Σχεδιασμό διαπεφών χρήστη GTK χρησιμοποιώντας υποδοχείς (containers)</p></item>
<item><p>Φόρτωση και εμφάνιση εικόνων</p></item>
</list>
<p>Θα χρειαστείτε τα παρακάτω για να μπορέσετε να ακολουθήσετε αυτόν τον οδηγό:</p>
<list>
<item><p>Ένα εγκατεστημένο αντίγραφο του </p></item>
<item><p>An installed copy of the <em>gjs</em> interpreter</p></item>
<item><p>Basic knowledge of any object-orientated programming language</p></item>
</list>
</synopsis>
<media type="image" mime="image/png" src="media/image-viewer.png"/>
<section id="anjuta">
<title>Δημιουργήστε ένα έργο με το Anjuta</title>
<p>Πριν ξεκινήσετε να προγραμματίζετε, πρέπει να δημιουργήσετε ένα καινούργιο έργο στο Anjuta. Έτσι θα δημιουργηθούν όλα τα απαραίτητα αρχεία που χρειάζονται για την εκτέλεση του κώδικα αργότερα. Επίσης θα ήταν χρήσιμο να τα κρατάτε όλα μαζί.</p>
<steps>
<item>
<p>Ξεκινήστε το Anjuta και πατήστε <guiseq><gui>Αρχείο</gui><gui>Νέο</gui><gui>Έργο</gui></guiseq> για να ανοίξετε το μάγο του έργου (project wizard).</p>
</item>
<item>
<p>Choose <gui>Generic Javascript</gui> from the <gui>JS</gui> tab, click <gui>Forward</gui>, and fill out your details on the next few pages. Use <file>image-viewer</file> as project name and directory.</p>
</item>
<item>
<p>Click <gui>Apply</gui> and the project will be created for you. Open <file>src/main.js</file> from the <gui>Project</gui> or <gui>File</gui> tabs. It contains very basic example code.</p>
</item>
</steps>
</section>
<section id="js">
<title>JavaScript basics: Hello World</title>
<p>Before we start writing the image viewer, let's find out more about the way JavaScript is used in GNOME. Of course, your very first contact with any programming language should be the Hello World program which can already be found in <file>main.js</file>:</p>
<code mime="text/javascript">print ("Hello world!");</code>
<p>This should look quite natural if you're familiar with almost any other programming language. The function <code>print</code> is called with the argument <code>"Hello world!"</code>, which will be printed on the screen. Note that each line of code ends with a semicolon.</p>
</section>
<section id="classes">
<title>Classes in JavaScript</title>
<p>This is the standard way to define a class in JavaScript:</p>
<code mime="text/javascript" style="numbered"><![CDATA[
function MyClass () {
this._init ();
}
MyClass.prototype = {
_init: function () {
this.propertyA = "This is an object's field";
this.propertyB = 10;
},
aMethod: function (arg1, arg2) {
print ("inside aMethod: " + arg1 + " " + arg2);
},
dumpProperties: function () {
print (this.propertyA);
print (this.propertyB);
}
}]]></code>
<p>This defines a class called <code>MyClass</code>. Let's go through each part of the class definition:</p>
<steps>
<item>
<p><code>function MyClass</code> is the constructor of the class — its name must match the class's name. You can access any member of the class by using the <code>this</code> object; here, the constructor calls the class's <code>_init</code> method.</p>
</item>
<item>
<p>The <code>MyClass.prototype</code> block is where you define the <em>structure</em> of the class. Each class is made up of methods (functions) and fields (variables); there are three methods and two fields in this example.</p>
</item>
<item>
<p>The first method defined here is called <code>_init</code>, and we specify that it is a function with no arguments:</p>
<code>_init: function ()</code>
<p>We write the function inside some curly braces. Two fields are defined here, <code>propertyA</code> and <code>propertyB</code>. The first is set to a string and the second is set to an integer (10). The function doesn't return any value.</p>
</item>
<item>
<p>The next method is called <code>aMethod</code> and has two arguments, which it prints out when you call it. The final method is <code>dumpProperties</code>, and prints the fields <code>propertyA</code> and <code>propertyB</code>.</p>
</item>
<item>
<p>Note how the class definition (prototype) is arranged; each function definition is separated by a comma.</p>
</item>
</steps>
<p>Now that MyClass has been defined, we can play with it:</p>
<code mime="text/javascript" style="numbered"><![CDATA[
var o = new MyClass ();
o.aMethod ("Hello", "world");
o.propertyA = "Just changed its value!";
o.dumpProperties ();]]></code>
<p>This code creates a new instance of the class called <code>o</code>, runs <code>aMethod</code>, changes <code>propertyA</code> to a different string, and then calls <code>dumpProperties</code> (which outputs the fields).</p>
<p>Save the code in the <file>main.js</file> and then run it by using
<guiseq><gui>Run</gui><gui>Execute</gui></guiseq> from the menu or using the toolbar.</p>
</section>
<section id="gtk">
<title>Μια πρώτη εφαρμογή σε Gtk</title>
<p>Let's see what a very basic Gtk application looks like in JavaScript:</p>
<code mime="text/javascript" style="numbered"><![CDATA[
const Gtk = imports.gi.Gtk;
Gtk.init (null, null);
var w = new Gtk.Window ({title: "Image Viewer Demo"});
w.show ();
Gtk.main ();]]></code>
<p>Ας ρίξουμε μια ματιά στο τι γίνεται:</p>
<list>
<item>
<p>Η πρώτη γραμμή εισάγει το Gtk namespace (αυτό είναι που περιέχει την βιβλιοθήκη του Gtk). Οι βιβλιοθήκες παρέχονται από το GObject Introspection (gi), που παρέχει γλωσσικές επεκτάσεις για πολλές βιβλιοθήκες του GNOME.</p>
</item>
<item>
<p><code>Gtk.init</code> initializes the Gtk library; this statement is mandatory for all Gtk programs.</p>
</item>
<item>
<p>The next line creates the main window by creating a new <code>Gtk.Window</code> object. You can pass several properties to the window's constructor by using the syntax <code>{property: value, property: value, ...}</code>. In this case we are setting the title of the window.</p></item>
<item><p>The next line explicitly shows the window. In Gtk, every widget is hidden by default.</p></item>
<item><p>Finally, <code>Gtk.main</code> runs the main loop — in other words, it executes the program. The main loop listens for events (signals) from the user interface and then calls a signal handler which will do something useful. We'll learn more about signals shortly.</p></item>
</list>
<p>Save the code in <file>main.js</file> and run it. You will notice that the application does not quit when you close the window. This is because we haven't set up a signal handler to deal with the window's <code>destroy</code> (close) signal yet. We'll do this shortly, but for now you can just hit <keyseq><key>Ctrl</key><key>C</key></keyseq> in the terminal window to quit the program.</p>
</section>
<section id="classes2">
<title>Adding classes</title>
<p>The proper way of doing Gtk programming is by using classes. Let's rewrite the simple code you just wrote using classes:</p>
<code mime="text/javascript" style="numbered"><![CDATA[
const Gtk = imports.gi.Gtk;
function ImageViewer () {
this._init ();
}
ImageViewer.prototype = {
_init: function () {
this.window = new Gtk.Window ({title: "Image Viewer Demo"});
this.window.show ();
}
}
Gtk.init (0, null);
var iv = new ImageViewer ();
Gtk.main ();]]></code>
<!-- FIXME: Throws an error, "JS ERROR: !!! Unhandled type int32 releasing GArgument" on Ubuntu 10.10 -->
<p>Notice that the program is the same; we just moved the window creation code to our own <code>ImageViewer</code> class. The class's constructor calls the <code>_init</code> method, which creates and shows the window. We then create an instance of the class before running the main loop (<code>Gtk.main</code>).</p>
<p>This code is modular and can be split into multiple files easily. This makes it cleaner and easier to read.</p>
</section>
<section id="signals">
<title>Σήματα</title>
<p>Τα σήματα είναι μια από τις έννοιες κλειδιά για τον προγραμματισμό σε Gtk. Όποτε κάτι συμβαίνει σε ένα αντικείμενο, εκπέμπει ένα σήμα! Για παράδειγμα, όταν πατιέται ένα κουμπί εκπέμπει το σήμα <code>clicked</code>. Άμα θέλετε το πρόγραμμα να κάνει κάτι όταν αυτό συμβαίνει, πρέπει να συνδέσετε μια συνάρτηση (ένα χειριστή σημάτων-signal handler) σε αυτό το σήμα. Ορίστε ένα παράδειγμα:</p>
<code mime="text/javascript" style="numbered"><![CDATA[
function button_clicked () {
print ("you clicked me!");
}
var b = new Gtk.Button ({label:"Click me"});
b.connect ("clicked", button_clicked);]]></code>
<p>Οι τελευταίες δύο γραμμές δημιουργούν ένα <code>Gtk.Button</code> που ονομάζεται <code>b</code> και συνδέει το σήμα <code>clicked</code> στην συνάρτηση <code>button_clicked</code>, η οποία ορίζεται πιο πάνω. Κάθε φορά που πατιέται ένα κουμπί, ο κώδικας στη συνάρτηση <code>button_clicked</code> θα εκτελείται. Εδώ απλά τυπώνει ένα μήνυμα.</p>
<p>The syntax for connecting any signal to a function is:</p>
<code mime="text/javascript"><![CDATA[
object.connect (<signal_name>, <function_to_be_called>);]]></code>
<p>You can find signal definitions for any object in the <link href="http://library.gnome.org/devel/gtk/stable/ch01.html">GTK class reference</link>.</p>
<note>
<p>You can simplify the code by making use of an inline function definition:</p>
<code mime="text/javascript"><![CDATA[
b.connect ("clicked", function () { print ("you clicked me!"); });]]></code>
</note>
</section>
<section id="close">
<title>Closing the window</title>
<p>When you close a Gtk window it's not really closed, it's hidden. This allows you to keep the window around (which is useful if you want to ask the user if they really want to close the window, for example).</p>
<p>In our case, we really do just want to close the window. The simplest way of doing this is by connecting the <code>hide</code> signal of the GtkWindow object to a function that closes the application. Go back to the <file>image-viewer.js</file> file and add the following code to the <code>_init</code> method, on the line above <code>this.window.show</code>:</p>
<code mime="text/javascript" style="numbered">this.window.connect ("hide", Gtk.main_quit);</code>
<p>This connects the <code>hide</code> signal of the window to Gtk's <code>main_quit</code> function, which ends the execution of the Gtk main loop. Once the main loop finishes, the function <code>Gtk.main</code> returns. Our program would continue to run any code written after the <code>Gtk.main ();</code> line, but since we don't have any code after that point, the program just ends.</p>
</section>
<section id="containers2">
<title>Υποδοχείς (containers): Σχεδίαση διεπαφής χρήστης</title>
<p>Γραφικά συστατικά (widgets) (όπως τα κουμπιά και οι ετικέτες) μπορούν να τοποθετηθούν στο παράθυρο κάνοντας χρήση των <em>υποδοχέων (containers)</em>. Μπορείτε να οργανώσετε την διάταξη συνδυάζοντας διαφορετικών ειδών υποδοχείς (containers), όπως κουτιά και πλέγματα.</p>
<p>Ένα <code>Gtk.Window</code> είναι από μόνο του ένα είδος υποδοχέα (container), αλλά μπορείτε να τοποθετήσετε μόνο ένα γραφικό συστατικό (widget) άμεσα πάνω του. Θα θέλαμε να είχαμε δύο γραφικά συστατικά (widgets), μια εικόνα και ένα κουμπί, άρα θα πρέπει να τοποθετήσουμε έναν υποδοχέα (container) «υψηλής ποσότητας» μέσα στο παράθυρο για να κρατάει τα άλλα widget. Ένας αριθμός από <link href="http://library.gnome.org/devel/gtk/stable/GtkContainer.html">τύπους container</link> είναι διαθέσιμοι, αλλά θα πρέπει εδώ να χρησιμοποιήσουμε ένα <code>Gtk.Box</code>. Ένα <code>Gtk.Box</code> μπορεί να κρατήσει πολλά γραφικά συστατικά (widgets), τοποθετημένα οριζόντια ή κάθετα. Μπορείτε να κάνετε και πιο περίπλοκες διατάξεις χρησιμοποιώντας πολλά κουτιά το ένα μέσα στο άλλο.</p>
<note>
<p>Υπάρχει ένας σχεδιαστής γραφικού περιβάλλοντος με όνομα <app>Glade</app> ενσωματωμένο στο <app>Anjuta</app> το οποίο κάνει τη σχεδίαση γραφικού περιβάλλοντος πολύ εύκολη. Για αυτό το απλό παράδειγμα, όμως, θα γράψουμε τα πάντα σε κώδικα.</p>
</note>
<p>Let's add the box and widgets to the window. Insert the following code into the <code>_init</code> method, immediately above the <code>this.window.show</code> line:</p>
<code mime="text/javascript" style="numbered"><![CDATA[
var main_box = new Gtk.Box ({orientation: Gtk.Orientation.VERTICAL, spacing: 0});
this.window.add (main_box);]]></code>
<p>The first line creates a <code>Gtk.Box</code> called <code>main_box</code> and sets two of its properties: the <code>orientation</code> is set to vertical (so widgets are arranged in a column), and the <code>spacing</code> between the widgets is set to 0 pixels. The next line then adds the newly-created <code>Gtk.Box</code> to the window.</p>
<p>Μέχρι στιγμής το παράθυρο περιέχει μόνο ένα άδειο <code>Gtk.Box</code> και άμα εκτελέσετε το πρόγραμμα δε θα δείτε καμία απολύτως αλλαγή (το <code>Gtk.Box</code> είναι ένας διαφανής υποδοχέας-container, οπότε δεν μπορείτε να το δείτε).</p>
</section>
<section id="packing2">
<title>Συσκευασία: Πρόσθεση γραφικών συστατικών (widgets) στους υποδοχείς (container)</title>
<p>To add some widgets to the <code>Gtk.Box</code>, insert the following code directly below the <code>this.window.add (main_box)</code> line:</p>
<code mime="text/javascript" style="numbered"><![CDATA[
this.image = new Gtk.Image ();
main_box.pack_start (this.image, true, true, 0);]]></code>
<p>The first line creates a new <code>Gtk.Image</code> called <code>image</code>, which will be used to display an image file. Then, the image widget is added (<em>packed</em>) into the <code>main_box</code> container using <code>Gtk.Box</code>'s <link href="http://library.gnome.org/devel/gtk/stable/GtkBox.html#gtk-box-pack-start"><code>pack_start</code></link> method.</p>
<p><code>pack_start</code> takes 4 arguments: the widget that is to be added to the <code>Gtk.Box</code> (<code>child</code>); whether the <code>Gtk.Box</code> should grow larger when the new widget is added (<code>expand</code>); whether the new widget should take up all of the extra space created if the <code>Gtk.Box</code> gets bigger (<code>fill</code>); and how much space there should be, in pixels, between the widget and its neighbors inside the <code>Gtk.Box</code> (<code>padding</code>).</p>
<p>Οι υποδοχείς (containers) (και τα γραφικά συστατικά-widgets) του Gtk επεκτείνονται δυναμικά για να καλύπτουν τον διαθέσιμο χώρο, αν το επιλέξετε. Δεν τοποθετείτε τα γραφικά συστατικά (widgets) δίνοντας τους ακριβής, x, y-συντεταγμένες στο παράθυρο! Αλλά, τοποθετούνται σε σχέση το ένα με το άλλο. Αυτό κάνει την διαχείριση της αλλαγής του μεγέθους του παραθύρου πιο εύκολη, και τα γραφικά συστατικά (widgets) στις περισσότερες περιπτώσεις θα πάρουν από μόνα τους ένα λογικό μέγεθος.</p>
<p>Επίσης σημειώστε πως τα widgets τοποθετούνται με μια ιεραρχία. Μόλις τοποθετήθηκε μέσα στο <code>Gtk.Box</code>, το <code>Gtk.Image</code> θεωρείται <em>θυγατρικό</em> του <code>Gtk.Box</code>. Αυτό μας δίνει την δυνατότητα να συμπεριφερθούμε σε όλα τα θυγατρικά ενός γραφικού στοιχείου (widget) ως μια ομάδα! Για παράδειγμα, μπορείτε να κρύψετε το <code>Gtk.Box</code>, το οποίο θα κρύψει όλες τα θυγατρικά του την ίδια στιγμή.</p>
<p>Τώρα προσθέστε αυτές τις δύο γραμμές, κάτω από αυτές που μόλις προσθέσατε:</p>
<code mime="text/javascript" style="numbered"><![CDATA[
var open_button = new Gtk.Button ({label: "Open a picture..."});
main_box.pack_start (open_button, false, false, 0);]]></code>
<p>These lines are similar to the first two, but this time they create a <code>Gtk.Button</code> and add it to <code>main_box</code>. Notice that we are setting the <code>expand</code> argument (the second one) to <code>false</code> here, whereas it was set to <code>true</code> for the <code>Gtk.Image</code>. This will cause the image to take up all available space and the button to take only the space it needs. When you maximize the window, the button size will remain the same, but the image size will increase, taking up all of the rest of the window.</p>
<p>Finally, we must change the <code>this.window.show ();</code> line to read:</p>
<code>this.window.show_all ();</code>
<p>This will show the child of the Gtk window, and all of its children, and its children's children, and so on. (Remember that Gtk widgets are all hidden by default.)</p>
</section>
<section id="loading2">
<title>Φόρτωση της εικόνας: Σύνδεση στο σήμα του κουμπιού <code>clicked</code></title>
<p>When the user clicks on the <gui>Open</gui> button, a dialog should appear so that the user can choose a picture. Once chosen, the picture should be loaded and shown in the image widget.</p>
<p>The first step is to connect the <code>clicked</code> signal of the button to a signal handler function, which we call <code>_openClicked</code>. Put this code immediately after the <code>var open_button = new Gtk.Button</code> line where the button was created:</p>
<code mime="text/javascript"><![CDATA[
open_button.connect ("clicked", Lang.bind (this, this._openClicked));]]></code>
<p>We are using the <em>Lang</em> JavaScript helper here. It allows us to connect a <em>class method</em> to the signal, rather than a plain function (without a class) which we had used before for the window's <code>hide</code> signal. Don't worry about this for now, it's just a technical detail. For it to work, you also need to put the following line at the top of the file:</p>
<code mime="text/javascript">const Lang = imports.lang;</code>
</section>
<section id="loading3">
<title>Φόρτωση της εικόνας: Γράφοντας την επανάκληση (callback) του σήματος</title>
<p>Now we can create the <code>_openClicked()</code> method. Insert the following into the <code>ImageViewer.prototype</code> code block, after the <code>_init</code> method (and not forgetting the comma):</p>
<code mime="text/javascript" style="numbered"><![CDATA[
_openClicked: function () {
var chooser = new Gtk.FileChooserDialog ({title: "Select an image",
action: Gtk.FileChooserAction.OPEN,
transient_for: this.window,
modal: true});
chooser.add_button (Gtk.STOCK_CANCEL, 0);
chooser.add_button (Gtk.STOCK_OPEN, 1);
chooser.set_default_response (1);
var filter = new Gtk.FileFilter ();
filter.add_pixbuf_formats ();
chooser.filter = filter;
if (chooser.run () == 1)
this.image.file = chooser.get_filename ();
chooser.destroy ();
}]]></code>
<p>Αυτό είναι λίγο πιο περίπλοκο από όσα έχουμε κάνει μέχρι τώρα, για αυτό θα το χωρίσουμε σε κομμάτια:</p>
<list>
<item>
<p>The line beginning with <code>var chooser</code> creates an <gui>Open</gui> dialog, which the user can use to choose files. We set four properties: the title of the dialog; the action (type) of the dialog (it's an "open" dialog, but we could have used <code>SAVE</code> if the intention was to save a file; <code>transient_for</code>, which sets the parent window of the dialog; and <code>modal</code> which, if set to <code>true</code>, prevents the user from clicking on another area of the application until the dialog is closed.</p>
</item>
<item>
<p>Οι επόμενες δύο γραμμές προσθέτουν τα κουμπιά <gui>Cancel</gui> και <gui>Open</gui> στο διάλογο. Η δεύτερη παράμετρος (argument) της μεθόδου του <code>add_button</code> είναι η (ακέραιη) τιμή που επιστρέφει όταν πατιέται το κουμπί: 0 για το <gui>Ακύρωση</gui> και 1 για το <gui>Άνοιγμα</gui>.</p>
<p>Σημειώστε όταν χρησιμοποιούμε τα <em>προκαθορισμένα</em> ονόματα κουμπιών που υπάρχουν στο Gtk, αντί να γράψουμε οι ίδιοι «Ακύρωση» ή «Άνοιγμα». Το πλεονέκτημα στη χρήση των προκαθορισμένων ονομάτων είναι ότι οι ετικέτες των κουμπιών θα έχουν ήδη μεταφραστεί στη γλώσσα του χρήστη.</p>
</item>
<item>
<p>To <code>set_default_response</code> καθορίζει ποιο κουμπί θα ενεργοποιηθεί όταν ο χρήστης επιλέξει ένα αρχείο με διπλό κλικ ή πατήσει <key>Enter</key>. Στην περίπτωση μας, χρησιμοποιούμε το κουμπί <gui>Άνοιγμα</gui> σαν προεπιλεγμένο (το οποίο έχει τιμή 1).</p>
</item>
<item>
<p>Οι επόμενες τρεις γραμμές περιορίζουν το διάλογο <gui>Άνοιγμα</gui> να εμφανίζει μόνο αρχεία που μπορούν να ανοιχθούν από το <code>Gtk.Image</code>. Δημιουργούμε πρώτα ένα αντικείμενο φίλτρου· προσθέτουμε στο φίλτρο όλων των ειδών αρχεία που υποστηρίζονται από το <code>Gdk.Pixbuf</code> (το οποίο περιέχει τα περισσότερα είδη εικόνων όπως PNG και JPEG). Τέλος, καθορίζουμε το φίλτρο να είναι το φίλτρο του διαλόγου <gui>Άνοιγμα</gui>.</p>
</item>
<item>
<p><code>chooser.run</code> displays the <gui>Open</gui> dialog. The dialog will wait for the user to choose an image; when they do, <code>chooser.run</code> will return the value <output>1</output> (it would return <output>0</output> if the user clicked <gui>Cancel</gui>). The <code>if</code> statement tests for this.</p>
</item>
<item><p>Αν υποθέσουμε ότι ο χρήστης πάτησε το <gui>Άνοιγμα</gui>, η επόμενη γραμμή ορίζει την ιδιότητα <code>file</code> του <code>Gtk.Image</code> στο όνομα του αρχείου εικόνας που επέλεξε ο χρήστης. Το <code>Gtk.Image</code> θα φορτώσει και θα εμφανίσει την επιλεγμένη εικόνα.</p>
</item>
<item>
<p>Στην τελευταία γραμμή αυτής της μεθόδου, καταστρέφουμε τον διάλογο <gui>Open</gui> γιατί δεν τον χρειαζόμαστε πια.</p>
</item>
</list>
</section>
<section id="run">
<title>Τρέξτε την εφαρμογή</title>
<p>All of the code you need should now be in place, so try running the code. That should be it; a fully-functioning image viewer (and a whistlestop tour of JavaScript and Gtk) in not much time at all!</p>
</section>
<section id="impl">
<title>Υλοποίηση αναφοράς</title>
<p>If you run into problems with the tutorial, compare your code with this <link href="image-viewer/image-viewer.js">reference code</link>.</p>
</section>
<section id="next">
<title>Επόμενα βήματα</title>
<p>Εδώ είναι κάποιες ιδέες για το πως μπορείτε να επεκτείνετε αυτή την απλή επίδειξη:</p>
<list>
<item>
<p>Βάλτε τον χρήστη να επιλέξει ένα φάκελο αντί για αρχείο, και παρέχετε του τη δυνατότητα να περιηγηθεί σε όλες τις εικόνες σε ένα φάκελο.</p>
</item>
<item>
<p>Εφαρμόστε τυχαία φίλτρα και εφέ στην εικόνα όταν αυτή φορτωθεί και δώστε την δυνατότητα στον χρήστη να αποθηκεύσει την επεξεργασμένη εικόνα.</p>
<p>Το <link href="http://www.gegl.org/api.html">GEGL</link> παρέχει ισχυρές δυνατότητες επεξεργασίας εικόνας.</p>
</item>
<item>
<p>Επιτρέψτε στον χρήστη να φορτώνει εικόνες από υπηρεσίες διαμοιρασμού αρχείων του Διαδικτύου, από σαρωτές και από άλλες περίπλοκες πηγές.</p>
<p>Μπορείτε να χρησιμοποιήσετε το <link href="http://library.gnome.org/devel/gio/unstable/">GIO</link> για να ελέγχετε μεταφορές αρχείων και παρόμοια, και τη <link href="http://library.gnome.org/devel/gnome-scan/unstable/">Σάρωση του GNOME</link> για τους σαρωτές.</p>
</item>
</list>
</section>
</page>
|