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 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
|
<?xml version="1.0" encoding="utf-8"?>
<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="toolbar_builder.py" xml:lang="el">
<info>
<title type="text">Η εργαλειοθήκη δημιουργήθηκε χρησιμοποιώντας Glade (Python)</title>
<link type="guide" xref="beginner.py#menu-combo-toolbar"/>
<link type="seealso" xref="toolbar.py"/>
<link type="seealso" xref="grid.py"/>
<link type="next" xref="menubar.py"/>
<revision version="0.1" date="2012-07-17" status="draft"/>
<credit type="author copyright">
<name>Tiffany Antopolski</name>
<email its:translate="no">tiffany.antopolski@gmail.com</email>
<years>2012</years>
</credit>
<credit type="author copyright edit">
<name>Marta Maria Casetti</name>
<email its:translate="no">mmcasetti@gmail.com</email>
<years>2012</years>
</credit>
<credit type="author copyright">
<name>Sebastian Pölsterl</name>
<email its:translate="no">sebp@k-d-w.org</email>
<years>2011</years>
</credit>
<desc>Μια γραμμή κουμπιών και άλλα γραφικά στοιχεία</desc>
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
<mal:name>Ελληνική μεταφραστική ομάδα GNOME</mal:name>
<mal:email>team@gnome.gr</mal:email>
<mal:years>2012-2015</mal:years>
</mal:credit>
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
<mal:name>Δημήτρης Σπίγγος</mal:name>
<mal:email>dmtrs32@gmail.com</mal:email>
<mal:years>2012, 2013</mal:years>
</mal:credit>
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
<mal:name>Μαρία Θουκιδίδου</mal:name>
<mal:email>marablack3@gmail.com</mal:email>
<mal:years>2014</mal:years>
</mal:credit>
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
<mal:name>Θάνος Τρυφωνίδης</mal:name>
<mal:email>tomtryf@gmail.com</mal:email>
<mal:years>2014, 2015</mal:years>
</mal:credit>
</info>
<title>Η γραμμή εργαλείων δημιουργήθηκε χρησιμοποιώντας Glade</title>
<media type="image" mime="image/png" src="media/toolbar.png"/>
<p>Αυτό το παράδειγμα είναι παρόμοιο με <link xref="toolbar.py"/>, εκτός από τη χρήση Glade για δημιουργία της εργαλειοθήκης σε ένα αρχείο XML .ui.</p>
<links type="sections"/>
<section id="glade">
<title>Δημιουργία της εργαλειοθήκης με Glade</title>
<p>Για δημιουργία της γραμμής εργαλείων χρησιμοποιώντας το <link href="http://glade.gnome.org/">σχεδιαστή διεπαφής Glade</link>:</p>
<steps>
<item><p>Άνοιγμα του Glade και αποθήκευση του αρχείου ως <file>toolbar_builder.ui</file></p>
<p><media type="image" src="media/glade_ui.png" width="900"> Στιγμιότυπο διεπαφής του Glade </media></p>
</item>
<item><p>Στο <gui>περιέκτες</gui> στα αριστερά, δεξί πάτημα στην εργαλειοθήκη και επιλογή <gui>προσθήκη γραφικού στοιχείου ως ανώτατου επιπέδου</gui>.</p>
<p><media type="image" src="media/glade_select_toolbar.png"> Στιγμιότυπο του εικονιδίου εργαλειοθήκης στο Glade ui </media></p>
</item>
<item><p>Στην καρτέλα <gui>γενικά</gui> στα κάτω δεξιά, αλλαγή του <gui>ονόματος</gui> σε <input>γραμμή εργαλείων</input> και <gui>εμφάνιση βέλους</gui> σε <gui>όχι</gui>.</p>
<p><media type="image" src="media/glade_toolbar_general.png"> Στιγμιότυπο της καρτέλας Γενικά</media></p>
</item>
<item><p>Στην καρτέλα <gui>κοινά</gui>, ορίστε <gui>οριζόντια επέκταση</gui> σε <gui>ναι</gui>.</p>
<p><media type="image" src="media/glade_toolbar_common.png"> Στιγμιότυπο της καρτέλας Κοινά </media></p>
</item>
<item><p>Δεξί κλικ στη γραμμή εργαλείων στα πάνω δεξιά και επιλέξτε <gui>επεξεργασία</gui>. Το παράθυρο <gui>επεξεργαστής γραμμής εργαλείων</gui> θα εμφανιστεί.</p>
<p><media type="image" src="media/glade_toolbar_edit.png"> Στιγμιότυπο πού να δεξιοπατήσετε για να επεξεργαστείτε την εργαλειοθήκη. </media></p>
</item>
<item><p>Θέλουμε να προσθέσουμε 5 κουμπιά εργαλείων: νέο, άνοιγμα, αναίρεση, πλήρης οθόνη και εγκατάλειψη πλήρους οθόνης. Πρώτα, θα προσθέσουμε το νέο ToolButton.</p>
<steps>
<item><p>Στην καρτέλα <gui>ιεραρχία</gui>, πατήστε <gui>προσθήκη</gui>.</p></item>
<item><p>Αλλαγή του ονόματος του στοιχείου εργαλείου σε <input>new_button</input>.</p></item>
<item><p>Κύλιση προς τα κάτω και ρύθμιση του <gui>είναι σημαντικό</gui> σε <gui>ναι</gui>. Αυτό θα προκαλέσει την ετικέτα του ToolButton να εμφανιστεί, όταν προβάλετε τη γραμμή εργαλείων.</p></item>
<item><p>Εισάγετε το <gui>όνομα ενέργειας</gui>: <input>app.new</input>.</p></item>
<item><p>Αλλαγή του <gui>ετικέτα</gui> σε <input>New</input>.</p></item>
<item><p>Επιλογή του <gui>νέου</gui> αναγνωριστικού παρακαταθήκης από το πτυσσόμενο μενού, ή πληκτρολογήστε <input>gtk-new</input>.</p></item>
</steps>
<p>Επανάληψη των παραπάνω βημάτων για τα υπολειπόμενα κουμπιά εργαλείων (ToolButtons), με τις παρακάτω ιδιότητες:</p>
<table frame="all" rules="rows">
<thead>
<tr>
<td><p>Όνομα</p></td>
<td><p>Είναι σημαντικό</p></td>
<td><p>Όνομα ενέργειας</p></td>
<td><p>Ετικέτα</p></td>
<td><p>Αναγνωριστικό παρακαταθήκης</p></td>
</tr>
</thead>
<tbody>
<tr>
<td><p>open_button</p></td>
<td><p>Ναι</p></td>
<td><p>app.open</p></td>
<td><p>Open</p></td>
<td><p>gtk-open</p></td>
</tr>
<tr>
<td><p>undo_button</p></td>
<td><p>Ναι</p></td>
<td><p>win.undo</p></td>
<td><p>Αναίρεση</p></td>
<td><p>gtk-undo</p></td>
</tr>
<tr>
<td><p>fullscreen_button</p></td>
<td><p>Ναι</p></td>
<td><p>win.fullscreen</p></td>
<td><p>Πλήρης οθόνη</p></td>
<td><p>gtk-fullscreen</p></td>
</tr>
<tr>
<td><p>leave_fullscreen_button</p></td>
<td><p>Ναι</p></td>
<td><p>win.fullscreen</p></td>
<td><p>Έξοδος από πλήρη οθόνη</p></td>
<td><p>gtk-leave-fullscreen</p></td>
</tr>
</tbody>
</table>
<media type="image" src="media/glade_toolbar_editor.png">
</media>
</item>
<item><p>Κλείσιμο του <gui>επεξεργαστή γραμμής εργαλείων</gui>.</p>
</item>
<item><p>Όταν το πρόγραμμά μας θα ξεκινήσει στην αρχή, δεν θέλουμε το κουμπί εργαλείου (ToolButton) <gui>Έξοδος από πλήρη οθόνη</gui> να είναι ορατό, αφού η εφαρμογή δεν θα είναι σε λειτουργία πλήρους οθόνης. Μπορείτε να το ρυθμίσετε στην καρτέλα <gui>κοινά</gui>, πατώντας στην ιδιότητα <gui>ορατό</gui> σε <gui>όχι</gui>. Το κουμπί εργαλείου θα εξακολουθεί να εμφανίζεται στον σχεδιαστή διεπαφής, αλλά θα συμπεριφέρεται σωστά, όταν το αρχείο φορτώνεται στον κώδικα προγράμματός σας. Σημειώστε ότι η μέθοδος <code>show_all()</code> θα αντικαταστήσει αυτή τη ρύθμιση - έτσι στον κώδικα πρέπει να χρησιμοποιήσουμε <code>show()</code> ξεχωριστά σε όλα τα στοιχεία.</p>
<p><media type="image" src="media/glade_visible_no.png"> Ορισμός της ιδιότητας ορατό σε Όχι </media></p>
</item>
<item><p>Αποθήκευση της εργασίας σας και κλείσιμο του Glade.</p>
</item>
<item><p>Το δημιουργημένο αρχείο XML από το Glade εμφανίζεται παρακάτω. Αυτή είναι η περιγραφή της εργαλειοθήκης. Τη στιγμή της εγγραφής, η επιλογή προσθήκης στην κλάση Gtk.STYLE_CLASS_PRIMARY_TOOLBAR στην διεπαφή Glade δεν υπάρχει. Μπορούμε χειροκίνητα να το προσθέσουμε στο αρχείο XML. Για να το κάνουμε, προσθέστε τον παρακάτω κώδικα XML στη γραμμή 9 του <file>toolbar_builder.ui</file>:</p>
<code>
<style>
<class name="primary-toolbar"/>
</style>
</code>
<p>Εάν δεν το προσθέσετε, το πρόγραμμα θα εξακολουθήσει να δουλεύει υπέροχα. Η τελική εργαλειοθήκη όμως θα φαίνεται ελαφρά διαφορετική τότε από το στιγμιότυπο στην κορυφή αυτής της σελίδας.</p>
</item>
</steps>
<code mime="application/xml" style="numbered"><?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkToolbar" id="toolbar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="show_arrow">False</property>
<child>
<object class="GtkToolButton" id="new_button">
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="is_important">True</property>
<property name="action_name">app.new</property>
<property name="label" translatable="yes">New</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-new</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="open_button">
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="is_important">True</property>
<property name="action_name">app.open</property>
<property name="label" translatable="yes">Open</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-open</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="undo_button">
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="is_important">True</property>
<property name="action_name">win.undo</property>
<property name="label" translatable="yes">Undo</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-undo</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="fullscreen_button">
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="is_important">True</property>
<property name="action_name">win.fullscreen</property>
<property name="label" translatable="yes">Fullscreen</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-fullscreen</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="leave_fullscreen_button">
<property name="use_action_appearance">False</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="is_important">True</property>
<property name="action_name">win.fullscreen</property>
<property name="label" translatable="yes">Leave Fullscreen</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-leave-fullscreen</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
</object>
</interface>
</code>
</section>
<section id="code">
<title>Ο χρησιμοποιούμενος κώδικας για παραγωγή αυτού παραδείγματος</title>
<p>Τώρα δημιουργούμε τον παρακάτω κώδικα, που προσθέτει την εργαλειοθήκη από το αρχείο που μόλις δημιουργήσαμε.</p>
<code mime="text/x-python" style="numbered">from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import Gio
import sys
class MyWindow(Gtk.ApplicationWindow):
def __init__(self, app):
Gtk.Window.__init__(self, title="Toolbar Example", application=app)
self.set_default_size(400, 200)
# a grid to attach the toolbar (see below)
grid = Gtk.Grid()
self.add(grid)
# we have to show the grid (and therefore the toolbar) with show(),
# as show_all() would show also the buttons in the toolbar that we want to
# be hidden (such as the leave_fullscreen button)
grid.show()
# a builder to add the UI designed with Glade to the grid:
builder = Gtk.Builder()
# get the file (if it is there)
try:
builder.add_from_file("toolbar_builder.ui")
except:
print("file not found")
sys.exit()
# and attach it to the grid
grid.attach(builder.get_object("toolbar"), 0, 0, 1, 1)
# two buttons that will be used later in a method
self.fullscreen_button = builder.get_object("fullscreen_button")
self.leave_fullscreen_button = builder.get_object(
"leave_fullscreen_button")
# create the actions that control the window, connect their signal to a
# callback method (see below), add the action to the window:
# undo
undo_action = Gio.SimpleAction.new("undo", None)
undo_action.connect("activate", self.undo_callback)
self.add_action(undo_action)
# and fullscreen
fullscreen_action = Gio.SimpleAction.new("fullscreen", None)
fullscreen_action.connect("activate", self.fullscreen_callback)
self.add_action(fullscreen_action)
# callback for undo
def undo_callback(self, action, parameter):
print("You clicked \"Undo\".")
# callback for fullscreen
def fullscreen_callback(self, action, parameter):
# check if the state is the same as Gdk.WindowState.FULLSCREEN, which
# is a bit flag
is_fullscreen = self.get_window().get_state(
) & Gdk.WindowState.FULLSCREEN != 0
if is_fullscreen:
self.unfullscreen()
self.leave_fullscreen_button.hide()
self.fullscreen_button.show()
else:
self.fullscreen()
self.fullscreen_button.hide()
self.leave_fullscreen_button.show()
class MyApplication(Gtk.Application):
def __init__(self):
Gtk.Application.__init__(self)
def do_activate(self):
win = MyWindow(self)
# show the window - with show() not show_all() because that would show also
# the leave_fullscreen button
win.show()
def do_startup(self):
Gtk.Application.do_startup(self)
# actions that control the application: create, connect their signal to a
# callback method (see below), add the action to the application
# new
new_action = Gio.SimpleAction.new("new", None)
new_action.connect("activate", self.new_callback)
app.add_action(new_action)
# open
open_action = Gio.SimpleAction.new("open", None)
open_action.connect("activate", self.open_callback)
app.add_action(open_action)
# callback for new
def new_callback(self, action, parameter):
print("You clicked \"New\".")
# callback for open
def open_callback(self, action, parameter):
print("You clicked \"Open\".")
app = MyApplication()
exit_status = app.run(sys.argv)
sys.exit(exit_status)
</code>
</section>
<section id="methods">
<title>Χρήσιμες μέθοδοι για Gtk.Builder</title>
<p>Για τις χρήσιμες μεθόδους για ένα γραφικό στοιχείο εργαλειοθήκης, δείτε <link xref="toolbar.py"/></p>
<p>Το Gtk.Builder κατασκευάζει μια διεπαφή από έναν ορισμό UI XML.</p>
<list>
<item><p>Η <code>add_from_file(filename)</code> φορτώνει και αναλύει το δεδομένο αρχείο και το συγχωνεύει με τα τρέχοντα περιεχόμενα του Gtk.Builder.</p></item>
<item><p>Η <code>add_from_file(string)</code> φορτώνει την δεδομένη συμβολοσειρά και το συγχωνεύει με τα τρέχοντα περιεχόμενα του Gtk.Builder.</p></item>
<item><p>Η <code>add_objects_from_file(filename, object_ids)</code> είναι η ίδια με <code>add_from_file()</code>, αλλά φορτώνει μόνο τα αντικείμενα με τις ταυτότητες που δίνονται στη λίστα <code>object_id</code>.</p></item>
<item><p>Το <code>add_objects_from_string(string, object_ids)</code> είναι ίδιο με το <code>add_from_string()</code>, αλλά φορτώνει μόνο τα αντικείμενα με τα αναγνωριστικά που δόθηκαν στη λίστα <code>object_id</code>s.</p></item>
<item><p>Η <code>get_object(object_id)</code> ανακτά το γραφικό στοιχείο με την ταυτότητα <code>object_id</code> από τα φορτωμένα αντικείμενα του δομητή.</p></item>
<item><p>Η <code>get_objects()</code> επιστρέφει όλα τα φορτωμένα αντικείμενα.</p></item>
<item><p>Το <code>connect_signals(handler_object)</code> συνδέει τα σήματα στις μεθόδους που δίνονται στον <code>handler_object</code>. Αυτό μπορεί να είναι οποιοδήποτε αντικείμενο περιέχει κλειδιά ή γνωρίσματα που καλούνται όπως τα ονόματα χειριστή σήματος που δίνονται στην περιγραφή διεπαφής, π.χ. μια κλάση ή ένα λεξικό. Στη γραμμή 39 το σήμα <code>"activate"</code> από την ενέργεια <code>undo_action</code> συνδέεται σε μια συνάρτηση επανάκλησης <code>undo_callback()</code> χρησιμοποιώντας <code><var>action</var>.connect(<var>signal</var>, <var>callback function</var>)</code>. Δείτε <link xref="signals-callbacks.py"/> για μια πιο λεπτομερή εξήγηση.</p>
</item>
</list>
</section>
<section id="references">
<title>Αναφορές API</title>
<p>Σε αυτό το παράδειγμα χρησιμοποιήσαμε τα παρακάτω:</p>
<list>
<item><p><link href="http://developer.gnome.org/gtk3/unstable/GtkGrid.html">GtkGrid</link></p></item>
<item><p><link href="http://developer.gnome.org/gtk3/unstable/GtkBuilder.html">GtkBuilder</link></p></item>
<item><p><link href="http://developer.gnome.org/gtk3/unstable/GtkWidget.html">GtkWidget</link></p></item>
<item><p><link href="http://developer.gnome.org/gdk3/unstable/gdk3-Event-Structures.html#GdkEventWindowState">Δομή γεγονότων</link></p></item>
</list>
</section>
</page>
|