Reputation: 2916
I have translated this code to python 2.7, it's working. But now I have a problem I can't solve by myself: I would like to have the 100 value on the top, and 0 on the down. How to do this?
Here's my code:
#!/usr/bin/env python
# coding: utf8
import pygtk
pygtk.require('2.0')
import gtk
class Fan():
def destroy(self, widget, donnees=None):
gtk.main_quit()
exit()
def __init__(self):
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_title('Vertical Scales')
window.set_border_width(10)
window.connect("destroy", self.destroy)
window.set_size_request(-1, 150)
# Récupération des informations de surface d'affichage
self.screen = window.get_screen()
self.largeur = int(self.screen.get_width())
self.hauteur = int(self.screen.get_height())
window.move(self.largeur/2-150,self.hauteur/2-40)
window.set_default_size(100, 200)
#Adjustments
#value, min, max, step, pg-incr,pg-size
adj1 = gtk.Adjustment(50, 0, 100, 1.0, 1.0, 0.0)
adj2 = gtk.Adjustment(50, 0, 100, 1.0, 1.0, 0.0)
scale1 = gtk.VScale(adj1)
scale2 = gtk.VScale(adj2)
scale1.value_pos = gtk.POS_RIGHT
scale2.value_pos = gtk.POS_LEFT
hbox = gtk.HBox(True, 5)
hbox.pack_start_defaults(scale1)
hbox.pack_start_defaults(scale2)
window.add(hbox)
hbox.show()
window.show_all()
if __name__ == "__main__":
base = Fan()
gtk.main()
Here is a screenshot, I would like to have 100 with the curser on the top, and 0 with the curseur on the bottom of the window:
Thanks
Upvotes: 2
Views: 935
Reputation: 55499
gtk.Scale objects inherit from gtk.Range; you need to set the Range property "inverted" to True.
So put this somewhere after the statements that create your VScales:
scale1.set_inverted(True)
scale2.set_inverted(True)
PS. To run your code on my system I had to change your coding statement to
# -*- coding: latin-1 -*-
but I think that's because of changes the Stackoverflow formatting software does to text posted here.
The official GTK+ tutorials are good (although they contain some examples that use deprecated code) but GTK is so big that it's not easy for the tutorials to cover everything. You need to get familiar with the GTK reference manual, and how it hides explains things. :)
So if you look at the page for gtk.HScale, it has a link to various properties, including gtk.Range properties. That link mentions "inverted" as one of the properties, and elsewhere on the page it explicitly describes the set_inverted
and get_inverted
methods. Note that functions named like that are standard in GTK for setting & getting properties, so if you know (or can guess :) ) a property name, then you also know how to set or get it.
The gtk.HScale page also mentions that it inherits from gtk.Scale, so that page is also worth looking at for extra info.
I just noticed that you have
self.largeur = int(self.screen.get_width())
self.hauteur = int(self.screen.get_height())
But you can just do
self.largeur = self.screen.get_width()
self.hauteur = self.screen.get_height()
since those get_width() & get_height() methods both return int
.
Rather than using window.move(), you should take a look at gtk.Window.set_position()
and the GTK Window Position Constants.
Upvotes: 3