|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
xmlns:its="http://www.w3.org/2005/11/its"
|
|
Packit |
1470ea |
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
Packit |
1470ea |
type="guide" style="task"
|
|
Packit |
1470ea |
id="scale.py">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">Scale (Python)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="beginner.py#entry"/>
|
|
Packit |
1470ea |
<link type="seealso" xref="grid.py"/>
|
|
Packit |
1470ea |
<link type="next" xref="textview.py" />
|
|
Packit |
1470ea |
<revision version="0.2" date="2012-06-23" status="draft"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<credit type="author copyright">
|
|
Packit |
1470ea |
<name>Marta Maria Casetti</name>
|
|
Packit |
1470ea |
<email its:translate="no">mmcasetti@gmail.com</email>
|
|
Packit |
1470ea |
<years>2012</years>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<desc>A slider widget for selecting a value from a range</desc>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>Scale</title>
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/scale.png"/>
|
|
Packit |
1470ea |
Slide the scales!
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<links type="section" />
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="code">
|
|
Packit |
1470ea |
<title>Code used to generate this example</title>
|
|
Packit |
1470ea |
<xi:include href="samples/scale.py" parse="text"><xi:fallback/></xi:include>
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="methods">
|
|
Packit |
1470ea |
<title>Useful methods for a Scale widget</title>
|
|
Packit |
1470ea |
A Gtk.Adjustment is needed to construct the Gtk.Scale. This is the representation of a value with a lower and upper bound, together with step and page increments, and a page size, and it is constructed as Gtk.Adjustment(value, lower, upper, step_increment, page_increment, page_size) where the fields are of type float ; step_increment is the increment/decrement that is obtained by using the cursor keys, page_increment the one that is obtained clicking on the scale itself. Note that page_size is not used in this case, it should be set to 0 .
|
|
Packit |
1470ea |
In line 28 the signal "value-changed" is connected to the callback function scale_moved() using widget.connect(signal, callback function) . See <link xref="signals-callbacks.py"/> for a more detailed explanation.
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item>get_value() retrieves the current value of the scale; set_value(value) sets it (if the value , of type float , is outside the minimum or maximum range, it will be clamped to fit inside them). These are methods of the class Gtk.Range. </item>
|
|
Packit |
1470ea |
<item>Use set_draw_value(False) to avoid displaying the current value as a string next to the slider. </item>
|
|
Packit |
1470ea |
<item>To highlight the part of the scale between the origin and the current value:
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
self.h_scale.set_restrict_to_fill_level(False)
|
|
Packit |
1470ea |
self.h_scale.set_fill_level(self.h_scale.get_value())
|
|
Packit |
1470ea |
self.h_scale.set_show_fill_level(True)
|
|
Packit |
1470ea |
in the callback function of the "value-changed" signal, so to have the new filling every time the value is changed. These are methods of the class Gtk.Range.
|
|
Packit |
1470ea |
</item>
|
|
Packit |
1470ea |
<item>add_mark(value, position, markup) adds a mark at the value (float or int if that is the precision of the scale), in position (Gtk.PositionType.LEFT, Gtk.PositionType.RIGHT, Gtk.PositionType.TOP, Gtk.PositionType.BOTTOM ) with text Null or markup in the Pango Markup Language. To clear marks, clear_marks() . </item>
|
|
Packit |
1470ea |
<item>set_digits(digits) sets the precision of the scale at digits digits. </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="references">
|
|
Packit |
1470ea |
<title>API References</title>
|
|
Packit |
1470ea |
In this sample we used the following:
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/unstable/GtkScale.html">GtkScale</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/unstable/GtkAdjustment.html">GtkAdjustment</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/unstable/gtk3-Standard-Enumerations.html">Standard Enumerations</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
</page>
|