Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

The app is written in HTML and is running using webkit and Quickly. The opacity can be changed using Glade.

I want to add a slider functionality in HTML which will change the title of the HTML document according to the opacity.

How to code the main app/AppWindow.py so that it will change the opacity dynamically according to the HTML document title?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

You can use the set_opacity() method of GtkWindow object.

It will expect a float, so you should do a type conversion before.

try:
    self.set_opacity(float(title))
except ValueError:
    pass  # Do something with the invalid value here.
share|improve this answer

Glade doesn't add any magic function or properties to the widgets, it just uses what GTK provides.

Looking at the docs, I can find that GtkWidget has a set_opacity() method. This only works since 3.8 and is the preferred way to do it. If your code also has to support GTK 3.6 and lower, use GtkWindow.set_opacity()

share|improve this answer
    
I have found a command self.set_opacity() which works statically. When I dynamically code self.set_opacity(title) python says Traceback (most recent call last): File "/home/archisman/up-clock/up_clock/UpClockWindow.py", line 86, in title_changed self.set_opacity("title") TypeError: Must be number, not str –  Archisman Panigrahi Mar 14 at 11:27
    
Why are you using "title" as a parameter for set_opacity?. It expects a number between 0 and 1, where 0 is invisible and 1 totally opaque. –  Javier Rivera Mar 17 at 7:56
    
@JavierRivera So that I could change the document title using a slider in HTML like this. And Python would set opacity same as the title. But since it isn't supporting string variables I had to do all this. github.com/gabrielbarbosanascimento/Up-Clock/commit/… –  Archisman Panigrahi Mar 18 at 7:06
1  
OMG!!!!... you know, you can convert between types ;). Just do self.set_opacity(float(title)). But please note that if title has a value than can't be converted to a float the program will break. –  Javier Rivera Mar 18 at 8:01
1  
That piece of code is a stab to the programmmer's heart :-). Just convert it to a float like Javier said and catch the ValueError exception. –  Timo Mar 18 at 9:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.