I'm trying to develop a simple GTK application with gtkme (1.3.5) library and I'm having trouble using GtkScale
object in Glade (3.20.0-1). I created one of them and it's defined in .glade
file by default as:
<object class="GtkScale">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="round_digits">1</property>
</object>
Yet the way it appears in Glade and my application makes it unusable, even after messing around with all of the available settings:
I expected to see something like volume bars in pavucontrol instead:
After messing around with the code from this thread I learned that changing object to <widget class="GtkHScale" id="hscale1">
or adding <property name="update_policy">GTK_UPDATE_CONTINUOUS</property>
doesn't change anything.
To get a completely working Scale
, you need to define two elements: A Gtk.Adjustment
(which does the math work and defines limits) and a Gtk.Scale
which shows the element on the Scale
. Without an Adjustment
, the Scale
shows as in your image.
So, in Glade
, you need to define those two elements. The Adjustment
will show as a non-visible element (see below), apart from the elements in the actual widget tree. The Scale
will show initially as you've seen, and has to be connected to the Adjustment
to actually show something. Adjustment
and Scale
are in different 'widget sections' in Glade
, which might not be obvious:
and it will appear in the widget tree like this:
In the Scale
's properties, you can select the Adjustment
you want to assign to it. Of course you can do this also at run-time. The code to 'manually' make a working Scale
is this (i.e. without Glade
, but directly in your Python code):
adj = Gtk.Adjustment(100.0, 0.0, 150.0, 2.0, 10.0, 10.0)
scale = Gtk.Scale()
scale.set_orientation(Gtk.Orientation.HORIZONTAL)
scale.set_adjustment(adj)
You can define the Adjustment
in Glade
(or add it later) and the same goes for the Scale
widget (though it's more logical to do that in Glade
anyway.
Added references:
An huge help while programming Python
is Lazca's Python PGI API
reference. It not only documents Gtk
calls but a large number of other libraries which are similarly accessible. You can consult it online, or you can install a copy on your computer. Eg. the parameters for the Gtk.Adjustment
are here.
One of the most complete tutorials for Python
is here. It just doesn't cover GtkScale
, but is fairly thorough for the rest.
There's a huge number of tutorials on the 'net. Many of them are excellent. Rarely you encounter a more difficult problem, but even then you'll probably find a solution in someone's blog.
And finally, another huge resource is the Nullege Python source code search engine
. BlackDuck's Code search used to be useful, though the interface was not entirely reliable. It seems it has been disabled now.